diff options
author | jessib <jessib@riseup.net> | 2013-04-25 09:47:01 -0700 |
---|---|---|
committer | jessib <jessib@riseup.net> | 2013-04-25 09:47:01 -0700 |
commit | 4927abe188c7615fe6844ae0e20144b116a52a99 (patch) | |
tree | e4f333fbb0eded2fc0c2a13ac693b0591c98678b | |
parent | fb66f8e30d302b7230d22112aebe2fcb4912c3f0 (diff) | |
parent | d5f0e5b67332e7c72ef9e738678e9b0e220b164b (diff) |
Merge pull request #44 from azul/bugfix/2298-fix-couchdb-view
Bugfix/2298 fix couchdb view
-rw-r--r-- | users/app/designs/user/email_by_login_or_alias.js | 9 | ||||
-rw-r--r-- | users/app/models/user.rb | 15 | ||||
-rw-r--r-- | users/test/unit/user_test.rb | 11 |
3 files changed, 25 insertions, 10 deletions
diff --git a/users/app/designs/user/email_by_login_or_alias.js b/users/app/designs/user/email_by_login_or_alias.js deleted file mode 100644 index 2a86d68..0000000 --- a/users/app/designs/user/email_by_login_or_alias.js +++ /dev/null @@ -1,9 +0,0 @@ -function(doc) { - if (doc.type != 'User') { - return; - } - emit(doc.login, doc.public_key); - doc.email_aliases.forEach(function(alias){ - emit(alias.username, doc.public_key); - }); -} diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 62c5054..5c849f0 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -51,7 +51,20 @@ class User < CouchRest::Model::Base load_views(own_path.join('..', 'designs', 'user')) view :by_login view :by_created_at - end + view :pgp_key_by_handle, + map: <<-EOJS + function(doc) { + if (doc.type != 'User') { + return; + } + emit(doc.login, doc.public_key); + doc.email_aliases.forEach(function(alias){ + emit(alias.username, doc.public_key); + }); + } + EOJS + + end # end of design class << self alias_method :find_by_param, :find diff --git a/users/test/unit/user_test.rb b/users/test/unit/user_test.rb index 10c8b46..c8c837b 100644 --- a/users/test/unit/user_test.rb +++ b/users/test/unit/user_test.rb @@ -64,4 +64,15 @@ class UserTest < ActiveSupport::TestCase other_user.destroy end + test "pgp key view" do + @user.public_key = SecureRandom.base64(4096) + @user.save + + view = User.pgp_key_by_handle.key(@user.login) + + assert_equal 1, view.rows.count + assert result = view.rows.first + assert_equal @user.login, result["key"] + assert_equal @user.public_key, result["value"] + end end |