Skip to content

Commit

Permalink
Include base controller helpers when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
waj committed Dec 8, 2022
1 parent 2bcca49 commit 8d1db6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 7 additions & 0 deletions lib/tapioca/dsl/compilers/action_controller_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 1 addition & 7 deletions spec/tapioca/dsl/compilers/action_controller_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8d1db6c

Please sign in to comment.