Commit e8e43940cf7044876c7076f55afcf419abacad05
1 parent
baa2faf8
Exists in
master
and in
12 other branches
article_test: use profile from #setup
This also sets User.current to avoid random activities failures
Showing
1 changed file
with
35 additions
and
46 deletions
Show diff stats
test/unit/article_test.rb
@@ -7,7 +7,8 @@ class ArticleTest < ActiveSupport::TestCase | @@ -7,7 +7,8 @@ class ArticleTest < ActiveSupport::TestCase | ||
7 | 7 | ||
8 | def setup | 8 | def setup |
9 | ActiveSupport::TestCase::setup | 9 | ActiveSupport::TestCase::setup |
10 | - @profile = create_user('testing').person | 10 | + user = User.current = create_user 'testing' |
11 | + @profile = user.person | ||
11 | end | 12 | end |
12 | attr_reader :profile | 13 | attr_reader :profile |
13 | 14 | ||
@@ -468,14 +469,12 @@ class ArticleTest < ActiveSupport::TestCase | @@ -468,14 +469,12 @@ class ArticleTest < ActiveSupport::TestCase | ||
468 | end | 469 | end |
469 | 470 | ||
470 | should 'say that logged off user cannot see private article' do | 471 | should 'say that logged off user cannot see private article' do |
471 | - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') | ||
472 | article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) | 472 | article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) |
473 | 473 | ||
474 | refute article.display_to?(nil) | 474 | refute article.display_to?(nil) |
475 | end | 475 | end |
476 | 476 | ||
477 | should 'say that not member of profile cannot see private article' do | 477 | should 'say that not member of profile cannot see private article' do |
478 | - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') | ||
479 | article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) | 478 | article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) |
480 | person = create_user('test_user').person | 479 | person = create_user('test_user').person |
481 | 480 | ||
@@ -483,7 +482,6 @@ class ArticleTest < ActiveSupport::TestCase | @@ -483,7 +482,6 @@ class ArticleTest < ActiveSupport::TestCase | ||
483 | end | 482 | end |
484 | 483 | ||
485 | should 'say that member user can not see private article' do | 484 | should 'say that member user can not see private article' do |
486 | - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') | ||
487 | article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false, :show_to_followers => false) | 485 | article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false, :show_to_followers => false) |
488 | person = create_user('test_user').person | 486 | person = create_user('test_user').person |
489 | profile.affiliate(person, Profile::Roles.member(profile.environment.id)) | 487 | profile.affiliate(person, Profile::Roles.member(profile.environment.id)) |
@@ -492,25 +490,23 @@ class ArticleTest < ActiveSupport::TestCase | @@ -492,25 +490,23 @@ class ArticleTest < ActiveSupport::TestCase | ||
492 | end | 490 | end |
493 | 491 | ||
494 | should 'say that profile admin can see private article' do | 492 | should 'say that profile admin can see private article' do |
495 | - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') | 493 | + org = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') |
496 | article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) | 494 | article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) |
497 | - person = create_user('test_user').person | ||
498 | - profile.affiliate(person, Profile::Roles.admin(profile.environment.id)) | 495 | + org.affiliate(profile, Profile::Roles.admin(org.environment.id)) |
499 | 496 | ||
500 | - assert article.display_to?(person) | 497 | + assert article.display_to?(profile) |
501 | end | 498 | end |
502 | 499 | ||
503 | should 'say that profile moderator can see private article' do | 500 | should 'say that profile moderator can see private article' do |
504 | - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') | ||
505 | - article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) | ||
506 | - person = create_user('test_user').person | ||
507 | - profile.affiliate(person, Profile::Roles.moderator(profile.environment.id)) | 501 | + org = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') |
502 | + article = fast_create(Article, :name => 'test article', :profile_id => org.id, :published => false) | ||
503 | + org.affiliate(profile, Profile::Roles.moderator(org.environment.id)) | ||
508 | 504 | ||
509 | - assert article.display_to?(person) | 505 | + assert article.display_to?(profile) |
510 | end | 506 | end |
511 | 507 | ||
512 | should 'show article to non member if article public but profile private' do | 508 | should 'show article to non member if article public but profile private' do |
513 | - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile', :public_profile => false) | 509 | + profile.update public_profile: false |
514 | article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => true) | 510 | article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => true) |
515 | person1 = create_user('test_user1').person | 511 | person1 = create_user('test_user1').person |
516 | profile.affiliate(person1, Profile::Roles.member(profile.environment.id)) | 512 | profile.affiliate(person1, Profile::Roles.member(profile.environment.id)) |
@@ -522,7 +518,6 @@ class ArticleTest < ActiveSupport::TestCase | @@ -522,7 +518,6 @@ class ArticleTest < ActiveSupport::TestCase | ||
522 | end | 518 | end |
523 | 519 | ||
524 | should 'make new article private if created inside a private folder' do | 520 | should 'make new article private if created inside a private folder' do |
525 | - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') | ||
526 | folder = fast_create(Folder, :name => 'my_intranet', :profile_id => profile.id, :published => false) | 521 | folder = fast_create(Folder, :name => 'my_intranet', :profile_id => profile.id, :published => false) |
527 | article = fast_create(Article, :name => 'my private article', :profile_id => profile.id, :parent_id => folder.id) | 522 | article = fast_create(Article, :name => 'my private article', :profile_id => profile.id, :parent_id => folder.id) |
528 | 523 | ||
@@ -530,7 +525,6 @@ class ArticleTest < ActiveSupport::TestCase | @@ -530,7 +525,6 @@ class ArticleTest < ActiveSupport::TestCase | ||
530 | end | 525 | end |
531 | 526 | ||
532 | should 'save as private' do | 527 | should 'save as private' do |
533 | - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') | ||
534 | folder = fast_create(Folder, :name => 'my_intranet', :profile_id => profile.id, :published => false) | 528 | folder = fast_create(Folder, :name => 'my_intranet', :profile_id => profile.id, :published => false) |
535 | article = fast_create(Article, :name => 'my private article') | 529 | article = fast_create(Article, :name => 'my private article') |
536 | article.profile = profile | 530 | article.profile = profile |
@@ -1012,13 +1006,13 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1012,13 +1006,13 @@ class ArticleTest < ActiveSupport::TestCase | ||
1012 | 1006 | ||
1013 | should 'not notify activity by default on create' do | 1007 | should 'not notify activity by default on create' do |
1014 | ActionTracker::Record.delete_all | 1008 | ActionTracker::Record.delete_all |
1015 | - create Article, :name => 'test', :profile_id => fast_create(Profile).id, :published => true | 1009 | + create Article, :name => 'test', :profile_id => profile.id, :published => true |
1016 | assert_equal 0, ActionTracker::Record.count | 1010 | assert_equal 0, ActionTracker::Record.count |
1017 | end | 1011 | end |
1018 | 1012 | ||
1019 | should 'not notify activity by default on update' do | 1013 | should 'not notify activity by default on update' do |
1020 | ActionTracker::Record.delete_all | 1014 | ActionTracker::Record.delete_all |
1021 | - a = create Article, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | 1015 | + a = create Article, :name => 'bar', :profile_id => profile.id, :published => true |
1022 | a.name = 'foo' | 1016 | a.name = 'foo' |
1023 | a.save! | 1017 | a.save! |
1024 | assert_equal 0, ActionTracker::Record.count | 1018 | assert_equal 0, ActionTracker::Record.count |
@@ -1026,13 +1020,13 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1026,13 +1020,13 @@ class ArticleTest < ActiveSupport::TestCase | ||
1026 | 1020 | ||
1027 | should 'not notify activity by default on destroy' do | 1021 | should 'not notify activity by default on destroy' do |
1028 | ActionTracker::Record.delete_all | 1022 | ActionTracker::Record.delete_all |
1029 | - a = create Article, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | 1023 | + a = create Article, :name => 'bar', :profile_id => profile.id, :published => true |
1030 | a.destroy | 1024 | a.destroy |
1031 | assert_equal 0, ActionTracker::Record.count | 1025 | assert_equal 0, ActionTracker::Record.count |
1032 | end | 1026 | end |
1033 | 1027 | ||
1034 | should 'create activity' do | 1028 | should 'create activity' do |
1035 | - a = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true | 1029 | + a = create TextileArticle, :name => 'bar', :profile_id => profile.id, :published => true |
1036 | a.activity.destroy | 1030 | a.activity.destroy |
1037 | assert_nil a.activity | 1031 | assert_nil a.activity |
1038 | 1032 | ||
@@ -1212,10 +1206,9 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1212,10 +1206,9 @@ class ArticleTest < ActiveSupport::TestCase | ||
1212 | end | 1206 | end |
1213 | 1207 | ||
1214 | should 'get article galleries' do | 1208 | should 'get article galleries' do |
1215 | - p = fast_create(Profile) | ||
1216 | - a = fast_create(Article, :profile_id => p.id) | ||
1217 | - g = fast_create(Gallery, :profile_id => p.id) | ||
1218 | - assert_equal [g], p.articles.galleries | 1209 | + a = fast_create(Article, :profile_id => profile.id) |
1210 | + g = fast_create(Gallery, :profile_id => profile.id) | ||
1211 | + assert_equal [g], profile.articles.galleries | ||
1219 | end | 1212 | end |
1220 | 1213 | ||
1221 | should 'has many translations' do | 1214 | should 'has many translations' do |
@@ -1236,7 +1229,7 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1236,7 +1229,7 @@ class ArticleTest < ActiveSupport::TestCase | ||
1236 | end | 1229 | end |
1237 | 1230 | ||
1238 | should 'validate inclusion of language' do | 1231 | should 'validate inclusion of language' do |
1239 | - a = build(Article, :profile_id => fast_create(Profile).id) | 1232 | + a = build(Article, :profile_id => profile.id) |
1240 | a.language = '12' | 1233 | a.language = '12' |
1241 | a.valid? | 1234 | a.valid? |
1242 | assert a.errors[:language.to_s].present? | 1235 | assert a.errors[:language.to_s].present? |
@@ -1268,7 +1261,7 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1268,7 +1261,7 @@ class ArticleTest < ActiveSupport::TestCase | ||
1268 | end | 1261 | end |
1269 | 1262 | ||
1270 | should 'list possible translations' do | 1263 | should 'list possible translations' do |
1271 | - native_article = fast_create(Article, :language => 'pt', :profile_id => fast_create(Profile).id ) | 1264 | + native_article = fast_create(Article, :language => 'pt', :profile_id => profile.id ) |
1272 | article_translation = fast_create(Article, :language => 'en', :translation_of_id => native_article.id) | 1265 | article_translation = fast_create(Article, :language => 'en', :translation_of_id => native_article.id) |
1273 | possible_translations = native_article.possible_translations | 1266 | possible_translations = native_article.possible_translations |
1274 | refute possible_translations.include?('en') | 1267 | refute possible_translations.include?('en') |
@@ -1278,7 +1271,7 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1278,7 +1271,7 @@ class ArticleTest < ActiveSupport::TestCase | ||
1278 | should 'verify if translation is already in use' do | 1271 | should 'verify if translation is already in use' do |
1279 | native_article = fast_create(Article, :language => 'pt') | 1272 | native_article = fast_create(Article, :language => 'pt') |
1280 | article_translation = fast_create(Article, :language => 'en', :translation_of_id => native_article.id) | 1273 | article_translation = fast_create(Article, :language => 'en', :translation_of_id => native_article.id) |
1281 | - a = build(Article, :profile => fast_create(Profile)) | 1274 | + a = build(Article, :profile => profile) |
1282 | a.language = 'en' | 1275 | a.language = 'en' |
1283 | a.translation_of = native_article | 1276 | a.translation_of = native_article |
1284 | a.valid? | 1277 | a.valid? |
@@ -1290,7 +1283,7 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1290,7 +1283,7 @@ class ArticleTest < ActiveSupport::TestCase | ||
1290 | 1283 | ||
1291 | should 'verify if native translation is already in use' do | 1284 | should 'verify if native translation is already in use' do |
1292 | native_article = fast_create(Article, :language => 'pt') | 1285 | native_article = fast_create(Article, :language => 'pt') |
1293 | - a = build(Article, :profile => fast_create(Profile)) | 1286 | + a = build(Article, :profile => profile) |
1294 | a.language = 'pt' | 1287 | a.language = 'pt' |
1295 | a.translation_of = native_article | 1288 | a.translation_of = native_article |
1296 | a.valid? | 1289 | a.valid? |
@@ -1302,7 +1295,7 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1302,7 +1295,7 @@ class ArticleTest < ActiveSupport::TestCase | ||
1302 | 1295 | ||
1303 | should 'translation have a language' do | 1296 | should 'translation have a language' do |
1304 | native_article = fast_create(Article, :language => 'pt') | 1297 | native_article = fast_create(Article, :language => 'pt') |
1305 | - a = build(Article, :profile_id => fast_create(Profile).id) | 1298 | + a = build(Article, :profile_id => profile.id) |
1306 | a.translation_of = native_article | 1299 | a.translation_of = native_article |
1307 | a.valid? | 1300 | a.valid? |
1308 | assert a.errors[:language.to_s].present? | 1301 | assert a.errors[:language.to_s].present? |
@@ -1312,8 +1305,8 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1312,8 +1305,8 @@ class ArticleTest < ActiveSupport::TestCase | ||
1312 | end | 1305 | end |
1313 | 1306 | ||
1314 | should 'native translation have a language' do | 1307 | should 'native translation have a language' do |
1315 | - native_article = fast_create(Article, :profile_id => fast_create(Profile).id ) | ||
1316 | - a = build(Article, :profile_id => fast_create(Profile).id) | 1308 | + native_article = fast_create(Article, :profile_id => profile.id ) |
1309 | + a = build(Article, :profile_id => profile.id) | ||
1317 | a.language = 'en' | 1310 | a.language = 'en' |
1318 | a.translation_of = native_article | 1311 | a.translation_of = native_article |
1319 | a.valid? | 1312 | a.valid? |
@@ -1378,22 +1371,22 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1378,22 +1371,22 @@ class ArticleTest < ActiveSupport::TestCase | ||
1378 | end | 1371 | end |
1379 | 1372 | ||
1380 | should 'get only non translated articles' do | 1373 | should 'get only non translated articles' do |
1381 | - p = fast_create(Profile) | ||
1382 | - native = fast_create(Article, :language => 'pt', :profile_id => p.id) | ||
1383 | - translation = fast_create(Article, :language => 'en', :translation_of_id => native.id, :profile_id => p.id) | ||
1384 | - assert_equal [native], p.articles.native_translations | 1374 | + profile.articles.delete_all |
1375 | + native = fast_create(Article, :language => 'pt', :profile_id => profile.id) | ||
1376 | + translation = fast_create(Article, :language => 'en', :translation_of_id => native.id, :profile_id => profile.id) | ||
1377 | + assert_equal [native], profile.articles.native_translations | ||
1385 | end | 1378 | end |
1386 | 1379 | ||
1387 | should 'not list own language as a possible translation if language has changed' do | 1380 | should 'not list own language as a possible translation if language has changed' do |
1388 | - a = build(Article, :language => 'pt', :profile_id => fast_create(Profile).id) | 1381 | + a = build(Article, :language => 'pt', :profile_id => profile.id) |
1389 | refute a.possible_translations.include?('pt') | 1382 | refute a.possible_translations.include?('pt') |
1390 | - a = fast_create(Article, :language => 'pt', :profile_id => fast_create(Profile).id ) | 1383 | + a = fast_create(Article, :language => 'pt', :profile_id => profile.id ) |
1391 | a.language = 'en' | 1384 | a.language = 'en' |
1392 | refute a.possible_translations.include?('en') | 1385 | refute a.possible_translations.include?('en') |
1393 | end | 1386 | end |
1394 | 1387 | ||
1395 | should 'list own language as a possible translation if language has not changed' do | 1388 | should 'list own language as a possible translation if language has not changed' do |
1396 | - a = fast_create(Article, :language => 'pt', :profile_id => fast_create(Profile).id) | 1389 | + a = fast_create(Article, :language => 'pt', :profile_id => profile.id) |
1397 | assert a.possible_translations.include?('pt') | 1390 | assert a.possible_translations.include?('pt') |
1398 | end | 1391 | end |
1399 | 1392 | ||
@@ -1435,7 +1428,6 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1435,7 +1428,6 @@ class ArticleTest < ActiveSupport::TestCase | ||
1435 | should 'return only folders' do | 1428 | should 'return only folders' do |
1436 | not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle] | 1429 | not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle] |
1437 | folders = [Folder, Blog, Gallery, Forum] | 1430 | folders = [Folder, Blog, Gallery, Forum] |
1438 | - profile = fast_create(Profile) | ||
1439 | 1431 | ||
1440 | not_folders.each do |klass| | 1432 | not_folders.each do |klass| |
1441 | item = fast_create(klass) | 1433 | item = fast_create(klass) |
@@ -1451,7 +1443,6 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1451,7 +1443,6 @@ class ArticleTest < ActiveSupport::TestCase | ||
1451 | should 'return no folders' do | 1443 | should 'return no folders' do |
1452 | not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle] | 1444 | not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle] |
1453 | folders = [Folder, Blog, Gallery, Forum] | 1445 | folders = [Folder, Blog, Gallery, Forum] |
1454 | - profile = fast_create(Profile) | ||
1455 | 1446 | ||
1456 | not_folders.each do |klass| | 1447 | not_folders.each do |klass| |
1457 | item = fast_create(klass) | 1448 | item = fast_create(klass) |
@@ -1611,18 +1602,16 @@ class ArticleTest < ActiveSupport::TestCase | @@ -1611,18 +1602,16 @@ class ArticleTest < ActiveSupport::TestCase | ||
1611 | end | 1602 | end |
1612 | 1603 | ||
1613 | should 'delegate region info to profile' do | 1604 | should 'delegate region info to profile' do |
1614 | - profile = fast_create(Profile) | ||
1615 | - Profile.any_instance.expects(:region) | ||
1616 | - Profile.any_instance.expects(:region_id) | 1605 | + Person.any_instance.expects(:region) |
1606 | + Person.any_instance.expects(:region_id) | ||
1617 | article = fast_create(Article, :profile_id => profile.id) | 1607 | article = fast_create(Article, :profile_id => profile.id) |
1618 | article.region | 1608 | article.region |
1619 | article.region_id | 1609 | article.region_id |
1620 | end | 1610 | end |
1621 | 1611 | ||
1622 | should 'delegate environment info to profile' do | 1612 | should 'delegate environment info to profile' do |
1623 | - profile = fast_create(Profile) | ||
1624 | - Profile.any_instance.expects(:environment) | ||
1625 | - Profile.any_instance.expects(:environment_id) | 1613 | + Person.any_instance.expects(:environment) |
1614 | + Person.any_instance.expects(:environment_id) | ||
1626 | article = fast_create(Article, :profile_id => profile.id) | 1615 | article = fast_create(Article, :profile_id => profile.id) |
1627 | article.environment | 1616 | article.environment |
1628 | article.environment_id | 1617 | article.environment_id |