Permalink
Browse files

Ensure that the format isn't applied twice to the cache key, else it …

…becomes impossible to target with expire_action.
  • Loading branch information...
1 parent 58b0d50 commit b23cd21c2d936ac12aa3f1dbbeb61f1b3348441e @cmeiklejohn cmeiklejohn committed with tenderlove Jul 30, 2011
Showing with 14 additions and 1 deletion.
  1. +1 −1 actionpack/lib/action_controller/caching/actions.rb
  2. +13 −0 actionpack/test/controller/caching_test.rb
View
2 actionpack/lib/action_controller/caching/actions.rb
@@ -175,7 +175,7 @@ def initialize(controller, options = {}, infer_extension = true)
private
def normalize!(path)
path << 'index' if path[-1] == ?/
- path << ".#{extension}" if extension and !path.ends_with?(extension)
+ path << ".#{extension}" if extension and !path.split('?').first.try(:ends_with?, ".#{extension}")
URI.parser.unescape(path)
end
end
View
13 actionpack/test/controller/caching_test.rb
@@ -191,6 +191,7 @@ class ActionCachingTestController < CachingController
caches_action :show, :cache_path => 'http://test.host/custom/show'
caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : "http://test.host/edit" }
caches_action :with_layout
+ caches_action :with_format_and_http_param, :cache_path => Proc.new { |c| { :key => 'value' } }
caches_action :layout_false, :layout => false
caches_action :record_not_found, :four_oh_four, :simple_runtime_error
@@ -216,6 +217,11 @@ def with_layout
render :text => @cache_this, :layout => true
end
+ def with_format_and_http_param
+ @cache_this = MockTime.now.to_f.to_s
+ render :text => @cache_this
+ end
+
def record_not_found
raise ActiveRecord::RecordNotFound, "oops!"
end
@@ -356,6 +362,13 @@ def test_action_cache_conditional_options
assert !fragment_exist?('hostname.com/action_caching_test')
end
+ def test_action_cache_with_format_and_http_param
+ get :with_format_and_http_param, :format => 'json'
+ assert_response :success
+ assert !fragment_exist?('hostname.com/action_caching_test/with_format_and_http_param.json?key=value.json')
+ assert fragment_exist?('hostname.com/action_caching_test/with_format_and_http_param.json?key=value')
+ end
+
def test_action_cache_with_store_options
MockTime.expects(:now).returns(12345).once
@controller.expects(:read_fragment).with('hostname.com/action_caching_test', :expires_in => 1.hour).once

0 comments on commit b23cd21

Please sign in to comment.