From 70fd692c1eada44027f9581f84461ca87abba8c6 Mon Sep 17 00:00:00 2001
From: Santiago Pastorino <santiago@wyeworks.com>
Date: Mon, 20 Feb 2012 16:48:43 -0200
Subject: Use the right format when a partial is missing.

Closes #5025
---
 actionpack/lib/action_view/template.rb        | 1 +
 actionpack/test/fixtures/with_format.json.erb | 1 +
 actionpack/test/template/render_test.rb       | 7 +++++++
 3 files changed, 9 insertions(+)
 create mode 100644 actionpack/test/fixtures/with_format.json.erb

(limited to 'actionpack')

diff --git a/actionpack/lib/action_view/template.rb b/actionpack/lib/action_view/template.rb
index edb3d427d5..644debd49c 100644
--- a/actionpack/lib/action_view/template.rb
+++ b/actionpack/lib/action_view/template.rb
@@ -163,6 +163,7 @@ module ActionView
       pieces  = @virtual_path.split("/")
       name    = pieces.pop
       partial = !!name.sub!(/^_/, "")
+      lookup.formats = @formats
       lookup.disable_cache do
         lookup.find_template(name, [ pieces.join('/') ], partial, @locals)
       end
diff --git a/actionpack/test/fixtures/with_format.json.erb b/actionpack/test/fixtures/with_format.json.erb
new file mode 100644
index 0000000000..a7f480ab1d
--- /dev/null
+++ b/actionpack/test/fixtures/with_format.json.erb
@@ -0,0 +1 @@
+<%= render :partial => 'missing', :formats => [:json] %>
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index 788ad61356..e4ce756bf8 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -51,6 +51,13 @@ module RenderTestCases
     assert_match "<error>No Comment</error>", @view.render(:template => "comments/empty", :formats => [:xml])
   end
 
+  def test_render_template_with_a_missing_partial_of_another_format
+    assert_raise ActionView::Template::Error, "Missing partial /missing with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder]}" do
+      @view.lookup_context.freeze_formats([:html])
+      @view.render(:template => "with_format", :formats => [:json])
+    end
+  end
+
   def test_render_file_with_locale
     assert_equal "<h1>Kein Kommentar</h1>", @view.render(:file => "comments/empty", :locale => [:de])
     assert_equal "<h1>Kein Kommentar</h1>", @view.render(:file => "comments/empty", :locale => :de)
-- 
cgit v1.2.3