Commit 723fb3b9db99be4e0b65a72694d803c8d9ae32ae

Authored by Gabriela Navarro
1 parent 5255150f
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

fix_institution: Fix some unit tests, add teardown

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Signed-off-by: Parley Martins <parley@outlook.com>
test/unit/communities_block_test.rb
@@ -25,6 +25,16 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase @@ -25,6 +25,16 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase
25 @comminities_block.expects(:owner).at_least_once.returns(@person) 25 @comminities_block.expects(:owner).at_least_once.returns(@person)
26 end 26 end
27 27
  28 + def teardown
  29 + GovernmentalPower.destroy_all
  30 + GovernmentalSphere.destroy_all
  31 + JuridicalNature.destroy_all
  32 + CommunitiesBlock.destroy_all
  33 + @person = nil
  34 + @institution = nil
  35 + @community = nil
  36 + @software_info = nil
  37 + end
28 should "not have community of software or institution in block" do 38 should "not have community of software or institution in block" do
29 assert_equal 1, @comminities_block.profile_list.count 39 assert_equal 1, @comminities_block.profile_list.count
30 end 40 end
test/unit/database_helper_test.rb
@@ -6,11 +6,11 @@ class DatabaseHelperTest &lt; ActiveSupport::TestCase @@ -6,11 +6,11 @@ class DatabaseHelperTest &lt; ActiveSupport::TestCase
6 6
7 def setup 7 def setup
8 dd1 = DatabaseDescription.create(:name => "Oracle") 8 dd1 = DatabaseDescription.create(:name => "Oracle")
9 - dd2 = DatabaseDescription.create(:name => "MySQL") 9 + dd2 = DatabaseDescription.create!(:name => "MySQL")
10 10
11 @database_objects = [ 11 @database_objects = [
12 {:database_description_id => dd1.id.to_s ,:version => "2.0", :operating_system => "debian"}, 12 {:database_description_id => dd1.id.to_s ,:version => "2.0", :operating_system => "debian"},
13 - {:database_description_id => dd2.id.to_s ,:version => "2.1", :operating_system => "debian"}, 13 + {:database_description_id => dd2.id.to_s ,:version => "2.1", :operating_system => "debian"}
14 ] 14 ]
15 end 15 end
16 16
@@ -64,7 +64,7 @@ class DatabaseHelperTest &lt; ActiveSupport::TestCase @@ -64,7 +64,7 @@ class DatabaseHelperTest &lt; ActiveSupport::TestCase
64 should "remove invalid tables from the list" do 64 should "remove invalid tables from the list" do
65 @database_objects.push({ 65 @database_objects.push({
66 :database_description_id => "I'm not a valid id", 66 :database_description_id => "I'm not a valid id",
67 - :version => "2.0", 67 + :version => "2.5",
68 :operating_system => "debian" 68 :operating_system => "debian"
69 }) 69 })
70 70
test/unit/institution_test.rb
@@ -11,6 +11,12 @@ class InstitutionTest &lt; ActiveSupport::TestCase @@ -11,6 +11,12 @@ class InstitutionTest &lt; ActiveSupport::TestCase
11 @institution = create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @gov_power, @gov_sphere, "11.222.333/4444-55") 11 @institution = create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @gov_power, @gov_sphere, "11.222.333/4444-55")
12 end 12 end
13 13
  14 + def teardown
  15 + GovernmentalPower.destroy_all
  16 + GovernmentalSphere.destroy_all
  17 + JuridicalNature.destroy_all
  18 + @institution = nil
  19 + end
14 should "not save institutions without name" do 20 should "not save institutions without name" do
15 @institution.name = nil 21 @institution.name = nil
16 assert !@institution.save 22 assert !@institution.save
test/unit/operating_system_helper_test.rb
@@ -16,7 +16,7 @@ class OperatingSystemHelperTest &lt; ActiveSupport::TestCase @@ -16,7 +16,7 @@ class OperatingSystemHelperTest &lt; ActiveSupport::TestCase
16 end 16 end
17 17
18 def teardown 18 def teardown
19 - @database_objects = nil 19 + @operating_system_objects = nil
20 end 20 end
21 21
22 should "return an empty list" do 22 should "return an empty list" do
@@ -44,7 +44,7 @@ class OperatingSystemHelperTest &lt; ActiveSupport::TestCase @@ -44,7 +44,7 @@ class OperatingSystemHelperTest &lt; ActiveSupport::TestCase
44 assert_equal false,OperatingSystemHelper.valid_list_operating_system?(list_compare) 44 assert_equal false,OperatingSystemHelper.valid_list_operating_system?(list_compare)
45 end 45 end
46 46
47 - should "return a html text with operating system" do 47 + should "return a html text with operating system" do
48 operating_systems = [] 48 operating_systems = []
49 49
50 operating_system = OperatingSystemName.new 50 operating_system = OperatingSystemName.new
@@ -57,5 +57,5 @@ class OperatingSystemHelperTest &lt; ActiveSupport::TestCase @@ -57,5 +57,5 @@ class OperatingSystemHelperTest &lt; ActiveSupport::TestCase
57 operating_systems << software_operating_system 57 operating_systems << software_operating_system
58 58
59 assert_not_nil OperatingSystemHelper.operating_system_as_tables(operating_systems).first.call.index(OperatingSystemName.first.name) 59 assert_not_nil OperatingSystemHelper.operating_system_as_tables(operating_systems).first.call.index(OperatingSystemName.first.name)
60 - end 60 + end
61 end 61 end
test/unit/operating_system_validation_test.rb
@@ -9,6 +9,10 @@ class OperatingSystemValidationTest &lt; ActiveSupport::TestCase @@ -9,6 +9,10 @@ class OperatingSystemValidationTest &lt; ActiveSupport::TestCase
9 @operating_system 9 @operating_system
10 end 10 end
11 11
  12 + def teardown
  13 + @operating_system.destroy
  14 + end
  15 +
