diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index e71761db6d..4dbbd2eb6a 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -89,16 +89,13 @@ module ActionView self.class.send(:include_helper_modules!) make_test_case_available_to_view! + say_no_to_protect_against_forgery! end def config @controller.config if @controller.respond_to?(:config) end - def protect_against_forgery? - false - end - def render(options = {}, local_assigns = {}, &block) @rendered << output = _view.render(options, local_assigns, &block) output @@ -117,6 +114,14 @@ module ActionView HTML::Document.new(@rendered.blank? ? @output_buffer : @rendered).root end + def say_no_to_protect_against_forgery! + _helpers.module_eval do + def protect_against_forgery? + false + end + end + end + def make_test_case_available_to_view! test_case_instance = self _helpers.module_eval do diff --git a/actionpack/test/template/test_case_test.rb b/actionpack/test/template/test_case_test.rb index a34bca8145..16e5ee4f72 100644 --- a/actionpack/test/template/test_case_test.rb +++ b/actionpack/test/template/test_case_test.rb @@ -122,6 +122,21 @@ module ActionView helper_method :from_test_case end + class IgnoreProtectAgainstForgeryTest < ActionView::TestCase + module HelperThatInvokesProtectAgainstForgery + def help_me + protect_against_forgery? + end + end + + helper HelperThatInvokesProtectAgainstForgery + + test "protect_from_forgery? in any helpers returns false" do + assert !_view.help_me + end + + end + class ATestHelperTest < ActionView::TestCase include SharedTests test_case = self