Permalink
Browse files

Now we are aware if the cache_digests stuff is around and use that ke…

…y. If not then we use the fragment keys used from the normal cache do invocation.


Closes #5.
  • Loading branch information...
1 parent b4a9223 commit 4375103c57e1821cb464abdac99dafe8b005f4de @n8 committed Dec 29, 2012
Showing with 18 additions and 6 deletions.
  1. +2 −2 Gemfile.lock
  2. +8 −1 lib/multi_fetch_fragments.rb
  3. +2 −1 mutli_fetch_fragments.gemspec
  4. +6 −2 spec/multi_fetch_fragments_spec.rb
View
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- multi_fetch_fragments (0.0.9)
+ multi_fetch_fragments (0.0.12)
GEM
remote: http://rubygems.org/
@@ -44,7 +44,7 @@ GEM
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
- rake (10.0.2)
+ rake (10.0.3)
rdoc (3.12)
json (~> 1.4)
rspec-core (2.12.1)
@@ -26,7 +26,14 @@ def render_collection_with_multi_fetch_cache
@collection.each do |item|
key = @options[:cache].is_a?(Proc) ? @options[:cache].call(item) : item
- expanded_key = ActiveSupport::Cache.expand_cache_key(key)
+
+ expanded_key = nil
+ if defined?(@view.fragment_name_with_digest)
+ expanded_key = @view.fragment_name_with_digest(key)
+ else
+ expanded_key = @view.controller.fragment_cache_key(key)
+ end
+
keys_to_collection_map[expanded_key] = item
end
@@ -1,10 +1,11 @@
Gem::Specification.new do |s|
s.name = 'multi_fetch_fragments'
- s.version = '0.0.11'
+ s.version = '0.0.12'
s.author = 'Nathan Kontny'
s.email = 'nate.kontny@gmail.com'
s.summary = 'multi_fetch_fragments allows you to render a collection of partials through Rails multi read caching mechanism.'
s.files = Dir["lib/multi_fetch_fragments.rb"]
s.add_development_dependency 'rspec-rails', '~> 2'
+
end
@@ -13,10 +13,14 @@
RAILS_CACHE = cache_mock
MultiFetchFragments::Railtie.run_initializers
- view = ActionView::Base.new([File.dirname(__FILE__)], {})
+ controller = ActionController::Base.new
+ view = ActionView::Base.new([File.dirname(__FILE__)], {}, controller)
+
customer = Customer.new("david")
- key = ActiveSupport::Cache.expand_cache_key([customer, 'key'])
+ key = controller.fragment_cache_key([customer, 'key'])
+
cache_mock.should_receive(:read_multi).with([key]).and_return({key => 'Hello'})
+
view.render(:partial => "views/customer", :collection => [ customer ], :cache => Proc.new{ |item| [item, 'key']}).should == "Hello"
end
end

0 comments on commit 4375103

Please sign in to comment.