Skip to content

Commit

Permalink
activerecord: Add types for strict_loading (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
dak2 authored Dec 25, 2024
1 parent 7a0046f commit ccbd2bb
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gems/activerecord/6.1/_test/activerecord-6.1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@
user.articles.upsert_all([{ id: 1, name: 'James' }], returning: %i[id name], unique_by: :id, record_timestamps: true)
user.values_at(:name, :age)
user.values_at("name", :age)
User.strict_loading
User.strict_loading(false)
user.strict_loading!
user.strict_loading?
6 changes: 6 additions & 0 deletions gems/activerecord/6.1/activerecord-6.1.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ module ActiveRecord
def delegated_type: (Symbol role, types: Array[String], **untyped options) -> void
end
extend DelegatedType

module ClassMethods[Model, Relation, PrimaryKey]
def strict_loading: (?bool value) -> Relation
end
end

module Core
def values_at: (*Symbol | String) -> Array[untyped]
def strict_loading!: () -> bool
def strict_loading?: () -> bool
end

class AssociationRelation
Expand Down
5 changes: 5 additions & 0 deletions gems/activerecord/7.0/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Article < ActiveRecord::Base
User.insert_all!([{ id: 1, name: 'James' }], returning: %i[id name], record_timestamps: true)
User.upsert({ id: 1, name: 'James' }, returning: %i[id name], unique_by: :id, record_timestamps: true)
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 = User.new(secret: 'dummy', key: 'dummy', token: 'dummy', phrase: 'dummy')
user.encrypt
user.encrypted_attribute?(:secret)
Expand All @@ -47,4 +49,7 @@ class Article < ActiveRecord::Base
user.articles.upsert_all([{ id: 1, name: 'James' }], returning: %i[id name], unique_by: :id, record_timestamps: true)
user.values_at(:name, :age)
user.values_at("name", :age)
user.strict_loading!
user.strict_loading!(false, mode: :n_plus_one_only)
user.strict_loading?
end
6 changes: 6 additions & 0 deletions gems/activerecord/7.0/activerecord-7.0.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ module ActiveRecord
class Base
include Encryption::EncryptableRecord
extend Encryption::EncryptableRecord::ClassMethods

module ClassMethods[Model, Relation, PrimaryKey]
def strict_loading: (?bool value) -> Relation
end
end

module Core
def values_at: (*Symbol | String) -> Array[untyped]
def strict_loading!: (?bool value, ?mode: Symbol) -> bool
def strict_loading?: () -> bool
end

class AssociationRelation
Expand Down
5 changes: 5 additions & 0 deletions gems/activerecord/7.1/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class Article < ActiveRecord::Base
User.upsert({ id: 1, name: 'James' }, returning: %i[id name], unique_by: :id, record_timestamps: true)
User.upsert_all([{ id: 1, name: 'James' }], returning: %i[id name], unique_by: :id, record_timestamps: true)
User.with(admin_users: User.where(role: 0))
User.strict_loading
User.strict_loading(false)
user = User.new(secret: 'dummy', key: 'dummy', token: 'dummy', phrase: 'dummy')
user.encrypt
user.encrypted_attribute?(:secret)
Expand All @@ -56,6 +58,9 @@ class Article < ActiveRecord::Base
user.generate_token_for(:password_reset)
user.values_at(:name, :age)
user.values_at("name", :age)
user.strict_loading!
user.strict_loading!(false, mode: :n_plus_one_only)
user.strict_loading?

user = User.new
user.normalize_attribute(:email)
Expand Down
6 changes: 6 additions & 0 deletions gems/activerecord/7.1/activerecord-7.1.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ module ActiveRecord
extend SecurePassword::ClassMethods
include TokenFor
extend TokenFor::ClassMethods

module ClassMethods[Model, Relation, PrimaryKey]
def strict_loading: (?bool value) -> Relation
end
end

module Core
def values_at: (*Symbol | String) -> Array[untyped]
def strict_loading!: (?bool value, ?mode: Symbol) -> bool
def strict_loading?: () -> bool
end

class AssociationRelation
Expand Down
5 changes: 5 additions & 0 deletions gems/activerecord/7.2/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class Article < ApplicationRecord
User.upsert({ id: 1, name: 'James' }, returning: %i[id name], unique_by: :id, record_timestamps: true)
User.upsert_all([{ id: 1, name: 'James' }], returning: %i[id name], unique_by: :id, record_timestamps: true)
User.with(admin_users: User.where(role: 0))
User.strict_loading
User.strict_loading(false)
user = User.new(secret: 'dummy', key: 'dummy', token: 'dummy', phrase: 'dummy')
user.encrypt
user.encrypted_attribute?(:secret)
Expand All @@ -54,6 +56,9 @@ class Article < ApplicationRecord
user.generate_token_for(:password_reset)
user.values_at(:name, :age)
user.values_at("name", :age)
user.strict_loading!
user.strict_loading!(false, mode: :n_plus_one_only)
user.strict_loading?

user = User.new
user.normalize_attribute(:email)
Expand Down
6 changes: 6 additions & 0 deletions gems/activerecord/7.2/activerecord-7.2.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ module ActiveRecord
extend SecurePassword::ClassMethods
include TokenFor
extend TokenFor::ClassMethods

module ClassMethods[Model, Relation, PrimaryKey]
def strict_loading: (?bool value) -> Relation
end
end

module Core
def values_at: (*Symbol | String) -> Array[untyped]
def strict_loading!: (?bool value, ?mode: Symbol) -> bool
def strict_loading?: () -> bool
end

class Relation
Expand Down

0 comments on commit ccbd2bb

Please sign in to comment.