-
-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding metadata to page iteration #342
Adding metadata to page iteration #342
Conversation
else | ||
chain.send(meth) | ||
chain.send(meth, &blk) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without this, the Model.each
et al returned an enumerable even if it was passed a block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
expect { |b| model.where(id: '1').find_by_pages(&b) }.to yield_successive_args( | ||
[all(be_kind_of(model)), {last_evaluated_key: an_instance_of(Hash)}], | ||
[all(be_kind_of(model)), {last_evaluated_key: nil}], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually testing the behavior here
end | ||
expect { |b| User.each(&b)}.to yield_successive_args( | ||
be_kind_of(User).and(have_attributes('new_record' => false)), | ||
be_kind_of(User).and(have_attributes('new_record' => false)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validating the yields
eb94f3a
to
9198801
Compare
match_array([{ name: 'Josh', id: '2' }, { name: 'Josh', id: '1' }]), | ||
{last_evaluated_key: nil} | ||
] | ||
]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add some specs for new behavior of query
/scan
- returning of non-nullable last_evaluated_key
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do have that expectation at a higher level for the find_by_pages
https://github.com/Dynamoid/dynamoid/pull/342/files#diff-de03691a59eb936547beef74a4f01686R963
I should be able to move that down to this level too.
first_page, first_page_meta = User.find_by_pages.first | ||
second_page, = User.start(first_page_meta[:last_evaluated_key]).find_by_pages.first | ||
|
||
expect(first_page & second_page).to be_empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andrykonchin This test paginates using the method described by the readme. The expectation is, a bit weird... Essentially ensuring we get a different set of records on each call.
Is this test also sufficient for the non-null last_evaluated_key or would you like me to write one down in the adapter too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's OK. Good job. Will review the PR a little bit later
Looks good 👍 |
Adds the metadata for each pages as a second parameter
find_by_pages
.While I was testing I also found a bug with all of the criteria delegation such as
Model.each
, and theModel.find_by_pages
method I added. The specs didn't catch it with mine becausematch_array
coerces it to an array. The test for criteria.each
method had a false positive because noexpect
was ever called.