From c7e606a5d69ba197e51350d3b4f54ec62c626c23 Mon Sep 17 00:00:00 2001 From: Forest Carlisle Date: Sat, 18 Oct 2014 17:19:24 -0700 Subject: [PATCH] Fixes #13 - make it possible to pass auto_paginate: false per request. * For time when you want a small subset of the results. --- lib/tracker_api/client.rb | 3 ++- test/client_test.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/tracker_api/client.rb b/lib/tracker_api/client.rb index 5f55a6b..531dd07 100644 --- a/lib/tracker_api/client.rb +++ b/lib/tracker_api/client.rb @@ -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? diff --git a/test/client_test.rb b/test/client_test.rb index 1f49254..ed9999c 100644 --- a/test/client_test.rb +++ b/test/client_test.rb @@ -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)