Skip to content

Commit b066645

Browse files
committed
Remove action, controller, format query parameters from page links
1 parent 0e560ca commit b066645

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/graphiti/delegates/pagination.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ def links
2020

2121
private
2222

23+
def pagination_params
24+
@pagination_params ||= @proxy.query.params.reject { |k, _| [:action, :controller, :format].include?(k) }
25+
end
26+
2327
def pagination_link(page)
2428
return nil unless @proxy.resource.endpoint
2529

2630
uri = URI(@proxy.resource.endpoint[:url].to_s)
2731

2832
# Overwrite the pagination query params with the desired page
29-
uri.query = @proxy.query.params.merge({
33+
uri.query = pagination_params.merge({
3034
page: {
3135
number: page,
3236
size: page_size

spec/delegates/pagination_spec.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,26 @@
5959
{include: "bar,bazzes", filter: {"bazzes.deprecated" => "foo"}}
6060
}
6161

62-
it "is preserved correctly" do
62+
it "preserves include directive and filters on relationships" do
6363
query = URI.decode_www_form(URI(subject[:first]).query).to_h
6464
expect(query["include"]).to include("bar")
6565
expect(query["include"]).to include("bazzes")
6666
expect(query["filter[bazzes.deprecated]"]).to eq("foo")
6767
end
6868
end
69+
70+
context "with rails parameters" do
71+
let(:params) {
72+
{controller: "foos", action: "index", format: "jsonapi"}
73+
}
74+
75+
it "removes them" do
76+
page_links = subject.values
77+
expect(page_links).to all(satisfy { |v| v["controller=foos"].nil? })
78+
expect(page_links).to all(satisfy { |v| v["action=index"].nil? })
79+
expect(page_links).to all(satisfy { |v| v["format=jsonapi"].nil? })
80+
end
81+
end
6982
end
7083

7184
def pagination_link(number, size: current_per_page)

0 commit comments

Comments
 (0)