Sha256: 58eb0aca507424746fca739966e903e97e3072c17c3e762a98781596be16a851
Contents?: true
Size: 1.6 KB
Versions: 4
Compression:
Stored size: 1.6 KB
Contents
module CacheHelpers ActionController::Base.public_class_method :page_cache_path class CacheMatcher def initialize(method = :cached?) @method = method end def matches?(actual) (@actual = actual).send @method end def failure_message "Expected path #{@actual.inspect} to be cached, but was not" end def negative_failure_message "Expected path #{@actual.inspect} not to be cached, but it was" end end def be_cached CacheMatcher.new end def be_action_cached CacheMatcher.new(:action_cached?) end def be_page_cached CacheMatcher.new(:page_cached?) end def posts_cache_path(options = {}) ActionController::Caching::Actions::ActionCachePath.new(controller, options.merge(:only_path => true)).path end def show_post_cache_path posts_cache_path :action => 'show', :id => @post.id end def posts_feed_cache_path posts_cache_path :action => 'feed', :format => 'atom' end def self.included(base) base.class_eval do before do path = File.dirname(File.expand_path(ActionController::Base.page_cache_path('/posts/index'))) FileUtils.rm_rf path path = File.expand_path('../dummy_rails_app/public/posts.html', File.dirname(__FILE__)) FileUtils.rm path if File.exist?(path) end end end end class String def action_cached? Rails.cache.exist?(File.join 'views', 'www.example.com', self) end def page_cached? File.exists? ActionController::Base.page_cache_path(self) end def cached? action_cached? || page_cached? end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
mist-0.6.3 | spec/support/cache_helpers.rb |
mist-0.6.2 | spec/support/cache_helpers.rb |
mist-0.6.1 | spec/support/cache_helpers.rb |
mist-0.6.0 | spec/support/cache_helpers.rb |