Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/action_figure/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ def notify
private

def normalize_params(kwargs)
return kwargs unless contract

raw = kwargs[:params]
return kwargs unless raw.respond_to?(:to_unsafe_h)

Expand Down
10 changes: 7 additions & 3 deletions test/action_figure/core_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,10 @@ def call(params:)
assert_equal({ name: "Tad" }, result[:json][:data])
end

def test_params_with_to_unsafe_h_are_unwrapped_without_schema
def test_params_with_to_unsafe_h_pass_through_without_schema
# Without a params_schema there is nothing to validate or whitelist, so
# to_unsafe_h must NOT be called — the raw params object passes through
# untouched and the action handles it (e.g. via strong params) itself.
fake_params = Class.new do
def initialize(hash) = @hash = hash
def to_unsafe_h = @hash
Expand All @@ -216,10 +219,11 @@ def call(params:)
end
end

result = action.call(params: fake_params.new({ name: "Tad" }))
raw = fake_params.new({ name: "Tad" })
result = action.call(params: raw)

assert_equal :ok, result[:status]
assert_equal({ name: "Tad" }, result[:json][:data])
assert_same raw, result[:json][:data]
end
end

Expand Down