Use unique controller per ActionView::TestCase

Previously the same class, ActionView::TestCase::TestController, was
used to build a controller for every ActionView::TestCase class.

This caused issues when helpers/helper methods were set directly on the
controller (which from one test we seem to want to support).

This commit solves this by creating a new controller class for every
test case, which gives the controller a unique set of helpers to work
with.

Co-authored-by: John Crepezzi <seejohnrun@github.com>
This commit is contained in:
John Hawthorn 2020-08-27 13:45:15 -07:00
parent fbaf50f5f8
commit 65e42c91f5
3 changed files with 12 additions and 4 deletions

View File

@ -126,7 +126,7 @@ module ActionController
# ==== Returns
# * <tt>string</tt>
def self.controller_name
@controller_name ||= name.demodulize.delete_suffix("Controller").underscore
@controller_name ||= (name.demodulize.delete_suffix("Controller").underscore unless anonymous?)
end
def self.make_response!(request)

View File

@ -16,11 +16,12 @@ module ActionView
attr_accessor :request, :response, :params
class << self
attr_writer :controller_path
# Overrides AbstractController::Base#controller_path
attr_accessor :controller_path
end
def controller_path=(path)
self.class.controller_path = (path)
self.class.controller_path = path
end
def initialize
@ -101,7 +102,7 @@ module ActionView
end
def setup_with_controller
@controller = ActionView::TestCase::TestController.new
@controller = Class.new(ActionView::TestCase::TestController).new
@request = @controller.request
@view_flow = ActionView::OutputFlow.new
# empty string ensures buffer has UTF-8 encoding as

View File

@ -156,6 +156,13 @@ module ActionView
assert_equal "controller_helper_method", some_method
end
class AnotherTestClass < ActionView::TestCase
test "doesn't use controller helpers from other tests" do
assert_not_respond_to view, :render_from_helper
assert_not_includes @controller._helpers.instance_methods, :render_from_helper
end
end
end
class ViewAssignsTest < ActionView::TestCase