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

[BUG FIX] Handles edge case where requested current_page > total_pages. #2399

Merged
merged 6 commits into from
Jan 3, 2021

Conversation

f3z0
Copy link

@f3z0 f3z0 commented Dec 2, 2020

Purpose

Fixes an edge case whereby the client requests a current_page > total_pages.

Changes

ActiveModelSerializers::Adapter::JsonApi::PaginationLinks#next_page_url should return nil if there is no next_page however if the client incorrectly requests a pager greater than the total number of pages it will return an invalid next_page. Also similarly if the current_page is greater than total pages the prev_page_url should return the last previous page with results which would be equivalent to last_page_url.

Caveats

None.

Related GitHub issues

Did not see any.

Additional helpful information

N/A

@f3z0
Copy link
Author

f3z0 commented Dec 4, 2020

@bf4 should I be concerned with the failing tests, they seem unrelated to my changes?

@wasifhossain
Copy link
Member

Hey @f3z0, could you please rebase your commit (df9b7a8) on top of 0-10-stable branch and push that commit here again. with that, I think Github Actions would be able to run the tests for your changes.

Thanks.

…ge is greater than total_pages

adding tests

fixing rubocop violation
@f3z0
Copy link
Author

f3z0 commented Jan 2, 2021

@wasifhossain strange I squashed rebased and force pushed and github actions did not change, codedclimate did not re-run as far as I can tell. Should I close this PR and reopen? Appreciate you helping me on this 🙏.

@wasifhossain
Copy link
Member

oh I am sorry in that case. let me do the reopening for you :)

@wasifhossain wasifhossain reopened this Jan 2, 2021
@wasifhossain
Copy link
Member

seems like it didn't help either. we might need to configure something in the ci file. will get back to you if we find something.

thanks for the PR 👍

@wasifhossain
Copy link
Member

@f3z0 I have made a small addition in the CI file, so hopefully tests will run now if you rebase your branch again. thanks

@f3z0
Copy link
Author

f3z0 commented Jan 2, 2021

@wasifhossain awesome that worked 🙏

@wasifhossain
Copy link
Member

tests look fine! could you please add a line in the changelog documenting this. thanks

@f3z0
Copy link
Author

f3z0 commented Jan 2, 2021

@wasifhossain yes absolutely, I've added under v0.10.12 fixes.

CHANGELOG.md Outdated
@@ -15,6 +15,7 @@ Misc:
Fixes:

- [#2398](https://github.com/rails-api/active_model_serializers/pull/2398) Update rails dependency to < 6.2 (@ritikesh)
- [#2399](https://github.com/rails-api/active_model_serializers/pull/2399) Handles edge case where requested current_page > total_pages (@f3z0)
Copy link
Member

Choose a reason for hiding this comment

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

as 0.10.12 has already been published, I guess this change would fit under Unreleased -> Fixes section.

Copy link
Author

Choose a reason for hiding this comment

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

Sorry about that, this makes more sense.

@wasifhossain
Copy link
Member

looks good to me! let's merge this 🙌

@wasifhossain wasifhossain merged commit 8f38571 into rails-api:0-10-stable Jan 3, 2021
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.

2 participants