Made ensure valid a named param for confirm!, and added a test.
This commit is contained in:
parent
4ba84eeb27
commit
3b882dadac
|
@ -56,7 +56,7 @@ module Devise
|
||||||
# Confirm a user by setting it's confirmed_at to actual time. If the user
|
# 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
|
# is already confirmed, add an error to email field. If the user is invalid
|
||||||
# add errors
|
# add errors
|
||||||
def confirm!(ensure_valid=false)
|
def confirm!(ensure_valid: false)
|
||||||
pending_any_confirmation do
|
pending_any_confirmation do
|
||||||
if confirmation_period_expired?
|
if confirmation_period_expired?
|
||||||
self.errors.add(:email, :confirmation_period_expired,
|
self.errors.add(:email, :confirmation_period_expired,
|
||||||
|
|
|
@ -315,6 +315,12 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||||
assert_not user.confirm!
|
assert_not user.confirm!
|
||||||
assert_equal user.username, old
|
assert_equal user.username, old
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
class ReconfirmableTest < ActiveSupport::TestCase
|
class ReconfirmableTest < ActiveSupport::TestCase
|
||||||
|
|
Loading…
Reference in New Issue