From 6e8a45145722c12dee4d15b33cc28d2b09881e1a Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 18 Dec 2012 11:46:58 +0100 Subject: adjusted tests - we now reload the user so invalid records are cleared Actually that might not be the best idea. Issue at hand was that invalid email aliases were getting displayed when rendering the edit form again. We probably want to solve this different. --- users/test/functional/users_controller_test.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'users/test') diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb index ce17500..b31a642 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.expects(:reload).returns(user) 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.expects(:reload).returns(user) login :is_admin? => true put :update, :user => user.params, :id => user.id, :format => :json -- cgit v1.2.3 From 285b23f39765d8346a658a81eca8b70d70b3e9bf Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 18 Dec 2012 13:41:41 +0100 Subject: refactored email_alias creation and validation using CouchRests user.email_aliases.build so the casted_by method is set in the alias Used this to move the validations into the alias itself. This is where they belong and allows us to render the errors inline along the email field they belong to. --- users/test/unit/email_aliases_test.rb | 11 ++++++----- users/test/unit/email_test.rb | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'users/test') 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..5aa2b11 100644 --- a/users/test/unit/email_test.rb +++ b/users/test/unit/email_test.rb @@ -20,9 +20,9 @@ class EmailTest < ActiveSupport::TestCase 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 -- cgit v1.2.3 From 5a35873f8a12915d44cfa77239d094960ce6971e Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 18 Dec 2012 14:05:28 +0100 Subject: only destroy user that has been persisted in teardown --- users/test/unit/email_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'users/test') diff --git a/users/test/unit/email_test.rb b/users/test/unit/email_test.rb index 5aa2b11..6f9beaa 100644 --- a/users/test/unit/email_test.rb +++ b/users/test/unit/email_test.rb @@ -14,7 +14,7 @@ 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 -- cgit v1.2.3 From 42a76e82c8c1911f04a71244eea3ac07275367df Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 18 Dec 2012 14:09:25 +0100 Subject: adopted functional tests to new controller design --- users/test/functional/users_controller_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'users/test') diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb index b31a642..1fa1462 100644 --- a/users/test/functional/users_controller_test.rb +++ b/users/test/functional/users_controller_test.rb @@ -50,7 +50,7 @@ class UsersControllerTest < ActionController::TestCase user.expects(:attributes=).with(user.params) user.expects(:changed?).returns(true) user.expects(:save).returns(true) - user.expects(:reload).returns(user) + user.stubs(:email_aliases).returns([]) login user put :update, :user => user.params, :id => user.id, :format => :json @@ -65,7 +65,7 @@ class UsersControllerTest < ActionController::TestCase user.expects(:attributes=).with(user.params) user.expects(:changed?).returns(true) user.expects(:save).returns(true) - user.expects(:reload).returns(user) + user.stubs(:email_aliases).returns([]) login :is_admin? => true put :update, :user => user.params, :id => user.id, :format => :json -- cgit v1.2.3