Sanitise pagination input for new API

This commit is contained in:
Maikel Linke
2022-02-15 13:17:31 +11:00
parent 75fc35574e
commit b89715149c
2 changed files with 6 additions and 3 deletions

View File

@@ -53,7 +53,7 @@ module JsonApiPagination
end
def current_page
params[:page] || 1
(params[:page] || 1).to_i
end
def total_pages

View File

@@ -73,11 +73,14 @@ describe "Customers", type: :request do
describe "pagination" do
it "renders the first page" do
pending "pagination logic compares string with integer"
get "/api/v1/customers", params: { page: "1" }
expect(json_response_ids).to eq [customer1.id.to_s, customer2.id.to_s]
end
it "renders the second page" do
get "/api/v1/customers", params: { page: "2", per_page: "1" }
expect(json_response_ids).to eq [customer2.id.to_s]
end
end
post "Create customer" do