Skip to content

Commit

Permalink
Fixes #13 - make it possible to pass auto_paginate: false per request.
Browse files Browse the repository at this point in the history
   * For time when you want a small subset of the results.
  • Loading branch information
forest committed Oct 19, 2014
1 parent 7aa439b commit c7e606a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/tracker_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ def get(path, options = {})
# @return [Array]
def paginate(path, options = {}, &block)
opts = parse_query_and_convenience_headers path, options.dup
auto_paginate = opts[:params].delete(:auto_paginate) { |k| @auto_paginate }
@last_response = request :get, opts
data = @last_response.body
raise TrackerApi::Errors::UnexpectedData, 'Array expected' unless data.is_a? Array

if @auto_paginate
if auto_paginate
pager = Pagination.new @last_response.headers

while pager.more?
Expand Down
11 changes: 11 additions & 0 deletions test/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@
end
end

it 'allows auto pagination to be turned off when just a subset of a list is desired' do
VCR.use_cassette('client: get limited stories with no pagination', record: :new_episodes) do
project = client.project(project_id)

# force no pagination
stories = project.stories(limit: 7, auto_paginate: false)
stories.wont_be_empty
stories.length.must_equal 7
end
end

it 'can handle negative offsets' do
VCR.use_cassette('client: done iterations with pagination', record: :new_episodes) do
project = client.project(project_id)
Expand Down

0 comments on commit c7e606a

Please sign in to comment.