Skip to content

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

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

yuzisee
Copy link
Contributor

@yuzisee yuzisee commented May 18, 2025

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.

Copy link

@yuzisee 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

activerecord

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

@hibariya, @ksss, @Little-Rubyist, @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.

@yuzisee yuzisee changed the title Fix type signature for ActiveRecord::Base.validate (to match official Ruby documentation) Fix type signature for ActiveRecord::Base.validate (to better support official Ruby documentation) May 18, 2025
Copy link
Contributor

@tk0miya tk0miya left a 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.

yuzisee added a commit to yuzisee/gem_rbs_collection_edits that referenced this pull request May 18, 2025
yuzisee added 9 commits June 4, 2025 11:10
…mbining-validation-conditions

In the official documentation, you can have `if: [Proc.new { |c| c.market.retail? }, :desktop?],` so, RBS signatures should reflect that
…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?
@yuzisee yuzisee force-pushed the yuzisee-patch-1 branch from 9e111f0 to f74a06e Compare June 4, 2025 18:13
@yuzisee yuzisee force-pushed the yuzisee-patch-1 branch from f6a5e30 to 4ea2426 Compare June 4, 2025 18:31
yuzisee added 6 commits June 4, 2025 11:39
…::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
Copy link
Contributor Author

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!

yuzisee added a commit to yuzisee/gem_rbs_collection_edits that referenced this pull request Jun 4, 2025
…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#788ruby#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.
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