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
#
def reset_confirmation!
reset_confirmation
reset_perishable_token!
send_confirmation_instructions
unless_confirmed do
reset_confirmation
reset_perishable_token!
send_confirmation_instructions
end
end
private

View File

@ -3,7 +3,7 @@ require 'test/test_helper'
class UsersConfirmationTest < ActionController::IntegrationTest
test 'user should be able to request a new confirmation' do
user = create_user
user = create_user(:confirm => false)
ActionMailer::Base.deliveries.clear
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
user = create_user
assert_not user.confirmed?
user.confirm!
assert user.confirmed?
confirmation_user = User.send_confirmation_instructions(:email => user.email)
assert_not user.reload.confirmed?
end
@ -150,4 +148,13 @@ class ConfirmableTest < ActiveSupport::TestCase
user.save!
assert_not user.reload.confirmed?
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