2013-01-19 09:20:13 -05:00
|
|
|
require 'abstract_unit'
|
|
|
|
require 'action_controller/metal/strong_parameters'
|
|
|
|
|
|
|
|
class RaiseOnUnpermittedParamsTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
2013-01-19 12:32:27 -05:00
|
|
|
ActionController::Parameters.action_on_unpermitted_parameters = :raise
|
2013-01-19 09:20:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2013-01-19 12:32:27 -05:00
|
|
|
ActionController::Parameters.action_on_unpermitted_parameters = false
|
2013-01-19 09:20:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "raises on unexpected params" do
|
|
|
|
params = ActionController::Parameters.new({
|
|
|
|
book: { pages: 65 },
|
|
|
|
fishing: "Turnips"
|
|
|
|
})
|
|
|
|
|
2013-01-19 12:32:27 -05:00
|
|
|
assert_raises(ActionController::UnpermittedParameters) do
|
2013-01-19 09:20:13 -05:00
|
|
|
params.permit(book: [:pages])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "raises on unexpected nested params" do
|
|
|
|
params = ActionController::Parameters.new({
|
|
|
|
book: { pages: 65, title: "Green Cats and where to find then." }
|
|
|
|
})
|
|
|
|
|
2013-01-19 12:32:27 -05:00
|
|
|
assert_raises(ActionController::UnpermittedParameters) do
|
2013-01-19 09:20:13 -05:00
|
|
|
params.permit(book: [:pages])
|
|
|
|
end
|
|
|
|
end
|
2013-01-19 12:32:27 -05:00
|
|
|
end
|