Index: test/helper.rb =================================================================== --- test/helper.rb (revision 418) +++ test/helper.rb (working copy) @@ -2,24 +2,17 @@ # This file exists to fake out all the Railsisms we use so we can run the # tests in isolation. $LOAD_PATH.unshift 'lib/' +# -# prepend vendor rails to the load path if it exists -VENDOR_RAILS_ROOT = File.dirname(__FILE__) + "/../../../../vendor/rails" -if File.directory?(VENDOR_RAILS_ROOT) - $LOAD_PATH.unshift "#{VENDOR_RAILS_ROOT}/activesupport/lib", "#{VENDOR_RAILS_ROOT}/actionpack/lib" -end - begin require 'rubygems' gem 'mocha', '>= 0.4.0' require 'mocha' gem 'test-spec', '= 0.3.0' require 'test/spec' - require 'active_support' - require 'action_controller' - require 'action_view' + require 'multi_rails_init' rescue LoadError - puts '=> acts_as_cached tests depend on the following gems: mocha (0.4.0+), test-spec (0.3.0), and rails.' + puts '=> acts_as_cached tests depend on the following gems: mocha (0.4.0+), test-spec (0.3.0), multi_rails (0.0.2), and rails.' end begin Index: test/fragment_cache_test.rb =================================================================== --- test/fragment_cache_test.rb (revision 418) +++ 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 @@ -111,6 +115,7 @@ include FragmentCacheSpecSetup page_content = "give me my bongos" index_content = "doop!" + edit_content = "rawk" setup do @controller = BarController.new @@ -186,6 +191,54 @@ get :page 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 + specify "should be able to skip action caching when passed something that returns false" do BarController.caches_action :page => { :if => Proc.new {|c| !c.trees_are_swell?} } Index: Rakefile =================================================================== --- Rakefile (revision 418) +++ Rakefile (working copy) @@ -1,6 +1,7 @@ require 'rake' require 'rake/testtask' require 'rake/rdoctask' +require 'load_multi_rails_rake_tasks' desc "Run all the tests" task :default => :test @@ -14,6 +15,14 @@ end end +desc 'Test the cache_fu plugin against Rails 1.2.5' +task :test_with_125 do + ENV['MULTIRAILS_RAILS_VERSION'] = '1.2.5' + test_files.each do |file| + ruby "#{file}" + end +end + desc "Run cache_fu tests using a memcache daemon" task :test_with_memcache do test_files.each do |file| Index: lib/acts_as_cached/fragment_cache.rb =================================================================== --- lib/acts_as_cached/fragment_cache.rb (revision 418) +++ lib/acts_as_cached/fragment_cache.rb (working copy) @@ -35,10 +35,18 @@ ::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| - action.is_a?(Hash) ? hsh.merge(action) : hsh.merge(action => { :ttl => nil }) + if [].respond_to?(:extract_options!) + #edge + @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) + else + #1.2.5 + @actions = actions.inject({}) do |hsh, action| + action.is_a?(Hash) ? hsh.merge(action) : hsh.merge(action => { :ttl => nil }) + end end end @@ -63,11 +71,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, :text => cache) false else # 1.2.x compatibility