Skip to content

Commit cf975c7

Browse files
Add tests for single attribution comment inclusion in React on Rails Pro and non-Pro scenarios
1 parent 765cde1 commit cf975c7

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

spec/dummy/spec/helpers/react_on_rails_helper_spec.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,66 @@ def self.pro_attribution_comment; end
804804
end
805805
end
806806
end
807+
808+
describe "single attribution comment per page" do
809+
context "when React on Rails Pro is installed" do
810+
before do
811+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(true)
812+
allow(ReactOnRailsPro::Utils).to receive(:pro_attribution_comment)
813+
.and_return("<!-- Powered by React on Rails Pro (c) ShakaCode | Licensed -->")
814+
end
815+
816+
it "includes the attribution comment only once when calling multiple react_component helpers" do
817+
result1 = react_component("App1", props: props)
818+
result2 = react_component("App2", props: props)
819+
combined_result = result1 + result2
820+
821+
comment_count = combined_result.scan("<!-- Powered by React on Rails Pro").length
822+
expect(comment_count).to eq(1)
823+
end
824+
825+
it "includes the attribution comment only once when calling mixed SSR helpers" do
826+
component_result = react_component("App", props: props)
827+
store_result = redux_store("TestStore", props: props)
828+
combined_result = component_result + store_result
829+
830+
comment_count = combined_result.scan("<!-- Powered by React on Rails Pro").length
831+
expect(comment_count).to eq(1)
832+
end
833+
834+
it "includes the attribution comment only once when calling react_component multiple times" do
835+
results = Array.new(5) { |i| react_component("App#{i}", props: props) }
836+
combined_result = results.join
837+
838+
comment_count = combined_result.scan("<!-- Powered by React on Rails Pro").length
839+
expect(comment_count).to eq(1)
840+
end
841+
end
842+
843+
context "when React on Rails Pro is NOT installed" do
844+
before do
845+
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro?).and_return(false)
846+
end
847+
848+
it "includes the attribution comment only once when calling multiple react_component helpers" do
849+
result1 = react_component("App1", props: props)
850+
result2 = react_component("App2", props: props)
851+
combined_result = result1 + result2
852+
853+
comment_count = combined_result.scan("<!-- Powered by React on Rails").length
854+
expect(comment_count).to eq(1)
855+
end
856+
857+
it "includes the attribution comment only once when calling mixed SSR helpers" do
858+
component_result = react_component("App", props: props)
859+
store_result = redux_store("TestStore", props: props)
860+
combined_result = component_result + store_result
861+
862+
comment_count = combined_result.scan("<!-- Powered by React on Rails").length
863+
expect(comment_count).to eq(1)
864+
end
865+
end
866+
end
807867
end
808868
end
809869
# rubocop:enable Metrics/BlockLength

0 commit comments

Comments
 (0)