Skip to content

Commit

Permalink
Add specs for page caching matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
avit committed Mar 10, 2014
1 parent 409cc67 commit 3b9b3cb
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
42 changes: 42 additions & 0 deletions spec/controllers/page_caching_spec.rb
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
32 changes: 32 additions & 0 deletions spec/resources/controllers/page_cache_spec_controller.rb
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
27 changes: 27 additions & 0 deletions spec/spec_helper.rb
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

0 comments on commit 3b9b3cb

Please sign in to comment.