summaryrefslogtreecommitdiff
path: root/users/test/unit/email_aliases_test.rb
diff options
context:
space:
mode:
authorAzul <azul@leap.se>2012-12-20 17:38:36 +0100
committerAzul <azul@leap.se>2012-12-20 17:38:36 +0100
commitc83ada50de6b9a7084a23037068ba7f12e09dfc9 (patch)
tree75c0eef72cb7a2c4e0cfb8350a79631e5c5a8595 /users/test/unit/email_aliases_test.rb
parentc4f87b3447ab2a96dc9181d0b89be4f6f025042a (diff)
fixed tests, testing corner cases, fixed these
Diffstat (limited to 'users/test/unit/email_aliases_test.rb')
-rw-r--r--users/test/unit/email_aliases_test.rb60
1 files changed, 36 insertions, 24 deletions
diff --git a/users/test/unit/email_aliases_test.rb b/users/test/unit/email_aliases_test.rb
index f680ac6..88f97f4 100644
--- a/users/test/unit/email_aliases_test.rb
+++ b/users/test/unit/email_aliases_test.rb
@@ -6,6 +6,11 @@ class EmailAliasTest < ActiveSupport::TestCase
@attribs = User.valid_attributes_hash
User.find_by_login(@attribs[:login]).try(:destroy)
@user = User.new(@attribs)
+ @attribs.merge!(:login => "other_user")
+ User.find_by_login(@attribs[:login]).try(:destroy)
+ @other_user = User.create(@attribs)
+ @alias = "valid_alias@#{APP_CONFIG[:domain]}"
+ User.find_by_email_or_alias(@alias).try(:destroy)
end
test "no email aliases set in the beginning" do
@@ -13,46 +18,53 @@ class EmailAliasTest < ActiveSupport::TestCase
end
test "adding email alias through params" do
- email_alias = "valid_alias@domain.net"
- @user.attributes = {:email_aliases_attributes => {"0" => {:email => email_alias}}}
+ @user.attributes = {:email_aliases_attributes => {"0" => {:email => @alias}}}
assert @user.changed?
assert @user.save
- assert_equal email_alias, @user.email_aliases.first.to_s
+ assert_equal @alias, @user.email_aliases.first.to_s
end
test "adding email alias directly" do
- email_alias = "valid_alias@domain.net"
- @user.email_aliases.build :email => email_alias
- assert @user.changed?
+ @user.email_aliases.build :email => @alias
assert @user.save
- assert_equal email_alias, @user.reload.email_aliases.first.to_s
+ assert_equal @alias, @user.reload.email_aliases.first.to_s
end
test "duplicated email aliases are invalid" do
- email_alias = "valid_alias@domain.net"
- @user.email_aliases.build :email => email_alias
+ @user.email_aliases.build :email => @alias
@user.save
- # add again
- email_alias = @user.email_aliases.build :email => email_alias
- assert !email_alias.valid?
- assert @user.changed?
- assert !@user.valid?
+ assert_invalid_alias @alias
+ end
+
+ test "email alias needs to be different from other peoples email" do
+ @other_user.email = @alias
+ @other_user.save
+ assert_invalid_alias @alias
+ end
+
+ test "email needs to be different from other peoples email aliases" do
+ @other_user.email_aliases.build :email => @alias
+ @other_user.save
+ assert_invalid_alias @alias
end
test "email is invalid as email alias" do
- email_alias = "valid_alias@domain.net"
- @user.email = email_alias
- @user.email_aliases.build :email => email_alias
- assert @user.changed?
- assert !@user.valid?
+ @user.email = @alias
+ assert_invalid_alias @alias
end
test "find user by email alias" do
- email_alias = "valid_alias@domain.net"
- @user.email_aliases.build :email => email_alias
+ @user.email_aliases.build :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)
+ assert_equal @user, User.find_by_email_or_alias(@alias)
+ assert_equal @user, User.find_by_email_alias(@alias)
+ assert_nil User.find_by_email(@alias)
+ end
+
+ def assert_invalid_alias(string)
+ email_alias = @user.email_aliases.build :email => string
+ assert !email_alias.valid?
+ assert !@user.valid?
end
+
end