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

ActionControllerHelpers DSL compiler should not call name directly #1354

Merged
merged 1 commit into from
Jan 16, 2023
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/action_controller_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def create_unknown_proxy_method(helper_methods, method_name)
sig { params(mod: Module).returns(T::Array[String]) }
def gather_includes(mod)
mod.ancestors
.reject { |ancestor| ancestor.is_a?(Class) || ancestor == mod || ancestor.name.nil? }
.reject { |ancestor| ancestor.is_a?(Class) || ancestor == mod || name_of(ancestor).nil? }
.map { |ancestor| T.must(qualified_name_of(ancestor)) }
.reverse
end
Expand Down
42 changes: 42 additions & 0 deletions spec/tapioca/dsl/compilers/action_controller_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,48 @@ class HelperProxy < ::ActionView::Base

assert_equal(expected, rbi_for(:UserController))
end

it "does not crash if the helper redefines `name`" do
add_ruby_file("greet_helper.rb", <<~RUBY)
module GreetHelper
class << self
def name(str)
str
end
end
end
RUBY

add_ruby_file("controller.rb", <<~RUBY)
class UserController < ActionController::Base
helper GreetHelper

def current_user_name
# ...
end
end
RUBY

expected = <<~RBI
# typed: strong

class UserController
sig { returns(HelperProxy) }
def helpers; end

module HelperMethods
include ::ActionController::Base::HelperMethods
include ::GreetHelper
end

class HelperProxy < ::ActionView::Base
include HelperMethods
end
end
RBI

assert_equal(expected, rbi_for(:UserController))
end
end
end
end
Expand Down