Commit 0279e0af07b9e1274212c82b0d38dcc9f8adfc6b

Authored by Luciano Prestes
1 parent 5ebe705c
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 unit tests

Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>
Signed-off-by: Luiz Matos <luizff.matos@gmail.com>
lib/institution.rb
@@ -20,28 +20,41 @@ class Institution &lt; ActiveRecord::Base @@ -20,28 +20,41 @@ class Institution &lt; ActiveRecord::Base
20 where("name ilike ? OR acronym ilike ?", "%#{value}%", "%#{value}%" ) 20 where("name ilike ? OR acronym ilike ?", "%#{value}%", "%#{value}%" )
21 } 21 }
22 22
23 - validate :validate_country, :validate_state, :validate_city 23 + validate :validate_country, :validate_state, :validate_city, :verify_institution_type
24 24
25 protected 25 protected
26 26
27 def verify_institution_type 27 def verify_institution_type
28 - # valid_institutions_type = ["PublicInstitution", "PrivateInstitution"] 28 + valid_institutions_type = ["PublicInstitution", "PrivateInstitution"]
29 29
30 - # unless valid_institutions_type.include? self.type  
31 - # self.errors.add(:type, _("invalid, only public and private institutions are allowed."))  
32 - # false  
33 - # end 30 + unless valid_institutions_type.include? self.type
  31 + self.errors.add(:type, _("invalid, only public and private institutions are allowed."))
  32 + return false
  33 + end
  34 + return true
34 end 35 end
35 36
36 def validate_country 37 def validate_country
37 - # self.errors.add(:country, _("can't be blank")) if self.community.country.blank? && self.errors[:country].blank? 38 + if (self.community.blank?) || self.community.country.blank? && self.errors[:country].blank?
  39 + self.errors.add(:country, _("can't be blank"))
  40 + return false
  41 + end
  42 + return true
38 end 43 end
39 44
40 def validate_state 45 def validate_state
41 - # self.errors.add(:state, _("can't be blank")) if self.community.state.blank? && self.errors[:state].blank? 46 + if (self.community.blank?) || self.errors[:state].blank? && self.community.state.blank?
  47 + self.errors.add(:state, _("can't be blank"))
  48 + return false
  49 + end
  50 + return true
42 end 51 end
43 52
44 def validate_city 53 def validate_city
45 - # self.errors.add(:city, _("can't be blank")) if self.community.city.blank? && self.errors[:city].blank? 54 + if (self.community.blank?) || self.errors[:city].blank? && self.community.city.blank?
  55 + self.errors.add(:city, _("can't be blank"))
  56 + return false
  57 + end
  58 + return true
46 end 59 end
47 end 60 end
test/functional/software_test_helper.rb
@@ -141,7 +141,7 @@ module SoftwareTestHelper @@ -141,7 +141,7 @@ module SoftwareTestHelper
141 fields['acronym'] = 'test' 141 fields['acronym'] = 'test'
142 fields['objectives'] = 'test' 142 fields['objectives'] = 'test'
143 fields['features'] = 'test' 143 fields['features'] = 'test'
144 - fields['operating_platform'] = 'operating_plataform_test' 144 + fields['operating_platform'] = 'operating_platform_test'
145 fields['demonstration_url'] = 'test' 145 fields['demonstration_url'] = 'test'
146 146
147 fields_categories = {} 147 fields_categories = {}
test/unit/institution_test.rb
1 require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/plugin_test_helper'
2 3
3 class InstitutionTest < ActiveSupport::TestCase 4 class InstitutionTest < ActiveSupport::TestCase
4 - 5 + include PluginTestHelper
5 def setup 6 def setup
6 - community = Community.create(:name => "Simple Public Institution")  
7 -  
8 - @institution = Institution::new :name=>"Simple Institution" 7 + @gov_power = GovernmentalPower.create(:name=>"Some Gov Power")
  8 + @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
  9 + @juridical_nature = JuridicalNature.create(:name => "Autarquia")
