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

Fix Rails/HttpPositionalArguments offenses #957

Merged
merged 26 commits into from
May 30, 2022
Merged

Conversation

JoeCohen
Copy link
Member

This branch fixes all the Rails/HttpPositionalArguments offenses, including these auxiliary changes:

  • Removes mokey-patches that expedited those offenses;
  • Enables the Rails/HttpPositionalArguments cop

More details at MO Developers, ruby 2.7.6 and rails 6.1

There is no manual test -- all changes are in test, rather than app

JoeCohen and others added 9 commits May 28, 2022 10:06
Autocorrects all these offenses by running
```
rubocop -f html -o rubocop.html --only Rails/HttpPositionalArguments -a
```
Enables Rails/HttpPositionalArguments (plus other incidental changes)
Removes the monkey-patch added during the Rails 5.2 upgrade in order to avoid kwarg deprecation warnings
test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
@coveralls
Copy link
Collaborator

coveralls commented May 28, 2022

Coverage Status

Coverage remained the same at 93.065% when pulling 9021408 on joe-fix-test-kwargs into 319d80d on master.

@nimmolo
Copy link
Contributor

nimmolo commented May 28, 2022

@JoeCohen If this removes the use of check_for_params and extract_body maybe those methods should be deleted too.

I believe that fixing the kwarg issue for 2.7 will require further changes to functional_test_case methods, since they do not send the args to Rails test_case the way it wants them. Waiting for advice from Jason about that. But that should be a separate PR.

@JoeCohen
Copy link
Member Author

Thanks @nimmolo!
You're right about check_for_params and extract_body. I had it in mind to remove them (as part of removing the old monkey-patches), but then completely forgot to do that.
I'm interested in who you find out about the Ruby 2.7 kwargs warnings.

Deletes two methods which, due to prior commits in this branch, are no longer used.

Responds to #957 (comment)
test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
@JoeCohen
Copy link
Member Author

I'll get to work on the Codeclimate/RuboCop offenses. I'm not sure why there are so many of them.

test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/account_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/api_controller_test.rb Outdated Show resolved Hide resolved
@nimmolo
Copy link
Contributor

nimmolo commented May 28, 2022

@JoeCohen I think it's that your line length in VS Code is not set to 80? I am happy to open and save the file, that will fix it.

Also -- I believe I solved the kwargs issue once and for all. Pushed it to this branch.

Also -- fixed a rubocop "Prefer index_with to each_with_object in NameControllerTest just now.

test/controllers/api_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/api_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/api_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/api_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/collection_number_controller_test.rb Outdated Show resolved Hide resolved
@nimmolo
Copy link
Contributor

nimmolo commented May 28, 2022

Hi @JoeCohen -
I was mistaken, Rubocop doesn't do line length.
It's another setting: hit command-, for settings, then search for line length. You'll find it under HTML>Format: Wrap Line Length

Here are the configs to set up rubocop with VS Code, in case you need them
Screen Shot 2022-05-28 at 4 15 49 PM
.

@nimmolo
Copy link
Contributor

nimmolo commented May 28, 2022

There's one more kwarg thing to fix, in session_extensions.rb:104. Commit coming soon.

@JoeCohen
Copy link
Member Author

JoeCohen commented May 28, 2022 via email

Fixes remaining kwarg deprecations in session_extensions and controller_extensions.
Removes &block from args in functional_test_case (not used)
Fixes ApiControllerTest and Api2ControllerTest passing hashes instead of kwargs
test/controller_extensions.rb Show resolved Hide resolved
test/controller_extensions.rb Show resolved Hide resolved
test/controller_extensions.rb Show resolved Hide resolved
test/controllers/collection_number_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/collection_number_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/interest_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/interest_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/interest_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/interest_controller_test.rb Outdated Show resolved Hide resolved
test/controllers/interest_controller_test.rb Outdated Show resolved Hide resolved
test/session_extensions.rb Show resolved Hide resolved
test/session_extensions.rb Show resolved Hide resolved
@nimmolo
Copy link
Contributor

nimmolo commented May 29, 2022

@JoeCohen I believe this is now good to go. With respect to our calls to http get etc., I believe the "Rails/HttpPositionalArguments" cop is incorrect, as far as I can understand.

See the rails code here, scroll down to the get method etc. It seems to me it expects the args like we're sending them. Maybe it's a case of old rubocop?

@JoeCohen
Copy link
Member Author

JoeCohen commented May 29, 2022 via email

@nimmolo
Copy link
Contributor

nimmolo commented May 29, 2022

I'm not at home but thought of another consideration. When a test inherits from functional_test_case, which the tests that inherit from controller_extensions and session_extensions may or may not do, MO intercepts all calls to get etc to do our check_for_unsafe_html. These methods certainly expect get(action, **args) like the test_case classes they inherit from.

…rver/mushroom-observer into joe-fix-test-kwargs

# Conflicts:
#	test/controllers/account_controller_test.rb
#	test/controllers/api_controller_test.rb
#	test/controllers/collection_number_controller_test.rb
#	test/controllers/image_controller_test.rb
#	test/controllers/interest_controller_test.rb
#	test/controllers/location_controller_test.rb
#	test/controllers/naming_controller_test.rb
#	test/controllers/project_controller_test.rb
#	test/controllers/translation_controller_test.rb
@pellaea
Copy link
Member

pellaea commented May 29, 2022 via email

@nimmolo
Copy link
Contributor

nimmolo commented May 29, 2022

@pellaea - This PR fixes dozens of HttpPositionalArguments offenses, except for 5 in controller_extensions and session_extensions. I believe the cop is throwing a false positive in those.

The native Rails test_case method get(action, **args) expects a positional argument, plus however many kwargs. The cop complains when we send exactly that, from our own "get"-like (and "post"-like) methods (such as post_without_redirecting and reget). I don't know any way to solve it, but i'm no splat doctor.

@nimmolo
Copy link
Contributor

nimmolo commented May 29, 2022

PS - in case you're reading on email and didn't catch the typo i edited after sending, the native Rails method is of course get(action, **args) not get(action: **args). It is used like get(:show, params)

@JoeCohen
Copy link
Member Author

JoeCohen commented May 29, 2022 via email

@JoeCohen JoeCohen marked this pull request as draft May 29, 2022 12:33
@JoeCohen JoeCohen mentioned this pull request May 29, 2022
@nimmolo nimmolo mentioned this pull request May 29, 2022
@JoeCohen
Copy link
Member Author

I've resolved the conflicts locally, but am getting 18 errors.
I will push it with errors so that everyone can see what's going on.
I suspect that the changes I had are now incorrect in light of changes @nimmolo made on other branches.

@JoeCohen
Copy link
Member Author

Oh wait. I think I messed up the merger. I will try to fix it, then push if successful.

# Conflicts:
#	.rubocop_todo.yml
#	test/controllers/account_controller_test.rb
@JoeCohen JoeCohen marked this pull request as ready for review May 30, 2022 04:16
@JoeCohen
Copy link
Member Author

I'm done for tonight.
I'm fine with merging this.

@pellaea
Copy link
Member

pellaea commented May 30, 2022 via email

@codeclimate
Copy link
Contributor

codeclimate bot commented May 30, 2022

Code Climate has analyzed commit 9021408 and detected 0 issues on this pull request.

View more on Code Climate.

@nimmolo nimmolo merged commit 2c7eabc into master May 30, 2022
@JoeCohen JoeCohen deleted the joe-fix-test-kwargs branch June 6, 2022 00:24
@nimmolo
Copy link
Contributor

nimmolo commented Oct 11, 2022 via email

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

4 participants