diff --git a/test/factories.rb b/test/factories.rb index 0cb2886..c6cfe85 100644 --- a/test/factories.rb +++ b/test/factories.rb @@ -220,6 +220,11 @@ module Noosfero::Factory { :name => name, :slug => name.to_slug, :path => name.to_slug } end + alias :defaults_for_text_article :defaults_for_article + alias :defaults_for_textile_article :defaults_for_article + alias :defaults_for_tiny_mce_article :defaults_for_article + alias :defaults_for_rss_feed :defaults_for_article + ############################################### # Folder ############################################### @@ -249,7 +254,8 @@ module Noosfero::Factory # Blog ############################################### def defaults_for_blog - { :name => 'My blog ' + factory_num_seq.to_s } + name = 'My blog ' + factory_num_seq.to_s + { :name => name, :slug => name.to_slug } end def create_blog @@ -289,12 +295,11 @@ module Noosfero::Factory # Category ############################################### def defaults_for_category - { :environment_id => Environment.default.id, :name => 'category' + factory_num_seq.to_s } + name = 'category' + factory_num_seq.to_s + { :environment_id => 1, :name => name, :slug => name.to_slug, :path => name.to_slug } end - def defaults_for_region - defaults_for_category - end + alias :defaults_for_region :defaults_for_category ############################################### # Box @@ -303,4 +308,23 @@ module Noosfero::Factory { } end + ############################################### + # Block + ############################################### + def defaults_for_block + { } + end + + ############################################### + # Task + ############################################### + def defaults_for_task + { :code => "task_for_test_#{factory_num_seq.to_s}" } + end + + alias :defaults_for_add_friend :defaults_for_task + alias :defaults_for_add_member :defaults_for_task + alias :defaults_for_create_community :defaults_for_task + alias :defaults_for_email_activation :defaults_for_task + end diff --git a/test/unit/acts_as_filesystem_test.rb b/test/unit/acts_as_filesystem_test.rb index 82739f1..2e7a2f9 100644 --- a/test/unit/acts_as_filesystem_test.rb +++ b/test/unit/acts_as_filesystem_test.rb @@ -75,9 +75,9 @@ class ActsAsFilesystemTest < Test::Unit::TestCase should 'be able to list text articles that are children of a folder' do profile = create_user('testinguser').person - folder = Folder.create!(:name => 'folder', :profile => profile) - article1 = Article.create(:name => 'article 1', :profile => profile, :parent => folder) - article2 = Article.create(:name => 'article 2', :profile => profile, :parent => folder) + folder = fast_create(Folder, :name => 'folder', :profile_id => profile.id) + article1 = Article.create!(:name => 'article 1', :profile => profile, :parent => folder) + article2 = Article.create!(:name => 'article 2', :profile => profile, :parent => folder) folder.reload assert_equal [folder, article1, article2], folder.map_traversal diff --git a/test/unit/acts_as_having_boxes.rb b/test/unit/acts_as_having_boxes.rb deleted file mode 100644 index 0df9959..0000000 --- a/test/unit/acts_as_having_boxes.rb +++ /dev/null @@ -1,16 +0,0 @@ -require File.dirname(__FILE__) + '/../test_helper' - -class ActsAsHavingBoxesTest < Test::Unit::TestCase - - should 'be able to find blocks by id' do - env = Environment.create!(:name => 'my test environment') - env.boxes.destroy_all - - env.boxes << Box.new - block = Block.new - env.boxes.first.blocks << block - - assert_equal block, env.blocks.find(block.id) - end - -end diff --git a/test/unit/acts_as_having_boxes_test.rb b/test/unit/acts_as_having_boxes_test.rb new file mode 100644 index 0000000..e9138a4 --- /dev/null +++ b/test/unit/acts_as_having_boxes_test.rb @@ -0,0 +1,15 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ActsAsHavingBoxesTest < Test::Unit::TestCase + + should 'be able to find blocks by id' do + env = fast_create(Environment, :name => 'An environment without blocks') + + env.boxes << Box.new + block = Block.new + env.boxes.first.blocks << block + + assert_equal block, env.blocks.find(block.id) + end + +end diff --git a/test/unit/add_friend_test.rb b/test/unit/add_friend_test.rb index 5c80d1e..956d2ba 100644 --- a/test/unit/add_friend_test.rb +++ b/test/unit/add_friend_test.rb @@ -10,7 +10,7 @@ class AddFriendTest < ActiveSupport::TestCase p1 = create_user('testuser1').person p2 = create_user('testuser2').person - task = AddFriend.create!(:person => p1, :friend => p2) + task = fast_create(AddFriend, :requestor_id => p1.id, :target_id => p2.id, :target_type => 'Person') assert_difference Friendship, :count, 2 do task.finish @@ -26,7 +26,10 @@ class AddFriendTest < ActiveSupport::TestCase p1 = create_user('testuser1').person p2 = create_user('testuser2').person - task = AddFriend.create!(:person => p1, :group_for_person => 'friend1', :friend => p2, :group_for_friend => 'friend2') + task = fast_create(AddFriend, :requestor_id => p1, :target_id => p2.id, :target_type => 'Person') + task.group_for_person = 'friend1' + task.group_for_friend = 'friend2' + assert task.save assert_difference Friendship, :count, 2 do task.finish @@ -72,7 +75,7 @@ class AddFriendTest < ActiveSupport::TestCase p1 = create_user('testuser1').person p2 = create_user('testuser2').person - task = AddFriend.create!(:person => p1, :friend => p2) + task = fast_create(AddFriend, :requestor_id => p1.id, :target_id => p2.id) assert_equal 'testuser1 wants to be your friend.', task.description end @@ -85,7 +88,7 @@ class AddFriendTest < ActiveSupport::TestCase should 'not add friend twice' do p1 = create_user('testuser1').person p2 = create_user('testuser2').person - AddFriend.create!(:person => p1, :friend => p2) + fast_create(AddFriend, :requestor_id => p1.id, :target_id => p2.id) assert_raise ActiveRecord::RecordInvalid do AddFriend.create!(:person => p1, :friend => p2) end diff --git a/test/unit/add_member_test.rb b/test/unit/add_member_test.rb index 6e5f482..fa363e9 100644 --- a/test/unit/add_member_test.rb +++ b/test/unit/add_member_test.rb @@ -8,9 +8,10 @@ class AddMemberTest < ActiveSupport::TestCase should 'actually add memberships when confirmed' do p = create_user('testuser1').person - c = Community.create!(:name => 'closed community', :closed => true) + c = fast_create(Community, :name => 'closed community') + c.update_attribute(:closed, true) TaskMailer.stubs(:deliver_target_notification) - task = AddMember.create!(:person => p, :organization => c) + task = fast_create(AddMember, :requestor_id => p.id, :target_id => c.id, :target_type => 'Community') assert_difference c, :members, [p] do task.finish c.reload @@ -41,7 +42,8 @@ class AddMemberTest < ActiveSupport::TestCase should 'send e-mails' do p = create_user('testuser1').person - c = Community.create!(:name => 'closed community', :closed => true) + c = fast_create(Community, :name => 'closed community') + c.update_attribute(:closed, true) TaskMailer.expects(:deliver_target_notification).at_least_once @@ -50,11 +52,12 @@ class AddMemberTest < ActiveSupport::TestCase should 'provide proper description' do p = create_user('testuser1').person - c = Community.create!(:name => 'closed community', :closed => true) + c = fast_create(Community, :name => 'closed community') + c.update_attribute(:closed, true) TaskMailer.stubs(:deliver_target_notification) - task = AddMember.create!(:person => p, :organization => c) + task = fast_create(AddMember, :requestor_id => p.id, :target_id => c.id, :target_type => 'Community') assert_equal 'testuser1 wants to be a member of "closed community".', task.description end @@ -66,7 +69,7 @@ class AddMemberTest < ActiveSupport::TestCase should 'have roles' do p = create_user('testuser1').person - c = Community.create!(:name => 'community_test') + c = fast_create(Community, :name => 'community_test') TaskMailer.stubs(:deliver_target_notification) task = AddMember.create!(:roles => [1,2,3], :person => p, :organization => c) assert_equal [1,2,3], task.roles @@ -74,7 +77,7 @@ class AddMemberTest < ActiveSupport::TestCase should 'put member with the right roles' do p = create_user('testuser1').person - c = Community.create!(:name => 'community_test') + c = fast_create(Community, :name => 'community_test') roles = [Profile::Roles.member(c.environment.id), Profile::Roles.admin(c.environment.id)] TaskMailer.stubs(:deliver_target_notification) @@ -97,7 +100,7 @@ class AddMemberTest < ActiveSupport::TestCase should 'ignore roles with id zero' do p = create_user('testuser1').person - c = Community.create!(:name => 'community_test') + c = fast_create(Community, :name => 'community_test') role = Profile::Roles.member(c.environment.id) TaskMailer.stubs(:deliver_target_notification) diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb index 9dc0cfd..0d203d3 100644 --- a/test/unit/application_helper_test.rb +++ b/test/unit/application_helper_test.rb @@ -98,36 +98,11 @@ class ApplicationHelperTest < Test::Unit::TestCase should 'rolename for' do person = create_user('usertest').person - community = Community.create!(:name => 'new community', :identifier => 'new-community', :environment => Environment.default) + community = fast_create(Community, :name => 'new community', :identifier => 'new-community', :environment_id => Environment.default.id) community.add_member(person) assert_equal 'Profile Member', rolename_for(person, community) end - should 'display categories' do - # FIXME implement this test!!! - assert true - #category = Category.create!(:name => 'parent category for testing', :environment_id => Environment.default) - #child = Category.create!(:name => 'child category for testing', :environment => Environment.default, :display_in_menu => true, :parent => category) - #owner = create_user('testuser').person - #@article = owner.articles.create!(:name => 'ytest') - #@article.add_category(category) - #expects(:environment).returns(Environment.default) - #result = select_categories(:article) - #assert_match /parent category/, result - end - - should 'not display categories if has no child' do - # FIXME implement this test!!! - assert true - #category = Category.create!(:name => 'parent category for testing', :environment_id => Environment.default) - #owner = create_user('testuser').person - #@article = owner.articles.create!(:name => 'ytest') - #@article.add_category(category) - #expects(:environment).returns(Environment.default) - #result = select_categories(:article) - #assert_no_match /parent category/, result - end - should 'get theme from environment by default' do @environment = mock @environment.stubs(:theme).returns('my-environment-theme') @@ -229,7 +204,7 @@ class ApplicationHelperTest < Test::Unit::TestCase end should 'return nil if disable_categories is enabled' do - env = Environment.create!(:name => 'env test') + env = fast_create(Environment, :name => 'env test') stubs(:environment).returns(env) assert_not_nil env env.enable(:disable_categories) @@ -263,14 +238,14 @@ class ApplicationHelperTest < Test::Unit::TestCase end should 'not draw sex icon when disabled in the environment' do - env = Environment.create!(:name => 'env test') + env = fast_create(Environment, :name => 'env test') env.expects(:enabled?).with('disable_gender_icon').returns(true) stubs(:environment).returns(env) assert_equal '', profile_sex_icon(Person.new(:sex => 'male')) end should 'display field on signup' do - env = Environment.create!(:name => 'env test') + env = fast_create(Environment, :name => 'env test') stubs(:environment).returns(env) controller = mock @@ -283,7 +258,7 @@ class ApplicationHelperTest < Test::Unit::TestCase end should 'not display field on signup' do - env = Environment.create!(:name => 'env test') + env = fast_create(Environment, :name => 'env test') stubs(:environment).returns(env) controller = mock @@ -296,7 +271,7 @@ class ApplicationHelperTest < Test::Unit::TestCase end should 'display active fields' do - env = Environment.create!(:name => 'env test') + env = fast_create(Environment, :name => 'env test') stubs(:environment).returns(env) controller = mock @@ -309,7 +284,7 @@ class ApplicationHelperTest < Test::Unit::TestCase end should 'not display active fields' do - env = Environment.create!(:name => 'env test') + env = fast_create(Environment, :name => 'env test') stubs(:environment).returns(env) controller = mock @@ -322,7 +297,7 @@ class ApplicationHelperTest < Test::Unit::TestCase end should 'display required fields' do - env = Environment.create!(:name => 'env test') + env = fast_create(Environment, :name => 'env test') stubs(:environment).returns(env) controller = mock @@ -380,7 +355,7 @@ class ApplicationHelperTest < Test::Unit::TestCase e.stubs(:enabled?).with(:join_community_popup).returns(true) stubs(:environment).returns(e) - c = Community.create(:name => 'test_comm', :identifier => 'test_comm') + c = fast_create(Community, :name => 'test_comm', :identifier => 'test_comm') stubs(:profile).returns(c) stubs(:logged_in?).returns(false) assert ! ask_to_join? @@ -393,7 +368,7 @@ class ApplicationHelperTest < Test::Unit::TestCase e.stubs(:enabled?).with(:join_community_popup).returns(true) stubs(:environment).returns(e) - c = Community.create(:name => 'test_comm', :identifier => 'test_comm') + c = fast_create(Community, :name => 'test_comm', :identifier => 'test_comm') stubs(:profile).returns(c) stubs(:logged_in?).returns(false) assert ask_to_join? @@ -406,7 +381,7 @@ class ApplicationHelperTest < Test::Unit::TestCase e.stubs(:enabled?).with(:join_community_popup).returns(true) stubs(:environment).returns(e) - c = Community.create(:name => 'test_comm', :identifier => 'test_comm') + c = fast_create(Community, :name => 'test_comm', :identifier => 'test_comm') stubs(:profile).returns(c) stubs(:logged_in?).returns(true) p = create_user('test_user').person @@ -422,7 +397,7 @@ class ApplicationHelperTest < Test::Unit::TestCase e = Environment.default e.stubs(:enabled?).with(:join_community_popup).returns(true) stubs(:environment).returns(e) - c = Community.create(:name => 'test_comm', :identifier => 'test_comm') + c = fast_create(Community, :name => 'test_comm', :identifier => 'test_comm') stubs(:profile).returns(c) stubs(:logged_in?).returns(true) p = create_user('test_user').person @@ -438,7 +413,7 @@ class ApplicationHelperTest < Test::Unit::TestCase e = Environment.default e.stubs(:enabled?).with(:join_community_popup).returns(false) stubs(:environment).returns(e) - c = Community.create(:name => 'test_comm', :identifier => 'test_comm') + c = fast_create(Community, :name => 'test_comm', :identifier => 'test_comm') stubs(:profile).returns(c) stubs(:logged_in?).returns(false) assert !ask_to_join? @@ -450,7 +425,7 @@ class ApplicationHelperTest < Test::Unit::TestCase e = Environment.default e.stubs(:enabled?).with(:join_community_popup).returns(false) stubs(:environment).returns(e) - c = Community.create(:name => 'test_comm', :identifier => 'test_comm') + c = fast_create(Community, :name => 'test_comm', :identifier => 'test_comm') stubs(:profile).returns(c) stubs(:logged_in?).returns(true) p = create_user('test_user').person @@ -467,7 +442,7 @@ class ApplicationHelperTest < Test::Unit::TestCase e.stubs(:enabled?).with(:join_community_popup).returns(true) stubs(:environment).returns(e) - c = Community.create(:name => 'test_comm', :identifier => 'test_comm') + c = fast_create(Community, :name => 'test_comm', :identifier => 'test_comm') stubs(:profile).returns(c) stubs(:logged_in?).returns(false) stubs(:session).returns({:no_asking => [c.id]}) @@ -482,7 +457,7 @@ class ApplicationHelperTest < Test::Unit::TestCase e.stubs(:enabled?).with(:join_community_popup).returns(true) stubs(:environment).returns(e) - c = Community.create(:name => 'test_comm', :identifier => 'test_comm') + c = fast_create(Community, :name => 'test_comm', :identifier => 'test_comm') stubs(:profile).returns(c) stubs(:logged_in?).returns(true) stubs(:session).returns({:no_asking => [c.id]}) @@ -507,7 +482,7 @@ class ApplicationHelperTest < Test::Unit::TestCase should 'display name on page title if profile doesnt have nickname' do stubs(:environment).returns(Environment.default) - c = Community.create(:name => 'Comm name', :identifier => 'test_comm') + c = fast_create(Community, :name => 'Comm name', :identifier => 'test_comm') stubs(:profile).returns(c) assert_match(/Comm name/, page_title) end @@ -515,7 +490,7 @@ class ApplicationHelperTest < Test::Unit::TestCase should 'display nickname on page title if profile has nickname' do stubs(:environment).returns(Environment.default) - c = Community.create(:name => 'Community for tests', :nickname => 'Community nickname', :identifier => 'test_comm') + c = fast_create(Community, :name => 'Community for tests', :nickname => 'Community nickname', :identifier => 'test_comm') stubs(:profile).returns(c) assert_match(/Community nickname/, page_title) end diff --git a/test/unit/approve_article_test.rb b/test/unit/approve_article_test.rb index af35f81..2aab15d 100644 --- a/test/unit/approve_article_test.rb +++ b/test/unit/approve_article_test.rb @@ -11,7 +11,7 @@ class ApproveArticleTest < ActiveSupport::TestCase attr_reader :profile should 'have name, reference article and profile' do - article = profile.articles.create!(:name => 'test article') + article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article') a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) @@ -21,7 +21,7 @@ class ApproveArticleTest < ActiveSupport::TestCase end should 'create published article when finished' do - article = profile.articles.create!(:name => 'test article') + article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article') a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) assert_difference PublishedArticle, :count do @@ -39,7 +39,7 @@ class ApproveArticleTest < ActiveSupport::TestCase end should 'have parent if defined' do - article = profile.articles.create!(:name => 'test article') + article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article') folder = profile.articles.create!(:name => 'test folder', :type => 'Folder') a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile, :article_parent_id => folder.id) @@ -48,7 +48,7 @@ class ApproveArticleTest < ActiveSupport::TestCase end should 'not have parent if not defined' do - article = profile.articles.create!(:name => 'test article') + article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article') a = ApproveArticle.create!(:name => 'test name', :article => article, :target => profile, :requestor => profile) @@ -75,7 +75,7 @@ class ApproveArticleTest < ActiveSupport::TestCase should 'handle blank names' do article = profile.articles.create!(:name => 'test article') - community = Community.create!(:name => 'test comm') + community = fast_create(Community, :name => 'test comm') a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile) assert_difference PublishedArticle, :count do @@ -84,14 +84,14 @@ class ApproveArticleTest < ActiveSupport::TestCase end should 'notify target if group is moderated' do - article = profile.articles.create!(:name => 'test article') + article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article') community = Community.create!(:name => 'test comm', :moderated_articles => true) a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile) assert !ActionMailer::Base.deliveries.empty? end should 'not notify target if group is not moderated' do - article = profile.articles.create!(:name => 'test article') + article = fast_create(TextArticle, :profile_id => profile.id, :name => 'test article') community = Community.create!(:name => 'test comm', :moderated_articles => false) a = ApproveArticle.create!(:name => '', :article => article, :target => community, :requestor => profile) assert ActionMailer::Base.deliveries.empty? diff --git a/test/unit/article_block_test.rb b/test/unit/article_block_test.rb index b3f7a5c..42ad4c6 100644 --- a/test/unit/article_block_test.rb +++ b/test/unit/article_block_test.rb @@ -71,7 +71,7 @@ class ArticleBlockTest < Test::Unit::TestCase env.articles.destroy_all assert_equal [], env.articles community = fast_create(Community) - a = community.articles.create!(:name => 'test') + a = fast_create(TextArticle, :profile_id => community.id, :name => 'test') env.portal_community=community env.save block = ArticleBlock.create(:article => a) diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 9ed5c29..881b9a3 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -76,7 +76,7 @@ class ArticleTest < Test::Unit::TestCase should 'provide HTML version' do profile = create_user('testinguser').person - a = Article.create!(:name => 'my article', :profile_id => profile.id) + a = fast_create(Article, :name => 'my article', :profile_id => profile.id) a.expects(:body).returns('the body of the article') assert_equal 'the body of the article', a.to_html end @@ -88,7 +88,7 @@ class ArticleTest < Test::Unit::TestCase should 'provide first paragraph of HTML version' do profile = create_user('testinguser').person - a = Article.create!(:name => 'my article', :profile_id => profile.id) + a = fast_create(Article, :name => 'my article', :profile_id => profile.id) a.expects(:body).returns('
the first paragraph of the article
The second paragraph') assert_equal 'the first paragraph of the article
', a.first_paragraph end @@ -149,11 +149,11 @@ class ArticleTest < Test::Unit::TestCase Article.destroy_all - first = profile.articles.build(:name => 'first'); first.save! - second = profile.articles.build(:name => 'second'); second.save! - third = profile.articles.build(:name => 'third'); third.save! - fourth = profile.articles.build(:name => 'fourth'); fourth.save! - fifth = profile.articles.build(:name => 'fifth'); fifth.save! + first = fast_create(TextArticle, :profile_id => profile.id, :name => 'first') + second = fast_create(TextArticle, :profile_id => profile.id, :name => 'second') + third = fast_create(TextArticle, :profile_id => profile.id, :name => 'third') + fourth = fast_create(TextArticle, :profile_id => profile.id, :name => 'fourth') + fifth = fast_create(TextArticle, :profile_id => profile.id, :name => 'fifth') other_first = other_profile.articles.build(:name => 'first'); other_first.save! @@ -165,8 +165,8 @@ class ArticleTest < Test::Unit::TestCase p = create_user('usr1').person Article.destroy_all - first = p.articles.build(:name => 'first', :published => true); first.save! - second = p.articles.build(:name => 'second', :published => false); second.save! + first = fast_create(TextArticle, :profile_id => p.id, :name => 'first', :published => true) + second = fast_create(TextArticle, :profile_id => p.id, :name => 'second', :published => false) assert_equal [ first ], Article.recent(nil) end @@ -175,8 +175,8 @@ class ArticleTest < Test::Unit::TestCase p = create_user('usr1').person Article.destroy_all - first = p.articles.build(:name => 'first', :published => true); first.save! - second = p.articles.build(:name => 'second', :published => false); second.save! + first = fast_create(TextArticle, :profile_id => p.id, :name => 'first', :published => true) + second = fast_create(TextArticle, :profile_id => p.id, :name => 'second', :published => false) assert_equal [ first ], Article.recent(nil) end @@ -185,8 +185,8 @@ class ArticleTest < Test::Unit::TestCase p = fast_create(Person, :public_profile => false) Article.destroy_all - first = p.articles.build(:name => 'first', :published => true); first.save! - second = p.articles.build(:name => 'second', :published => false); second.save! + first = fast_create(TextArticle, :profile_id => p.id, :name => 'first', :published => true) + second = fast_create(TextArticle, :profile_id => p.id, :name => 'second', :published => false) assert_equal [ ], Article.recent(nil) end @@ -195,8 +195,8 @@ class ArticleTest < Test::Unit::TestCase p = fast_create(Person, :visible => false) Article.destroy_all - first = p.articles.build(:name => 'first', :published => true); first.save! - second = p.articles.build(:name => 'second', :published => false); second.save! + first = fast_create(TextArticle, :profile_id => p.id, :name => 'first', :published => true) + second = fast_create(TextArticle, :profile_id => p.id, :name => 'second', :published => false) assert_equal [ ], Article.recent(nil) end @@ -224,7 +224,7 @@ class ArticleTest < Test::Unit::TestCase Article.destroy_all first = UploadedFile.new(:profile => p, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')); first.save! - second = p.articles.build(:name => 'second'); second.save! + second = fast_create(TextArticle, :profile_id => p.id, :name => 'second') assert_equal [ second ], Article.recent(nil) end @@ -232,7 +232,7 @@ class ArticleTest < Test::Unit::TestCase should 'not show RssFeed as recent' do p = create_user('usr1').person Article.destroy_all - first = RssFeed.create!(:profile => p, :name => 'my feed', :advertise => true) + first = fast_create(RssFeed, :profile_id => p.id, :name => 'my feed', :advertise => true) first.limit = 10; first.save! second = p.articles.build(:name => 'second'); second.save! @@ -242,7 +242,7 @@ class ArticleTest < Test::Unit::TestCase should 'not show blog as recent' do p = create_user('usr1').person Article.destroy_all - first = Blog.create!(:profile => p, :name => 'my blog', :advertise => true) + first = fast_create(Blog, :profile_id => p.id, :name => 'my blog', :advertise => true) second = p.articles.build(:name => 'second'); second.save! assert_equal [ second ], Article.recent(nil) @@ -425,8 +425,8 @@ class ArticleTest < Test::Unit::TestCase end should 'be able to create an article already with categories' do - c1 = Category.create!(:environment => Environment.default, :name => 'c1') - c2 = Category.create!(:environment => Environment.default, :name => 'c2') + c1 = fast_create(Category, :environment_id => Environment.default.id, :name => 'c1') + c2 = fast_create(Category, :environment_id => Environment.default.id, :name => 'c2') p = create_user('testinguser').person a = p.articles.create!(:name => 'test', :category_ids => [c1.id, c2.id]) @@ -435,7 +435,7 @@ class ArticleTest < Test::Unit::TestCase end should 'not add a category twice to article' do - c1 = Category.create!(:environment => Environment.default, :name => 'c1') + c1 = fast_create(Category, :environment_id => Environment.default.id, :name => 'c1') c2 = c1.children.create!(:environment => Environment.default, :name => 'c2') c3 = c1.children.create!(:environment => Environment.default, :name => 'c3') owner = create_user('testuser').person @@ -454,23 +454,23 @@ class ArticleTest < Test::Unit::TestCase end should 'say that logged off user cannot see private article' do - profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') - article = Article.create!(:name => 'test article', :profile => profile, :published => false) + profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile') + article = fast_create(Article, :name => 'test article', :profile_id => profile.id, :published => false) assert !article.display_to?(nil) end should 'say that not member of profile cannot see private article' do - profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') - article = Article.create!(:name => 'test article', :profile => profile, :published => false) + 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 assert !article.display_to?(person) end should 'say that member user can not see private article' do - profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') - article = Article.create!(:name => 'test article', :profile => profile, :published => false) + 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.member(profile.environment.id)) @@ -478,8 +478,8 @@ class ArticleTest < Test::Unit::TestCase end should 'say that profile admin can see private article' do - profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') - article = Article.create!(:name => 'test article', :profile => profile, :published => false) + 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.admin(profile.environment.id)) @@ -487,8 +487,8 @@ class ArticleTest < Test::Unit::TestCase end should 'say that profile moderator can see private article' do - profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') - article = Article.create!(:name => 'test article', :profile => profile, :published => false) + 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)) @@ -496,8 +496,8 @@ class ArticleTest < Test::Unit::TestCase end should 'not show article to non member if article public but profile private' do - profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile', :public_profile => false) - article = Article.create!(:name => 'test article', :profile => profile, :published => true) + profile = fast_create(Profile, :name => 'test profile', :identifier => 'test_profile', :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)) person2 = create_user('test_user2').person @@ -508,17 +508,17 @@ class ArticleTest < Test::Unit::TestCase end should 'make new article private if created inside a private folder' do - profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') - folder = Folder.create!(:name => 'my_intranet', :profile => profile, :published => false) - article = Article.create!(:name => 'my private article', :profile => profile, :parent => folder) + 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) assert !article.published? end should 'save as private' do - profile = Profile.create!(:name => 'test profile', :identifier => 'test_profile') - folder = Folder.create!(:name => 'my_intranet', :profile => profile, :published => false) - article = TextileArticle.new(:name => 'my private article') + 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 article.parent = folder article.save! @@ -540,7 +540,7 @@ class ArticleTest < Test::Unit::TestCase should 'display private articles to people who can view private content' do person = create_user('test_user').person - article = Article.create!(:name => 'test article', :profile => person, :published => false) + article = fast_create(Article, :name => 'test article', :profile_id => person.id, :published => false) admin_user = create_user('admin_user').person admin_user.stubs(:has_permission?).with('view_private_content', article.profile).returns('true') @@ -570,7 +570,7 @@ class ArticleTest < Test::Unit::TestCase should 'mantain the type in a copy' do p = create_user('test_user').person - a = Folder.create!(:name => 'test folder', :profile => p) + a = fast_create(Folder, :name => 'test folder', :profile_id => p.id) b = a.copy(:parent => a, :profile => p) assert_kind_of Folder, b @@ -638,15 +638,15 @@ class ArticleTest < Test::Unit::TestCase should 'identify if belongs to blog' do p = create_user('user_blog_test').person - blog = Blog.create!(:name => 'Blog test', :profile => p) - post = TextileArticle.create!(:name => 'First post', :profile => p, :parent => blog) + blog = fast_create(Blog, :name => 'Blog test', :profile_id => p.id) + post = fast_create(TextileArticle, :name => 'First post', :profile_id => p.id, :parent_id => blog.id) assert post.belongs_to_blog? end should 'not belongs to blog' do p = create_user('user_blog_test').person - folder = Folder.create!(:name => 'Not Blog', :profile => p) - a = TextileArticle.create!(:name => 'Not blog post', :profile => p, :parent => folder) + folder = fast_create(Folder, :name => 'Not Blog', :profile_id => p.id) + a = fast_create(TextileArticle, :name => 'Not blog post', :profile_id => p.id, :parent_id => folder.id) assert !a.belongs_to_blog? end @@ -656,7 +656,7 @@ class ArticleTest < Test::Unit::TestCase end should 'hold hits count' do - a = Article.create!(:name => 'Test article', :profile => profile) + a = fast_create(Article, :name => 'Test article', :profile_id => profile.id) a.hits = 10 a.save! a.reload @@ -664,7 +664,7 @@ class ArticleTest < Test::Unit::TestCase end should 'increment hit counter when hitted' do - a = Article.create!(:name => 'Test article', :profile => profile, :hits => 10) + a = fast_create(Article, :name => 'Test article', :profile_id => profile.id, :hits => 10) a.hit assert_equal 11, a.hits a.reload @@ -672,13 +672,13 @@ class ArticleTest < Test::Unit::TestCase end should 'have display_hits setting with default true' do - a = Article.create!(:name => 'Test article', :profile => profile) + a = fast_create(Article, :name => 'Test article', :profile_id => profile.id) assert_respond_to a, :display_hits assert_equal true, a.display_hits end should 'can display hits' do - a = Article.create!(:name => 'Test article', :profile => profile) + a = fast_create(Article, :name => 'Test article', :profile_id => profile.id) assert_respond_to a, :can_display_hits? assert_equal true, a.can_display_hits? end @@ -690,7 +690,7 @@ class ArticleTest < Test::Unit::TestCase end should 'not return a view url when common article' do - a = Article.create!(:name => 'Test article', :profile => profile) + a = fast_create(Article, :name => 'Test article', :profile_id => profile.id) assert_equal a.url, a.view_url end @@ -708,17 +708,17 @@ class ArticleTest < Test::Unit::TestCase end should 'published_at is same as created_at if not set' do - a = Article.create!(:name => 'Published at', :profile => profile) + a = fast_create(Article, :name => 'Published at', :profile_id => profile.id) assert_equal a.created_at, a.published_at end should 'use npage to compose cache key' do - a = Article.create!(:name => 'Published at', :profile => profile) + a = fast_create(Article, :name => 'Published at', :profile_id => profile.id) assert_match(/-npage-2/,a.cache_key(:npage => 2)) end should 'use year and month to compose cache key' do - a = Article.create!(:name => 'Published at', :profile => profile) + a = fast_create(Article, :name => 'Published at', :profile_id => profile.id) assert_match(/-year-2009-month-04/, a.cache_key(:year => '2009', :month => '04')) end @@ -728,7 +728,7 @@ class ArticleTest < Test::Unit::TestCase end should 'get tagged with tag' do - a = Article.create!(:name => 'Published at', :profile => profile, :tag_list => 'bli') + a = create(Article, :name => 'Published at', :profile_id => profile.id, :tag_list => 'bli') as = Article.find_tagged_with('bli') assert_includes as, a @@ -749,7 +749,7 @@ class ArticleTest < Test::Unit::TestCase should 'ignore category with zero as id' do a = profile.articles.create!(:name => 'a test article') - c = Category.create!(:name => 'test category', :environment => profile.environment) + c = fast_create(Category, :name => 'test category', :environment_id => profile.environment.id) a.category_ids = ['0', c.id, nil] assert a.save assert_equal [c], a.categories @@ -766,13 +766,13 @@ class ArticleTest < Test::Unit::TestCase end should 'add owner on cache_key when profile is community' do - c = Community.create!(:name => 'new_comm') + c = fast_create(Community) a = c.articles.create!(:name => 'a test article') assert_match(/-owner/, a.cache_key({}, c)) end should 'have a creator method' do - c = Community.create!(:name => 'new_comm') + c = fast_create(Community) a = c.articles.create!(:name => 'a test article', :last_changed_by => profile) p = create_user('other_user').person a.update_attributes(:body => 'some content', :last_changed_by => p); a.save! @@ -780,7 +780,7 @@ class ArticleTest < Test::Unit::TestCase end should 'allow creator to edit if is publisher' do - c = Community.create!(:name => 'new_comm') + c = fast_create(Community) p = create_user_with_permission('test_user', 'publish_content', c) a = c.articles.create!(:name => 'a test article', :last_changed_by => p) @@ -788,7 +788,7 @@ class ArticleTest < Test::Unit::TestCase end should 'allow user with "Manage content" permissions to edit' do - c = Community.create!(:name => 'new_comm') + c = fast_create(Community) p = create_user_with_permission('test_user', 'post_content', c) a = c.articles.create!(:name => 'a test article') @@ -796,7 +796,7 @@ class ArticleTest < Test::Unit::TestCase end should 'update slug from name' do - article = Article.create!(:name => 'A test article', :profile => profile) + article = create(Article, :name => 'A test article', :profile_id => profile.id) assert_equal 'a-test-article', article.slug article.name = 'Changed name' assert_equal 'changed-name', article.slug diff --git a/test/unit/block_test.rb b/test/unit/block_test.rb index 9efaa9e..2c40972 100644 --- a/test/unit/block_test.rb +++ b/test/unit/block_test.rb @@ -9,7 +9,7 @@ class BlockTest < Test::Unit::TestCase should 'access owner through box' do user = create_user('testinguser').person - box = Box.create!(:owner => user) + box = fast_create(Box, :owner_id => user, :owner_type => 'Person') block = Block.new block.box = box @@ -54,14 +54,14 @@ class BlockTest < Test::Unit::TestCase should 'provide chache keys' do p = create_user('test_user').person box = p.boxes[0] - b = Block.create!(:box => box) + b = fast_create(Block, :box_id => box.id) assert_equal( "block-id-#{b.id}", b.cache_keys) end should 'list enabled blocks' do - block1 = Block.create!(:title => 'test 1') - block2 = Block.create!(:title => 'test 2', :enabled => false) + block1 = fast_create(Block, :title => 'test 1') + block2 = fast_create(Block, :title => 'test 2', :enabled => false) assert_includes Block.enabled, block1 assert_not_includes Block.enabled, block2 end @@ -89,7 +89,7 @@ class BlockTest < Test::Unit::TestCase should 'be able to save display setting' do user = create_user('testinguser').person box = fast_create(Box, :owner_id => user.id) - block = Block.create!(:display => 'never', :box => box) + block = create(Block, :display => 'never', :box_id => box.id) block.reload assert_equal 'never', block.display end @@ -97,7 +97,7 @@ class BlockTest < Test::Unit::TestCase should 'be able to update display setting' do user = create_user('testinguser').person box = fast_create(Box, :owner_id => user.id) - block = Block.create!(:display => 'never', :box => box) + block = create(Block, :display => 'never', :box_id => box.id) assert block.update_attributes!(:display => 'always') block.reload assert_equal 'always', block.display diff --git a/test/unit/blog_archives_block_test.rb b/test/unit/blog_archives_block_test.rb index 39c2103..914bb8a 100644 --- a/test/unit/blog_archives_block_test.rb +++ b/test/unit/blog_archives_block_test.rb @@ -21,7 +21,7 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase date = DateTime.parse('2008-01-01') blog = profile.blog for i in 1..10 do - post = TextileArticle.create!(:name => "post #{i} test", :profile => profile, :parent => blog) + post = fast_create(TextileArticle, :name => "post #{i} test", :profile_id => profile.id, :parent_id => blog.id) post.update_attribute(:published_at, date) end block = BlogArchivesBlock.new @@ -33,7 +33,7 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase date = DateTime.parse('2008-01-01') blog = profile.blog for i in 1..10 do - post = TextileArticle.create!(:name => "post #{i} test", :profile => profile, :parent => blog) + post = fast_create(TextileArticle, :name => "post #{i} test", :profile_id => profile.id, :parent_id => blog.id) assert post.update_attribute(:published_at, date) end block = BlogArchivesBlock.new @@ -44,7 +44,7 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase should 'order list of amount posts' do blog = profile.blog for i in 1..10 do - post = TextileArticle.create!(:name => "post #{i} test", :profile => profile, :parent => blog) + post = fast_create(TextileArticle, :name => "post #{i} test", :profile_id => profile.id, :parent_id => blog.id) post.update_attribute(:published_at, DateTime.parse("2008-#{i}-01")) end block = BlogArchivesBlock.new @@ -90,11 +90,11 @@ class BlogArchivesBlockTest < ActiveSupport::TestCase end should 'show posts from first blog' do - (blog_one, blog_two) = profile.blogs profile.articles << Blog.new(:name => 'Blog Two', :profile => profile) + (blog_one, blog_two) = profile.blogs for month in 1..3 - TextileArticle.create!(:name => "blog one - post #{month}", :profile => profile, :parent => blog_one) - TextileArticle.create!(:name => "blog two - post #{month}", :profile => profile, :parent => blog_two) + create(TextileArticle, :name => "blog one - post #{month}", :profile_id => profile.id, :parent_id => blog_one.id) + create(TextileArticle, :name => "blog two - post #{month}", :profile_id => profile.id, :parent_id => blog_two.id) end block = BlogArchivesBlock.new block.stubs(:owner).returns(profile) diff --git a/test/unit/blog_helper_test.rb b/test/unit/blog_helper_test.rb index 7edf7bf..a87d71a 100644 --- a/test/unit/blog_helper_test.rb +++ b/test/unit/blog_helper_test.rb @@ -11,7 +11,7 @@ class BlogHelperTest < Test::Unit::TestCase stubs(:show_date).returns('') @environment = Environment.default @profile = create_user('blog_helper_test').person - @blog = Blog.create!(:profile => profile, :name => 'Blog test') + @blog = fast_create(Blog, :profile_id => profile.id, :name => 'Blog test') end attr :profile diff --git a/test/unit/blog_test.rb b/test/unit/blog_test.rb index 7f73a31..36c0842 100644 --- a/test/unit/blog_test.rb +++ b/test/unit/blog_test.rb @@ -28,7 +28,7 @@ class BlogTest < ActiveSupport::TestCase should 'create rss feed automatically' do p = create_user('testuser').person - b = Blog.create!(:profile => p, :name => 'blog_feed_test') + b = create(Blog, :profile_id => p.id, :name => 'blog_feed_test') assert_kind_of RssFeed, b.feed end @@ -61,37 +61,37 @@ class BlogTest < ActiveSupport::TestCase should 'has posts' do p = create_user('testuser').person - blog = Blog.create!(:profile => p, :name => 'Blog test') - post = TextileArticle.create!(:name => 'First post', :profile => p, :parent => blog) + blog = fast_create(Blog, :profile_id => p.id, :name => 'Blog test') + post = fast_create(TextileArticle, :name => 'First post', :profile_id => p.id, :parent_id => blog.id) blog.children << post assert_includes blog.posts, post end should 'not includes rss feed in posts' do p = create_user('testuser').person - blog = Blog.create!(:profile => p, :name => 'Blog test') + blog = create(Blog, :profile_id => p.id, :name => 'Blog test') assert_includes blog.children, blog.feed assert_not_includes blog.posts, blog.feed end should 'list posts ordered by published at' do p = create_user('testuser').person - blog = Blog.create!(:profile => p, :name => 'Blog test') - newer = TextileArticle.create!(:name => 'Post 2', :parent => blog, :profile => p) - older = TextileArticle.create!(:name => 'Post 1', :parent => blog, :profile => p, :published_at => Time.now - 1.month) + blog = fast_create(Blog, :profile_id => p.id, :name => 'Blog test') + newer = create(TextileArticle, :name => 'Post 2', :parent => blog, :profile => p) + older = create(TextileArticle, :name => 'Post 1', :parent => blog, :profile => p, :published_at => Time.now - 1.month) assert_equal [newer, older], blog.posts end should 'has filter' do p = create_user('testuser').person - blog = Blog.create!(:profile => p, :name => 'Blog test') + blog = fast_create(Blog, :profile_id => p.id, :name => 'Blog test') blog.filter = {:param => 'value'} assert_equal 'value', blog.filter[:param] end should 'has one external feed' do p = create_user('testuser').person - blog = Blog.create!(:profile => p, :name => 'Blog test') + blog = fast_create(Blog, :profile_id => p.id, :name => 'Blog test') efeed = blog.create_external_feed(:address => 'http://invalid.url') assert_equal efeed, blog.external_feed end @@ -135,7 +135,7 @@ class BlogTest < ActiveSupport::TestCase should 'profile has more then one blog' do p = create_user('testuser').person - Blog.create!(:name => 'Blog test', :profile => p) + fast_create(Blog, :name => 'Blog test', :profile_id => p.id) assert_nothing_raised ActiveRecord::RecordInvalid do Blog.create!(:name => 'Another Blog', :profile => p) end diff --git a/test/unit/comment_notifier_test.rb b/test/unit/comment_notifier_test.rb index aebffe9..1327d1e 100644 --- a/test/unit/comment_notifier_test.rb +++ b/test/unit/comment_notifier_test.rb @@ -8,47 +8,39 @@ class CommentNotifierTest < Test::Unit::TestCase ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true ActionMailer::Base.deliveries = [] - + @profile = create_user('user_comment_test').person + @article = fast_create(Article, :name => 'Article test', :profile_id => @profile.id, :notify_comments => true) end should 'deliver mail after make aarticle commment' do - p = create_user('user_comment_test').person - a = Article.create!(:name => 'Article test', :profile => p, :notify_comments => true) assert_difference ActionMailer::Base.deliveries, :size do - a.comments << Comment.new(:author => p, :title => 'test comment', :body => 'you suck!') + @article.comments << Comment.new(:author => @profile, :title => 'test comment', :body => 'you suck!') end end should 'deliver mail to owner of article' do - p = create_user('user_comment_test').person - a = Article.create!(:name => 'Article test', :profile => p, :notify_comments => true) - a.comments << Comment.new(:author => p, :title => 'test comment', :body => 'you suck!') + @article.comments << Comment.new(:author => @profile, :title => 'test comment', :body => 'you suck!') sent = ActionMailer::Base.deliveries.first - assert_equal [p.email], sent.to + assert_equal [@profile.email], sent.to end should 'display author name in delivered mail' do - p = create_user('user_comment_test').person - a = Article.create!(:name => 'Article test', :profile => p, :notify_comments => true) - a.comments << Comment.new(:author => p, :title => 'test comment', :body => 'you suck!') + @article.comments << Comment.new(:author => @profile, :title => 'test comment', :body => 'you suck!') sent = ActionMailer::Base.deliveries.first assert_match /user_comment_test/, sent.body end should 'display unauthenticated author name and email in delivered mail' do - p = create_user('user_comment_test').person - a = Article.create!(:name => 'Article test', :profile => p, :notify_comments => true) - a.comments << Comment.new(:name => 'flatline', :email => 'flatline@invalid.com', :title => 'test comment', :body => 'you suck!') + @article.comments << Comment.new(:name => 'flatline', :email => 'flatline@invalid.com', :title => 'test comment', :body => 'you suck!') sent = ActionMailer::Base.deliveries.first assert_match /flatline/, sent.body assert_match /flatline@invalid.com/, sent.body end should 'not deliver mail if notify comments is false' do - p = create_user('user_comment_test').person - a = Article.create!(:name => 'Article test', :profile => p, :notify_comments => false) + @article.update_attribute(:notify_comments, false) assert_no_difference ActionMailer::Base.deliveries, :size do - a.comments << Comment.new(:author => p, :title => 'test comment', :body => 'you suck!') + @article.comments << Comment.new(:author => @profile, :title => 'test comment', :body => 'you suck!') end end diff --git a/test/unit/communities_block_test.rb b/test/unit/communities_block_test.rb index 07cceba..a4cc7db 100644 --- a/test/unit/communities_block_test.rb +++ b/test/unit/communities_block_test.rb @@ -121,7 +121,7 @@ class CommunitiesBlockTest < Test::Unit::TestCase community_public = fast_create(Community, :environment_id => Environment.default.id, :public_profile => true) community_public.add_member(user) - community_private = fast_create(Community, :environment_id => Environment.default.id, :public_profile => false) + community_private = fast_create(Community, :public_profile => false) community_private.add_member(user) block = CommunitiesBlock.new @@ -133,10 +133,10 @@ class CommunitiesBlockTest < Test::Unit::TestCase should 'not count non-visible profile communities' do user = create_user('testuser').person - visible_community = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :visible => true) + visible_community = fast_create(Community, :name => 'tcommunity 1', :identifier => 'comm1', :visible => true) visible_community.add_member(user) - not_visible_community = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :visible => false) + not_visible_community = fast_create(Community, :name => ' community 2', :identifier => 'comm2', :visible => false) not_visible_community.add_member(user) block = CommunitiesBlock.new @@ -146,9 +146,9 @@ class CommunitiesBlockTest < Test::Unit::TestCase end should 'count non-public environment communities' do - community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true) + community_public = fast_create(Community, :name => 'tcommunity 1', :identifier => 'comm1', :public_profile => true) - community_private = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => false) + community_private = fast_create(Community, :name => ' community 2', :identifier => 'comm2', :public_profile => false) block = CommunitiesBlock.new block.expects(:owner).at_least_once.returns(Environment.default) @@ -157,9 +157,9 @@ class CommunitiesBlockTest < Test::Unit::TestCase end should 'not count non-visible environment communities' do - visible_community = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :visible => true) + visible_community = fast_create(Community, :name => 'tcommunity 1', :identifier => 'comm1', :visible => true) - not_visible_community = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :visible => false) + not_visible_community = fast_create(Community, :name => ' community 2', :identifier => 'comm2', :visible => false) block = CommunitiesBlock.new block.expects(:owner).at_least_once.returns(Environment.default) diff --git a/test/unit/community_test.rb b/test/unit/community_test.rb index 2e4ef02..a6de20f 100644 --- a/test/unit/community_test.rb +++ b/test/unit/community_test.rb @@ -51,7 +51,7 @@ class CommunityTest < Test::Unit::TestCase end should 'allow to add new members' do - c = Community.create!(:environment => Environment.default, :name => 'my test profile', :identifier => 'mytestprofile') + c = fast_create(Community, :name => 'my test profile', :identifier => 'mytestprofile') p = create_user('mytestuser').person c.add_member(p) @@ -60,7 +60,7 @@ class CommunityTest < Test::Unit::TestCase end should 'allow to remove members' do - c = Community.create!(:environment => Environment.default, :name => 'my other test profile', :identifier => 'myothertestprofile') + c = fast_create(Community, :name => 'my other test profile', :identifier => 'myothertestprofile') p = create_user('myothertestuser').person c.add_member(p) @@ -71,7 +71,7 @@ class CommunityTest < Test::Unit::TestCase end should 'clear relationships after destroy' do - c = Community.create!(:environment => Environment.default, :name => 'my test profile', :identifier => 'mytestprofile') + c = fast_create(Community, :name => 'my test profile', :identifier => 'mytestprofile') member = create_user('memberuser').person admin = create_user('adminuser').person moderator = create_user('moderatoruser').person @@ -91,7 +91,7 @@ class CommunityTest < Test::Unit::TestCase should 'have a community template' do env = Environment.create!(:name => 'test env') - p = Community.create!(:environment => Environment.default, :name => 'test_com', :identifier => 'test_com', :environment => env) + p = Community.create!(:name => 'test_com', :identifier => 'test_com', :environment => env) assert_kind_of Community, p.template end @@ -124,28 +124,28 @@ class CommunityTest < Test::Unit::TestCase end should 'return newest text articles as news' do - c = Community.create!(:name => 'test_com') - f = Folder.create!(:name => 'folder', :profile => c) + c = fast_create(Community, :name => 'test_com') + f = fast_create(Folder, :name => 'folder', :profile_id => c.id) u = UploadedFile.create!(:profile => c, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) - older_t = TinyMceArticle.create!(:name => 'old news', :profile => c) - t = TinyMceArticle.create!(:name => 'news', :profile => c) - t_in_f = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => f) + older_t = fast_create(TinyMceArticle, :name => 'old news', :profile_id => c.id) + t = fast_create(TinyMceArticle, :name => 'news', :profile_id => c.id) + t_in_f = fast_create(TinyMceArticle, :name => 'news', :profile_id => c.id, :parent_id => f.id) assert_equal [t_in_f, t], c.news(2) end should 'not return highlighted news when not asked' do - c = Community.create!(:name => 'test_com') - highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true) - t = TinyMceArticle.create!(:name => 'news', :profile => c) + c = fast_create(Community, :name => 'test_com') + highlighted_t = fast_create(TinyMceArticle, :name => 'high news', :profile_id => c.id, :highlighted => true) + t = fast_create(TinyMceArticle, :name => 'news', :profile_id => c.id) assert_equal [t].map(&:slug), c.news(2).map(&:slug) end should 'return highlighted news when asked' do - c = Community.create!(:name => 'test_com') - highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true) - t = TinyMceArticle.create!(:name => 'news', :profile => c) + c = fast_create(Community, :name => 'test_com') + highlighted_t = fast_create(TinyMceArticle, :name => 'high news', :profile_id => c.id, :highlighted => true) + t = fast_create(TinyMceArticle, :name => 'news', :profile_id => c.id) assert_equal [highlighted_t].map(&:slug), c.news(2, true).map(&:slug) end diff --git a/test/unit/contact_test.rb b/test/unit/contact_test.rb index 1e01290..bc71fc2 100644 --- a/test/unit/contact_test.rb +++ b/test/unit/contact_test.rb @@ -32,13 +32,13 @@ class ContactTest < ActiveSupport::TestCase end should 'deliver message' do - ent = Enterprise.create!(:name => 'my enterprise', :identifier => 'myent', :environment => Environment.default) + ent = fast_create(Enterprise, :name => 'my enterprise', :identifier => 'myent') c = Contact.new(:name => 'john', :email => 'john@invalid.com', :subject => 'hi', :message => 'hi, all', :dest => ent) assert c.deliver end should 'not deliver message if contact is invalid' do - ent = Enterprise.create!(:name => 'my enterprise', :identifier => 'myent', :environment => Environment.default) + ent = fast_create(Enterprise, :name => 'my enterprise', :identifier => 'myent') c = Contact.new(:name => 'john', :subject => 'hi', :message => 'hi, all', :dest => ent) assert !c.valid? assert !c.deliver diff --git a/test/unit/content_viewer_helper_test.rb b/test/unit/content_viewer_helper_test.rb index a675c09..a1bb321 100644 --- a/test/unit/content_viewer_helper_test.rb +++ b/test/unit/content_viewer_helper_test.rb @@ -13,7 +13,7 @@ class ContentViewerHelperTest < Test::Unit::TestCase attr :profile should 'display published-at for blog posts' do - blog = Blog.create!(:name => 'Blog test', :profile => profile) + blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id) post = TextileArticle.create!(:name => 'post test', :profile => profile, :parent => blog) result = article_title(post) assert_match /#{show_date(post.published_at)}, by .*#{profile.identifier}/, result @@ -26,22 +26,22 @@ class ContentViewerHelperTest < Test::Unit::TestCase end should 'create link on title of blog posts' do - blog = Blog.create!(:name => 'Blog test', :profile => profile) - post = TextileArticle.create!(:name => 'post test', :profile => profile, :parent => blog) + blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id) + post = fast_create(TextileArticle, :name => 'post test', :profile_id => profile.id, :parent_id => blog.id) assert post.belongs_to_blog? result = article_title(post) assert_match /a href='#{post.url}'>#{post.name}, result end should 'not create link on title if pass no_link option' do - blog = Blog.create!(:name => 'Blog test', :profile => profile) - post = TextileArticle.create!(:name => 'post test', :profile => profile, :parent => blog) + blog = fast_create(Blog, :name => 'Blog test', :profile_id => profile.id) + post = fast_create(TextileArticle, :name => 'post test', :profile_id => profile.id, :parent_id => blog.id) result = article_title(post, :no_link => :true) assert_no_match /a href='#{post.url}'>#{post.name}, result end should 'not create link on title if non-blog post' do - article = TextileArticle.create!(:name => 'art test', :profile => profile) + article = fast_create(TextileArticle, :name => 'art test', :profile_id => profile.id) result = article_title(article) assert_no_match /a href='#{article.url}'>#{article.name}, result end diff --git a/test/unit/create_enterprise_test.rb b/test/unit/create_enterprise_test.rb index 3c8dd0b..ff07a25 100644 --- a/test/unit/create_enterprise_test.rb +++ b/test/unit/create_enterprise_test.rb @@ -46,8 +46,8 @@ class CreateEnterpriseTest < Test::Unit::TestCase should 'require that the informed target (validator organization) actually validates for the chosen region' do environment = fast_create(Environment) - region = Region.create!(:name => 'My region', :environment_id => environment.id) - validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) + region = fast_create(Region, :name => 'My region', :environment_id => environment.id) + validator = fast_create(Organization, :name => "My organization", :identifier => 'myorg', :environment_id => environment.id) task = CreateEnterprise.new @@ -94,8 +94,8 @@ class CreateEnterpriseTest < Test::Unit::TestCase should 'actually create an enterprise when finishing the task and associate the task requestor as its owner through the "user" association' do environment = fast_create(Environment) - region = Region.create!(:name => 'My region', :environment_id => environment.id) - validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) + region = fast_create(Region, :name => 'My region', :environment_id => environment.id) + validator = fast_create(Organization, :name => "My organization", :identifier => 'myorg', :environment_id => environment.id) region.validators << validator person = create_user('testuser').person @@ -128,8 +128,8 @@ class CreateEnterpriseTest < Test::Unit::TestCase should 'actually create an enterprise when finishing the task and associate the task requestor as its owner through the "user" association even when environment is not default' do environment = fast_create(Environment) - region = Region.create!(:name => 'My region', :environment_id => environment.id) - validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) + region = fast_create(Region, :name => 'My region', :environment_id => environment.id) + validator = fast_create(Organization, :name => "My organization", :identifier => 'myorg', :environment_id => environment.id) region.validators << validator person = create_user('testuser').person @@ -170,8 +170,8 @@ class CreateEnterpriseTest < Test::Unit::TestCase should 'validate that eveything is ok but the validator (target)' do environment = fast_create(Environment) - region = Region.create!(:name => 'My region', :environment_id => environment.id) - validator = Organization.create!(:name => "My organization", :identifier => 'myorg', :environment_id => environment.id) + region = fast_create(Region, :name => 'My region', :environment_id => environment.id) + validator = fast_create(Organization, :name => "My organization", :identifier => 'myorg', :environment_id => environment.id) region.validators << validator person = create_user('testuser').person task = CreateEnterprise.new({ diff --git a/test/unit/disabled_enterprise_message_block_test.rb b/test/unit/disabled_enterprise_message_block_test.rb index a19ebc6..98ef277 100644 --- a/test/unit/disabled_enterprise_message_block_test.rb +++ b/test/unit/disabled_enterprise_message_block_test.rb @@ -7,7 +7,7 @@ class DisabledEnterpriseMessageBlockTest < Test::Unit::TestCase end should 'display message for disabled enterprise' do - e = Environment.create(:name => 'test_env') + e = Environment.default e.expects(:message_for_disabled_enterprise).returns('This message is for disabled enterprises') block = DisabledEnterpriseMessageBlock.new p = Profile.new @@ -19,7 +19,7 @@ class DisabledEnterpriseMessageBlockTest < Test::Unit::TestCase end should 'display nothing if environment has no message' do - e = Environment.create(:name => 'test_env') + e = fast_create(Environment) block = DisabledEnterpriseMessageBlock.new p = Profile.new block.expects(:owner).returns(p) diff --git a/test/unit/domain_test.rb b/test/unit/domain_test.rb index 082077a..be2598c 100644 --- a/test/unit/domain_test.rb +++ b/test/unit/domain_test.rb @@ -51,7 +51,7 @@ class DomainTest < Test::Unit::TestCase def test_find_by_name Domain.delete_all - Domain.create(:name => 'example.net') + fast_create(Domain, :name => 'example.net') d1 = Domain.find_by_name('example.net') d2 = Domain.find_by_name('www.example.net') assert !d1.nil? diff --git a/test/unit/email_activation_test.rb b/test/unit/email_activation_test.rb index f8b7127..ba15261 100644 --- a/test/unit/email_activation_test.rb +++ b/test/unit/email_activation_test.rb @@ -25,7 +25,7 @@ class EmailActivationTest < Test::Unit::TestCase should 'enable user email when finish' do ze = create_user('zezinho', :environment_id => Environment.default.id) assert !ze.enable_email - task = EmailActivation.create!(:requestor => ze.person, :target => Environment.default) + task = fast_create(EmailActivation, :requestor_id => ze.person.id, :target_id => Environment.default.id) task.finish ze.reload assert ze.enable_email diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index 6decc46..b348cee 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -46,7 +46,7 @@ class EnterpriseTest < Test::Unit::TestCase end should 'remove products when removing enterprise' do - e = Enterprise.create!(:name => "My enterprise", :identifier => 'myenterprise') + e = fast_create(Enterprise) e.products.build(:name => 'One product').save! e.products.build(:name => 'Another product').save! @@ -77,7 +77,7 @@ class EnterpriseTest < Test::Unit::TestCase end should 'be found in search for its product categories' do - ent1 = Enterprise.create!(:name => 'test1', :identifier => 'test1') + ent1 = fast_create(Enterprise) prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) prod = ent1.products.create!(:name => 'teste', :product_category => prod_cat) @@ -90,7 +90,7 @@ class EnterpriseTest < Test::Unit::TestCase end should 'be found in search for its product categories hierarchy' do - ent1 = Enterprise.create!(:name => 'test1', :identifier => 'test1') + ent1 = fast_create(Enterprise) prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) prod_child = ProductCategory.create!(:name => 'pchild', :environment => Environment.default, :parent => prod_cat) prod = ent1.products.create!(:name => 'teste', :product_category => prod_child) @@ -104,7 +104,7 @@ class EnterpriseTest < Test::Unit::TestCase end should 'not allow to add new members' do - o = Enterprise.create!(:name => 'my test profile', :identifier => 'mytestprofile') + o = fast_create(Enterprise) p = create_user('mytestuser').person o.add_member(p) @@ -114,7 +114,7 @@ class EnterpriseTest < Test::Unit::TestCase end should 'allow to remove members' do - c = Enterprise.create!(:name => 'my other test profile', :identifier => 'myothertestprofile') + c = fast_create(Enterprise) c.expects(:closed?).returns(false) p = create_user('myothertestuser').person @@ -126,27 +126,27 @@ class EnterpriseTest < Test::Unit::TestCase end should 'have foudation_year' do - ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent') + ent = fast_create(Enterprise) assert_respond_to ent, 'foundation_year' assert_respond_to ent, 'foundation_year=' end should 'have cnpj' do - ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent') + ent = fast_create(Enterprise) assert_respond_to ent, 'cnpj' assert_respond_to ent, 'cnpj=' end should 'block' do - ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent') + ent = fast_create(Enterprise) ent.block assert Enterprise.find(ent.id).blocked? end should 'unblock' do - ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent') + ent = fast_create(Enterprise) ent.data[:blocked] = true ent.save ent.unblock @@ -154,7 +154,7 @@ class EnterpriseTest < Test::Unit::TestCase end should 'enable and make user admin' do - ent = Enterprise.create!(:name => 'test enteprise', :identifier => 'test_ent', :enabled => false) + ent = fast_create(Enterprise, :enabled => false) p = create_user('test_user').person assert ent.enable(p) diff --git a/test/unit/enterprises_block_test.rb b/test/unit/enterprises_block_test.rb index ec8f204..06e297f 100644 --- a/test/unit/enterprises_block_test.rb +++ b/test/unit/enterprises_block_test.rb @@ -125,11 +125,11 @@ class EnterprisesBlockTest < Test::Unit::TestCase should 'count number of owner enterprises' do user = create_user('testuser').person - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default) + ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'ent1') ent1.expects(:closed?).returns(false) ent1.add_member(user) - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => Environment.default) + ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'ent2') ent2.expects(:closed?).returns(false) ent2.add_member(user) @@ -186,9 +186,9 @@ class EnterprisesBlockTest < Test::Unit::TestCase end should 'not count non-visible environment enterprises' do - env = Environment.create!(:name => 'test_env') - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => env, :visible => true) - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => env, :visible => false) + env = fast_create(Environment) + ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'ent1', :environment_id => env.id, :visible => true) + ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'ent2', :environment_id => env.id, :visible => false) block = EnterprisesBlock.new block.expects(:owner).at_least_once.returns(env) diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index aaa1abb..2fadc54 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -107,9 +107,9 @@ class EnvironmentTest < Test::Unit::TestCase def test_should_list_top_level_categories env = fast_create(Environment) - cat1 = Category.create!(:name => 'first category', :environment_id => env.id) - cat2 = Category.create!(:name => 'second category', :environment_id => env.id) - subcat = Category.create!(:name => 'child category', :environment_id => env.id, :parent_id => cat2.id) + cat1 = fast_create(Category, :name => 'first category', :environment_id => env.id) + cat2 = fast_create(Category, :name => 'second category', :environment_id => env.id) + subcat = fast_create(Category, :name => 'child category', :environment_id => env.id, :parent_id => cat2.id) cats = env.top_level_categories assert_equal 2, cats.size @@ -120,9 +120,9 @@ class EnvironmentTest < Test::Unit::TestCase def test_should_list_all_categories env = fast_create(Environment) - cat1 = Category.create!(:name => 'first category', :environment_id => env.id) - cat2 = Category.create!(:name => 'second category', :environment_id => env.id) - subcat = Category.create!(:name => 'child category', :environment_id => env.id, :parent_id => cat2.id) + cat1 = fast_create(Category, :name => 'first category', :environment_id => env.id) + cat2 = fast_create(Category, :name => 'second category', :environment_id => env.id) + subcat = fast_create(Category, :name => 'child category', :environment_id => env.id, :parent_id => cat2.id) cats = env.categories assert_equal 3, cats.size @@ -315,21 +315,21 @@ class EnvironmentTest < Test::Unit::TestCase should 'provide recent_documents' do environment = fast_create(Environment) - p1 = environment.profiles.build(:identifier => 'testprofile1', :name => 'test profile 1'); p1.save! - p2 = environment.profiles.build(:identifier => 'testprofile2', :name => 'test profile 2'); p2.save! + p1 = fast_create(Profile, :environment_id => environment.id) + p2 = fast_create(Profile, :environment_id => environment.id) # clear the articles Article.destroy_all # p1 creates one article - doc1 = p1.articles.build(:name => 'text 1'); doc1.save! + doc1 = fast_create(Article, :profile_id => p1.id) # p2 creates two articles - doc2 = p2.articles.build(:name => 'text 2'); doc2.save! - doc3 = p2.articles.build(:name => 'text 3'); doc3.save! + doc2 = fast_create(Article, :profile_id => p2.id) + doc3 = fast_create(Article, :profile_id => p2.id) # p1 creates another article - doc4 = p1.articles.build(:name => 'text 4'); doc4.save! + doc4 = fast_create(Article, :profile_id => p1.id) all_recent = environment.recent_documents [doc1,doc2,doc3,doc4].each do |item| @@ -404,34 +404,10 @@ class EnvironmentTest < Test::Unit::TestCase assert_equal 'this enterprise was disabled', env.message_for_disabled_enterprise end - should 'have articles and text_articles' do - # FIXME - assert true - #environment = Environment.create(:name => 'a test environment') - - ## creates profile - #profile = environment.profiles.create!(:identifier => 'testprofile1', :name => 'test profile 1') - - ## profile creates one article - #article = profile.articles.create!(:name => 'text article') - - ## profile creates one textile article - #textile = TextileArticle.create!(:name => 'textile article', :profile => profile) - #profile.articles << textile - - #assert_includes environment.articles, article - #assert_includes environment.articles, textile - - #assert_includes environment.text_articles, textile - #assert_not_includes environment.text_articles, article - end - should 'find by contents from articles' do environment = fast_create(Environment) assert_nothing_raised do environment.articles.find_by_contents('') - # FIXME - #environment.text_articles.find_by_contents('') end end @@ -768,7 +744,7 @@ class EnvironmentTest < Test::Unit::TestCase e = Environment.default c = e.portal_community = fast_create(Community) - news_folder = Folder.create!(:name => 'news folder', :profile => c) + news_folder = fast_create(Folder, :name => 'news folder', :profile_id => c.id) e.portal_folders = [news_folder] e.save!; e.reload @@ -848,9 +824,9 @@ class EnvironmentTest < Test::Unit::TestCase should 'list tags with their counts' do person = fast_create(Person) - person.articles.build(:name => 'article 1', :tag_list => 'first-tag').save! - person.articles.build(:name => 'article 2', :tag_list => 'first-tag, second-tag').save! - person.articles.build(:name => 'article 3', :tag_list => 'first-tag, second-tag, third-tag').save! + person.articles.create!(:name => 'article 1', :tag_list => 'first-tag') + person.articles.create!(:name => 'article 2', :tag_list => 'first-tag, second-tag') + person.articles.create!(:name => 'article 3', :tag_list => 'first-tag, second-tag, third-tag') assert_equal({ 'first-tag' => 3, 'second-tag' => 2, 'third-tag' => 1 }, Environment.default.tag_counts) end diff --git a/test/unit/event_test.rb b/test/unit/event_test.rb index c9b8b8b..fd161db 100644 --- a/test/unit/event_test.rb +++ b/test/unit/event_test.rb @@ -172,7 +172,7 @@ class EventTest < ActiveSupport::TestCase end should 'list all events' do - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') + profile = fast_create(Profile) event1 = Event.new(:name => 'Ze Birthday', :start_date => Date.today) event2 = Event.new(:name => 'Mane Birthday', :start_date => Date.today >> 1) profile.events << [event1, event2] @@ -181,7 +181,7 @@ class EventTest < ActiveSupport::TestCase end should 'list events by day' do - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') + profile = fast_create(Profile) today = Date.today yesterday_event = Event.new(:name => 'Joao Birthday', :start_date => today - 1.day) @@ -194,7 +194,7 @@ class EventTest < ActiveSupport::TestCase end should 'list events in a range' do - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') + profile = fast_create(Profile) today = Date.today event_in_range = Event.new(:name => 'Noosfero Conference', :start_date => today - 2.day, :end_date => today + 2.day) @@ -208,7 +208,7 @@ class EventTest < ActiveSupport::TestCase end should 'not list events out of range' do - profile = Profile.create!(:name => "Test Profile", :identifier => 'testprofile') + profile = fast_create(Profile) today = Date.today event_in_range1 = Event.new(:name => 'Foswiki Conference', :start_date => today - 2.day, :end_date => today + 2.day) diff --git a/test/unit/favorite_enterprises_block_test.rb b/test/unit/favorite_enterprises_block_test.rb index 3b2fb53..e673b0c 100644 --- a/test/unit/favorite_enterprises_block_test.rb +++ b/test/unit/favorite_enterprises_block_test.rb @@ -63,9 +63,9 @@ class FavoriteEnterprisesBlockTest < ActiveSupport::TestCase should 'count number of owner favorite enterprises' do user = create_user('testuser').person - ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default) + ent1 = fast_create(Enterprise, :name => 'test enterprise 1', :identifier => 'ent1') - ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => Environment.default) + ent2 = fast_create(Enterprise, :name => 'test enterprise 2', :identifier => 'ent2') user.favorite_enterprises << [ent1, ent2] diff --git a/test/unit/folder_test.rb b/test/unit/folder_test.rb index 887cf51..c176161 100644 --- a/test/unit/folder_test.rb +++ b/test/unit/folder_test.rb @@ -24,13 +24,13 @@ class FolderTest < ActiveSupport::TestCase should 'can display hits' do profile = create_user('testuser').person - a = Folder.create!(:name => 'Test article', :profile => profile) + a = fast_create(Folder, :profile_id => profile.id) assert_equal false, a.can_display_hits? end should 'be viewed as image gallery' do p = create_user('test_user').person - f = Folder.create!(:name => 'Test folder', :profile => p) + f = fast_create(Folder, :profile_id => p.id) f.view_as = 'image_gallery'; f.save! f.reload @@ -39,14 +39,14 @@ class FolderTest < ActiveSupport::TestCase should 'not allow view as bogus' do p = create_user('test_user').person - f = Folder.create!(:name => 'Test folder', :profile => p) + f = fast_create(Folder, :profile_id => p.id) f.view_as = 'bogus' assert !f.save end should 'view as folder by default' do p = create_user('test_user').person - f = Folder.create!(:name => 'Test folder', :profile => p) + f = fast_create(Folder, :profile_id => p.id) f.expects(:folder) f.to_html @@ -55,60 +55,60 @@ class FolderTest < ActiveSupport::TestCase should 'have images that are only images or other folders' do p = create_user('test_user').person - f = Folder.create!(:name => 'Test folder', :profile => p) + f = fast_create(Folder, :profile_id => p.id) file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/test.txt', 'text/plain'), :parent => f, :profile => p) image = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => f, :profile => p) - folder = Folder.create!(:name => 'child test folder', :parent => f, :profile => p) + folder = fast_create(Folder, :profile_id => p.id, :parent_id => f.id) assert_equivalent [folder, image], f.images end should 'bring folders first in alpha order in images listing' do p = create_user('test_user').person - f = Folder.create!(:name => 'Test folder', :profile => p) - folder1 = Folder.create!(:name => 'child test folder 1', :parent => f, :profile => p) + f = fast_create(Folder, :profile_id => p.id) + folder1 = fast_create(Folder, :name => 'b', :profile_id => p.id, :parent_id => f.id) image = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => f, :profile => p) - folder2 = Folder.create!(:name => 'child test folder 2', :parent => f, :profile => p) - folder3 = Folder.create!(:name => 'another child test folder', :parent => f, :profile => p) + folder2 = fast_create(Folder, :name => 'c', :profile_id => p.id, :parent_id => f.id) + folder3 = fast_create(Folder, :name => 'a', :profile_id => p.id, :parent_id => f.id) assert_equal [folder3.id, folder1.id, folder2.id, image.id], f.images.map(&:id) end should 'images support pagination' do p = create_user('test_user').person - f = Folder.create!(:name => 'Test folder', :profile => p) - folder = Folder.create!(:name => 'child test folder', :parent => f, :profile => p) + f = fast_create(Folder, :profile_id => p.id) + folder = fast_create(Folder, :profile_id => p.id, :parent_id => f.id) image = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => f, :profile => p) assert_equal [image], f.images.paginate(:page => 2, :per_page => 1) end should 'return newest text articles as news' do - c = Community.create!(:name => 'test_com') - folder = Folder.create!(:name => 'folder', :profile => c) - f = Folder.create!(:name => 'folder', :profile => c, :parent => folder) + c = fast_create(Community) + folder = fast_create(Folder, :profile_id => c.id) + f = fast_create(Folder, :name => 'folder', :profile_id => c.id, :parent_id => folder.id) u = UploadedFile.create!(:profile => c, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent => folder) - older_t = TinyMceArticle.create!(:name => 'old news', :profile => c, :parent => folder) - t = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => folder) - t_in_f = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => f) + older_t = fast_create(TinyMceArticle, :name => 'old news', :profile_id => c.id, :parent_id => folder.id) + t = fast_create(TinyMceArticle, :name => 'news', :profile_id => c.id, :parent_id => folder.id) + t_in_f = fast_create(TinyMceArticle, :name => 'news', :profile_id => c.id, :parent_id => f.id) assert_equal [t], folder.news(1) end should 'not return highlighted news when not asked' do - c = Community.create!(:name => 'test_com') - folder = Folder.create!(:name => 'folder', :profile => c) - highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true, :parent => folder) - t = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => folder) + c = fast_create(Community) + folder = fast_create(Folder, :profile_id => c.id) + highlighted_t = fast_create(TinyMceArticle, :name => 'high news', :profile_id => c.id, :highlighted => true, :parent_id => folder.id) + t = fast_create(TinyMceArticle, :name => 'news', :profile_id => c.id, :parent_id => folder.id) assert_equal [t].map(&:slug), folder.news(2).map(&:slug) end should 'return highlighted news when asked' do - c = Community.create!(:name => 'test_com') - folder = Folder.create!(:name => 'folder', :profile => c) - highlighted_t = TinyMceArticle.create!(:name => 'high news', :profile => c, :highlighted => true, :parent => folder) - t = TinyMceArticle.create!(:name => 'news', :profile => c, :parent => folder) + c = fast_create(Community) + folder = fast_create(Folder, :profile_id => c.id) + highlighted_t = fast_create(TinyMceArticle, :name => 'high news', :profile_id => c.id, :highlighted => true, :parent_id => folder.id) + t = fast_create(TinyMceArticle, :name => 'news', :profile_id => c.id, :parent_id => folder.id) assert_equal [highlighted_t].map(&:slug), folder.news(2, true).map(&:slug) end @@ -117,8 +117,8 @@ class FolderTest < ActiveSupport::TestCase p = create_user('test_user').person i = UploadedFile.create!(:profile => p, :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png')) - c = Community.create!(:name => 'test_com') - folder = Folder.create!(:name => 'folder', :profile => c) + c = fast_create(Community) + folder = fast_create(Folder, :profile_id => c.id) pi = PublishedArticle.create!(:profile => c, :reference_article => i, :parent => folder) assert_includes folder.images(true), pi diff --git a/test/unit/organization_test.rb b/test/unit/organization_test.rb index 1c42e83..c5ef7aa 100644 --- a/test/unit/organization_test.rb +++ b/test/unit/organization_test.rb @@ -4,7 +4,7 @@ class OrganizationTest < Test::Unit::TestCase fixtures :profiles def create_create_enterprise(org) - region = Region.create!(:name => 'some region', :environment => Environment.default) + region = fast_create(Region, :name => 'some region') region.validators << org requestor = create_user('testreq').person @@ -130,7 +130,7 @@ class OrganizationTest < Test::Unit::TestCase end should 'be able to find a pending validation by its code' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg') + org = fast_create(Organization) validation = create_create_enterprise(org) @@ -148,7 +148,7 @@ class OrganizationTest < Test::Unit::TestCase end should 'be able to find an already processed validation by its code' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg') + org = fast_create(Organization) validation = create_create_enterprise(org) validation.finish @@ -167,7 +167,7 @@ class OrganizationTest < Test::Unit::TestCase end should 'update contact_person' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg') + org = fast_create(Organization) assert_nil org.contact_person org.contact_person = 'person' assert_not_nil org.contact_person @@ -197,7 +197,7 @@ class OrganizationTest < Test::Unit::TestCase end should 'allow to add new member' do - o = Organization.create!(:name => 'my test profile', :identifier => 'mytestprofile') + o = fast_create(Organization) p = create_user('mytestuser').person o.add_member(p) @@ -206,7 +206,7 @@ class OrganizationTest < Test::Unit::TestCase end should 'allow to remove members' do - c = Organization.create!(:name => 'my other test profile', :identifier => 'myothertestprofile') + c = fast_create(Organization) p = create_user('myothertestuser').person c.add_member(p) @@ -217,7 +217,7 @@ class OrganizationTest < Test::Unit::TestCase end should 'allow to add new moderator' do - o = Organization.create!(:name => 'my test profile', :identifier => 'mytestprofile') + o = fast_create(Organization) p = create_user('myanothertestuser').person o.add_moderator(p) @@ -226,14 +226,14 @@ class OrganizationTest < Test::Unit::TestCase end should 'moderator has moderate_comments permission' do - o = Organization.create!(:name => 'my test profile', :identifier => 'mytestprofile') + o = fast_create(Organization) p = create_user('myanothertestuser').person o.add_moderator(p) assert p.has_permission?(:moderate_comments, o) end should 'be able to change identifier' do - o = Organization.create!(:name => 'Test Org', :identifier => 'test_org') + o = fast_create(Organization) assert_nothing_raised do o.identifier = 'test_org_new_url' end diff --git a/test/unit/pending_task_notifier_test.rb b/test/unit/pending_task_notifier_test.rb index cf8e3c5..ec56c3b 100644 --- a/test/unit/pending_task_notifier_test.rb +++ b/test/unit/pending_task_notifier_test.rb @@ -21,7 +21,7 @@ class PendingTaskNotifierTest < Test::Unit::TestCase should 'list organization pending tasks' do p = create_user('maelcum').person - c = Community.create!(:name => 'my test community') + c = fast_create(Community) c.add_admin(p) c.tasks << Task.new diff --git a/test/unit/people_block_test.rb b/test/unit/people_block_test.rb index 752dfea..5eb7796 100644 --- a/test/unit/people_block_test.rb +++ b/test/unit/people_block_test.rb @@ -24,7 +24,7 @@ class PeopleBlockTest < ActiveSupport::TestCase end should 'list people' do - owner = Environment.create!(:name => 'test environment') + owner = fast_create(Environment) block = PeopleBlock.new block.expects(:owner).returns(owner).at_least_once person1 = fast_create(Person, :environment_id => owner.id) diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index c9ca2fd..7aebcf3 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -36,7 +36,7 @@ class PersonTest < Test::Unit::TestCase end should 'belong to communities' do - c = Community.create!(:name => 'my test community') + c = fast_create(Community) p = create_user('mytestuser').person c.add_member(p) @@ -78,7 +78,7 @@ class PersonTest < Test::Unit::TestCase should 'change the roles of the user' do p = create_user('jonh', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person - e = Enterprise.create(:identifier => 'enter', :name => 'Enter') + e = fast_create(Enterprise) r1 = Role.create(:name => 'associate') assert e.affiliate(p, r1) r2 = Role.create(:name => 'partner') @@ -91,7 +91,7 @@ class PersonTest < Test::Unit::TestCase should 'report that the user has the permission' do p = create_user('john', :email => 'john@doe.org', :password => 'dhoe', :password_confirmation => 'dhoe').person r = Role.create(:name => 'associate', :permissions => ['edit_profile']) - e = Enterprise.create(:identifier => 'enterpri', :name => 'Enterpri') + e = fast_create(Enterprise) assert e.affiliate(p, r) p = Person.find(p.id) assert e.reload @@ -147,7 +147,7 @@ class PersonTest < Test::Unit::TestCase should 'be an admin if have permission of environment administration' do role = Role.create!(:name => 'just_another_admin_role') - env = Environment.create!(:name => 'blah') + env = fast_create(Environment) person = create_user('just_another_person').person env.affiliate(person, role) assert ! person.is_admin?(env) @@ -157,8 +157,8 @@ class PersonTest < Test::Unit::TestCase end should 'separate admins of different environments' do - env1 = Environment.create!(:name => 'blah1') - env2 = Environment.create!(:name => 'blah2') + env1 = fast_create(Environment) + env2 = fast_create(Environment) # role is an admin role role = Role.create!(:name => 'just_another_admin_role') @@ -290,7 +290,7 @@ class PersonTest < Test::Unit::TestCase should 'have favorite enterprises' do p = create_user('test_person').person - e = Enterprise.create!(:name => 'test_ent', :identifier => 'test_ent') + e = fast_create(Enterprise) p.favorite_enterprises << e @@ -325,7 +325,8 @@ class PersonTest < Test::Unit::TestCase end should 'have e-mail addresses' do - env = Environment.create!(:name => 'sample env', :domains => [Domain.new(:name => 'somedomain.com')]) + env = fast_create(Environment) + env.domains << Domain.new(:name => 'somedomain.com') person = Person.new(:environment => env, :identifier => 'testuser') person.expects(:environment).returns(env) @@ -333,9 +334,9 @@ class PersonTest < Test::Unit::TestCase end should 'not show www in e-mail addresses when force_www=true' do - env = Environment.create!(:name => 'sample env', :domains => [Domain.new(:name => 'somedomain.com')]) - env.force_www = true - env.save + env = fast_create(Environment) + env.domains << Domain.new(:name => 'somedomain.com') + env.update_attribute(:force_www, true) person = Person.new(:environment => env, :identifier => 'testuser') person.expects(:environment).returns(env) @@ -377,12 +378,12 @@ class PersonTest < Test::Unit::TestCase should 'person has group with pending tasks' do p1 = create_user('user_with_tasks').person - c1 = Community.create!(:name => 'my test community') + c1 = fast_create(Community) c1.tasks << Task.new assert !c1.tasks.pending.empty? c1.add_admin(p1) - c2 = Community.create!(:name => 'my other test community') + c2 = fast_create(Community) p2 = create_user('user_without_tasks').person c2.add_admin(p2) @@ -391,7 +392,7 @@ class PersonTest < Test::Unit::TestCase end should 'not allow simple member to view group pending tasks' do - c = Community.create!(:name => 'my test community') + c = fast_create(Community) c.tasks << Task.new p = create_user('user_without_tasks').person c.add_member(p) @@ -400,7 +401,7 @@ class PersonTest < Test::Unit::TestCase end should 'person has organization pending tasks' do - c = Community.create!(:name => 'my test community') + c = fast_create(Community) c.tasks << Task.new p = create_user('user_with_tasks').person c.add_admin(p) @@ -409,7 +410,7 @@ class PersonTest < Test::Unit::TestCase end should 'select organization pending tasks' do - c = Community.create!(:name => 'my test community') + c = fast_create(Community) c.tasks << Task.new p = create_user('user_with_tasks').person c.add_admin(p) @@ -505,7 +506,7 @@ class PersonTest < Test::Unit::TestCase should 'refuse join community' do p = create_user('test_user').person - c = Community.create!(:name => 'Test community', :identifier => 'test_community') + c = fast_create(Community) assert p.ask_to_join?(c) p.refuse_join(c) @@ -514,7 +515,7 @@ class PersonTest < Test::Unit::TestCase should 'not ask to join for a member' do p = create_user('test_user').person - c = Community.create!(:name => 'Test community', :identifier => 'test_community') + c = fast_create(Community) c.add_member(p) assert !p.ask_to_join?(c) @@ -522,7 +523,7 @@ class PersonTest < Test::Unit::TestCase should 'not ask to join if already asked' do p = create_user('test_user').person - c = Community.create!(:name => 'Test community', :identifier => 'test_community') + c = fast_create(Community) AddMember.create!(:person => p, :organization => c) assert !p.ask_to_join?(c) diff --git a/test/unit/profile_list_block_test.rb b/test/unit/profile_list_block_test.rb index 6a5b8e1..50ee43e 100644 --- a/test/unit/profile_list_block_test.rb +++ b/test/unit/profile_list_block_test.rb @@ -24,7 +24,8 @@ class ProfileListBlockTest < Test::Unit::TestCase person2 = create_user('testperson2').person person3 = create_user('testperson3').person - owner = Environment.create!(:name => 'test env') + owner = fast_create(Environment) + owner.boxes << Box.new block = ProfileListBlock.new owner.boxes.first.blocks << block block.save! @@ -43,7 +44,8 @@ class ProfileListBlockTest < Test::Unit::TestCase end should 'list private profiles' do - env = Environment.create!(:name => 'test env') + env = fast_create(Environment) + env.boxes << Box.new profile1 = fast_create(Profile, :environment_id => env.id) profile2 = fast_create(Profile, :environment_id => env.id, :public_profile => false) # private profile block = ProfileListBlock.new @@ -56,7 +58,8 @@ class ProfileListBlockTest < Test::Unit::TestCase end should 'not list invisible profiles' do - env = Environment.create!(:name => 'test env') + env = fast_create(Environment) + env.boxes << Box.new profile1 = fast_create(Profile, :environment_id => env.id) profile2 = fast_create(Profile, :environment_id => env.id, :visible => false) # not visible profile block = ProfileListBlock.new @@ -81,7 +84,8 @@ class ProfileListBlockTest < Test::Unit::TestCase end should 'provide view_title' do - env = Environment.create!(:name => 'test env') + env = fast_create(Environment) + env.boxes << Box.new block = ProfileListBlock.new(:title => 'Title from block') env.boxes.first.blocks << block block.save! @@ -89,7 +93,8 @@ class ProfileListBlockTest < Test::Unit::TestCase end should 'provide view title with variables' do - env = Environment.create!(:name => 'test env') + env = fast_create(Environment) + env.boxes << Box.new block = ProfileListBlock.new(:title => '{#} members') env.boxes.first.blocks << block block.save! @@ -97,7 +102,8 @@ class ProfileListBlockTest < Test::Unit::TestCase end should 'count number of public and private profiles' do - env = Environment.create!(:name => 'test env') + env = fast_create(Environment) + env.boxes << Box.new block = ProfileListBlock.new env.boxes.first.blocks << block block.save! @@ -115,7 +121,8 @@ class ProfileListBlockTest < Test::Unit::TestCase end should 'only count number of visible profiles' do - env = Environment.create!(:name => 'test env') + env = fast_create(Environment) + env.boxes << Box.new block = ProfileListBlock.new env.boxes.first.blocks << block block.save! diff --git a/test/unit/published_article_test.rb b/test/unit/published_article_test.rb index 16fb527..3ed9a66 100644 --- a/test/unit/published_article_test.rb +++ b/test/unit/published_article_test.rb @@ -4,12 +4,11 @@ class PublishedArticleTest < ActiveSupport::TestCase def setup @profile = create_user('test_user').person - @article = @profile.articles.create!(:name => 'test_article', :body => 'some trivial body') + @article = fast_create(Article, :profile_id => @profile.id, :name => 'test_article', :body => 'some trivial body') end - should 'have a reference article and profile' do - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') + prof = fast_create(Community) p = PublishedArticle.create(:reference_article => @article, :profile => prof) assert p @@ -18,7 +17,7 @@ class PublishedArticleTest < ActiveSupport::TestCase end should 'have a different name than reference article' do - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') + prof = fast_create(Community) p = PublishedArticle.create(:reference_article => @article, :profile => prof, :name => 'other title') assert_equal 'other title', p.name @@ -27,7 +26,7 @@ class PublishedArticleTest < ActiveSupport::TestCase end should 'use name of reference article a default name' do - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') + prof = fast_create(Community) p = PublishedArticle.create!(:reference_article => @article, :profile => prof) assert_equal @article.name, p.name @@ -37,7 +36,7 @@ class PublishedArticleTest < ActiveSupport::TestCase parent = mock @article.expects(:parent).returns(parent) parent.expects(:blog?).returns(true) - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') + prof = fast_create(Community) p = PublishedArticle.create!(:reference_article => @article, :profile => prof) assert !prof.has_blog? @@ -48,7 +47,7 @@ class PublishedArticleTest < ActiveSupport::TestCase parent = mock @article.expects(:parent).returns(parent) parent.expects(:blog?).returns(true) - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') + prof = fast_create(Community) prof.articles << Blog.new(:profile => prof, :name => 'Blog test') p = PublishedArticle.create!(:reference_article => @article, :profile => prof) @@ -59,8 +58,8 @@ class PublishedArticleTest < ActiveSupport::TestCase parent = mock @article.expects(:parent).returns(parent) parent.expects(:blog?).returns(false) - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') - blog = Blog.create!(:profile => prof, :name => 'Blog test') + prof = fast_create(Community) + blog = fast_create(Blog, :profile_id => prof.id, :name => 'Blog test') p = PublishedArticle.create!(:reference_article => @article, :profile => prof) assert_nil p.parent @@ -78,8 +77,8 @@ class PublishedArticleTest < ActiveSupport::TestCase end should 'have parent if defined' do - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') - folder = Folder.create(:name => 'folder test', :profile => prof) + prof = fast_create(Community) + folder = fast_create(Folder, :name => 'folder test', :profile_id => prof.id) p = PublishedArticle.create(:reference_article => @article, :profile => prof, :parent => folder) assert p @@ -87,23 +86,23 @@ class PublishedArticleTest < ActiveSupport::TestCase end should 'use to_html from reference_article' do - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') + prof = fast_create(Community) p = PublishedArticle.create!(:reference_article => @article, :profile => prof) assert_equal @article.to_html, p.to_html end should 'use to_html from reference_article when is Textile' do - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') - textile_article = TextileArticle.new(:name => 'textile_article', :body => '*my text*', :profile => prof) + prof = fast_create(Community) + textile_article = fast_create(TextileArticle, :name => 'textile_article', :body => '*my text*', :profile_id => prof.id) p = PublishedArticle.create!(:reference_article => textile_article, :profile => prof) assert_equal textile_article.to_html, p.to_html end should 'display message when reference_article does not exist' do - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') - textile_article = TextileArticle.new(:name => 'textile_article', :body => '*my text*', :profile => prof) + prof = fast_create(Community) + textile_article = fast_create(TextileArticle, :name => 'textile_article', :body => '*my text*', :profile_id => prof.id) p = PublishedArticle.create!(:reference_article => textile_article, :profile => prof) textile_article.destroy p.reload @@ -115,17 +114,17 @@ class PublishedArticleTest < ActiveSupport::TestCase parent = mock @article.stubs(:parent).returns(parent) parent.stubs(:blog?).returns(true) - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') + prof = fast_create(Community) prof.articles << Blog.new(:profile => prof, :name => 'Blog test') - new_parent = Folder.create!(:profile => prof, :name => 'Folder test') + new_parent = fast_create(Folder, :profile_id => prof.id, :name => 'Folder test') p = PublishedArticle.create!(:reference_article => @article, :profile => prof, :parent => new_parent) assert_equal p.parent, new_parent end should 'provide first paragraph of HTML version' do - prof = Community.create!(:name => 'test_comm', :identifier => 'test_comm') - a = Article.create!(:name => 'my article', :profile_id => prof.id) + prof = fast_create(Community) + a = fast_create(Article, :name => 'my article', :profile_id => prof.id) a.expects(:body).returns('the first paragraph of the article
The second paragraph') p = PublishedArticle.create(:reference_article => a, :profile => prof) assert_equal 'the first paragraph of the article
', p.first_paragraph diff --git a/test/unit/region_test.rb b/test/unit/region_test.rb index 16b6896..9a1aeb2 100644 --- a/test/unit/region_test.rb +++ b/test/unit/region_test.rb @@ -17,8 +17,8 @@ class RegionTest < Test::Unit::TestCase end should 'be able to search for possible validators by name' do - env = Environment.create!(:name => "my test environment") - region = Region.create!(:environment_id => env.id, :name => 'My Region') + env = fast_create(Environment) + region = fast_create(Region, :environment_id => env.id, :name => 'My Region') org1 = Organization.create!(:name => 'Organization 1', :identifier => 'org1', :environment_id => env.id) org2 = Organization.create!(:name => 'Organization 2', :identifier => 'org2', :environment_id => env.id) @@ -29,10 +29,10 @@ class RegionTest < Test::Unit::TestCase end should 'return search results without validators that are already associated to the current region' do - env = Environment.create!(:name => "my test environment") - region = Region.create!(:environment_id => env.id, :name => 'My Region') - org1 = Organization.create!(:name => 'Organization 1', :identifier => 'org1', :environment_id => env.id) - org2 = Organization.create!(:name => 'Organization 2', :identifier => 'org2', :environment_id => env.id) + env = fast_create(Environment) + region = fast_create(Region, :environment_id => env.id, :name => 'My Region') + org1 = fast_create(Organization, :name => 'Organization 1', :identifier => 'org1', :environment_id => env.id) + org2 = fast_create(Organization, :name => 'Organization 2', :identifier => 'org2', :environment_id => env.id) region.validators << org1 possible = region.search_possible_validators('organization') @@ -41,15 +41,15 @@ class RegionTest < Test::Unit::TestCase end should 'has validator' do - env = Environment.create!(:name => "my test environment") - region = Region.create!(:environment_id => env.id, :name => 'My Region') + env = fast_create(Environment) + region = fast_create(Region, :environment_id => env.id, :name => 'My Region') region.validators.create!(:name => 'Validator entity', :identifier => 'validator-entity') assert region.has_validator? end should 'has no validator' do - env = Environment.create!(:name => "my test environment") - region = Region.create!(:environment_id => env.id, :name => 'My Region') + env = fast_create(Environment) + region = fast_create(Region, :environment_id => env.id, :name => 'My Region') assert !region.has_validator? end diff --git a/test/unit/rss_feed_test.rb b/test/unit/rss_feed_test.rb index 680710a..73c477c 100644 --- a/test/unit/rss_feed_test.rb +++ b/test/unit/rss_feed_test.rb @@ -94,7 +94,7 @@ class RssFeedTest < Test::Unit::TestCase blog = Blog.create!(:name => 'blog-test', :profile => profile) posts = [] 6.times do |i| - posts << TextArticle.create!(:name => "post #{i}", :profile => profile, :parent => blog) + posts << fast_create(TextArticle, :name => "post #{i}", :profile_id => profile.id, :parent_id => blog.id) end feed = blog.feed feed.limit = 5 @@ -108,7 +108,7 @@ class RssFeedTest < Test::Unit::TestCase blog = Blog.create!(:name => 'blog-test', :profile => profile) posts = [] 5.times do |i| - posts << TextArticle.create!(:name => "post #{i}", :profile => profile, :parent => blog) + posts << fast_create(TextArticle, :name => "post #{i}", :profile_id => profile.id, :parent_id => blog.id) end posts[0].published = false posts[0].save! diff --git a/test/unit/text_article_test.rb b/test/unit/text_article_test.rb index 6614191..8573be2 100644 --- a/test/unit/text_article_test.rb +++ b/test/unit/text_article_test.rb @@ -10,7 +10,7 @@ class TextArticleTest < Test::Unit::TestCase should 'found TextileArticle by TextArticle class' do person = create_user('testuser').person - article = TextileArticle.create!(:name => 'textile article test', :profile => person) + article = fast_create(TextileArticle, :name => 'textile article test', :profile_id => person.id) assert_includes TextArticle.find(:all), article end diff --git a/test/unit/uploaded_file_test.rb b/test/unit/uploaded_file_test.rb index c604d02..1ea94d0 100644 --- a/test/unit/uploaded_file_test.rb +++ b/test/unit/uploaded_file_test.rb @@ -87,7 +87,7 @@ class UploadedFileTest < Test::Unit::TestCase should 'create icon when created in folder' do p = create_user('test_user').person - f = Folder.create!(:name => 'test_folder', :profile => p) + f = fast_create(Folder, :name => 'test_folder', :profile_id => p.id) file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :parent_id => f.id, :profile => p) assert File.exists?(file.public_filename(:icon)) diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index d0af632..cda95ac 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -153,7 +153,7 @@ class UserTest < Test::Unit::TestCase end should 'set the same environment for user and person objects' do - env = Environment.create!(:name => 'my test environment') + env = fast_create(Environment) user = new_user(:environment_id => env.id) assert_equal env, user.environment assert_equal env, user.person.environment -- libgit2 0.21.2