1
0
Fork 0
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:
Serj L 2014-02-24 13:25:38 +04:00
parent 174c9f0df3
commit 88cfeca16a
3 changed files with 28 additions and 6 deletions

View file

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

View file

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

View file

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