GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

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
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
mephisto / test / unit / site_permalink_test.rb
100644 86 lines (69 sloc) 2.841 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
require File.dirname(__FILE__) + '/../test_helper'
require 'site'
 
context "Site Permalink Validations" do
  fixtures :sites
  
  def setup
    @site = sites(:first)
  end
  
  specify "should strip ending and beginning slashes" do
    @site.permalink_style = '/:year/:month/:day/:permalink/'
    assert_valid @site
    assert_equal ':year/:month/:day/:permalink', @site.permalink_style
  end
  
  specify "should not allow empty paths" do
    @site.permalink_style = ':year//:month/:day/:permalink'
    assert !@site.valid?
    assert_match /blank/, @site.errors.on(:permalink_style)
  end
  
  specify "should require either permalink or id" do
    @site.permalink_style = ':year/:month/:day'
    assert !@site.valid?
    assert_equal "must contain either :permalink or :id", @site.errors.on(:permalink_style)
  end
  
  specify "should require at least year for any date based permalinks" do
    %w(month day).each do |var|
      @site.permalink_style = ":#{var}/:id"
      assert !@site.valid?
      assert_equal "must contain :year for any date-based permalinks", @site.errors.on(:permalink_style)
    end
  end
  
  specify "should require valid attributes" do
    @site.permalink_style = ':year/:month/:day/:permalink/:id'
    assert_valid @site
 
    @site.permalink_style = ':year/:foo/:month/:day/:permalink'
    assert !@site.valid?
    assert_equal "cannot contain ':foo' variable", @site.errors.on(:permalink_style)
  end
 
  specify "should not recongize hyphens as token separators" do
    @site.permalink_style = ':id-:permalink'
    assert !@site.valid?
  end
end
 
context "Site Permalink Generation" do
  fixtures :sites, :contents
  
  def setup
    @site = sites(:first)
    @article = contents(:welcome)
  end
 
  specify "should generate correct permalink format" do
    assert_equal "/#{@article.year}/#{@article.month}/#{@article.day}/#{@article.permalink}", @site.permalink_for(@article)
  end
 
  specify "should generate correct permalink format with comment" do
    assert_equal "/#{@article.year}/#{@article.month}/#{@article.day}/#{@article.permalink}", @site.permalink_for(contents(:welcome_comment))
  end
 
  specify "should generate correct permalink format for draft" do
    @article.published_at = nil
    now = Time.now.utc
    assert_equal "/#{now.year}/#{now.month}/#{now.day}/#{@article.permalink}", @site.permalink_for(@article)
  end
 
  specify "should generate custom id permalink" do
    @site.permalink_style = 'posts/:year/:id'
    assert_valid @site
    assert_equal "/posts/#{@article.year}/#{@article.id}", @site.permalink_for(@article)
  end
 
  specify "should generate custom id permalink with comment" do
    @site.permalink_style = 'posts/:year/:id'
    assert_valid @site
    assert_equal "/posts/#{@article.year}/#{@article.id}", @site.permalink_for(contents(:welcome_comment))
  end
end