@@ -40,6 +40,12 @@ class PlainReactOnRailsHelper
4040 "{\" hello\" :\" world\" ,\" free\" :\" of charge\" ,\" x\" :\" </script><script>alert('foo')</script>\" }"
4141 end
4242
43+ let ( :rails_context_script ) do
44+ <<-SCRIPT . strip_heredoc
45+ <script type="application/json" id="js-react-on-rails-context">{"railsEnv":"test","inMailer":false,"i18nLocale":"en","i18nDefaultLocale":"en","rorVersion":"#{ ReactOnRails ::VERSION } ","rorPro":false,"href":"http://foobar.com/development","location":"/development","scheme":"http","host":"foobar.com","port":null,"pathname":"/development","search":null,"httpAcceptLanguage":"en","somethingUseful":null,"serverSide":false}</script>
46+ SCRIPT
47+ end
48+
4349 describe "#load_pack_for_generated_component" do
4450 let ( :render_options ) do
4551 ReactOnRails ::ReactComponent ::RenderOptions . new ( react_component_name : "component_name" ,
@@ -142,7 +148,7 @@ class PlainReactOnRailsHelper
142148
143149 let ( :react_definition_script ) do
144150 <<-SCRIPT . strip_heredoc
145- <script type="application/json" id="js-react-on-rails-context">{"railsEnv":"test","inMailer":false,"i18nLocale":"en","i18nDefaultLocale":"en","rorVersion":" #{ ReactOnRails :: VERSION } ","rorPro":false,"href":"http://foobar.com/development","location":"/development","scheme":"http","host":"foobar.com","port":null,"pathname":"/development","search":null,"httpAcceptLanguage":"en","somethingUseful":null,"serverSide":false}</script>
151+ #{ rails_context_script }
146152 <div id="App-react-component"></div>
147153 <script type="application/json" class="js-react-on-rails-component" id="js-react-on-rails-component-App-react-component" data-component-name="App" data-dom-id="App-react-component" data-store-dependencies="[]">{"name":"My Test Name"}</script>
148154 SCRIPT
@@ -198,7 +204,7 @@ class PlainReactOnRailsHelper
198204
199205 let ( :react_definition_script ) do
200206 <<-SCRIPT . strip_heredoc
201- <script type="application/json" id="js-react-on-rails-context">{"railsEnv":"test","inMailer":false,"i18nLocale":"en","i18nDefaultLocale":"en","rorVersion":" #{ ReactOnRails :: VERSION } ","rorPro":false,"href":"http://foobar.com/development","location":"/development","scheme":"http","host":"foobar.com","port":null,"pathname":"/development","search":null,"httpAcceptLanguage":"en","somethingUseful":null,"serverSide":false}</script>
207+ #{ rails_context_script }
202208 <div id="App-react-component"></div>
203209 <script type="application/json" class="js-react-on-rails-component" id="js-react-on-rails-component-App-react-component" data-component-name="App" data-dom-id="App-react-component" data-store-dependencies="[]">{"name":"My Test Name"}</script>
204210 SCRIPT
@@ -213,7 +219,7 @@ class PlainReactOnRailsHelper
213219
214220 let ( :react_definition_script ) do
215221 <<-SCRIPT . strip_heredoc
216- <script type="application/json" id="js-react-on-rails-context">{"railsEnv":"test","inMailer":false,"i18nLocale":"en","i18nDefaultLocale":"en","rorVersion":" #{ ReactOnRails :: VERSION } ","rorPro":false,"href":"http://foobar.com/development","location":"/development","scheme":"http","host":"foobar.com","port":null,"pathname":"/development","search":null,"httpAcceptLanguage":"en","somethingUseful":null,"serverSide":false}</script>
222+ #{ rails_context_script }
217223 <div id="App-react-component-0"></div>
218224 <script type="application/json" class="js-react-on-rails-component" id="js-react-on-rails-component-App-react-component-0" data-component-name="App" data-dom-id="App-react-component-0" data-store-dependencies="[]">{"name":"My Test Name"}</script>
219225 SCRIPT
@@ -234,7 +240,7 @@ class PlainReactOnRailsHelper
234240
235241 let ( :react_definition_script ) do
236242 <<-SCRIPT . strip_heredoc
237- <script type="application/json" id="js-react-on-rails-context">{"railsEnv":"test","inMailer":false,"i18nLocale":"en","i18nDefaultLocale":"en","rorVersion":" #{ ReactOnRails :: VERSION } ","rorPro":false,"href":"http://foobar.com/development","location":"/development","scheme":"http","host":"foobar.com","port":null,"pathname":"/development","search":null,"httpAcceptLanguage":"en","somethingUseful":null,"serverSide":false}</script>
243+ #{ rails_context_script }
238244 <div id="App-react-component"></div>
239245 <script type="application/json" class="js-react-on-rails-component" id="js-react-on-rails-component-App-react-component" data-component-name="App" data-dom-id="App-react-component" data-store-dependencies="[]">{"name":"My Test Name"}</script>
240246 SCRIPT
@@ -251,7 +257,7 @@ class PlainReactOnRailsHelper
251257
252258 let ( :react_definition_script ) do
253259 <<-SCRIPT . strip_heredoc
254- <script type="application/json" id="js-react-on-rails-context">{"railsEnv":"test","inMailer":false,"i18nLocale":"en","i18nDefaultLocale":"en","rorVersion":" #{ ReactOnRails :: VERSION } ","rorPro":false,"href":"http://foobar.com/development","location":"/development","scheme":"http","host":"foobar.com","port":null,"pathname":"/development","search":null,"httpAcceptLanguage":"en","somethingUseful":null,"serverSide":false}</script>
260+ #{ rails_context_script }
255261 <div id="shaka_div"></div>
256262 <script type="application/json" class="js-react-on-rails-component" id="js-react-on-rails-component-shaka_div" data-component-name="App" data-dom-id="shaka_div" data-store-dependencies="[]">{"name":"My Test Name"}</script>
257263 SCRIPT
@@ -317,27 +323,36 @@ class PlainReactOnRailsHelper
317323 end
318324
319325 describe "#redux_store" do
320- subject ( :store ) { redux_store ( "reduxStore" , props : props ) }
326+ let ( :store ) { redux_store ( "reduxStore" , props : props ) }
327+ let ( :second_store ) { redux_store ( "secondStore" , props : props ) }
321328
322329 let ( :props ) do
323330 { name : "My Test Name" }
324331 end
325-
326332 let ( :react_store_script ) do
327333 '<script type="application/json" data-js-react-on-rails-store="reduxStore">' \
328334 '{"name":"My Test Name"}' \
329335 "</script>"
330336 end
337+ let ( :second_react_store_script ) do
338+ '<script type="application/json" data-js-react-on-rails-store="secondStore">' \
339+ '{"name":"My Test Name"}' \
340+ "</script>"
341+ end
331342
332343 it { expect ( self ) . to respond_to :redux_store }
333344
334- it { is_expected . to be_an_instance_of ActiveSupport ::SafeBuffer }
335- it { is_expected . to start_with "<script" }
336- it { is_expected . to end_with "</script>" }
345+ it { expect ( store ) . to be_an_instance_of ActiveSupport ::SafeBuffer }
346+ it { expect ( store ) . to start_with "<script" }
347+ it { expect ( store ) . to end_with "</script>" }
337348
338- it {
339- expect ( expect ( store ) . target ) . to script_tag_be_included ( react_store_script )
340- }
349+ it "adds the rails context script to the first store only" do
350+ expect ( store ) . to script_tag_be_included ( react_store_script )
351+ expect ( store ) . to script_tag_be_included ( rails_context_script )
352+
353+ expect ( second_store ) . to script_tag_be_included ( second_react_store_script )
354+ expect ( second_store ) . not_to script_tag_be_included ( rails_context_script )
355+ end
341356 end
342357
343358 describe "#server_render_js" , :js , type : :system do
0 commit comments