1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Checking required fields on lockable

This commit is contained in:
Rodrigo Flores 2012-03-13 15:50:13 -03:00
parent 033e91b7b9
commit a7658f9d75
2 changed files with 39 additions and 8 deletions

View file

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

View file

@ -236,7 +236,9 @@ 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
swap Devise, :unlock_strategy => :both do
swap Devise, :lock_strategy => :failed_attempts do
assert_same_content Devise::Models::Lockable.required_fields(User), [ assert_same_content Devise::Models::Lockable.required_fields(User), [
:failed_attempts, :failed_attempts,
:unlock_at, :unlock_at,
@ -244,3 +246,27 @@ class LockableTest < ActiveSupport::TestCase
] ]
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