mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
lock_access! without sending email
This commit is contained in:
parent
01e029fd9b
commit
be236fa6dd
2 changed files with 23 additions and 2 deletions
|
@ -34,10 +34,13 @@ module Devise
|
|||
end
|
||||
|
||||
# Lock a user setting its locked_at to actual time.
|
||||
def lock_access!
|
||||
# * +opts+: Hash options if you don't want to send email
|
||||
# when you lock access, you could pass the next hash
|
||||
# `{ :send_instructions => false } as option`.
|
||||
def lock_access!(opts = { })
|
||||
self.locked_at = Time.now.utc
|
||||
|
||||
if unlock_strategy_enabled?(:email)
|
||||
if unlock_strategy_enabled?(:email) && opts.fetch(:send_instructions, true)
|
||||
send_unlock_instructions
|
||||
else
|
||||
save(:validate => false)
|
||||
|
|
|
@ -130,6 +130,24 @@ class LockableTest < ActiveSupport::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test "doesn't send email when you pass option send_instructions to false" do
|
||||
swap Devise, :unlock_strategy => :email do
|
||||
user = create_user
|
||||
assert_email_not_sent do
|
||||
user.lock_access! send_instructions: false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "sends email when you pass options other than send_instructions" do
|
||||
swap Devise, :unlock_strategy => :email do
|
||||
user = create_user
|
||||
assert_email_sent do
|
||||
user.lock_access! foo: :bar, bar: :foo
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "should not send email with unlock instructions when :email is not an unlock strategy" do
|
||||
swap Devise, :unlock_strategy => :time do
|
||||
user = create_user
|
||||
|
|
Loading…
Add table
Reference in a new issue