diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-05-18 09:27:48 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2013-05-18 09:27:48 +0000 |
commit | 61dfab12fd72aa3546746a8354476a9572e0bf23 (patch) | |
tree | 34144ee44e11a58c360a00f07dd32e36846c6d95 /test/unit/user_test.rb | |
parent | 474c01074638e46c505dc826c0d631980093f145 (diff) | |
download | redmine-61dfab12fd72aa3546746a8354476a9572e0bf23.tar.gz redmine-61dfab12fd72aa3546746a8354476a9572e0bf23.zip |
Removed some shoulda context.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11865 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'test/unit/user_test.rb')
-rw-r--r-- | test/unit/user_test.rb | 149 |
1 files changed, 67 insertions, 82 deletions
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index 230e5b140..5c6400298 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -404,25 +404,22 @@ class UserTest < ActiveSupport::TestCase assert_not_nil u.errors[:mail_notification] end - context "User#try_to_login" do - should "fall-back to case-insensitive if user login is not found as-typed." do - user = User.try_to_login("AdMin", "admin") - assert_kind_of User, user - assert_equal "admin", user.login - end - - should "select the exact matching user first" do - case_sensitive_user = User.generate! do |user| - user.password = "admin123" - end - # bypass validations to make it appear like existing data - case_sensitive_user.update_attribute(:login, 'ADMIN') - - user = User.try_to_login("ADMIN", "admin123") - assert_kind_of User, user - assert_equal "ADMIN", user.login + test "User#try_to_login should fall-back to case-insensitive if user login is not found as-typed" do + user = User.try_to_login("AdMin", "admin") + assert_kind_of User, user + assert_equal "admin", user.login + end + test "User#try_to_login should select the exact matching user first" do + case_sensitive_user = User.generate! do |user| + user.password = "admin123" end + # bypass validations to make it appear like existing data + case_sensitive_user.update_attribute(:login, 'ADMIN') + + user = User.try_to_login("ADMIN", "admin123") + assert_kind_of User, user + assert_equal "ADMIN", user.login end def test_password @@ -527,20 +524,14 @@ class UserTest < ActiveSupport::TestCase assert_equal nil, user end - context ".try_to_login" do - context "with good credentials" do - should "return the user" do - user = User.try_to_login("admin", "admin") - assert_kind_of User, user - assert_equal "admin", user.login - end - end + test ".try_to_login with good credentials should return the user" do + user = User.try_to_login("admin", "admin") + assert_kind_of User, user + assert_equal "admin", user.login + end - context "with wrong credentials" do - should "return nil" do - assert_nil User.try_to_login("admin", "foo") - end - end + test ".try_to_login with wrong credentials should return nil" do + assert_nil User.try_to_login("admin", "foo") end if ldap_configured? @@ -684,50 +675,46 @@ class UserTest < ActiveSupport::TestCase end end - context "User#api_key" do - should "generate a new one if the user doesn't have one" do - user = User.generate!(:api_token => nil) - assert_nil user.api_token + test "#api_key should generate a new one if the user doesn't have one" do + user = User.generate!(:api_token => nil) + assert_nil user.api_token - key = user.api_key - assert_equal 40, key.length - user.reload - assert_equal key, user.api_key - end + key = user.api_key + assert_equal 40, key.length + user.reload + assert_equal key, user.api_key + end - should "return the existing api token value" do - user = User.generate! - token = Token.create!(:action => 'api') - user.api_token = token - assert user.save + test "#api_key should return the existing api token value" do + user = User.generate! + token = Token.create!(:action => 'api') + user.api_token = token + assert user.save - assert_equal token.value, user.api_key - end + assert_equal token.value, user.api_key end - context "User#find_by_api_key" do - should "return nil if no matching key is found" do - assert_nil User.find_by_api_key('zzzzzzzzz') - end + test "#find_by_api_key should return nil if no matching key is found" do + assert_nil User.find_by_api_key('zzzzzzzzz') + end - should "return nil if the key is found for an inactive user" do - user = User.generate! - user.status = User::STATUS_LOCKED - token = Token.create!(:action => 'api') - user.api_token = token - user.save + test "#find_by_api_key should return nil if the key is found for an inactive user" do + user = User.generate! + user.status = User::STATUS_LOCKED + token = Token.create!(:action => 'api') + user.api_token = token + user.save - assert_nil User.find_by_api_key(token.value) - end + assert_nil User.find_by_api_key(token.value) + end - should "return the user if the key is found for an active user" do - user = User.generate! - token = Token.create!(:action => 'api') - user.api_token = token - user.save + test "#find_by_api_key should return the user if the key is found for an active user" do + user = User.generate! + token = Token.create!(:action => 'api') + user.api_token = token + user.save - assert_equal user, User.find_by_api_key(token.value) - end + assert_equal user, User.find_by_api_key(token.value) end def test_default_admin_account_changed_should_return_false_if_account_was_not_changed @@ -880,29 +867,27 @@ class UserTest < ActiveSupport::TestCase assert !u.password_confirmation.blank? end - context "#change_password_allowed?" do - should "be allowed if no auth source is set" do - user = User.generate! - assert user.change_password_allowed? - end + test "#change_password_allowed? should be allowed if no auth source is set" do + user = User.generate! + assert user.change_password_allowed? + end - should "delegate to the auth source" do - user = User.generate! + test "#change_password_allowed? should delegate to the auth source" do + user = User.generate! - allowed_auth_source = AuthSource.generate! - def allowed_auth_source.allow_password_changes?; true; end + allowed_auth_source = AuthSource.generate! + def allowed_auth_source.allow_password_changes?; true; end - denied_auth_source = AuthSource.generate! - def denied_auth_source.allow_password_changes?; false; end + denied_auth_source = AuthSource.generate! + def denied_auth_source.allow_password_changes?; false; end - assert user.change_password_allowed? + assert user.change_password_allowed? - user.auth_source = allowed_auth_source - assert user.change_password_allowed?, "User not allowed to change password, though auth source does" + user.auth_source = allowed_auth_source + assert user.change_password_allowed?, "User not allowed to change password, though auth source does" - user.auth_source = denied_auth_source - assert !user.change_password_allowed?, "User allowed to change password, though auth source does not" - end + user.auth_source = denied_auth_source + assert !user.change_password_allowed?, "User allowed to change password, though auth source does not" end def test_own_account_deletable_should_be_true_with_unsubscrive_enabled |