9 10
10 - @institution.community = community  
11 - @institution.community.country = "BR"  
12 - @institution.community.state = "DF"  
13 - @institution.community.city = "Gama" 11 + @institution = create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @gov_power, @gov_sphere)
14 end 12 end
15 13
16 should "not save institutions without name" do 14 should "not save institutions without name" do
test/unit/juridical_nature_test.rb
@@ -20,24 +20,4 @@ class JuridicalNatureTest &lt; ActiveSupport::TestCase @@ -20,24 +20,4 @@ class JuridicalNatureTest &lt; ActiveSupport::TestCase
20 create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", juridical_nature, @govPower, @govSphere) 20 create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", juridical_nature, @govPower, @govSphere)
21 assert juridical_nature.public_institutions.count == PublicInstitution.count 21 assert juridical_nature.public_institutions.count == PublicInstitution.count
22 end 22 end
23 -  
24 - private  
25 -  
26 - def build_institution name, type="PublicInstitution", cnpj=nil  
27 - institution = Institution::new  
28 - institution.name = name  
29 - institution.type = type  
30 - institution.cnpj = cnpj  
31 -  
32 - institution.community = Community.create(:name => "Simple Public Institution")  
33 - institution.community.country = "BR"  
34 - institution.community.state = "DF"  
35 - institution.community.city = "Gama"  
36 -  
37 - if type == "PublicInstitution"  
38 - institution.juridical_nature = JuridicalNature.first  
39 - end  
40 -  
41 - end  
42 -  
43 end 23 end
test/unit/mpog_software_plugin_test.rb
@@ -6,7 +6,7 @@ class MpogSoftwarePluginTest &lt; ActiveSupport::TestCase @@ -6,7 +6,7 @@ class MpogSoftwarePluginTest &lt; ActiveSupport::TestCase
6 6
7 def setup 7 def setup
8 @plugin = MpogSoftwarePlugin.new 8 @plugin = MpogSoftwarePlugin.new
9 - @user = create_user 9 + @user = create_user("login", "user@email.com", "123456", "123456", "user@secondary_email.com")
10 @person = @user.person 10 @person = @user.person
11 end 11 end
12 12
@@ -33,18 +33,4 @@ class MpogSoftwarePluginTest &lt; ActiveSupport::TestCase @@ -33,18 +33,4 @@ class MpogSoftwarePluginTest &lt; ActiveSupport::TestCase
33 33
34 assert_equal(test_percentege, plugin_percentege) 34 assert_equal(test_percentege, plugin_percentege)
35 end 35 end
36 -  
37 - private  
38 -  
39 - def create_user  
40 - user = User.new  
41 - user.login = "login"  
42 - user.email = "user@email.com"  
43 - user.password = "123456"  
44 - user.password_confirmation = "123456"  
45 - user.secondary_email = "user@secondary_email.com"  
46 - user.save  
47 - user.person.save  
48 - user  
49 - end  
50 end 36 end
test/unit/mpog_user_test.rb
1 require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/plugin_test_helper'
2 3
3 class MpogSoftwarePluginUserTest < ActiveSupport::TestCase 4 class MpogSoftwarePluginUserTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
4 6
5 should 'not save user whose both email and secondary email are the same' do 7 should 'not save user whose both email and secondary email are the same' do
6 8
@@ -95,13 +97,16 @@ class MpogSoftwarePluginUserTest &lt; ActiveSupport::TestCase @@ -95,13 +97,16 @@ class MpogSoftwarePluginUserTest &lt; ActiveSupport::TestCase
95 should 'have institution if email is governmental' do 97 should 'have institution if email is governmental' do
96 user = fast_create(User) 98 user = fast_create(User)
97 99
98 - user.email = "test@gov.br" 100 + user.email = "testtest@gov.br"
99 101
100 user.institutions = [] 102 user.institutions = []
101 assert !user.save, "this should not save" 103 assert !user.save, "this should not save"
102 104
103 - institution = build_institution "Test simple institution"  
104 - institution.save 105 + gov_power = GovernmentalPower.create(:name=>"Some Gov Power")
  106 + gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
  107 + juridical_nature = JuridicalNature.create(:name => "Autarquia")
  108 + institution = create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", juridical_nature, gov_power, gov_sphere)
  109 + institution.save!
