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 !
mephisto / test / unit / cached_page_test.rb
100644 51 lines (43 sloc) 1.789 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
require File.dirname(__FILE__) + '/../test_helper'
 
class CachedPageTest < Test::Unit::TestCase
  fixtures :contents, :sites, :cached_pages
  
  def test_should_find_by_references
    assert_models_equal [cached_pages(:first)], sites(:first).cached_pages.find_by_references(contents(:welcome))
  end
 
  def test_should_find_by_reference_keys
    assert_models_equal [cached_pages(:first)], sites(:first).cached_pages.find_by_reference_keys(['Article', 1])
  end
 
  def test_should_find_by_reference_key
    assert_models_equal [cached_pages(:first)], sites(:first).cached_pages.find_by_reference_key('Article', 1)
  end
  
  def test_should_create_cached_page
    assert_difference CachedPage, :count do
      assert_difference sites(:first).cached_pages, :count do
        page = CachedPage.create_by_url(sites(:first), '/blah', [contents(:welcome)])
        assert_valid page
        assert_equal '/blah', page.url
        assert_equal "[1:Article]", page.references
      end
    end
  end
  
  def test_should_create_cached_page_from_existing_record
    assert_no_difference CachedPage, :count do
      assert_no_difference sites(:first).cached_pages, :count do
        page = CachedPage.create_by_url(sites(:first), '/bar', [contents(:welcome)])
        assert_valid page
        assert_equal '/bar', page.url
        assert_equal "[1:Article]", page.references
        assert_equal cached_pages(:first_cleared), page
        assert_nil page.cleared_at
      end
    end
  end
  
  def test_should_expire_sites
    assert_no_difference CachedPage, :count do
      assert_no_difference sites(:first).cached_pages, :count do
        CachedPage.expire_pages(sites(:first), [cached_pages(:first)])
        assert_not_nil cached_pages(:first).reload.cleared_at
      end
    end
  end
end