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:
parent
fbaf50f5f8
commit
65e42c91f5
3 changed files with 12 additions and 4 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue