diff options
Diffstat (limited to 'actionview')
-rw-r--r-- | actionview/lib/action_view/digestor.rb | 7 | ||||
-rw-r--r-- | actionview/lib/action_view/lookup_context.rb | 8 | ||||
-rw-r--r-- | actionview/test/template/digestor_test.rb | 8 | ||||
-rw-r--r-- | actionview/test/template/lookup_context_test.rb | 13 |
4 files changed, 31 insertions, 5 deletions
diff --git a/actionview/lib/action_view/digestor.rb b/actionview/lib/action_view/digestor.rb index dad3cea73a..abbfdc786e 100644 --- a/actionview/lib/action_view/digestor.rb +++ b/actionview/lib/action_view/digestor.rb @@ -122,11 +122,8 @@ module ActionView def template @template ||= begin - finder.formats = [format] - finder.variants = [variant] - - finder.disable_cache do - finder.find(logical_name, [], partial?) + finder.with_formats_and_variants([format], [variant]) do + finder.disable_cache { finder.find(logical_name, [], partial?) } end end end diff --git a/actionview/lib/action_view/lookup_context.rb b/actionview/lib/action_view/lookup_context.rb index 76c9890776..d7f116c10c 100644 --- a/actionview/lib/action_view/lookup_context.rb +++ b/actionview/lib/action_view/lookup_context.rb @@ -246,5 +246,13 @@ module ActionView end end end + + def with_formats_and_variants(new_formats, new_variants) + old_formats, old_variants = formats, variants + self.formats, self.variants = new_formats, new_variants + yield + ensure + self.formats, self.variants = old_formats, old_variants + end end end diff --git a/actionview/test/template/digestor_test.rb b/actionview/test/template/digestor_test.rb index 1c47952f54..72d1f43f12 100644 --- a/actionview/test/template/digestor_test.rb +++ b/actionview/test/template/digestor_test.rb @@ -40,6 +40,14 @@ class FixtureFinder def disable_cache(&block) yield end + + def with_formats_and_variants(new_formats, new_variants) + old_formats, old_variants = formats, variants + self.formats, self.variants = new_formats, new_variants + yield + ensure + self.formats, self.variants = old_formats, old_variants + end end class TemplateDigestorTest < ActionView::TestCase diff --git a/actionview/test/template/lookup_context_test.rb b/actionview/test/template/lookup_context_test.rb index 4f7823045e..b11f252110 100644 --- a/actionview/test/template/lookup_context_test.rb +++ b/actionview/test/template/lookup_context_test.rb @@ -205,6 +205,19 @@ class LookupContextTest < ActiveSupport::TestCase @lookup_context.prefixes = ["foo"] assert_equal ["foo"], @lookup_context.prefixes end + + test "with_formats_and_variants preserves original values after execution" do + @lookup_context.formats = [:html] + @lookup_context.variants = [:phone] + + @lookup_context.with_formats_and_variants([:xml], [:tablet]) do + assert_equal [:xml], @lookup_context.formats + assert_equal [:tablet], @lookup_context.variants + end + + assert_equal [:html], @lookup_context.formats + assert_equal [:phone], @lookup_context.variants + end end class LookupContextWithFalseCaching < ActiveSupport::TestCase |