Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 193
- Log:
First stage commit of Typo 4.1, modified for the ROOL site.
Includes all local modifications but a final pass needs to be
made to delete any files left over from earlier Typo versions
that shouldn't be here anymore. See the 'tags' section of the
repository for a clean Typo 4.1 tree.Note that symlinks to shared files in the RISC OS Open theme
directory have been deliberately included this time around; I
decided that on balance it was better to leave them in as
placeholders, since unlike symlinks in app/views/shared, the
Typo theme structure is not a standard Rails concept.
- Author:
- rool
- Date:
- Wed Apr 04 18:51:02 +0100 2007
- Size:
- 4894 Bytes
1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | |
3 | require 'dns_mock' |
4 | |
5 | class CommentTest < Test::Unit::TestCase |
6 | fixtures :contents, :feedback, :blacklist_patterns, :text_filters, :blogs |
7 | |
8 | def setup |
9 | CachedModel.cache_reset |
10 | end |
11 | |
12 | def test_permalink_url |
13 | c = feedback(:old_comment) |
14 | assert_equal "http://myblog.net/articles/2004/05/01/inactive-article#comment-#{c.id}", c.permalink_url |
15 | end |
16 | |
17 | def test_edit_url |
18 | c = feedback(:old_comment) |
19 | assert_equal "http://myblog.net/admin/comments/edit/#{c.id}", c.edit_url |
20 | end |
21 | |
22 | def test_delete_url |
23 | c = feedback(:old_comment) |
24 | assert_equal "http://myblog.net/admin/comments/destroy/#{c.id}", c.delete_url |
25 | end |
26 | |
27 | def test_save_regular |
28 | assert feedback(:comment2).save |
29 | assert_equal "http://www.google.com", feedback(:comment2).url |
30 | end |
31 | |
32 | def test_save_spam |
33 | assert feedback(:spam_comment).save |
34 | assert_equal "http://fakeurl.com", feedback(:spam_comment).url |
35 | end |
36 | |
37 | def test_create_comment |
38 | c = Comment.new |
39 | c.author = 'Bob' |
40 | c.article_id = 1 |
41 | c.body = 'nice post' |
42 | c.ip = '1.2.3.4' |
43 | |
44 | assert c.save |
45 | assert c.guid.size > 15 |
46 | end |
47 | |
48 | def test_reject_spam_rbl |
49 | cmt = Comment.new do |c| |
50 | c.author = "Spammer" |
51 | c.body = %{This is just some random text. <a href="http://chinaaircatering.com">without any senses.</a>. Please disregard.} |
52 | c.url = "http://buy-computer.us" |
53 | c.ip = "212.42.230.206" |
54 | end |
55 | assert cmt.spam? |
56 | assert !cmt.status_confirmed? |
57 | end |
58 | |
59 | def test_not_spam_but_rbl_lookup_succeeds |
60 | cmt = Comment.new do |c| |
61 | c.author = "Not a Spammer" |
62 | c.body = "Useful commentary!" |
63 | c.url = "http://www.bofh.org.uk" |
64 | c.ip = "10.10.10.10" |
65 | end |
66 | assert !cmt.spam? |
67 | assert !cmt.status_confirmed? |
68 | end |
69 | |
70 | def test_reject_spam_pattern |
71 | cmt = Comment.new do |c| |
72 | c.author = "Another Spammer" |
73 | c.body = "Texas hold-em poker crap" |
74 | c.url = "http://texas.hold-em.us" |
75 | end |
76 | assert cmt.spam? |
77 | assert !cmt.status_confirmed? |
78 | end |
79 | |
80 | def test_reject_spam_uri_limit |
81 | c = Comment.new do |c| |
82 | c.author = "Yet Another Spammer" |
83 | c.body = %{ <a href="http://www.one.com/">one</a> <a href="http://www.two.com/">two</a> <a href="http://www.three.com/">three</a> <a href="http://www.four.com/">four</a> } |
84 | c.url = "http://www.uri-limit.com" |
85 | c.ip = "123.123.123.123" |
86 | end |
87 | |
88 | assert c.spam? |
89 | assert !c.status_confirmed? |
90 | end |
91 | |
92 | def test_reject_article_age |
93 | c = Comment.new do |c| |
94 | c.author = "Old Spammer" |
95 | c.body = "Old trackback body" |
96 | c.article = contents(:inactive_article) |
97 | end |
98 | |
99 | assert ! c.save |
100 | assert c.errors.invalid?('article_id') |
101 | |
102 | c.article = @article1 |
103 | |
104 | assert c.save |
105 | assert c.errors.empty? |
106 | end |
107 | |
108 | def test_modify_old_comment |
109 | c = contents(:inactive_article).comments.first |
110 | c.body = 'Comment body <em>italic</em> <strong>bold</strong>' |
111 | assert c.save |
112 | assert c.errors.empty? |
113 | end |
114 | |
115 | def test_article_relation |
116 | assert feedback(:comment2).article |
117 | assert_equal 1, feedback(:comment2).article.id |
118 | end |
119 | |
120 | def test_xss_rejection |
121 | c = Comment.new do |c| |
122 | c.body = "Test foo <script>do_evil();</script>" |
123 | c.author = 'Bob' |
124 | c.article_id = 1 |
125 | end |
126 | |
127 | # Test each filter to make sure that we don't allow scripts through. |
128 | # Yes, this is ugly. |
129 | ['','textile','markdown','smartypants','markdown smartypants'].each do |filter| |
130 | this_blog.comment_text_filter = filter |
131 | |
132 | assert c.save |
133 | assert c.errors.empty? |
134 | |
135 | assert c.html(:body) !~ /<script>/ |
136 | end |
137 | end |
138 | |
139 | def test_withdraw |
140 | c = Comment.find(feedback(:comment2).id) |
141 | assert c.withdraw! |
142 | assert ! c.published? |
143 | assert c.spam? |
144 | assert c.status_confirmed? |
145 | c.reload |
146 | assert ! c.published? |
147 | assert c.spam? |
148 | assert c.status_confirmed? |
149 | end |
150 | |
151 | def test_published |
152 | a = Article.new(:title => 'foo', :blog_id => 1) |
153 | assert a.save |
154 | |
155 | assert_equal 0, a.published_comments.size |
156 | c = a.comments.build(:body => 'foo', :author => 'bob', :published => true, :published_at => Time.now) |
157 | assert c.save |
158 | assert c.published? |
159 | c.reload |
160 | a.reload |
161 | |
162 | assert_equal 1, a.published_comments.size |
163 | c.withdraw! |
164 | |
165 | a = Article.new(:title => 'foo', :blog_id => 1) |
166 | assert_equal 0, a.published_comments.size |
167 | end |
168 | |
169 | def test_status_confirmed |
170 | a = contents(:spammed_article) |
171 | assert !a.comments[0].status_confirmed? |
172 | assert a.comments[1].status_confirmed? |
173 | |
174 | a.reload |
175 | assert_equal 1, |
176 | a.comments.find_all_by_status_confirmed(true).size |
177 | assert_equal 1, |
178 | a.comments.find_all_by_status_confirmed(true).size |
179 | a.comments[0].withdraw! |
180 | assert_equal 2, |
181 | a.comments.find_all_by_status_confirmed(true).size |
182 | end |
183 | |
184 | def test_default_filter |
185 | a = Comment.find(:first) |
186 | assert_equal 'markdown', a.default_text_filter.name |
187 | end |
188 | end |