Skip to content

Commit 782bf07

Browse files
committed
Call to_s on the extension as it may be a symbol. Fixes #10
1 parent a45e972 commit 782bf07

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
* Call `to_s` on the extension as it may be a symbol
2+
3+
Fixes #10
4+
5+
*Andrew White*
6+
7+
## 1.1.1 (January 2, 2014)
8+
19
* Fix load order problem with other gems
210

311
*Andrew White*
412

5-
## 1.1.0
13+
## 1.1.0 (November 1, 2013)
614

715
* Allow to use non-proc object in `cache_path` option. You can pass an object that
816
responds to a `call` method.

lib/action_controller/caching/actions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ def initialize(controller, options = {}, infer_extension = true)
199199

200200
private
201201
def normalize!(path)
202-
ext = URI.parser.escape(extension) if extension
202+
ext = URI.parser.escape(extension.to_s) if extension
203203
path << 'index' if path[-1] == ?/
204204
path << ".#{ext}" if extension and !path.split('?', 2).first.ends_with?(".#{ext}")
205205
URI.parser.unescape(path)

test/caching_test.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@ class ActionCachingTestController < CachingController
2626
# Eliminate uninitialized ivar warning
2727
before_filter { @title = nil }
2828

29+
before_filter only: :with_symbol_format do
30+
request.params[:format] = :json
31+
end
32+
2933
caches_action :index, :redirected, :forbidden, if: Proc.new { |c| c.request.format && !c.request.format.json? }, expires_in: 1.hour
3034
caches_action :show, cache_path: 'http://test.host/custom/show'
3135
caches_action :edit, cache_path: Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : 'http://test.host/edit' }
3236
caches_action :custom_cache_path, cache_path: CachePath.new
3337
caches_action :with_layout
3438
caches_action :with_format_and_http_param, cache_path: Proc.new { |c| { key: 'value' } }
39+
caches_action :with_symbol_format, cache_path: 'http://test.host/action_caching_test/with_symbol_format'
3540
caches_action :layout_false, layout: false
3641
caches_action :with_layout_proc_param, layout: Proc.new { |c| c.params[:layout] }
3742
caches_action :record_not_found, :four_oh_four, :simple_runtime_error
@@ -65,6 +70,11 @@ def with_format_and_http_param
6570
render text: @cache_this
6671
end
6772

73+
def with_symbol_format
74+
@cache_this = MockTime.now.to_f.to_s
75+
render json: { timestamp: @cache_this }
76+
end
77+
6878
def record_not_found
6979
raise ActiveRecord::RecordNotFound, 'oops!'
7080
end
@@ -269,6 +279,13 @@ def test_action_cache_with_format_and_http_param
269279
assert fragment_exist?('hostname.com/action_caching_test/with_format_and_http_param.json?key=value')
270280
end
271281

282+
def test_action_cache_with_symbol_format
283+
get :with_symbol_format
284+
assert_response :success
285+
assert !fragment_exist?('test.host/action_caching_test/with_symbol_format')
286+
assert fragment_exist?('test.host/action_caching_test/with_symbol_format.json')
287+
end
288+
272289
def test_action_cache_with_store_options
273290
MockTime.expects(:now).returns(12345).once
274291
@controller.expects(:read_fragment).with('hostname.com/action_caching_test', expires_in: 1.hour).once

0 commit comments

Comments
 (0)