diff options
author | azul <azul@riseup.net> | 2012-12-20 01:53:32 -0800 |
---|---|---|
committer | azul <azul@riseup.net> | 2012-12-20 01:53:32 -0800 |
commit | 69a6c34998328b2168053184e1e487b60e1cc536 (patch) | |
tree | 361b0be19535b0d7ddb3eaac7acdfcebc7a0e3a8 /users/test | |
parent | e899e5c3f33acb3228fac295013d7cc8b6e4eb04 (diff) | |
parent | dc827d0a80360aa245d4d724dc42bc47571faea6 (diff) |
Merge pull request #5 from leapcode/feature/removing-email-aliases
Removing email aliases - proper error display
Diffstat (limited to 'users/test')
-rw-r--r-- | users/test/functional/users_controller_test.rb | 4 | ||||
-rw-r--r-- | users/test/unit/email_aliases_test.rb | 11 | ||||
-rw-r--r-- | users/test/unit/email_test.rb | 8 |
3 files changed, 13 insertions, 10 deletions
diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb index ce17500..1fa1462 100644 --- a/users/test/functional/users_controller_test.rb +++ b/users/test/functional/users_controller_test.rb @@ -45,11 +45,12 @@ class UsersControllerTest < ActionController::TestCase assert_equal user, assigns[:user] end - test "should process updated params" do + test "user can change settings" do user = find_record User user.expects(:attributes=).with(user.params) user.expects(:changed?).returns(true) user.expects(:save).returns(true) + user.stubs(:email_aliases).returns([]) login user put :update, :user => user.params, :id => user.id, :format => :json @@ -64,6 +65,7 @@ class UsersControllerTest < ActionController::TestCase user.expects(:attributes=).with(user.params) user.expects(:changed?).returns(true) user.expects(:save).returns(true) + user.stubs(:email_aliases).returns([]) login :is_admin? => true put :update, :user => user.params, :id => user.id, :format => :json diff --git a/users/test/unit/email_aliases_test.rb b/users/test/unit/email_aliases_test.rb index 762aaea..f680ac6 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_alias(email_alias) + @user.email_aliases.build :email => email_alias assert @user.changed? assert @user.save assert_equal email_alias, @user.reload.email_aliases.first.to_s @@ -30,10 +30,11 @@ class EmailAliasTest < ActiveSupport::TestCase test "duplicated email aliases are invalid" do email_alias = "valid_alias@domain.net" - @user.add_email_alias(email_alias) + @user.email_aliases.build :email => email_alias @user.save # add again - @user.add_email_alias(email_alias) + email_alias = @user.email_aliases.build :email => email_alias + assert !email_alias.valid? assert @user.changed? assert !@user.valid? end @@ -41,14 +42,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_alias(email_alias) + @user.email_aliases.build :email => 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) + @user.email_aliases.build :email => 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 1e216d6..6f9beaa 100644 --- a/users/test/unit/email_test.rb +++ b/users/test/unit/email_test.rb @@ -14,15 +14,15 @@ class EmailTest < ActiveSupport::TestCase teardown do @user.destroy if @user.persisted? # just in case - @other_user.destroy + @other_user.destroy if @other_user.persisted? end test "email aliases need to be unique" do email_alias = "valid_alias@domain.net" - @other_user.add_email_alias email_alias + @other_user.email_aliases.build :email => email_alias @other_user.save - @user.add_email_alias email_alias + @user.email_aliases.build :email => 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.add_email_alias email_alias + @user.email_aliases.build :email => email_alias assert @user.changed? assert !@user.save end |