Skip to content

Commit e248263

Browse files
Update integration spec to mock ReactOnRailsPro instead of core config
Changed the shared context to stub ReactOnRailsPro module and its configuration instead of trying to set immediate_hydration on core ReactOnRails configuration (which no longer exists). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 4526427 commit e248263

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

spec/dummy/spec/system/integration_spec.rb

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,50 @@ def finished_all_ajax_requests?
8888

8989
shared_context "with pro features and immediate hydration" do
9090
before do
91-
allow(ReactOnRails::Utils).to receive(:react_on_rails_pro_licence_valid?).and_return(true)
92-
end
91+
allow(ReactOnRails::Utils).to receive_messages(
92+
react_on_rails_pro_licence_valid?: true,
93+
react_on_rails_pro?: true
94+
)
95+
96+
# Mock Pro gem for immediate_hydration
97+
pro_config = Struct.new(:immediate_hydration).new(true)
98+
stub_const("ReactOnRailsPro", Module.new do
99+
define_singleton_method(:configuration) { pro_config }
100+
end)
101+
102+
stub_const("ReactOnRailsPro::Helper", Module.new do
103+
def self.enhance_component_script_data(args)
104+
if args[:render_options].immediate_hydration
105+
dom_id = args[:render_options].dom_id
106+
script_tag = "<script>\n typeof ReactOnRails === 'object' && " \
107+
"ReactOnRails.reactOnRailsComponentLoaded('#{dom_id}');\n </script>"
108+
{
109+
script_attrs: args[:script_attrs].merge("data-immediate-hydration" => true),
110+
additional_scripts: [script_tag]
111+
}
112+
else
113+
{ script_attrs: args[:script_attrs], additional_scripts: [] }
114+
end
115+
end
116+
117+
def self.enhance_store_script_data(args)
118+
if args[:redux_store_data][:immediate_hydration]
119+
store_name = args[:redux_store_data][:store_name]
120+
script_tag = "<script>\n typeof ReactOnRails === 'object' && " \
121+
"ReactOnRails.reactOnRailsStoreLoaded('#{store_name}');\n </script>"
122+
{
123+
script_attrs: args[:script_attrs].merge("data-immediate-hydration" => true),
124+
additional_scripts: [script_tag]
125+
}
126+
else
127+
{ script_attrs: args[:script_attrs], additional_scripts: [] }
128+
end
129+
end
130+
end)
93131

94-
around do |example|
95-
ReactOnRails.configure { |config| config.immediate_hydration = true }
96-
example.run
97-
ReactOnRails.configure { |config| config.immediate_hydration = false }
132+
# Mock Gem.loaded_specs for version
133+
gem_spec = Struct.new(:version).new(Gem::Version.new("1.0.0"))
134+
allow(Gem).to receive(:loaded_specs).and_return({ "react_on_rails_pro" => gem_spec })
98135
end
99136
end
100137

0 commit comments

Comments
 (0)