105 110
106 user.institutions << institution 111 user.institutions << institution
107 assert user.save, "this should save" 112 assert user.save, "this should save"
@@ -119,21 +124,4 @@ class MpogSoftwarePluginUserTest &lt; ActiveSupport::TestCase @@ -119,21 +124,4 @@ class MpogSoftwarePluginUserTest &lt; ActiveSupport::TestCase
119 return user 124 return user
120 end 125 end
121 126
122 - def build_institution name, type="PublicInstitution", cnpj=nil  
123 - institution = Institution::new  
124 - institution.name = name  
125 - institution.type = type  
126 - institution.cnpj = cnpj  
127 -  
128 - institution.community = Community.create(:name => name)  
129 - institution.community.country = "BR"  
130 - institution.community.state = "DF"  
131 - institution.community.city = "Gama"  
132 -  
133 - if type == "PublicInstitution"  
134 - institution.juridical_nature = JuridicalNature.first  
135 - end  
136 -  
137 - institution  
138 - end  
139 end 127 end
test/unit/mpog_validation_test.rb
@@ -7,11 +7,7 @@ class MpogSoftwarePluginValidationTest &lt; ActiveSupport::TestCase @@ -7,11 +7,7 @@ class MpogSoftwarePluginValidationTest &lt; ActiveSupport::TestCase
7 def setup 7 def setup
8 @plugin = MpogSoftwarePlugin.new 8 @plugin = MpogSoftwarePlugin.new
9 9
10 - institution = build_institution("Test institution")  
11 - institution.save  
12 -  
13 @user = fast_create(User) 10 @user = fast_create(User)
14 - @user.institutions << institution  
15 end 11 end
16 12
17 def teardown 13 def teardown
@@ -29,24 +25,4 @@ class MpogSoftwarePluginValidationTest &lt; ActiveSupport::TestCase @@ -29,24 +25,4 @@ class MpogSoftwarePluginValidationTest &lt; ActiveSupport::TestCase
29 @user.email = "test_email@net.br" 25 @user.email = "test_email@net.br"
30 assert @user.save 26 assert @user.save
31 end 27 end
32 -  
33 - private  
34 -  
35 - def build_institution name, type="PublicInstitution", cnpj=nil  
36 - institution = Institution::new  
37 - institution.name = name  
38 - institution.type = type  
39 - institution.cnpj = cnpj  
40 -  
41 - institution.community = Community.create(:name => "Simple Public Institution")  
42 - institution.community.country = "BR"  
43 - institution.community.state = "DF"  
44 - institution.community.city = "Gama"  
45 -  
46 - if type == "PublicInstitution"  
47 - institution.juridical_nature = JuridicalNature.first  
48 - end  
49 -  
50 - institution  
51 - end  
52 end 28 end
test/unit/plugin_test_helper.rb
@@ -9,7 +9,7 @@ module PluginTestHelper @@ -9,7 +9,7 @@ module PluginTestHelper
9 institution.acronym = acronym 9 institution.acronym = acronym
10 institution.governmental_power = gov_p 10 institution.governmental_power = gov_p
11 institution.governmental_sphere = gov_s 11 institution.governmental_sphere = gov_s
12 - institution.save! 12 + institution.save
13 13
14 institution 14 institution
15 end 15 end
@@ -20,7 +20,7 @@ module PluginTestHelper @@ -20,7 +20,7 @@ module PluginTestHelper
20 institution.name = name 20 institution.name = name
21 institution.sisp = false 21 institution.sisp = false
22 institution.cnpj = cnpj 22 institution.cnpj = cnpj
23 - institution.save! 23 + institution.save
24 24
25 institution 25 institution
26 end 26 end
@@ -31,7 +31,7 @@ module PluginTestHelper @@ -31,7 +31,7 @@ module PluginTestHelper
31 community.country = country 31 community.country = country
32 community.state = state 32 community.state = state
33 community.city = city 33 community.city = city
34 - community.save! 34 + community.save
35 community 35 community
36 end 36 end
37 37
@@ -47,4 +47,13 @@ module PluginTestHelper @@ -47,4 +47,13 @@ module PluginTestHelper
47 user 47 user
48 end 48 end
49 49
  50 + def create_person name, email, password, password_confirmation, secondary_email, state, city
  51 + user = create_user(name.downcase, email, password, password_confirmation, secondary_email)
  52 + user.person.name = name
  53 + user.person.state = state
  54 + user.person.city = city
  55 + user.person.save
  56 + user.person
  57 + end
  58 +
