Made ensure valid a named param for confirm!, and added a test.

This commit is contained in:
Tim Scott 2014-11-19 16:48:35 -06:00
parent 4ba84eeb27
commit 3b882dadac
2 changed files with 7 additions and 1 deletions

View File

@ -56,7 +56,7 @@ module Devise
# Confirm a user by setting it's confirmed_at to actual time. If the user
# is already confirmed, add an error to email field. If the user is invalid
# add errors
def confirm!(ensure_valid=false)
def confirm!(ensure_valid: false)
pending_any_confirmation do
if confirmation_period_expired?
self.errors.add(:email, :confirmation_period_expired,

View File

@ -315,6 +315,12 @@ class ConfirmableTest < ActiveSupport::TestCase
assert_not user.confirm!
assert_equal user.username, old
end
test 'should always perform validations upon confirm when ensure valid true' do
admin = create_admin
admin.stubs(:valid?).returns(false)
assert_not admin.confirm!(ensure_valid: true)
end
end
class ReconfirmableTest < ActiveSupport::TestCase