Permalink
Browse files

Fix the resolver cache and stop mutating the lookup_context

Before we had a bug in the resolver cache so the disable_cache were not
working when passing options to find
  • Loading branch information...
1 parent 5f9f2cd commit fe5f2b4046ffca9b8fff84418f67b76e9e2712f7 @rafaelfranca rafaelfranca committed Mar 14, 2014
@@ -122,8 +122,8 @@ def partial?
def template
@template ||= begin
- finder.with_formats_and_variants([format], [variant]) do
- finder.disable_cache { finder.find(logical_name, [], partial?) }
+ finder.disable_cache do
+ finder.find(logical_name, [], partial?, [], formats: [format], variants: [variant])
end
end
end
@@ -159,7 +159,14 @@ def args_for_lookup(name, prefixes, partial, keys, details_options) #:nodoc:
def detail_args_for(options)
return @details, details_key if options.empty? # most common path.
user_details = @details.merge(options)
- [user_details, DetailsKey.get(user_details)]
+
+ if @cache
+ details_key = DetailsKey.get(user_details)
+ else
+ details_key = nil
+ end
+
+ [user_details, details_key]
end
# Support legacy foo.erb names even though we now ignore .erb
@@ -246,13 +253,5 @@ def with_layout_format
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
@@ -40,14 +40,6 @@ def find(name, prefixes = [], partial = false, keys = [], options = {})
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
@@ -205,19 +205,6 @@ def teardown
@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

0 comments on commit fe5f2b4

Please sign in to comment.