diff options
Diffstat (limited to 'users')
-rw-r--r-- | users/app/models/identity.rb | 7 | ||||
-rw-r--r-- | users/app/models/user.rb | 13 | ||||
-rw-r--r-- | users/test/unit/identity_test.rb | 11 |
3 files changed, 17 insertions, 14 deletions
diff --git a/users/app/models/identity.rb b/users/app/models/identity.rb index a081394..9fd0cad 100644 --- a/users/app/models/identity.rb +++ b/users/app/models/identity.rb @@ -7,13 +7,6 @@ class Identity < CouchRest::Model::Base property :address property :destination - def initialize(attribs = {}, &block):q - attribs.reverse_merge! user_id: user.id, - address: user.main_email_address, - destination: user.main_email_address - Identity.new attribs - end - design do view :by_user_id end diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 413b4ac..dda5a41 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -73,6 +73,19 @@ class User < CouchRest::Model::Base alias_method :find_by_param, :find end + def create_identity(attribs = {}, &block) + build_identity(attribs, &block) + identity.save + identity + end + + def build_identity(attribs = {}, &block) + attribs.reverse_merge! user_id: self.id, + address: self.email_address, + destination: self.email_address + Identity.new(attribs, &block) + end + def to_param self.id end diff --git a/users/test/unit/identity_test.rb b/users/test/unit/identity_test.rb index 389ef89..3130ddc 100644 --- a/users/test/unit/identity_test.rb +++ b/users/test/unit/identity_test.rb @@ -7,13 +7,10 @@ class IdentityTest < ActiveSupport::TestCase end test "user has identity to start with" do - id = Identity.new user_id: @user.id - id.save - assert_equal 1, Identity.by_user_id.key(@user.id).count - identity = Identity.find_by_user_id(@user.id) - assert_equal @user.email_address, identity.address - assert_equal @user.email_address, identity.destination - assert_equal @user, identity.user + id = @user.build_identity + assert_equal @user.email_address, id.address + assert_equal @user.email_address, id.destination + assert_equal @user, id.user end test "add alias" do |