Commit 5255150fd38ebdf3bb0feae59d516141367bf72b
Committed by
Gabriela Navarro
1 parent
37d8ade7
Exists in
master
and in
79 other branches
fix_institution: Fix unit and some functional tests
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
20 changed files
with
258 additions
and
214 deletions
Show diff stats
lib/software_database.rb
... | ... | @@ -8,4 +8,6 @@ class SoftwareDatabase < ActiveRecord::Base |
8 | 8 | validates_length_of :operating_system, maximum: 20, too_long: _("Software database is too long (maximum is 20 characters)") |
9 | 9 | |
10 | 10 | validates_presence_of :database_description_id, :version, :operating_system |
11 | + validates :database_description_id, :numericality => { :greater_than_or_equal_to => 1 } | |
12 | + | |
11 | 13 | end | ... | ... |
test/functional/institution_test_helper.rb
... | ... | @@ -22,15 +22,8 @@ module InstitutionTestHelper |
22 | 22 | end |
23 | 23 | |
24 | 24 | def self.create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s, cnpj |
25 | - institution_community = Community::new | |
26 | - institution_community.name = name | |
27 | - institution_community.country = country | |
28 | - institution_community.state = state | |
29 | - institution_community.city = city | |
30 | - institution_community.save! | |
31 | - | |
32 | 25 | institution = PublicInstitution.new |
33 | - institution.community = institution_community | |
26 | + institution.community = institution_community(name, country, state, city) | |
34 | 27 | institution.name = name |
35 | 28 | institution.juridical_nature = juridical_nature |
36 | 29 | institution.acronym = acronym |
... | ... | @@ -41,4 +34,26 @@ module InstitutionTestHelper |
41 | 34 | institution.save! |
42 | 35 | institution |
43 | 36 | end |
37 | + | |
38 | + def self.create_private_institution name, acronym, country, state, city, cnpj | |
39 | + institution = PrivateInstitution.new | |
40 | + institution.community = institution_community(name, country, state, city) | |
41 | + institution.name = name | |
42 | + institution.acronym = acronym | |
43 | + institution.cnpj = cnpj | |
44 | + institution.corporate_name = "corporate default" | |
45 | + institution.save! | |
46 | + | |
47 | + institution | |
48 | + end | |
49 | + | |
50 | + def self.institution_community name, country, state, city | |
51 | + institution_community = Community::new | |
52 | + institution_community.name = name | |
53 | + institution_community.country = country | |
54 | + institution_community.state = state | |
55 | + institution_community.city = city | |
56 | + institution_community.save! | |
57 | + institution_community | |
58 | + end | |
44 | 59 | end |
45 | 60 | \ No newline at end of file | ... | ... |
test/functional/mpog_software_plugin_controller_test.rb
1 | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | -require File.dirname(__FILE__) + '/institution_test_helper' | |
2 | +require File.dirname(__FILE__) + '/../helpers/institution_test_helper' | |
3 | 3 | require File.dirname(__FILE__) + '/../../controllers/mpog_software_plugin_controller' |
4 | 4 | |
5 | 5 | class MpogSoftwarePluginController; def rescue_action(e) raise e end; end | ... | ... |
test/functional/mpog_software_plugin_myprofile_controller_test.rb
1 | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | 2 | require File.dirname(__FILE__) + '/../../controllers/mpog_software_plugin_myprofile_controller' |
3 | 3 | require File.dirname(__FILE__) + '/software_test_helper' |
4 | -require File.dirname(__FILE__) + '/institution_test_helper' | |
4 | +require File.dirname(__FILE__) + '/../helpers/institution_test_helper' | |
5 | 5 | |
6 | 6 | class MpogSoftwarePluginMyprofileController; def rescue_action(e) raise e end; |
7 | 7 | end | ... | ... |
test/functional/profile_editor_controller_test.rb
1 | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | -require File.dirname(__FILE__) + '/institution_test_helper' | |
2 | +require File.dirname(__FILE__) + '/../helpers/institution_test_helper' | |
3 | 3 | require File.dirname(__FILE__) + '/../../../../app/controllers/my_profile/profile_editor_controller' |
4 | 4 | |
5 | 5 | class ProfileEditorController; def rescue_action(e) raise e end; end | ... | ... |
... | ... | @@ -0,0 +1,59 @@ |
1 | +module InstitutionTestHelper | |
2 | + | |
3 | + def self.generate_form_fields name, country, state, city, cnpj, type | |
4 | + fields = { | |
5 | + :community => { | |
6 | + :name => name, | |
7 | + :country => country, | |
8 | + :state => state, | |
9 | + :city => city | |
10 | + }, | |
11 | + :institutions => { | |
12 | + :cnpj=> cnpj, | |
13 | + :type => type, | |
14 | + :acronym => "", | |
15 | + :governmental_power => "", | |
16 | + :governmental_sphere => "", | |
17 | + :juridical_nature => "", | |
18 | + :corporate_name => "coporate default" | |
19 | + } | |
20 | + } | |
21 | + fields | |
22 | + end | |
23 | + | |
24 | + def self.create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s, cnpj | |
25 | + institution = PublicInstitution.new | |
26 | + institution.community = institution_community(name, country, state, city) | |
27 | + institution.name = name | |
28 | + institution.juridical_nature = juridical_nature | |
29 | + institution.acronym = acronym | |
30 | + institution.governmental_power = gov_p | |
31 | + institution.governmental_sphere = gov_s | |
32 | + institution.cnpj = cnpj | |
33 | + institution.corporate_name = "corporate default" | |
34 | + institution.save | |
35 | + institution | |
36 | + end | |
37 | + | |
38 | + def self.create_private_institution name, acronym, country, state, city, cnpj | |
39 | + institution = PrivateInstitution.new | |
40 | + institution.community = institution_community(name, country, state, city) | |
41 | + institution.name = name | |
42 | + institution.acronym = acronym | |
43 | + institution.cnpj = cnpj | |
44 | + institution.corporate_name = "corporate default" | |
45 | + institution.save | |
46 | + | |
47 | + institution | |
48 | + end | |
49 | + | |
50 | + def self.institution_community name, country, state, city | |
51 | + institution_community = Community::new | |
52 | + institution_community.name = name | |
53 | + institution_community.country = country | |
54 | + institution_community.state = state | |
55 | + institution_community.city = city | |
56 | + institution_community.save | |
57 | + institution_community | |
58 | + end | |
59 | +end | |
0 | 60 | \ No newline at end of file | ... | ... |
test/unit/communities_block_test.rb
1 | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | +require File.dirname(__FILE__) + '/../helpers/institution_test_helper' | |
2 | 3 | require File.dirname(__FILE__) + '/plugin_test_helper' |
3 | 4 | |
4 | 5 | class CommunitiesBlockTest < ActiveSupport::TestCase |
... | ... | @@ -10,7 +11,7 @@ class CommunitiesBlockTest < ActiveSupport::TestCase |
10 | 11 | @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") |
11 | 12 | @juridical_nature = JuridicalNature.create(:name => "Autarquia") |
12 | 13 | |
13 | - @institution = create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @gov_power, @gov_sphere) | |
14 | + @institution = InstitutionTestHelper.create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @gov_power, @gov_sphere, "12.345.678/9012-45") | |
14 | 15 | @institution.community.add_member(@person) |
15 | 16 | |
16 | 17 | @software_info = create_software_info("Novo Software") | ... | ... |
test/unit/database_helper_test.rb
... | ... | @@ -11,12 +11,12 @@ class DatabaseHelperTest < ActiveSupport::TestCase |
11 | 11 | @database_objects = [ |
12 | 12 | {:database_description_id => dd1.id.to_s ,:version => "2.0", :operating_system => "debian"}, |
13 | 13 | {:database_description_id => dd2.id.to_s ,:version => "2.1", :operating_system => "debian"}, |
14 | - {:database_description_id => dd1.id.to_s ,:version => "2.2", :operating_system => "debian"}] | |
15 | - @database_objects | |
14 | + ] | |
16 | 15 | end |
17 | 16 | |
18 | 17 | def teardown |
19 | 18 | @database_objects = nil |
19 | + SoftwareDatabase.destroy_all | |
20 | 20 | DatabaseDescription.destroy_all |
21 | 21 | end |
22 | 22 | |
... | ... | @@ -70,7 +70,6 @@ class DatabaseHelperTest < ActiveSupport::TestCase |
70 | 70 | |
71 | 71 | database_objects_length = @database_objects.count |
72 | 72 | list_compare = DatabaseHelper.list_database(@database_objects) |
73 | - | |
74 | - assert_equal database_objects_length-1, list_compare.count | |
73 | + assert_equal list_compare.count, database_objects_length-1 | |
75 | 74 | end |
76 | 75 | end | ... | ... |
test/unit/database_validation_test.rb
test/unit/governmental_power_test.rb
1 | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | +require File.dirname(__FILE__) + '/../helpers/institution_test_helper' | |
2 | 3 | |
3 | 4 | class GovernmentalPowerTest < ActiveSupport::TestCase |
5 | + | |
6 | + def setup | |
7 | + @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
8 | + @juridical_nature = JuridicalNature.create(:name => "Autarquia") | |
9 | + end | |
10 | + | |
4 | 11 | def teardown |
5 | 12 | Institution.destroy_all |
6 | 13 | end |
7 | 14 | |
8 | 15 | should "get public institutions" do |
9 | 16 | gov_power = GovernmentalPower::new :name=>"Some gov power" |
17 | + InstitutionTestHelper.create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, gov_power, @gov_sphere, "12.345.678/9012-45") | |
10 | 18 | |
11 | - assert build_institution("one").save | |
12 | - assert build_institution("two").save | |
13 | - assert build_institution("three").save | |
14 | - | |
15 | - assert gov_power.public_institutions.count == PublicInstitution.count | |
16 | - end | |
17 | - | |
18 | - should "not get private institutions" do | |
19 | - gov_power = GovernmentalPower::new :name=>"Some gov power" | |
20 | - | |
21 | - assert build_institution("one", "PrivateInstitution", "00.000.000/0000-00").save | |
22 | - assert build_institution("two","PrivateInstitution", "00.000.000/0000-01").save | |
23 | - assert build_institution("three","PrivateInstitution", "00.000.000/0000-02").save | |
24 | - | |
25 | - assert gov_power.public_institutions.count == 0 | |
26 | - assert gov_power.public_institutions.count == PublicInstitution.count | |
27 | - assert gov_power.public_institutions.count != PrivateInstitution.count | |
28 | - end | |
29 | - | |
30 | - private | |
31 | - | |
32 | - def build_institution name, type="PublicInstitution", cnpj=nil | |
33 | - institution = Institution::new | |
34 | - institution.name = name | |
35 | - institution.type = type | |
36 | - institution.cnpj = cnpj | |
37 | - | |
38 | - institution.community = Community.create(:name => "Simple Public Institution") | |
39 | - institution.community.country = "BR" | |
40 | - institution.community.state = "DF" | |
41 | - institution.community.city = "Gama" | |
42 | - | |
43 | - if type == "PublicInstitution" | |
44 | - institution.governmental_power = GovernmentalPower.first | |
45 | - institution.governmental_sphere = GovernmentalSphere.first | |
46 | - end | |
47 | - | |
48 | - institution | |
19 | + assert_equal gov_power.public_institutions.count, PublicInstitution.count | |
49 | 20 | end |
50 | 21 | end |
51 | 22 | \ No newline at end of file | ... | ... |
test/unit/institution_test.rb
... | ... | @@ -8,7 +8,7 @@ class InstitutionTest < ActiveSupport::TestCase |
8 | 8 | @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") |
9 | 9 | @juridical_nature = JuridicalNature.create(:name => "Autarquia") |
10 | 10 | |
11 | - @institution = create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @gov_power, @gov_sphere) | |
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 | 12 | end |
13 | 13 | |
14 | 14 | should "not save institutions without name" do | ... | ... |
test/unit/institutions_block_test.rb
... | ... | @@ -25,7 +25,7 @@ class InstitutionsBlockTest < ActiveSupport::TestCase |
25 | 25 | should 'list institutions' do |
26 | 26 | user = create_person("Jose_Augusto", "jose_augusto@email.com", "aaaaaaa", "aaaaaaa", "jose_silva@email.com", "DF", "Gama") |
27 | 27 | |
28 | - institution = create_private_institution "inst", "00000000000000", "country", "state", "city" | |
28 | + institution = create_private_institution "inst name", "IN", "country", "state", "city", "00.111.222/3333-44" | |
29 | 29 | institution.community.add_member(user) |
30 | 30 | |
31 | 31 | block = InstitutionsBlock.new | ... | ... |
test/unit/juridical_nature_test.rb
... | ... | @@ -16,8 +16,8 @@ class JuridicalNatureTest < ActiveSupport::TestCase |
16 | 16 | |
17 | 17 | should "get public institutions" do |
18 | 18 | juridical_nature = JuridicalNature.create(:name => "Autarquia") |
19 | - create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", juridical_nature, @govPower, @govSphere) | |
20 | - create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", juridical_nature, @govPower, @govSphere) | |
19 | + create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", juridical_nature, @govPower, @govSphere, "22.333.444/5555-66") | |
20 | + create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", juridical_nature, @govPower, @govSphere, "22.333.444/5555-77") | |
21 | 21 | assert juridical_nature.public_institutions.count == PublicInstitution.count |
22 | 22 | end |
23 | 23 | end | ... | ... |
... | ... | @@ -0,0 +1,127 @@ |
1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
2 | +require File.dirname(__FILE__) + '/plugin_test_helper' | |
3 | + | |
4 | +class MpogSoftwarePluginUserTest < ActiveSupport::TestCase | |
5 | + include PluginTestHelper | |
6 | + | |
7 | + should 'not save user whose both email and secondary email are the same' do | |
8 | + | |
9 | + user = fast_create(User) | |
10 | + user.email = "test@email.com" | |
11 | + user.secondary_email = "test@email.com" | |
12 | + | |
13 | + assert !user.save | |
14 | + end | |
15 | + | |
16 | + should 'not save user whose both email and secondary email have already been used' do | |
17 | + user1 = create_default_user | |
18 | + user2 = fast_create(User) | |
19 | + | |
20 | + user2.email = "primary@email.com" | |
21 | + user2.secondary_email = "secondary@email.com" | |
22 | + assert !user2.save | |
23 | + end | |
24 | + | |
25 | + should 'not save user whose email has already been used' do | |
26 | + user1 = create_default_user | |
27 | + user2 = fast_create(User) | |
28 | + | |
29 | + user2.email = "primary@email.com" | |
30 | + user2.secondary_email = "noosfero@email.com" | |
31 | + assert !user2.save | |
32 | + end | |
33 | + | |
34 | + should 'not save user whose email has already been used in another users secondary email' do | |
35 | + user1 = create_default_user | |
36 | + user2 = fast_create(User) | |
37 | + | |
38 | + user2.login = "another-login" | |
39 | + user2.email = "secondary@email.com" | |
40 | + user2.secondary_email = "noosfero@email.com" | |
41 | + assert !user2.save | |
42 | + end | |
43 | + | |
44 | + should 'not save user whose secondary email has already been used in another users email' do | |
45 | + user1 = create_default_user | |
46 | + user2 = fast_create(User) | |
47 | + | |
48 | + user2.login = "another-login" | |
49 | + user2.email = "noosfero@email.com" | |
50 | + user2.secondary_email = "primary@email.com" | |
51 | + assert !user2.save | |
52 | + end | |
53 | + | |
54 | + should 'not save user whose secondary email has already been used in another users secondary email' do | |
55 | + user1 = create_default_user | |
56 | + user2 = fast_create(User) | |
57 | + | |
58 | + user2.login = "another-login" | |
59 | + user2.email = "noosfero@email.com" | |
60 | + user2.secondary_email = "secondary@email.com" | |
61 | + assert !user2.save | |
62 | + end | |
63 | + | |
64 | + should 'not save user whose secondary email is in the wrong format' do | |
65 | + user = fast_create(User) | |
66 | + user.email = "test@email.com" | |
67 | + user.secondary_email = "notarightformat.com" | |
68 | + | |
69 | + assert !user.save | |
70 | + | |
71 | + user.secondary_email = "not@arightformatcom" | |
72 | + | |
73 | + assert !user.save | |
74 | + end | |
75 | + | |
76 | + should 'save more than one user without secondary email' do | |
77 | + user = fast_create(User) | |
78 | + user.email = "test@email.com" | |
79 | + user.secondary_email = "" | |
80 | + user.save | |
81 | + | |
82 | + user2 = fast_create(User) | |
83 | + user2.email = "test2@email.com" | |
84 | + user2.secondary_email = "" | |
85 | + assert user2.save | |
86 | + end | |
87 | + should 'return an error if secondary email is governmental and primary is not' do | |
88 | + user = fast_create(User) | |
89 | + | |
90 | + user.email = "test@email.com" | |
91 | + user.secondary_email = "test@gov.br" | |
92 | + | |
93 | + assert !user.save | |
94 | + assert user.errors.full_messages.include?("The governamental email must be the primary one.") | |
95 | + end | |
96 | + | |
97 | + should 'have institution if email is governmental' do | |
98 | + user = fast_create(User) | |
99 | + | |
100 | + user.email = "testtest@gov.br" | |
101 | + | |
102 | + user.institutions = [] | |
103 | + assert !user.save, "this should not save" | |
104 | + | |
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, "44.555.666/7777-88") | |
109 | + institution.save! | |
110 | + | |
111 | + user.institutions << institution | |
112 | + assert user.save, "this should save" | |
113 | + end | |
114 | + | |
115 | + private | |
116 | + | |
117 | + def create_default_user | |
118 | + user = fast_create(User) | |
119 | + user.login = "a-login" | |
120 | + user.email = "primary@email.com" | |
121 | + user.secondary_email = "secondary@email.com" | |
122 | + user.save | |
123 | + | |
124 | + return user | |
125 | + end | |
126 | + | |
127 | +end | ... | ... |
test/unit/mpog_user_test.rb
... | ... | @@ -1,127 +0,0 @@ |
1 | -require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
2 | -require File.dirname(__FILE__) + '/plugin_test_helper' | |
3 | - | |
4 | -class MpogSoftwarePluginUserTest < ActiveSupport::TestCase | |
5 | - include PluginTestHelper | |
6 | - | |
7 | - should 'not save user whose both email and secondary email are the same' do | |
8 | - | |
9 | - user = fast_create(User) | |
10 | - user.email = "test@email.com" | |
11 | - user.secondary_email = "test@email.com" | |
12 | - | |
13 | - assert !user.save | |
14 | - end | |
15 | - | |
16 | - should 'not save user whose both email and secondary email have already been used' do | |
17 | - user1 = create_default_user | |
18 | - user2 = fast_create(User) | |
19 | - | |
20 | - user2.email = "primary@email.com" | |
21 | - user2.secondary_email = "secondary@email.com" | |
22 | - assert !user2.save | |
23 | - end | |
24 | - | |
25 | - should 'not save user whose email has already been used' do | |
26 | - user1 = create_default_user | |
27 | - user2 = fast_create(User) | |
28 | - | |
29 | - user2.email = "primary@email.com" | |
30 | - user2.secondary_email = "noosfero@email.com" | |
31 | - assert !user2.save | |
32 | - end | |
33 | - | |
34 | - should 'not save user whose email has already been used in another users secondary email' do | |
35 | - user1 = create_default_user | |
36 | - user2 = fast_create(User) | |
37 | - | |
38 | - user2.login = "another-login" | |
39 | - user2.email = "secondary@email.com" | |
40 | - user2.secondary_email = "noosfero@email.com" | |
41 | - assert !user2.save | |
42 | - end | |
43 | - | |
44 | - should 'not save user whose secondary email has already been used in another users email' do | |
45 | - user1 = create_default_user | |
46 | - user2 = fast_create(User) | |
47 | - | |
48 | - user2.login = "another-login" | |
49 | - user2.email = "noosfero@email.com" | |
50 | - user2.secondary_email = "primary@email.com" | |
51 | - assert !user2.save | |
52 | - end | |
53 | - | |
54 | - should 'not save user whose secondary email has already been used in another users secondary email' do | |
55 | - user1 = create_default_user | |
56 | - user2 = fast_create(User) | |
57 | - | |
58 | - user2.login = "another-login" | |
59 | - user2.email = "noosfero@email.com" | |
60 | - user2.secondary_email = "secondary@email.com" | |
61 | - assert !user2.save | |
62 | - end | |
63 | - | |
64 | - should 'not save user whose secondary email is in the wrong format' do | |
65 | - user = fast_create(User) | |
66 | - user.email = "test@email.com" | |
67 | - user.secondary_email = "notarightformat.com" | |
68 | - | |
69 | - assert !user.save | |
70 | - | |
71 | - user.secondary_email = "not@arightformatcom" | |
72 | - | |
73 | - assert !user.save | |
74 | - end | |
75 | - | |
76 | - should 'save more than one user without secondary email' do | |
77 | - user = fast_create(User) | |
78 | - user.email = "test@email.com" | |
79 | - user.secondary_email = "" | |
80 | - user.save | |
81 | - | |
82 | - user2 = fast_create(User) | |
83 | - user2.email = "test2@email.com" | |
84 | - user2.secondary_email = "" | |
85 | - assert user2.save | |
86 | - end | |
87 | - should 'return an error if secondary email is governmental and primary is not' do | |
88 | - user = fast_create(User) | |
89 | - | |
90 | - user.email = "test@email.com" | |
91 | - user.secondary_email = "test@gov.br" | |
92 | - | |
93 | - assert !user.save | |
94 | - assert user.errors.full_messages.include?("The governamental email must be the primary one.") | |
95 | - end | |
96 | - | |
97 | - should 'have institution if email is governmental' do | |
98 | - user = fast_create(User) | |
99 | - | |
100 | - user.email = "testtest@gov.br" | |
101 | - | |
102 | - user.institutions = [] | |
103 | - assert !user.save, "this should not save" | |
104 | - | |
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! | |
110 | - | |
111 | - user.institutions << institution | |
112 | - assert user.save, "this should save" | |
113 | - end | |
114 | - | |
115 | - private | |
116 | - | |
117 | - def create_default_user | |
118 | - user = fast_create(User) | |
119 | - user.login = "a-login" | |
120 | - user.email = "primary@email.com" | |
121 | - user.secondary_email = "secondary@email.com" | |
122 | - user.save | |
123 | - | |
124 | - return user | |
125 | - end | |
126 | - | |
127 | -end |
test/unit/plugin_test_helper.rb
1 | +require File.dirname(__FILE__) + '/../helpers/institution_test_helper' | |
2 | + | |
1 | 3 | module PluginTestHelper |
2 | 4 | |
5 | + def create_public_institution *params | |
6 | + InstitutionTestHelper.create_public_institution *params | |
7 | + end | |
8 | + | |
3 | 9 | def create_community name |
4 | 10 | community = fast_create(Community) |
5 | 11 | community.name = name |
... | ... | @@ -15,29 +21,8 @@ module PluginTestHelper |
15 | 21 | software_info |
16 | 22 | end |
17 | 23 | |
18 | - def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s | |
19 | - institution = PublicInstitution.new | |
20 | - institution.community = create_community_institution(name, country, state, city) | |
21 | - institution.name = name | |
22 | - institution.juridical_nature = juridical_nature | |
23 | - institution.sisp = false | |
24 | - institution.acronym = acronym | |
25 | - institution.governmental_power = gov_p | |
26 | - institution.governmental_sphere = gov_s | |
27 | - institution.save | |
28 | - | |
29 | - institution | |
30 | - end | |
31 | - | |
32 | - def create_private_institution name, cnpj, country, state, city | |
33 | - institution = PrivateInstitution.new | |
34 | - institution.community = create_community_institution(name, country, state, city) | |
35 | - institution.name = name | |
36 | - institution.sisp = false | |
37 | - institution.cnpj = cnpj | |
38 | - institution.save | |
39 | - | |
40 | - institution | |
24 | + def create_private_institution *params | |
25 | + InstitutionTestHelper.create_private_institution *params | |
41 | 26 | end |
42 | 27 | |
43 | 28 | def create_community_institution name, country, state, city | ... | ... |
test/unit/private_institution_test.rb
... | ... | @@ -4,7 +4,7 @@ require File.dirname(__FILE__) + '/plugin_test_helper' |
4 | 4 | class PrivateInstitutionTest < ActiveSupport::TestCase |
5 | 5 | include PluginTestHelper |
6 | 6 | def setup |
7 | - @institution = create_private_institution "Simple Private Institution", "00.000.000/0001-00", "BR", "DF", "Gama" | |
7 | + @institution = create_private_institution "Simple Private Institution", "SPI", "BR", "DF", "Gama", "00.000.000/0001-00" | |
8 | 8 | end |
9 | 9 | |
10 | 10 | should "not save without a cnpj" do |
... | ... | @@ -16,8 +16,8 @@ class PrivateInstitutionTest < ActiveSupport::TestCase |
16 | 16 | |
17 | 17 | should "not save with a repeated cnpj" do |
18 | 18 | assert @institution.save |
19 | - sec_institution = create_private_institution "Another Private Institution", "00.000.000/0001-00", "BR", "DF", "Gama" | |
20 | - assert !sec_institution.save | |
19 | + sec_institution = create_private_institution "Another Private Institution", "API", "BR", "DF", "Gama", "00.000.000/0001-00" | |
20 | + | |
21 | 21 | assert sec_institution.errors.full_messages.include? "Cnpj has already been taken" |
22 | 22 | end |
23 | 23 | ... | ... |
test/unit/public_institution_test.rb
... | ... | @@ -8,12 +8,12 @@ class PublicInstitutionTest < ActiveSupport::TestCase |
8 | 8 | @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") |
9 | 9 | @juridical_nature = JuridicalNature.create(:name => "Autarquia") |
10 | 10 | |
11 | - @institution = create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @gov_power, @gov_sphere) | |
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 | 12 | end |
13 | 13 | |
14 | - should "save without a cnpj" do | |
14 | + should "not save without a cnpj" do | |
15 | 15 | @institution.cnpj = nil |
16 | - assert @institution.save | |
16 | + assert !@institution.save | |
17 | 17 | end |
18 | 18 | |
19 | 19 | should "save institution without an acronym" do | ... | ... |
test/unit/software_categories_test.rb
... | ... | @@ -41,6 +41,11 @@ class SoftwareCategoriesTest < ActiveSupport::TestCase |
41 | 41 | @software_info.software_categories = @software_categories |
42 | 42 | end |
43 | 43 | |
44 | + def teardown | |
45 | + SoftwareDatabase.destroy_all | |
46 | + DatabaseDescription.destroy_all | |
47 | + end | |
48 | + | |
44 | 49 | should "save software correctly with SoftwareCategories filds" do |
45 | 50 | assert @software_info.save |
46 | 51 | end | ... | ... |
test/unit/software_database_test.rb
... | ... | @@ -8,6 +8,11 @@ class SoftwareDatabaseTest < ActiveSupport::TestCase |
8 | 8 | @software_database.database_description_id = 1 |
9 | 9 | end |
10 | 10 | |
11 | + def teardown | |
12 | + DatabaseDescription.destroy_all | |
13 | + SoftwareDatabase.destroy_all | |
14 | + end | |
15 | + | |
11 | 16 | should "save if all informations of @software_database are filled" do |
12 | 17 | assert @software_database.save, "Database should have been saved" |
13 | 18 | end | ... | ... |