Skip to content

Commit

Permalink
fix: prevent :id stripping when :id not in path (#447)
Browse files Browse the repository at this point in the history
Address edge case where ResourceName.find({id: id}) would error if controller was set up as a show action
  • Loading branch information
doublevoid committed Mar 18, 2024
1 parent c79b4dc commit e1dd811
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/graphiti/resource/links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def allow_request?(request_path, params, action)
path = request_path
if [:update, :show, :destroy].include?(context_namespace) && has_id
path = request_path.split("/")
path.pop
path.pop if path.last == has_id.to_s
path = path.join("/")
end
e[:full_path].to_s == path && e[:actions].include?(context_namespace)
Expand Down
13 changes: 13 additions & 0 deletions spec/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,19 @@ def self.name
end
end
end

# singular resource with singular route
context "that is a singular show route without an id but finding the resource by id" do
before do
request.env["PATH_INFO"] += ""
end

it "works" do
Graphiti.with_context ctx, :show do
expect { klass.find(id: 123) }.to_not raise_error
end
end
end
end

context "and the request matches a secondary endpoint" do
Expand Down

0 comments on commit e1dd811

Please sign in to comment.