Skip to content

Commit

Permalink
Merge pull request #1985 from Shopify/ba-fix-ar-new
Browse files Browse the repository at this point in the history
Fix ActiveRecordRelation new defined out of class
  • Loading branch information
bitwise-aiden authored Aug 12, 2024
2 parents 2634126 + cd51cbb commit df6e272
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
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

0 comments on commit df6e272

Please sign in to comment.