Skip to content

Commit

Permalink
activerecord: Apply recent changes to AR 7.2
Browse files Browse the repository at this point in the history
refs:

* #652
* #655
* #659
* #660
  • Loading branch information
tk0miya committed Sep 30, 2024
1 parent 4f55d83 commit a8f009b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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 @@ -39,6 +39,7 @@ class Article < ApplicationRecord
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.with(admin_users: User.where(role: 0))
user = User.new(secret: 'dummy', key: 'dummy', token: 'dummy', phrase: 'dummy')
user.encrypt
user.encrypted_attribute?(:secret)
Expand All @@ -50,6 +51,7 @@ class Article < ApplicationRecord
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
29 changes: 29 additions & 0 deletions gems/activerecord/7.2/activerecord-7.2.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ module ActiveRecord
extend Encryption::EncryptableRecord::ClassMethods
include Normalization
extend Normalization::ClassMethods
include SecurePassword
extend SecurePassword::ClassMethods
include TokenFor
extend TokenFor::ClassMethods
end

class Relation
Expand Down Expand Up @@ -133,18 +137,43 @@ module ActiveRecord

def timestamps_for_create: () -> Hash[String, String]
end

module SecurePassword
module ClassMethods
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 Arel
class Table
def initialize: (untyped name, ?type_caster: untyped type_caster, ?as: untyped? as, ?klass: untyped?) -> void
end
end

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

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

0 comments on commit a8f009b

Please sign in to comment.