mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Simple Sungularize ActionController::UnpermittedParameters error in case when only 1 parameter is unpermitted.
This commit is contained in:
parent
174c9f0df3
commit
88cfeca16a
3 changed files with 28 additions and 6 deletions
|
@ -50,7 +50,7 @@ module ActionController
|
|||
|
||||
def unpermitted_parameters(event)
|
||||
unpermitted_keys = event.payload[:keys]
|
||||
debug("Unpermitted parameters: #{unpermitted_keys.join(", ")}")
|
||||
debug("Unpermitted parameter#{'s' if unpermitted_keys.size > 1}: #{unpermitted_keys.join(", ")}")
|
||||
end
|
||||
|
||||
def deep_munge(event)
|
||||
|
|
|
@ -32,7 +32,7 @@ module ActionController
|
|||
|
||||
def initialize(params) # :nodoc:
|
||||
@params = params
|
||||
super("found unpermitted parameters: #{params.join(", ")}")
|
||||
super("found unpermitted parameter#{'s' if params.size > 1 }: #{params.join(", ")}")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -10,23 +10,45 @@ class LogOnUnpermittedParamsTest < ActiveSupport::TestCase
|
|||
ActionController::Parameters.action_on_unpermitted_parameters = false
|
||||
end
|
||||
|
||||
test "logs on unexpected params" do
|
||||
test "logs on unexpected param" do
|
||||
params = ActionController::Parameters.new({
|
||||
book: { pages: 65 },
|
||||
fishing: "Turnips"
|
||||
})
|
||||
|
||||
assert_logged("Unpermitted parameters: fishing") do
|
||||
assert_logged("Unpermitted parameter: fishing") do
|
||||
params.permit(book: [:pages])
|
||||
end
|
||||
end
|
||||
|
||||
test "logs on unexpected params" do
|
||||
params = ActionController::Parameters.new({
|
||||
book: { pages: 65 },
|
||||
fishing: "Turnips",
|
||||
car: "Mersedes"
|
||||
})
|
||||
|
||||
assert_logged("Unpermitted parameters: fishing, car") do
|
||||
params.permit(book: [:pages])
|
||||
end
|
||||
end
|
||||
|
||||
test "logs on unexpected nested param" do
|
||||
params = ActionController::Parameters.new({
|
||||
book: { pages: 65, title: "Green Cats and where to find then." }
|
||||
})
|
||||
|
||||
assert_logged("Unpermitted parameter: title") do
|
||||
params.permit(book: [:pages])
|
||||
end
|
||||
end
|
||||
|
||||
test "logs on unexpected nested params" do
|
||||
params = ActionController::Parameters.new({
|
||||
book: { pages: 65, title: "Green Cats and where to find then." }
|
||||
book: { pages: 65, title: "Green Cats and where to find then.", author: "G. A. Dog" }
|
||||
})
|
||||
|
||||
assert_logged("Unpermitted parameters: title") do
|
||||
assert_logged("Unpermitted parameters: title, author") do
|
||||
params.permit(book: [:pages])
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue