Send confirmation instructions only works if the record is not confirmed.

This commit is contained in:
Carlos A. da Silva 2009-10-15 16:54:04 -03:00
parent 417f273a81
commit e8611609ac
3 changed files with 15 additions and 6 deletions

View File

@ -59,9 +59,11 @@ module Devise
# confirming it's account # confirming it's account
# #
def reset_confirmation! def reset_confirmation!
reset_confirmation unless_confirmed do
reset_perishable_token! reset_confirmation
send_confirmation_instructions reset_perishable_token!
send_confirmation_instructions
end
end end
private private

View File

@ -3,7 +3,7 @@ require 'test/test_helper'
class UsersConfirmationTest < ActionController::IntegrationTest class UsersConfirmationTest < ActionController::IntegrationTest
test 'user should be able to request a new confirmation' do test 'user should be able to request a new confirmation' do
user = create_user user = create_user(:confirm => false)
ActionMailer::Base.deliveries.clear ActionMailer::Base.deliveries.clear
visit new_user_session_path visit new_user_session_path

View File

@ -112,8 +112,6 @@ class ConfirmableTest < ActiveSupport::TestCase
test 'should reset confirmation status when sending the confirmation instructions' do test 'should reset confirmation status when sending the confirmation instructions' do
user = create_user user = create_user
assert_not user.confirmed? assert_not user.confirmed?
user.confirm!
assert user.confirmed?
confirmation_user = User.send_confirmation_instructions(:email => user.email) confirmation_user = User.send_confirmation_instructions(:email => user.email)
assert_not user.reload.confirmed? assert_not user.reload.confirmed?
end end
@ -150,4 +148,13 @@ class ConfirmableTest < ActiveSupport::TestCase
user.save! user.save!
assert_not user.reload.confirmed? assert_not user.reload.confirmed?
end end
test 'should not be able to send instructions if the user is already confirmed' do
user = create_user
user.confirm!
assert_not user.reset_confirmation!
assert user.confirmed?
assert user.errors[:email].present?
assert_equal 'already confirmed', user.errors[:email]
end
end end