Commit 92bbe720ef4c20de8d7214a9da388e97c8d7dd84

Authored by Rodrigo Souto
1 parent e016d4cd

rails3: fix mass-assignment on approve_article

Showing 1 changed file with 56 additions and 56 deletions   Show diff stats
test/unit/approve_article_test.rb
@@ -13,20 +13,20 @@ class ApproveArticleTest < ActiveSupport::TestCase @@ -13,20 +13,20 @@ class ApproveArticleTest < ActiveSupport::TestCase
13 attr_reader :profile, :article, :community 13 attr_reader :profile, :article, :community
14 14
15 should 'have name, reference article and profile' do 15 should 'have name, reference article and profile' do
16 - a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile) 16 + a = create(ApproveArticle, :name => 'test name', :article => article, :target => community, :requestor => profile)
17 17
18 assert_equal article, a.article 18 assert_equal article, a.article
19 assert_equal community, a.target 19 assert_equal community, a.target
20 end 20 end
21 21
22 should 'have abstract and body' do 22 should 'have abstract and body' do
23 - a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile) 23 + a = create(ApproveArticle, :name => 'test name', :article => article, :target => community, :requestor => profile)
24 24
25 assert_equal ['Lead of article', 'This is my article'], [a.abstract, a.body] 25 assert_equal ['Lead of article', 'This is my article'], [a.abstract, a.body]
26 end 26 end
27 27
28 should 'create an article with the same class as original when finished' do 28 should 'create an article with the same class as original when finished' do
29 - a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) 29 + a = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
30 30
31 assert_difference article.class, :count do 31 assert_difference article.class, :count do
32 a.finish 32 a.finish
@@ -36,28 +36,28 @@ class ApproveArticleTest < ActiveSupport::TestCase @@ -36,28 +36,28 @@ class ApproveArticleTest < ActiveSupport::TestCase
36 should 'override target notification message method from Task' do 36 should 'override target notification message method from Task' do
37 p1 = profile 37 p1 = profile
38 p2 = create_user('testuser2').person 38 p2 = create_user('testuser2').person
39 - task = AddFriend.new(:person => p1, :friend => p2) 39 + task = build(AddFriend, :person => p1, :friend => p2)
40 assert_nothing_raised NotImplementedError do 40 assert_nothing_raised NotImplementedError do
41 task.target_notification_message 41 task.target_notification_message
42 end 42 end
43 end 43 end
44 44
45 should 'have parent if defined' do 45 should 'have parent if defined' do
46 - folder = profile.articles.create!(:name => 'test folder', :type => 'Folder') 46 + folder = create(Folder, :name => 'test folder', :profile => profile)
47 47
48 - a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile, :article_parent_id => folder.id) 48 + a = create(ApproveArticle, :name => 'test name', :article => article, :target => profile, :requestor => profile, :article_parent_id => folder.id)
49 49
50 assert_equal folder, a.article_parent 50 assert_equal folder, a.article_parent
51 end 51 end
52 52
53 should 'not have parent if not defined' do 53 should 'not have parent if not defined' do
54 - a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) 54 + a = create(ApproveArticle, :name => 'test name', :article => article, :target => profile, :requestor => profile)
55 55
56 assert_nil a.article_parent 56 assert_nil a.article_parent
57 end 57 end
58 58
59 should 'alert when reference article is removed' do 59 should 'alert when reference article is removed' do
60 - a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) 60 + a = create(ApproveArticle, :name => 'test name', :article => article, :target => profile, :requestor => profile)
61 61
62 article.destroy 62 article.destroy
63 a.reload 63 a.reload
@@ -66,13 +66,13 @@ class ApproveArticleTest < ActiveSupport::TestCase @@ -66,13 +66,13 @@ class ApproveArticleTest < ActiveSupport::TestCase
66 end 66 end
67 67
68 should 'preserve article_parent' do 68 should 'preserve article_parent' do
69 - a = ApproveArticle.new(:article_parent => article) 69 + a = build(ApproveArticle, :article_parent => article)
70 70
71 assert_equal article, a.article_parent 71 assert_equal article, a.article_parent
72 end 72 end
73 73
74 should 'handle blank names' do 74 should 'handle blank names' do
75 - a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile) 75 + a = create(ApproveArticle, :name => '', :article => article, :target => community, :requestor => profile)
76 76
77 assert_difference article.class, :count do 77 assert_difference article.class, :count do
78 a.finish 78 a.finish
@@ -84,7 +84,7 @@ class ApproveArticleTest < ActiveSupport::TestCase @@ -84,7 +84,7 @@ class ApproveArticleTest < ActiveSupport::TestCase
84 community.save 84 community.save
85 community.stubs(:notification_emails).returns(['adm@example.com']) 85 community.stubs(:notification_emails).returns(['adm@example.com'])
86 86
87 - a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile) 87 + a = create(ApproveArticle, :name => '', :article => article, :target => community, :requestor => profile)
88 assert !ActionMailer::Base.deliveries.empty? 88 assert !ActionMailer::Base.deliveries.empty?
89 end 89 end
90 90
@@ -92,7 +92,7 @@ class ApproveArticleTest < ActiveSupport::TestCase @@ -92,7 +92,7 @@ class ApproveArticleTest < ActiveSupport::TestCase
92 community.moderated_articles = false 92 community.moderated_articles = false
93 community.save 93 community.save
94 94
95 - a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile) 95 + a = create(ApproveArticle, :name => '', :article => article, :target => community, :requestor => profile)
96 assert ActionMailer::Base.deliveries.empty? 96 assert ActionMailer::Base.deliveries.empty?
97 end 97 end
98 98
@@ -100,14 +100,14 @@ class ApproveArticleTest < ActiveSupport::TestCase @@ -100,14 +100,14 @@ class ApproveArticleTest < ActiveSupport::TestCase
100 article.source = 'sample-feed.com' 100 article.source = 'sample-feed.com'
101 article.save 101 article.save
102 102
103 - a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile) 103 + a = create(ApproveArticle, :name => 'test name', :article => article, :target => community, :requestor => profile)
104 a.finish 104 a.finish
105 105
106 assert_equal article.class.last.source, article.source 106 assert_equal article.class.last.source, article.source
107 end 107 end
108 108
109 should 'have a reference article and profile on published article' do 109 should 'have a reference article and profile on published article' do
110 - a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile) 110 + a = create(ApproveArticle, :name => 'test name', :article => article, :target => community, :requestor => profile)
111 a.finish 111 a.finish
112 112
113 published = article.class.last 113 published = article.class.last
@@ -115,14 +115,14 @@ class ApproveArticleTest < ActiveSupport::TestCase @@ -115,14 +115,14 @@ class ApproveArticleTest < ActiveSupport::TestCase
115 end 115 end
116 116
117 should 'copy name from original article' do 117 should 'copy name from original article' do
118 - a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) 118 + a = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
119 a.finish 119 a.finish
120 120
121 assert_equal 'test name', article.class.last.name 121 assert_equal 'test name', article.class.last.name
122 end 122 end
123 123
124 should 'be able to edit name of generated article' do 124 should 'be able to edit name of generated article' do
125 - a = ApproveArticle.create!(:name => 'Other name', :article => article, :target => community, :requestor => profile) 125 + a = create(ApproveArticle, :name => 'Other name', :article => article, :target => community, :requestor => profile)
126 a.abstract = 'Abstract edited';a.save 126 a.abstract = 'Abstract edited';a.save
127 a.finish 127 a.finish
128 128
@@ -130,14 +130,14 @@ class ApproveArticleTest < ActiveSupport::TestCase @@ -130,14 +130,14 @@ class ApproveArticleTest < ActiveSupport::TestCase
130 end 130 end
131 131
132 should 'copy abstract from original article' do 132 should 'copy abstract from original article' do
133 - a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile) 133 + a = create(ApproveArticle, :name => 'test name', :article => article, :target => community, :requestor => profile)
134 a.finish 134 a.finish
135 135
136 assert_equal 'Lead of article', article.class.last.abstract 136 assert_equal 'Lead of article', article.class.last.abstract
137 end 137 end
138 138
139 should 'be able to edit abstract of generated article' do 139 should 'be able to edit abstract of generated article' do
140 - a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile) 140 + a = create(ApproveArticle, :name => 'test name', :article => article, :target => community, :requestor => profile)
141 a.abstract = 'Abstract edited';a.save 141 a.abstract = 'Abstract edited';a.save
142 a.finish 142 a.finish
143 143
@@ -145,14 +145,14 @@ class ApproveArticleTest < ActiveSupport::TestCase @@ -145,14 +145,14 @@ class ApproveArticleTest < ActiveSupport::TestCase
145 end 145 end
146 146
147 should 'copy body from original article' do 147 should 'copy body from original article' do
148 - a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile) 148 + a = create(ApproveArticle, :name => 'test name', :article => article, :target => community, :requestor => profile)
149 a.finish 149 a.finish
150 150
151 assert_equal 'This is my article', article.class.last.body 151 assert_equal 'This is my article', article.class.last.body
152 end 152 end
153 153
154 should 'be able to edit body of generated article' do 154 should 'be able to edit body of generated article' do
155 - a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile) 155 + a = create(ApproveArticle, :name => 'test name', :article => article, :target => community, :requestor => profile)
156 a.body = 'Body edited';a.save 156 a.body = 'Body edited';a.save
157 a.finish 157 a.finish
158 158
@@ -164,7 +164,7 @@ class ApproveArticleTest < ActiveSupport::TestCase @@ -164,7 +164,7 @@ class ApproveArticleTest < ActiveSupport::TestCase
164 article.parent = profile_blog 164 article.parent = profile_blog
165 article.save 165 article.save
166 166
167 - a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) 167 + a = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
168 a.finish 168 a.finish
169 169
170 assert !community.has_blog? 170 assert !community.has_blog?
@@ -177,7 +177,7 @@ class ApproveArticleTest < ActiveSupport::TestCase @@ -177,7 +177,7 @@ class ApproveArticleTest < ActiveSupport::TestCase
177 article.save 177 article.save
178 178
179 community.articles << Blog.new(:profile => community) 179 community.articles << Blog.new(:profile => community)
180 - a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) 180 + a = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
181 a.finish 181 a.finish
182 182
183 assert_equal community.blog, article.class.last.parent 183 assert_equal community.blog, article.class.last.parent
@@ -189,7 +189,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -189,7 +189,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
189 article.save 189 article.save
190 190
191 blog = fast_create(Blog, :profile_id => community.id) 191 blog = fast_create(Blog, :profile_id => community.id)
192 - a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) 192 + a = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
193 a.finish 193 a.finish
194 194
195 assert_nil article.class.last.parent 195 assert_nil article.class.last.parent
@@ -203,7 +203,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -203,7 +203,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
203 community.articles << Blog.new(:profile => community) 203 community.articles << Blog.new(:profile => community)
204 community_folder = fast_create(Folder, :profile_id => profile.id) 204 community_folder = fast_create(Folder, :profile_id => profile.id)
205 205
206 - a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile, :article_parent => community_folder) 206 + a = create(ApproveArticle, :article => article, :target => community, :requestor => profile, :article_parent => community_folder)
207 a.finish 207 a.finish
208 208
209 assert_equal community_folder, article.class.last.parent 209 assert_equal community_folder, article.class.last.parent
@@ -211,7 +211,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -211,7 +211,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
211 211
212 should 'use author from original article on published' do 212 should 'use author from original article on published' do
213 article.class.any_instance.stubs(:author).returns(profile) 213 article.class.any_instance.stubs(:author).returns(profile)
214 - a = ApproveArticle.create!(:name => 'test name', :article => article, :target => community, :requestor => profile) 214 + a = create(ApproveArticle, :name => 'test name', :article => article, :target => community, :requestor => profile)
215 a.finish 215 a.finish
216 216
217 assert_equal profile, article.class.last.author 217 assert_equal profile, article.class.last.author
@@ -219,7 +219,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -219,7 +219,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
219 219
220 should 'use original article author even if article is destroyed' do 220 should 'use original article author even if article is destroyed' do
221 article.class.any_instance.stubs(:author).returns(profile) 221 article.class.any_instance.stubs(:author).returns(profile)
222 - a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) 222 + a = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
223 a.finish 223 a.finish
224 224
225 article.destroy 225 article.destroy
@@ -229,14 +229,14 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -229,14 +229,14 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
229 229
230 should 'the published article have parent if defined' do 230 should 'the published article have parent if defined' do
231 folder = fast_create(Folder, :profile_id => community.id) 231 folder = fast_create(Folder, :profile_id => community.id)
232 - a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile, :article_parent => folder) 232 + a = create(ApproveArticle, :article => article, :target => community, :requestor => profile, :article_parent => folder)
233 a.finish 233 a.finish
234 234
235 assert_equal folder, article.class.last.parent 235 assert_equal folder, article.class.last.parent
236 end 236 end
237 237
238 should 'copy to_html from reference_article' do 238 should 'copy to_html from reference_article' do
239 - a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) 239 + a = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
240 a.finish 240 a.finish
241 241
242 assert_equal article.to_html, article.class.last.to_html 242 assert_equal article.to_html, article.class.last.to_html
@@ -244,7 +244,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -244,7 +244,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
244 244
245 should 'notify activity on creating published' do 245 should 'notify activity on creating published' do
246 ActionTracker::Record.delete_all 246 ActionTracker::Record.delete_all
247 - a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) 247 + a = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
248 a.finish 248 a.finish
249 249
250 assert_equal 1, ActionTracker::Record.count 250 assert_equal 1, ActionTracker::Record.count
@@ -254,16 +254,16 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -254,16 +254,16 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
254 ActionTracker::Record.delete_all 254 ActionTracker::Record.delete_all
255 255
256 article = fast_create(TextileArticle) 256 article = fast_create(TextileArticle)
257 - a = ApproveArticle.create!(:name => 'bar', :article => article, :target => community, :requestor => profile) 257 + a = create(ApproveArticle, :name => 'bar', :article => article, :target => community, :requestor => profile)
258 a.finish 258 a.finish
259 259
260 article = fast_create(TextileArticle) 260 article = fast_create(TextileArticle)
261 - a = ApproveArticle.create!(:name => 'another bar', :article => article, :target => community, :requestor => profile) 261 + a = create(ApproveArticle, :name => 'another bar', :article => article, :target => community, :requestor => profile)
262 a.finish 262 a.finish
263 263
264 article = fast_create(TextileArticle) 264 article = fast_create(TextileArticle)
265 other_community = fast_create(Community) 265 other_community = fast_create(Community)
266 - a = ApproveArticle.create!(:name => 'another bar', :article => article, :target => other_community, :requestor => profile) 266 + a = create(ApproveArticle, :name => 'another bar', :article => article, :target => other_community, :requestor => profile)
267 a.finish 267 a.finish
268 assert_equal 3, ActionTracker::Record.count 268 assert_equal 3, ActionTracker::Record.count
269 end 269 end
@@ -271,12 +271,12 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -271,12 +271,12 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
271 should 'not create trackers activity when updating articles' do 271 should 'not create trackers activity when updating articles' do
272 ActionTracker::Record.delete_all 272 ActionTracker::Record.delete_all
273 article1 = fast_create(TextileArticle) 273 article1 = fast_create(TextileArticle)
274 - a = ApproveArticle.create!(:name => 'bar', :article => article1, :target => community, :requestor => profile) 274 + a = create(ApproveArticle, :name => 'bar', :article => article1, :target => community, :requestor => profile)
275 a.finish 275 a.finish
276 276
277 article2 = fast_create(TinyMceArticle) 277 article2 = fast_create(TinyMceArticle)
278 other_community = fast_create(Community) 278 other_community = fast_create(Community)
279 - a = ApproveArticle.create!(:name => 'another bar', :article => article2, :target => other_community, :requestor => profile) 279 + a = create(ApproveArticle, :name => 'another bar', :article => article2, :target => other_community, :requestor => profile)
280 a.finish 280 a.finish
281 assert_equal 2, ActionTracker::Record.count 281 assert_equal 2, ActionTracker::Record.count
282 282
@@ -294,7 +294,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -294,7 +294,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
294 person = fast_create(Person) 294 person = fast_create(Person)
295 community.add_member(person) 295 community.add_member(person)
296 296
297 - a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) 297 + a = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
298 a.finish 298 a.finish
299 299
300 approved_article = community.articles.find_by_name(article.name) 300 approved_article = community.articles.find_by_name(article.name)
@@ -306,7 +306,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -306,7 +306,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
306 ActionTracker::Record.delete_all 306 ActionTracker::Record.delete_all
307 person = fast_create(Person) 307 person = fast_create(Person)
308 308
309 - a = ApproveArticle.create!(:article => article, :target => person, :requestor => profile) 309 + a = create(ApproveArticle, :article => article, :target => person, :requestor => profile)
310 a.finish 310 a.finish
311 311
312 approved_article = person.articles.find_by_name(article.name) 312 approved_article = person.articles.find_by_name(article.name)
@@ -315,7 +315,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -315,7 +315,7 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
315 end 315 end
316 316
317 should "have the same is_trackable method as original article" do 317 should "have the same is_trackable method as original article" do
318 - a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) 318 + a = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
319 a.finish 319 a.finish
320 320
321 assert_equal article.is_trackable?, article.class.last.is_trackable? 321 assert_equal article.is_trackable?, article.class.last.is_trackable?
@@ -323,13 +323,13 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -323,13 +323,13 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
323 323
324 should 'not have target notification message if it is not a moderated oganization' do 324 should 'not have target notification message if it is not a moderated oganization' do
325 community.moderated_articles = false; community.save 325 community.moderated_articles = false; community.save
326 - task = ApproveArticle.new(:article => article, :target => community, :requestor => profile) 326 + task = build(ApproveArticle, :article => article, :target => community, :requestor => profile)
327 327
328 assert_nil task.target_notification_message 328 assert_nil task.target_notification_message
329 end 329 end
330 330
331 should 'have target notification message if is organization and not moderated' do 331 should 'have target notification message if is organization and not moderated' do
332 - task = ApproveArticle.new(:article => article, :target => community, :requestor => profile) 332 + task = build(ApproveArticle, :article => article, :target => community, :requestor => profile)
333 333
334 community.expects(:moderated_articles?).returns(['true']) 334 community.expects(:moderated_articles?).returns(['true'])
335 335
@@ -338,52 +338,52 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -338,52 +338,52 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
338 338
339 should 'have target notification description' do 339 should 'have target notification description' do
340 community.moderated_articles = false; community.save 340 community.moderated_articles = false; community.save
341 - task = ApproveArticle.new(:article => article, :target => community, :requestor => profile) 341 + task = build(ApproveArticle, :article => article, :target => community, :requestor => profile)
342 342
343 assert_match(/#{task.requestor.name} wants to publish the article: #{article.name}/, task.target_notification_description) 343 assert_match(/#{task.requestor.name} wants to publish the article: #{article.name}/, task.target_notification_description)
344 end 344 end
345 345
346 should 'deliver target notification message' do 346 should 'deliver target notification message' do
347 - task = ApproveArticle.new(:article => article, :target => community, :requestor => profile) 347 + task = build(ApproveArticle, :article => article, :target => community, :requestor => profile)
348 348
349 community.expects(:notification_emails).returns(['target@example.com']) 349 community.expects(:notification_emails).returns(['target@example.com'])
350 community.expects(:moderated_articles?).returns(['true']) 350 community.expects(:moderated_articles?).returns(['true'])
351 351
352 - email = TaskMailer.deliver_target_notification(task, task.target_notification_message) 352 + email = TaskMailer.target_notification(task, task.target_notification_message).deliver
353 assert_match(/#{task.requestor.name} wants to publish the article: #{article.name}/, email.subject) 353 assert_match(/#{task.requestor.name} wants to publish the article: #{article.name}/, email.subject)
354 end 354 end
355 355
356 should 'deliver target finished message' do 356 should 'deliver target finished message' do
357 - task = ApproveArticle.new(:article => article, :target => community, :requestor => profile) 357 + task = build(ApproveArticle, :article => article, :target => community, :requestor => profile)
358 358
359 - email = TaskMailer.deliver_task_finished(task) 359 + email = task.send(:send_notification, :finished).deliver
360 360
361 assert_match(/#{task.requestor.name} wants to publish the article: #{article.name}/, email.subject) 361 assert_match(/#{task.requestor.name} wants to publish the article: #{article.name}/, email.subject)
362 end 362 end
363 363
364 should 'deliver target finished message about article deleted' do 364 should 'deliver target finished message about article deleted' do
365 - task = ApproveArticle.new(:article => article, :target => community, :requestor => profile) 365 + task = build(ApproveArticle, :article => article, :target => community, :requestor => profile)
366 article.destroy 366 article.destroy
367 367
368 - email = TaskMailer.deliver_task_finished(task) 368 + email = task.send(:send_notification, :finished).deliver
369 369
370 assert_match(/#{task.requestor.name} wanted to publish an article but it was removed/, email.subject) 370 assert_match(/#{task.requestor.name} wanted to publish an article but it was removed/, email.subject)
371 end 371 end
372 372
373 should 'approve an event' do 373 should 'approve an event' do
374 event = fast_create(Event, :profile_id => profile.id, :name => 'Event test', :slug => 'event-test', :abstract => 'Lead of article', :body => 'This is my event') 374 event = fast_create(Event, :profile_id => profile.id, :name => 'Event test', :slug => 'event-test', :abstract => 'Lead of article', :body => 'This is my event')
375 - task = ApproveArticle.create!(:name => 'Event test', :article => event, :target => community, :requestor => profile) 375 + task = create(ApproveArticle, :name => 'Event test', :article => event, :target => community, :requestor => profile)
376 assert_difference event.class, :count do 376 assert_difference event.class, :count do
377 task.finish 377 task.finish
378 end 378 end
379 end 379 end
380 380
381 should 'approve same article twice changing its name' do 381 should 'approve same article twice changing its name' do
382 - task1 = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) 382 + task1 = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
383 assert_difference article.class, :count do 383 assert_difference article.class, :count do
384 task1.finish 384 task1.finish
385 end 385 end
386 - task2 = ApproveArticle.create!(:name => article.name + ' v2', :article => article, :target => community, :requestor => profile) 386 + task2 = create(ApproveArticle, :name => article.name + ' v2', :article => article, :target => community, :requestor => profile)
387 assert_difference article.class, :count do 387 assert_difference article.class, :count do
388 assert_nothing_raised ActiveRecord::RecordInvalid do 388 assert_nothing_raised ActiveRecord::RecordInvalid do
389 task2.finish 389 task2.finish
@@ -392,11 +392,11 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -392,11 +392,11 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
392 end 392 end
393 393
394 should 'not approve same article twice if not changing its name' do 394 should 'not approve same article twice if not changing its name' do
395 - task1 = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) 395 + task1 = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
396 assert_difference article.class, :count do 396 assert_difference article.class, :count do
397 task1.finish 397 task1.finish
398 end 398 end
399 - task2 = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) 399 + task2 = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
400 assert_no_difference article.class, :count do 400 assert_no_difference article.class, :count do
401 assert_raises ActiveRecord::RecordInvalid do 401 assert_raises ActiveRecord::RecordInvalid do
402 task2.finish 402 task2.finish
@@ -405,18 +405,18 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -405,18 +405,18 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
405 end 405 end
406 406
407 should 'return reject message even without reject explanation' do 407 should 'return reject message even without reject explanation' do
408 - task = ApproveArticle.new(:name => 'My Article') 408 + task = build(ApproveArticle, :name => 'My Article')
409 assert_not_nil task.task_cancelled_message 409 assert_not_nil task.task_cancelled_message
410 end 410 end
411 411
412 should 'show the name of the article in the reject message' do 412 should 'show the name of the article in the reject message' do
413 - task = ApproveArticle.new(:name => 'My Article') 413 + task = build(ApproveArticle, :name => 'My Article')
414 assert_match /My Article/, task.task_cancelled_message 414 assert_match /My Article/, task.task_cancelled_message
415 end 415 end
416 416
417 should 'not save 4 on the new article\'s last_changed_by_ud after approval if author is nil' do 417 should 'not save 4 on the new article\'s last_changed_by_ud after approval if author is nil' do
418 article = fast_create(Article) 418 article = fast_create(Article)
419 - task = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) 419 + task = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
420 task.finish 420 task.finish
421 new_article = Article.last 421 new_article = Article.last
422 assert_nil new_article.last_changed_by_id 422 assert_nil new_article.last_changed_by_id
@@ -424,9 +424,9 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase @@ -424,9 +424,9 @@ class ApproveArticleTest &lt; ActiveSupport::TestCase
424 424
425 should 'not crash if target has its own domain' do 425 should 'not crash if target has its own domain' do
426 article = fast_create(Article) 426 article = fast_create(Article)
427 - profile.domains << Domain.create(:name => 'example.org') 427 + profile.domains << create(Domain, :name => 'example.org')
428 assert_nothing_raised do 428 assert_nothing_raised do
429 - ApproveArticle.create!(:article => article, :target => profile, :requestor => community) 429 + create(ApproveArticle, :article => article, :target => profile, :requestor => community)
430 end 430 end
431 end 431 end
432 432