Repository navigation
Build the has_one child path from the parent's prefix - #479
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
When the associated class is not a singleton, `has_one` fetched the
record from `"/#{collection_name}/#{id}/#{name}.json"`. The leading `/`
replaces the path of the parent's `site` when the connection merges it,
and the parent's prefix options are never applied. For a parent with
`self.site = "http://example.com/api/v1"`, `post.author` requested
`/posts/1/author.json` instead of `/api/v1/posts/1/author.json`, and a
nested parent such as `/posts/:post_id/comments` requested
`/comments/1/author.json`.
Build the path from `prefix(prefix_options)`, like `element_path` and
custom methods do, and encode the id as a path segment.
This branch has not been deployed
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.
Summary
When the associated class is not a singleton,
has_onefetches the record from"/#{collection_name}/#{id}/#{name}.json". The connection merges that absolute path intosite, so the path of the parent'ssiteis lost, and the parent's prefix options are never applied.This change builds the path from
self.class.prefix(prefix_options), the same wayelement_pathand custom methods build theirs, and encodes the id withERB::Util.url_encodeto matchelement_path.Fixes #334. Earlier attempts (#300, #333) were closed as stale without review.
Tests
Two tests in
test/cases/base_test.rbcover a parentsitewith a path and a parent with a prefix parameter. Both fail onmainwithActiveResource::InvalidRequestErrorfor the wrong URL and pass with this change.bundle exec rake testandrubocoppass.