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

Fixed Calling << to an ActiveModel::Errors deprecation warning #690

Merged

Conversation

dannytip
Copy link
Contributor

@dannytip dannytip commented Aug 8, 2023

Fixes #689

@dannytip
Copy link
Contributor Author

dannytip commented Aug 8, 2023

This is currently failing linting due to:

Metrics/AbcSize: Assignment Branch Condition size for get_error_messages is too high. [<3, 18, 6> 19.21/18]

Any suggestion on how to resolve that @lcreid ?

Copy link
Contributor

@lcreid lcreid left a comment

Choose a reason for hiding this comment

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

Thanks for submitting a PR. We should have a test that shows that this is fixed. I believe our test suite wasn't triggering this code before, which is why we never noticed the error. Do you have a test that can reproduce the error (before your fix) that we could add to our tests?

@lcreid
Copy link
Contributor

lcreid commented Aug 8, 2023

This is currently failing linting due to:

Metrics/AbcSize: Assignment Branch Condition size for get_error_messages is too high. [<3, 18, 6> 19.21/18]

Any suggestion on how to resolve that @lcreid ?

I wonder why that's come up for you? Perhaps that's why the original code used a temporary variable? For now, put # rubocop:disable Metrics/AbcSize at the start of the method, and # rubocop:enable Metrics/AbcSize at the end of the method.

@dannytip
Copy link
Contributor Author

dannytip commented Aug 8, 2023

@lcreid ive added a test case which triggers the warning when you change REQUIRED_RAILS_VERSION to v6.1.7.4 strangely you don't get the warning with rails v7.0.6.

Copy link
Contributor

@lcreid lcreid left a comment

Choose a reason for hiding this comment

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

This looks great. I'm interested in seeing your response to my comments before approving, but we should be good to go after that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the AddressesController and the routes for addresses?

object.class.try(:reflections)&.each do |association_name, a|
next unless a.is_a?(ActiveRecord::Reflection::BelongsToReflection)
next unless a.foreign_key == name.to_s

messages << object.errors[association_name]
object.errors[association_name].each do |error|
object.errors.add(name, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

I was intrigued by your comment that it didn't say anything at version 7. You would think it should have errored, if the deprecation warning was in 6.1. You're right. << seems to still work, and without a deprecation message. Very strange.

I was unable to get it to show me the deprecation message, even with version 6.1. (I tweaked the code to run your test case, but with the << operator instead of #add.) Also strange. At any time, did you see the deprecation warning when running the test you added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If i revert my changes to get_error_messages but leave the new testcase in place i get the following:

Screenshot 2023-08-10 at 09 28 03

@lcreid
Copy link
Contributor

lcreid commented Aug 10, 2023

Oops. Looks like the test fails on edge.

@dannytip
Copy link
Contributor Author

Oops. Looks like the test fails on edge.

It looks like it doesn't pick up that the relationship is required in rails 7.1. Possibly something in required_association?

Copy link
Contributor

@lcreid lcreid left a comment

Choose a reason for hiding this comment

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

Thanks for removing the unnecessary code.

We can merge this with failing tests in edge. I've created an issue for that failure. The issue has a lead about what may be the problem.

@lcreid lcreid merged commit 00b5ad2 into bootstrap-ruby:main Aug 12, 2023
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.

DEPRECATION WARNING: Calling << to an ActiveModel::Errors message array in order to add an error is deprecated
2 participants