n8 / multi_fetch_fragments

Multi-fetch Fragments makes rendering and caching a collection of template partials easier and faster.
http://ninjasandrobots.com/rails-faster-partial-rendering-and-caching
MIT License
539 stars 63 forks source link

Fixing failing spec #27

Closed aaronrenner closed 5 years ago

aaronrenner commented 9 years ago

I checked out this project to make a pull request, but ended up getting a failing spec. The first error I got was the following

  1) MultiFetchFragments works for passing in a custom key
     Failure/Error: cache_mock = mock()
     NoMethodError:
       undefined method `mock' for #<RSpec::ExampleGroups::MultiFetchFragments:0x007fc4a30a8b50>
     # ./spec/multi_fetch_fragments_spec.rb:12:in `block (2 levels) in <top (required)>'

I changed the mock call to double() and then got this error

  1) MultiFetchFragments works for passing in a custom key
     Failure/Error: view.render(:partial => "views/customer", :collection => [ customer ], :cache => Proc.new{ |item| [item, 'key']}).should == "Hello"
     NoMethodError:
       undefined method `read_multi' for nil:NilClass
     # ./lib/multi_fetch_fragments.rb:45:in `render_collection_with_multi_fetch_cache'
     # ./spec/multi_fetch_fragments_spec.rb:24:in `block (2 levels) in <top (required)>'

To fix that, I set Rails.cache to the cache mock variable and everything started passing again.

I also included a Gemfile.lock anyone who pulls down the gem for development, will be using the same version of rspec.