summaryrefslogtreecommitdiff
path: root/users/test/unit/email_aliases_test.rb
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-12-13 17:17:30 +0100
committerAzul <azul@leap.se>2012-12-13 17:17:30 +0100
commita77d5cf5fd2ff6cc335b586477d6d6e58f758591 (patch)
tree32640ef2457ecce3a08f704f5b5b0ac00a37f9d8 /users/test/unit/email_aliases_test.rb
parent961fe13b784e7f44e55f9cd0a106728c69354a0f (diff)
parent32db6e2ee3ae449f2fe0f947f9ac4aafde340a9d (diff)
Merge branch 'master' into develop
Conflicts: users/test/unit/user_test.rb
Diffstat (limited to 'users/test/unit/email_aliases_test.rb')
-rw-r--r--users/test/unit/email_aliases_test.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/users/test/unit/email_aliases_test.rb b/users/test/unit/email_aliases_test.rb
new file mode 100644
index 0000000..762aaea
--- /dev/null
+++ b/users/test/unit/email_aliases_test.rb
@@ -0,0 +1,57 @@
+require 'test_helper'
+
+class EmailAliasTest < ActiveSupport::TestCase
+
+ setup do
+ @attribs = User.valid_attributes_hash
+ User.find_by_login(@attribs[:login]).try(:destroy)
+ @user = User.new(@attribs)
+ end
+
+ test "no email aliases set in the beginning" do
+ assert_equal [], @user.email_aliases
+ end
+
+ test "adding email alias through params" do
+ email_alias = "valid_alias@domain.net"
+ @user.attributes = {:email_aliases_attributes => {"0" => {:email => email_alias}}}
+ assert @user.changed?
+ assert @user.save
+ assert_equal email_alias, @user.email_aliases.first.to_s
+ end
+
+ test "adding email alias directly" do
+ email_alias = "valid_alias@domain.net"
+ @user.add_email_alias(email_alias)
+ assert @user.changed?
+ assert @user.save
+ assert_equal email_alias, @user.reload.email_aliases.first.to_s
+ end
+
+ test "duplicated email aliases are invalid" do
+ email_alias = "valid_alias@domain.net"
+ @user.add_email_alias(email_alias)
+ @user.save
+ # add again
+ @user.add_email_alias(email_alias)
+ assert @user.changed?
+ assert !@user.valid?
+ end
+
+ test "email is invalid as email alias" do
+ email_alias = "valid_alias@domain.net"
+ @user.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_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)
+ assert_nil User.find_by_email(email_alias)
+ end
+end