Commit 2fc52fa335584d59ce6b4f57adfe16b713cf80e9
1 parent
b376dedb
Exists in
master
and in
28 other branches
[postgres-tests] Avoiding database retrieve order assumptions from article tests
Showing
1 changed file
with
24 additions
and
14 deletions
Show diff stats
test/unit/article_test.rb
| ... | ... | @@ -327,16 +327,15 @@ class ArticleTest < ActiveSupport::TestCase |
| 327 | 327 | |
| 328 | 328 | should 'list most commented articles' do |
| 329 | 329 | Article.delete_all |
| 330 | - (1..4).each do |n| | |
| 331 | - create(TextileArticle, :name => "art #{n}", :profile_id => profile.id) | |
| 332 | - end | |
| 333 | - first_article = profile.articles.first | |
| 334 | - 2.times { Comment.create(:title => 'test', :body => 'asdsad', :author => profile, :source => first_article).save! } | |
| 330 | + a1 = create(TextileArticle, :name => "art 1", :profile_id => profile.id) | |
| 331 | + a2 = create(TextileArticle, :name => "art 2", :profile_id => profile.id) | |
| 332 | + a3 = create(TextileArticle, :name => "art 3", :profile_id => profile.id) | |
| 333 | + | |
| 334 | + 2.times { Comment.create(:title => 'test', :body => 'asdsad', :author => profile, :source => a2).save! } | |
| 335 | + 4.times { Comment.create(:title => 'test', :body => 'asdsad', :author => profile, :source => a3).save! } | |
| 335 | 336 | |
| 336 | - last_article = profile.articles.last | |
| 337 | - 4.times { Comment.create(:title => 'test', :body => 'asdsad', :author => profile, :source => last_article).save! } | |
| 338 | 337 | # should respect the order (more commented comes first) |
| 339 | - assert_equal [last_article, first_article], profile.articles.most_commented(2) | |
| 338 | + assert_equal [a3, a2, a1], profile.articles.most_commented(3) | |
| 340 | 339 | end |
| 341 | 340 | |
| 342 | 341 | should 'identify itself as a non-folder' do |
| ... | ... | @@ -434,8 +433,15 @@ class ArticleTest < ActiveSupport::TestCase |
| 434 | 433 | owner = create_user('testuser').person |
| 435 | 434 | art = owner.articles.create!(:name => 'ytest') |
| 436 | 435 | art.category_ids = [c2,c3,c3].map(&:id) |
| 437 | - assert_equal [c2, c3], art.categories(true) | |
| 438 | - assert_equal [c2, c1, c3], art.categories_including_virtual(true) | |
| 436 | + | |
| 437 | + categories = art.categories(true) | |
| 438 | + categories_including_virtual = art.categories_including_virtual(true) | |
| 439 | + assert_not_includes categories, c1 | |
| 440 | + assert_includes categories, c2 | |
| 441 | + assert_includes categories, c3 | |
| 442 | + assert_includes categories_including_virtual, c1 | |
| 443 | + assert_includes categories_including_virtual, c2 | |
| 444 | + assert_includes categories_including_virtual, c3 | |
| 439 | 445 | end |
| 440 | 446 | |
| 441 | 447 | should 'not accept Product category as category' do |
| ... | ... | @@ -1290,11 +1296,15 @@ class ArticleTest < ActiveSupport::TestCase |
| 1290 | 1296 | |
| 1291 | 1297 | should 'rotate translations when root article is destroyed' do |
| 1292 | 1298 | native_article = fast_create(Article, :language => 'pt', :profile_id => @profile.id) |
| 1293 | - translation1 = fast_create(Article, :language => 'en', :translation_of_id => native_article.id, :profile_id => @profile.id) | |
| 1294 | - translation2 = fast_create(Article, :language => 'es', :translation_of_id => native_article.id, :profile_id => @profile.id) | |
| 1299 | + fast_create(Article, :language => 'en', :translation_of_id => native_article.id, :profile_id => @profile.id) | |
| 1300 | + fast_create(Article, :language => 'es', :translation_of_id => native_article.id, :profile_id => @profile.id) | |
| 1301 | + | |
| 1302 | + new_root = native_article.translations.first | |
| 1303 | + child = (native_article.translations - [new_root]).first | |
| 1295 | 1304 | native_article.destroy |
| 1296 | - assert translation1.translation_of.nil? | |
| 1297 | - assert translation1.translations.include?(translation2) | |
| 1305 | + | |
| 1306 | + assert new_root.translation_of.nil? | |
| 1307 | + assert new_root.translations.include?(child) | |
| 1298 | 1308 | end |
| 1299 | 1309 | |
| 1300 | 1310 | should 'rotate one translation when root article is destroyed' do | ... | ... |