2016-08-06 12:54:50 -04:00
|
|
|
require "abstract_unit"
|
|
|
|
require "action_controller/metal/strong_parameters"
|
2013-01-19 09:20:13 -05:00
|
|
|
|
|
|
|
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
|
2016-08-09 17:36:39 -04:00
|
|
|
params = ActionController::Parameters.new(
|
|
|
|
book: { pages: 65 },
|
2016-08-06 13:44:11 -04:00
|
|
|
fishing: "Turnips")
|
2013-01-19 09:20:13 -05:00
|
|
|
|
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
|
2016-08-09 17:36:39 -04:00
|
|
|
params = ActionController::Parameters.new(
|
|
|
|
book: { pages: 65, title: "Green Cats and where to find then." })
|
2013-01-19 09:20:13 -05:00
|
|
|
|
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
|