12 should "save OperatingSystem if all fields are filled" do 16 should "save OperatingSystem if all fields are filled" do
13 assert @operating_system.save 17 assert @operating_system.save
14 end 18 end
test/unit/private_institution_test.rb
@@ -7,6 +7,11 @@ class PrivateInstitutionTest &lt; ActiveSupport::TestCase @@ -7,6 +7,11 @@ class PrivateInstitutionTest &lt; ActiveSupport::TestCase
7 @institution = create_private_institution "Simple Private Institution", "SPI", "BR", "DF", "Gama", "00.000.000/0001-00" 7 @institution = create_private_institution "Simple Private Institution", "SPI", "BR", "DF", "Gama", "00.000.000/0001-00"
8 end 8 end
9 9
  10 + def teardown
  11 + @institution = nil
  12 + Institution.destroy_all
  13 + end
  14 +
10 should "not save without a cnpj" do 15 should "not save without a cnpj" do
11 @institution.cnpj = nil 16 @institution.cnpj = nil
12 17
test/unit/public_institution_test.rb
@@ -11,6 +11,17 @@ class PublicInstitutionTest &lt; ActiveSupport::TestCase @@ -11,6 +11,17 @@ class PublicInstitutionTest &lt; ActiveSupport::TestCase
11 @institution = create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @gov_power, @gov_sphere, "11.222.333/4444-55") 11 @institution = create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @gov_power, @gov_sphere, "11.222.333/4444-55")
12 end 12 end
13 13
  14 + def teardown
  15 + GovernmentalPower.destroy_all
  16 + GovernmentalSphere.destroy_all
  17 + JuridicalNature.destroy_all
  18 + Institution.destroy_all
  19 + @gov_power = nil
  20 + @gov_sphere = nil
  21 + @juridical_nature = nil
  22 + @institution = nil
  23 + end
  24 +
14 should "not save without a cnpj" do 25 should "not save without a cnpj" do
15 @institution.cnpj = nil 26 @institution.cnpj = nil
16 assert !@institution.save 27 assert !@institution.save
test/unit/search_person_test.rb
@@ -10,6 +10,10 @@ class SearchPersonTest &lt; ActiveSupport::TestCase @@ -10,6 +10,10 @@ class SearchPersonTest &lt; ActiveSupport::TestCase
10 create_person("Joao_da_silva_costa_cunha", "joao_da_silva_costa_cunha@email.com", "aaaaaaa", "aaaaaaa", "joao_cunha@email.com" ,"RJ", "Rio de Janeiro") 10 create_person("Joao_da_silva_costa_cunha", "joao_da_silva_costa_cunha@email.com", "aaaaaaa", "aaaaaaa", "joao_cunha@email.com" ,"RJ", "Rio de Janeiro")
11 end 11 end
12 12
  13 + def teardown
  14 + Person.destroy_all
  15 + end
  16 +
13 should "Find people with Jo in name" do 17 should "Find people with Jo in name" do
14 people_list = Person.search("Jo") 18 people_list = Person.search("Jo")
15 19
@@ -46,4 +50,4 @@ class SearchPersonTest &lt; ActiveSupport::TestCase @@ -46,4 +50,4 @@ class SearchPersonTest &lt; ActiveSupport::TestCase
46 assert_equal 1, people_list.count 50 assert_equal 1, people_list.count
47 end 51 end
48 52
49 -end  
50 \ No newline at end of file 53 \ No newline at end of file
  54 +end
test/unit/software_categories_test.rb
@@ -44,6 +44,11 @@ class SoftwareCategoriesTest &lt; ActiveSupport::TestCase @@ -44,6 +44,11 @@ class SoftwareCategoriesTest &lt; ActiveSupport::TestCase
44 def teardown 44 def teardown
45 SoftwareDatabase.destroy_all 45 SoftwareDatabase.destroy_all
46 DatabaseDescription.destroy_all 46 DatabaseDescription.destroy_all
  47 + ProgrammingLanguage.destroy_all
  48 + SoftwareLanguage.destroy_all
  49 + OperatingSystem.destroy_all
  50 + SoftwareCategories.destroy_all
  51 + SoftwareInfo.destroy_all
