Skip to content

Commit

Permalink
Now we are aware if the cache_digests stuff is around and use that ke…
Browse files Browse the repository at this point in the history
…y. If not then we use the fragment keys used from the normal cache do invocation.

Closes #5.
  • Loading branch information
n8 committed Dec 29, 2012
1 parent b4a9223 commit 4375103
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
multi_fetch_fragments (0.0.9)
multi_fetch_fragments (0.0.12)

GEM
remote: http://rubygems.org/
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion lib/multi_fetch_fragments.rb
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion mutli_fetch_fragments.gemspec
@@ -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
8 changes: 6 additions & 2 deletions spec/multi_fetch_fragments_spec.rb
Expand Up @@ -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.