Skip to content
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

Fix ActiveRecordRelation new defined out of class #1985

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tapioca/dsl/compilers/active_record_relations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ def create_common_methods
# it doesn't allow for an array to be passed. If we kept it as a blanket it
# would mean the passing any `T.untyped` value to the method would assume
# the result is `T::Array` which is not the case majority of the time.
model.create_method("new") do |method|
model.create_method("new", class_method: true) do |method|
method.add_opt_param("attributes", "nil")
method.add_block_param("block")

Expand Down
16 changes: 10 additions & 6 deletions spec/tapioca/dsl/compilers/active_record_relations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ class Post
extend CommonRelationMethods
extend GeneratedRelationMethods

sig { params(attributes: T.untyped, block: T.nilable(T.proc.params(object: ::Post).void)).returns(::Post) }
def new(attributes = nil, &block); end

private

sig { returns(NilClass) }
def to_ary; end

class << self
sig { params(attributes: T.untyped, block: T.nilable(T.proc.params(object: ::Post).void)).returns(::Post) }
def new(attributes = nil, &block); end
end

module CommonRelationMethods
sig { params(block: T.nilable(T.proc.params(record: ::Post).returns(T.untyped))).returns(T::Boolean) }
def any?(&block); end
Expand Down Expand Up @@ -794,14 +796,16 @@ class Post
extend CommonRelationMethods
extend GeneratedRelationMethods

sig { params(attributes: T.untyped, block: T.nilable(T.proc.params(object: ::Post).void)).returns(::Post) }
def new(attributes = nil, &block); end

private

sig { returns(NilClass) }
def to_ary; end

class << self
sig { params(attributes: T.untyped, block: T.nilable(T.proc.params(object: ::Post).void)).returns(::Post) }
def new(attributes = nil, &block); end
end

module CommonRelationMethods
sig { params(block: T.nilable(T.proc.params(record: ::Post).returns(T.untyped))).returns(T::Boolean) }
def any?(&block); end
Expand Down
Loading