50 end 59 end
test/unit/private_institution_test.rb
1 require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/plugin_test_helper'
2 3
3 class PrivateInstitutionTest < ActiveSupport::TestCase 4 class PrivateInstitutionTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
4 def setup 6 def setup
5 - community = Community.create(:name => "Simple Private Institution")  
6 - @institution = PrivateInstitution::new :name=>"Simple Private Institution",  
7 - :cnpj=>"00.000.000/0001-00"  
8 - @institution.community = community  
9 - @institution.community.country = "BR"  
10 - @institution.community.state = "DF"  
11 - @institution.community.city = "Gama" 7 + @institution = create_private_institution "Simple Private Institution", "00.000.000/0001-00", "BR", "DF", "Gama"
12 end 8 end
13 9
14 should "not save without a cnpj" do 10 should "not save without a cnpj" do
@@ -20,11 +16,7 @@ class PrivateInstitutionTest &lt; ActiveSupport::TestCase @@ -20,11 +16,7 @@ class PrivateInstitutionTest &lt; ActiveSupport::TestCase
20 16
21 should "not save with a repeated cnpj" do 17 should "not save with a repeated cnpj" do
22 assert @institution.save 18 assert @institution.save
23 -  
24 - sec_institution = PrivateInstitution::new :name=>"Another Private Institution",  
25 - :cnpj=>"00.000.000/0001-00"  
26 - sec_institution.community = Community.create(:name => "Another Private Institution")  
27 - 19 + sec_institution = create_private_institution "Another Private Institution", "00.000.000/0001-00", "BR", "DF", "Gama"
28 assert !sec_institution.save 20 assert !sec_institution.save
29 assert sec_institution.errors.full_messages.include? "Cnpj has already been taken" 21 assert sec_institution.errors.full_messages.include? "Cnpj has already been taken"
30 end 22 end
test/unit/public_institution_test.rb
1 require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/plugin_test_helper'
2 3
3 class PublicInstitutionTest < ActiveSupport::TestCase 4 class PublicInstitutionTest < ActiveSupport::TestCase
  5 + include PluginTestHelper
4 def setup 6 def setup
5 - govPower = GovernmentalPower.create(:name=>"Some Gov Power")  
6 - govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")  
7 - juriNature = JuridicalNature.create(:name => "Some jurid nature")  
8 - community = Community.create(:name => "Simple Public Institution")  
9 -  
10 - @institution = PublicInstitution::new :name=>"Simple Public Institution", :acronym=>"SPI",  
11 - :governmental_power=>govPower, :governmental_sphere=>govSphere, :juridical_nature => juriNature  
12 -  
13 - @institution.community = community  
14 - @institution.community.country = "BR"  
15 - @institution.community.state = "DF"  
16 - @institution.community.city = "Gama" 7 + @gov_power = GovernmentalPower.create(:name=>"Some Gov Power")
  8 + @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere")
  9 + @juridical_nature = JuridicalNature.create(:name => "Autarquia")
  10 +
  11 + @institution = create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @gov_power, @gov_sphere)
17 end 12 end
18 13
19 should "save without a cnpj" do 14 should "save without a cnpj" do
test/unit/search_person_test.rb
1 require File.dirname(__FILE__) + '/../../../../test/test_helper' 1 require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/plugin_test_helper'
2 3
3 -class SearchPersonTest < ActiveSupport::TestCase  
4 4
  5 +class SearchPersonTest < ActiveSupport::TestCase
  6 + include PluginTestHelper
5 def setup 7 def setup
6 - create_person("Jose_Augusto", "DF", "Gama", "jose_augusto@email.com")  
7 - create_person("Maria_cunha", "RJ", "Rio de Janeiro", "maria_cunha@email.com")  
8 - create_person("Joao_da_silva_costa_cunha", "RJ", "Rio de Janeiro", "joao_da_silva_costa_cunha@gemail.com") 8 + create_person("Jose_Augusto", "jose_augusto@email.com", "aaaaaaa", "aaaaaaa", "jose_silva@email.com", "DF", "Gama")
  9 + create_person("Maria_cunha", "maria_cunha@email.com", "aaaaaaa", "aaaaaaa", "maria_silva@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")
9 end 11 end
10 12
11 should "Find people with Jo in name" do 13 should "Find people with Jo in name" do
@@ -44,21 +46,4 @@ class SearchPersonTest &lt; ActiveSupport::TestCase @@ -44,21 +46,4 @@ class SearchPersonTest &lt; ActiveSupport::TestCase
44 assert_equal 1, people_list.count 46 assert_equal 1, people_list.count
45 end 47 end
46 48
47 - def create_person name, state, city, email  
48 - user = User::new  
49 - user.login = name.downcase  
50 - user.email = email  
51 - user.secondary_email = "#{name}_secondary@email2.com"  
52 - user.password = "adlasdasd"  
53 - user.password_confirmation = "adlasdasd"  
54 - user.save!  
55 -  
56 - user.person.name = name  
57 - user.person.state = state  
58 - user.person.city = city  
59 - user.person.save!  
60 -  
61 - user.save!  
62 - end  
63 -  
64 end 49 end
65 \ No newline at end of file 50 \ No newline at end of file