diff options
Diffstat (limited to 'users/test/unit')
-rw-r--r-- | users/test/unit/email_aliases_test.rb | 30 | ||||
-rw-r--r-- | users/test/unit/email_test.rb | 61 | ||||
-rw-r--r-- | users/test/unit/user_test.rb | 14 |
3 files changed, 29 insertions, 76 deletions
diff --git a/users/test/unit/email_aliases_test.rb b/users/test/unit/email_aliases_test.rb index e3f060d..86d14aa 100644 --- a/users/test/unit/email_aliases_test.rb +++ b/users/test/unit/email_aliases_test.rb @@ -4,9 +4,9 @@ class EmailAliasTest < ActiveSupport::TestCase setup do @user = FactoryGirl.build :user - @other_user = FactoryGirl.build :user - @alias = "valid_alias@#{APP_CONFIG[:domain]}" - User.find_by_email_or_alias(@alias).try(:destroy) + @alias = "valid_alias" + # make sure no existing records are in the way... + User.find_by_login_or_alias(@alias).try(:destroy) end test "no email aliases set in the beginning" do @@ -17,13 +17,13 @@ class EmailAliasTest < ActiveSupport::TestCase @user.attributes = {:email_aliases_attributes => {"0" => {:email => @alias}}} assert @user.changed? assert @user.save - assert_equal @alias, @user.email_aliases.first.to_s + assert_equal @alias, @user.email_aliases.first.username end test "adding email alias directly" do @user.email_aliases.build :email => @alias assert @user.save - assert_equal @alias, @user.reload.email_aliases.first.to_s + assert_equal @alias, @user.email_aliases.first.username end test "duplicated email aliases are invalid" do @@ -32,29 +32,29 @@ class EmailAliasTest < ActiveSupport::TestCase assert_invalid_alias @alias end - test "email alias needs to be different from other peoples email" do - @other_user.email = @alias - @other_user.save + test "email alias needs to be different from other peoples login" do + other_user = FactoryGirl.create :user, :login => @alias assert_invalid_alias @alias + other_user.destroy end test "email needs to be different from other peoples email aliases" do - @other_user.email_aliases.build :email => @alias - @other_user.save + other_user = FactoryGirl.create :user, :email_aliases_attributes => {'1' => @alias} assert_invalid_alias @alias + other_user.destroy end - test "email is invalid as email alias" do - @user.email = @alias + test "login is invalid as email alias" do + @user.login = @alias assert_invalid_alias @alias end test "find user by email alias" do @user.email_aliases.build :email => @alias assert @user.save - 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) + assert_equal @user, User.find_by_login_or_alias(@alias) + assert_equal @user, User.find_by_alias(@alias) + assert_nil User.find_by_login(@alias) end def assert_invalid_alias(string) diff --git a/users/test/unit/email_test.rb b/users/test/unit/email_test.rb deleted file mode 100644 index d7ef1f8..0000000 --- a/users/test/unit/email_test.rb +++ /dev/null @@ -1,61 +0,0 @@ -require 'test_helper' - -class EmailTest < ActiveSupport::TestCase - - setup do - @user = FactoryGirl.build :user - @other_user = FactoryGirl.build :user - @email_string = "valid_alias@#{APP_CONFIG[:domain]}" - User.find_by_email_or_alias(@email_string).try(:destroy) - end - - teardown do - @user.destroy if @user.persisted? # just in case - @other_user.destroy if @other_user.persisted? - end - - test "email needs to be different from other peoples email" do - @other_user.email = @email_string - @other_user.save - assert_invalid_email @email_string - end - - test "email needs to be different from other peoples email aliases" do - @other_user.email_aliases.build :email => @email_string - @other_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 diff --git a/users/test/unit/user_test.rb b/users/test/unit/user_test.rb index 917728b..66563a3 100644 --- a/users/test/unit/user_test.rb +++ b/users/test/unit/user_test.rb @@ -57,4 +57,18 @@ class UserTest < ActiveSupport::TestCase assert @user.is_admin? end + test "login needs to be unique" do + other_user = FactoryGirl.create :user, login: @user.login + assert !@user.valid? + other_user.destroy + end + + test "login needs to be different from other peoples email aliases" do + other_user = FactoryGirl.create :user + other_user.email_aliases.build :email => @user.login + other_user.save + assert !@user.valid? + other_user.destroy + end + end |