diff --git a/lib/react.rb b/lib/react.rb index 5e6b0f75..209b1f79 100644 --- a/lib/react.rb +++ b/lib/react.rb @@ -13,7 +13,11 @@ def self.camelize_props(props) when Array props.map { |item| camelize_props(item) } else - props + if defined?(ActionController::Parameters) && props.is_a?(ActionController::Parameters) + camelize_props(props.to_h) + else + props + end end end end diff --git a/test/react_test.rb b/test/react_test.rb index 779e9251..ccb92bb3 100644 --- a/test/react_test.rb +++ b/test/react_test.rb @@ -28,4 +28,23 @@ def test_it_camelizes_props assert_equal expected_props, React.camelize_props(raw_props) end + + def test_it_camelizes_params + raw_params = ActionController::Parameters.new({ + foo_bar_baz: 'foo bar baz', + nested_keys: { + qux_etc: 'bish bash bosh' + } + }) + permitted_params = raw_params.permit(:foo_bar_baz, nested_keys: :qux_etc) + + expected_params = { + 'fooBarBaz' => 'foo bar baz', + 'nestedKeys' => { + 'quxEtc' => 'bish bash bosh' + } + } + + assert_equal expected_params, React.camelize_props(permitted_params) + end end