提交 65e42c91 编写于 作者: J John Hawthorn

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: NJohn Crepezzi <seejohnrun@github.com>
上级 fbaf50f5
......@@ -126,7 +126,7 @@ class Metal < AbstractController::Base
# ==== 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)
......
......@@ -16,11 +16,12 @@ class TestController < ActionController::Base
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 @@ def include_helper_modules!
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
......
......@@ -156,6 +156,13 @@ def render_from_helper
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册