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 !
technoweenie (author)
Sun Sep 17 22:56:44 -0700 2006
commit  940954d66b52f281bce9ec928ddc91369dd48a90
tree    869e83b42f5844599607ff5a0f523737aefc51eb
parent  ca0a4b4e1d7729035d56aecca7e740f758cd70d0
mephisto / test / unit / article_test.rb
100644 162 lines (130 sloc) 5.507 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
require File.dirname(__FILE__) + '/../test_helper'
 
class ArticleTest < Test::Unit::TestCase
  fixtures :contents, :users, :sections, :sites
 
  def test_should_create_permalink
    a = create_article :title => 'This IS a Tripped out title!!.!1 (well/ not really)', :body => 'foo'
    assert_equal 'this-is-a-tripped-out-title-1-well-not-really', a.permalink
  end
 
  def test_should_set_permalink
    a = create_article :title => 'This IS a Tripped out title!!.!1 (well/ not really)', :body => 'foo', :permalink => 'trippy'
    assert_equal 'trippy', a.permalink
  end
 
  def test_full_permalink
    date = 3.days.ago
    assert_equal ['', date.year, date.month, date.day, 'welcome-to-mephisto'].join('/'), contents(:welcome).full_permalink
  end
 
  def test_should_show_published_status
    assert !Article.new(:published_at => 5.minutes.ago).published?
    assert contents(:welcome).published?
    assert contents(:future).published?
  end
 
  def test_should_show_pending_status
    assert !contents(:welcome).pending?
    assert contents(:future).pending?
  end
 
  def test_should_show_status
    assert_equal :published, contents(:welcome).status
    assert_equal :pending, contents(:future).status
  end
 
  def test_should_cache_redcloth
    a = Article.create :title => 'This IS a Tripped out title!!!1 (well not really)', :user => users(:quentin), :excerpt => '*foo*', :body => '_bar_', :site_id => 1
    assert_equal '<p><strong>foo</strong></p>', a.excerpt_html
    assert_equal '<p><em>bar</em></p>', a.body_html
  end
 
  def test_should_save_filter_from_user
    a = Article.new
    assert_nil a.filter
    a.set_default_filter_from(users(:quentin))
    assert_equal 'textile_filter', a.filter
  end
 
  def test_should_modify_filter
    assert_equal 'textile_filter', contents(:welcome).filter
    
    contents(:welcome).filter = 'markdown_filter'
    contents(:welcome).save
 
    assert_equal 'markdown_filter', contents(:welcome).reload.filter
  end
 
  def test_should_modify_filter_and_leave_comments_alone
    assert_equal 'textile_filter', contents(:welcome_comment).filter
    old_time = contents(:welcome_comment)
    
    contents(:welcome).filter = 'markdown_filter'
    contents(:welcome).save
 
    assert_equal 'textile_filter', contents(:welcome_comment).reload.filter
  end
 
  def test_should_modify_filter_and_not_modify_comment_timestamps
    old_time = contents(:welcome_comment).updated_at
    
    contents(:welcome).filter = 'markdown_filter'
    contents(:welcome).save
 
    assert_equal old_time, contents(:welcome_comment).reload.updated_at
  end
 
  def test_should_cache_bluecloth
    a = Article.create :title => 'simple Title', :user => users(:arthur), :body => "# bar\n\nfoo", :filter => 'markdown_filter', :site_id => 1
    assert_equal "<h1>bar</h1>\n\n<p>foo</p>", a.body_html
  end
 
  def test_should_create_article_version
    assert_difference Article::Version, :count, 2 do
      Article.create :title => 'This IS a Tripped out title!!!1 (well not really)', :body => 'foo', :user_id => 1, :site_id => 1
      contents(:welcome).update_attributes :title => 'whoo!'
    end
  end
 
  def test_should_not_create_article_version_for_useless_changes
    contents(:welcome).body_html = 'nope'
    assert !contents(:welcome).save_version?
  end
 
  def test_comment_expiration_date_on_draft
    a = create_fake_article
    a.published_at = nil
    assert_equal 10.days.from_now.utc.to_i, a.comments_expired_at.to_i
  end
 
  def test_comment_expiration_date
    a = create_fake_article
    assert_equal 5.days.from_now.utc.to_i, a.comments_expired_at.to_i
  end
 
  def test_comment_expiry
    a = create_fake_article(5.days.from_now)
    assert !a.accept_comments?
    a.published_at = 5.days.ago.utc
    assert a.accept_comments?
    a.comment_age = 2
    assert !a.accept_comments?
    a.published_at = 5.years.ago.utc
    assert !a.accept_comments?
    a.comment_age = 0
    assert a.accept_comments?
  end
 
  def test_should_set_published_to_utc
    a = create_article :body => 'body', :published_at => Time.now
    assert a.published_at.utc?
  end
 
  def test_should_find_deleted_user
    assert_equal User.find_with_deleted(3), contents(:another).user
  end
 
  def test_should_set_tags
    assert_equal '', contents(:welcome).tag
    assert_difference Tagging, :count, 2 do
      contents(:welcome).update_attribute :tag, 'ruby, rails'
    end
    assert_equal 'rails, ruby', contents(:welcome).reload.tag
  end
 
  def test_should_set_tags_upon_article_creation
    a = nil
    assert_difference Tagging, :count, 2 do
      a = create_article :tag => 'ruby, rails', :body => 'foo'
      assert_valid a
    end
    assert_equal 'rails, ruby', a.reload.tag
  end
 
  def test_should_find_article_by_permalink
    assert_equal contents(:welcome), sites(:first).articles.find_by_permalink(:id => contents(:welcome).id)
    assert_equal contents(:welcome), sites(:first).articles.find_by_permalink(:permalink => contents(:welcome).permalink)
    assert_equal contents(:welcome), sites(:first).articles.find_by_permalink(:year => contents(:welcome).year, :permalink => contents(:welcome).permalink)
  end
 
  protected
    def create_article(options = {})
      Article.create options.reverse_merge(:user_id => 1, :site_id => 1, :title => 'foo')
    end
    
    def create_fake_article(time = 5.days.ago)
      returning Article.new(:comment_age => 10, :published_at => time.utc) do |a|
        def a.new_record?() false ; end
      end
    end
end