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

activemodel: ActiveModel::Errors#add accepts String and Proc for type #717

Merged
merged 4 commits into from
Dec 31, 2024

Conversation

sanfrecce-osaka
Copy link
Contributor

The behavior of passing String or Proc for type should be allowed.

FYI: It is documented in 6.1, but It is already available in 6.0.

cf. rails/rails@fcd1e41#diff-4deafad6fefcf6aa6626a1f7e3cd0ca1cf95e358f55a10a69e02be84d926bb31R368-R374

cf. rails/rails@d9011e3#diff-4deafad6fefcf6aa6626a1f7e3cd0ca1cf95e358f55a10a69e02be84d926bb31R370

Also, the name of the second argument was changed from message to type in 6.1.

Copy link

@sanfrecce-osaka Thanks for your contribution!

Please follow the instructions below for each change.
See also: https://github.com/ruby/gem_rbs_collection/blob/main/docs/CONTRIBUTING.md

Available commands

You can use the following commands by commenting on this PR.

  • /merge: Merge this PR if CI passes

activemodel

You changed RBS files for an existing gem.
You need to get approval from the reviewers of this gem.

@hibariya, @ksss, @tk0miya, please review this pull request.
If this change is acceptable, please make a review comment including APPROVE from here.
Screen Shot 2024-03-19 at 14 13 36

After that, the PR author or the reviewers can merge this PR.
Just comment /merge to merge this PR.

@sanfrecce-osaka sanfrecce-osaka force-pushed the fix-activemodel-errors-add branch from d783e3c to 0b39c22 Compare November 10, 2024 15:12
… type

The behavior of passing String or Proc for type should be allowed.

FYI: It is documented in 6.1, but It is already available in 6.0.

cf. rails/rails@fcd1e41#diff-4deafad6fefcf6aa6626a1f7e3cd0ca1cf95e358f55a10a69e02be84d926bb31R368-R374

cf. rails/rails@d9011e3#diff-4deafad6fefcf6aa6626a1f7e3cd0ca1cf95e358f55a10a69e02be84d926bb31R370

Also, the name of the second argument was changed from `message` to `type` in 6.1.
@sanfrecce-osaka sanfrecce-osaka force-pushed the fix-activemodel-errors-add branch from 0b39c22 to fe5bb2d Compare November 10, 2024 15:51
# # => {:base=>["either name or email must be present"]}
# person.errors.details
# # => {:base=>[{error: :name_or_email_blank}]}
def add: (untyped attribute, ?::Symbol | ::String | ^(untyped base, ::Hash[untyped, untyped]) -> (::Symbol | ::String) type, ?::Hash[untyped, untyped] options) -> void
Copy link
Collaborator

Choose a reason for hiding this comment

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

What makes you think return type should be void instead of ActiveModel::Error?

Copy link
Contributor Author

@sanfrecce-osaka sanfrecce-osaka Nov 24, 2024

Choose a reason for hiding this comment

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

Thank you for your feedback.
ActiveModel::Error was added on 6.1.

cf. rails/rails@ef68d3e

On 6.1 or later, ActiveModel::Errors#add returns ActiveModel::Error.
On the other hand, ActiveModel::Errors#add returns messages array on rails 6.0, because last evaluated is Array#<<.

cf. https://github.com/rails/rails/blob/v6.0.0/activemodel/lib/active_model/errors.rb#L311-L322

Currently in gem_rbs_collection, activemodel type definitions are defined 6.0 and 7.0, but not 6.1.

cf. #615

So I fixed them on 174b6ce

…o 6.0 and 7.0

ActiveModel::Error was added on 6.1.

cf. rails/rails@ef68d3e

On 6.1 or later, ActiveModel::Errors#add returns ActiveModel::Error.

On the other hand, `ActiveModel::Errors#add` returns messages array on rails 6.0, because last evaluated is `Array#<<`.

cf. https://github.com/rails/rails/blob/v6.0.0/activemodel/lib/active_model/errors.rb#L311-L322

Currently in gem_rbs_collection, activemodel type definitions are defined 6.0 and 7.0, but not 6.1.

cf. ruby#615

So I divide type definition of ActiveModel::Errors#add to 6.0 and 7.0.
@sanfrecce-osaka sanfrecce-osaka force-pushed the fix-activemodel-errors-add branch from 4981ed6 to 174b6ce Compare November 24, 2024 04:34
Copy link
Collaborator

@ksss ksss left a comment

Choose a reason for hiding this comment

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

APPROVE

Copy link

Thanks for your review, @ksss!

@sanfrecce-osaka, @ksss This PR is ready to be merged.
Just comment /merge to merge this PR.

…ors-add

# Conflicts:
#	gems/activemodel/6.0/activemodel-6.0.rbs
@sanfrecce-osaka
Copy link
Contributor Author

/merge

Copy link

/merge command failed.

This PR is not approved yet by the reviewers. Please get approval from the reviewers.

See the Actions tab for detail.

@sanfrecce-osaka
Copy link
Contributor Author

@ksss

Sorry, I resolved conflict. Please re-review 🙏 🙏 🙏

Copy link
Collaborator

@ksss ksss left a comment

Choose a reason for hiding this comment

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

APPROVE

Copy link

Thanks for your review, @ksss!

@sanfrecce-osaka, @ksss This PR is ready to be merged.
Just comment /merge to merge this PR.

@sanfrecce-osaka
Copy link
Contributor Author

/merge

@github-actions github-actions bot merged commit 09beb21 into ruby:main Dec 31, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants