From 2eb3df9888358960cc4e1858029659e16177e7d5 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Fri, 11 Dec 2009 16:23:07 -0300 Subject: [PATCH] Speeding up tests some tests --- test/factories.rb | 20 +++++++++++++++++++- test/functional/profile_editor_controller_test.rb | 332 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- test/functional/search_controller_test.rb | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------- 3 files changed, 250 insertions(+), 272 deletions(-) diff --git a/test/factories.rb b/test/factories.rb index 39be342..aa96fc9 100644 --- a/test/factories.rb +++ b/test/factories.rb @@ -163,7 +163,7 @@ module Noosfero::Factory end ############################################### - # Enterprise + # Community ############################################### def defaults_for_community @@ -172,6 +172,15 @@ module Noosfero::Factory end ############################################### + # Person + ############################################### + + def defaults_for_person + n = factory_num_seq.to_s + defaults_for_profile.merge({ :identifier => "person-" + n, :name => 'Person ' + n }) + end + + ############################################### # Profile ############################################### @@ -181,6 +190,15 @@ module Noosfero::Factory end ############################################### + # Organization + ############################################### + + def defaults_for_organization + n = factory_num_seq.to_s + defaults_for_profile.merge({:identifier => 'organization-' + n, :name => 'Organization ' + n}) + end + + ############################################### # Article ############################################### diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index b59b63a..df99e19 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -27,13 +27,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end def test_index - person = create_user('test_profile').person - person.name = 'a test profile' - person.address = 'my address' - person.contact_information = 'my contact information' - person.save! - - get :index, :profile => person.identifier + get :index, :profile => profile.identifier assert_template 'index' assert_response :success assert_not_nil assigns(:profile) @@ -53,15 +47,14 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end def test_edit_person_info - person = create_user('test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person - get :edit, :profile => person.identifier + get :edit, :profile => profile.identifier assert_response :success assert_template 'edit' end should 'saving profile info' do - person = create_user('test_profile').person - post :edit, :profile => 'test_profile', :profile_data => { 'name' => 'new person', 'contact_information' => 'new contact information', 'address' => 'new address', 'sex' => 'female' } + person = profile + post :edit, :profile => profile.identifier, :profile_data => { 'name' => 'new person', 'contact_information' => 'new contact information', 'address' => 'new address', 'sex' => 'female' } assert_redirected_to :action => 'index' person = Person.find(person.id) assert_equal 'new person', person.name @@ -72,15 +65,15 @@ class ProfileEditorControllerTest < Test::Unit::TestCase should 'not permmit if not logged' do logout - person = create_user('test_user') - get :index, :profile => 'test_user' + get :index, :profile => profile.identifier + assert_response 302 end should 'display categories to choose to associate profile' do cat1 = Environment.default.categories.build(:display_in_menu => true, :name => 'top category'); cat1.save! cat2 = Environment.default.categories.build(:display_in_menu => true, :name => 'sub category', :parent => cat1); cat2.save! - person = create_user('test_user').person - get :edit, :profile => 'test_user' + person = profile + get :edit, :profile => profile.identifier assert_response :success assert_template 'edit' assert_tag :tag => 'input', :attributes => {:name => 'profile_data[category_ids][]', :value => cat2.id} @@ -89,114 +82,95 @@ class ProfileEditorControllerTest < Test::Unit::TestCase should 'save categorization of profile' do cat1 = Environment.default.categories.build(:name => 'top category'); cat1.save! cat2 = Environment.default.categories.build(:name => 'sub category', :parent => cat1); cat2.save! - person = create_user('test_user').person - post :edit, :profile => 'test_user', :profile_data => {:category_ids => [cat2.id]} + person = profile + post :edit, :profile => profile.identifier, :profile_data => {:category_ids => [cat2.id]} assert_response :redirect assert_redirected_to :action => 'index' assert_includes person.categories, cat2 end - should 'filter html from name when edit person_info' do - person = create_user('test_profile').person + should 'filter html from person name' do name = "name with html" - post :edit, :profile => person.identifier, :profile_data => { :name => name } + post :edit, :profile => profile.identifier, :profile_data => { :name => name } assert_sanitized assigns(:profile).name end - should 'filter html from contact_person to organization' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) + should 'filter html from organization fields' do + org = fast_create(Organization) contact = "name with html" - post :edit, :profile => org.identifier, :profile_data => { :contact_person => contact } - assert_sanitized assigns(:profile).contact_person - end + acronym = "name with html" + legal_form = "name with html" + economic_activity = "name with html" + management_information = "name with html" - should 'filter html from acronym organization' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) - value = "name with html" - post :edit, :profile => org.identifier, :profile_data => { :acronym => value } - assert_sanitized assigns(:profile).acronym - end + post :edit, :profile => org.identifier, :profile_data => { :name => name, :contact_person => contact, :acronym => acronym, :legal_form => legal_form, :economic_activity => economic_activity, :management_information => management_information} - should 'filter html from legal_form organization' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) - value = "name with html" - post :edit, :profile => org.identifier, :profile_data => { :legal_form => value } + assert_sanitized assigns(:profile).contact_person + assert_sanitized assigns(:profile).acronym assert_sanitized assigns(:profile).legal_form - end - - should 'filter html from economic_activity organization' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) - value = "name with html" - post :edit, :profile => org.identifier, :profile_data => { :economic_activity => value } assert_sanitized assigns(:profile).economic_activity - end - - should 'filter html from management_information organization' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) - value = "name with html" - post :edit, :profile => org.identifier, :profile_data => { :management_information => value } assert_sanitized assigns(:profile).management_information end should 'saving profile organization_info' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) - post :edit, :profile => 'testorg', :profile_data => { :contact_person => 'contact person' } + org = fast_create(Organization) + post :edit, :profile => org.identifier, :profile_data => { :contact_person => 'contact person' } assert_equal 'contact person', Organization.find(org.id).contact_person end should 'show contact_phone field on edit enterprise' do - org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) + org = fast_create(Enterprise) Enterprise.any_instance.expects(:active_fields).returns(['contact_phone']).at_least_once get :edit, :profile => org.identifier assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_phone]' } end should 'save community description' do - org = Community.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) - post :edit, :profile => 'testorg', :profile_data => { :description => 'my description' } + org = fast_create(Community) + post :edit, :profile => org.identifier, :profile_data => { :description => 'my description' } assert_equal 'my description', Organization.find(org.id).description end should 'show community description' do - org = Community.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) + org = fast_create(Community) Community.any_instance.expects(:active_fields).returns(['description']).at_least_once - get :edit, :profile => 'testorg' + get :edit, :profile => org.identifier assert_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' } end should 'not show enterprise description' do - org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) - get :edit, :profile => 'testorg' + org = fast_create(Enterprise) + get :edit, :profile => org.identifier assert_no_tag :tag => 'textarea', :attributes => { :name => 'profile_data[description]' } end should 'save organization contact_person' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg') - post :edit, :profile => 'testorg', :profile_data => { :contact_person => 'my contact' } + org = fast_create(Organization) + post :edit, :profile => org.identifier, :profile_data => { :contact_person => 'my contact' } assert_equal 'my contact', Organization.find(org.id).contact_person end should 'save enterprise contact_person' do - org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) - post :edit, :profile => 'testorg', :profile_data => { :contact_person => 'my contact' } + org = fast_create(Enterprise) + post :edit, :profile => org.identifier, :profile_data => { :contact_person => 'my contact' } assert_equal 'my contact', Enterprise.find(org.id).contact_person end should 'show field values on edit community info' do Community.any_instance.expects(:active_fields).returns(['contact_person']).at_least_once - org = Community.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) + org = fast_create(Community) org.contact_person = 'my contact' org.save! - get :edit, :profile => 'testorg' + get :edit, :profile => org.identifier assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]', :value => 'my contact' } end should 'show field values on edit enterprise info' do Enterprise.any_instance.expects(:active_fields).returns(['contact_person']).at_least_once - org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) + org = fast_create(Enterprise) org.contact_person = 'my contact' org.save! - get :edit, :profile => 'testorg' + get :edit, :profile => org.identifier assert_tag :tag => 'input', :attributes => { :name => 'profile_data[contact_person]', :value => 'my contact' } end @@ -225,40 +199,38 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'show error messages for invalid foundation_year' do - org = Community.create!(:name => 'test org', :identifier => 'testorg', :environment => Environment.default) - post :edit, :profile => 'testorg', :profile_data => { :foundation_year => 'aaa' } + org = fast_create(Community) + post :edit, :profile => org.identifier, :profile_data => { :foundation_year => 'aaa' } assert_tag :tag => 'div', :attributes => { :id => 'errorExplanation' } end should 'edit enterprise' do - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :environment => Environment.default) - get :edit, :profile => 'testent' + ent = fast_create(Enterprise) + get :edit, :profile => ent.identifier assert_response :success end should 'back when update community info fail' do - org = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) + org = fast_create(Community) Community.any_instance.stubs(:update_attributes!).returns(false) - post :edit, :profile => 'testorg' + post :edit, :profile => org.identifier assert_template 'edit' end should 'back when update enterprise info fail' do - org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) + org = fast_create(Enterprise) Enterprise.any_instance.stubs(:update_attributes!).returns(false) - post :edit, :profile => 'testorg' + post :edit, :profile => org.identifier assert_template 'edit' end should 'show edit profile button' do - person = create_user('testuser').person - get :index, :profile => 'testuser' - assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testuser/profile_editor/edit' } + get :index, :profile => profile.identifier + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/profile_editor/edit" } end should 'show image field on edit profile' do - person = create_user('testuser').person - get :edit, :profile => 'testuser' + get :edit, :profile => profile.identifier assert_tag :tag => 'input', :attributes => { :name => 'profile_data[image_builder][uploaded_data]' } end @@ -271,13 +243,12 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'render edit template' do - person = create_user('test_profile').person - get :edit, :profile => person.identifier + get :edit, :profile => profile.identifier assert_template 'edit' end should 'render person partial' do - person = create_user('test_profile', :environment => Environment.default).person + person = profile Person.any_instance.expects(:active_fields).returns(['contact_phone', 'address']).at_least_once get :edit, :profile => person.identifier person.active_fields.each do |field| @@ -287,70 +258,73 @@ class ProfileEditorControllerTest < Test::Unit::TestCase should 'display only active person fields' do Person.any_instance.expects(:active_fields).returns(['cell_phone']).at_least_once - person = create_user('test_profile').person - get :edit, :profile => person.identifier + get :edit, :profile => profile.identifier assert_tag :tag => 'input', :attributes => { :name => "profile_data[cell_phone]" } assert_no_tag :tag => 'input', :attributes => { :name => "profile_data[comercial_phone]" } end should 'be able to upload an image' do - person = create_user('test_profile').person - assert_nil person.image - post :edit, :profile => 'test_profile', :profile_data => { :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } } + assert_nil profile.image + post :edit, :profile => profile.identifier, :profile_data => { :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } } assert_not_nil assigns(:profile).image end should 'display closed attribute for communities when it is set' do - org = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => true, :environment => Environment.default) - get :edit, :profile => 'testorg' + org = fast_create(Community) + org.closed = true + org.save! + + get :edit, :profile => org.identifier assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' } assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' } end should 'display closed attribute for communities when it is set to false' do - org = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => false) - get :edit, :profile => 'testorg' - assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' } - assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' } - end - - should 'display closed attribute for communities when it is set to nothing at all' do - org = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => nil) - get :edit, :profile => 'testorg' - assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' } - assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' } + org = fast_create(Community) + + [false, nil].each do |value| + org.closed = value + org.save! + get :edit, :profile => org.identifier + assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true', :checked => 'checked' } + assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false', :checked => 'checked' } + end end should 'set closed attribute correctly' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => false) + org = fast_create(Organization) + org.closed = false + org.save! - post :edit, :profile => 'testorg', :profile_data => { :closed => 'true' } + post :edit, :profile => org.identifier, :profile_data => { :closed => 'true' } org.reload assert org.closed end should 'unset closed attribute correctly' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :closed => true) + org = fast_create(Organization) + org.closed = true + org.save! - post :edit, :profile => 'testorg', :profile_data => { :closed => 'false' } + post :edit, :profile => org.identifier, :profile_data => { :closed => 'false' } org.reload assert !org.closed end should 'not display option to close when it is enterprise' do - org = Enterprise.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) - get :edit, :profile => 'testorg' + org = fast_create(Enterprise) + get :edit, :profile => org.identifier assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true' } assert_no_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false' } end should 'display option to close when it is community' do - org = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) - get :edit, :profile => 'testorg' + org = fast_create(Community) + get :edit, :profile => org.identifier assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'true' } assert_tag :tag => 'input', :attributes => { :type => 'radio', :name => 'profile_data[closed]', :value => 'false' } @@ -358,26 +332,26 @@ class ProfileEditorControllerTest < Test::Unit::TestCase should 'display manage members options if has permission' do profile = Profile['ze'] - community = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) + community = fast_create(Community) @controller.stubs(:user).returns(profile) @controller.stubs(:profile).returns(community) profile.stubs(:has_permission?).returns(true) - get :index, :profile => 'testorg' + get :index, :profile => community.identifier assert_tag :tag => 'a', :content => 'Manage Members' end should 'not display manage members options if has no permission' do profile = Profile['ze'] - community = Community.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact', :environment => Environment.default) + community = fast_create(Community) @controller.stubs(:user).returns(profile) @controller.stubs(:profile).returns(community) profile.stubs(:has_permission?).returns(false) - get :index, :profile => 'testorg' + get :index, :profile => community.identifier assert_no_tag :tag => 'a', :content => 'Manage Members' end should 'render enterprise partial' do - ent = Enterprise.create(:name => 'test_profile', :identifier => 'testorg', :environment => Environment.default) + ent = fast_create(Enterprise) Enterprise.any_instance.expects(:active_fields).returns(['contact_phone', 'contact_person', 'contact_email']).at_least_once get :edit, :profile => ent.identifier ent.active_fields.each do |field| @@ -386,7 +360,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'render community partial' do - community = Community.create(:name => 'test_profile', :identifier => 'testorg', :environment => Environment.default) + community = fast_create(Community) Community.any_instance.expects(:active_fields).returns(['contact_person', 'language']).at_least_once get :edit, :profile => community.identifier community.active_fields.each do |field| @@ -395,7 +369,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'show task if user has permission' do - user1 = create_user('userone').person + user1 = profile user2 = create_user('usertwo').person AddFriend.create!(:person => user1, :friend => user2) @controller.stubs(:user).returns(user2) @@ -407,7 +381,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'not show task if user has no permission' do - user1 = create_user('userone').person + user1 = profile user2 = create_user('usertwo').person task = AddFriend.create!(:person => user1, :friend => user2) @controller.stubs(:user).returns(user2) @@ -419,14 +393,13 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'show favorite enterprises button for person' do - person = create_user('testuser').person - get :index, :profile => 'testuser' + get :index, :profile => profile.identifier assert_tag :tag => 'a', :content => 'Favorite Enterprises' end should 'not show favorite enterprises button for organization' do - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact') - get :index, :profile => 'testorg' + org = fast_create(Organization) + get :index, :profile => org.identifier assert_no_tag :tag => 'a', :content => 'Favorite Enterprises' end @@ -438,8 +411,8 @@ class ProfileEditorControllerTest < Test::Unit::TestCase should 'not link to mailconf for organizations' do MailConf.stubs(:enabled?).returns(true).at_least_once - org = Organization.create!(:name => 'test org', :identifier => 'testorg', :contact_person => 'my contact') - get :index, :profile => 'testorg' + org = fast_create(Organization) + get :index, :profile => org.identifier assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/testorg/mailconf' } end @@ -450,50 +423,50 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'link to enable enterprise' do - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false, :environment => Environment.default) - get :index, :profile => 'testent' - assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testent/profile_editor/enable' } + ent = fast_create(Enterprise, :enabled => false) + get :index, :profile => ent.identifier + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{ent.identifier}/profile_editor/enable" } end should 'link to disable enterprise' do - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true, :environment => Environment.default) - get :index, :profile => 'testent' - assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testent/profile_editor/disable' } + ent = fast_create(Enterprise, :enabled => true) + get :index, :profile => ent.identifier + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{ent.identifier}/profile_editor/disable" } end should 'not link to enable/disable for non enterprises' do - ent = Organization.create!(:name => 'test org', :identifier => 'testorg', :enabled => true) - get :index, :profile => 'testorg' - assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/testorg/profile_editor/disable' } + ent = fast_create(Organization, :enabled => true) + get :index, :profile => ent.identifier + assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/#{ent.identifier}/profile_editor/disable" } end should 'request enable enterprise confirmation' do - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false, :environment => Environment.default) - get :enable, :profile => 'testent' - assert_tag :tag => 'form', :attributes => { :action => '/myprofile/testent/profile_editor/enable', :method => 'post' } + ent = fast_create(Enterprise, :enabled => false) + get :enable, :profile => ent.identifier + assert_tag :tag => 'form', :attributes => { :action => "/myprofile/#{ent.identifier}/profile_editor/enable", :method => 'post' } end should 'enable enterprise after confirmation' do - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false, :environment => Environment.default) - post :enable, :profile => 'testent', :confirmation => 1 + ent = fast_create(Enterprise, :enabled => false) + post :enable, :profile => ent.identifier, :confirmation => 1 assert assigns(:to_enable).enabled? end should 'not enable enterprise without confirmation' do - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => false, :environment => Environment.default) - post :enable, :profile => 'testent' + ent = fast_create(Enterprise, :enabled => false) + post :enable, :profile => ent.identifier assert !assigns(:to_enable).enabled? end should 'disable enterprise after confirmation' do - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true, :environment => Environment.default) - post :disable, :profile => 'testent', :confirmation => 1 + ent = fast_create(Enterprise, :enabled => true) + post :disable, :profile => ent.identifier, :confirmation => 1 assert !assigns(:to_disable).enabled? end should 'not disable enterprise without confirmation' do - ent = Enterprise.create!(:name => 'test org', :identifier => 'testent', :enabled => true, :environment => Environment.default) - post :disable, :profile => 'testent' + ent = fast_create(Enterprise, :enabled => true) + post :disable, :profile => ent.identifier assert assigns(:to_disable).enabled? end @@ -509,45 +482,43 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'display manage my groups button for person' do - person = create_user('testuser').person - get :index, :profile => 'testuser' + get :index, :profile => profile.identifier assert_tag :tag => 'a', :content => 'Manage my groups' end should 'display footer edit screen' do - person = create_user('designtestuser').person + person = profile person.custom_header = 'my custom header' person.custom_footer = 'my custom footer' person.save! - get :header_footer, :profile => 'designtestuser' + get :header_footer, :profile => profile.identifier assert_tag :tag => 'textarea', :content => 'my custom header' assert_tag :tag => 'textarea', :content => 'my custom footer' end should 'save footer and header' do - person = create_user('designtestuser').person - post :header_footer, :profile => 'designtestuser', :custom_header => 'new header', :custom_footer => 'new footer' + person = profile + post :header_footer, :profile => profile.identifier, :custom_header => 'new header', :custom_footer => 'new footer' person = Person.find(person.id) assert_equal 'new header', person.custom_header assert_equal 'new footer', person.custom_footer end should 'save header and footer even if model is invalid' do - person = create_user('designtestuser').person + person = profile person.sex = nil; person.save! person.environment.custom_person_fields = {'sex' => {'required' => 'true', 'active' => 'true'} }; person.environment.save! - post :header_footer, :profile => 'designtestuser', :custom_header => 'new header', :custom_footer => 'new footer' + post :header_footer, :profile => profile.identifier, :custom_header => 'new header', :custom_footer => 'new footer' person = Person.find(person.id) assert_equal 'new header', person.custom_header assert_equal 'new footer', person.custom_footer end should 'go back to editor after saving header/footer' do - person = create_user('designtestuser').person - post :header_footer, :profile => 'designtestuser', :custom_header => 'new header', :custom_footer => 'new footer' + post :header_footer, :profile => profile.identifier, :custom_header => 'new header', :custom_footer => 'new footer' assert_redirected_to :action => 'index' end @@ -561,13 +532,13 @@ class ProfileEditorControllerTest < Test::Unit::TestCase env.enable('disable_header_and_footer') env.save! - enterprise = Enterprise.create!(:name => 'Enterprise for test', :identifier => 'enterprise_for_test') + enterprise = fast_create(Enterprise) u = create_user_with_permission('test_user', 'edit_profile', enterprise) login_as('test_user') get :index, :profile => enterprise.identifier - assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/enterprise_for_test/profile_editor/header_footer" } + assert_no_tag :tag => 'a', :attributes => { :href => "/myprofile/#{enterprise.identifier}/profile_editor/header_footer" } end should 'display header/footer button to enterprises if the environment disabled it but user is admin' do @@ -575,59 +546,55 @@ class ProfileEditorControllerTest < Test::Unit::TestCase env.enable('disable_header_and_footer') env.save! - enterprise = Enterprise.create!(:name => 'Enterprise for test', :identifier => 'enterprise_for_test') + enterprise = fast_create(Enterprise) Person.any_instance.expects(:is_admin?).returns(true).at_least_once get :index, :profile => enterprise.identifier - assert_tag :tag => 'a', :attributes => { :href => "/myprofile/enterprise_for_test/profile_editor/header_footer" } + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{enterprise.identifier}/profile_editor/header_footer" } end should 'not list the manage products button if the environment disabled it' do env = Environment.default env.enable('disable_products_for_enterprises') env.save! - ent = Enterprise.create!(:name => 'test enterprise', :identifier => 'test_ent', :environment => env) + ent = fast_create(Enterprise) u = create_user_with_permission('test_user', 'edit_profile', ent) login_as('test_user') - get :index, :profile => 'test_ent' + get :index, :profile => ent.identifier assert_no_tag :tag => 'span', :content => 'Manage Products and Services' end should 'display categories if environment disable_categories disabled' do Environment.any_instance.stubs(:enabled?).with(anything).returns(false) - person = create_user('test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person - get :edit, :profile => person.identifier + get :edit, :profile => profile.identifier assert_tag :tag => 'div', :descendant => { :tag => 'h2', :content => 'Select the categories of your interest' } end should 'not display categories if environment disable_categories enabled' do Environment.any_instance.stubs(:enabled?).with(anything).returns(true) - person = create_user('test_profile', :email => 'test@noosfero.org', :password => 'test', :password_confirmation => 'test').person - get :edit, :profile => person.identifier + get :edit, :profile => profile.identifier assert_no_tag :tag => 'div', :descendant => { :tag => 'h2', :content => 'Select the categories of your interest' } end should 'show a e-mail field in profile editor' do - create_user('test_user', :email=>'teste_user@teste.com') - login_as('test_user') - get :edit, :profile => 'test_user' + get :edit, :profile => profile.identifier assert_tag :tag => 'input', - :attributes => { :name=>'profile_data[email]', :value=>'teste_user@teste.com' } + :attributes => { :name=>'profile_data[email]', :value => profile.email } end should 'display enable contact us for enterprise' do - org = Enterprise.create!(:name => 'test org', :identifier => 'testorg') - get :edit, :profile => 'testorg' + org = fast_create(Enterprise) + get :edit, :profile => org.identifier assert_tag :tag => 'input', :attributes => {:name => 'profile_data[enable_contact_us]', :type => 'checkbox'} end should 'display link to CMS' do - get :index, :profile => 'default_user' + get :index, :profile => profile.identifier assert_tag :tag => 'a', :attributes => { :href => '/myprofile/default_user/cms' } end @@ -635,20 +602,20 @@ class ProfileEditorControllerTest < Test::Unit::TestCase env = Environment.default env.enable('disable_cms') env.save! - get :index, :profile => 'default_user' + get :index, :profile => profile.identifier assert_no_tag :tag => 'a', :attributes => { :href => '/myprofile/default_user/cms' } end should 'offer to create blog in control panel' do - get :index, :profile => 'default_user' + get :index, :profile => profile.identifier assert_tag :tag => 'a', :attributes => { :href => "/myprofile/default_user/cms/new?type=Blog" } end should 'offer to config blog in control panel' do profile.articles << Blog.new(:name => 'My blog', :profile => profile) get :index, :profile => profile.identifier - assert_tag :tag => 'a', :attributes => { :href => "/myprofile/default_user/cms/edit/#{profile.blog.id}" } + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/cms/edit/#{profile.blog.id}" } end should 'not show select preferred domain if not enabled in environment' do @@ -688,7 +655,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase should 'not be able to upload an image bigger than max size' do Image.any_instance.stubs(:size).returns(Image.attachment_options[:max_size] + 1024) - person = create_user('test_profile').person + person = profile assert_nil person.image post :edit, :profile => person.identifier, :profile_data => { :image_builder => { :uploaded_data => fixture_file_upload('/files/rails.png', 'image/png') } } assert_nil person.image @@ -736,7 +703,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase env.enable('enterprise_activation') env.save! - enterprise = Enterprise.create!(:name => 'bli', :identifier => 'bli') + enterprise = fast_create(Enterprise) enterprise.add_admin(profile) get :index, :profile => enterprise.identifier @@ -744,7 +711,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'have url field for identifier when environment allows' do - c = Community.create!(:name => 'test community', :identifier => 'test_comm') + c = fast_create(Community) env = c.environment env.enable('enable_organization_url_change') env.save! @@ -757,7 +724,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'not have url field for identifier when environment not allows' do - c = Community.create!(:name => 'test community', :identifier => 'test_comm') + c = fast_create(Community) env = c.environment env.disable('enable_organization_url_change') env.save! @@ -770,14 +737,14 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'redirect to new url when is changed' do - c = Community.create!(:name => 'test community', :identifier => 'test_comm') + c = fast_create(Community) post :edit, :profile => c.identifier, :profile_data => {:identifier => 'new_address'} assert_response :redirect assert_redirected_to :action => 'index', :profile => 'new_address' end should 'not crash if identifier is left blank' do - c = Community.create!(:name => 'test community', :identifier => 'test_comm') + c = fast_create(Community) assert_nothing_raised do post :edit, :profile => c.identifier, :profile_data => c.attributes.merge('identifier' => '') end @@ -791,7 +758,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase 'contact_phone' => {'active' => 'true', 'required' => 'false'} } env.save! - community = Community.create(:name => 'test_profile') + community = fast_create(Community) get :edit, :profile => community.identifier @@ -807,7 +774,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase 'contact_phone' => {'active' => 'false', 'required' => 'false'} } env.save! - community = Community.create(:name => 'test_profile') + community = fast_create(Community) get :edit, :profile => community.identifier @@ -817,18 +784,17 @@ class ProfileEditorControllerTest < Test::Unit::TestCase end should 'show profile nickname on title' do - person = create_user('testuser', {}, :nickname => 'my nick').person - get :index, :profile => 'testuser' + profile.update_attributes(:nickname => 'my nick') + get :index, :profile => profile.identifier assert_tag :tag => 'h1', :attributes => { :class => 'block-title'}, :descendant => { :tag => 'span', :attributes => { :class => 'control-panel-title' }, :content => 'my nick' } end should 'show profile name on title when no nickname' do - person = create_user('testuser').person - get :index, :profile => 'testuser' + get :index, :profile => profile.identifier assert_tag :tag => 'h1', :attributes => { :class => 'block-title'}, :descendant => { - :tag => 'span', :attributes => { :class => 'control-panel-title' }, :content => 'testuser' + :tag => 'span', :attributes => { :class => 'control-panel-title' }, :content => profile.identifier } end diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index f77ee37..11b4798 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -11,8 +11,20 @@ class SearchControllerTest < Test::Unit::TestCase @response = ActionController::TestResponse.new @category = Category.create!(:name => 'my category', :environment => Environment.default) - Profile.rebuild_index - Article.rebuild_index + end + + def create_article_with_optional_category(name, profile, category = nil) + article = fast_create(Article, :name => name, :profile_id => profile.id) + article.add_category(category) if category + article.ferret_create + article + end + + def create_profile_with_optional_category(klass, name, category = nil, data = {}) + profile = fast_create(klass, { :name => name }.merge(data)) + profile.add_category(category) if category + profile.ferret_create + profile end def test_local_files_reference @@ -54,25 +66,20 @@ class SearchControllerTest < Test::Unit::TestCase end should 'search for articles' do - person = create_user('teste').person - art = person.articles.build(:name => 'an article to be found'); art.save! + person = fast_create(Person) + art = create_article_with_optional_category('an article to be found', person) get 'index', :query => 'article found', :find_in => [ 'articles' ] - assert_includes assigns(:results)[:articles], art end should 'search for articles in a specific category' do - person = create_user('teste').person + person = fast_create(Person) # in category - art1 = person.articles.build(:name => 'an article to be found') - art1.add_category @category - art1.save! - + art1 = create_article_with_optional_category('an article to be found', person, @category) # not in category - art2 = person.articles.build(:name => 'another article to be found') - art2.save! + art2 = create_article_with_optional_category('another article to be found', person) get :index, :category_path => [ 'my-category' ], :query => 'article found', :find_in => [ 'articles' ] @@ -82,12 +89,10 @@ class SearchControllerTest < Test::Unit::TestCase # 'assets' outside any category should 'list articles in general' do - person = create_user('testuser').person - person2 = create_user('anotheruser').person + person = fast_create(Person) - art1 = person.articles.create!(:name => 'one article', :category_ids => [@category.id]) - - art2 = person2.articles.create!(:name => 'two article', :category_ids => [@category.id]) + art1 = create_article_with_optional_category('one article', person, @category) + art2 = create_article_with_optional_category('two article', person, @category) get :assets, :asset => 'articles' @@ -97,14 +102,13 @@ class SearchControllerTest < Test::Unit::TestCase # 'assets' inside a category should 'list articles in a specific category' do - person = create_user('testuser').person + person = fast_create(Person) # in category - art1 = person.articles.create!(:name => 'one article', :category_ids => [@category.id]) - art2 = person.articles.create!(:name => 'other article', :category_ids => [@category.id]) - + art1 = create_article_with_optional_category('one article', person, @category) + art2 = create_article_with_optional_category('two article', person, @category) # not in category - art3 = person.articles.create!(:name => 'another article') + art3 = create_article_with_optional_category('another article', person) get :assets, :asset => 'articles', :category_path => ['my-category'] @@ -114,7 +118,7 @@ class SearchControllerTest < Test::Unit::TestCase end should 'find enterprises' do - ent = Enterprise.create!(:name => 'teste', :identifier => 'teste') + ent = create_profile_with_optional_category(Enterprise, 'teste') get 'index', :query => 'teste', :find_in => [ 'enterprises' ] assert_includes assigns(:results)[:enterprises], ent end @@ -122,10 +126,9 @@ class SearchControllerTest < Test::Unit::TestCase should 'find enterprises in a specified category' do # in category - ent1 = Enterprise.create!(:name => 'testing enterprise 1', :identifier => 'test1', :category_ids => [@category.id]) - + ent1 = create_profile_with_optional_category(Enterprise, 'testing enterprise 1', @category) # not in category - ent2 = Enterprise.create!(:name => 'testing enterprise 2', :identifier => 'test2') + ent2 = create_profile_with_optional_category(Enterprise, 'testing enterprise 2') get :index, :category_path => [ 'my-category' ], :query => 'testing', :find_in => [ 'enterprises' ] @@ -134,8 +137,8 @@ class SearchControllerTest < Test::Unit::TestCase end should 'list enterprises in general' do - ent1 = Enterprise.create!(:name => 'teste 1', :identifier => 'teste1') - ent2 = Enterprise.create!(:name => 'teste 2', :identifier => 'teste2') + ent1 = create_profile_with_optional_category(Enterprise, 'teste 1') + ent2 = create_profile_with_optional_category(Enterprise, 'teste 2') get :assets, :asset => 'enterprises' assert_includes assigns(:results)[:enterprises], ent1 @@ -145,10 +148,9 @@ class SearchControllerTest < Test::Unit::TestCase # 'assets' menu inside a category should 'list enterprises in a specified category' do # in category - ent1 = Enterprise.create!(:name => 'teste 1', :identifier => 'teste1', :category_ids => [@category.id]) - + ent1 = create_profile_with_optional_category(Enterprise, 'teste 1', @category) # not in category - ent2 = Enterprise.create!(:name => 'teste 2', :identifier => 'teste2') + ent2 = create_profile_with_optional_category(Enterprise, 'teste 2') get :assets, :asset => 'enterprises', :category_path => [ 'my-category' ] assert_includes assigns(:results)[:enterprises], ent1 @@ -196,15 +198,14 @@ class SearchControllerTest < Test::Unit::TestCase end should 'find communities' do - c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) + c1 = create_profile_with_optional_category(Community, 'a beautiful community') get :index, :query => 'beautiful', :find_in => [ 'communities' ] assert_includes assigns(:results)[:communities], c1 end should 'find communities in a specified category' do - c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) - c2 = Community.create!(:name => 'another beautiful community', :identifier => 'an_bea_comm', :environment => Environment.default) - c1.add_category @category; c1.save! + c1 = create_profile_with_optional_category(Community, 'a beautiful community', @category) + c2 = create_profile_with_optional_category(Community, 'another beautiful community') get :index, :category_path => [ 'my-category' ], :query => 'beautiful', :find_in => [ 'communities' ] assert_includes assigns(:results)[:communities], c1 assert_not_includes assigns(:results)[:communities], c2 @@ -212,8 +213,8 @@ class SearchControllerTest < Test::Unit::TestCase # 'assets' menu outside any category should 'list communities in general' do - c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) - c2 = Community.create!(:name => 'another beautiful community', :identifier => 'an_bea_comm', :environment => Environment.default) + c1 = create_profile_with_optional_category(Community, 'a beautiful community') + c2 = create_profile_with_optional_category(Community, 'another beautiful community') get :assets, :asset => 'communities' assert_equivalent [c2, c1], assigns(:results)[:communities] @@ -223,15 +224,13 @@ class SearchControllerTest < Test::Unit::TestCase should 'list communities in a specified category' do # in category - c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) - c1.add_category @category + c1 = create_profile_with_optional_category(Community, 'a beautiful community', @category) # not in category - c2 = Community.create!(:name => 'another beautiful community', :identifier => 'an_bea_comm', :environment => Environment.default) + c2 = create_profile_with_optional_category(Community, 'another beautiful community') # in category - c3 = Community.create!(:name => 'yet another beautiful community', :identifier => 'yet_an_bea_comm', :environment => Environment.default) - c3.add_category @category + c3 = create_profile_with_optional_category(Community, 'yet another beautiful community', @category) get :assets, :asset => 'communities', :category_path => [ 'my-category' ] @@ -239,22 +238,22 @@ class SearchControllerTest < Test::Unit::TestCase end should 'find communities in signup wizard' do - c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) + c1 = create_profile_with_optional_category(Community, 'a beautiful community') get :index, :query => 'beautiful', :find_in => [ 'communities' ], :wizard => true assert_includes assigns(:results)[:communities], c1 assert_equal 'layouts/wizard', @response.layout end should 'find products' do - ent = Enterprise.create!(:name => 'teste', :identifier => 'teste') + ent = create_profile_with_optional_category(Enterprise, 'teste') prod = ent.products.create!(:name => 'a beautiful product') get 'index', :query => 'beautiful', :find_in => ['products'] assert_includes assigns(:results)[:products], prod end should 'find products in a specific category' do - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1', :category_ids => [@category.id]) - ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2') + ent1 = create_profile_with_optional_category(Enterprise, 'teste1', @category) + ent2 = create_profile_with_optional_category(Enterprise, 'teste2') prod1 = ent1.products.create!(:name => 'a beautiful product') prod2 = ent2.products.create!(:name => 'another beautiful product') get :index, :category_path => @category.path.split('/'), :query => 'beautiful', :find_in => ['products'] @@ -266,8 +265,8 @@ class SearchControllerTest < Test::Unit::TestCase should 'list products in general' do Profile.delete_all - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1') - ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2') + ent1 = create_profile_with_optional_category(Enterprise, 'teste1') + ent2 = create_profile_with_optional_category(Enterprise, 'teste2') prod1 = ent1.products.create!(:name => 'a beautiful product') prod2 = ent2.products.create!(:name => 'another beautiful product') @@ -280,11 +279,11 @@ class SearchControllerTest < Test::Unit::TestCase Profile.delete_all # in category - ent1 = Enterprise.create!(:name => 'teste1', :identifier => 'teste1'); ent1.add_category @category + ent1 = create_profile_with_optional_category(Enterprise, 'teste1', @category) prod1 = ent1.products.create!(:name => 'a beautiful product') # not in category - ent2 = Enterprise.create!(:name => 'teste2', :identifier => 'teste2') + ent2 = create_profile_with_optional_category(Enterprise, 'teste2') prod2 = ent2.products.create!(:name => 'another beautiful product') get :assets, :asset => 'products', :category_path => [ 'my-category' ] @@ -294,8 +293,8 @@ class SearchControllerTest < Test::Unit::TestCase should 'paginate enterprise listing' do @controller.expects(:limit).returns(1) - ent1 = Enterprise.create!(:name => 'teste 1', :identifier => 'teste_1') - ent2 = Enterprise.create!(:name => 'teste 2', :identifier => 'teste_2') + ent1 = create_profile_with_optional_category(Enterprise, 'teste 1') + ent2 = create_profile_with_optional_category(Enterprise, 'teste 2') get :assets, :asset => 'enterprises', :page => '2' @@ -303,13 +302,13 @@ class SearchControllerTest < Test::Unit::TestCase end should 'display search results' do - ent = Enterprise.create!(:name => 'display enterprise', :identifier => 'teste1') + ent = create_profile_with_optional_category(Enterprise, 'display enterprise') product = ent.products.create!(:name => 'display product') person = create_user('displayperson').person; person.name = 'display person'; person.save! article = person.articles.create!(:name => 'display article') event = Event.new(:name => 'display event', :start_date => Date.today); event.profile = person; event.save! comment = article.comments.create!(:title => 'display comment', :body => '...', :author => person) - community = Community.create!(:name => 'display community', :identifier => 'an_bea_comm') + community = create_profile_with_optional_category(Community, 'display community') get :index, :query => 'display' @@ -320,8 +319,8 @@ class SearchControllerTest < Test::Unit::TestCase :products => ['Products', product], :events => ['Events', event], } - names.each do |thing, description| - description, object = description + names.each do |thing, pair| + description, object = pair assert_tag :tag => 'div', :attributes => { :class => /search-results-#{thing}/ }, :descendant => { :tag => 'h3', :content => Regexp.new(description) } assert_tag :tag => 'a', :content => object.respond_to?(:short_name) ? object.short_name : object.name end @@ -507,9 +506,7 @@ class SearchControllerTest < Test::Unit::TestCase parent = Category.create!(:name => 'Parent Category', :environment => Environment.default) child = Category.create!(:name => 'Child Category', :environment => Environment.default, :parent => parent) - p = create_user('test_profile').person - p.add_category child - p.save! + p = create_profile_with_optional_category(Person, 'test_profile', child) get :index, :category_path => ['parent-category'], :query => 'test_profile', :find_in => ['people'] @@ -526,11 +523,11 @@ class SearchControllerTest < Test::Unit::TestCase end should 'find enterprise by product category' do - ent1 = Enterprise.create!(:name => 'test1', :identifier => 'test1') + ent1 = create_profile_with_optional_category(Enterprise, 'test1') prod_cat = ProductCategory.create!(:name => 'pctest', :environment => Environment.default) prod = ent1.products.create!(:name => 'teste', :product_category => prod_cat) - ent2 = Enterprise.create!(:name => 'test2', :identifier => 'test2') + ent2 = create_profile_with_optional_category(Enterprise, 'test2') get :index, :query => prod_cat.name @@ -540,12 +537,11 @@ class SearchControllerTest < Test::Unit::TestCase should 'find profiles by radius and region' do city = City.create!(:name => 'r-test', :environment => Environment.default, :lat => 45.0, :lng => 45.0) - ent1 = Enterprise.create!(:name => 'test 1', :identifier => 'test1', :lat => 45.0, :lng => 45.0) - p1 = create_user('test2').person - p1.name = 'test 2'; p1.lat = 45.0; p1.lng = 45.0; p1.save! - ent2 = Enterprise.create!(:name => 'test 3', :identifier => 'test3', :lat => 30.0, :lng => 30.0) - p2 = create_user('test4').person - p2.name = 'test 4'; p2.lat = 30.0; p2.lng = 30.0; p2.save! + ent1 = create_profile_with_optional_category(Enterprise, 'test 1', nil, :lat => 45.0, :lng => 45.0) + p1 = create_profile_with_optional_category(Person, 'test 2', nil, :lat => 45.0, :lng => 45.0) + + ent2 = create_profile_with_optional_category(Enterprise, 'test 1', nil, :lat => 30.0, :lng => 30.0) + p2 = create_profile_with_optional_category(Person, 'test 2', nil, :lat => 30.0, :lng => 30.0) get :index, :city => city.id, :radius => 10, :query => 'test' @@ -732,7 +728,7 @@ class SearchControllerTest < Test::Unit::TestCase should 'list only categories with products' do cat1 = ProductCategory.create!(:name => 'pc test 1', :environment => Environment.default) cat2 = ProductCategory.create!(:name => 'pc test 2', :environment => Environment.default) - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') + ent = create_profile_with_optional_category(Enterprise, 'test ent') cat1.products.create!(:name => 'prod test 1', :enterprise => ent) @@ -744,7 +740,7 @@ class SearchControllerTest < Test::Unit::TestCase should 'display only within a product category when specified' do prod_cat = ProductCategory.create!(:name => 'prod cat test', :environment => Environment.default) - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') + ent = create_profile_with_optional_category(Enterprise, 'test ent') p = prod_cat.products.create!(:name => 'prod test 1', :enterprise => ent) @@ -757,7 +753,7 @@ class SearchControllerTest < Test::Unit::TestCase cat = Category.create(:name => 'cat', :environment => Environment.default) prod_cat1 = ProductCategory.create!(:name => 'prod cat test 1', :environment => Environment.default) prod_cat2 = ProductCategory.create!(:name => 'prod cat test 2', :environment => Environment.default, :parent => prod_cat1) - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent', :category_ids => [cat.id]) + ent = create_profile_with_optional_category(Enterprise, 'test ent', cat) p = prod_cat2.products.create!(:name => 'prod test 1', :enterprise => ent) @@ -769,7 +765,7 @@ class SearchControllerTest < Test::Unit::TestCase should 'display only top level product categories that has products when no product category filter is specified' do cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) cat2 = ProductCategory.create(:name => 'prod cat 2', :environment => Environment.default) - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') + ent = create_profile_with_optional_category(Enterprise, 'test ent') p = cat1.products.create!(:name => 'prod test 1', :enterprise => ent) get :index, :find_in => 'products' @@ -782,7 +778,7 @@ class SearchControllerTest < Test::Unit::TestCase cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) cat11 = ProductCategory.create(:name => 'prod cat 11', :environment => Environment.default, :parent => cat1) cat12 = ProductCategory.create(:name => 'prod cat 12', :environment => Environment.default, :parent => cat1) - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') + ent = create_profile_with_optional_category(Enterprise, 'test ent') p = cat11.products.create!(:name => 'prod test 1', :enterprise => ent) get :index, :find_in => 'products', :product_category => cat1.id @@ -794,7 +790,7 @@ class SearchControllerTest < Test::Unit::TestCase should 'list only product categories with enterprises' do cat1 = ProductCategory.create!(:name => 'pc test 1', :environment => Environment.default) cat2 = ProductCategory.create!(:name => 'pc test 2', :environment => Environment.default) - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') + ent = create_profile_with_optional_category(Enterprise, 'test ent') cat1.products.create!(:name => 'prod test 1', :enterprise => ent) @@ -806,10 +802,10 @@ class SearchControllerTest < Test::Unit::TestCase should 'display only enterprises in the product category when its specified' do prod_cat = ProductCategory.create!(:name => 'prod cat test', :environment => Environment.default) - ent1 = Enterprise.create!(:name => 'test ent 1', :identifier => 'test_ent1') + ent1 = create_profile_with_optional_category(Enterprise, 'test_ent1') p = prod_cat.products.create!(:name => 'prod test 1', :enterprise => ent1) - ent2 = Enterprise.create!(:name => 'test ent 2', :identifier => 'test_ent2') + ent2 = create_profile_with_optional_category(Enterprise, 'test_ent2') get :index, :find_in => 'enterprises', :product_category => prod_cat.id @@ -821,10 +817,10 @@ class SearchControllerTest < Test::Unit::TestCase cat = Category.create(:name => 'cat', :environment => Environment.default) prod_cat1 = ProductCategory.create!(:name => 'prod cat test 1', :environment => Environment.default) prod_cat2 = ProductCategory.create!(:name => 'prod cat test 2', :environment => Environment.default, :parent => prod_cat1) - ent1 = Enterprise.create!(:name => 'test ent 1', :identifier => 'test_ent1', :category_ids => [cat.id]) + ent1 = create_profile_with_optional_category(Enterprise, 'test ent 1', cat) p = prod_cat2.products.create!(:name => 'prod test 1', :enterprise => ent1) - ent2 = Enterprise.create!(:name => 'test ent 2', :identifier => 'test_ent2', :category_ids => [cat.id]) + ent2 = create_profile_with_optional_category(Enterprise, 'test ent 2', cat) get :index, :find_in => 'enterprises', :category_path => cat.path.split('/'), :product_category => prod_cat1.id @@ -835,7 +831,7 @@ class SearchControllerTest < Test::Unit::TestCase should 'display only top level product categories that has enterprises when no product category filter is specified' do cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) cat2 = ProductCategory.create(:name => 'prod cat 2', :environment => Environment.default) - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') + ent = create_profile_with_optional_category(Enterprise, 'test ent') p = cat1.products.create!(:name => 'prod test 1', :enterprise => ent) get :index, :find_in => 'enterprises' @@ -848,7 +844,7 @@ class SearchControllerTest < Test::Unit::TestCase cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) cat11 = ProductCategory.create(:name => 'prod cat 11', :environment => Environment.default, :parent => cat1) cat12 = ProductCategory.create(:name => 'prod cat 12', :environment => Environment.default, :parent => cat1) - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') + ent = create_profile_with_optional_category(Enterprise, 'test ent') p = cat11.products.create!(:name => 'prod test 1', :enterprise => ent) get :index, :find_in => 'enterprises', :product_category => cat1.id @@ -861,7 +857,7 @@ class SearchControllerTest < Test::Unit::TestCase cat1 = ProductCategory.create(:name => 'prod cat 1', :environment => Environment.default) cat11 = ProductCategory.create(:name => 'prod cat 11', :environment => Environment.default, :parent => cat1) cat12 = ProductCategory.create(:name => 'prod cat 12', :environment => Environment.default, :parent => cat1) - ent = Enterprise.create!(:name => 'test ent', :identifier => 'test_ent') + ent = create_profile_with_optional_category(Enterprise, 'test ent') p = cat11.products.create!(:name => 'prod test 1', :enterprise => ent) get :index, :find_in => 'enterprises' @@ -924,12 +920,10 @@ class SearchControllerTest < Test::Unit::TestCase should 'search for products by origin and radius correctly' do s = City.create!(:name => 'Salvador', :lat => -12.97, :lng => -38.51, :environment => Environment.default) - e1 = Enterprise.create!(:name => 'test ent 1', :identifier => 'test_ent1', :lat => -12.97, :lng => -38.51) + e1 = create_profile_with_optional_category(Enterprise, 'test ent 1', nil, :lat => -12.97, :lng => -38.51) p1 = e1.products.create!(:name => 'test_product1') - e1.save! - e2 = Enterprise.create!(:name => 'test ent 2', :identifier => 'test_ent2', :lat => -14.97, :lng => -40.51) + e2 = create_profile_with_optional_category(Enterprise, 'test ent 2', nil, :lat => -14.97, :lng => -40.51) p2 = e2.products.create!(:name => 'test_product2') - e2.save! get :assets, :asset => 'products', :city => s.id, :radius => 15 @@ -956,7 +950,7 @@ class SearchControllerTest < Test::Unit::TestCase should 'indicate more than page for total_entries' do Enterprise.destroy_all ('1'..'20').each do |n| - Enterprise.create!(:name => 'test ' + n, :identifier => 'test_' + n) + create_profile_with_optional_category(Enterprise, 'test ' + n) end get :index, :query => 'test' @@ -979,7 +973,7 @@ class SearchControllerTest < Test::Unit::TestCase end should 'display steps when searching on wizard' do - c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) + c1 = create_profile_with_optional_category(Community, 'a beautiful community') login_as('ze') get :index, :query => 'beautiful', :find_in => [ 'communities' ], :wizard => true assert_equal 'layouts/wizard', @response.layout @@ -987,14 +981,14 @@ class SearchControllerTest < Test::Unit::TestCase end should 'not display steps when searching not on wizard' do - c1 = Community.create!(:name => 'a beautiful community', :identifier => 'bea_comm', :environment => Environment.default) + c1 = create_profile_with_optional_category(Community, 'a beautiful community') get :index, :query => 'beautiful', :find_in => [ 'communities' ] assert_equal 'layouts/application', @response.layout assert_no_tag :tag => 'div', :attributes => {:id => 'wizard-steps'} end should 'find products when enterprises has own hostname' do - ent = Enterprise.create!(:name => 'teste', :identifier => 'teste') + ent = create_profile_with_optional_category(Enterprise, 'teste') ent.domains << Domain.new(:name => 'testent.com'); ent.save! prod = ent.products.create!(:name => 'a beautiful product') get 'index', :query => 'beautiful', :find_in => ['products'] -- libgit2 0.21.2