mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Fix error when params is not a hash
This commit is contained in:
parent
1c8e97c75a
commit
8866b8e5eb
2 changed files with 41 additions and 1 deletions
|
@ -135,7 +135,19 @@ module Devise
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_params
|
def default_params
|
||||||
@params.fetch(@resource_name, {})
|
if hashable_resource_params?
|
||||||
|
@params.fetch(@resource_name)
|
||||||
|
else
|
||||||
|
empty_params
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def hashable_resource_params?
|
||||||
|
@params[@resource_name].respond_to?(:permit)
|
||||||
|
end
|
||||||
|
|
||||||
|
def empty_params
|
||||||
|
ActionController::Parameters.new({})
|
||||||
end
|
end
|
||||||
|
|
||||||
def permit_keys(parameters, keys)
|
def permit_keys(parameters, keys)
|
||||||
|
|
|
@ -16,6 +16,34 @@ class ParameterSanitizerTest < ActiveSupport::TestCase
|
||||||
assert_equal({ 'email' => 'jose' }, sanitized)
|
assert_equal({ 'email' => 'jose' }, sanitized)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'permits empty params when received not a hash' do
|
||||||
|
sanitizer = sanitizer({ 'user' => 'string' })
|
||||||
|
sanitized = sanitizer.sanitize(:sign_in)
|
||||||
|
|
||||||
|
assert_equal({}, sanitized)
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'does not rise error when received string instead of hash' do
|
||||||
|
sanitizer = sanitizer('user' => 'string')
|
||||||
|
assert_nothing_raised do
|
||||||
|
sanitizer.sanitize(:sign_in)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'does not rise error when received nil instead of hash' do
|
||||||
|
sanitizer = sanitizer('user' => nil)
|
||||||
|
assert_nothing_raised do
|
||||||
|
sanitizer.sanitize(:sign_in)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test 'permits empty params when received nil instead of hash' do
|
||||||
|
sanitizer = sanitizer({ 'user' => nil })
|
||||||
|
sanitized = sanitizer.sanitize(:sign_in)
|
||||||
|
|
||||||
|
assert_equal({}, sanitized)
|
||||||
|
end
|
||||||
|
|
||||||
test 'permits the default parameters for sign up' do
|
test 'permits the default parameters for sign up' do
|
||||||
sanitizer = sanitizer('user' => { 'email' => 'jose', 'role' => 'invalid' })
|
sanitizer = sanitizer('user' => { 'email' => 'jose', 'role' => 'invalid' })
|
||||||
sanitized = sanitizer.sanitize(:sign_up)
|
sanitized = sanitizer.sanitize(:sign_up)
|
||||||
|
|
Loading…
Reference in a new issue