Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only include pagination total if ?total=true #240

Merged
merged 1 commit into from
Dec 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/concerns/json_collection_pagination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ def paginated_json_collection(collection, path_helper, offset, per_page, total,
# Meta
offset = (offset.presence || 0).to_i
per_page = (per_page.presence || self.class::PER_PAGE).to_i
total = total.present?
include_total = (total == true || total == 'true')
meta = {
offset: offset,
per_page: per_page
}
meta[:total] = collection.count if total
meta[:total] = collection.count if include_total

# Get the current page of results.
# Add +1 to limit to see if there is a next page.
Expand Down
10 changes: 10 additions & 0 deletions spec/controllers/json_collection_pagination_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ class FakeController < ApplicationController
per_page: 10
}
})

expect(
object.send(:paginated_json_collection, collection, path_helper, 0, 10, false, {})
).to eq({
json: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
meta: {
offset: 0,
per_page: 10
}
})
end

it 'has a next page' do
Expand Down