Checking required fields on lockable
This commit is contained in:
parent
033e91b7b9
commit
a7658f9d75
|
@ -23,7 +23,12 @@ module Devise
|
||||||
delegate :lock_strategy_enabled?, :unlock_strategy_enabled?, :to => "self.class"
|
delegate :lock_strategy_enabled?, :unlock_strategy_enabled?, :to => "self.class"
|
||||||
|
|
||||||
def self.required_fields(klass)
|
def self.required_fields(klass)
|
||||||
[:failed_attempts, :unlock_at, :unlock_token]
|
attributes = []
|
||||||
|
attributes << :failed_attempts if klass.lock_strategy_enabled?(:failed_attempts)
|
||||||
|
attributes << :unlock_at if klass.unlock_strategy_enabled?(:time)
|
||||||
|
attributes << :unlock_token if klass.unlock_strategy_enabled?(:email)
|
||||||
|
|
||||||
|
attributes
|
||||||
end
|
end
|
||||||
|
|
||||||
# Lock a user setting its locked_at to actual time.
|
# Lock a user setting its locked_at to actual time.
|
||||||
|
|
|
@ -236,11 +236,37 @@ class LockableTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'required_fields should contain the fields that Devise uses' do
|
test 'required_fields should contain the all the fields when all the strategies are enabled' do
|
||||||
assert_same_content Devise::Models::Lockable.required_fields(User), [
|
swap Devise, :unlock_strategy => :both do
|
||||||
:failed_attempts,
|
swap Devise, :lock_strategy => :failed_attempts do
|
||||||
:unlock_at,
|
assert_same_content Devise::Models::Lockable.required_fields(User), [
|
||||||
:unlock_token
|
:failed_attempts,
|
||||||
]
|
:unlock_at,
|
||||||
|
:unlock_token
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
test 'required_fields should contain only failed_attempts and unlock_at when the strategies are time and failed_attempts are enabled' do
|
||||||
|
swap Devise, :unlock_strategy => :time do
|
||||||
|
swap Devise, :lock_strategy => :failed_attempts do
|
||||||
|
assert_same_content Devise::Models::Lockable.required_fields(User), [
|
||||||
|
:failed_attempts,
|
||||||
|
:unlock_at
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'required_fields should contain only failed_attempts and unlock_token when the strategies are token and failed_attempts are enabled' do
|
||||||
|
swap Devise, :unlock_strategy => :email do
|
||||||
|
swap Devise, :lock_strategy => :failed_attempts do
|
||||||
|
assert_same_content Devise::Models::Lockable.required_fields(User), [
|
||||||
|
:failed_attempts,
|
||||||
|
:unlock_token
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue