-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require_relative '../spec_helper' | ||
require_relative '../resources/controllers/page_cache_spec_controller' | ||
|
||
describe PageCacheSpecController, :type => :controller do | ||
describe "response.should cache_page" do | ||
|
||
it "matches an action for a cached page" do | ||
expect { | ||
expect { get "action_with_page_caching" } | ||
.to cache_page '/action_with_page_caching' | ||
}.to_not raise_error | ||
end | ||
|
||
it "does not match an action for an uncached page" do | ||
expect { | ||
expect { get "action_without_page_caching" } | ||
.to cache_page '/action_without_page_caching' | ||
}.to raise_error(RSpec::Expectations::ExpectationNotMetError) | ||
end | ||
|
||
end | ||
|
||
describe "response.should expire_page" do | ||
|
||
it "matches an action for an expired page" do | ||
expect { | ||
get "action_with_page_caching" | ||
expect { get "action_with_page_expiry" } | ||
.to expire_page '/action_with_page_caching' | ||
}.to_not raise_error | ||
end | ||
|
||
it "does not match an action without expiry" do | ||
expect { | ||
expect { get "action_with_page_caching" } | ||
.to expire_page '/action_with_page_caching' | ||
}.to raise_error(RSpec::Expectations::ExpectationNotMetError) | ||
end | ||
|
||
end | ||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class PageCacheSpecController < ActionController::Base | ||
include Rails.application.routes.url_helpers | ||
|
||
caches_page :action_with_page_caching | ||
|
||
def action_without_page_caching | ||
render :text => "" | ||
end | ||
|
||
def action_with_page_caching | ||
render :text => "" | ||
end | ||
|
||
def action_with_page_expiry | ||
expire_page :action => 'action_with_page_caching' | ||
render :text => "" | ||
end | ||
end | ||
|
||
RSpec::Rails::Application.routes.draw do | ||
get "action_without_page_caching", | ||
:controller => "page_cache_spec", | ||
:action => "action_without_page_caching" | ||
|
||
get "action_with_page_caching", | ||
:controller => "page_cache_spec", | ||
:action => "action_with_page_caching" | ||
|
||
get "action_with_page_expiry", | ||
:controller => "page_cache_spec", | ||
:action => "action_with_page_expiry" | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'rails' | ||
require 'action_controller/railtie' | ||
unless Rails::VERSION::MAJOR < 4 | ||
require 'action_controller/action_caching' | ||
require 'action_controller/page_caching' | ||
end | ||
require 'rspec/rails' | ||
require 'rspec-rails-caching' | ||
|
||
module RSpec::Rails | ||
class Application < ::Rails::Application | ||
config.secret_key_base = 'test' | ||
config.action_controller.page_cache_directory = | ||
File.dirname(__FILE__) | ||
end | ||
end | ||
|
||
RSpec.configure do |config| | ||
config.before(:each) do | ||
@real_world = RSpec.world | ||
RSpec.instance_variable_set(:@world, RSpec::Core::World.new) | ||
end | ||
config.after(:each) do | ||
RSpec.instance_variable_set(:@world, @real_world) | ||
end | ||
config.order = :random | ||
end |