test/client_test.rb in tracker_api-0.1.0 vs test/client_test.rb in tracker_api-0.2.0

- old
+ new

@@ -56,6 +56,40 @@ project.account.must_be_nil project.account_id.wont_be_nil end end end + + describe '.paginate' do + let(:pt_user) { PT_USER_1 } + let(:client) { TrackerApi::Client.new token: pt_user[:token] } + let(:project_id) { pt_user[:project_id] } + + it 'auto paginates when needed' do + VCR.use_cassette('client: get all stories with pagination', record: :new_episodes) do + project = client.project(project_id) + + # skip pagination with a hugh limit + unpaged_stories = project.stories(limit: 300) + unpaged_stories.wont_be_empty + unpaged_stories.length.must_be :>, 7 + + # force pagination with a small limit + paged_stories = project.stories(limit: 7) + paged_stories.wont_be_empty + paged_stories.length.must_equal unpaged_stories.length + paged_stories.map(&:id).sort.uniq.must_equal unpaged_stories.map(&:id).sort.uniq + 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) + + done_iterations = project.iterations(scope: :done, offset: -12, limit: 5) + + done_iterations.wont_be_empty + done_iterations.length.must_be :<=, 12 + end + end + end end