mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Avoid module_eval on helpers from AV::TestCase
Previously we were using module_eval to manually add some helpers in ActionView::TestCase, which assumes a lot about what _helpers allows. Instead, we can use a standard helper block to define these methods only one time, and add a method to the new uniq controller class to tie back to the test instance.
This commit is contained in:
parent
65e42c91f5
commit
3ec8ddd0cf
1 changed files with 14 additions and 22 deletions
|
@ -102,7 +102,8 @@ module ActionView
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_with_controller
|
def setup_with_controller
|
||||||
@controller = Class.new(ActionView::TestCase::TestController).new
|
controller_class = Class.new(ActionView::TestCase::TestController)
|
||||||
|
@controller = controller_class.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
|
||||||
|
@ -110,8 +111,8 @@ module ActionView
|
||||||
@output_buffer = ActiveSupport::SafeBuffer.new ""
|
@output_buffer = ActiveSupport::SafeBuffer.new ""
|
||||||
@rendered = +""
|
@rendered = +""
|
||||||
|
|
||||||
make_test_case_available_to_view!
|
test_case_instance = self
|
||||||
say_no_to_protect_against_forgery!
|
controller_class.define_method(:_test_case) { test_case_instance }
|
||||||
end
|
end
|
||||||
|
|
||||||
def config
|
def config
|
||||||
|
@ -161,6 +162,16 @@ module ActionView
|
||||||
included do
|
included do
|
||||||
setup :setup_with_controller
|
setup :setup_with_controller
|
||||||
ActiveSupport.run_load_hooks(:action_view_test_case, self)
|
ActiveSupport.run_load_hooks(:action_view_test_case, self)
|
||||||
|
|
||||||
|
helper do
|
||||||
|
def protect_against_forgery?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def _test_case
|
||||||
|
controller._test_case
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -169,25 +180,6 @@ module ActionView
|
||||||
Nokogiri::HTML::Document.parse(@rendered.blank? ? @output_buffer : @rendered).root
|
Nokogiri::HTML::Document.parse(@rendered.blank? ? @output_buffer : @rendered).root
|
||||||
end
|
end
|
||||||
|
|
||||||
def say_no_to_protect_against_forgery!
|
|
||||||
_helpers.module_eval do
|
|
||||||
silence_redefinition_of_method :protect_against_forgery?
|
|
||||||
def protect_against_forgery?
|
|
||||||
false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def make_test_case_available_to_view!
|
|
||||||
test_case_instance = self
|
|
||||||
_helpers.module_eval do
|
|
||||||
unless private_method_defined?(:_test_case)
|
|
||||||
define_method(:_test_case) { test_case_instance }
|
|
||||||
private :_test_case
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module Locals
|
module Locals
|
||||||
attr_accessor :rendered_views
|
attr_accessor :rendered_views
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue