Skip to content

Commit

Permalink
Add tests for unpermitted param expected behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
martinemde committed Aug 7, 2024
1 parent 30d7df3 commit 2983907
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,40 @@ def teardown
params.permit(book: [:pages])
end
end

test "expect raises on unexpected nested params" do
params = ActionController::Parameters.new(
book: { pages: 65, title: "Green Cats and where to find then." })

assert_raises(ActionController::UnpermittedParameters) do
params.expect(book: [:pages])
end
end

test "expect doesn't raise on unpermitted root params" do
params = ActionController::Parameters.new(
id: 1,
book: { pages: 65, title: "Green Cats and where to find then." })

params.expect(book: [:pages, :title])
params.expect(:id)
end

test "allow raises on unexpected nested params" do
params = ActionController::Parameters.new(
book: { pages: 65, title: "Green Cats and where to find then." })

assert_raises(ActionController::UnpermittedParameters) do
params.allow(book: [:pages])
end
end

test "allow doesn't raise on unpermitted root params" do
params = ActionController::Parameters.new(
id: 1,
book: { pages: 65, title: "Green Cats and where to find then." })

params.allow(book: [:pages, :title])
params.allow(:id)
end
end

0 comments on commit 2983907

Please sign in to comment.