-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Added test current_page for array when page 1 per 0 #1002
Conversation
Could you elaborate on why you are sending this PR? |
@yuki24 sorry, tests didn't run locally. And I have a problem with current_page when use limit(0) |
@yuki24 In tests I wanted to reproduce the problem |
@yuki24, Could you please clarify behaviour of pagination when per = 0.
Why It seems it is possible to avoid such kind of exceptions, without impact. Client could handle result as no items, i.e total_pages = 0. |
@@ -61,6 +61,8 @@ def assert_blank_array_page(arr) | |||
|
|||
test 'page 1 per 0' do | |||
assert_equal 0, @array.page(1).per(0).count | |||
assert_equal 1, @array.page(1).per(0).current_page |
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 also add a test with page number 2?
assert_equal 2, @array.page(2).per(0).current_page
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.
ok
@@ -61,6 +61,8 @@ def assert_blank_array_page(arr) | |||
|
|||
test 'page 1 per 0' do | |||
assert_equal 0, @array.page(1).per(0).count | |||
assert_equal 1, @array.page(1).per(0).current_page | |||
assert_equal 1, @array.page(1).per(0).total_pages |
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 don't think this spec makes sense since it is mathematically impossible to define what total_pages
is in case of per(0)
and it would make the definition of total_pages
ambiguous.
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.
You're right
First of all, we may be deprecating the To answer your question, Also, what are the reasons why you have to pass in |
I agree, it is unusual case for pure pagination logic. We have API with aggregations, similar to elasticsearch aggregations https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html Example: with result: {
"items": [
{"city": "Tokyo"}
],
"aggregations": {
"city": ["Tokyo", "Kyoto"]
},
"metadata": {
"total_pages": 2,
"current_page": 1
}
} Using such API, client is getting items and list of aggregations data per filter at once. Use case:
Sometimes client wants only aggregations, without items. |
I wanted to check in and see how this is going. I think @solutus's use case is legit and I am open to changing the behavior here. However, the failing builds should be fixe and new tests should be added to demonstrate the point of the change. |
I'd be happy to take another look at this pull request, but there doesn't seem to be a lot of activity here. I'll close this issue in the coming weeks if there are no more updates |
No description provided.