diff --git a/lib/tapioca/dsl/compilers/active_record_relations.rb b/lib/tapioca/dsl/compilers/active_record_relations.rb index e38f56a83..0e009186d 100644 --- a/lib/tapioca/dsl/compilers/active_record_relations.rb +++ b/lib/tapioca/dsl/compilers/active_record_relations.rb @@ -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") diff --git a/spec/tapioca/dsl/compilers/active_record_relations_spec.rb b/spec/tapioca/dsl/compilers/active_record_relations_spec.rb index 5406b465b..9d9b9462c 100644 --- a/spec/tapioca/dsl/compilers/active_record_relations_spec.rb +++ b/spec/tapioca/dsl/compilers/active_record_relations_spec.rb @@ -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 @@ -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