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 | |
8 | 8 | def setup |
9 | 9 | ActiveSupport::TestCase::setup |
10 | - @profile = create_user('testing').person | |
10 | + user = User.current = create_user 'testing' | |
11 | + @profile = user.person | |
11 | 12 | end |
12 | 13 | attr_reader :profile |
13 | 14 | |
... | ... | @@ -468,14 +469,12 @@ class ArticleTest < ActiveSupport::TestCase |
468 | 469 | end |
469 | 470 | |
470 | 471 | should 'say that logged off user cannot see private article' do |
471 | - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') | |
472 | 472 | article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) |
473 | 473 | |
474 | 474 | refute article.display_to?(nil) |
475 | 475 | end |
476 | 476 | |
477 | 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 | 478 | article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) |
480 | 479 | person = create_user('test_user').person |
481 | 480 | |
... | ... | @@ -483,7 +482,6 @@ class ArticleTest < ActiveSupport::TestCase |
483 | 482 | end |
484 | 483 | |
485 | 484 | should 'say that member user can not see private article' do |
486 | - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') | |
487 | 485 | article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false, :show_to_followers => false) |
488 | 486 | person = create_user('test_user').person |
489 | 487 | profile.affiliate(person, Profile::Roles.member(profile.environment.id)) |
... | ... | @@ -492,25 +490,23 @@ class ArticleTest < ActiveSupport::TestCase |
492 | 490 | end |
493 | 491 | |
494 | 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 | 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 | 498 | end |
502 | 499 | |
503 | 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 | 506 | end |
511 | 507 | |
512 | 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 | 510 | article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => true) |
515 | 511 | person1 = create_user('test_user1').person |
516 | 512 | profile.affiliate(person1, Profile::Roles.member(profile.environment.id)) |
... | ... | @@ -522,7 +518,6 @@ class ArticleTest < ActiveSupport::TestCase |
522 | 518 | end |
523 | 519 | |
524 | 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 | 521 | folder = fast_create(Folder, :name => 'my_intranet', :profile_id => profile.id, :published => false) |
527 | 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 | 525 | end |
531 | 526 | |
532 | 527 | should 'save as private' do |
533 | - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') | |
534 | 528 | folder = fast_create(Folder, :name => 'my_intranet', :profile_id => profile.id, :published => false) |
535 | 529 | article = fast_create(Article, :name => 'my private article') |
536 | 530 | article.profile = profile |
... | ... | @@ -1012,13 +1006,13 @@ class ArticleTest < ActiveSupport::TestCase |
1012 | 1006 | |
1013 | 1007 | should 'not notify activity by default on create' do |
1014 | 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 | 1010 | assert_equal 0, ActionTracker::Record.count |
1017 | 1011 | end |
1018 | 1012 | |
1019 | 1013 | should 'not notify activity by default on update' do |
1020 | 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 | 1016 | a.name = 'foo' |
1023 | 1017 | a.save! |
1024 | 1018 | assert_equal 0, ActionTracker::Record.count |
... | ... | @@ -1026,13 +1020,13 @@ class ArticleTest < ActiveSupport::TestCase |
1026 | 1020 | |
1027 | 1021 | should 'not notify activity by default on destroy' do |
1028 | 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 | 1024 | a.destroy |
1031 | 1025 | assert_equal 0, ActionTracker::Record.count |
1032 | 1026 | end |
1033 | 1027 | |
1034 | 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 | 1030 | a.activity.destroy |
1037 | 1031 | assert_nil a.activity |
1038 | 1032 | |
... | ... | @@ -1212,10 +1206,9 @@ class ArticleTest < ActiveSupport::TestCase |
1212 | 1206 | end |
1213 | 1207 | |
1214 | 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 | 1212 | end |
1220 | 1213 | |
1221 | 1214 | should 'has many translations' do |
... | ... | @@ -1236,7 +1229,7 @@ class ArticleTest < ActiveSupport::TestCase |
1236 | 1229 | end |
1237 | 1230 | |
1238 | 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 | 1233 | a.language = '12' |
1241 | 1234 | a.valid? |
1242 | 1235 | assert a.errors[:language.to_s].present? |
... | ... | @@ -1268,7 +1261,7 @@ class ArticleTest < ActiveSupport::TestCase |
1268 | 1261 | end |
1269 | 1262 | |
1270 | 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 | 1265 | article_translation = fast_create(Article, :language => 'en', :translation_of_id => native_article.id) |
1273 | 1266 | possible_translations = native_article.possible_translations |
1274 | 1267 | refute possible_translations.include?('en') |
... | ... | @@ -1278,7 +1271,7 @@ class ArticleTest < ActiveSupport::TestCase |
1278 | 1271 | should 'verify if translation is already in use' do |
1279 | 1272 | native_article = fast_create(Article, :language => 'pt') |
1280 | 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 | 1275 | a.language = 'en' |
1283 | 1276 | a.translation_of = native_article |
1284 | 1277 | a.valid? |
... | ... | @@ -1290,7 +1283,7 @@ class ArticleTest < ActiveSupport::TestCase |
1290 | 1283 | |
1291 | 1284 | should 'verify if native translation is already in use' do |
1292 | 1285 | native_article = fast_create(Article, :language => 'pt') |
1293 | - a = build(Article, :profile => fast_create(Profile)) | |
1286 | + a = build(Article, :profile => profile) | |
1294 | 1287 | a.language = 'pt' |
1295 | 1288 | a.translation_of = native_article |
1296 | 1289 | a.valid? |
... | ... | @@ -1302,7 +1295,7 @@ class ArticleTest < ActiveSupport::TestCase |
1302 | 1295 | |
1303 | 1296 | should 'translation have a language' do |
1304 | 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 | 1299 | a.translation_of = native_article |
1307 | 1300 | a.valid? |
1308 | 1301 | assert a.errors[:language.to_s].present? |
... | ... | @@ -1312,8 +1305,8 @@ class ArticleTest < ActiveSupport::TestCase |
1312 | 1305 | end |
1313 | 1306 | |
1314 | 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 | 1310 | a.language = 'en' |
1318 | 1311 | a.translation_of = native_article |
1319 | 1312 | a.valid? |
... | ... | @@ -1378,22 +1371,22 @@ class ArticleTest < ActiveSupport::TestCase |
1378 | 1371 | end |
1379 | 1372 | |
1380 | 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 | 1378 | end |
1386 | 1379 | |
1387 | 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 | 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 | 1384 | a.language = 'en' |
1392 | 1385 | refute a.possible_translations.include?('en') |
1393 | 1386 | end |
1394 | 1387 | |
1395 | 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 | 1390 | assert a.possible_translations.include?('pt') |
1398 | 1391 | end |
1399 | 1392 | |
... | ... | @@ -1435,7 +1428,6 @@ class ArticleTest < ActiveSupport::TestCase |
1435 | 1428 | should 'return only folders' do |
1436 | 1429 | not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle] |
1437 | 1430 | folders = [Folder, Blog, Gallery, Forum] |
1438 | - profile = fast_create(Profile) | |
1439 | 1431 | |
1440 | 1432 | not_folders.each do |klass| |
1441 | 1433 | item = fast_create(klass) |
... | ... | @@ -1451,7 +1443,6 @@ class ArticleTest < ActiveSupport::TestCase |
1451 | 1443 | should 'return no folders' do |
1452 | 1444 | not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle] |
1453 | 1445 | folders = [Folder, Blog, Gallery, Forum] |
1454 | - profile = fast_create(Profile) | |
1455 | 1446 | |
1456 | 1447 | not_folders.each do |klass| |
1457 | 1448 | item = fast_create(klass) |
... | ... | @@ -1611,18 +1602,16 @@ class ArticleTest < ActiveSupport::TestCase |
1611 | 1602 | end |
1612 | 1603 | |
1613 | 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 | 1607 | article = fast_create(Article, :profile_id => profile.id) |
1618 | 1608 | article.region |
1619 | 1609 | article.region_id |
1620 | 1610 | end |
1621 | 1611 | |
1622 | 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 | 1615 | article = fast_create(Article, :profile_id => profile.id) |
1627 | 1616 | article.environment |
1628 | 1617 | article.environment_id | ... | ... |