Skip to content
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

Merged
merged 3 commits into from Apr 14, 2019

Conversation

arjes
Copy link

@arjes arjes commented Apr 9, 2019

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 the Model.find_by_pages method I added. The specs didn't catch it with mine because match_array coerces it to an array. The test for criteria .each method had a false positive because no expect was ever called.

else
chain.send(meth)
chain.send(meth, &blk)
Copy link
Author

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.

Copy link
Member

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}],
)
Copy link
Author

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))
Copy link
Author

Choose a reason for hiding this comment

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

Validating the yields

@arjes arjes force-pushed the add_metadata_to_page_iterator branch from eb94f3a to 9198801 Compare April 10, 2019 00:55
match_array([{ name: 'Josh', id: '2' }, { name: 'Josh', id: '1' }]),
{last_evaluated_key: nil}
]
])
Copy link
Member

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?

Copy link
Contributor

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
Copy link
Author

@arjes arjes Apr 14, 2019

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?

Copy link
Member

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

@andrykonchin
Copy link
Member

Looks good 👍
Thank you for the contribution

@andrykonchin andrykonchin merged commit 930dc3e into Dynamoid:master Apr 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants