Skip to content

Conversation

@ihabadham
Copy link
Contributor

@ihabadham ihabadham commented Sep 16, 2025

Summary

Fix two integration tests broken by immediate_hydration Pro license requirements in PR #1781. The issue was Pro license validation blocking immediate hydration behavior which tests relies on as being default.

Pull Request checklist

  • Add/update test to cover these changes (tests already exist, just fixed)
  • Update documentation
  • Update CHANGELOG file

Other Information

Uses per-test mocking approach consistent with existing helper specs. Both tests now pass reliably.


This change is Reviewable

Summary by CodeRabbit

  • Tests
    • Made client-side hydration timing deterministic during system tests to reduce flakiness.
    • Re-enabled previously skipped scenarios by stubbing license validation, increasing test coverage.
    • Improvements cover page-transition flows and streamed component updates (Turbolinks/TurboStream).
    • Enhances test reliability and confidence without affecting runtime behavior or public APIs.

Mock Pro license validation per-test using around blocks.
Follows existing helper spec patterns.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 16, 2025

Warning

Rate limit exceeded

@ihabadham has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 3 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between db11247 and 84b20b5.

📒 Files selected for processing (1)
  • spec/dummy/spec/system/integration_spec.rb (2 hunks)

Walkthrough

Added RSpec around blocks in spec/dummy/spec/system/integration_spec.rb to enable immediate ReactOnRails hydration during specific examples and restore the prior setting after each. Two previously skipped tests were unskipped by stubbing ReactOnRails::Utils.react_on_rails_pro_licence_valid? to return true, enabling Turbo/Turbolinks and immediate-load test execution.

Changes

Cohort / File(s) Summary of Changes
System test hydration control and license stubs
spec/dummy/spec/system/integration_spec.rb
Added RSpec around blocks to set immediate_hydration = true for targeted examples and restore the previous value after each. Replaced two skipped tests by stubbing ReactOnRails::Utils.react_on_rails_pro_licence_valid? to return true, allowing the "Turbolinks across pages" and "TurboStream send react component / force load hello-world component immediately" examples to run.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant RSpec as RSpec Example
  participant Around as Around Block
  participant Config as ReactOnRails::Config
  participant Utils as ReactOnRails::Utils
  participant App as Test App (Turbo/Turbolinks)

  RSpec->>Around: start example
  activate Around
  Around->>Config: set immediate_hydration = true (save previous)
  Around->>Utils: stub react_on_rails_pro_licence_valid? => true
  RSpec->>App: navigate / trigger Turbo/Turbolinks actions
  App->>Config: hydrate React component immediately
  Around->>Config: restore previous immediate_hydration
  Around-->>RSpec: finish example
  deactivate Around
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • justin808

Poem

A rabbit nudges specs at dawn,
"Hydrate quick, then set it gone."
Licenses mocked, the tests now play—
Turbo hops and Turbolinks sway.
Carrots clapped, the CI sings hooray. 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title accurately and concisely summarizes the primary change: it fixes integration tests that broke due to the immediate_hydration behavior tied to the Pro license. It names the scope (integration tests) and the cause (immediate_hydration Pro license changes), which matches the PR description and file summaries. The phrasing is specific and clear for reviewers scanning history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@claude
Copy link

claude bot commented Sep 16, 2025

Code Review for PR #1783

Summary

This PR effectively fixes two integration tests that were broken by the immediate_hydration Pro license requirements introduced in PR #1781. The solution is clean and follows established patterns in the codebase.

✅ Strengths

  1. Consistent with existing patterns: The mocking approach using allow(ReactOnRails::Utils).to receive(:react_on_rails_pro_licence_valid?).and_return(true) is consistent with the pattern already used in spec/dummy/spec/helpers/react_on_rails_helper_spec.rb.

  2. Proper test isolation: The use of around blocks ensures that the immediate_hydration configuration is properly set before each test and reset afterward, preventing test pollution.

  3. Removes misleading skip messages: The tests were marked as "Flaky test - needs investigation" when the actual issue was Pro license validation, not flakiness. This fix properly addresses the root cause.

🔍 Observations

  1. Code duplication: Both test blocks use identical around blocks and Pro license mocking. Consider extracting this into a shared context or helper method to follow DRY principles.

💡 Suggestions

  1. Consider a shared context: You could create a shared context for tests requiring Pro features with immediate hydration:
