Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 15
- Log:
Attempt to update Typo to a Typo SVN HEAD release from around the
time the prototype installation was set up on the RISC OS Open Limited
web site. Timestamps place this at 04-Jul so a revision from 05-Jul or
earlier was pulled and copied over the 2.6.0 tarball stable code.
- Author:
- adh
- Date:
- Sat Jul 22 23:27:35 +0100 2006
- Size:
- 7552 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, :articles_categories, :users, :notifications |
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_blog |
20 | a = Article.new |
21 | |
22 | assert_equal(1, a.blog_id) |
23 | assert_kind_of(Blog, a.blog) |
24 | end |
25 | |
26 | def test_create |
27 | a = Article.new |
28 | a.user_id = 1 |
29 | a.body = "Foo" |
30 | a.title = "Zzz" |
31 | assert a.save |
32 | |
33 | a.categories << Category.find(1) |
34 | assert_equal 1, a.categories.size |
35 | |
36 | b = Article.find(a.id) |
37 | assert_equal 1, b.categories.size |
38 | end |
39 | |
40 | def test_permalink |
41 | assert_equal( contents(:article3), this_blog.articles.find_by_date(2004,06,01) ) |
42 | assert_equal( [contents(:article2), contents(:article1)], |
43 | this_blog.articles.find_all_by_date(2.days.ago.year) ) |
44 | end |
45 | |
46 | def test_permalink_with_title |
47 | assert_equal( contents(:article3), |
48 | this_blog.articles.find_by_permalink(2004, 06, 01, "article-3") ) |
49 | assert_nil this_blog.articles.find_by_permalink(2005, 06, 01, "article-5") |
50 | end |
51 | |
52 | def test_strip_title |
53 | assert_equal "article-3", "Article-3".to_url |
54 | assert_equal "article-3", "Article 3!?#".to_url |
55 | assert_equal "there-is-sex-in-my-violence", "There is Sex in my Violence!".to_url |
56 | assert_equal "article", "-article-".to_url |
57 | assert_equal "lorem-ipsum-dolor-sit-amet-consectetaur-adipisicing-elit", "Lorem ipsum dolor sit amet, consectetaur adipisicing elit".to_url |
58 | assert_equal "my-cats-best-friend", "My Cat's Best Friend".to_url |
59 | end |
60 | |
61 | def test_perma_title |
62 | assert_equal "article-1", contents(:article1).stripped_title |
63 | assert_equal "article-2", contents(:article2).stripped_title |
64 | assert_equal "article-3", contents(:article3).stripped_title |
65 | end |
66 | |
67 | def test_html_title |
68 | a = Article.new |
69 | a.title = "This <i>is</i> a <b>test</b>" |
70 | assert a.save |
71 | |
72 | assert_equal 'this-is-a-test', a.permalink |
73 | end |
74 | |
75 | def test_urls |
76 | urls = contents(:article4).html_urls |
77 | assert_equal ["http://www.example.com/public"], urls |
78 | end |
79 | |
80 | ### XXX: Should we have a test here? |
81 | def test_send_pings |
82 | end |
83 | |
84 | ### XXX: Should we have a test here? |
85 | def test_send_multiple_pings |
86 | end |
87 | |
88 | def test_tags |
89 | a = Article.new(:title => 'Test tag article', |
90 | :keywords => 'test tag tag stuff'); |
91 | |
92 | assert_kind_of Article, a |
93 | assert_equal 0, a.tags.size |
94 | |
95 | a.keywords_to_tags |
96 | |
97 | assert_equal 3, a.tags.size |
98 | assert_equal ["test", "tag", "stuff"].sort , a.tags.collect {|t| t.name}.sort |
99 | assert a.save |
100 | |
101 | a.keywords = 'tag bar stuff foo' |
102 | a.keywords_to_tags |
103 | |
104 | assert_equal 4, a.tags.size |
105 | assert_equal ["foo", "bar", "tag", "stuff"].sort , a.tags.collect {|t| t.name}.sort |
106 | |
107 | a.keywords='tag bar' |
108 | a.keywords_to_tags |
109 | |
110 | assert_equal 2, a.tags.size |
111 | |
112 | a.keywords='' |
113 | a.keywords_to_tags |
114 | |
115 | assert_equal 0, a.tags.size |
116 | |
117 | b = Article.new(:title => 'Tag Test 2', |
118 | :keywords => 'tag test article one two three') |
119 | |
120 | assert_kind_of Article,b |
121 | assert_equal 0, b.tags.size |
122 | end |
123 | |
124 | def test_find_published_by_tag_name |
125 | @articles = Tag.find_by_name(tags(:foo_tag).name).published_articles |
126 | |
127 | assert_results_are(:article1, :article2) |
128 | end |
129 | |
130 | |
131 | def test_find_published |
132 | @articles = this_blog.articles.find_published |
133 | assert_results_are(:search_target, :article1, :article2, |
134 | :article3, :inactive_article,:xmltest) |
135 | |
136 | @articles = this_blog.articles.find_published(:all, |
137 | :conditions => "title = 'Article 1!'") |
138 | assert_results_are :article1 |
139 | end |
140 | |
141 | def test_just_published_flag |
142 | art = this_blog.articles.build(:title => 'title', |
143 | :body => 'body', |
144 | :published => true) |
145 | assert art.just_published? |
146 | assert art.save |
147 | assert !art.just_published? |
148 | |
149 | art = Article.create!(:title => 'title2', |
150 | :body => 'body', |
151 | :published => false) |
152 | |
153 | assert ! art.just_published? |
154 | end |
155 | |
156 | def test_future_publishing |
157 | assert_sets_trigger(Article.create!(:title => 'title', :body => 'body', |
158 | :published => true, |
159 | :published_at => Time.now + 2.seconds)) |
160 | end |
161 | |
162 | def test_future_publishing_without_published_flag |
163 | assert_sets_trigger Article.create!(:title => 'title', :body => 'body', |
164 | :published_at => Time.now + 2.seconds) |
165 | end |
166 | |
167 | def test_triggers_are_dependent |
168 | art = Article.create!(:title => 'title', :body => 'body', |
169 | :published_at => Time.now + 1.hour) |
170 | assert_equal 1, Trigger.count |
171 | art.destroy |
172 | assert_equal 0, Trigger.count |
173 | end |
174 | |
175 | def assert_sets_trigger(art) |
176 | assert_equal 1, Trigger.count |
177 | assert Trigger.find(:first, :conditions => ['pending_item_id = ?', art.id]) |
178 | sleep 2 |
179 | Trigger.fire |
180 | art.reload |
181 | assert art.published |
182 | end |
183 | |
184 | def test_find_published_by_category |
185 | Article.create!(:title => "News from the future!", |
186 | :body => "The future is cool!", |
187 | :keywords => "future", |
188 | :published_at => Time.now + 12.minutes) |
189 | |
190 | @articles = Category.find_by_permalink('personal').published_articles |
191 | assert_results_are :article1, :article2, :article3 |
192 | |
193 | @articles = Category.find_by_permalink('foobar').published_articles |
194 | assert @articles.empty? |
195 | |
196 | @articles = Category.find_by_permalink('software').published_articles |
197 | assert_results_are :article1 |
198 | end |
199 | |
200 | def test_destroy_file_upload_associations |
201 | assert_equal 2, contents(:article1).resources.size |
202 | contents(:article1).resources << resources(:resource1) << resources(:resource2) |
203 | assert_equal 4, contents(:article1).resources.size |
204 | contents(:article1).destroy |
205 | assert_equal 0, Resource.find(:all, :conditions => "article_id = #{contents(:article1).id}").size |
206 | end |
207 | |
208 | def test_notifications |
209 | a = Article.new(:title => 'New Article', :body => 'Foo', :author => 'Tobi', :user => users(:tobi)) |
210 | assert a.save |
211 | |
212 | assert_equal 2, a.notify_users.size |
213 | assert_equal ['bob', 'randomuser'], a.notify_users.collect {|u| u.login }.sort |
214 | end |
215 | |
216 | def test_tags_on_update |
217 | contents(:article3).update_attribute :keywords, "my new tags" |
218 | assert_equal 3, contents(:article3).reload.tags.size |
219 | assert contents(:article3).tags.include?(Tag.find_by_name("new")) |
220 | end |
221 | |
222 | # this also tests time_delta, indirectly |
223 | def test_find_all_by_date |
224 | feb28 = this_blog.articles.build(:published => true) |
225 | mar1 = this_blog.articles.build(:published => true) |
226 | mar2 = this_blog.articles.build(:published => true) |
227 | |
228 | feb28.title = "February 28" |
229 | mar1.title = "March 1" |
230 | mar2.title = "March 2" |
231 | |
232 | feb28.created_at = feb28.published_at = "2004-02-28" |
233 | mar1.created_at = mar1.published_at = "2004-03-01" |
234 | mar2.created_at = mar2.published_at = "2004-03-02" |
235 | |
236 | [feb28, mar1, mar2].each do |x| |
237 | x.state = ContentState::Published.instance |
238 | x.save |
239 | end |
240 | |
241 | assert_equal(1, Article.find_all_by_date(2004,02).size) |
242 | assert_equal(2, Article.find_all_by_date(2004,03).size) |
243 | assert_equal(1, Article.find_all_by_date(2004,03,01).size) |
244 | end |
245 | end |