Repository navigation
Fix request_path being replaced by a named route helper (supersedes #3) - #19
Merged
Merged
Conversation
A route like `resources :requests` generates a public `request_path` helper, and Rails includes the url_helpers module into controllers after resources_controller's modules (url_helpers sits at ancestor index 7, RequestPathIntrospection at 12, and the lower index wins). resources_controller's own request_path was therefore replaced by the route helper, so it read the helper's value instead of the path of the current request, and could not work out the enclosing resources: with a top level `resources :requests` route in the spec app, 6 examples in spec/lib/request_path_introspection_spec.rb fail. The internal reader is renamed to rc_request_path, so that no plausible route name can collide with it, and the specs are updated to match. Based on PR #3 by Robert Thau, which diagnosed this and proposed the same rename (as path_of_request) but is written against the pre-rename lib/ardes/ layout and RSpec 2 syntax, so it no longer applies. Adds a regression spec that includes a module defining a public request_path into the controller under test - the position url_helpers occupies - and asserts the path of the request is still read. Co-authored-by: DeepSeek <agent@deepseek.com>
v5.0.0 is tagged at the PR #18 merge, so the two changes that landed on master after the tag get their own section: this request_path fix, and the README.rdoc to README.md conversion (which was pushed in 1db30bb, after the tag). Bumps VERSION to 5.0.1 so that version.rb, the gemspec and the CHANGELOG agree. Co-authored-by: DeepSeek <agent@deepseek.com>
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.
Supersedes #3. The diagnosis is @rst's (Robert Thau's) — he reported this in 2010 with a patch that renamed the method to
path_of_request. This is that idea rebased onto the current code; the credit is his.The problem
resources :requestsgenerates a member route helper calledrequest_path. Rails includes the generatedurl_helpersmodule into controllers after resources_controller's modules, so it wins the method lookup:url_helpers(definesrequest_path)ResourcesController::RequestPathIntrospection(has its ownrequest_path)RequestPathIntrospectioncallsrequest_pathinternally (nesting_request_path,namespace_segments), so with such a route present it read the helper's value instead ofparams[:resource_path] || request.path. The real request path was lost, so enclosing resources were not detected — and the invented path was then fed to the wildcard loader, so unrelated controllers tried to load resources that were not part of the request.Measured on master (Ruby 4.0.7, Rails 8.1.4) with a top level
resources :requestsadded tospec/app.rb:spec/lib/request_path_introspection_spec.rbThe fix
RequestPathIntrospection#request_pathis renamed to#rc_request_path(its ivars with it), and the caller inraise_resource_mismatchis updated.#nesting_request_pathis left alone: no plausible route is named that.request_pathinto the controller under test — the positionurl_helpersoccupies — and asserts the path of the request is still read. It fails on master with "the shadowing route helper was called" and passes here.VERSIONis bumped to 5.0.1. The README.rdoc → README.md note moved there too, since that landed on master after the tag.Note for anyone overriding
request_path#request_pathwas protected and undocumented, but an app may have overridden it to customise the path; that no longer works. The documented mechanism is unchanged: pass:resource_pathin the route (see the docs inlib/resources_controller.rb), or override#rc_request_path.bundle exec rspec→ 667 examples, 0 failures, andgem buildproduces rc_rails-5.0.1 without warnings.