Add #skip_confirmation_notification to Confirmable
This commit is contained in:
parent
22897150d8
commit
72cfaad618
|
@ -34,7 +34,7 @@ module Devise
|
||||||
|
|
||||||
included do
|
included do
|
||||||
before_create :generate_confirmation_token, :if => :confirmation_required?
|
before_create :generate_confirmation_token, :if => :confirmation_required?
|
||||||
after_create :send_on_create_confirmation_instructions, :if => :confirmation_required?
|
after_create :send_on_create_confirmation_instructions, :if => :send_confirmation_notification?
|
||||||
before_update :postpone_email_change_until_confirmation, :if => :postpone_email_change?
|
before_update :postpone_email_change_until_confirmation, :if => :postpone_email_change?
|
||||||
after_update :send_confirmation_instructions, :if => :reconfirmation_required?
|
after_update :send_confirmation_instructions, :if => :reconfirmation_required?
|
||||||
end
|
end
|
||||||
|
@ -119,6 +119,12 @@ module Devise
|
||||||
self.confirmed_at = Time.now.utc
|
self.confirmed_at = Time.now.utc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Skips sending the confirmation notification email after_create. Unlike
|
||||||
|
# #skip_confirmation!, record still requires confirmation.
|
||||||
|
def skip_confirmation_notification!
|
||||||
|
@skip_confirmation_notification = true
|
||||||
|
end
|
||||||
|
|
||||||
# If you don't want reconfirmation to be sent, neither a code
|
# If you don't want reconfirmation to be sent, neither a code
|
||||||
# to be generated, call skip_reconfirmation!
|
# to be generated, call skip_reconfirmation!
|
||||||
def skip_reconfirmation!
|
def skip_reconfirmation!
|
||||||
|
@ -223,6 +229,10 @@ module Devise
|
||||||
self.class.reconfirmable && @reconfirmation_required
|
self.class.reconfirmable && @reconfirmation_required
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def send_confirmation_notification?
|
||||||
|
confirmation_required? && !@skip_confirmation_notification
|
||||||
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
# Attempt to find a user by its email. If a record is found, send new
|
# Attempt to find a user by its email. If a record is found, send new
|
||||||
# confirmation instructions to it. If not, try searching for a user by unconfirmed_email
|
# confirmation instructions to it. If not, try searching for a user by unconfirmed_email
|
||||||
|
|
|
@ -104,6 +104,16 @@ class ConfirmableTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'should skip confirmation e-mail without confirming if skip_confirmation_notification! is invoked' do
|
||||||
|
user = new_user
|
||||||
|
user.skip_confirmation_notification!
|
||||||
|
|
||||||
|
assert_email_not_sent do
|
||||||
|
user.save!
|
||||||
|
assert !user.confirmed?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
test 'should find a user to send confirmation instructions' do
|
test 'should find a user to send confirmation instructions' do
|
||||||
user = create_user
|
user = create_user
|
||||||
confirmation_user = User.send_confirmation_instructions(:email => user.email)
|
confirmation_user = User.send_confirmation_instructions(:email => user.email)
|
||||||
|
|
Loading…
Reference in New Issue