shared_context 'with pro features and immediate hydration' do
  before do
    allow(ReactOnRails::Utils).to receive(:react_on_rails_pro_licence_valid?).and_return(true)
  end
  
  around do |example|
    ReactOnRails.configure { |config| config.immediate_hydration = true }
    example.run
    ReactOnRails.configure { |config| config.immediate_hydration = false }
  end
end

Then use it as: include_context 'with pro features and immediate hydration'

  1. Test coverage: The tests now pass, but consider adding a negative test case that verifies the behavior when Pro license is not available, to ensure the feature degrades gracefully.

✅ Security & Performance

  • No security concerns identified
  • No performance implications

✅ Test Coverage

  • The fix enables existing tests to run properly
  • Tests cover the immediate hydration feature with Pro license

Conclusion

This is a solid fix that addresses the immediate issue. The code is correct and follows existing patterns. The suggested improvements are optional enhancements for better maintainability. LGTM! 👍

@claude
Copy link

claude bot commented Sep 16, 2025

Code Review for PR #1783

✅ Summary

This PR appropriately fixes the integration tests that were broken by the immediate_hydration Pro license requirements introduced in PR #1781. The fix is well-targeted and follows existing patterns in the codebase.

👍 Positive Aspects

  1. Consistent with existing patterns: The approach of mocking react_on_rails_pro_licence_valid? matches the established pattern used in spec/dummy/spec/helpers/react_on_rails_helper_spec.rb:68-70 and elsewhere.

  2. Proper test isolation: Using around blocks to temporarily enable immediate_hydration ensures tests don't affect each other and properly restore the original configuration.

  3. Removes technical debt: Successfully un-skips two previously flaky tests that were marked as "needs investigation".

🔍 Observations & Minor Suggestions

  1. Configuration reset in around block: The current implementation correctly resets immediate_hydration to false, which is the default. Consider using a more defensive approach to restore the original value:

    around do |example|
      original_value = ReactOnRails.configuration.immediate_hydration
      ReactOnRails.configure { |config| config.immediate_hydration = true }
      example.run
    ensure
      ReactOnRails.configure { |config| config.immediate_hydration = original_value }
    end

    This ensures the original state is preserved even if the default changes.

  2. Mocking placement: The allow(ReactOnRails::Utils).to receive(:react_on_rails_pro_licence_valid?).and_return(true) is placed inside each test. Since both tests in each describe block need this mock, consider moving it to a before block for DRYness:

    before do
      allow(ReactOnRails::Utils).to receive(:react_on_rails_pro_licence_valid?).and_return(true)
    end
  3. Test documentation: Consider adding a comment explaining why these specific tests require Pro license mocking, to help future maintainers understand the dependency.

✅ Security & Performance

  • No security concerns identified
  • No performance impact (test-only changes)

✅ Test Coverage

  • The fix properly restores test coverage for Turbolinks and TurboStream functionality
  • Both affected integration tests now pass reliably

🎯 Overall Assessment

Approved - This is a solid fix that addresses the immediate issue while maintaining code consistency. The minor suggestions above are optional improvements for consideration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
spec/dummy/spec/system/integration_spec.rb (3)

92-96: Restore previous config and ensure cleanup in around hook

Hard‑resetting to false risks leaking state if the default isn’t false and if an example fails mid‑run. Capture the prior value and restore it in an ensure block.

If specs run in parallel, global config toggling can still cause flakes. Confirm parallelization is off for this suite.

-around do |example|
-  ReactOnRails.configure { |config| config.immediate_hydration = true }
-  example.run
-  ReactOnRails.configure { |config| config.immediate_hydration = false }
-end
+around do |example|
+  previous = ReactOnRails.configuration.immediate_hydration
+  ReactOnRails.configure { |config| config.immediate_hydration = true }
+  begin
+    example.run
+  ensure
+    ReactOnRails.configure { |config| config.immediate_hydration = previous }
+  end
+end

111-115: Repeat of around hook: DRY and safe restore

Same concern as above. Use the safer pattern and consider extracting a shared_context to avoid duplication across describes.

-around do |example|
-  ReactOnRails.configure { |config| config.immediate_hydration = true }
-  example.run
-  ReactOnRails.configure { |config| config.immediate_hydration = false }
-end
+around do |example|
+  previous = ReactOnRails.configuration.immediate_hydration
+  ReactOnRails.configure { |config| config.immediate_hydration = true }
+  begin
+    example.run
+  ensure
+    ReactOnRails.configure { |config| config.immediate_hydration = previous }
+  end
+end

