mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Fix the build on Rails 3.2
This commit is contained in:
parent
bc0cab8d60
commit
efe34219a9
2 changed files with 13 additions and 10 deletions
|
@ -20,16 +20,18 @@ module Devise
|
|||
def sanitize(kind)
|
||||
if block = @blocks[kind]
|
||||
block.call(default_params)
|
||||
elsif respond_to?(kind, true)
|
||||
send(kind)
|
||||
else
|
||||
raise NotImplementedError, "Devise doesn't know how to sanitize parameters for #{kind}"
|
||||
default_sanitize(kind)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def default_for(kind)
|
||||
raise ArgumentError, "a block is expected in Devise base sanitizer"
|
||||
end
|
||||
|
||||
def default_sanitize(kind)
|
||||
default_params
|
||||
end
|
||||
|
||||
|
@ -64,6 +66,14 @@ module Devise
|
|||
@permitted[kind] || raise("No sanitizer provided for #{kind}")
|
||||
end
|
||||
|
||||
def default_sanitize(kind)
|
||||
if respond_to?(kind, true)
|
||||
send(kind)
|
||||
else
|
||||
raise NotImplementedError, "Devise doesn't know how to sanitize parameters for #{kind}"
|
||||
end
|
||||
end
|
||||
|
||||
def attributes_for(kind)
|
||||
case kind
|
||||
when :sign_in
|
||||
|
|
|
@ -3,18 +3,11 @@ require 'devise/parameter_sanitizer'
|
|||
|
||||
class BaseSanitizerTest < ActiveSupport::TestCase
|
||||
def sanitizer(params)
|
||||
params = ActionController::Parameters.new(params)
|
||||
Devise::BaseSanitizer.new(User, :user, params)
|
||||
end
|
||||
|
||||
test 'returns chosen params' do
|
||||
sanitizer = sanitizer(user: { "email" => "jose" })
|
||||
assert_equal({ "email" => "jose" }, sanitizer.for(:sign_in))
|
||||
end
|
||||
|
||||
test 'allow custom blocks' do
|
||||
sanitizer = sanitizer(user: { "email" => "jose", "password" => "invalid" })
|
||||
sanitizer.for(:sign_in) { |user| user.permit(:email) }
|
||||
assert_equal({ "email" => "jose" }, sanitizer.sanitize(:sign_in))
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue