Skip to content

Commit

Permalink
Change Datastore#next? to use NOT_FINISHED
Browse files Browse the repository at this point in the history
Change what check is made to paginate. Requested by the Datastore team.

[closes #793]
  • Loading branch information
blowmage committed Jul 25, 2016
1 parent 1666591 commit e5584e1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
10 changes: 10 additions & 0 deletions acceptance/datastore/datastore_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,16 @@
entities[2]["name"].must_equal arya["name"]
end

it "should paginate with all" do
query = Gcloud::Datastore::Query.new.
kind("Character").ancestor(book).
order("appearances")
entities = dataset.run(query).all.to_a
entities.count.must_equal 8
entities[0]["name"].must_equal rickard["name"]
entities[5]["name"].must_equal sansa["name"]
end

it "should resume from a start cursor" do
query = Gcloud::Datastore::Query.new.
kind("Character").ancestor(book).
Expand Down
2 changes: 1 addition & 1 deletion lib/gcloud/datastore/dataset/query_results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def initialize arr = []
# end
#
def next?
!no_more?
not_finished?
end

##
Expand Down
9 changes: 4 additions & 5 deletions test/gcloud/datastore/query_results/all_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
Google::Datastore::V1beta3::RunQueryResponse.new(
batch: Google::Datastore::V1beta3::QueryResultBatch.new(
entity_results: run_query_res_entities,
more_results: :MORE_RESULTS_AFTER_CURSOR,
more_results: :NOT_FINISHED,
end_cursor: "second-page-cursor".force_encoding("ASCII-8BIT")
)
)
Expand Down Expand Up @@ -101,10 +101,10 @@
end
first_entities.cursor.must_equal Gcloud::Datastore::Cursor.from_grpc("second-page-cursor")
first_entities.end_cursor.must_equal Gcloud::Datastore::Cursor.from_grpc("second-page-cursor")
first_entities.more_results.must_equal :MORE_RESULTS_AFTER_CURSOR
refute first_entities.not_finished?
first_entities.more_results.must_equal :NOT_FINISHED
assert first_entities.not_finished?
refute first_entities.more_after_limit?
assert first_entities.more_after_cursor?
refute first_entities.more_after_cursor?
refute first_entities.no_more?

assert first_entities.next?
Expand Down Expand Up @@ -137,7 +137,6 @@
refute next_entities.next?
end


it "run will fulfill a query and return an object that can paginate with all" do
entities = dataset.run dataset.query("Task")
entities.all.each do |entity|
Expand Down
4 changes: 2 additions & 2 deletions test/gcloud/datastore/query_results/all_with_more_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
Google::Datastore::V1beta3::RunQueryResponse.new(
batch: Google::Datastore::V1beta3::QueryResultBatch.new(
entity_results: run_query_res_entities,
more_results: :MORE_RESULTS_AFTER_CURSOR,
more_results: :NOT_FINISHED,
end_cursor: "second-page-cursor".force_encoding("ASCII-8BIT")
)
)
Expand All @@ -64,7 +64,7 @@
Google::Datastore::V1beta3::RunQueryResponse.new(
batch: Google::Datastore::V1beta3::QueryResultBatch.new(
entity_results: run_query_res_entities,
more_results: :MORE_RESULTS_AFTER_CURSOR,
more_results: :NOT_FINISHED,
end_cursor: "third-page-cursor".force_encoding("ASCII-8BIT")
)
)
Expand Down

0 comments on commit e5584e1

Please sign in to comment.