47 end 52 end
48 53
49 should "save software correctly with SoftwareCategories filds" do 54 should "save software correctly with SoftwareCategories filds" do
test/unit/software_database_test.rb
1 require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
2 2
3 class SoftwareDatabaseTest < ActiveSupport::TestCase 3 class SoftwareDatabaseTest < ActiveSupport::TestCase
4 - DatabaseDescription.create!(name: "MySQL")  
5 -  
6 def setup 4 def setup
  5 + DatabaseDescription.create!(name: "PostgreSQL")
7 @software_database = SoftwareDatabase.new(:version => "1.0", :operating_system => "Debian") 6 @software_database = SoftwareDatabase.new(:version => "1.0", :operating_system => "Debian")
8 @software_database.database_description_id = 1 7 @software_database.database_description_id = 1
9 end 8 end
test/unit/software_info_validation_test.rb
@@ -39,6 +39,17 @@ class SoftwareInfoValidationTest &lt; ActiveSupport::TestCase @@ -39,6 +39,17 @@ class SoftwareInfoValidationTest &lt; ActiveSupport::TestCase
39 @software_info.software_categories = software_categories 39 @software_info.software_categories = software_categories
40 end 40 end
41 41
  42 + def teardown
  43 + ProgrammingLanguage.destroy_all
  44 + SoftwareLanguage.destroy_all
  45 + DatabaseDescription.destroy_all
  46 + SoftwareDatabase.destroy_all
  47 + OperatingSystem.destroy_all
  48 + OperatingSystemName.destroy_all
  49 + SoftwareInfo.destroy_all
  50 + SoftwareCategories.destroy_all
  51 + end
  52 +
42 should 'Save SoftwareInfo if all fields are filled' do 53 should 'Save SoftwareInfo if all fields are filled' do
43 assert_equal true, @software_info.save 54 assert_equal true, @software_info.save
44 end 55 end
test/unit/software_language_validation.rb
@@ -7,6 +7,11 @@ class SoftwareLanguageValidationTest &lt; ActiveSupport::TestCase @@ -7,6 +7,11 @@ class SoftwareLanguageValidationTest &lt; ActiveSupport::TestCase
7 @software_info.save 7 @software_info.save
8 end 8 end
9 9
  10 + def teardown
  11 + @software_info = nil
  12 + SoftwareInfo.destroy_all
  13 + end
  14 +
10 should "Save SoftwareLanguage if version and programming_language are filled" do 15 should "Save SoftwareLanguage if version and programming_language are filled" do
11 @software_language = create_software_language 16 @software_language = create_software_language
12 assert_equal true, @software_language.save 17 assert_equal true, @software_language.save
test/unit/software_license_info_test.rb
@@ -2,24 +2,22 @@ require File.dirname(__FILE__) + &#39;/../../../../test/test_helper&#39; @@ -2,24 +2,22 @@ require File.dirname(__FILE__) + &#39;/../../../../test/test_helper&#39;
2 2
3 class SoftwareDatabaseTest < ActiveSupport::TestCase 3 class SoftwareDatabaseTest < ActiveSupport::TestCase
4 4
5 - # def setup  
6 - # software_license_info = LicenseInfo.new(:version => "1.0", :link => "www.gpl2.com")  
7 - # end 5 + def setup
  6 + @software_license_info = LicenseInfo.create!(:version => "1.0", :link => "www.gpl2.com")
  7 + end
8 8
9 should "save if all informations are filled" do 9 should "save if all informations are filled" do
10 - software_license_info = LicenseInfo.new(:version => "1.0", :link => "www.gpl2.com")  
11 - assert software_license_info.save, "License Info should have been saved" 10 + puts @software_license_info.inspect
  11 + assert @software_license_info.save!, "License Info should have been saved"
12 end 12 end
13 13
14 should "not save if license info version is empty" do 14 should "not save if license info version is empty" do
15 - software_license_info = LicenseInfo.new(:version => "1.0", :link => "www.gpl2.com")  
16 - software_license_info.version = nil  
17 - assert !software_license_info.save, "Version can't be blank" 15 + @software_license_info.version = nil
  16 + assert !@software_license_info.save, "Version can't be blank"
18 end 17 end
19 18
20 should "save if link is empty" do 19 should "save if link is empty" do
21 - software_license_info = LicenseInfo.new(:version => "1.0", :link => "www.gpl2.com")  
22 - software_license_info.link = nil  
23 - assert software_license_info.save, "License info should have been saved" 20 + @software_license_info.link = nil
  21 + assert @oftware_license_info.save, "License info should have been saved"
24 end 22 end
25 -end  
26 \ No newline at end of file 23 \ No newline at end of file
  24 +end