mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Move param filtering to its own object and make all finder methods pass through it, closes #1413.
This commit is contained in:
parent
ab54e1f66a
commit
dc8aa9ef83
5 changed files with 65 additions and 39 deletions
|
|
@ -22,26 +22,9 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
|||
assert_equal email.strip, user.email
|
||||
end
|
||||
|
||||
test 'find_for_authentication and filter_auth_params should not modify the conditions hash' do
|
||||
FilterAuthUser = Class.new(User) do
|
||||
def self.filter_auth_params(conditions)
|
||||
if conditions.is_a?(Hash) && login = conditions.delete('login')
|
||||
key = login.include?('@') ? :email : :username
|
||||
conditions[key] = login
|
||||
end
|
||||
super(conditions)
|
||||
end
|
||||
end
|
||||
|
||||
conditions = { 'login' => 'foo@bar.com' }
|
||||
FilterAuthUser.find_for_authentication(conditions)
|
||||
|
||||
assert_equal({ 'login' => 'foo@bar.com' }, conditions)
|
||||
end
|
||||
|
||||
test "filter_auth_params should not convert booleans and integer to strings" do
|
||||
test "param filter should not convert booleans and integer to strings" do
|
||||
conditions = { 'login' => 'foo@bar.com', "bool1" => true, "bool2" => false, "fixnum" => 123, "will_be_converted" => (1..10) }
|
||||
conditions = User.__send__(:filter_auth_params, conditions)
|
||||
conditions = Devise::ParamFilter.new([], []).filter(conditions)
|
||||
assert_equal( { 'login' => 'foo@bar.com', "bool1" => true, "bool2" => false, "fixnum" => 123, "will_be_converted" => "1..10" }, conditions)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue