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:
- 8953 Bytes
1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | |
3 | require 'http_mock' |
4 | |
5 | class ArticleTest < Test::Unit::TestCase |
6 | fixtures :blogs, :contents, :articles_tags, :tags, :resources, :categories, :categorizations, :users, :notifications, :text_filters |
7 | |
8 | def setup |
9 | @articles = [] |
10 | end |
11 | |
12 | def assert_results_are(*expected) |
13 | assert_equal expected.size, @articles.size |
14 | expected.each do |i| |
15 | assert @articles.include?(i.is_a?(Symbol) ? contents(i) : i) |
16 | end |
17 | end |
18 | |
19 | def test_content_fields |
20 | a = Article.new |
21 | assert_equal [:body, :extended], a.content_fields |
22 | end |
23 | |
24 | def test_permalink_url |
25 | a = contents(:article3) |
26 | assert_equal 'http://myblog.net/articles/2004/06/01/article-3', a.permalink_url |
27 | end |
28 | |
29 | def test_edit_url |
30 | a = contents(:article3) |
31 | assert_equal 'http://myblog.net/admin/content/edit/3', a.edit_url |
32 | end |
33 | |
34 | def test_delete_url |
35 | a = contents(:article3) |
36 | assert_equal 'http://myblog.net/admin/content/destroy/3', a.delete_url |
37 | end |
38 | |
39 | def test_feed_url |
40 | a = contents(:article3) |
41 | assert_equal 'http://myblog.net/xml/atom10/article/3/feed.xml', a.feed_url(:atom10) |
42 | assert_equal 'http://myblog.net/xml/rss20/article/3/feed.xml', a.feed_url(:rss20) |
43 | end |
44 | |
45 | def test_blog |
46 | a = Article.new |
47 | |
48 | assert_equal(1, a.blog_id) |
49 | assert_kind_of(Blog, a.blog) |
50 | end |
51 | |
52 | def test_create |
53 | a = Article.new |
54 | a.user_id = 1 |
55 | a.body = "Foo" |
56 | a.title = "Zzz" |
57 | assert a.save |
58 | |
59 | a.categories << Category.find(1) |
60 | assert_equal 1, a.categories.size |
61 | |
62 | b = Article.find(a.id) |
63 | assert_equal 1, b.categories.size |
64 | end |
65 | |
66 | def test_permalink |
67 | assert_equal( contents(:article3), this_blog.articles.find_by_date(2004,06,01) ) |
68 | assert_equal( [contents(:article2), contents(:article1)], |
69 | this_blog.articles.find_all_by_date(2.days.ago.year) ) |
70 | end |
71 | |
72 | def test_permalink_with_title |
73 | assert_equal( contents(:article3), |
74 | this_blog.articles.find_by_permalink(2004, 06, 01, "article-3") ) |
75 | assert_nil this_blog.articles.find_by_permalink(2005, 06, 01, "article-5") |
76 | end |
77 | |
78 | def test_strip_title |
79 | assert_equal "article-3", "Article-3".to_url |
80 | assert_equal "article-3", "Article 3!?#".to_url |
81 | assert_equal "there-is-sex-in-my-violence", "There is Sex in my Violence!".to_url |
82 | assert_equal "article", "-article-".to_url |
83 | assert_equal "lorem-ipsum-dolor-sit-amet-consectetaur-adipisicing-elit", "Lorem ipsum dolor sit amet, consectetaur adipisicing elit".to_url |
84 | assert_equal "my-cats-best-friend", "My Cat's Best Friend".to_url |
85 | end |
86 | |
87 | def test_perma_title |
88 | assert_equal "article-1", contents(:article1).stripped_title |
89 | assert_equal "article-2", contents(:article2).stripped_title |
90 | assert_equal "article-3", contents(:article3).stripped_title |
91 | end |
92 | |
93 | def test_html_title |
94 | a = Article.new |
95 | a.title = "This <i>is</i> a <b>test</b>" |
96 | assert a.save |
97 | |
98 | assert_equal 'this-is-a-test', a.permalink |
99 | end |
100 | |
101 | def test_urls |
102 | urls = contents(:article4).html_urls |
103 | assert_equal ["http://www.example.com/public"], urls |
104 | end |
105 | |
106 | ### XXX: Should we have a test here? |
107 | def test_send_pings |
108 | end |
109 | |
110 | ### XXX: Should we have a test here? |
111 | def test_send_multiple_pings |
112 | end |
113 | |
114 | def test_tags |
115 | a = Article.new(:title => 'Test tag article', |
116 | :keywords => 'test tag tag stuff'); |
117 | |
118 | assert_kind_of Article, a |
119 | assert_equal 0, a.tags.size |
120 | |
121 | a.keywords_to_tags |
122 | |
123 | assert_equal 3, a.tags.size |
124 | assert_equal ["test", "tag", "stuff"].sort , a.tags.collect {|t| t.name}.sort |
125 | assert a.save |
126 | |
127 | a.keywords = 'tag bar stuff foo' |
128 | a.keywords_to_tags |
129 | |
130 | assert_equal 4, a.tags.size |
131 | assert_equal ["foo", "bar", "tag", "stuff"].sort , a.tags.collect {|t| t.name}.sort |
132 | |
133 | a.keywords='tag bar' |
134 | a.keywords_to_tags |
135 | |
136 | assert_equal 2, a.tags.size |
137 | |
138 | a.keywords='' |
139 | a.keywords_to_tags |
140 | |
141 | assert_equal 0, a.tags.size |
142 | |
143 | b = Article.new(:title => 'Tag Test 2', |
144 | :keywords => 'tag test article one two three') |
145 | |
146 | assert_kind_of Article,b |
147 | assert_equal 0, b.tags.size |
148 | |
149 | c = Article.new(:title => 'Foo', :keywords => 'test "tag test" web2.0') |
150 | c.keywords_to_tags |
151 | |
152 | assert_equal 3, c.tags.size |
153 | assert_equal ['test', 'tagtest', 'web2.0'].sort, c.tags.collect(&:name).sort |
154 | end |
155 | |
156 | def test_find_published_by_tag_name |
157 | @articles = Tag.find_by_name(tags(:foo_tag).name).published_articles |
158 | |
159 | assert_results_are(:article1, :article2) |
160 | end |
161 | |
162 | |
163 | def test_find_published |
164 | @articles = this_blog.articles.find_published |
165 | assert_results_are(:search_target, :article1, :article2, |
166 | :article3, :inactive_article,:xmltest, |
167 | :spammed_article) |
168 | |
169 | @articles = this_blog.articles.find_published(:all, |
170 | :conditions => "title = 'Article 1!'") |
171 | assert_results_are :article1 |
172 | end |
173 | |
174 | def test_just_published_flag |
175 | art = this_blog.articles.build(:title => 'title', |
176 | :body => 'body', |
177 | :published => true) |
178 | assert art.just_published? |
179 | assert art.save |
180 | art.reload |
181 | assert !art.just_published? |
182 | |
183 | art = Article.create!(:title => 'title2', |
184 | :body => 'body', |
185 | :published => false) |
186 | |
187 | assert ! art.just_published? |
188 | end |
189 | |
190 | def test_future_publishing |
191 | assert_sets_trigger(Article.create!(:title => 'title', :body => 'body', |
192 | :published => true, |
193 | :published_at => Time.now + 4.seconds)) |
194 | end |
195 | |
196 | def test_future_publishing_without_published_flag |
197 | assert_sets_trigger Article.create!(:title => 'title', :body => 'body', |
198 | :published_at => Time.now + 4.seconds) |
199 | end |
200 | |
201 | def test_triggers_are_dependent |
202 | art = Article.create!(:title => 'title', :body => 'body', |
203 | :published_at => Time.now + 1.hour) |
204 | assert_equal 1, Trigger.count |
205 | art.destroy |
206 | assert_equal 0, Trigger.count |
207 | end |
208 | |
209 | def assert_sets_trigger(art) |
210 | assert_equal 1, Trigger.count |
211 | assert Trigger.find(:first, :conditions => ['pending_item_id = ?', art.id]) |
212 | sleep 4 |
213 | Trigger.fire |
214 | art.reload |
215 | assert art.published |
216 | end |
217 | |
218 | def test_find_published_by_category |
219 | Article.create!(:title => "News from the future!", |
220 | :body => "The future is cool!", |
221 | :keywords => "future", |
222 | :published_at => Time.now + 12.minutes) |
223 | |
224 | @articles = Category.find_by_permalink('personal').published_articles |
225 | assert_results_are :article1, :article2, :article3 |
226 | |
227 | @articles = Category.find_by_permalink('foobar').published_articles |
228 | assert @articles.empty? |
229 | |
230 | @articles = Category.find_by_permalink('software').published_articles |
231 | assert_results_are :article1 |
232 | end |
233 | |
234 | def test_destroy_file_upload_associations |
235 | assert_equal 2, contents(:article1).resources.size |
236 | contents(:article1).resources << resources(:resource1) << resources(:resource2) |
237 | assert_equal 4, contents(:article1).resources.size |
238 | contents(:article1).destroy |
239 | assert_equal 0, Resource.find(:all, :conditions => "article_id = #{contents(:article1).id}").size |
240 | end |
241 | |
242 | def test_notifications |
243 | a = Article.new(:title => 'New Article', :body => 'Foo', :author => 'Tobi', :user => users(:tobi)) |
244 | assert a.save |
245 | |
246 | assert_equal 2, a.notify_users.size |
247 | assert_equal ['bob', 'randomuser'], a.notify_users.collect {|u| u.login }.sort |
248 | end |
249 | |
250 | def test_tags_on_update |
251 | contents(:article3).update_attribute :keywords, "my new tags" |
252 | assert_equal 3, contents(:article3).reload.tags.size |
253 | assert contents(:article3).tags.include?(Tag.find_by_name("new")) |
254 | end |
255 | |
256 | # this also tests time_delta, indirectly |
257 | def test_find_all_by_date |
258 | feb28 = this_blog.articles.build(:published => true) |
259 | mar1 = this_blog.articles.build(:published => true) |
260 | mar2 = this_blog.articles.build(:published => true) |
261 | |
262 | feb28.title = "February 28" |
263 | mar1.title = "March 1" |
264 | mar2.title = "March 2" |
265 | |
266 | feb28.created_at = feb28.published_at = "2004-02-28" |
267 | mar1.created_at = mar1.published_at = "2004-03-01" |
268 | mar2.created_at = mar2.published_at = "2004-03-02" |
269 | |
270 | [feb28, mar1, mar2].each do |x| |
271 | x.state = ContentState::Published.instance |
272 | x.save |
273 | end |
274 | |
275 | assert_equal(1, Article.find_all_by_date(2004,02).size) |
276 | assert_equal(2, Article.find_all_by_date(2004,03).size) |
277 | assert_equal(1, Article.find_all_by_date(2004,03,01).size) |
278 | end |
279 | |
280 | def test_withdrawal |
281 | art = Article.find(contents(:article1).id) |
282 | assert art.published? |
283 | assert ! art.withdrawn? |
284 | art.withdraw! |
285 | assert ! art.published? |
286 | assert art.withdrawn? |
287 | art.reload |
288 | assert ! art.published? |
289 | assert art.withdrawn? |
290 | end |
291 | |
292 | def test_default_filter |
293 | a = Article.find(1) |
294 | assert_equal 'textile', a.default_text_filter.name |
295 | end |
296 | end |