Created
June 12, 2012 19:46
-
-
Save avit/2919699 to your computer and use it in GitHub Desktop.
Testing page caching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostsController < ApplicationController | |
caches_page :index | |
def index | |
render text: "html!" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
describe PostsController do | |
describe "GET index", caching: true do | |
around do |example| | |
ActionController::Base.perform_caching = true | |
Rails.application.config.action_controller.perform_caching = true | |
example.run | |
ActionController::Base.perform_caching = false | |
Rails.application.config.action_controller.perform_caching = false | |
end | |
it "caches the index page" do | |
controller.class.perform_caching.should be_true # true. | |
controller.should_receive(:cache_page).and_return true | |
# ^ .with("html!", controller: "posts", action: "index") | |
get :index | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Turns out page caching only works when
perform_caching
is set in environments/test.rb.Turning it on selectively the spec doesn't work: I suspect this is a reloading issue, even though checking
perform_caching
in the spec example returns true.