Created
August 20, 2012 15:18
-
-
Save mirakui/3405104 to your computer and use it in GitHub Desktop.
大域的なperform_cachingの値にかかわらずcaches_actionのテストをする
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 FooController < ApplicationController | |
caches_action :index | |
def index | |
render :text => Time.now | |
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 FooController do | |
describe "GET 'index'" do | |
before(:all) do | |
request.host = 'example.com' | |
end | |
around do |example| | |
ActionController::Base.cache_store.clear | |
old_perform_caching = ActionController::Base.perform_caching | |
ActionController::Base.perform_caching = perform_caching | |
reload_controller_class FooController | |
old_controller = @controller | |
@controller = FooController.new | |
example.run | |
@controller = old_controller | |
ActionController::Base.perform_caching = old_perform_caching | |
reload_controller_class FooController | |
ActionController::Base.cache_store.clear | |
end | |
describe "caching" do | |
let(:perform_caching) { true } | |
before do | |
get 'index' | |
end | |
subject { controller.fragment_exist?('example.com/foo') } | |
it { should be_true } | |
end | |
describe "without caching" do | |
let(:perform_caching) { false } | |
before do | |
get 'index' | |
end | |
subject { controller.fragment_exist?('example.com/foo') } | |
it { should be_false } | |
end | |
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
# : | |
# (略) | |
# : | |
def reload_controller_class(controller_class) | |
Object.send(:remove_const, controller_class.to_s) | |
load Rails.root.join("app/controllers/#{controller_class.to_s.underscore}.rb") | |
end |
Author
mirakui
commented
Aug 20, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment