Skip to content

Commit

Permalink
Merge branch 'main' into activerecord/7.2/insert_all
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed Sep 12, 2024
2 parents 7efe942 + 2275d26 commit 6f2364b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions gems/activerecord/7.1/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class User < ApplicationRecord
encrypts :token, deterministic: true
encrypts :phrase, ignore_case: true

generates_token_for :password_reset, expires_in: 15.minutes

normalizes :email, with: -> email {
# @type var email: String
email.strip.downcase
Expand Down Expand Up @@ -50,6 +52,7 @@ class Article < ActiveRecord::Base
user.articles.insert_all!([{ id: 1, name: 'James' }], returning: %i[id name], record_timestamps: true)
user.articles.upsert({ id: 1, name: 'James' }, returning: %i[id name], unique_by: :id, record_timestamps: true)
user.articles.upsert_all([{ id: 1, name: 'James' }], returning: %i[id name], unique_by: :id, record_timestamps: true)
user.generate_token_for(:password_reset)

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

class AssociationRelation
Expand Down Expand Up @@ -145,6 +147,16 @@ module ActiveRecord
def authenticate_by: (untyped attributes) -> instance?
end
end

module TokenFor
module ClassMethods
def generates_token_for: (Symbol purpose, ?expires_in: ActiveSupport::Duration) ? { () [self: instance] -> untyped } -> untyped
def find_by_token_for: (Symbol purpose, String token) -> untyped
def find_by_token_for!: (Symbol purpose, String token) -> untyped
end

def generate_token_for: (Symbol purpose) -> String
end
end

module ActiveRecord
Expand Down
1 change: 1 addition & 0 deletions gems/activerecord/7.2/_test/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@ class Article < ApplicationRecord
user = User.new
user.normalize_attribute(:email)
User.normalize_value_for(:email, ' [email protected]\n')
User.with_recursive(admin_users: User.where(role: 0))
end
26 changes: 26 additions & 0 deletions gems/activerecord/7.2/activerecord-7.2.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ module ActiveRecord
def upsert_all: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?, ?record_timestamps: bool?) -> untyped
end

class Relation
module QueryMethods
def with_recursive: (*untyped) -> untyped
def with_recursive!: (*untyped) -> untyped
end
end

module Inheritance
module ClassMethods
def primary_abstract_class: () -> void
Expand Down Expand Up @@ -111,6 +118,10 @@ module ActiveRecord
def upsert_all: (untyped attributes, ?unique_by: untyped?, ?returning: untyped?, ?record_timestamps: bool?) -> untyped
end

module Querying
def with_recursive: (*untyped) -> untyped
end

class InsertAll
@record_timestamps: bool

Expand All @@ -123,3 +134,18 @@ module ActiveRecord
def timestamps_for_create: () -> Hash[String, String]
end
end

module ActiveRecord
class Relation
module Methods[Model, PrimaryKey]
def with_recursive: (*untyped) -> self
def with_recursive!: (*untyped) -> self
end
end

class Base
module ClassMethods[Model, Relation, PrimaryKey]
def with_recursive: (*untyped) -> Relation
end
end
end

0 comments on commit 6f2364b

Please sign in to comment.