Commit dae370c61cbdde34329dbd46608ce082d09b18e0

Authored by Rodrigo Souto
1 parent 29f6b68e

rails3: fix comment tests

PS: still failing due to ActionTracker::Record#current_user_from_model
Showing 1 changed file with 60 additions and 60 deletions   Show diff stats
test/unit/comment_test.rb
@@ -60,7 +60,7 @@ class CommentTest < ActiveSupport::TestCase @@ -60,7 +60,7 @@ class CommentTest < ActiveSupport::TestCase
60 c1.name = 'my name' 60 c1.name = 'my name'
61 c1.valid? 61 c1.valid?
62 assert c1.errors[:name.to_s].present? 62 assert c1.errors[:name.to_s].present?
63 - assert_no_match /\{fn\}/, c1.errors.on(:name) 63 + assert_no_match /\{fn\}/, c1.errors[:name].first
64 end 64 end
65 65
66 should 'update counter cache in article' do 66 should 'update counter cache in article' do
@@ -86,7 +86,7 @@ class CommentTest < ActiveSupport::TestCase @@ -86,7 +86,7 @@ class CommentTest < ActiveSupport::TestCase
86 person = fast_create(Person) 86 person = fast_create(Person)
87 community = fast_create(Community) 87 community = fast_create(Community)
88 88
89 - activity = ActionTracker::Record.create :user => person, :target => community, :verb => 'add_member_in_community' 89 + activity = create ActionTracker::Record, :user => person, :target => community, :verb => 'add_member_in_community'
90 90
91 cc = activity.comments_count 91 cc = activity.comments_count
92 92
@@ -96,40 +96,40 @@ class CommentTest < ActiveSupport::TestCase @@ -96,40 +96,40 @@ class CommentTest < ActiveSupport::TestCase
96 96
97 should 'provide author name for authenticated authors' do 97 should 'provide author name for authenticated authors' do
98 owner = create_user('testuser').person 98 owner = create_user('testuser').person
99 - assert_equal 'testuser', Comment.new(:author => owner).author_name 99 + assert_equal 'testuser', build(Comment, :author => owner).author_name
100 end 100 end
101 101
102 should 'provide author name for unauthenticated author' do 102 should 'provide author name for unauthenticated author' do
103 - assert_equal 'anonymous coward', Comment.new(:name => 'anonymous coward').author_name 103 + assert_equal 'anonymous coward', build(Comment, :name => 'anonymous coward').author_name
104 end 104 end
105 105
106 should 'provide empty text for author name if user was removed ' do 106 should 'provide empty text for author name if user was removed ' do
107 - assert_equal '', Comment.new(:author_id => 9999).author_name 107 + assert_equal '', build(Comment, :author_id => 9999).author_name
108 end 108 end
109 109
110 should "provide author e-mail for athenticated authors" do 110 should "provide author e-mail for athenticated authors" do
111 owner = create_user('testuser').person 111 owner = create_user('testuser').person
112 - assert_equal owner.email, Comment.new(:author => owner).author_email 112 + assert_equal owner.email, build(Comment, :author => owner).author_email
113 end 113 end
114 114
115 should "provide author e-mail for unauthenticated author" do 115 should "provide author e-mail for unauthenticated author" do
116 - assert_equal 'my@email.com', Comment.new(:email => 'my@email.com').author_email 116 + assert_equal 'my@email.com', build(Comment, :email => 'my@email.com').author_email
117 end 117 end
118 118
119 should 'provide author link for authenticated author' do 119 should 'provide author link for authenticated author' do
120 author = Person.new 120 author = Person.new
121 author.expects(:url).returns('http://blabla.net/author') 121 author.expects(:url).returns('http://blabla.net/author')
122 - assert_equal 'http://blabla.net/author', Comment.new(:author => author).author_link 122 + assert_equal 'http://blabla.net/author', build(Comment, :author => author).author_link
123 end 123 end
124 124
125 should 'provide author e-mail as author link for unauthenticated author' do 125 should 'provide author e-mail as author link for unauthenticated author' do
126 - assert_equal 'my@email.com', Comment.new(:email => 'my@email.com').author_link 126 + assert_equal 'my@email.com', build(Comment, :email => 'my@email.com').author_link
127 end 127 end
128 128
129 should 'provide url to comment' do 129 should 'provide url to comment' do
130 art = Article.new 130 art = Article.new
131 art.expects(:url).returns({ :controller => 'lala', :action => 'something' }) 131 art.expects(:url).returns({ :controller => 'lala', :action => 'something' })
132 - comment = Comment.new(:article => art) 132 + comment = build(Comment, :article => art)
133 comment.expects(:id).returns(9876) 133 comment.expects(:id).returns(9876)
134 134
135 assert_equal({ :controller => 'lala', :action => 'something', :anchor => 'comment-9876'}, comment.url) 135 assert_equal({ :controller => 'lala', :action => 'something', :anchor => 'comment-9876'}, comment.url)
@@ -148,7 +148,7 @@ class CommentTest < ActiveSupport::TestCase @@ -148,7 +148,7 @@ class CommentTest < ActiveSupport::TestCase
148 art = owner.articles.build(:name => 'ytest'); art.save! 148 art = owner.articles.build(:name => 'ytest'); art.save!
149 comments = [] 149 comments = []
150 3.times do 150 3.times do
151 - comments.unshift art.comments.create!(:title => 'a test comment', :body => 'bla', :author => owner) 151 + comments.unshift create(Comment, :article => art, :title => 'a test comment', :body => 'bla', :author => owner)
152 end 152 end
153 153
154 assert_equal comments, Comment.recent 154 assert_equal comments, Comment.recent
@@ -161,7 +161,7 @@ class CommentTest < ActiveSupport::TestCase @@ -161,7 +161,7 @@ class CommentTest < ActiveSupport::TestCase
161 art = owner.articles.build(:name => 'ytest'); art.save! 161 art = owner.articles.build(:name => 'ytest'); art.save!
162 comments = [] 162 comments = []
163 3.times do 163 3.times do
164 - comments.unshift art.comments.create!(:title => 'a test comment', :body => 'bla', :author => owner) 164 + comments.unshift create(Comment, :article => art, :title => 'a test comment', :body => 'bla', :author => owner)
165 end 165 end
166 166
167 comments.pop 167 comments.pop
@@ -170,15 +170,15 @@ class CommentTest < ActiveSupport::TestCase @@ -170,15 +170,15 @@ class CommentTest < ActiveSupport::TestCase
170 end 170 end
171 171
172 should 'not accept invalid email' do 172 should 'not accept invalid email' do
173 - c = Comment.new(:name => 'My Name', :email => 'my@invalid') 173 + c = build(Comment, :name => 'My Name', :email => 'my@invalid')
174 c.valid? 174 c.valid?
175 assert c.errors[:email.to_s].present? 175 assert c.errors[:email.to_s].present?
176 end 176 end
177 177
178 should 'generate links to comments on images with view set to true' do 178 should 'generate links to comments on images with view set to true' do
179 owner = create_user('testuser').person 179 owner = create_user('testuser').person
180 - image = UploadedFile.create!(:profile => owner, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))  
181 - comment = image.comments.create!(:article => image, :author => owner, :title => 'a random comment', :body => 'just another comment') 180 + image = create(UploadedFile, :profile => owner, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
  181 + comment = create(Comment, :article => image, :author => owner, :title => 'a random comment', :body => 'just another comment')
182 182
183 assert comment.url[:view] 183 assert comment.url[:view]
184 end 184 end
@@ -187,14 +187,14 @@ class CommentTest < ActiveSupport::TestCase @@ -187,14 +187,14 @@ class CommentTest < ActiveSupport::TestCase
187 owner = create_user('testuser').person 187 owner = create_user('testuser').person
188 article = owner.articles.create!(:name => 'test', :body => '...') 188 article = owner.articles.create!(:name => 'test', :body => '...')
189 javascript = "<script>alert('XSS')</script>" 189 javascript = "<script>alert('XSS')</script>"
190 - comment = article.comments.create!(:article => article, :name => javascript, :title => javascript, :body => javascript, :email => 'cracker@test.org') 190 + comment = create(Comment, :article => article, :name => javascript, :title => javascript, :body => javascript, :email => 'cracker@test.org')
191 assert_no_match(/<script>/, comment.name) 191 assert_no_match(/<script>/, comment.name)
192 end 192 end
193 193
194 should 'sanitize required fields before validation' do 194 should 'sanitize required fields before validation' do
195 owner = create_user('testuser').person 195 owner = create_user('testuser').person
196 article = owner.articles.create(:name => 'test', :body => '...') 196 article = owner.articles.create(:name => 'test', :body => '...')
197 - comment = article.comments.new(:title => '<h1 title </h1>', :body => '<h1 body </h1>', :name => '<h1 name </h1>', :email => 'cracker@test.org') 197 + comment = build(Comment, :article => article, :title => '<h1 title </h1>', :body => '<h1 body </h1>', :name => '<h1 name </h1>', :email => 'cracker@test.org')
198 comment.valid? 198 comment.valid?
199 199
200 assert comment.errors[:name.to_s].present? 200 assert comment.errors[:name.to_s].present?
@@ -204,7 +204,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -204,7 +204,7 @@ class CommentTest &lt; ActiveSupport::TestCase
204 should 'escape malformed html tags' do 204 should 'escape malformed html tags' do
205 owner = create_user('testuser').person 205 owner = create_user('testuser').person
206 article = owner.articles.create(:name => 'test', :body => '...') 206 article = owner.articles.create(:name => 'test', :body => '...')
207 - comment = article.comments.new(:title => '<h1 title </h1>>> sd f <<', :body => '<h1>> sdf><asd>< body </h1>', :name => '<h1 name </h1>>><<dfsf<sd', :email => 'cracker@test.org') 207 + comment = build(Comment, :article => article, :title => '<h1 title </h1>>> sd f <<', :body => '<h1>> sdf><asd>< body </h1>', :name => '<h1 name </h1>>><<dfsf<sd', :email => 'cracker@test.org')
208 comment.valid? 208 comment.valid?
209 209
210 assert_no_match /[<>]/, comment.title 210 assert_no_match /[<>]/, comment.title
@@ -213,7 +213,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -213,7 +213,7 @@ class CommentTest &lt; ActiveSupport::TestCase
213 end 213 end
214 214
215 should 'use an existing image for deleted comments' do 215 should 'use an existing image for deleted comments' do
216 - image = Comment.new.removed_user_image 216 + image = Comment.new.removed_user_image[1..-1]
217 assert File.exists?(Rails.root.join('public', image)), "#{image} does not exist." 217 assert File.exists?(Rails.root.join('public', image)), "#{image} does not exist."
218 end 218 end
219 219
@@ -245,10 +245,10 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -245,10 +245,10 @@ class CommentTest &lt; ActiveSupport::TestCase
245 Comment.delete_all 245 Comment.delete_all
246 owner = create_user('testuser').person 246 owner = create_user('testuser').person
247 article = owner.articles.create!(:name => 'test', :body => '...') 247 article = owner.articles.create!(:name => 'test', :body => '...')
248 - c = article.comments.create!(:article => article, :name => 'foo', :title => 'bar', :body => 'my comment', :email => 'cracker@test.org')  
249 - c1 = article.comments.create!(:article => article, :name => 'foo', :title => 'bar', :body => 'my comment', :email => 'cracker@test.org', :reply_of_id => c.id)  
250 - c2 = article.comments.create!(:article => article, :name => 'foo', :title => 'bar', :body => 'my comment', :email => 'cracker@test.org')  
251 - c3 = article.comments.create!(:article => article, :name => 'foo', :title => 'bar', :body => 'my comment', :email => 'cracker@test.org', :reply_of_id => c.id) 248 + c = create(Comment, :article => article, :name => 'foo', :title => 'bar', :body => 'my comment', :email => 'cracker@test.org')
  249 + c1 = create(Comment, :article => article, :name => 'foo', :title => 'bar', :body => 'my comment', :email => 'cracker@test.org', :reply_of_id => c.id)
  250 + c2 = create(Comment, :article => article, :name => 'foo', :title => 'bar', :body => 'my comment', :email => 'cracker@test.org')
  251 + c3 = create(Comment, :article => article, :name => 'foo', :title => 'bar', :body => 'my comment', :email => 'cracker@test.org', :reply_of_id => c.id)
252 assert_equal 4, Comment.count 252 assert_equal 4, Comment.count
253 c.destroy 253 c.destroy
254 assert_equal [c2], Comment.all 254 assert_equal [c2], Comment.all
@@ -287,12 +287,12 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -287,12 +287,12 @@ class CommentTest &lt; ActiveSupport::TestCase
287 287
288 should "return activities comments as a thread" do 288 should "return activities comments as a thread" do
289 person = fast_create(Person) 289 person = fast_create(Person)
290 - a = TextileArticle.create!(:profile => person, :name => 'My article', :body => 'Article body')  
291 - c0 = Comment.create!(:source => a, :body => 'My comment', :author => person)  
292 - c1 = Comment.create!(:reply_of_id => c0.id, :source => a, :body => 'bla', :author => person)  
293 - c2 = Comment.create!(:reply_of_id => c1.id, :source => a, :body => 'bla', :author => person)  
294 - c3 = Comment.create!(:reply_of_id => c0.id, :source => a, :body => 'bla', :author => person)  
295 - c4 = Comment.create!(:source => a, :body => 'My comment', :author => person) 290 + a = create(TextileArticle, :profile => person, :name => 'My article', :body => 'Article body')
  291 + c0 = create(Comment, :source => a, :body => 'My comment', :author => person)
  292 + c1 = create(Comment, :reply_of_id => c0.id, :source => a, :body => 'bla', :author => person)
  293 + c2 = create(Comment, :reply_of_id => c1.id, :source => a, :body => 'bla', :author => person)
  294 + c3 = create(Comment, :reply_of_id => c0.id, :source => a, :body => 'bla', :author => person)
  295 + c4 = create(Comment, :source => a, :body => 'My comment', :author => person)
296 result = a.activity.comments_as_thread 296 result = a.activity.comments_as_thread
297 assert_equal c0, result[0] 297 assert_equal c0, result[0]
298 assert_equal [c1, c3], result[0].replies 298 assert_equal [c1, c3], result[0].replies
@@ -304,11 +304,11 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -304,11 +304,11 @@ class CommentTest &lt; ActiveSupport::TestCase
304 should 'provide author url for authenticated user' do 304 should 'provide author url for authenticated user' do
305 author = Person.new 305 author = Person.new
306 author.expects(:url).returns('http://blabla.net/author') 306 author.expects(:url).returns('http://blabla.net/author')
307 - assert_equal 'http://blabla.net/author', Comment.new(:author => author).author_url 307 + assert_equal 'http://blabla.net/author', build(Comment, :author => author).author_url
308 end 308 end
309 309
310 should 'not provide author url for unauthenticated user' do 310 should 'not provide author url for unauthenticated user' do
311 - assert_nil Comment.new(:email => 'my@email.com').author_url 311 + assert_nil build(Comment, :email => 'my@email.com').author_url
312 end 312 end
313 313
314 should 'be able to reject a comment' do 314 should 'be able to reject a comment' do
@@ -324,28 +324,28 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -324,28 +324,28 @@ class CommentTest &lt; ActiveSupport::TestCase
324 person = create_user('follower').person 324 person = create_user('follower').person
325 article = fast_create(Article, :profile_id => owner.id) 325 article = fast_create(Article, :profile_id => owner.id)
326 assert_not_includes article.followers, person.email 326 assert_not_includes article.followers, person.email
327 - article.comments.create!(:source => article, :author => person, :title => 'new comment', :body => 'new comment') 327 + create(Comment, :source => article, :author => person, :title => 'new comment', :body => 'new comment')
328 assert_includes article.reload.followers, person.email 328 assert_includes article.reload.followers, person.email
329 end 329 end
330 330
331 should 'subscribe guest user as follower of an article on new comment' do 331 should 'subscribe guest user as follower of an article on new comment' do
332 article = fast_create(Article, :profile_id => create_user('article_owner').person.id) 332 article = fast_create(Article, :profile_id => create_user('article_owner').person.id)
333 assert_not_includes article.followers, 'follower@example.com' 333 assert_not_includes article.followers, 'follower@example.com'
334 - article.comments.create!(:source => article, :name => 'follower', :email => 'follower@example.com', :title => 'new comment', :body => 'new comment') 334 + create(Comment, :source => article, :name => 'follower', :email => 'follower@example.com', :title => 'new comment', :body => 'new comment')
335 assert_includes article.reload.followers, 'follower@example.com' 335 assert_includes article.reload.followers, 'follower@example.com'
336 end 336 end
337 337
338 should 'keep unique emails in list of followers' do 338 should 'keep unique emails in list of followers' do
339 article = fast_create(Article, :profile_id => create_user('article_owner').person.id) 339 article = fast_create(Article, :profile_id => create_user('article_owner').person.id)
340 - article.comments.create!(:source => article, :name => 'follower one', :email => 'follower@example.com', :title => 'new comment', :body => 'new comment')  
341 - article.comments.create!(:source => article, :name => 'follower two', :email => 'follower@example.com', :title => 'another comment', :body => 'new comment') 340 + create(Comment, :source => article, :name => 'follower one', :email => 'follower@example.com', :title => 'new comment', :body => 'new comment')
  341 + create(Comment, :source => article, :name => 'follower two', :email => 'follower@example.com', :title => 'another comment', :body => 'new comment')
342 assert_equal 1, article.reload.followers.select{|v| v == 'follower@example.com'}.count 342 assert_equal 1, article.reload.followers.select{|v| v == 'follower@example.com'}.count
343 end 343 end
344 344
345 should 'not subscribe owner as follower of an article on new comment' do 345 should 'not subscribe owner as follower of an article on new comment' do
346 owner = create_user('owner_of_article').person 346 owner = create_user('owner_of_article').person
347 article = fast_create(Article, :profile_id => owner.id) 347 article = fast_create(Article, :profile_id => owner.id)
348 - article.comments.create!(:source => article, :author => owner, :title => 'new comment', :body => 'new comment') 348 + create(Comment, :source => article, :author => owner, :title => 'new comment', :body => 'new comment')
349 assert_not_includes article.reload.followers, owner.email 349 assert_not_includes article.reload.followers, owner.email
350 end 350 end
351 351
@@ -355,8 +355,8 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -355,8 +355,8 @@ class CommentTest &lt; ActiveSupport::TestCase
355 admin = create_user('admin_of_community').person 355 admin = create_user('admin_of_community').person
356 owner.add_admin(admin) 356 owner.add_admin(admin)
357 article = fast_create(Article, :profile_id => owner.id) 357 article = fast_create(Article, :profile_id => owner.id)
358 - article.comments.create!(:source => article, :author => follower, :title => 'new comment', :body => 'new comment')  
359 - article.comments.create!(:source => article, :author => admin, :title => 'new comment', :body => 'new comment') 358 + create(Comment, :source => article, :author => follower, :title => 'new comment', :body => 'new comment')
  359 + create(Comment, :source => article, :author => admin, :title => 'new comment', :body => 'new comment')
360 assert_not_includes article.reload.followers, admin.email 360 assert_not_includes article.reload.followers, admin.email
361 assert_includes article.followers, follower.email 361 assert_includes article.followers, follower.email
362 end 362 end
@@ -501,12 +501,12 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -501,12 +501,12 @@ class CommentTest &lt; ActiveSupport::TestCase
501 end 501 end
502 502
503 should 'store User-Agent' do 503 should 'store User-Agent' do
504 - c = Comment.new(:user_agent => 'foo') 504 + c = build(Comment, :user_agent => 'foo')
505 assert_equal 'foo', c.user_agent 505 assert_equal 'foo', c.user_agent
506 end 506 end
507 507
508 should 'store referrer' do 508 should 'store referrer' do
509 - c = Comment.new(:referrer => 'bar') 509 + c = build(Comment, :referrer => 'bar')
510 assert_equal 'bar', c.referrer 510 assert_equal 'bar', c.referrer
511 end 511 end
512 512
@@ -528,7 +528,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -528,7 +528,7 @@ class CommentTest &lt; ActiveSupport::TestCase
528 528
529 should 'not need moderation if article is not moderated' do 529 should 'not need moderation if article is not moderated' do
530 article = Article.new 530 article = Article.new
531 - comment = Comment.new(:article => article) 531 + comment = build(Comment, :article => article)
532 532
533 assert !comment.need_moderation? 533 assert !comment.need_moderation?
534 end 534 end
@@ -540,7 +540,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -540,7 +540,7 @@ class CommentTest &lt; ActiveSupport::TestCase
540 article.stubs(:author).returns(author) 540 article.stubs(:author).returns(author)
541 article.moderate_comments = true 541 article.moderate_comments = true
542 542
543 - comment = Comment.new(:article => article) 543 + comment = build(Comment, :article => article)
544 comment.stubs(:author).returns(author) 544 comment.stubs(:author).returns(author)
545 545
546 assert !comment.need_moderation? 546 assert !comment.need_moderation?
@@ -550,7 +550,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -550,7 +550,7 @@ class CommentTest &lt; ActiveSupport::TestCase
550 article = Article.new 550 article = Article.new
551 article.stubs(:moderate_comments?).returns(true) 551 article.stubs(:moderate_comments?).returns(true)
552 552
553 - comment = Comment.new(:article => article) 553 + comment = build(Comment, :article => article)
554 554
555 assert comment.need_moderation? 555 assert comment.need_moderation?
556 end 556 end
@@ -563,7 +563,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -563,7 +563,7 @@ class CommentTest &lt; ActiveSupport::TestCase
563 article.stubs(:author).returns(article_author) 563 article.stubs(:author).returns(article_author)
564 article.stubs(:moderate_comments?).returns(true) 564 article.stubs(:moderate_comments?).returns(true)
565 565
566 - comment = Comment.new(:article => article) 566 + comment = build(Comment, :article => article)
567 comment.stubs(:author).returns(comment_author) 567 comment.stubs(:author).returns(comment_author)
568 568
569 assert comment.need_moderation? 569 assert comment.need_moderation?
@@ -578,8 +578,8 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -578,8 +578,8 @@ class CommentTest &lt; ActiveSupport::TestCase
578 should 'not be able to destroy comment' do 578 should 'not be able to destroy comment' do
579 user = Person.new 579 user = Person.new
580 profile = Profile.new 580 profile = Profile.new
581 - article = Article.new(:profile => profile)  
582 - comment = Comment.new(:article => article) 581 + article = build(Article, :profile => profile)
  582 + comment = build(Comment, :article => article)
583 user.expects(:has_permission?).with(:moderate_comments, profile).returns(false) 583 user.expects(:has_permission?).with(:moderate_comments, profile).returns(false)
584 584
585 assert !comment.can_be_destroyed_by?(user) 585 assert !comment.can_be_destroyed_by?(user)
@@ -587,15 +587,15 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -587,15 +587,15 @@ class CommentTest &lt; ActiveSupport::TestCase
587 587
588 should 'be able to destroy comment if is the author' do 588 should 'be able to destroy comment if is the author' do
589 user = Person.new 589 user = Person.new
590 - comment = Comment.new(:author => user) 590 + comment = build(Comment, :author => user)
591 591
592 assert comment.can_be_destroyed_by?(user) 592 assert comment.can_be_destroyed_by?(user)
593 end 593 end
594 594
595 should 'be able to destroy comment if is the profile' do 595 should 'be able to destroy comment if is the profile' do
596 user = Person.new 596 user = Person.new
597 - article = Article.new(:profile => user)  
598 - comment = Comment.new(:article => article) 597 + article = build(Article, :profile => user)
  598 + comment = build(Comment, :article => article)
599 599
600 assert comment.can_be_destroyed_by?(user) 600 assert comment.can_be_destroyed_by?(user)
601 end 601 end
@@ -603,8 +603,8 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -603,8 +603,8 @@ class CommentTest &lt; ActiveSupport::TestCase
603 should 'be able to destroy comment if can moderate_comments on the profile' do 603 should 'be able to destroy comment if can moderate_comments on the profile' do
604 user = Person.new 604 user = Person.new
605 profile = Profile.new 605 profile = Profile.new
606 - article = Article.new(:profile => profile)  
607 - comment = Comment.new(:article => article) 606 + article = build(Article, :profile => profile)
  607 + comment = build(Comment, :article => article)
608 608
609 user.expects(:has_permission?).with(:moderate_comments, profile).returns(true) 609 user.expects(:has_permission?).with(:moderate_comments, profile).returns(true)
610 610
@@ -620,8 +620,8 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -620,8 +620,8 @@ class CommentTest &lt; ActiveSupport::TestCase
620 should 'not be able to mark comment as spam' do 620 should 'not be able to mark comment as spam' do
621 user = Person.new 621 user = Person.new
622 profile = Profile.new 622 profile = Profile.new
623 - article = Article.new(:profile => profile)  
624 - comment = Comment.new(:article => article) 623 + article = build(Article, :profile => profile)
  624 + comment = build(Comment, :article => article)
625 user.expects(:has_permission?).with(:moderate_comments, profile).returns(false) 625 user.expects(:has_permission?).with(:moderate_comments, profile).returns(false)
626 626
627 assert !comment.can_be_marked_as_spam_by?(user) 627 assert !comment.can_be_marked_as_spam_by?(user)
@@ -629,8 +629,8 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -629,8 +629,8 @@ class CommentTest &lt; ActiveSupport::TestCase
629 629
630 should 'be able to mark comment as spam if is the profile' do 630 should 'be able to mark comment as spam if is the profile' do
631 user = Person.new 631 user = Person.new
632 - article = Article.new(:profile => user)  
633 - comment = Comment.new(:article => article) 632 + article = build(Article, :profile => user)
  633 + comment = build(Comment, :article => article)
634 634
635 assert comment.can_be_marked_as_spam_by?(user) 635 assert comment.can_be_marked_as_spam_by?(user)
636 end 636 end
@@ -638,8 +638,8 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -638,8 +638,8 @@ class CommentTest &lt; ActiveSupport::TestCase
638 should 'be able to mark comment as spam if can moderate_comments on the profile' do 638 should 'be able to mark comment as spam if can moderate_comments on the profile' do
639 user = Person.new 639 user = Person.new
640 profile = Profile.new 640 profile = Profile.new
641 - article = Article.new(:profile => profile)  
642 - comment = Comment.new(:article => article) 641 + article = build(Article, :profile => profile)
  642 + comment = build(Comment, :article => article)
643 643
644 user.expects(:has_permission?).with(:moderate_comments, profile).returns(true) 644 user.expects(:has_permission?).with(:moderate_comments, profile).returns(true)
645 645
@@ -661,15 +661,15 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -661,15 +661,15 @@ class CommentTest &lt; ActiveSupport::TestCase
661 661
662 should 'be able to update comment if is the author' do 662 should 'be able to update comment if is the author' do
663 user = Person.new 663 user = Person.new
664 - comment = Comment.new(:author => user) 664 + comment = build(Comment, :author => user)
665 665
666 assert comment.can_be_updated_by?(user) 666 assert comment.can_be_updated_by?(user)
667 end 667 end
668 668
669 should 'get comment root' do 669 should 'get comment root' do
670 c1 = Comment.new 670 c1 = Comment.new
671 - c2 = Comment.new(:reply_of => c1)  
672 - c3 = Comment.new(:reply_of => c2) 671 + c2 = build(Comment, :reply_of => c1)
  672 + c3 = build(Comment, :reply_of => c2)
673 673
674 assert_equal c1, c3.comment_root 674 assert_equal c1, c3.comment_root
675 assert_equal c1, c2.comment_root 675 assert_equal c1, c2.comment_root