Skip to content

15 minute fix: Add default argument to JsonApiSortParam#13369

Merged
citizen428 merged 2 commits intomasterfrom
citizen428/update-json-api-sort-param
Apr 14, 2021
Merged

15 minute fix: Add default argument to JsonApiSortParam#13369
citizen428 merged 2 commits intomasterfrom
citizen428/update-json-api-sort-param

Conversation

@citizen428
Copy link
Contributor

@citizen428 citizen428 commented Apr 13, 2021

What type of PR is this? (check all applicable)

  • Refactor

Description

I recently added the JsonApiSortParam concern. However, the included parse_sort_param method always required the param string to be passed it explicitly. Given that is a controller concern we can assume that a params method will always be available in the including scope, so I'm using this as the default now.

Related Tickets & Documents

n/a

QA Instructions, Screenshots, Recordings

Refactoring only, specs should still pass

UI accessibility concerns?

n/a

Added tests?

  • Yes

[Forem core team only] How will this change be communicated?

  • This change does not need to be communicated, and this is why not: refactoring, no user-facing changes

@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Apr 13, 2021
@citizen428 citizen428 requested review from a team, Zhao-Andy and djuber and removed request for a team April 13, 2021 07:03
Copy link
Contributor

@rhymes rhymes left a comment

Choose a reason for hiding this comment

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

Make sense! Give it to Rails that instantiates a new controller each request :D

@pr-triage pr-triage bot added PR: partially-approved bot applied label for PR's where a single reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Apr 13, 2021
RSpec.describe JsonApiSortParam do
let!(:controller) { Class.new { include JsonApiSortParam }.new }
let!(:controller) do
Class.new(Api::V0::ApiController) { include JsonApiSortParam }.new
Copy link
Contributor

Choose a reason for hiding this comment

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

this change was required (instead of Class.new) since you're now relying on Controller behavior, like having a params method. Makes sense.

The existing tests (with an explicit param string) were left unchanged - also makes sense.

Copy link
Contributor Author

@citizen428 citizen428 Apr 14, 2021

Choose a reason for hiding this comment

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

Yes, I wanted to test both the default and explicit param cases and the explicit params are also easier to test so I didn't want to go and change existing tests to an IMO less readable form.

@citizen428 citizen428 merged commit dc16b94 into master Apr 14, 2021
@citizen428 citizen428 deleted the citizen428/update-json-api-sort-param branch April 14, 2021 03:32
@pr-triage pr-triage bot added PR: merged bot applied label for PR's that are merged and removed PR: partially-approved bot applied label for PR's where a single reviewer approves changes labels Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: merged bot applied label for PR's that are merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants