diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 5204e9e..633ca6b 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -7,7 +7,8 @@ class ArticleTest < ActiveSupport::TestCase def setup ActiveSupport::TestCase::setup - @profile = create_user('testing').person + user = User.current = create_user 'testing' + @profile = user.person end attr_reader :profile @@ -468,14 +469,12 @@ class ArticleTest < ActiveSupport::TestCase end should 'say that logged off user cannot see private article' do - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) refute article.display_to?(nil) end should 'say that not member of profile cannot see private article' do - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) person = create_user('test_user').person @@ -483,7 +482,6 @@ class ArticleTest < ActiveSupport::TestCase end should 'say that member user can not see private article' do - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false, :show_to_followers => false) person = create_user('test_user').person profile.affiliate(person, Profile::Roles.member(profile.environment.id)) @@ -492,25 +490,23 @@ class ArticleTest < ActiveSupport::TestCase end should 'say that profile admin can see private article' do - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') + org = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) - person = create_user('test_user').person - profile.affiliate(person, Profile::Roles.admin(profile.environment.id)) + org.affiliate(profile, Profile::Roles.admin(org.environment.id)) - assert article.display_to?(person) + assert article.display_to?(profile) end should 'say that profile moderator can see private article' do - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') - article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) - person = create_user('test_user').person - profile.affiliate(person, Profile::Roles.moderator(profile.environment.id)) + org = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') + article = fast_create(Article, :name => 'test article', :profile_id => org.id, :published => false) + org.affiliate(profile, Profile::Roles.moderator(org.environment.id)) - assert article.display_to?(person) + assert article.display_to?(profile) end should 'show article to non member if article public but profile private' do - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile', :public_profile => false) + profile.update public_profile: false article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => true) person1 = create_user('test_user1').person profile.affiliate(person1, Profile::Roles.member(profile.environment.id)) @@ -522,7 +518,6 @@ class ArticleTest < ActiveSupport::TestCase end should 'make new article private if created inside a private folder' do - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') folder = fast_create(Folder, :name => 'my_intranet', :profile_id => profile.id, :published => false) article = fast_create(Article, :name => 'my private article', :profile_id => profile.id, :parent_id => folder.id) @@ -530,7 +525,6 @@ class ArticleTest < ActiveSupport::TestCase end should 'save as private' do - profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') folder = fast_create(Folder, :name => 'my_intranet', :profile_id => profile.id, :published => false) article = fast_create(Article, :name => 'my private article') article.profile = profile @@ -1012,13 +1006,13 @@ class ArticleTest < ActiveSupport::TestCase should 'not notify activity by default on create' do ActionTracker::Record.delete_all - create Article, :name => 'test', :profile_id => fast_create(Profile).id, :published => true + create Article, :name => 'test', :profile_id => profile.id, :published => true assert_equal 0, ActionTracker::Record.count end should 'not notify activity by default on update' do ActionTracker::Record.delete_all - a = create Article, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true + a = create Article, :name => 'bar', :profile_id => profile.id, :published => true a.name = 'foo' a.save! assert_equal 0, ActionTracker::Record.count @@ -1026,13 +1020,13 @@ class ArticleTest < ActiveSupport::TestCase should 'not notify activity by default on destroy' do ActionTracker::Record.delete_all - a = create Article, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true + a = create Article, :name => 'bar', :profile_id => profile.id, :published => true a.destroy assert_equal 0, ActionTracker::Record.count end should 'create activity' do - a = create TextileArticle, :name => 'bar', :profile_id => fast_create(Profile).id, :published => true + a = create TextileArticle, :name => 'bar', :profile_id => profile.id, :published => true a.activity.destroy assert_nil a.activity @@ -1212,10 +1206,9 @@ class ArticleTest < ActiveSupport::TestCase end should 'get article galleries' do - p = fast_create(Profile) - a = fast_create(Article, :profile_id => p.id) - g = fast_create(Gallery, :profile_id => p.id) - assert_equal [g], p.articles.galleries + a = fast_create(Article, :profile_id => profile.id) + g = fast_create(Gallery, :profile_id => profile.id) + assert_equal [g], profile.articles.galleries end should 'has many translations' do @@ -1236,7 +1229,7 @@ class ArticleTest < ActiveSupport::TestCase end should 'validate inclusion of language' do - a = build(Article, :profile_id => fast_create(Profile).id) + a = build(Article, :profile_id => profile.id) a.language = '12' a.valid? assert a.errors[:language.to_s].present? @@ -1268,7 +1261,7 @@ class ArticleTest < ActiveSupport::TestCase end should 'list possible translations' do - native_article = fast_create(Article, :language => 'pt', :profile_id => fast_create(Profile).id ) + native_article = fast_create(Article, :language => 'pt', :profile_id => profile.id ) article_translation = fast_create(Article, :language => 'en', :translation_of_id => native_article.id) possible_translations = native_article.possible_translations refute possible_translations.include?('en') @@ -1278,7 +1271,7 @@ class ArticleTest < ActiveSupport::TestCase should 'verify if translation is already in use' do native_article = fast_create(Article, :language => 'pt') article_translation = fast_create(Article, :language => 'en', :translation_of_id => native_article.id) - a = build(Article, :profile => fast_create(Profile)) + a = build(Article, :profile => profile) a.language = 'en' a.translation_of = native_article a.valid? @@ -1290,7 +1283,7 @@ class ArticleTest < ActiveSupport::TestCase should 'verify if native translation is already in use' do native_article = fast_create(Article, :language => 'pt') - a = build(Article, :profile => fast_create(Profile)) + a = build(Article, :profile => profile) a.language = 'pt' a.translation_of = native_article a.valid? @@ -1302,7 +1295,7 @@ class ArticleTest < ActiveSupport::TestCase should 'translation have a language' do native_article = fast_create(Article, :language => 'pt') - a = build(Article, :profile_id => fast_create(Profile).id) + a = build(Article, :profile_id => profile.id) a.translation_of = native_article a.valid? assert a.errors[:language.to_s].present? @@ -1312,8 +1305,8 @@ class ArticleTest < ActiveSupport::TestCase end should 'native translation have a language' do - native_article = fast_create(Article, :profile_id => fast_create(Profile).id ) - a = build(Article, :profile_id => fast_create(Profile).id) + native_article = fast_create(Article, :profile_id => profile.id ) + a = build(Article, :profile_id => profile.id) a.language = 'en' a.translation_of = native_article a.valid? @@ -1378,22 +1371,22 @@ class ArticleTest < ActiveSupport::TestCase end should 'get only non translated articles' do - p = fast_create(Profile) - native = fast_create(Article, :language => 'pt', :profile_id => p.id) - translation = fast_create(Article, :language => 'en', :translation_of_id => native.id, :profile_id => p.id) - assert_equal [native], p.articles.native_translations + profile.articles.delete_all + native = fast_create(Article, :language => 'pt', :profile_id => profile.id) + translation = fast_create(Article, :language => 'en', :translation_of_id => native.id, :profile_id => profile.id) + assert_equal [native], profile.articles.native_translations end should 'not list own language as a possible translation if language has changed' do - a = build(Article, :language => 'pt', :profile_id => fast_create(Profile).id) + a = build(Article, :language => 'pt', :profile_id => profile.id) refute a.possible_translations.include?('pt') - a = fast_create(Article, :language => 'pt', :profile_id => fast_create(Profile).id ) + a = fast_create(Article, :language => 'pt', :profile_id => profile.id ) a.language = 'en' refute a.possible_translations.include?('en') end should 'list own language as a possible translation if language has not changed' do - a = fast_create(Article, :language => 'pt', :profile_id => fast_create(Profile).id) + a = fast_create(Article, :language => 'pt', :profile_id => profile.id) assert a.possible_translations.include?('pt') end @@ -1435,7 +1428,6 @@ class ArticleTest < ActiveSupport::TestCase should 'return only folders' do not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle] folders = [Folder, Blog, Gallery, Forum] - profile = fast_create(Profile) not_folders.each do |klass| item = fast_create(klass) @@ -1451,7 +1443,6 @@ class ArticleTest < ActiveSupport::TestCase should 'return no folders' do not_folders = [RssFeed, TinyMceArticle, Event, TextileArticle] folders = [Folder, Blog, Gallery, Forum] - profile = fast_create(Profile) not_folders.each do |klass| item = fast_create(klass) @@ -1611,18 +1602,16 @@ class ArticleTest < ActiveSupport::TestCase end should 'delegate region info to profile' do - profile = fast_create(Profile) - Profile.any_instance.expects(:region) - Profile.any_instance.expects(:region_id) + Person.any_instance.expects(:region) + Person.any_instance.expects(:region_id) article = fast_create(Article, :profile_id => profile.id) article.region article.region_id end should 'delegate environment info to profile' do - profile = fast_create(Profile) - Profile.any_instance.expects(:environment) - Profile.any_instance.expects(:environment_id) + Person.any_instance.expects(:environment) + Person.any_instance.expects(:environment_id) article = fast_create(Article, :profile_id => profile.id) article.environment article.environment_id -- libgit2 0.21.2