Skip to content

Commit f596810

Browse files
Revert "tmp"
This reverts commit a66a617.
1 parent a66a617 commit f596810

File tree

2 files changed

+16
-33
lines changed

2 files changed

+16
-33
lines changed

spec/dummy/spec/helpers/react_on_rails_helper_spec.rb

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ 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-
4943
describe "#load_pack_for_generated_component" do
5044
let(:render_options) do
5145
ReactOnRails::ReactComponent::RenderOptions.new(react_component_name: "component_name",
@@ -148,7 +142,7 @@ class PlainReactOnRailsHelper
148142

149143
let(:react_definition_script) do
150144
<<-SCRIPT.strip_heredoc
151-
#{rails_context_script}
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>
152146
<div id="App-react-component"></div>
153147
<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>
154148
SCRIPT
@@ -204,7 +198,7 @@ class PlainReactOnRailsHelper
204198

205199
let(:react_definition_script) do
206200
<<-SCRIPT.strip_heredoc
207-
#{rails_context_script}
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>
208202
<div id="App-react-component"></div>
209203
<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>
210204
SCRIPT
@@ -219,7 +213,7 @@ class PlainReactOnRailsHelper
219213

220214
let(:react_definition_script) do
221215
<<-SCRIPT.strip_heredoc
222-
#{rails_context_script}
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>
223217
<div id="App-react-component-0"></div>
224218
<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>
225219
SCRIPT
@@ -240,7 +234,7 @@ class PlainReactOnRailsHelper
240234

241235
let(:react_definition_script) do
242236
<<-SCRIPT.strip_heredoc
243-
#{rails_context_script}
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>
244238
<div id="App-react-component"></div>
245239
<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>
246240
SCRIPT
@@ -257,7 +251,7 @@ class PlainReactOnRailsHelper
257251

258252
let(:react_definition_script) do
259253
<<-SCRIPT.strip_heredoc
260-
#{rails_context_script}
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>
261255
<div id="shaka_div"></div>
262256
<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>
263257
SCRIPT
@@ -323,36 +317,27 @@ class PlainReactOnRailsHelper
323317
end
324318

325319
describe "#redux_store" do
326-
let(:store) { redux_store("reduxStore", props: props) }
327-
let(:second_store) { redux_store("secondStore", props: props) }
320+
subject(:store) { redux_store("reduxStore", props: props) }
328321

329322
let(:props) do
330323
{ name: "My Test Name" }
331324
end
325+
332326
let(:react_store_script) do
333327
'<script type="application/json" data-js-react-on-rails-store="reduxStore">' \
334328
'{"name":"My Test Name"}' \
335329
"</script>"
336330
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
342331

343332
it { expect(self).to respond_to :redux_store }
344333

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>" }
348-
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)
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>" }
352337

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
338+
it {
339+
expect(expect(store).target).to script_tag_be_included(react_store_script)
340+
}
356341
end
357342

358343
describe "#server_render_js", :js, type: :system do

spec/dummy/spec/support/script_tag_utils.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
opts = {}
77
match do |actual|
88
Nokogiri::HTML.fragment(actual).css("script").map do |script|
9-
res = EquivalentXml.equivalent?(Nokogiri::HTML.fragment(script.to_s.strip),
10-
Nokogiri::HTML.fragment(expected.to_s.strip),
11-
opts)
12-
binding.pry
13-
res
9+
EquivalentXml.equivalent?(Nokogiri::HTML.fragment(script.to_s.delete(" \t\r\n")),
10+
Nokogiri::HTML.fragment(expected.delete(" \t\r\n")),
11+
opts)
1412
end.include?(true)
1513
end
1614

0 commit comments

Comments
 (0)