Commit 46f1339016b6ab52786ba332a78990f20da02e2b

Authored by Rodrigo Souto
1 parent 0945abec

rails3: fix article tests

PS: still breaking some tests due to action_tracker problem and html
generation on models problem.
Showing 1 changed file with 128 additions and 128 deletions   Show diff stats
test/unit/article_test.rb
@@ -31,7 +31,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -31,7 +31,7 @@ class ArticleTest < ActiveSupport::TestCase
31 end 31 end
32 32
33 should 'limit length of names' do 33 should 'limit length of names' do
34 - a = Article.new(:name => 'a'*151) 34 + a = build(Article, :name => 'a'*151)
35 a.valid? 35 a.valid?
36 assert a.errors[:name.to_s].present? 36 assert a.errors[:name.to_s].present?
37 37
@@ -41,7 +41,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -41,7 +41,7 @@ class ArticleTest < ActiveSupport::TestCase
41 end 41 end
42 42
43 should 'require value for slug and path if name is filled' do 43 should 'require value for slug and path if name is filled' do
44 - a = Article.new(:name => 'test article') 44 + a = build(Article, :name => 'test article')
45 a.slug = nil 45 a.slug = nil
46 a.path = nil 46 a.path = nil
47 a.valid? 47 a.valid?
@@ -57,7 +57,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -57,7 +57,7 @@ class ArticleTest < ActiveSupport::TestCase
57 end 57 end
58 58
59 should 'act as versioned' do 59 should 'act as versioned' do
60 - a = Article.create!(:name => 'my article', :body => 'my text', :profile_id => profile.id) 60 + a = create(Article, :name => 'my article', :body => 'my text', :profile_id => profile.id)
61 assert_equal 1, a.versions(true).size 61 assert_equal 1, a.versions(true).size
62 a.name = 'some other name' 62 a.name = 'some other name'
63 a.save! 63 a.save!
@@ -65,7 +65,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -65,7 +65,7 @@ class ArticleTest < ActiveSupport::TestCase
65 end 65 end
66 66
67 should 'act as taggable' do 67 should 'act as taggable' do
68 - a = Article.create!(:name => 'my article', :profile_id => profile.id) 68 + a = create(Article, :name => 'my article', :profile_id => profile.id)
69 a.tag_list = ['one', 'two'] 69 a.tag_list = ['one', 'two']
70 tags = a.tag_list.names 70 tags = a.tag_list.names
71 assert tags.include?('one') 71 assert tags.include?('one')
@@ -73,16 +73,17 @@ class ArticleTest < ActiveSupport::TestCase @@ -73,16 +73,17 @@ class ArticleTest < ActiveSupport::TestCase
73 end 73 end
74 74
75 should 'act as filesystem' do 75 should 'act as filesystem' do
76 - a = Article.create!(:name => 'my article', :profile_id => profile.id)  
77 - b = a.children.build(:name => 'child article', :profile_id => profile.id) 76 + a = create(Article, :profile_id => profile.id)
  77 + b = create(Article, :profile_id => profile.id, :parent_id => a.id)
78 b.save! 78 b.save!
79 - assert_equal 'my-article/child-article', b.path 79 + assert_equal "#{a.slug}/#{b.slug}", b.path
80 80
81 a = Article.find(a.id); 81 a = Article.find(a.id);
82 a.name = 'another name' 82 a.name = 'another name'
83 a.save! 83 a.save!
  84 + b.reload
84 85
85 - assert_equal 'another-name/child-article', Article.find(b.id).path 86 + assert_equal "another-name/#{b.slug}", b.path
86 end 87 end
87 88
88 should 'provide HTML version' do 89 should 'provide HTML version' do
@@ -226,13 +227,14 @@ class ArticleTest < ActiveSupport::TestCase @@ -226,13 +227,14 @@ class ArticleTest < ActiveSupport::TestCase
226 227
227 now = Time.now 228 now = Time.now
228 229
229 - first = p.articles.build(:name => 'first', :published => true, :created_at => now, :published_at => now); first.save!  
230 - second = p.articles.build(:name => 'second', :published => true, :updated_at => now, :published_at => now + 1.second); second.save! 230 + first = create(Article, :name => 'first', :published => true, :created_at => now, :published_at => now, :profile_id => p.id)
  231 + second = create(Article, :name => 'second', :published => true, :updated_at => now, :published_at => now + 1.second, :profile_id => p.id)
231 232
232 assert_equal [ second, first ], Article.recent(2) 233 assert_equal [ second, first ], Article.recent(2)
233 234
234 Article.record_timestamps = false 235 Article.record_timestamps = false
235 - first.update_attributes!(:published_at => second.published_at + 1.second) 236 + first.published_at = second.published_at + 1.second
  237 + first.save!
236 Article.record_timestamps = true 238 Article.record_timestamps = true
237 239
238 assert_equal [ first, second ], Article.recent(2) 240 assert_equal [ first, second ], Article.recent(2)
@@ -242,7 +244,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -242,7 +244,7 @@ class ArticleTest < ActiveSupport::TestCase
242 p = create_user('usr1').person 244 p = create_user('usr1').person
243 Article.destroy_all 245 Article.destroy_all
244 246
245 - first = UploadedFile.new(:profile => p, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')); first.save! 247 + first = build(UploadedFile, :profile => p, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')); first.save!
246 second = fast_create(TextArticle, :profile_id => p.id, :name => 'second') 248 second = fast_create(TextArticle, :profile_id => p.id, :name => 'second')
247 249
248 assert_equal [ second ], Article.recent(nil) 250 assert_equal [ second ], Article.recent(nil)
@@ -262,7 +264,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -262,7 +264,7 @@ class ArticleTest < ActiveSupport::TestCase
262 p = create_user('usr1').person 264 p = create_user('usr1').person
263 Article.destroy_all 265 Article.destroy_all
264 first = fast_create(Blog, :profile_id => p.id, :name => 'my blog', :advertise => true) 266 first = fast_create(Blog, :profile_id => p.id, :name => 'my blog', :advertise => true)
265 - second = p.articles.build(:name => 'second'); second.save! 267 + second = create(Article, :name => 'second', :profile_id => p.id)
266 268
267 assert_equal [ second ], Article.recent(nil) 269 assert_equal [ second ], Article.recent(nil)
268 end 270 end
@@ -270,8 +272,8 @@ class ArticleTest < ActiveSupport::TestCase @@ -270,8 +272,8 @@ class ArticleTest < ActiveSupport::TestCase
270 should 'accept extra conditions to find recent' do 272 should 'accept extra conditions to find recent' do
271 p = create_user('usr1').person 273 p = create_user('usr1').person
272 Article.destroy_all 274 Article.destroy_all
273 - a1 = p.articles.create!(:name => 'first')  
274 - a2 = p.articles.create!(:name => 'second') 275 + a1 = create(Article, :name => 'first', :profile_id => p.id)
  276 + a2 = create(Article, :name => 'second', :profile_id => p.id)
