Skip to content

Commit

Permalink
Made ensure valid a named param for confirm!, and added a test.
Browse files Browse the repository at this point in the history
  • Loading branch information
timscott committed Nov 19, 2014
1 parent 4ba84ee commit 3b882da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/devise/models/confirmable.rb
Expand Up @@ -56,7 +56,7 @@ def self.required_fields(klass)
# 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,
Expand Down
6 changes: 6 additions & 0 deletions test/models/confirmable_test.rb
Expand Up @@ -315,6 +315,12 @@ def confirm_user_by_token_with_confirmation_sent_at(confirmation_sent_at)
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
Expand Down

0 comments on commit 3b882da

Please sign in to comment.