-
Notifications
You must be signed in to change notification settings - Fork 122
Fix type signature for ActiveRecord::Base.validate
(to better support official Ruby documentation)
#859
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
base: main
Are you sure you want to change the base?
Conversation
@yuzisee Thanks for your contribution! Please follow the instructions below for each change. Available commandsYou can use the following commands by commenting on this PR.
|
ActiveRecord::Base.validate
(to match official Ruby documentation)ActiveRecord::Base.validate
(to better support official Ruby documentation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Could you check the errors in CI? I'll merge this after CI passed.
…mbining-validation-conditions In the official documentation, you can have `if: [Proc.new { |c| c.market.retail? }, :desktop?],` so, RBS signatures should reflect that
…ntax in the official Rails documentation
https://github.com/ruby/rbs/blob/1b186a3e9379bbe26f786c153f616d3215e52b37/docs/syntax.md?plain=1#L218 and give some types for completeness
…thod Error: activerecord.rb:1:6: [error] Cannot find implementation of method `::TestCallbackObject#local_condition2` │ Diagnostic ID: Ruby::MethodDefinitionMissing │ └ class TestCallbackObject < ActiveRecord::Base ~~~~~~~~~~~~~~~~~~ Error: activerecord.rb:1:6: [error] Cannot find implementation of method `::TestCallbackObject#local_condition3` │ Diagnostic ID: Ruby::MethodDefinitionMissing │ └ class TestCallbackObject < ActiveRecord::Base ~~~~~~~~~~~~~~~~~~ Detected 3 problems from 1 file
But when did `Proc` set a different type than `^(T) [self: T] -> boolish` Is this a **steep 1.10** vs. **steep 1.5** thing?
Otherwise https://github.com/ruby/gem_rbs_collection/blob/058aa1cbedb1a80b83e53e45272f8dca2b2d616e/bin/check-untyped-call.rb#L32 will complain and there's nothing we can do about it?
…n/blob/058aa1cbedb1a80b83e53e45272f8dca2b2d616e/gems/activemodel/6.0/activemodel.rbs#L254 via https://github.com/ruby/gem_rbs_collection/blob/058aa1cbedb1a80b83e53e45272f8dca2b2d616e/gems/activerecord/6.0/activerecord.rbs#L10 Consider that ```rb User.first.method(:errors).source_location ``` gives ["/usr/local/bundle/gems/activemodel-6.0.6.1/lib/active_model/validations.rb", 301]
…::Symbol, ^(::TestCallbackObject) [self: ::TestCallbackObject] -> bool, ::Proc]` to a constant of type `[::Symbol, ^(::TestCallbackObject) [self: ::TestCallbackObject] -> bool, ^(::TestCallbackObject) [self: ::TestCallbackObject] -> bool]` │ [::Symbol, ^(::TestCallbackObject) [self: ::TestCallbackObject] -> bool, ::Proc] <: [::Symbol, ^(::TestCallbackObject) [self: ::TestCallbackObject] -> bool, ^(::TestCallbackObject) [self: ::TestCallbackObject] -> bool] │ ::Proc <: ^(::TestCallbackObject) [self: ::TestCallbackObject] -> bool │ │ Diagnostic ID: Ruby::IncompatibleAssignment │ └ RAILS_60_DOCS_EXAMPLE = ~~~~~~~~~~~~~~~~~~~~~~~
…ons.md We need to solve """ 1 method call with untyped receiver detected from activerecord.rb. Please assign the expected type to the receiver """
[true, false].sample | ||
end | ||
|
||
# https://guides.rubyonrails.org/v6.0/active_record_validations.html#combining-validation-conditions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tk0miya Okay! Tests are passing now.
I saw that #788 defined https://github.com/ruby/gem_rbs_collection/blob/e027cca6e68bc51ed5676638bfa9e65f885bf6d2/gems/activerecord/README.md but would you be okay merging this pull request into master first, since we started this before #863 was created?
I can make a follow-up pull request to bring everything to 8.0 afterward.
Thanks!
…ross all versions (6.0, 6.1, 7.0, 7.1, 7.2, 8.0) We found these cleanups during ruby#859 but following ruby#788 → ruby#863 there is an initiative to simplify ActiveRecord maintenance. This streamlines a few things across all versions to make it easier to maintain. Ideally after ruby#859 is merged, we can transfer those tests up to 8.0 as well.
According to https://guides.rubyonrails.org/v6.0/active_record_validations.html#combining-validation-conditions
the official documentation says you can have
if: [Proc.new { |c| c.market.retail? }, :desktop?],
so, RBS signatures should reflect that.