1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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

View file

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

View file

@ -156,6 +156,13 @@ module ActionView
assert_equal "controller_helper_method", some_method assert_equal "controller_helper_method", some_method
end 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 end
class ViewAssignsTest < ActionView::TestCase class ViewAssignsTest < ActionView::TestCase