Skip to content

Commit

Permalink
activerecord: Add types for create_with to singleton that inherited a…
Browse files Browse the repository at this point in the history
  • Loading branch information
dak2 committed Dec 28, 2024
1 parent ccbd2bb commit 0cdedb4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gems/activerecord/6.0/_test/activerecord-generated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Article < ActiveRecord::Base
User.in_order_of(:id, [1, 5, 3])
User.offset(5).limit(10)
User.count
User.create_with(name: 'name', age: 1)
User.create_with(nil)

t = User.arel_table
User.limit(10).select(:id, "name", t[:age].as("years"), t[:email])
1 change: 1 addition & 0 deletions gems/activerecord/6.0/activerecord.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module ActiveRecord
def self.create!: (**untyped) -> instance
def self.validate: (*untyped, ?if: condition[instance], ?unless: condition[instance], **untyped) -> void
def self.validates: (*untyped, ?if: condition[instance], ?unless: condition[instance], **untyped) -> void
def self.create_with: (nil | Hash[untyped, untyped]) -> Relation

# callbacks
type callback[T] = Symbol | ^(T) [self: T] -> void
Expand Down
2 changes: 2 additions & 0 deletions gems/activerecord/6.1/_test/activerecord-6.1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
User.strict_loading(false)
user.strict_loading!
user.strict_loading?
User.create_with(secret: 'secret', key: 'key')
User.create_with(nil)
2 changes: 2 additions & 0 deletions gems/activerecord/7.0/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Article < ActiveRecord::Base
User.upsert_all([{ id: 1, name: 'James' }], returning: %i[id name], unique_by: :id, record_timestamps: true)
User.strict_loading
User.strict_loading(false)
User.create_with(name: 'name', age: 1)
User.create_with(nil)
user = User.new(secret: 'dummy', key: 'dummy', token: 'dummy', phrase: 'dummy')
user.encrypt
user.encrypted_attribute?(:secret)
Expand Down
2 changes: 2 additions & 0 deletions gems/activerecord/7.1/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class Article < ActiveRecord::Base
User.with(admin_users: User.where(role: 0))
User.strict_loading
User.strict_loading(false)
User.create_with(name: 'name', age: 1)
User.create_with(nil)
user = User.new(secret: 'dummy', key: 'dummy', token: 'dummy', phrase: 'dummy')
user.encrypt
user.encrypted_attribute?(:secret)
Expand Down
2 changes: 2 additions & 0 deletions gems/activerecord/7.2/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Article < ApplicationRecord
User.with(admin_users: User.where(role: 0))
User.strict_loading
User.strict_loading(false)
User.create_with(name: 'name', age: 1)
User.create_with(nil)
user = User.new(secret: 'dummy', key: 'dummy', token: 'dummy', phrase: 'dummy')
user.encrypt
user.encrypted_attribute?(:secret)
Expand Down

0 comments on commit 0cdedb4

Please sign in to comment.