Skip to content

Commit 339a563

Browse files
authored
Merge pull request #932 from jcarlson/camelize-strong-parameters
Support camelizing ActionController::Parameters
2 parents 732a489 + 9b5117a commit 339a563

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/react.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ def self.camelize_props(props)
1313
when Array
1414
props.map { |item| camelize_props(item) }
1515
else
16-
props
16+
if defined?(ActionController::Parameters) && props.is_a?(ActionController::Parameters)
17+
camelize_props(props.to_h)
18+
else
19+
props
20+
end
1721
end
1822
end
1923
end

test/react_test.rb

+19
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,23 @@ def test_it_camelizes_props
2828

2929
assert_equal expected_props, React.camelize_props(raw_props)
3030
end
31+
32+
def test_it_camelizes_params
33+
raw_params = ActionController::Parameters.new({
34+
foo_bar_baz: 'foo bar baz',
35+
nested_keys: {
36+
qux_etc: 'bish bash bosh'
37+
}
38+
})
39+
permitted_params = raw_params.permit(:foo_bar_baz, nested_keys: :qux_etc)
40+
41+
expected_params = {
42+
'fooBarBaz' => 'foo bar baz',
43+
'nestedKeys' => {
44+
'quxEtc' => 'bish bash bosh'
45+
}
46+
}
47+
48+
assert_equal expected_params, React.camelize_props(permitted_params)
49+
end
3150
end

0 commit comments

Comments
 (0)