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

Fixes for errors in Rails/DeprecatedActiveModelErrorsMethods #739

Conversation

BrianHawley
Copy link
Contributor

@BrianHawley BrianHawley commented Jul 5, 2022

  • Fixed a NoMethodError on nil for errors.keys in a model.
  • Fixed a bad autocorrection of errors.details[:name] << value.
    There isn't really a replacement for this one.
  • The values, to_h, and to_xml methods are deprecated too.
  • Made the range calculation more exact so the replacement is easier.
  • Did some refactors prompted by rubocop complaints.
  • Fixed a misspelling of autocorrectable.
  • Added missing correction assertions to test cases.
  • Added missing test cases.

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

@BrianHawley
Copy link
Contributor Author

BrianHawley commented Jul 5, 2022

I added 3 changelog entries.

Basically, I went through the ActiveModel::Errors class, comparing Rails versions, and got a list of all the deprecated methods which weren't covered already, and added test cases for them. I also added correction assertions to all the test cases that didn't have them, and checked every correction to make sure that it generated code that would work. Then I fixed the cop class until the tests passed. I got the list of corrections needed from the tests that failed.

There's no check for errors.each do |key, value| because I don't know how to specify that. There's also a test case for which a better correction would exist, but I didn't want to add that in a bug fix PR.

- Fixed a NoMethodError on nil for `errors.keys` in a model.
- Fixed a bad autocorrection of `errors.details[:name] << value`.
  There isn't really a replacement for this one.
- The `values`, `to_h`, and `to_xml` methods are deprecated too.
- Made the range calculation more exact so the replacement is easier.
- Did some refactors prompted by rubocop complaints.
- Fixed a misspelling of autocorrectable.
- Added missing correction assertions to test cases.
- Added missing test cases.
@BrianHawley BrianHawley force-pushed the fix_rails_deprecated_active_model_errors_methods_errors_20220701 branch from 502e7b3 to c737e89 Compare July 5, 2022 18:39
@BrianHawley
Copy link
Contributor Author

You can do errors.add(:name, value) as a replacement for errors.messages[:name] << value but there's no equivalent action for errors.details[:name] << value without including the message, so it seemed safer to not correct it.

Maybe we should add an example of a correction using errors.add to replace both changing the messages and details?

@BrianHawley
Copy link
Contributor Author

BrianHawley commented Jul 5, 2022

@koic you did previous work on this class. Do you think you could review?

@koic
Copy link
Member

koic commented Jul 6, 2022

Can you separate the PR for each changelog entry? I think it can be separated into three PRs.

@BrianHawley
Copy link
Contributor Author

BrianHawley commented Jul 6, 2022

@koic I created #740, #741, and #742. After each is merged, I'll need to rebase the others, for the shared test code.

@BrianHawley BrianHawley closed this Jul 6, 2022
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