aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/middleware/cache_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test/application/middleware/cache_test.rb')
-rw-r--r--railties/test/application/middleware/cache_test.rb38
1 files changed, 24 insertions, 14 deletions
diff --git a/railties/test/application/middleware/cache_test.rb b/railties/test/application/middleware/cache_test.rb
index fffe79f9cc..c99666d7e4 100644
--- a/railties/test/application/middleware/cache_test.rb
+++ b/railties/test/application/middleware/cache_test.rb
@@ -19,17 +19,17 @@ module ApplicationTests
controller :expires, <<-RUBY
class ExpiresController < ApplicationController
def expires_header
- expires_in 10, :public => !params[:private]
- render :text => SecureRandom.hex(16)
+ expires_in 10, public: !params[:private]
+ render text: SecureRandom.hex(16)
end
def expires_etag
- render_conditionally(:etag => "1")
+ render_conditionally(etag: "1")
end
def expires_last_modified
$last_modified ||= Time.now.utc
- render_conditionally(:last_modified => $last_modified)
+ render_conditionally(last_modified: $last_modified)
end
def keeps_if_modified_since
@@ -37,8 +37,8 @@ module ApplicationTests
end
private
def render_conditionally(headers)
- if stale?(headers.merge(:public => !params[:private]))
- render :text => SecureRandom.hex(16)
+ if stale?(headers.merge(public: !params[:private]))
+ render text: SecureRandom.hex(16)
end
end
end
@@ -49,8 +49,6 @@ module ApplicationTests
get ':controller(/:action)'
end
RUBY
-
- add_to_config "config.action_dispatch.rack_cache = true"
end
def test_cache_keeps_if_modified_since
@@ -80,6 +78,8 @@ module ApplicationTests
def test_cache_works_with_expires
simple_controller
+ add_to_config "config.action_dispatch.rack_cache = true"
+
get "/expires/expires_header"
assert_equal "miss, store", last_response.headers["X-Rack-Cache"]
assert_equal "max-age=10, public", last_response.headers["Cache-Control"]
@@ -96,13 +96,15 @@ module ApplicationTests
def test_cache_works_with_expires_private
simple_controller
- get "/expires/expires_header", :private => true
+ add_to_config "config.action_dispatch.rack_cache = true"
+
+ get "/expires/expires_header", private: true
assert_equal "miss", last_response.headers["X-Rack-Cache"]
assert_equal "private, max-age=10", last_response.headers["Cache-Control"]
body = last_response.body
- get "/expires/expires_header", :private => true
+ get "/expires/expires_header", private: true
assert_equal "miss", last_response.headers["X-Rack-Cache"]
assert_not_equal body, last_response.body
end
@@ -110,6 +112,8 @@ module ApplicationTests
def test_cache_works_with_etags
simple_controller
+ add_to_config "config.action_dispatch.rack_cache = true"
+
get "/expires/expires_etag"
assert_equal "miss, store", last_response.headers["X-Rack-Cache"]
assert_equal "public", last_response.headers["Cache-Control"]
@@ -125,14 +129,16 @@ module ApplicationTests
def test_cache_works_with_etags_private
simple_controller
- get "/expires/expires_etag", :private => true
+ add_to_config "config.action_dispatch.rack_cache = true"
+
+ get "/expires/expires_etag", private: true
assert_equal "miss", last_response.headers["X-Rack-Cache"]
assert_equal "must-revalidate, private, max-age=0", last_response.headers["Cache-Control"]
body = last_response.body
etag = last_response.headers["ETag"]
- get "/expires/expires_etag", {:private => true}, "If-None-Match" => etag
+ get "/expires/expires_etag", {private: true}, "If-None-Match" => etag
assert_equal "miss", last_response.headers["X-Rack-Cache"]
assert_not_equal body, last_response.body
end
@@ -140,6 +146,8 @@ module ApplicationTests
def test_cache_works_with_last_modified
simple_controller
+ add_to_config "config.action_dispatch.rack_cache = true"
+
get "/expires/expires_last_modified"
assert_equal "miss, store", last_response.headers["X-Rack-Cache"]
assert_equal "public", last_response.headers["Cache-Control"]
@@ -155,14 +163,16 @@ module ApplicationTests
def test_cache_works_with_last_modified_private
simple_controller
- get "/expires/expires_last_modified", :private => true
+ add_to_config "config.action_dispatch.rack_cache = true"
+
+ get "/expires/expires_last_modified", private: true
assert_equal "miss", last_response.headers["X-Rack-Cache"]
assert_equal "must-revalidate, private, max-age=0", last_response.headers["Cache-Control"]
body = last_response.body
last = last_response.headers["Last-Modified"]
- get "/expires/expires_last_modified", {:private => true}, "If-Modified-Since" => last
+ get "/expires/expires_last_modified", {private: true}, "If-Modified-Since" => last
assert_equal "miss", last_response.headers["X-Rack-Cache"]
assert_not_equal body, last_response.body
end