Methods
- S
- T
-
- teardown,
- test_cache_is_disabled_in_dev_mode,
- test_cache_keeps_if_modified_since,
- test_cache_works_with_etags,
- test_cache_works_with_etags_private,
- test_cache_works_with_expires,
- test_cache_works_with_expires_private,
- test_cache_works_with_last_modified,
- test_cache_works_with_last_modified_private,
- test_root_path
Included Modules
- ActiveSupport::Testing::Isolation
- Rack::Test::Methods
Constants
| InitializeRackApp | = | lambda { |env| [200, {}, ["InitializeRackApp"]] } |
Instance Public methods
setup()
Link
simple_controller()
Link
# File railties/test/application/middleware/cache_test.rb, line 18 def simple_controller controller :expires, <<-RUBY class ExpiresController < ApplicationController def expires_header expires_in 10, :public => !params[:private] render :text => SecureRandom.hex(16) end def expires_etag render_conditionally(:etag => "1") end def expires_last_modified $last_modified ||= Time.now.utc render_conditionally(:last_modified => $last_modified) end def keeps_if_modified_since render :text => request.headers['If-Modified-Since'] end private def render_conditionally(headers) if stale?(headers.merge(:public => !params[:private])) render :text => SecureRandom.hex(16) end end end RUBY app_file 'config/routes.rb', <<-RUBY AppTemplate::Application.routes.draw do match ':controller(/:action)' end RUBY end
teardown()
Link
test_cache_is_disabled_in_dev_mode()
Link
# File railties/test/application/middleware/cache_test.rb, line 64 def test_cache_is_disabled_in_dev_mode simple_controller app("development") get "/expires/expires_header" assert_nil last_response.headers['X-Rack-Cache'] body = last_response.body get "/expires/expires_header" assert_nil last_response.headers['X-Rack-Cache'] assert_not_equal body, last_response.body end
test_cache_keeps_if_modified_since()
Link
# File railties/test/application/middleware/cache_test.rb, line 54 def test_cache_keeps_if_modified_since simple_controller expected = "Wed, 30 May 1984 19:43:31 GMT" get "/expires/keeps_if_modified_since", {}, "HTTP_IF_MODIFIED_SINCE" => expected assert_equal 200, last_response.status assert_equal expected, last_response.body, "cache should have kept If-Modified-Since" end
test_cache_works_with_expires()
Link
# File railties/test/application/middleware/cache_test.rb, line 78 def test_cache_works_with_expires simple_controller 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"] body = last_response.body get "/expires/expires_header" assert_equal "fresh", last_response.headers["X-Rack-Cache"] assert_equal body, last_response.body end
test_cache_works_with_expires_private()
Link
# File railties/test/application/middleware/cache_test.rb, line 94 def test_cache_works_with_expires_private simple_controller 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 assert_equal "miss", last_response.headers["X-Rack-Cache"] assert_not_equal body, last_response.body end
test_cache_works_with_last_modified()
Link
# File railties/test/application/middleware/cache_test.rb, line 138 def test_cache_works_with_last_modified simple_controller get "/expires/expires_last_modified" assert_equal "miss, store", last_response.headers["X-Rack-Cache"] assert_equal "public", last_response.headers["Cache-Control"] body = last_response.body last = last_response.headers["Last-Modified"] get "/expires/expires_last_modified", {}, "If-Modified-Since" => last assert_equal "stale, valid, store", last_response.headers["X-Rack-Cache"] assert_equal body, last_response.body end
test_cache_works_with_last_modified_private()
Link
# File railties/test/application/middleware/cache_test.rb, line 153 def test_cache_works_with_last_modified_private simple_controller 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 assert_equal "miss", last_response.headers["X-Rack-Cache"] assert_not_equal body, last_response.body end
test_root_path()
Link
# File railties/test/application/routing_test.rb, line 232 def test_root_path app('development') controller :foo, <<-RUBY class FooController < ApplicationController def index render :text => "foo" end end RUBY app_file 'config/routes.rb', <<-RUBY AppTemplate::Application.routes.draw do get 'foo', :to => 'foo#index' root :to => 'foo#index' end RUBY remove_file 'public/index.html' get '/' assert_equal 'foo', last_response.body end