Fix ViewRendering after hook wiping controller view_paths when controller is nil in before hook#2897
Open
krtierney wants to merge 1 commit into
Conversation
c1a18ce to
a5a0c89
Compare
…ller is nil in before hook The `render_views?` instance method returns different values in the `before` and `after` hooks when `controller` changes between them. This happens in request specs where `controller` is nil before the first request but set to a real controller instance afterwards: - `before`: controller is nil → NilClass doesn't respond_to?(:view_paths) → render_views? returns true → skips saving @_original_path_set - `after`: controller is set → controller.class responds_to?(:view_paths) → render_views? returns false → restores @_original_path_set (nil) → wipes controller.class.view_paths to an empty PathSet This class-level mutation persists across examples, causing ActionView::MissingTemplate errors in subsequent tests that depend on the same controller class having valid view paths. The fix adds a nil guard on @_original_path_set in the after hook so the restore only runs when the before hook actually saved the paths. Fixes rspec#2602
a5a0c89 to
6e4aa2a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
render_views?instance method returns different values in thebeforeandafterhooks whencontrollerchanges between them. This happens in request specs wherecontrolleris nil before the first request but set to a real controller instance afterwards:before: controller is nil → NilClass doesn't respond_to?(:view_paths) → render_views? returns true → skips saving @_original_path_setafter: controller is set → controller.class responds_to?(:view_paths) → render_views? returns false → restores @_original_path_set (nil) → wipes controller.class.view_paths to an empty PathSetThis class-level mutation persists across examples, causing ActionView::MissingTemplate errors in subsequent tests that depend on the same controller class having valid view paths.
The fix adds a nil guard on @_original_path_set in the after hook so the restore only runs when the before hook actually saved the paths.
Fixes #2602