Skip to content
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: 3 additions & 1 deletion lib/garb/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def all_results(profile, options = {})
options[:offset] = next_offset

break if limit && results.size >= limit
break if next_offset > results.total_results
# without a known total, a short page means there is nothing more to fetch

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [82/80]

total = results.total_results
break if total ? next_offset > total : rs.size < options[:limit]

options[:limit] = page_size(limit, results.size)
end
Expand Down
7 changes: 7 additions & 0 deletions test/unit/garb/model_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ class ModelTest < MiniTest::Unit::TestCase
end
end

should 'stop at a short page when the total is unknown' do
@results.total_results = nil
results = @test_model.all_results(@profile)
assert_equal @results.to_a, results.to_a
assert_received(Request::Data, :new) { |e| e.once }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/SymbolProc: Pass &:once as an argument to assert_received instead of a block.

end

context 'when fetching all pages from an offset' do
setup do
@rows = (11..25).map { |i| "result ##{i}" }
Expand Down