summaryrefslogtreecommitdiff
path: root/users/test/unit/email_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_test.rb
parentc4f87b3447ab2a96dc9181d0b89be4f6f025042a (diff)
fixed tests, testing corner cases, fixed these
Diffstat (limited to 'users/test/unit/email_test.rb')
-rw-r--r--users/test/unit/email_test.rb55
1 files changed, 41 insertions, 14 deletions
diff --git a/users/test/unit/email_test.rb b/users/test/unit/email_test.rb
index 6f9beaa..060ced5 100644
--- a/users/test/unit/email_test.rb
+++ b/users/test/unit/email_test.rb
@@ -10,6 +10,8 @@ class EmailTest < ActiveSupport::TestCase
@attribs.merge!(:login => "other_user")
User.find_by_login(@attribs[:login]).try(:destroy)
@other_user = User.create(@attribs)
+ @email_string = "valid_alias@#{APP_CONFIG[:domain]}"
+ User.find_by_email_or_alias(@email_string).try(:destroy)
end
teardown do
@@ -17,23 +19,48 @@ class EmailTest < ActiveSupport::TestCase
@other_user.destroy if @other_user.persisted?
end
-
- test "email aliases need to be unique" do
- email_alias = "valid_alias@domain.net"
- @other_user.email_aliases.build :email => email_alias
+ test "email needs to be different from other peoples email" do
+ @other_user.email = @email_string
@other_user.save
- @user.email_aliases.build :email => email_alias
- assert @user.changed?
- assert !@user.save
- # TODO handle errors
+ assert_invalid_email @email_string
end
- test "email aliases may not conflict with emails" do
- email_alias = "valid_alias@domain.net"
- @other_user.email = email_alias
+ test "email needs to be different from other peoples email aliases" do
+ @other_user.email_aliases.build :email => @email_string
@other_user.save
- @user.email_aliases.build :email => email_alias
- assert @user.changed?
- assert !@user.save
+ assert_invalid_email @email_string
+ end
+
+ test "email needs to be different from email aliases" do
+ @user.email_aliases.build :email => @email_string
+ @user.save
+ assert_invalid_email @email_string
+ end
+
+ test "non local emails are invalid" do
+ assert_invalid_email "not_valid@mail.me"
+ end
+
+ test "local emails are valid" do
+ local_email = "valid@#{APP_CONFIG[:domain]}"
+ @user.email = local_email
+ @user.valid?
+ assert_equal Hash.new, @user.errors.messages
+ end
+
+ test "find user by email" do
+ email = "finding@test.me"
+ @user.email = email
+ @user.save
+ assert_equal @user, User.find_by_email(email)
+ assert_equal @user, User.find_by_email_or_alias(email)
+ assert_nil User.find_by_email_alias(email)
end
+
+ def assert_invalid_email(string)
+ @user.email = string
+ assert !@user.valid?
+ assert @user.errors.keys.include?(:email)
+ end
+
end