make User#send_unlock_instructions to require all authentication_keys

Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
RStankov 2010-07-25 20:56:00 +03:00 committed by José Valim
parent b2066cc229
commit fb86f772e7
2 changed files with 19 additions and 2 deletions

View File

@ -132,7 +132,7 @@ module Devise
# with an email not found error.
# Options must contain the user email
def send_unlock_instructions(attributes={})
lockable = find_or_initialize_with_error_by(:email, attributes[:email], :not_found)
lockable = find_or_initialize_with_errors(authentication_keys, attributes, :not_found)
lockable.resend_unlock_token if lockable.persisted?
lockable
end

View File

@ -175,7 +175,24 @@ class LockableTest < ActiveSupport::TestCase
test 'should add error to new user email if no email was found' do
unlock_user = User.send_unlock_instructions(:email => "invalid@email.com")
assert_equal 'not found', unlock_user.errors[:email].join
assert_equal 'not found', unlock_user.errors[:base].join
end
test 'should find a user to send unlock instructions by authentication_keys' do
swap Devise, :authentication_keys => [:username, :email] do
user = create_user
unlock_user = User.send_unlock_instructions(:email => user.email, :username => user.username)
assert_equal unlock_user, user
end
end
test 'should require all authentication_keys' do
swap Devise, :authentication_keys => [:username, :email] do
user = create_user
unlock_user = User.send_unlock_instructions(:email => user.email)
assert_not unlock_user.persisted?
assert_equal "can't be blank", unlock_user.errors[:username].join
end
end
test 'should not be able to send instructions if the user is not locked' do