mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Refactoring confirmable to use hash options instead of parameters as recoverable does.
This commit is contained in:
parent
97ae1795bd
commit
98fa7bf336
2 changed files with 7 additions and 6 deletions
|
@ -50,9 +50,10 @@ module Devise
|
|||
# Find a user by it's confirmation token and try to confirm it.
|
||||
# If no user is found, returns a new user
|
||||
# If the user is already confirmed, create an error for the user
|
||||
# Options must have the perishable_token
|
||||
#
|
||||
def find_and_confirm(perishable_token)
|
||||
confirmable = find_or_initialize_with_error_by_perishable_token(perishable_token)
|
||||
def confirm!(options={})
|
||||
confirmable = find_or_initialize_with_error_by_perishable_token(options[:perishable_token])
|
||||
confirmable.confirm! unless confirmable.new_record?
|
||||
confirmable
|
||||
end
|
||||
|
|
|
@ -36,19 +36,19 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|||
|
||||
test 'should find and confirm an user automatically' do
|
||||
user = create_user
|
||||
confirmed_user = User.find_and_confirm(user.perishable_token)
|
||||
confirmed_user = User.confirm!(:perishable_token => user.perishable_token)
|
||||
assert_not_nil confirmed_user
|
||||
assert_equal confirmed_user, user
|
||||
assert user.reload.confirmed?
|
||||
end
|
||||
|
||||
test 'should return a new user with errors if no user exists while trying to confirm' do
|
||||
confirmed_user = User.find_and_confirm('invalid_perishable_token')
|
||||
confirmed_user = User.confirm!(:perishable_token => 'invalid_perishable_token')
|
||||
assert confirmed_user.new_record?
|
||||
end
|
||||
|
||||
test 'should return errors for a new user when trying to confirm' do
|
||||
confirmed_user = User.find_and_confirm('invalid_perishable_token')
|
||||
confirmed_user = User.confirm!(:perishable_token => 'invalid_perishable_token')
|
||||
assert_not_nil confirmed_user.errors[:perishable_token]
|
||||
assert_equal "invalid confirmation", confirmed_user.errors[:perishable_token]
|
||||
end
|
||||
|
@ -56,7 +56,7 @@ class ConfirmableTest < ActiveSupport::TestCase
|
|||
test 'should generate errors for a user email if user is already confirmed' do
|
||||
user = create_user
|
||||
user.confirm!
|
||||
confirmed_user = User.find_and_confirm(user.perishable_token)
|
||||
confirmed_user = User.confirm!(:perishable_token => user.perishable_token)
|
||||
assert confirmed_user.confirmed?
|
||||
assert confirmed_user.errors[:email]
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue