Skip to content

Commit 86594f2

Browse files
justin808claude
andcommitted
Add test coverage for with_unbundled_context and update CHANGELOG
- Added comprehensive test coverage for the with_unbundled_context wrapper to verify the Bundler API compatibility chain: * Tests with_unbundled_env (modern Bundler API) * Tests with_clean_env (legacy Bundler API) * Tests fallback when neither method is available * Tests execution when Bundler is not defined - Updated CHANGELOG.md with bug fix entry for issue #2084 All 18 examples in pack_generator_spec.rb pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 869a83f commit 86594f2

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ Changes since the last non-beta release.
2727

2828
- **CSP Nonce Support for Console Replay**: Added Content Security Policy (CSP) nonce support for the `consoleReplay` script generated during server-side rendering. When Rails CSP is configured, the console replay script will automatically include the nonce attribute, allowing it to execute under restrictive CSP policies like `script-src: 'self'`. The implementation includes cross-version Rails compatibility (5.2-7.x) and defense-in-depth nonce sanitization to prevent attribute injection attacks. [PR 2059](https://github.com/shakacode/react_on_rails/pull/2059) by [justin808](https://github.com/justin808).
2929

30+
#### Bug Fixes
31+
32+
- [PR 2085](https://github.com/shakacode/react_on_rails/pull/2085) by [justin808](https://github.com/justin808): Fix pack generation in bin/dev when running from Bundler context. Pack generation was failing with "Could not find command 'react_on_rails:generate_packs'" because Bundler was intercepting the subprocess call. The fix wraps the bundle exec call with `Bundler.with_unbundled_env` to prevent interception.
33+
3034
### [v16.2.0.beta.11] - 2025-11-19
3135

3236
#### Added

spec/react_on_rails/dev/pack_generator_spec.rb

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,5 +206,90 @@
206206
.with("bundle", "exec", "rake", "react_on_rails:generate_packs")
207207
end
208208
end
209+
210+
context "when calling bundle exec from within Bundler context" do
211+
before do
212+
# Ensure we're not in Rails context to trigger bundle exec path
213+
hide_const("Rails") if defined?(Rails)
214+
allow(ReactOnRails::PackerUtils).to receive(:shakapacker_precompile_hook_configured?).and_return(false)
215+
end
216+
217+
it "unwraps the Bundler context before executing with with_unbundled_env" do
218+
bundler_module = Module.new do
219+
def self.respond_to?(method, *)
220+
method == :with_unbundled_env
221+
end
222+
223+
def self.with_unbundled_env
224+
yield
225+
end
226+
end
227+
stub_const("Bundler", bundler_module)
228+
229+
allow(bundler_module).to receive(:with_unbundled_env).and_yield
230+
allow(described_class).to receive(:system)
231+
.with("bundle", "exec", "rake", "react_on_rails:generate_packs")
232+
.and_return(true)
233+
234+
described_class.generate(verbose: true)
235+
236+
expect(bundler_module).to have_received(:with_unbundled_env)
237+
end
238+
239+
it "falls back to with_clean_env when with_unbundled_env is not available" do
240+
bundler_module = Module.new do
241+
def self.respond_to?(method, *)
242+
method == :with_clean_env
243+
end
244+
245+
def self.with_clean_env
246+
yield
247+
end
248+
end
249+
stub_const("Bundler", bundler_module)
250+
251+
allow(bundler_module).to receive(:with_clean_env).and_yield
252+
allow(described_class).to receive(:system)
253+
.with("bundle", "exec", "rake", "react_on_rails:generate_packs")
254+
.and_return(true)
255+
256+
described_class.generate(verbose: true)
257+
258+
expect(bundler_module).to have_received(:with_clean_env)
259+
end
260+
261+
it "executes directly when neither with_unbundled_env nor with_clean_env are available" do
262+
bundler_module = Module.new do
263+
def self.respond_to?(_method, *)
264+
false
265+
end
266+
end
267+
stub_const("Bundler", bundler_module)
268+
269+
allow(described_class).to receive(:system)
270+
.with("bundle", "exec", "rake", "react_on_rails:generate_packs")
271+
.and_return(true)
272+
273+
expect { described_class.generate(verbose: true) }
274+
.to output(/📦 Generating React on Rails packs.../).to_stdout_from_any_process
275+
276+
expect(described_class).to have_received(:system)
277+
.with("bundle", "exec", "rake", "react_on_rails:generate_packs")
278+
end
279+
280+
it "executes directly when Bundler is not defined" do
281+
hide_const("Bundler") if defined?(Bundler)
282+
283+
allow(described_class).to receive(:system)
284+
.with("bundle", "exec", "rake", "react_on_rails:generate_packs")
285+
.and_return(true)
286+
287+
expect { described_class.generate(verbose: true) }
288+
.to output(/📦 Generating React on Rails packs.../).to_stdout_from_any_process
289+
290+
expect(described_class).to have_received(:system)
291+
.with("bundle", "exec", "rake", "react_on_rails:generate_packs")
292+
end
293+
end
209294
end
210295
end

0 commit comments

Comments
 (0)