275 277
276 assert_equal [ a1 ], Article.recent(nil, :name => 'first') 278 assert_equal [ a1 ], Article.recent(nil, :name => 'first')
277 end 279 end
@@ -293,27 +295,24 @@ class ArticleTest < ActiveSupport::TestCase @@ -293,27 +295,24 @@ class ArticleTest < ActiveSupport::TestCase
293 end 295 end
294 296
295 should 'provide a url to itself' do 297 should 'provide a url to itself' do
296 - article = profile.articles.build(:name => 'myarticle')  
297 - article.save!  
298 - 298 + article = create(Article, :name => 'myarticle', :profile_id => profile.id)
299 assert_equal(profile.url.merge(:page => ['myarticle']), article.url) 299 assert_equal(profile.url.merge(:page => ['myarticle']), article.url)
300 end 300 end
301 301
302 should 'provide a url to itself having a parent topic' do 302 should 'provide a url to itself having a parent topic' do
303 - parent = profile.articles.build(:name => 'parent'); parent.save!  
304 - child = profile.articles.build(:name => 'child', :parent => parent); child.save! 303 + parent = create(Article, :name => 'parent', :profile_id => profile.id)
  304 + child = create(Article, :name => 'child', :parent => parent, :profile_id => profile.id)
305 305
306 assert_equal(profile.url.merge(:page => [ 'parent', 'child']), child.url) 306 assert_equal(profile.url.merge(:page => [ 'parent', 'child']), child.url)
307 end 307 end
308 308
309 should 'associate with categories' do 309 should 'associate with categories' do
310 env = Environment.default 310 env = Environment.default
311 - parent_cat = env.categories.build(:name => "parent category")  
312 - parent_cat.save!  
313 - c1 = env.categories.build(:name => "test category 1", :parent_id => parent_cat.id); c1.save!  
314 - c2 = env.categories.build(:name => "test category 2"); c2.save! 311 + parent_cat = create(Category, :name => "parent category", :environment_id => env.id)
  312 + c1 = create(Category, :name => "test category 1", :parent_id => parent_cat.id, :environment_id => env.id)
  313 + c2 = create(Category, :name => "test category 2", :environment_id => env.id)
315 314
316 - article = profile.articles.build(:name => 'withcategories') 315 + article = create(Article, :name => 'withcategories', :profile_id => profile.id)
317 article.save! 316 article.save!
318 317
319 article.add_category c1 318 article.add_category c1
@@ -325,8 +324,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -325,8 +324,7 @@ class ArticleTest < ActiveSupport::TestCase
325 324
326 should 'remove comments when removing article' do 325 should 'remove comments when removing article' do
327 assert_no_difference Comment, :count do 326 assert_no_difference Comment, :count do
328 - a = profile.articles.build(:name => 'test article')  
329 - a.save! 327 + a = create(Article, :name => 'test article', :profile_id => profile.id)
330 328
331 assert_difference Comment, :count, 1 do 329 assert_difference Comment, :count, 1 do
332 comment = a.comments.build 330 comment = a.comments.build
@@ -346,10 +344,10 @@ class ArticleTest < ActiveSupport::TestCase @@ -346,10 +344,10 @@ class ArticleTest < ActiveSupport::TestCase
346 create(TextileArticle, :name => "art #{n}", :profile_id => profile.id) 344 create(TextileArticle, :name => "art #{n}", :profile_id => profile.id)
347 end 345 end
348 first_article = profile.articles.first 346 first_article = profile.articles.first
349 - 2.times { Comment.create(:title => 'test', :body => 'asdsad', :author => profile, :source => first_article).save! } 347 + 2.times { create(Comment, :title => 'test', :body => 'asdsad', :author => profile, :source => first_article).save! }
350 348
351 last_article = profile.articles.last 349 last_article = profile.articles.last
352 - 4.times { Comment.create(:title => 'test', :body => 'asdsad', :author => profile, :source => last_article).save! } 350 + 4.times { create(Comment, :title => 'test', :body => 'asdsad', :author => profile, :source => last_article).save! }
353 # should respect the order (more commented comes first) 351 # should respect the order (more commented comes first)
354 assert_equal [last_article, first_article], profile.articles.most_commented(2) 352 assert_equal [last_article, first_article], profile.articles.most_commented(2)
355 end 353 end
@@ -370,20 +368,21 @@ class ArticleTest < ActiveSupport::TestCase @@ -370,20 +368,21 @@ class ArticleTest < ActiveSupport::TestCase
370 should 'display to owner' do 368 should 'display to owner' do
371 # a person with private contents ... 369 # a person with private contents ...
372 person = create_user('testuser').person 370 person = create_user('testuser').person
373 - person.update_attributes!(:public_content => false) 371 + person.public_content = false
  372 + person.save!
374 373
375 # ... can see his own articles 374 # ... can see his own articles
376 - a = person.articles.create!(:name => 'test article') 375 + a = create(Article, :name => 'test article', :profile_id => person.id)
377 assert_equal true, a.display_to?(person) 376 assert_equal true, a.display_to?(person)
378 end 377 end
379 378
380 should 'cache children count' do 379 should 'cache children count' do
381 owner = create_user('testuser').person 380 owner = create_user('testuser').person
382 - art = owner.articles.build(:name => 'ytest'); art.save! 381 + art = create(Article, :name => 'ytest', :profile_id => owner.id)
383 382
384 # two children articles 383 # two children articles
385 - art.children.create!(:profile => owner, :name => 'c1')  
386 - art.children.create!(:profile => owner, :name => 'c2') 384 + create(Article, :profile => owner, :name => 'c1', :parent_id => art.id)
  385 + create(Article, :profile => owner, :name => 'c2', :parent_id => art.id)
387 386
388 art.reload 387 art.reload
389 388
@@ -393,12 +392,12 @@ class ArticleTest < ActiveSupport::TestCase @@ -393,12 +392,12 @@ class ArticleTest < ActiveSupport::TestCase
393 end 392 end
394 393
395 should 'categorize in the entire category hierarchy' do 394 should 'categorize in the entire category hierarchy' do
396 - c1 = Category.create!(:environment => Environment.default, :name => 'c1')  
397 - c2 = c1.children.create!(:environment => Environment.default, :name => 'c2')  
398 - c3 = c2.children.create!(:environment => Environment.default, :name => 'c3') 395 + c1 = create(Category, :environment => Environment.default, :name => 'c1')
  396 + c2 = create(Category, :environment => Environment.default, :name => 'c2', :parent_id => c1.id)
  397 + c3 = create(Category, :environment => Environment.default, :name => 'c3', :parent_id => c2.id)
399 398
400 owner = create_user('testuser').person 399 owner = create_user('testuser').person
401 - art = owner.articles.create!(:name => 'ytest') 400 + art = create(Article, :name => 'ytest', :profile_id => owner.id)
402 401
403 art.add_category(c3) 402 art.add_category(c3)
404 403
@@ -414,12 +413,12 @@ class ArticleTest < ActiveSupport::TestCase @@ -414,12 +413,12 @@ class ArticleTest < ActiveSupport::TestCase
414 end 413 end
415 414
416 should 'redefine the entire category set at once' do 415 should 'redefine the entire category set at once' do
417 - c1 = Category.create!(:environment => Environment.default, :name => 'c1')  
418 - c2 = c1.children.create!(:environment => Environment.default, :name => 'c2')  
419 - c3 = c2.children.create!(:environment => Environment.default, :name => 'c3')  
420 - c4 = c1.children.create!(:environment => Environment.default, :name => 'c4') 416 + c1 = create(Category, :environment => Environment.default, :name => 'c1')
  417 + c2 = create(Category, :environment => Environment.default, :name => 'c2', :parent_id => c1)
  418 + c3 = create(Category, :environment => Environment.default, :name => 'c3', :parent_id => c2)
  419 + c4 = create(Category, :environment => Environment.default, :name => 'c4', :parent_id => c1)
