Index: test/fragment_cache_test.rb =================================================================== --- test/fragment_cache_test.rb (revision 890) +++ test/fragment_cache_test.rb (working copy) @@ -20,6 +20,10 @@ def index render :text => "doop!" end + + def edit + render :text => "rawk" + end def trees_are_swell? true @@ -103,6 +107,7 @@ include FragmentCacheSpecSetup page_content = "give me my bongos" index_content = "doop!" + edit_content = "rawk" setup do @controller = BarController.new @@ -186,4 +191,52 @@ get :page @response.body.should == page_content end + + #check for edginess + if [].respond_to?(:extract_options!) + specify "should not break cache_path overrides" do + BarController.caches_action :page, :cache_path => 'http://test.host/some/custom/path' + cache_expects(:set).with('test.host/some/custom/path', page_content, ActsAsCached.config[:ttl]) + get :page + end + + specify "should not break cache_path block overrides" do + BarController.caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]}/edit" : "http://test.host/edit" } + cache_expects(:set).with('test.host/edit', edit_content, ActsAsCached.config[:ttl]) + get :edit + + get :index + cache_expects(:set).with('test.host/5/edit', edit_content, ActsAsCached.config[:ttl]) + get :edit, :id => 5 + end + + specify "should play nice with custom ttls and cache_path overrides" do + BarController.caches_action :page => { :ttl => 5.days }, :cache_path => 'http://test.host/my/custom/path' + cache_expects(:set).with('test.host/my/custom/path', page_content, 5.days) + get :page + end + + specify "should play nice with custom ttls and cache_path block overrides" do + BarController.caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]}/edit" : "http://test.host/edit" } + cache_expects(:set).with('test.host/5/edit', edit_content, ActsAsCached.config[:ttl]) + get :edit, :id => 5 + end + + specify "should play nice with the most complicated thing i can throw at it" do + BarController.caches_action :index => { :ttl => 24.hours }, :page => { :ttl => 5.seconds }, :edit => { :ttl => 5.days }, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]}/#{c.params[:action]}" : "http://test.host/#{c.params[:action]}" } + cache_expects(:set).with('test.host/index', index_content, 24.hours) + get :index + cache_expects(:set).with('test.host/5/edit', edit_content, 5.days) + get :edit, :id => 5 + cache_expects(:set).with('test.host/5/page', page_content, 5.seconds) + get :page, :id => 5 + + cache_expects(:read).with('test.host/5/page', nil).returns(page_content) + get :page, :id => 5 + cache_expects(:read).with('test.host/5/edit', nil).returns(edit_content) + get :edit, :id => 5 + cache_expects(:read).with('test.host/index', nil).returns(index_content) + get :index + end + end end Index: lib/acts_as_cached/fragment_cache.rb =================================================================== --- lib/acts_as_cached/fragment_cache.rb (revision 890) +++ lib/acts_as_cached/fragment_cache.rb (working copy) @@ -35,11 +35,11 @@ ::ActionController::Caching::Actions::ActionCacheFilter.class_eval do # convert all actions into a hash keyed by action named, with a value of a ttl hash (to match other cache APIs) def initialize(*actions, &block) - # no extract_options in 1.2.x - @options = actions.extract_options! if actions.respond_to? :extract_options! - @actions = actions.inject({}) do |hsh, action| + @options = actions.respond_to?(:extract_options!) ? actions.extract_options! : {} + @actions = actions.inject(@options.except(:cache_path)) do |hsh, action| action.is_a?(Hash) ? hsh.merge(action) : hsh.merge(action => { :ttl => nil }) end + @options.slice!(:cache_path) end # override to skip caching/rendering on evaluated if option @@ -63,11 +63,11 @@ if cache && (conditional || conditional.nil?) controller.rendered_action_cache = true if method(:set_content_type!).arity == 2 - set_content_type!(action_cache_path, action_cache_path.extension) + set_content_type!(controller, action_cache_path.extension) else set_content_type!(action_cache_path) end - controller.send(:render_text, cache) + controller.send(:render_for_text, cache) false else # 1.2.x compatibility