Removed some shoulda context.

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11865 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang
2013-05-18 09:27:48 +00:00
parent 474c010746
commit 61dfab12fd
5 changed files with 143 additions and 172 deletions
+69 -84
View File
@@ -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
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')
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
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
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
key = user.api_key
assert_equal 40, key.length
user.reload
assert_equal key, 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 "#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
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_equal token.value, user.api_key
end
assert_nil User.find_by_api_key(token.value)
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 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 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_equal user, User.find_by_api_key(token.value)
end
assert_nil User.find_by_api_key(token.value)
end
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
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