lock_access! without sending email

This commit is contained in:
Moises Vargas M 2013-12-23 19:46:15 -05:00
parent 01e029fd9b
commit be236fa6dd
2 changed files with 23 additions and 2 deletions

View File

@ -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)

View File

@ -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