421 owner = create_user('testuser').person 420 owner = create_user('testuser').person
422 - art = owner.articles.create!(:name => 'ytest') 421 + art = create(Article, :name => 'ytest', :profile_id => owner.id)
423 422
424 art.add_category(c4) 423 art.add_category(c4)
425 424
@@ -436,7 +435,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -436,7 +435,7 @@ class ArticleTest < ActiveSupport::TestCase
436 c2 = fast_create(Category, :environment_id => Environment.default.id, :name => 'c2') 435 c2 = fast_create(Category, :environment_id => Environment.default.id, :name => 'c2')
437 436
438 p = create_user('testinguser').person 437 p = create_user('testinguser').person
439 - a = p.articles.create!(:name => 'test', :category_ids => [c1.id, c2.id]) 438 + a = create(Article, :name => 'test', :category_ids => [c1.id, c2.id], :profile_id => p)
440 439
441 assert_equivalent [c1, c2], a.categories(true) 440 assert_equivalent [c1, c2], a.categories(true)
442 assert_includes a.categories_including_virtual(true), parent1 441 assert_includes a.categories_including_virtual(true), parent1
@@ -444,10 +443,10 @@ class ArticleTest < ActiveSupport::TestCase @@ -444,10 +443,10 @@ class ArticleTest < ActiveSupport::TestCase
444 443
445 should 'not add a category twice to article' do 444 should 'not add a category twice to article' do
446 c1 = fast_create(Category, :environment_id => Environment.default.id, :name => 'c1') 445 c1 = fast_create(Category, :environment_id => Environment.default.id, :name => 'c1')
447 - c2 = c1.children.create!(:environment => Environment.default, :name => 'c2', :parent_id => c1.id)  
448 - c3 = c1.children.create!(:environment => Environment.default, :name => 'c3', :parent_id => c1.id) 446 + c2 = create(Category, :environment => Environment.default, :name => 'c2', :parent_id => c1.id)
  447 + c3 = create(Category, :environment => Environment.default, :name => 'c3', :parent_id => c1.id)
