From d3e1fb720668c611d7045cb4b03f300138374d14 Mon Sep 17 00:00:00 2001 From: Juan Wajnerman Date: Wed, 23 Nov 2022 11:41:10 -0300 Subject: [PATCH] Include base controller helpers when possible --- lib/tapioca/dsl/compilers/action_controller_helpers.rb | 7 +++++++ .../dsl/compilers/action_controller_helpers_spec.rb | 8 +------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/tapioca/dsl/compilers/action_controller_helpers.rb b/lib/tapioca/dsl/compilers/action_controller_helpers.rb index 376597bd3..e51950674 100644 --- a/lib/tapioca/dsl/compilers/action_controller_helpers.rb +++ b/lib/tapioca/dsl/compilers/action_controller_helpers.rb @@ -84,6 +84,13 @@ def decorate # Create helper method module controller.create_module(helper_methods_name) do |helper_methods| + # If the controller has the same helpers module as the superclass + # just include superclass helpers + if helpers_module == constant.superclass._helpers + superclass_helper_methods = constant.superclass.const_get(helper_methods_name) + next helper_methods.create_include(qualified_name_of(superclass_helper_methods)) + end + # If the controller has no helper defined, then it just inherits # the Action Controlller base helper methods module, so we should # just add that as an include and stop doing more processing. diff --git a/spec/tapioca/dsl/compilers/action_controller_helpers_spec.rb b/spec/tapioca/dsl/compilers/action_controller_helpers_spec.rb index c58631d32..897e12580 100644 --- a/spec/tapioca/dsl/compilers/action_controller_helpers_spec.rb +++ b/spec/tapioca/dsl/compilers/action_controller_helpers_spec.rb @@ -160,13 +160,7 @@ class UserController def helpers; end module HelperMethods - include ::ActionController::Base::HelperMethods - - sig { returns(T.untyped) } - def current_user_name; end - - sig { params(user_id: ::Integer).void } - def notify_user(user_id); end + include ::BaseController::HelperMethods end class HelperProxy < ::ActionView::Base