public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Search Repo:
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
technoweenie (author)
Mon Jun 30 20:27:44 -0700 2008
commit  90e2cc253d94e2e544bc8b21f361c7360c1e9baa
tree    a8ae6d1f78307684fa5d0dd8f6dab5d0cb3990d2
parent  726723707b68665855b19d9f5999b38454c8fc37
mephisto / test / referenced_caching_test_helper.rb
100644 52 lines (44 sloc) 1.808 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
module Mephisto # :nodoc:
  module Caching # :nodoc:
    module ReferencedCachingTestHelper
      # Prepares a caching directory for use. Put this in your test case's #setup method.
      # Be sure to CHANGE the page_cache_directory in config/environments/test.rb, otherwise
      # this will remove your complete public directory
      def prepare_for_caching!
        FileUtils.rm_rf ActionController::Base.page_cache_directory rescue nil
        FileUtils.mkdir_p ActionController::Base.page_cache_directory
      end
 
      def assert_caches_pages(*urls)
        yield(urls) if block_given?
        urls.map { |url| assert_cached url }
      end
 
      def assert_expires_pages(*urls)
        yield(urls) if block_given?
        urls.map { |url| assert_not_cached url }
      end
 
      # Asserts a page was cached.
      def assert_cached(url)
        assert page_cache_exists?(url), "#{url} is not cached"
      end
 
      # Asserts a page was not cached.
      def assert_not_cached(url)
        assert !page_cache_exists?(url), "#{url} is cached"
      end
 
      alias assert_caches_page assert_caches_pages
      alias assert_expires_page assert_expires_pages
 
      private
        # Gets the page cache filename given a relative URL like /blah
        def page_cache_file(url)
          ActionController::Base.send :page_cache_file, url.gsub(/^https?:\/\//, '')
        end
 
        # Gets a test page cache filename given a relative URL like /blah
        def page_cache_test_file(url)
          File.join ActionController::Base.page_cache_directory, page_cache_file(url).reverse.chomp('/').reverse
        end
 
        # Returns true/false whether the page cache file exists.
        def page_cache_exists?(url)
          File.exists? page_cache_test_file(url)
        end
    end
  end
end