summaryrefslogtreecommitdiff
path: root/users
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-12-13 16:13:32 +0100
committerAzul <azul@leap.se>2012-12-13 17:15:41 +0100
commitaed03c04270bc9b7d48048ffb2f24fecc993c7ac (patch)
treeaee41c3bb73bf5167fb5b161ea159f82195d4535 /users
parent577c3d8149acbd483120847b994582268f93c0b3 (diff)
refactor: changed add_email to add_email_alias
that's what it does. Changed all tests to use it instead of the attributes method
Diffstat (limited to 'users')
-rw-r--r--users/app/models/user.rb4
-rw-r--r--users/test/unit/email_aliases_test.rb10
-rw-r--r--users/test/unit/email_test.rb6
3 files changed, 10 insertions, 10 deletions
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index b531dfd..4fd0039 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -112,7 +112,7 @@ class User < CouchRest::Model::Base
APP_CONFIG['admins'].include? self.login
end
- def add_email(email)
+ def add_email_alias(email)
email = LocalEmail.new(email) unless email.is_a? Email
email_aliases << email
end
@@ -121,7 +121,7 @@ class User < CouchRest::Model::Base
# All the ui needs for now.
def email_aliases_attributes=(attrs)
if attrs && attrs.values.first
- add_email attrs.values.first
+ add_email_alias attrs.values.first
end
end
diff --git a/users/test/unit/email_aliases_test.rb b/users/test/unit/email_aliases_test.rb
index 3c731e1..762aaea 100644
--- a/users/test/unit/email_aliases_test.rb
+++ b/users/test/unit/email_aliases_test.rb
@@ -22,7 +22,7 @@ class EmailAliasTest < ActiveSupport::TestCase
test "adding email alias directly" do
email_alias = "valid_alias@domain.net"
- @user.add_email(email_alias)
+ @user.add_email_alias(email_alias)
assert @user.changed?
assert @user.save
assert_equal email_alias, @user.reload.email_aliases.first.to_s
@@ -30,10 +30,10 @@ class EmailAliasTest < ActiveSupport::TestCase
test "duplicated email aliases are invalid" do
email_alias = "valid_alias@domain.net"
- @user.add_email(email_alias)
+ @user.add_email_alias(email_alias)
@user.save
# add again
- @user.add_email(email_alias)
+ @user.add_email_alias(email_alias)
assert @user.changed?
assert !@user.valid?
end
@@ -41,14 +41,14 @@ class EmailAliasTest < ActiveSupport::TestCase
test "email is invalid as email alias" do
email_alias = "valid_alias@domain.net"
@user.email = email_alias
- @user.add_email(email_alias)
+ @user.add_email_alias(email_alias)
assert @user.changed?
assert !@user.valid?
end
test "find user by email alias" do
email_alias = "valid_alias@domain.net"
- @user.add_email(email_alias)
+ @user.add_email_alias(email_alias)
assert @user.save
assert_equal @user, User.find_by_email_or_alias(email_alias)
assert_equal @user, User.find_by_email_alias(email_alias)
diff --git a/users/test/unit/email_test.rb b/users/test/unit/email_test.rb
index cba88a2..1e216d6 100644
--- a/users/test/unit/email_test.rb
+++ b/users/test/unit/email_test.rb
@@ -20,9 +20,9 @@ class EmailTest < ActiveSupport::TestCase
test "email aliases need to be unique" do
email_alias = "valid_alias@domain.net"
- @other_user.attributes = {:email_aliases_attributes => {"0" => {:email => email_alias}}}
+ @other_user.add_email_alias email_alias
@other_user.save
- @user.attributes = {:email_aliases_attributes => {"0" => {:email => email_alias}}}
+ @user.add_email_alias email_alias
assert @user.changed?
assert !@user.save
# TODO handle errors
@@ -32,7 +32,7 @@ class EmailTest < ActiveSupport::TestCase
email_alias = "valid_alias@domain.net"
@other_user.email = email_alias
@other_user.save
- @user.attributes = {:email_aliases_attributes => {"0" => {:email => email_alias}}}
+ @user.add_email_alias email_alias
assert @user.changed?
assert !@user.save
end