From dc58bea2e88782e08dda0eee413ddd3997546e8f Mon Sep 17 00:00:00 2001 From: Robert Mosolgo Date: Thu, 1 Dec 2016 15:17:10 -0500 Subject: [PATCH] feat(ComponentMount) allow overriding camelize_props=true with local false --- lib/react/rails/component_mount.rb | 2 +- test/react/rails/component_mount_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/react/rails/component_mount.rb b/lib/react/rails/component_mount.rb index 157c88d05..b516ed6cf 100644 --- a/lib/react/rails/component_mount.rb +++ b/lib/react/rails/component_mount.rb @@ -24,7 +24,7 @@ def teardown(env) # on the client. def react_component(name, props = {}, options = {}, &block) options = {:tag => options} if options.is_a?(Symbol) - if camelize_props_switch || options[:camelize_props] + if options.fetch(:camelize_props, camelize_props_switch) props = React.camelize_props(props) end diff --git a/test/react/rails/component_mount_test.rb b/test/react/rails/component_mount_test.rb index e9c4af33c..07d8ef18c 100644 --- a/test/react/rails/component_mount_test.rb +++ b/test/react/rails/component_mount_test.rb @@ -32,6 +32,14 @@ class ComponentMountTest < ActionDispatch::IntegrationTest expected_props.each do |segment| assert html.include?(segment) end + + React::Rails::ComponentMount.camelize_props_switch = true + helper = React::Rails::ComponentMount.new + html = helper.react_component('Foo', {foo_bar: 'value'}, camelize_props: false) + expected_props = %w(data-react-class="Foo" data-react-props="{"foo_bar":"value"}") + expected_props.each do |segment| + assert html.include?(segment) + end end test '#react_component accepts React props with camelize_props containing nested arrays' do