118-118: Confirm predicate name and extract test helper

Predicate is correct — defined as react_on_rails_pro_licence_valid? in lib/react_on_rails/utils.rb — and is stubbed in multiple specs (spec/dummy/spec/system/integration_spec.rb:99,118 and spec/dummy/spec/helpers/react_on_rails_helper_spec.rb). Extract a small helper in spec/support (e.g., stub_pro_licence!(value = true)) and include it where needed to DRY the stubs.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f7d5355 and 65b32ac.

📒 Files selected for processing (1)
  • spec/dummy/spec/system/integration_spec.rb (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rb

📄 CodeRabbit inference engine (CLAUDE.md)

Use RuboCop for all Ruby code

Files:

  • spec/dummy/spec/system/integration_spec.rb
🧠 Learnings (5)
📓 Common learnings
Learnt from: AbanoubGhadban
PR: shakacode/react_on_rails#1781
File: node_package/src/ClientSideRenderer.ts:82-95
Timestamp: 2025-09-15T21:24:48.207Z
Learning: In React on Rails, the force_load feature includes both explicit `data-force-load="true"` usage and the ability to hydrate components during the page loading state (`document.readyState === 'loading'`). Both capabilities require a Pro license, so the condition `!railsContext.rorPro && (isComponentForceLoaded || document.readyState === 'loading')` correctly gates both scenarios.
Learnt from: theforestvn88
PR: shakacode/react_on_rails#1620
File: spec/dummy/client/app/startup/HelloTurboStream.jsx:3-3
Timestamp: 2024-10-08T20:53:47.076Z
Learning: The `RailsContext` import in `spec/dummy/client/app/startup/HelloTurboStream.jsx` is used later in the project, as clarified by the user theforestvn88.
Learnt from: theforestvn88
PR: shakacode/react_on_rails#1620
File: spec/dummy/client/app/startup/HelloTurboStream.jsx:3-3
Timestamp: 2024-07-27T10:08:35.868Z
Learning: The `RailsContext` import in `spec/dummy/client/app/startup/HelloTurboStream.jsx` is used later in the project, as clarified by the user theforestvn88.
Learnt from: AbanoubGhadban
PR: shakacode/react_on_rails#1644
File: node_package/src/turbolinksUtils.ts:34-36
Timestamp: 2025-02-13T16:50:26.861Z
Learning: In React on Rails, when checking for Turbolinks version 5 using `turbolinksVersion5()`, always ensure `Turbolinks` exists first by checking `turbolinksInstalled()` to prevent TypeError when accessing properties.
Learnt from: AbanoubGhadban
PR: shakacode/react_on_rails#1644
File: lib/react_on_rails/helper.rb:190-197
Timestamp: 2025-02-18T13:08:01.477Z
Learning: RSC support validation in React on Rails Pro is handled through a chain of validations:
1. Pro version check in `run_stream_inside_fiber`
2. RSC support check during pack generation via `ReactOnRailsPro.configuration.enable_rsc_support`
3. RSC support validation during component registration
This makes additional validation in the helper methods unnecessary.
Learnt from: justin808
PR: shakacode/react_on_rails#1622
File: spec/dummy/spec/rake/assets_precompile_rake_spec.rb:12-12
Timestamp: 2024-06-27T05:22:46.156Z
Learning: When stubbing environment variables in RSpec tests, use `before` and `after` hooks to ensure that the original values are restored after the tests, preventing any side effects on other tests. Example provided by justin808:
```ruby
describe "My test" do
  before do
    original_value = ENV["VARIABLE_NAME"]
    allow(ENV).to receive(:[]).with("VARIABLE_NAME").and_return("stubbed_value")
  end

  after do
    allow(ENV).to receive(:[]).with("VARIABLE_NAME").and_call_original
    ENV["VARIABLE_NAME"] = original_value
  end

  it "tests something" do
    # Your test code here
  end
end
```
This practice ensures test isolation and reliability.
Learnt from: justin808
PR: shakacode/react_on_rails#1622
File: spec/dummy/spec/rake/assets_precompile_rake_spec.rb:12-12
Timestamp: 2024-10-08T20:53:47.076Z
Learning: When stubbing environment variables in RSpec tests, use `before` and `after` hooks to ensure that the original values are restored after the tests, preventing any side effects on other tests. Example provided by justin808:
```ruby
describe "My test" do
  before do
    original_value = ENV["VARIABLE_NAME"]
    allow(ENV).to receive(:[]).with("VARIABLE_NAME").and_return("stubbed_value")
  end

  after do
    allow(ENV).to receive(:[]).with("VARIABLE_NAME").and_call_original
    ENV["VARIABLE_NAME"] = original_value
  end

  it "tests something" do
    # Your test code here
  end
end
```
This practice ensures test isolation and reliability.
Learnt from: AbanoubGhadban
PR: shakacode/react_on_rails#1644
File: spec/react_on_rails/utils_spec.rb:218-218
Timestamp: 2025-02-13T14:29:49.267Z
Learning: In RSpec tests, prefer using local variables over constants within test blocks to avoid constant redefinition warnings and maintain better test isolation.
📚 Learning: 2024-10-08T20:53:47.076Z
Learnt from: theforestvn88
PR: shakacode/react_on_rails#1620
File: spec/dummy/client/app/startup/HelloTurboStream.jsx:3-3
Timestamp: 2024-10-08T20:53:47.076Z
Learning: The `RailsContext` import in `spec/dummy/client/app/startup/HelloTurboStream.jsx` is used later in the project, as clarified by the user theforestvn88.

Applied to files:

  • spec/dummy/spec/system/integration_spec.rb
📚 Learning: 2025-02-13T16:50:26.861Z
Learnt from: AbanoubGhadban
PR: shakacode/react_on_rails#1644
File: node_package/src/turbolinksUtils.ts:34-36
Timestamp: 2025-02-13T16:50:26.861Z
Learning: In React on Rails, when checking for Turbolinks version 5 using `turbolinksVersion5()`, always ensure `Turbolinks` exists first by checking `turbolinksInstalled()` to prevent TypeError when accessing properties.

Applied to files:

  • spec/dummy/spec/system/integration_spec.rb
📚 Learning: 2025-02-13T16:50:47.848Z
Learnt from: AbanoubGhadban
PR: shakacode/react_on_rails#1644
File: node_package/src/clientStartup.ts:18-21
Timestamp: 2025-02-13T16:50:47.848Z
Learning: In the react_on_rails module, the `reactOnRailsPageUnloaded` function in clientStartup.ts is intentionally kept private as it's only used internally as a callback for `onPageUnloaded`.

Applied to files:

  • spec/dummy/spec/system/integration_spec.rb
📚 Learning: 2025-09-15T21:24:48.207Z
Learnt from: AbanoubGhadban
PR: shakacode/react_on_rails#1781
File: node_package/src/ClientSideRenderer.ts:82-95
Timestamp: 2025-09-15T21:24:48.207Z
Learning: In React on Rails, the force_load feature includes both explicit `data-force-load="true"` usage and the ability to hydrate components during the page loading state (`document.readyState === 'loading'`). Both capabilities require a Pro license, so the condition `!railsContext.rorPro && (isComponentForceLoaded || document.readyState === 'loading')` correctly gates both scenarios.

Applied to files:

  • spec/dummy/spec/system/integration_spec.rb
🧬 Code graph analysis (1)
spec/dummy/spec/system/integration_spec.rb (2)
lib/react_on_rails/configuration.rb (1)
  • configure (6-9)
lib/react_on_rails/react_component/render_options.rb (1)
  • immediate_hydration (98-100)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: dummy-app-integration-tests (newest)
  • GitHub Check: dummy-app-integration-tests (oldest)
  • GitHub Check: rspec-package-tests (oldest)
  • GitHub Check: rspec-package-tests (newest)
  • GitHub Check: build
🔇 Additional comments (1)
spec/dummy/spec/system/integration_spec.rb (1)

99-99: Ignore — 'licence' spelling is correct here

The predicate is defined at lib/react_on_rails/utils.rb:216 and referenced in specs (e.g. spec/dummy/spec/system/integration_spec.rb:99, 118); no change required.

Likely an incorrect or invalid review comment.

@claude
Copy link

claude bot commented Sep 16, 2025

Code Review for PR #1783: Fix integration tests for immediate_hydration Pro license changes

Summary

This PR addresses test failures caused by the introduction of Pro license requirements for the immediate_hydration feature in PR #1781. The solution implements proper mocking and configuration management for two previously skipped system tests.

✅ Strengths

  1. Consistent Testing Pattern: The implementation uses a shared context pattern that aligns with existing test patterns in the codebase (as seen in react_on_rails_helper_spec.rb:91,399,415,431,etc.), maintaining consistency across the test suite.

  2. Proper Configuration Management: The around hook correctly restores the original configuration state after each test, preventing test pollution and ensuring test isolation.

  3. Clear Intent: The shared context name 'with pro features and immediate hydration' clearly communicates its purpose, making the tests more readable and maintainable.

  4. DRY Principle: Extracting the Pro feature setup into a reusable shared context eliminates code duplication and provides a single source of truth for this testing pattern.

🔍 Observations & Suggestions

  1. Test Coverage: Both tests now properly validate behavior with Pro features enabled. This ensures that Pro features work correctly in integration scenarios involving Turbolinks/Turbo navigation and TurboStream components.

  2. Mocking Strategy: The approach of stubbing ReactOnRails::Utils.react_on_rails_pro_licence_valid? is appropriate for integration tests, allowing them to test the actual behavior without requiring a valid Pro license.

  3. Configuration Reset: The use of an around hook to set and reset immediate_hydration is the correct approach, as it guarantees cleanup even if the test fails.

⚠️ Minor Considerations

  1. Documentation: Consider adding a comment in the shared context explaining why these specific tests require immediate hydration to be enabled (e.g., "These tests rely on immediate component hydration behavior that is now gated behind Pro features").

  2. Test Stability: Removing the skip statements and fixing the underlying issues is the right approach. The tests should now be more stable with deterministic hydration timing.

✅ Approval

This is a clean, focused fix that properly addresses the test failures introduced by the Pro license validation changes. The implementation follows established patterns in the codebase and maintains good testing practices.

The PR successfully:

  • Fixes the broken tests without modifying production code
  • Maintains test isolation through proper configuration management
  • Uses consistent mocking patterns found elsewhere in the test suite
  • Removes technical debt by un-skipping previously flaky tests

LGTM! 🚀

@claude
Copy link

claude bot commented Sep 16, 2025

Code Review for PR #1783: Fix integration tests for immediate_hydration Pro license changes

🎯 Overall Assessment

This PR effectively fixes the two integration tests that were broken by PR #1781's Pro license validation requirements. The solution is clean, well-structured, and follows existing patterns in the codebase.

✅ Strengths

  1. Consistent Pattern: The solution follows the exact same mocking pattern used in react_on_rails_helper_spec.rb, maintaining consistency across the test suite.

  2. Proper Test Isolation: Using a shared context with around hook ensures the configuration is properly reset after each test, preventing test pollution.

  3. Clear Intent: The shared context name "with pro features and immediate hydration" clearly communicates what the test setup does.

  4. Minimal Changes: The fix is surgical - only touching the necessary tests and removing the skip statements.

🔍 Code Quality Observations

Best Practices Followed:

  • ✅ Uses RSpec shared contexts appropriately
  • ✅ Properly resets configuration state with around hook
  • ✅ Follows existing mocking patterns from helper specs
  • ✅ Removes technical debt (unskipped tests)

Testing Approach:

  • The mocking of react_on_rails_pro_licence_valid? is appropriate for integration tests that need to test Pro features behavior without an actual license
  • Configuration toggling ensures tests run with the expected immediate hydration behavior

⚠️ Minor Considerations

  1. Documentation: Consider adding a brief comment in the shared context explaining why Pro license mocking is necessary for these specific tests.

  2. Alternative Approach: While the current approach works well, you could also consider using RSpec's stub_const or creating a test-specific configuration helper if more tests need this pattern in the future.

🔒 Security & Performance

  • No security concerns - this is test-only code
  • No performance impact - affects only test execution

✅ Test Coverage

  • Properly restores test coverage by re-enabling previously skipped tests
  • Tests now validate the immediate hydration behavior for both Turbolinks and TurboStream scenarios

🎯 Recommendation

APPROVED - This is a solid fix that addresses the immediate problem while maintaining code quality and consistency with existing patterns. The tests should now be stable and reliable.

Great work on quickly addressing the test failures introduced by the Pro license changes! 👍

Copy link
Collaborator

@AbanoubGhadban AbanoubGhadban left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@justin808 justin808 merged commit 3ed127f into master Sep 16, 2025
13 checks passed
@justin808 justin808 deleted the fix/integration-tests-immediate-hydration branch September 16, 2025 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants