diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/template_finder.rb | 13 | ||||
-rw-r--r-- | actionpack/test/template/template_object_test.rb | 28 |
2 files changed, 37 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/template_finder.rb b/actionpack/lib/action_view/template_finder.rb index 69832e9b4c..0fb5eaa65e 100644 --- a/actionpack/lib/action_view/template_finder.rb +++ b/actionpack/lib/action_view/template_finder.rb @@ -131,15 +131,20 @@ module ActionView #:nodoc: # # => "rhtml" # def pick_template_extension(template_path) - find_template_extension_from_handler(template_path) || find_template_extension_from_first_render + if extension = find_template_extension_from_handler(template_path, @template.template_format) || find_template_extension_from_first_render + extension + elsif @template.template_format == :js && extension = find_template_extension_from_handler(template_path, :html) + @template.template_format = :html + extension + end end - def find_template_extension_from_handler(template_path) - formatted_template_path = "#{template_path}.#{@template.template_format}" + def find_template_extension_from_handler(template_path, template_format = @template.template_format) + formatted_template_path = "#{template_path}.#{template_format}" view_paths.each do |path| if (extensions = @@file_extension_cache[path][formatted_template_path]).any? - return "#{@template.template_format}.#{extensions.first}" + return "#{template_format}.#{extensions.first}" elsif (extensions = @@file_extension_cache[path][template_path]).any? return extensions.first.to_s end diff --git a/actionpack/test/template/template_object_test.rb b/actionpack/test/template/template_object_test.rb index 780df17f0c..b3a33938cf 100644 --- a/actionpack/test/template/template_object_test.rb +++ b/actionpack/test/template/template_object_test.rb @@ -59,4 +59,32 @@ class TemplateObjectTest < Test::Unit::TestCase end end + class PartialTemplateFallbackTest < Test::Unit::TestCase + def setup + @view = ActionView::Base.new(LOAD_PATH_ROOT) + @path = 'test/layout_for_partial' + end + + def test_default + template = ActionView::PartialTemplate.new(@view, @path, nil) + assert_equal 'test/_layout_for_partial', template.path + assert_equal 'erb', template.extension + assert_equal :html, @view.template_format + end + + def test_js + @view.template_format = :js + template = ActionView::PartialTemplate.new(@view, @path, nil) + assert_equal 'test/_layout_for_partial', template.path + assert_equal 'erb', template.extension + assert_equal :html, @view.template_format + end + + def test_xml + @view.template_format = :xml + assert_raise ActionView::ActionViewError do + ActionView::PartialTemplate.new(@view, @path, nil) + end + end + end end |