Skip to content

Commit

Permalink
fix(CE): pagination fix for empty data (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
afthabvp authored and developer-united committed Dec 19, 2024
1 parent 798e4f4 commit 64a24fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions server/config/initializers/custom_pagination_links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def pages_from
{}.tap do |pages|
pages[:first] = FIRST_PAGE
pages[:prev] = first_page? ? nil : collection.current_page - FIRST_PAGE
pages[:next] = last_page? ? nil : collection.current_page + FIRST_PAGE
pages[:last] = collection.total_pages
pages[:next] = (!last_page? && collection.total_pages > 1) ? collection.current_page + FIRST_PAGE : nil
pages[:last] = [collection.total_pages, FIRST_PAGE].max
end
end

Expand Down
12 changes: 12 additions & 0 deletions server/spec/requests/api/v1/models_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@
expect(response_hash.dig(:links, :first)).to include("http://www.example.com/api/v1/models?page=1&per_page=20")
end

it "returns success and no models when the data is empty" do
workspace.models.destroy_all
get "/api/v1/models", headers: auth_headers(user, workspace_id)
expect(response).to have_http_status(:ok)
response_hash = JSON.parse(response.body).with_indifferent_access
expect(response_hash[:data].count).to eql(0)
expect(response_hash.dig(:links, :first)).to include("http://www.example.com/api/v1/models?page=1")
expect(response_hash.dig(:links, :last)).to include("http://www.example.com/api/v1/models?page=1")
expect(response_hash.dig(:links, :next)).to be_nil
expect(response_hash.dig(:links, :prev)).to be_nil
end

it "returns success and all mode for viewer role" do
workspace.workspace_users.first.update(role: viewer_role)
get "/api/v1/models", headers: auth_headers(user, workspace_id)
Expand Down

0 comments on commit 64a24fb

Please sign in to comment.