From aacf2581cde0147dc66c3eeacf6d7447c2bbafdf Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 19 May 2010 16:37:41 -0300 Subject: refactor evals and adds some __FILE__ and __LINE__ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- actionpack/lib/action_view/helpers/active_model_helper.rb | 2 +- actionpack/lib/action_view/helpers/form_helper.rb | 5 ++--- actionpack/lib/action_view/test_case.rb | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/helpers/active_model_helper.rb b/actionpack/lib/action_view/helpers/active_model_helper.rb index d9f09b5dc5..0cddd09eb0 100644 --- a/actionpack/lib/action_view/helpers/active_model_helper.rb +++ b/actionpack/lib/action_view/helpers/active_model_helper.rb @@ -43,7 +43,7 @@ module ActionView end %w(tag content_tag to_date_select_tag to_datetime_select_tag to_time_select_tag).each do |meth| - module_eval "def #{meth}(*) error_wrapping(super) end" + module_eval "def #{meth}(*) error_wrapping(super) end", __FILE__, __LINE__ end def error_wrapping(html_tag) diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 414a5d4cd9..b3db3151d3 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -1111,7 +1111,7 @@ module ActionView end (field_helpers - %w(label check_box radio_button fields_for hidden_field)).each do |selector| - src, line = <<-end_src, __LINE__ + 1 + class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def #{selector}(method, options = {}) # def text_field(method, options = {}) @template.send( # @template.send( #{selector.inspect}, # "text_field", @@ -1119,8 +1119,7 @@ module ActionView method, # method, objectify_options(options)) # objectify_options(options)) end # end - end_src - class_eval src, __FILE__, line + RUBY_EVAL end def fields_for(record_or_name_or_array, *args, &block) diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index f6417d5c2c..5517a56fb9 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -82,7 +82,7 @@ module ActionView def helper_method(*methods) # Almost a duplicate from ActionController::Helpers methods.flatten.each do |method| - _helpers.module_eval <<-end_eval + _helpers.module_eval <<-end_eval, __FILE__, __LINE__ + 1 def #{method}(*args, &block) # def current_user(*args, &block) _test_case.send(%(#{method}), *args, &block) # test_case.send(%(current_user), *args, &block) end # end -- cgit v1.2.3 From 05c95b5c5815c0b3ae55fda7a897922b7f3ec2c7 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 24 May 2010 13:38:23 -0300 Subject: translation method for arrays on TranslationHelper module returns an array where values for keys of the form (.|_)html keys are html_safe MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit [#4675] Signed-off-by: José Valim --- .../lib/action_view/helpers/translation_helper.rb | 50 +++++++++++----------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb index 086ad261c8..cb55f1edb4 100644 --- a/actionpack/lib/action_view/helpers/translation_helper.rb +++ b/actionpack/lib/action_view/helpers/translation_helper.rb @@ -3,7 +3,7 @@ require 'action_view/helpers/tag_helper' module ActionView module Helpers module TranslationHelper - # Delegates to I18n#translate but also performs three additional functions. First, it'll catch MissingTranslationData exceptions + # Delegates to I18n#translate but also performs three additional functions. First, it'll catch MissingTranslationData exceptions # and turn them into inline spans that contains the missing key, such that you can see in a view what is missing where. # # Second, it'll scope the key by the current partial if the key starts with a period. So if you call translate(".foo") from the @@ -11,20 +11,19 @@ module ActionView # to translate many keys within the same partials and gives you a simple framework for scoping them consistently. If you don't # prepend the key with a period, nothing is converted. # - # Third, it’ll mark the translation as safe HTML if the key has the suffix "_html" or the last element of the key is the word - # "html". For example, calling translate("footer_html") or translate("footer.html") will return a safe HTML string that won’t - # be escaped by other HTML helper methods. This naming convention helps to identify translations that include HTML tags so that + # Third, it’ll mark the translation as safe HTML if the key has the suffix "_html" or the last element of the key is the word + # "html". For example, calling translate("footer_html") or translate("footer.html") will return a safe HTML string that won’t + # be escaped by other HTML helper methods. This naming convention helps to identify translations that include HTML tags so that # you know what kind of output to expect when you call translate in a template. - def translate(key, options = {}) - options[:raise] = true - translation = I18n.translate(scope_key_by_partial(key), options) - translation = (translation.respond_to?(:join) ? translation.join : translation) - if html_safe_translation_key?(key) - translation.html_safe - else - translation - end + def translate(keys, options = {}) + options[:raise] = true + are_keys_a_string = keys.is_a?(String) + keys = scope_keys_by_partial(keys) + + translations = I18n.translate(keys, options) + translations = html_safe_translation_keys(keys, Array.wrap(translations)) + are_keys_a_string ? translations.first : translations rescue I18n::MissingTranslationData => e keys = I18n.normalize_keys(e.locale, e.key, e.options[:scope]) content_tag('span', keys.join(', '), :class => 'translation_missing') @@ -38,23 +37,24 @@ module ActionView alias :l :localize private - - def scope_key_by_partial(key) - strkey = key.respond_to?(:join) ? key.join : key.to_s - if strkey.first == "." - if @_virtual_path - @_virtual_path.gsub(%r{/_?}, ".") + strkey + + def scope_keys_by_partial(keys) + Array.wrap(keys).map do |key| + if key.to_s.first == "." + unless @_virtual_path + raise "Cannot use t(#{key.inspect}) shortcut because path is not available" + end + @_virtual_path.gsub(%r{/_?}, ".") + key else - raise "Cannot use t(#{key.inspect}) shortcut because path is not available" + key end - else - key end end - def html_safe_translation_key?(key) - key = key.is_a?(Array) ? key.last : key.to_s - key =~ /(\b|_|\.)html$/ + def html_safe_translation_keys(keys, translations) + keys.zip(translations).map do |key, translation| + key =~ /(\b|_|\.)html$/ ? translation.html_safe : translation + end end end end -- cgit v1.2.3 From 8e583b69e8b3017e85440c97b325ca7ae0c32dfb Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Tue, 4 May 2010 09:00:46 -0500 Subject: Move AV::TC to AV::TC::Behavior [#4678 state:resolved] MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - enables alternative testing frameworks to include AV::TC::Behavior instead of subclassing AV::TC - also added tests and code for: - test view delegates :notice to request.flash - useful since generators generate views that use notice - test case doesn't try to include modules that are actually classes Signed-off-by: José Valim --- actionpack/lib/action_view/test_case.rb | 150 ++++++++++++++++++-------------- 1 file changed, 85 insertions(+), 65 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 5517a56fb9..2c66e5ae09 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -24,80 +24,94 @@ module ActionView end end - include ActionDispatch::Assertions, ActionDispatch::TestProcess - include ActionController::TemplateAssertions - include ActionView::Context + module Behavior + extend ActiveSupport::Concern - include ActionController::PolymorphicRoutes - include ActionController::RecordIdentifier + include ActionDispatch::Assertions, ActionDispatch::TestProcess + include ActionController::TemplateAssertions + include ActionView::Context - include AbstractController::Helpers - include ActionView::Helpers + include ActionController::PolymorphicRoutes + include ActionController::RecordIdentifier - class_inheritable_accessor :helper_class - attr_accessor :controller, :output_buffer, :rendered + include AbstractController::Helpers + include ActionView::Helpers - setup :setup_with_controller - def setup_with_controller - @controller = TestController.new - @output_buffer = ActiveSupport::SafeBuffer.new - @rendered = '' + attr_accessor :controller, :output_buffer, :rendered + + module ClassMethods + def tests(helper_class) + self.helper_class = helper_class + end - self.class.send(:include_helper_modules!) - make_test_case_available_to_view! - end + def determine_default_helper_class(name) + mod = name.sub(/Test$/, '').constantize + mod.is_a?(Class) ? nil : mod + rescue NameError + nil + end - def config - @controller.config if @controller.respond_to?(:config) - end + def helper_method(*methods) + # Almost a duplicate from ActionController::Helpers + methods.flatten.each do |method| + _helpers.module_eval <<-end_eval + def #{method}(*args, &block) # def current_user(*args, &block) + _test_case.send(%(#{method}), *args, &block) # test_case.send(%(current_user), *args, &block) + end # end + end_eval + end + end - def render(options = {}, local_assigns = {}, &block) - @rendered << output = _view.render(options, local_assigns, &block) - output - end + attr_writer :helper_class - def protect_against_forgery? - false - end + def helper_class + @helper_class ||= determine_default_helper_class(name) + end - class << self - def tests(helper_class) - self.helper_class = helper_class - end + private - def helper_class - if current_helper_class = read_inheritable_attribute(:helper_class) - current_helper_class - else - self.helper_class = determine_default_helper_class(name) + def include_helper_modules! + helper(helper_class) if helper_class + include _helpers end + end - def determine_default_helper_class(name) - name.sub(/Test$/, '').constantize - rescue NameError - nil + def setup_with_controller + @controller = ActionView::TestCase::TestController.new + @output_buffer = ActiveSupport::SafeBuffer.new + @rendered = '' + + self.class.send(:include_helper_modules!) + make_test_case_available_to_view! end - def helper_method(*methods) - # Almost a duplicate from ActionController::Helpers - methods.flatten.each do |method| - _helpers.module_eval <<-end_eval, __FILE__, __LINE__ + 1 - def #{method}(*args, &block) # def current_user(*args, &block) - _test_case.send(%(#{method}), *args, &block) # test_case.send(%(current_user), *args, &block) - end # end - end_eval - end + def config + @controller.config if @controller.respond_to?(:config) end - private - def include_helper_modules! - helper(helper_class) if helper_class - include _helpers - end - end + def protect_against_forgery? + false + end + + def render(options = {}, local_assigns = {}, &block) + @rendered << output = _view.render(options, local_assigns, &block) + output + end + + included do + setup :setup_with_controller + end private + + # Support the selector assertions + # + # Need to experiment if this priority is the best one: rendered => output_buffer + def response_from_page_or_rjs + HTML::Document.new(@rendered.blank? ? @output_buffer : @rendered).root + end + def make_test_case_available_to_view! test_case_instance = self _helpers.module_eval do @@ -110,29 +124,30 @@ module ActionView view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller) view.singleton_class.send :include, _helpers view.singleton_class.send :include, @controller._router.url_helpers + view.singleton_class.send :delegate, :alert, :notice, :to => "request.flash" view.output_buffer = self.output_buffer view end - # Support the selector assertions - # - # Need to experiment if this priority is the best one: rendered => output_buffer - def response_from_page_or_rjs - HTML::Document.new(rendered.blank? ? output_buffer : rendered).root - end - EXCLUDE_IVARS = %w{ + @_result @output_buffer - @fixture_cache + @rendered + @templates + @view_context_class + @layouts + @partials + @controller + @method_name - @_result + @fixture_cache @loaded_fixtures @test_passed - @view } def _instance_variables instance_variables - EXCLUDE_IVARS + instance_variables end def _assigns @@ -155,5 +170,10 @@ module ActionView super end end + + end + + include Behavior + end end -- cgit v1.2.3 From 2b8eb5404e5545fb80eb6edf09c61bd5030034e8 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 24 May 2010 17:21:18 -0300 Subject: Revert "translation method for arrays on TranslationHelper module returns an array where values for keys of the form (.|_)html keys are html_safe" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 05c95b5c5815c0b3ae55fda7a897922b7f3ec2c7. Signed-off-by: José Valim --- .../lib/action_view/helpers/translation_helper.rb | 50 +++++++++++----------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb index cb55f1edb4..086ad261c8 100644 --- a/actionpack/lib/action_view/helpers/translation_helper.rb +++ b/actionpack/lib/action_view/helpers/translation_helper.rb @@ -3,7 +3,7 @@ require 'action_view/helpers/tag_helper' module ActionView module Helpers module TranslationHelper - # Delegates to I18n#translate but also performs three additional functions. First, it'll catch MissingTranslationData exceptions + # Delegates to I18n#translate but also performs three additional functions. First, it'll catch MissingTranslationData exceptions # and turn them into inline spans that contains the missing key, such that you can see in a view what is missing where. # # Second, it'll scope the key by the current partial if the key starts with a period. So if you call translate(".foo") from the @@ -11,19 +11,20 @@ module ActionView # to translate many keys within the same partials and gives you a simple framework for scoping them consistently. If you don't # prepend the key with a period, nothing is converted. # - # Third, it’ll mark the translation as safe HTML if the key has the suffix "_html" or the last element of the key is the word - # "html". For example, calling translate("footer_html") or translate("footer.html") will return a safe HTML string that won’t - # be escaped by other HTML helper methods. This naming convention helps to identify translations that include HTML tags so that + # Third, it’ll mark the translation as safe HTML if the key has the suffix "_html" or the last element of the key is the word + # "html". For example, calling translate("footer_html") or translate("footer.html") will return a safe HTML string that won’t + # be escaped by other HTML helper methods. This naming convention helps to identify translations that include HTML tags so that # you know what kind of output to expect when you call translate in a template. - def translate(keys, options = {}) - options[:raise] = true - are_keys_a_string = keys.is_a?(String) - keys = scope_keys_by_partial(keys) - - translations = I18n.translate(keys, options) - translations = html_safe_translation_keys(keys, Array.wrap(translations)) - are_keys_a_string ? translations.first : translations + def translate(key, options = {}) + options[:raise] = true + translation = I18n.translate(scope_key_by_partial(key), options) + translation = (translation.respond_to?(:join) ? translation.join : translation) + if html_safe_translation_key?(key) + translation.html_safe + else + translation + end rescue I18n::MissingTranslationData => e keys = I18n.normalize_keys(e.locale, e.key, e.options[:scope]) content_tag('span', keys.join(', '), :class => 'translation_missing') @@ -37,24 +38,23 @@ module ActionView alias :l :localize private - - def scope_keys_by_partial(keys) - Array.wrap(keys).map do |key| - if key.to_s.first == "." - unless @_virtual_path - raise "Cannot use t(#{key.inspect}) shortcut because path is not available" - end - @_virtual_path.gsub(%r{/_?}, ".") + key + + def scope_key_by_partial(key) + strkey = key.respond_to?(:join) ? key.join : key.to_s + if strkey.first == "." + if @_virtual_path + @_virtual_path.gsub(%r{/_?}, ".") + strkey else - key + raise "Cannot use t(#{key.inspect}) shortcut because path is not available" end + else + key end end - def html_safe_translation_keys(keys, translations) - keys.zip(translations).map do |key, translation| - key =~ /(\b|_|\.)html$/ ? translation.html_safe : translation - end + def html_safe_translation_key?(key) + key = key.is_a?(Array) ? key.last : key.to_s + key =~ /(\b|_|\.)html$/ end end end -- cgit v1.2.3 From b5f9c8822dce55b33a4a6ab929f5b86b055a0284 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 24 May 2010 17:49:21 -0300 Subject: translate method doesn't support arrays anymore and is optimized to be used with strings or symbols MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: José Valim --- .../lib/action_view/helpers/translation_helper.rb | 28 ++++++++-------------- 1 file changed, 10 insertions(+), 18 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb index 086ad261c8..6633ef295a 100644 --- a/actionpack/lib/action_view/helpers/translation_helper.rb +++ b/actionpack/lib/action_view/helpers/translation_helper.rb @@ -3,7 +3,7 @@ require 'action_view/helpers/tag_helper' module ActionView module Helpers module TranslationHelper - # Delegates to I18n#translate but also performs three additional functions. First, it'll catch MissingTranslationData exceptions + # Delegates to I18n#translate but also performs three additional functions. First, it'll catch MissingTranslationData exceptions # and turn them into inline spans that contains the missing key, such that you can see in a view what is missing where. # # Second, it'll scope the key by the current partial if the key starts with a period. So if you call translate(".foo") from the @@ -11,20 +11,14 @@ module ActionView # to translate many keys within the same partials and gives you a simple framework for scoping them consistently. If you don't # prepend the key with a period, nothing is converted. # - # Third, it’ll mark the translation as safe HTML if the key has the suffix "_html" or the last element of the key is the word - # "html". For example, calling translate("footer_html") or translate("footer.html") will return a safe HTML string that won’t - # be escaped by other HTML helper methods. This naming convention helps to identify translations that include HTML tags so that + # Third, it’ll mark the translation as safe HTML if the key has the suffix "_html" or the last element of the key is the word + # "html". For example, calling translate("footer_html") or translate("footer.html") will return a safe HTML string that won’t + # be escaped by other HTML helper methods. This naming convention helps to identify translations that include HTML tags so that # you know what kind of output to expect when you call translate in a template. def translate(key, options = {}) - options[:raise] = true - translation = I18n.translate(scope_key_by_partial(key), options) - translation = (translation.respond_to?(:join) ? translation.join : translation) - if html_safe_translation_key?(key) - translation.html_safe - else - translation - end + translation = I18n.translate(scope_key_by_partial(key), options.merge!(:raise => true)) + html_safe_translation_key?(key) ? translation.html_safe : translation rescue I18n::MissingTranslationData => e keys = I18n.normalize_keys(e.locale, e.key, e.options[:scope]) content_tag('span', keys.join(', '), :class => 'translation_missing') @@ -38,12 +32,11 @@ module ActionView alias :l :localize private - + def scope_key_by_partial(key) - strkey = key.respond_to?(:join) ? key.join : key.to_s - if strkey.first == "." + if key.to_s.first == "." if @_virtual_path - @_virtual_path.gsub(%r{/_?}, ".") + strkey + @_virtual_path.gsub(%r{/_?}, ".") + key.to_s else raise "Cannot use t(#{key.inspect}) shortcut because path is not available" end @@ -53,8 +46,7 @@ module ActionView end def html_safe_translation_key?(key) - key = key.is_a?(Array) ? key.last : key.to_s - key =~ /(\b|_|\.)html$/ + key.to_s =~ /(\b|_|\.)html$/ end end end -- cgit v1.2.3 From d8d38bedfd5716d55e50e85dc6c9a938b1848e66 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 24 May 2010 20:13:07 -0700 Subject: HTML safety: fix textarea with nil content --- actionpack/lib/action_view/helpers/form_tag_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/helpers/form_tag_helper.rb b/actionpack/lib/action_view/helpers/form_tag_helper.rb index 2a3f826c15..796268628a 100644 --- a/actionpack/lib/action_view/helpers/form_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/form_tag_helper.rb @@ -293,7 +293,7 @@ module ActionView escape = options.key?("escape") ? options.delete("escape") : true content = html_escape(content) if escape - content_tag :textarea, content.html_safe, { "name" => name, "id" => sanitize_to_id(name) }.update(options) + content_tag :textarea, content.to_s.html_safe, { "name" => name, "id" => sanitize_to_id(name) }.update(options) end # Creates a check box form input tag. -- cgit v1.2.3 From f53a6d814966e0ea039bde680b0fc3814236641c Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 24 May 2010 20:16:50 -0700 Subject: i18n: t() handles single keys returning an Array, also --- actionpack/lib/action_view/helpers/translation_helper.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/helpers/translation_helper.rb b/actionpack/lib/action_view/helpers/translation_helper.rb index 6633ef295a..0d2b2aa7b1 100644 --- a/actionpack/lib/action_view/helpers/translation_helper.rb +++ b/actionpack/lib/action_view/helpers/translation_helper.rb @@ -18,7 +18,11 @@ module ActionView def translate(key, options = {}) translation = I18n.translate(scope_key_by_partial(key), options.merge!(:raise => true)) - html_safe_translation_key?(key) ? translation.html_safe : translation + if html_safe_translation_key?(key) && translation.respond_to?(:html_safe) + translation.html_safe + else + translation + end rescue I18n::MissingTranslationData => e keys = I18n.normalize_keys(e.locale, e.key, e.options[:scope]) content_tag('span', keys.join(', '), :class => 'translation_missing') @@ -32,7 +36,6 @@ module ActionView alias :l :localize private - def scope_key_by_partial(key) if key.to_s.first == "." if @_virtual_path -- cgit v1.2.3 From 163152bfd0ea5344472d24b6f89e8c957dbd66f5 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Tue, 25 May 2010 00:34:55 -0500 Subject: Support configuration of controller.controller_path on instances of ActionView::TestCase::TestController without stubs. Just say: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @controller.controller_path = "path/i/need/for/this/test" [#4697 state:resolved] Signed-off-by: José Valim --- actionpack/lib/action_view/test_case.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'actionpack/lib/action_view') diff --git a/actionpack/lib/action_view/test_case.rb b/actionpack/lib/action_view/test_case.rb index 2c66e5ae09..e71761db6d 100644 --- a/actionpack/lib/action_view/test_case.rb +++ b/actionpack/lib/action_view/test_case.rb @@ -10,11 +10,16 @@ module ActionView attr_accessor :request, :response, :params - def self.controller_path - '' + class << self + attr_writer :controller_path + end + + def controller_path=(path) + self.class.controller_path=(path) end def initialize + self.class.controller_path = "" @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new -- cgit v1.2.3 From e02db06ece7aeecec7c37f5b0e3de7d65c8684e6 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Tue, 25 May 2010 23:46:00 -0500 Subject: In AV::TC, move protect_against_forgery? from the test_case to the _helper module included in the view. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ensures that protect_against_forgery? is present when a helper included in a partial that is rendered by the template under test calls it (which happens in FormTagHelper#extra_tags_for_form, for example). [#4700 state:resolved] Signed-off-by: José Valim --- actionpack/lib/action_view/test_case.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_view') 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 -- cgit v1.2.3