Created
November 28, 2011 03:33
-
-
Save cailinanne/1398979 to your computer and use it in GitHub Desktop.
Testing cache clearing with Rails 3.1 and Rspec
This file contains 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
#spec/requests/cache_book_spec.rb | |
require 'spec_helper' | |
describe "CacheBook" do | |
# Turn on caching | |
before do | |
ActionController::Base.perform_caching = true | |
ActionController::Base.cache_store = :file_store, "tmp/cache" | |
FileUtils.rm_rf(Dir['tmp/cache']) | |
end | |
it "show page cache is primed and cleared under correct cicumstances" do | |
book = FactoryGirl.create(:book,:title => "Fabulous Red Dog") | |
# 1. Start out with no cache | |
book_path.is_action_cached?.should be_false | |
# 2. Check to make sure that we do prime the cache if we visit the page | |
get book_path(book) | |
response.body.should have_content("Fabulous Red Dog") | |
response.should be_action_cached(request) | |
# 3. When a book is updated, check to make sure the cache is cleared | |
book.title = "Fabulous Blue Cat" | |
book.save! | |
book_path(book).is_action_cached?.should be_false | |
# 4. Visit the page again, make sure we see updated content and that the cache is re-primed | |
get book_path(book) | |
response.body.should have_content("Fabulous Blue Cat") | |
response.should be_action_cached(request) | |
end | |
# Turn off caching | |
after do | |
ActionController::Base.perform_caching = false | |
FileUtils.rm_rf(Dir['tmp/cache']) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rails.cache.clear
>FileUtils.rm_rf