449 owner = create_user('testuser').person 448 owner = create_user('testuser').person
450 - art = owner.articles.create!(:name => 'ytest') 449 + art = create(Article, :name => 'ytest', :profile_id => owner)
451 art.category_ids = [c2,c3,c3].map(&:id) 450 art.category_ids = [c2,c3,c3].map(&:id)
452 assert_equal [c2, c3], art.categories(true) 451 assert_equal [c2, c3], art.categories(true)
453 assert_equal [c2, c1, c3], art.categories_including_virtual(true) 452 assert_equal [c2, c1, c3], art.categories_including_virtual(true)
@@ -538,7 +537,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -538,7 +537,7 @@ class ArticleTest < ActiveSupport::TestCase
538 537
539 should 'not allow friends of private person see the article' do 538 should 'not allow friends of private person see the article' do
540 person = create_user('test_user').person 539 person = create_user('test_user').person
541 - article = Article.create!(:name => 'test article', :profile => person, :published => false) 540 + article = create(Article, :name => 'test article', :profile => person, :published => false)
542 friend = create_user('test_friend').person 541 friend = create_user('test_friend').person
543 person.add_friend(friend) 542 person.add_friend(friend)
544 person.save! 543 person.save!
@@ -559,7 +558,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -559,7 +558,7 @@ class ArticleTest < ActiveSupport::TestCase
559 558
560 should 'make a copy of the article as child of it' do 559 should 'make a copy of the article as child of it' do
561 person = create_user('test_user').person 560 person = create_user('test_user').person
562 - a = person.articles.create!(:name => 'test article', :body => 'some text') 561 + a = create(Article, :name => 'test article', :body => 'some text', :profile_id => person.id)
563 b = a.copy(:parent => a, :profile => a.profile) 562 b = a.copy(:parent => a, :profile => a.profile)
564 563
565 assert_includes a.children, b 564 assert_includes a.children, b
@@ -569,7 +568,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -569,7 +568,7 @@ class ArticleTest < ActiveSupport::TestCase
569 should 'make a copy of the article to other profile' do 568 should 'make a copy of the article to other profile' do
570 p1 = create_user('test_user1').person 569 p1 = create_user('test_user1').person
571 p2 = create_user('test_user2').person 570 p2 = create_user('test_user2').person
572 - a = p1.articles.create!(:name => 'test article', :body => 'some text') 571 + a = create(Article, :name => 'test article', :body => 'some text', :profile_id => p1)
573 b = a.copy(:parent => a, :profile => p2) 572 b = a.copy(:parent => a, :profile => p2)
574 573
575 p2 = Person.find(p2.id) 574 p2 = Person.find(p2.id)
@@ -593,7 +592,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -593,7 +592,7 @@ class ArticleTest < ActiveSupport::TestCase
593 592
594 should 'load article under an old path' do 593 should 'load article under an old path' do
595 p = create_user('test_user').person 594 p = create_user('test_user').person
596 - a = p.articles.create(:name => 'old-name') 595 + a = create(Article, :name => 'old-name', :profile_id => p.id)
597 old_path = a.explode_path 596 old_path = a.explode_path
598 a.name = 'new-name' 597 a.name = 'new-name'
599 a.save! 598 a.save!
@@ -605,7 +604,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -605,7 +604,7 @@ class ArticleTest < ActiveSupport::TestCase
605 604
606 should 'load new article name equal of another article old name' do 605 should 'load new article name equal of another article old name' do
607 p = create_user('test_user').person 606 p = create_user('test_user').person
608 - a1 = p.articles.create!(:name => 'old-name') 607 + a1 = create(Article, :name => 'old-name', :profile_id => p.id)
609 old_path = a1.explode_path 608 old_path = a1.explode_path
610 a1.name = 'new-name' 609 a1.name = 'new-name'
611 a1.save! 610 a1.save!
@@ -618,11 +617,11 @@ class ArticleTest < ActiveSupport::TestCase @@ -618,11 +617,11 @@ class ArticleTest < ActiveSupport::TestCase
618 617
619 should 'article with most recent version with the name must be loaded if no aritcle with the name' do 618 should 'article with most recent version with the name must be loaded if no aritcle with the name' do
620 p = create_user('test_user').person 619 p = create_user('test_user').person
621 - a1 = p.articles.create!(:name => 'old-name') 620 + a1 = create(Article, :name => 'old-name', :profile_id => p.id)
622 old_path = a1.explode_path 621 old_path = a1.explode_path
623 a1.name = 'new-name' 622 a1.name = 'new-name'
624 a1.save! 623 a1.save!
625 - a2 = p.articles.create!(:name => 'old-name') 624 + a2 = create(Article, :name => 'old-name', :profile_id => p.id)
626 a2.name = 'other-new-name' 625 a2.name = 'other-new-name'
627 a2.save! 626 a2.save!
628 627
@@ -633,7 +632,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -633,7 +632,7 @@ class ArticleTest < ActiveSupport::TestCase
633 632
634 should 'not return an article of a different user' do 633 should 'not return an article of a different user' do
635 p1 = create_user('test_user').person 634 p1 = create_user('test_user').person
636 - a = p1.articles.create!(:name => 'old-name') 635 + a = create(Article, :name => 'old-name', :profile_id => p1.id)
637 old_path = a.explode_path 636 old_path = a.explode_path
638 a.name = 'new-name' 637 a.name = 'new-name'
639 a.save! 638 a.save!
@@ -665,13 +664,13 @@ class ArticleTest < ActiveSupport::TestCase @@ -665,13 +664,13 @@ class ArticleTest < ActiveSupport::TestCase
665 end 664 end
666 665
667 should 'has moderate comments false by default' do 666 should 'has moderate comments false by default' do
668 - a = Article.create!(:name => 'my article', :body => 'my text', :profile_id => profile.id) 667 + a = create(Article, :name => 'my article', :body => 'my text', :profile_id => profile.id)
669 a.reload 668 a.reload
670 assert a.moderate_comments == false 669 assert a.moderate_comments == false
671 end 670 end
672 671
673 should 'save a article with moderate comments as true' do 672 should 'save a article with moderate comments as true' do
674 - a = Article.create!(:name => 'my article', :body => 'my text', :profile_id => profile.id, :moderate_comments => true) 673 + a = create(Article, :name => 'my article', :body => 'my text', :profile_id => profile.id, :moderate_comments => true)
675 a.reload 674 a.reload
676 assert a.moderate_comments 675 assert a.moderate_comments
677 end 676 end
@@ -717,7 +716,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -717,7 +716,7 @@ class ArticleTest < ActiveSupport::TestCase
717 end 716 end
718 717
719 should 'return a view url when image' do 718 should 'return a view url when image' do
720 - image = UploadedFile.create!(:profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) 719 + image = create(UploadedFile, :profile => profile, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'))
721 720
722 assert_equal image.url.merge(:view => true), image.view_url 721 assert_equal image.url.merge(:view => true), image.view_url
723 end 722 end
@@ -775,7 +774,7 @@ class ArticleTest < ActiveSupport::TestCase @@ -775,7 +774,7 @@ class ArticleTest < ActiveSupport::TestCase
775 end 774 end
776 775
777 should 'ignore category with zero as id' do 776 should 'ignore category with zero as id' do
778 - a = profile.articles.create!(:name => 'a test article') 777 + a = create(Article, :name => 'a test article', :profile_id => profile.id)
779 c = fast_create(Category, :name => 'test category', :environment_id => profile.environment.id, :parent_id => 0) 778 c = fast_create(Category, :name => 'test category', :environment_id => profile.environment.id, :parent_id => 0)
780 a.category_ids = ['0', c.id, nil] 779 a.category_ids = ['0', c.id, nil]
781 assert a.save 780 assert a.save
@@ -788,25 +787,25 @@ class ArticleTest < ActiveSupport::TestCase @@ -788,25 +787,25 @@ class ArticleTest < ActiveSupport::TestCase
788 end 787 end
789 788
790 should 'add owner on cache_key when has profile' do 789 should 'add owner on cache_key when has profile' do
791 - a = profile.articles.create!(:name => 'a test article') 790 + a = create(Article, :name => 'a test article', :profile_id => profile.id)
792 assert_match(/-owner/, a.cache_key({}, profile)) 791 assert_match(/-owner/, a.cache_key({}, profile))
793 end 792 end
794 793
795 should 'not add owner on cache_key when has no profile' do 794 should 'not add owner on cache_key when has no profile' do
796 - a = profile.articles.create!(:name => 'a test article') 795 + a = create(Article, :name => 'a test article', :profile_id => profile.id)
797 assert_no_match(/-owner/, a.cache_key({})) 796 assert_no_match(/-owner/, a.cache_key({}))
798 end 797 end
799 798
800 should 'add owner on cache_key when profile is community' do 799 should 'add owner on cache_key when profile is community' do
801 c = fast_create(Community) 800 c = fast_create(Community)
802 - a = c.articles.create!(:name => 'a test article') 801 + a = create(Article, :name => 'a test article', :profile_id => c.id)
803 assert_match(/-owner/, a.cache_key({}, c)) 802 assert_match(/-owner/, a.cache_key({}, c))
804 end 803 end
805 804
806 should 'allow author to edit if is publisher' do 805 should 'allow author to edit if is publisher' do
807 c = fast_create(Community) 806 c = fast_create(Community)
808 p = create_user_with_permission('test_user', 'publish_content', c) 807 p = create_user_with_permission('test_user', 'publish_content', c)
809 - a = c.articles.create!(:name => 'a test article', :last_changed_by => p) 808 + a = create(Article, :name => 'a test article', :last_changed_by => p, :profile_id => c.id)
810 809
811 assert a.allow_post_content?(p) 810 assert a.allow_post_content?(p)
812 end 811 end
@@ -814,13 +813,13 @@ class ArticleTest < ActiveSupport::TestCase @@ -814,13 +813,13 @@ class ArticleTest < ActiveSupport::TestCase
814 should 'allow user with "Manage content" permissions to edit' do 813 should 'allow user with "Manage content" permissions to edit' do
815 c = fast_create(Community) 814 c = fast_create(Community)
816 p = create_user_with_permission('test_user', 'post_content', c) 815 p = create_user_with_permission('test_user', 'post_content', c)
817 - a = c.articles.create!(:name => 'a test article') 816 + a = create(Article, :name => 'a test article', :profile_id => c.id)
818 817
819 assert a.allow_post_content?(p) 818 assert a.allow_post_content?(p)
820 end 819 end
821 820
822 should 'update slug from name' do 821 should 'update slug from name' do
823 - article = Article.create!(:name => 'A test article', :profile_id => profile.id) 822 + article = create(Article, :name => 'A test article', :profile_id => profile.id)
824 assert_equal 'a-test-article', article.slug 823 assert_equal 'a-test-article', article.slug
825 article.name = 'Changed name' 824 article.name = 'Changed name'
826 assert_equal 'changed-name', article.slug 825 assert_equal 'changed-name', article.slug
@@ -828,11 +827,11 @@ class ArticleTest < ActiveSupport::TestCase @@ -828,11 +827,11 @@ class ArticleTest < ActiveSupport::TestCase
828 827
829 should 'find articles in a specific category' do 828 should 'find articles in a specific category' do
830 env = Environment.default 829 env = Environment.default
831 - parent_category = env.categories.create!(:name => "parent category")  
832 - category_with_articles = env.categories.create!(:name => "Category with articles", :parent_id => parent_category.id)  
833 - category_without_articles = env.categories.create!(:name => "Category without articles") 830 + parent_category = create(Category, :name => "parent category", :environment_id => env.id)
  831 + category_with_articles = create(Category, :name => "Category with articles", :parent_id => parent_category.id, :environment_id => env.id)
  832 + category_without_articles = create(Category, :name => "Category without articles", :environment_id => env.id)
834 833
835 - article_in_category = profile.articles.create!(:name => 'Article in category') 834 + article_in_category = create(Article, :name => 'Article in category', :profile_id => profile.id)
836 835
837 article_in_category.add_category(category_with_articles) 836 article_in_category.add_category(category_with_articles)
838 837
@@ -843,33 +842,33 @@ class ArticleTest < ActiveSupport::TestCase @@ -843,33 +842,33 @@ class ArticleTest < ActiveSupport::TestCase
843 842
844 should 'has external_link attr' do 843 should 'has external_link attr' do
845 assert_nothing_raised NoMethodError do 844 assert_nothing_raised NoMethodError do
846 - Article.new(:external_link => 'http://some.external.link') 845 + build(Article, :external_link => 'http://some.external.link')
847 end 846 end
848 end 847 end
849 848
850 should 'validates format of external_link' do 849 should 'validates format of external_link' do
851 - article = Article.new(:external_link => 'http://invalid-url') 850 + article = build(Article, :external_link => 'http://invalid-url')
852 article.valid? 851 article.valid?
853 assert_not_nil article.errors[:external_link] 852 assert_not_nil article.errors[:external_link]
854 end 853 end
855 854
856 should 'put http in external_link' do 855 should 'put http in external_link' do
857 - article = Article.new(:external_link => 'url.without.http') 856 + article = build(Article, :external_link => 'url.without.http')
858 assert_equal 'http://url.without.http', article.external_link 857 assert_equal 'http://url.without.http', article.external_link
859 end 858 end
860 859
861 should 'list only published articles' do 860 should 'list only published articles' do
862 profile = fast_create(Person) 861 profile = fast_create(Person)
863 862
864 - published = profile.articles.create(:name => 'Published', :published => true)  
865 - unpublished = profile.articles.create(:name => 'Unpublished', :published => false) 863 + published = create(Article, :name => 'Published', :published => true, :profile_id => profile.id)
  864 + unpublished = create(Article, :name => 'Unpublished', :published => false, :profile_id => profile.id)
866 865
867 assert_equal [ published ], profile.articles.published 866 assert_equal [ published ], profile.articles.published
868 end 867 end
869 868
870 should 'sanitize tags after save article' do 869 should 'sanitize tags after save article' do
871 article = fast_create(Article, :slug => 'article-with-tags', :profile_id => profile.id) 870 article = fast_create(Article, :slug => 'article-with-tags', :profile_id => profile.id)
872 - article.tags << Tag.new(:name => "TV Web w<script type='javascript'></script>") 871 + article.tags << build(Tag, :name => "TV Web w<script type='javascript'></script>")
873 assert_match /[<>]/, article.tags.last.name 872 assert_match /[<>]/, article.tags.last.name
874 article.save! 873 article.save!
875 assert_no_match /[<>]/, article.tags.last.name 874 assert_no_match /[<>]/, article.tags.last.name
@@ -877,7 +876,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -877,7 +876,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
877 876
878 should 'strip HTML from tag names after save article' do 877 should 'strip HTML from tag names after save article' do
879 article = fast_create(Article, :slug => 'article-with-tags', :profile_id => profile.id) 878 article = fast_create(Article, :slug => 'article-with-tags', :profile_id => profile.id)
880 - article.tags << Tag.new(:name => "TV Web w<script type=...") 879 + article.tags << build(Tag, :name => "TV Web w<script type=...")
881 assert_match /</, article.tags.last.name 880 assert_match /</, article.tags.last.name
882 article.save! 881 article.save!
883 assert_no_match /</, article.tags.last.name 882 assert_no_match /</, article.tags.last.name
@@ -895,7 +894,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -895,7 +894,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
895 person = fast_create(Person) 894 person = fast_create(Person)
896 community = fast_create(Community) 895 community = fast_create(Community)
897 article = fast_create(Article, :name => 'article name', :profile_id => person.id) 896 article = fast_create(Article, :name => 'article name', :profile_id => person.id)
898 - a = ApproveArticle.create!(:article => article, :target => community, :requestor => profile) 897 + a = create(ApproveArticle, :article => article, :target => community, :requestor => profile)
899 a.finish 898 a.finish
900 899
901 published = community.articles.find_by_name('article name') 900 published = community.articles.find_by_name('article name')
@@ -905,7 +904,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -905,7 +904,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
905 end 904 end
906 905
907 should 'remove script tags from name' do 906 should 'remove script tags from name' do
908 - a = Article.new(:name => 'hello <script>alert(1)</script>') 907 + a = build(Article, :name => 'hello <script>alert(1)</script>')
909 a.valid? 908 a.valid?
910 909
911 assert_no_match(/<script>/, a.name) 910 assert_no_match(/<script>/, a.name)
@@ -926,7 +925,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -926,7 +925,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
926 end 925 end
927 926
928 should 'return abstract as lead' do 927 should 'return abstract as lead' do
929 - a = Article.new(:abstract => 'lead') 928 + a = build(Article, :abstract => 'lead')
930 assert_equal 'lead', a.lead 929 assert_equal 'lead', a.lead
931 end 930 end
932 931
@@ -937,13 +936,13 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -937,13 +936,13 @@ class ArticleTest &lt; ActiveSupport::TestCase
937 end 936 end
938 937
939 should 'return first paragraph as lead with empty but non-null abstract' do 938 should 'return first paragraph as lead with empty but non-null abstract' do
940 - a = Article.new(:abstract => '') 939 + a = build(Article, :abstract => '')
941 a.stubs(:first_paragraph).returns('<p>first</p>') 940 a.stubs(:first_paragraph).returns('<p>first</p>')
942 assert_equal '<p>first</p>', a.lead 941 assert_equal '<p>first</p>', a.lead
943 end 942 end
944 943
945 should 'return blank as lead when article has no paragraphs' do 944 should 'return blank as lead when article has no paragraphs' do
946 - a = Article.new(:body => "<div>an article with content <em>but without</em> a paragraph</div>") 945 + a = build(Article, :body => "<div>an article with content <em>but without</em> a paragraph</div>")
947 assert_equal '', a.lead 946 assert_equal '', a.lead
948 end 947 end
949 948
@@ -953,7 +952,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -953,7 +952,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
953 end 952 end
954 953
955 should 'remove html from short lead' do 954 should 'remove html from short lead' do
956 - a = Article.new(:body => "<p>an article with html that should be <em>removed</em></p>") 955 + a = build(Article, :body => "<p>an article with html that should be <em>removed</em></p>")
957 assert_equal 'an article with html that should be removed', a.short_lead 956 assert_equal 'an article with html that should be removed', a.short_lead
958 end 957 end
959 958
@@ -995,13 +994,13 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -995,13 +994,13 @@ class ArticleTest &lt; ActiveSupport::TestCase
995 994
996 should 'not notify activity by default on create' do 995 should 'not notify activity by default on create' do
997 ActionTracker::Record.delete_all 996 ActionTracker::Record.delete_all
998 - Article.create! :name => 'test', :profile_id => fast_create(Profile).id, :published => true 997 + create Article, :name => 'test', :profile_id => fast_create(Profile).id, :published => true
999 assert_equal 0, ActionTracker::Record.count 998 assert_equal 0, ActionTracker::Record.count
1000 end 999 end
1001 1000
1002 should 'not notify activity by default on update' do 1001 should 'not notify activity by default on update' do
1003 ActionTracker::Record.delete_all 1002 ActionTracker::Record.delete_all
1004 - a = Article.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true 1003 + a = create Article, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true
1005 a.name = 'foo' 1004 a.name = 'foo'
1006 a.save! 1005 a.save!
1007 assert_equal 0, ActionTracker::Record.count 1006 assert_equal 0, ActionTracker::Record.count
@@ -1009,13 +1008,13 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1009,13 +1008,13 @@ class ArticleTest &lt; ActiveSupport::TestCase
1009 1008
1010 should 'not notify activity by default on destroy' do 1009 should 'not notify activity by default on destroy' do
1011 ActionTracker::Record.delete_all 1010 ActionTracker::Record.delete_all
1012 - a = Article.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true 1011 + a = create Article, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true
1013 a.destroy 1012 a.destroy
1014 assert_equal 0, ActionTracker::Record.count 1013 assert_equal 0, ActionTracker::Record.count
1015 end 1014 end
1016 1015
1017 should 'create activity' do 1016 should 'create activity' do
1018 - a = TextileArticle.create! :name => 'bar', :profile_id => fast_create(Profile).id, :published => true 1017 + a = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true
1019 a.activity.destroy 1018 a.activity.destroy
1020 assert_nil a.activity 1019 assert_nil a.activity
1021 1020
@@ -1070,7 +1069,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1070,7 +1069,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1070 member_1 = Person.first 1069 member_1 = Person.first
1071 community.add_member(member_1) 1070 community.add_member(member_1)
1072 1071
1073 - article = TinyMceArticle.create! :name => 'Tracked Article 1', :profile_id => community.id 1072 + article = create TinyMceArticle, :name => 'Tracked Article 1', :profile_id => community.id
1074 first_activity = article.activity 1073 first_activity = article.activity
1075 assert_equal [first_activity], ActionTracker::Record.find_all_by_verb('create_article') 1074 assert_equal [first_activity], ActionTracker::Record.find_all_by_verb('create_article')
1076 1075
@@ -1080,7 +1079,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1080,7 +1079,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1080 member_2 = fast_create(Person) 1079 member_2 = fast_create(Person)
1081 community.add_member(member_2) 1080 community.add_member(member_2)
1082 1081
1083 - article2 = TinyMceArticle.create! :name => 'Tracked Article 2', :profile_id => community.id 1082 + article2 = create TinyMceArticle, :name => 'Tracked Article 2', :profile_id => community.id
1084 second_activity = article2.activity 1083 second_activity = article2.activity
1085 assert_equivalent [first_activity, second_activity], ActionTracker::Record.find_all_by_verb('create_article') 1084 assert_equivalent [first_activity, second_activity], ActionTracker::Record.find_all_by_verb('create_article')
1086 1085
@@ -1106,14 +1105,14 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1106,14 +1105,14 @@ class ArticleTest &lt; ActiveSupport::TestCase
1106 profile.add_friend(f1) 1105 profile.add_friend(f1)
1107 1106
1108 UserStampSweeper.any_instance.expects(:current_user).returns(profile).at_least_once 1107 UserStampSweeper.any_instance.expects(:current_user).returns(profile).at_least_once
1109 - article = TinyMceArticle.create! :name => 'Tracked Article 1', :profile_id => profile.id 1108 + article = create TinyMceArticle, :name => 'Tracked Article 1', :profile_id => profile.id
1110 assert_equal 1, ActionTracker::Record.find_all_by_verb('create_article').count 1109 assert_equal 1, ActionTracker::Record.find_all_by_verb('create_article').count
1111 process_delayed_job_queue 1110 process_delayed_job_queue
1112 assert_equal 2, ActionTrackerNotification.find_all_by_action_tracker_id(article.activity.id).count 1111 assert_equal 2, ActionTrackerNotification.find_all_by_action_tracker_id(article.activity.id).count
1113 1112
1114 f2 = fast_create(Person) 1113 f2 = fast_create(Person)
1115 profile.add_friend(f2) 1114 profile.add_friend(f2)
1116 - article2 = TinyMceArticle.create! :name => 'Tracked Article 2', :profile_id => profile.id 1115 + article2 = create TinyMceArticle, :name => 'Tracked Article 2', :profile_id => profile.id
1117 assert_equal 2, ActionTracker::Record.find_all_by_verb('create_article').count 1116 assert_equal 2, ActionTracker::Record.find_all_by_verb('create_article').count
1118 process_delayed_job_queue 1117 process_delayed_job_queue
1119 assert_equal 3, ActionTrackerNotification.find_all_by_action_tracker_id(article2.activity.id).count 1118 assert_equal 3, ActionTrackerNotification.find_all_by_action_tracker_id(article2.activity.id).count
@@ -1378,7 +1377,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1378,7 +1377,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1378 1377
1379 should "the author_name returns the name of the article's author" do 1378 should "the author_name returns the name of the article's author" do
1380 author = fast_create(Person) 1379 author = fast_create(Person)
1381 - a = profile.articles.create!(:name => 'a test article', :last_changed_by => author) 1380 + a = create(Article, :name => 'a test article', :last_changed_by => author, :profile_id => profile.id)
1382 assert_equal author.name, a.author_name 1381 assert_equal author.name, a.author_name
1383 author.destroy 1382 author.destroy
1384 a.reload 1383 a.reload
@@ -1397,7 +1396,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1397,7 +1396,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1397 should 'retrieve latest info from comment when has comments' do 1396 should 'retrieve latest info from comment when has comments' do
1398 forum = fast_create(Forum, :name => 'Forum test', :profile_id => profile.id) 1397 forum = fast_create(Forum, :name => 'Forum test', :profile_id => profile.id)
1399 post = fast_create(TextileArticle, :name => 'First post', :profile_id => profile.id, :parent_id => forum.id, :updated_at => Time.now) 1398 post = fast_create(TextileArticle, :name => 'First post', :profile_id => profile.id, :parent_id => forum.id, :updated_at => Time.now)
1400 - post.comments << Comment.new(:name => 'Guest', :email => 'guest@example.com', :title => 'test comment', :body => 'hello!') 1399 + post.comments << build(Comment, :name => 'Guest', :email => 'guest@example.com', :title => 'test comment', :body => 'hello!')
1401 assert_equal post.comments.last.created_at, post.info_from_last_update[:date] 1400 assert_equal post.comments.last.created_at, post.info_from_last_update[:date]
1402 assert_equal "Guest", post.info_from_last_update[:author_name] 1401 assert_equal "Guest", post.info_from_last_update[:author_name]
1403 assert_nil post.info_from_last_update[:author_url] 1402 assert_nil post.info_from_last_update[:author_url]
@@ -1463,7 +1462,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1463,7 +1462,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1463 1462
1464 should 'get images paths in article body' do 1463 should 'get images paths in article body' do
1465 Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') 1464 Environment.any_instance.stubs(:default_hostname).returns('noosfero.org')
1466 - a = TinyMceArticle.new :profile => @profile 1465 + a = build TinyMceArticle, :profile => @profile
1467 a.body = 'Noosfero <img src="http://noosfero.com/test.png" /> test <img src="http://test.com/noosfero.png" />' 1466 a.body = 'Noosfero <img src="http://noosfero.com/test.png" /> test <img src="http://test.com/noosfero.png" />'
1468 assert_includes a.body_images_paths, 'http://noosfero.com/test.png' 1467 assert_includes a.body_images_paths, 'http://noosfero.com/test.png'
1469 assert_includes a.body_images_paths, 'http://test.com/noosfero.png' 1468 assert_includes a.body_images_paths, 'http://test.com/noosfero.png'
@@ -1471,7 +1470,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1471,7 +1470,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1471 1470
1472 should 'get absolute images paths in article body' do 1471 should 'get absolute images paths in article body' do
1473 Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') 1472 Environment.any_instance.stubs(:default_hostname).returns('noosfero.org')
1474 - a = TinyMceArticle.new :profile => @profile 1473 + a = build TinyMceArticle, :profile => @profile
1475 a.body = 'Noosfero <img src="test.png" alt="Absolute" /> test <img src="/relative/path.png" />' 1474 a.body = 'Noosfero <img src="test.png" alt="Absolute" /> test <img src="/relative/path.png" />'
1476 assert_includes a.body_images_paths, 'http://noosfero.org/test.png' 1475 assert_includes a.body_images_paths, 'http://noosfero.org/test.png'
1477 assert_includes a.body_images_paths, 'http://noosfero.org/relative/path.png' 1476 assert_includes a.body_images_paths, 'http://noosfero.org/relative/path.png'
@@ -1479,20 +1478,20 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1479,20 +1478,20 @@ class ArticleTest &lt; ActiveSupport::TestCase
1479 1478
1480 should 'return empty if there are no images in article body' do 1479 should 'return empty if there are no images in article body' do
1481 Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') 1480 Environment.any_instance.stubs(:default_hostname).returns('noosfero.org')
1482 - a = Event.new :profile => @profile 1481 + a = build Event, :profile => @profile
1483 a.body = 'Noosfero test' 1482 a.body = 'Noosfero test'
1484 assert_equal [], a.body_images_paths 1483 assert_equal [], a.body_images_paths
1485 end 1484 end
1486 1485
1487 should 'return empty if body is nil' do 1486 should 'return empty if body is nil' do
1488 Environment.any_instance.stubs(:default_hostname).returns('noosfero.org') 1487 Environment.any_instance.stubs(:default_hostname).returns('noosfero.org')
1489 - a = Article.new :profile => @profile 1488 + a = build Article, :profile => @profile
1490 assert_equal [], a.body_images_paths 1489 assert_equal [], a.body_images_paths
1491 end 1490 end
1492 1491
1493 should 'survive to a invalid src attribute while looking for images in body' do 1492 should 'survive to a invalid src attribute while looking for images in body' do
1494 - domain = Environment.default.domains.first || Domain.new(:name => 'localhost')  
1495 - article = Article.new(:body => "An article with invalid src in img tag <img src='path with spaces.png' />", :profile => @profile) 1493 + domain = Environment.default.domains.first || build(Domain, :name => 'localhost')
  1494 + article = build(Article, :body => "An article with invalid src in img tag <img src='path with spaces.png' />", :profile => @profile)
1496 assert_nothing_raised URI::InvalidURIError do 1495 assert_nothing_raised URI::InvalidURIError do
1497 assert_equal ["http://#{profile.environment.default_hostname}/path%20with%20spaces.png"], article.body_images_paths 1496 assert_equal ["http://#{profile.environment.default_hostname}/path%20with%20spaces.png"], article.body_images_paths
1498 end 1497 end
@@ -1531,13 +1530,13 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1531,13 +1530,13 @@ class ArticleTest &lt; ActiveSupport::TestCase
1531 end 1530 end
1532 1531
1533 should "return 1 comment on label if the content has 1 comment" do 1532 should "return 1 comment on label if the content has 1 comment" do
1534 - a = Article.new(:comments_count => 1) 1533 + a = build(Article, :comments_count => 1)
1535 assert_equal 1, a.comments_count 1534 assert_equal 1, a.comments_count
1536 assert_equal "one comment", a.more_comments_label 1535 assert_equal "one comment", a.more_comments_label
1537 end 1536 end
1538 1537
1539 should "return number of comments on label if the content has more than one comment" do 1538 should "return number of comments on label if the content has more than one comment" do
1540 - a = Article.new(:comments_count => 4) 1539 + a = build(Article, :comments_count => 4)
1541 assert_equal 4, a.comments_count 1540 assert_equal 4, a.comments_count
1542 assert_equal "4 comments", a.more_comments_label 1541 assert_equal "4 comments", a.more_comments_label
1543 end 1542 end
@@ -1549,13 +1548,13 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1549,13 +1548,13 @@ class ArticleTest &lt; ActiveSupport::TestCase
1549 end 1548 end
1550 1549
1551 should "return 1 view on label if the content has 1 view" do 1550 should "return 1 view on label if the content has 1 view" do
1552 - a = Article.new(:hits => 1) 1551 + a = build(Article, :hits => 1)
1553 assert_equal 1, a.hits 1552 assert_equal 1, a.hits
1554 assert_equal "one view", a.more_popular_label 1553 assert_equal "one view", a.more_popular_label
1555 end 1554 end
1556 1555
1557 should "return number of views on label if the content has more than one view" do 1556 should "return number of views on label if the content has more than one view" do
1558 - a = Article.new(:hits => 4) 1557 + a = build(Article, :hits => 4)
1559 assert_equal 4, a.hits 1558 assert_equal 4, a.hits
1560 assert_equal "4 views", a.more_popular_label 1559 assert_equal "4 views", a.more_popular_label
1561 end 1560 end
@@ -1591,8 +1590,8 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1591,8 +1590,8 @@ class ArticleTest &lt; ActiveSupport::TestCase
1591 end 1590 end
1592 1591
1593 should 'remove all categorizations when destroyed' do 1592 should 'remove all categorizations when destroyed' do
1594 - art = Article.create!(:name => 'article 1', :profile_id => fast_create(Person).id)  
1595 - cat = Category.create!(:name => 'category 1', :environment_id => Environment.default.id) 1593 + art = create(Article, :name => 'article 1', :profile_id => fast_create(Person).id)
  1594 + cat = create(Category, :name => 'category 1', :environment_id => Environment.default.id)
1596 art.add_category cat 1595 art.add_category cat
1597 art.destroy 1596 art.destroy
1598 assert cat.articles.reload.empty? 1597 assert cat.articles.reload.empty?
@@ -1600,9 +1599,9 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1600,9 +1599,9 @@ class ArticleTest &lt; ActiveSupport::TestCase
1600 1599
1601 should 'show more popular articles' do 1600 should 'show more popular articles' do
1602 Article.destroy_all 1601 Article.destroy_all
1603 - art1 = Article.create!(:name => 'article 1', :profile_id => fast_create(Person).id)  
1604 - art2 = Article.create!(:name => 'article 2', :profile_id => fast_create(Person).id)  
1605 - art3 = Article.create!(:name => 'article 3', :profile_id => fast_create(Person).id) 1602 + art1 = create(Article, :name => 'article 1', :profile_id => fast_create(Person).id)
  1603 + art2 = create(Article, :name => 'article 2', :profile_id => fast_create(Person).id)
  1604 + art3 = create(Article, :name => 'article 3', :profile_id => fast_create(Person).id)
1606 1605
1607 art1.hits = 56; art1.save! 1606 art1.hits = 56; art1.save!
1608 art3.hits = 92; art3.save! 1607 art3.hits = 92; art3.save!
@@ -1612,11 +1611,11 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1612,11 +1611,11 @@ class ArticleTest &lt; ActiveSupport::TestCase
1612 end 1611 end
1613 1612
1614 should 'show if article is public' do 1613 should 'show if article is public' do
1615 - art1 = Article.create!(:name => 'article 1', :profile_id => fast_create(Person).id)  
1616 - art2 = Article.create!(:name => 'article 2', :profile_id => fast_create(Person).id, :advertise => false)  
1617 - art3 = Article.create!(:name => 'article 3', :profile_id => fast_create(Person).id, :published => false)  
1618 - art4 = Article.create!(:name => 'article 4', :profile_id => fast_create(Person, :visible => false).id)  
1619 - art5 = Article.create!(:name => 'article 5', :profile_id => fast_create(Person, :public_profile => false).id) 1614 + art1 = create(Article, :name => 'article 1', :profile_id => fast_create(Person).id)
  1615 + art2 = create(Article, :name => 'article 2', :profile_id => fast_create(Person).id, :advertise => false)
  1616 + art3 = create(Article, :name => 'article 3', :profile_id => fast_create(Person).id, :published => false)
  1617 + art4 = create(Article, :name => 'article 4', :profile_id => fast_create(Person, :visible => false).id)
  1618 + art5 = create(Article, :name => 'article 5', :profile_id => fast_create(Person, :public_profile => false).id)
1620 1619
1621 articles = Article.public 1620 articles = Article.public
1622 assert_includes articles, art1 1621 assert_includes articles, art1
@@ -1633,7 +1632,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1633,7 +1632,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1633 1632
1634 community.add_admin(admin) 1633 community.add_admin(admin)
1635 community.add_member(member) 1634 community.add_member(member)
1636 - a = Article.new(:profile => community) 1635 + a = build(Article, :profile => community)
1637 1636
1638 assert_equal false, a.allow_members_to_edit 1637 assert_equal false, a.allow_members_to_edit
1639 assert_equal false, a.allow_edit?(member) 1638 assert_equal false, a.allow_edit?(member)
@@ -1646,7 +1645,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1646,7 +1645,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1646 1645
1647 community.add_admin(admin) 1646 community.add_admin(admin)
1648 community.add_member(member) 1647 community.add_member(member)
1649 - a = Article.new(:profile => community) 1648 + a = build(Article, :profile => community)
1650 1649
1651 a.allow_members_to_edit = true 1650 a.allow_members_to_edit = true
1652 1651
@@ -1681,20 +1680,20 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1681,20 +1680,20 @@ class ArticleTest &lt; ActiveSupport::TestCase
1681 end 1680 end
1682 1681
1683 should 'store first image in tracked action' do 1682 should 'store first image in tracked action' do
1684 - a = TinyMceArticle.create! :name => 'Tracked Article', :body => '<p>Foo<img src="foo.png" />Bar</p>', :profile_id => profile.id 1683 + a = create TinyMceArticle, :name => 'Tracked Article', :body => '<p>Foo<img src="foo.png" />Bar</p>', :profile_id => profile.id
1685 assert_equal 'foo.png', ActionTracker::Record.last.get_first_image 1684 assert_equal 'foo.png', ActionTracker::Record.last.get_first_image
1686 end 1685 end
1687 1686
1688 should 'be able to have a license' do 1687 should 'be able to have a license' do
1689 - license = License.create!(:name => 'GPLv3', :environment => Environment.default)  
1690 - article = Article.new(:license_id => license.id) 1688 + license = create(License, :name => 'GPLv3', :environment => Environment.default)
  1689 + article = build(Article, :license_id => license.id)
1691 assert_equal license, article.license 1690 assert_equal license, article.license
1692 end 1691 end
1693 1692
1694 should 'update path if parent is changed' do 1693 should 'update path if parent is changed' do
1695 - f1 = Folder.create!(:name => 'Folder 1', :profile => profile)  
1696 - f2 = Folder.create!(:name => 'Folder 2', :profile => profile)  
1697 - article = TinyMceArticle.create!(:name => 'Sample Article', :parent_id => f1.id, :profile => profile) 1694 + f1 = create(Folder, :name => 'Folder 1', :profile => profile)
  1695 + f2 = create(Folder, :name => 'Folder 2', :profile => profile)
  1696 + article = create(TinyMceArticle, :name => 'Sample Article', :parent_id => f1.id, :profile => profile)
1698 assert_equal [f1.path,article.slug].join('/'), article.path 1697 assert_equal [f1.path,article.slug].join('/'), article.path
1699 1698
1700 article.parent = f2 1699 article.parent = f2
@@ -1705,12 +1704,13 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1705,12 +1704,13 @@ class ArticleTest &lt; ActiveSupport::TestCase
1705 article.save! 1704 article.save!
1706 assert_equal article.slug, article.path 1705 assert_equal article.slug, article.path
1707 1706
1708 - article.update_attributes({:parent_id => f2.id}) 1707 + article.parent = f2
  1708 + article.save!
1709 assert_equal [f2.path,article.slug].join('/'), article.path 1709 assert_equal [f2.path,article.slug].join('/'), article.path
1710 end 1710 end
1711 1711
1712 should 'not allow parent as itself' do 1712 should 'not allow parent as itself' do
1713 - article = Article.create!(:name => 'Sample Article', :profile => profile) 1713 + article = create(Article, :name => 'Sample Article', :profile => profile)
1714 article.parent = article 1714 article.parent = article
1715 article.valid? 1715 article.valid?
1716 1716
@@ -1718,9 +1718,9 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1718,9 +1718,9 @@ class ArticleTest &lt; ActiveSupport::TestCase
1718 end 1718 end
1719 1719
1720 should 'not allow cyclical paternity' do 1720 should 'not allow cyclical paternity' do
1721 - a1 = Article.create!(:name => 'Sample Article 1', :profile => profile)  
1722 - a2 = Article.create!(:name => 'Sample Article 2', :profile => profile, :parent => a1)  
1723 - a3 = Article.create!(:name => 'Sample Article 3', :profile => profile, :parent => a2) 1721 + a1 = create(Article, :name => 'Sample Article 1', :profile => profile)
  1722 + a2 = create(Article, :name => 'Sample Article 2', :profile => profile, :parent => a1)
  1723 + a3 = create(Article, :name => 'Sample Article 3', :profile => profile, :parent => a2)
1724 a1.parent = a3 1724 a1.parent = a3
1725 a1.valid? 1725 a1.valid?
1726 1726
@@ -1729,7 +1729,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1729,7 +1729,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1729 1729
1730 should 'set author_name before creating article if there is an author' do 1730 should 'set author_name before creating article if there is an author' do
1731 author = fast_create(Person) 1731 author = fast_create(Person)
1732 - article = Article.create!(:name => 'Test', :profile => profile, :last_changed_by => author) 1732 + article = create(Article, :name => 'Test', :profile => profile, :last_changed_by => author)
1733 assert_equal author.name, article.author_name 1733 assert_equal author.name, article.author_name
1734 1734
1735 author_name = author.name 1735 author_name = author.name
@@ -1740,12 +1740,12 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -1740,12 +1740,12 @@ class ArticleTest &lt; ActiveSupport::TestCase
1740 1740
1741 should "author_id return the author id of the article's author" do 1741 should "author_id return the author id of the article's author" do
1742 author = fast_create(Person) 1742 author = fast_create(Person)
1743 - article = Article.create!(:name => 'Test', :profile => profile, :last_changed_by => author) 1743 + article = create(Article, :name => 'Test', :profile => profile, :last_changed_by => author)
1744 assert_equal author.id, article.author_id 1744 assert_equal author.id, article.author_id
1745 end 1745 end
1746 1746
1747 should "author_id return nil if there is no article's author" do 1747 should "author_id return nil if there is no article's author" do
1748 - article = Article.create!(:name => 'Test', :profile => profile, :last_changed_by => nil) 1748 + article = create(Article, :name => 'Test', :profile => profile, :last_changed_by => nil)
1749 assert_nil article.author_id 1749 assert_nil article.author_id
1750 end 1750 end
1751 1751