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: ActiveSupportConcern recursively checks for ClassMethod #1933

Merged
Show file tree
Hide file tree
Changes from 2 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_support_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def decorate
mixed_in_class_methods = dependencies
.uniq # Deduplicate
.filter_map do |concern| # Map to class methods module name, if exists
"#{qualified_name_of(concern)}::ClassMethods" if concern.const_defined?(:ClassMethods)
"#{qualified_name_of(concern)}::ClassMethods" if concern.const_defined?(:ClassMethods, false)
end

return if mixed_in_class_methods.empty?
Expand Down
44 changes: 44 additions & 0 deletions spec/tapioca/dsl/compilers/active_support_concern_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,50 @@ module Qux
arguments_to_micm_in_effective_order(rbi_for(:Qux)),
)
end

it "only generates ClassMethods RBI when it's defined on a module" do
spencewenski marked this conversation as resolved.
Show resolved Hide resolved
add_ruby_file("test_case.rb", <<~RUBY)
module Foo
extend ActiveSupport::Concern

module ClassMethods
end
end

module Bar
extend ActiveSupport::Concern
include Foo
end

module Baz
extend ActiveSupport::Concern
include Bar

module ClassMethods
end
end

class Qux
include Baz
end
RUBY

# `mixes_in_class_methods ::Bar::ClassMethods` is not expected in this case because there is no
# `::Bar::ClassMethods` module.
expected = <<~RUBY
# typed: strong

module Baz
mixes_in_class_methods ::Foo::ClassMethods
end
RUBY

assert_equal(expected, rbi_for(:Baz))
assert_equal(
class_method_ancestors_for(:Qux),
arguments_to_micm_in_effective_order(rbi_for(:Baz)),
)
end
end
end

Expand Down
Loading