Commit a04fdedc7dc028ef4aa763fd404c1b9a73c0ffde
Committed by
Arthur Esposte
1 parent
2ef130ea
Exists in
master
and in
5 other branches
Add test for new institution fields.
Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> Signed-off-by: Parley Martins <parley@outlook.com>
Showing
4 changed files
with
116 additions
and
17 deletions
Show diff stats
test/unit/institution_test.rb
@@ -2,15 +2,46 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' | @@ -2,15 +2,46 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | 2 | ||
3 | class InstitutionTest < ActiveSupport::TestCase | 3 | class InstitutionTest < ActiveSupport::TestCase |
4 | 4 | ||
5 | - should "save public institutions without name" do | ||
6 | - institution = Institution::new | ||
7 | - assert !institution.save | ||
8 | - assert institution.errors.full_messages.include? "Name can't be blank" | 5 | + def setup |
6 | + community = Community.create(:name => "Simple Public Institution") | ||
7 | + | ||
8 | + @institution = Institution::new :name=>"Simple Institution" | ||
9 | + | ||
10 | + @institution.community = community | ||
11 | + @institution.community.country = "BR" | ||
12 | + @institution.community.state = "DF" | ||
13 | + @institution.community.city = "Gama" | ||
14 | + end | ||
15 | + | ||
16 | + should "not save institutions without name" do | ||
17 | + @institution.name = nil | ||
18 | + assert !@institution.save | ||
19 | + assert @institution.errors.full_messages.include? "Name can't be blank" | ||
9 | end | 20 | end |
10 | 21 | ||
11 | should "not save if institution has invalid type" do | 22 | should "not save if institution has invalid type" do |
12 | - institution = Institution::new :name => "teste", :type => "Other type" | ||
13 | - assert !institution.save | ||
14 | - assert institution.errors.full_messages.include? "Type invalid, only public and private institutions are allowed." | 23 | + @institution.type = "Other type" |
24 | + assert !@institution.save | ||
25 | + assert @institution.errors.full_messages.include? "Type invalid, only public and private institutions are allowed." | ||
26 | + end | ||
27 | + | ||
28 | + should "not save without country" do | ||
29 | + @institution.community.country = nil | ||
30 | + assert !@institution.save, "Country can't be blank" | ||
31 | + assert @institution.errors.full_messages.include? "Country can't be blank" | ||
32 | + end | ||
33 | + | ||
34 | + should "not save without state" do | ||
35 | + @institution.community.state = nil | ||
36 | + | ||
37 | + assert !@institution.save, "State can't be blank" | ||
38 | + assert @institution.errors.full_messages.include? "State can't be blank" | ||
39 | + end | ||
40 | + | ||
41 | + should "not save without city" do | ||
42 | + @institution.community.city = nil | ||
43 | + | ||
44 | + assert !@institution.save, "City can't be blank" | ||
45 | + assert @institution.errors.full_messages.include? "City can't be blank" | ||
15 | end | 46 | end |
16 | -end | ||
17 | \ No newline at end of file | 47 | \ No newline at end of file |
48 | +end |
@@ -0,0 +1,44 @@ | @@ -0,0 +1,44 @@ | ||
1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | + | ||
3 | +class JuridicalNatureTest < ActiveSupport::TestCase | ||
4 | + def teardown | ||
5 | + Institution.destroy_all | ||
6 | + end | ||
7 | + | ||
8 | + should "get public institutions" do | ||
9 | + juri_nature = JuridicalNature::new :name=>"Some juri nature" | ||
10 | + | ||
11 | + assert build_institution("one").save | ||
12 | + assert build_institution("two").save | ||
13 | + assert build_institution("three").save | ||
14 | + | ||
15 | + assert juri_nature.public_institutions.count == PublicInstitution.count | ||
16 | + end | ||
17 | + | ||
18 | + should "not get private institutions" do | ||
19 | + juri_nature = JuridicalNature::new :name=>"Some juri nature" | ||
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 juri_nature.public_institutions.count == 0 | ||
26 | + assert juri_nature.public_institutions.count == PublicInstitution.count | ||
27 | + assert juri_nature.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 | + if type == "PublicInstitution" | ||
39 | + institution.juridical_nature = JuridicalNature.first | ||
40 | + end | ||
41 | + | ||
42 | + institution | ||
43 | + end | ||
44 | +end |
test/unit/private_institution_test.rb
@@ -2,8 +2,13 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' | @@ -2,8 +2,13 @@ require File.dirname(__FILE__) + '/../../../../test/test_helper' | ||
2 | 2 | ||
3 | class PrivateInstitutionTest < ActiveSupport::TestCase | 3 | class PrivateInstitutionTest < ActiveSupport::TestCase |
4 | def setup | 4 | def setup |
5 | + community = Community.create(:name => "Simple Private Institution") | ||
5 | @institution = PrivateInstitution::new :name=>"Simple Private Institution", | 6 | @institution = PrivateInstitution::new :name=>"Simple Private Institution", |
6 | :cnpj=>"00.000.000/0001-00" | 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 | end | 12 | end |
8 | 13 | ||
9 | should "not save without a cnpj" do | 14 | should "not save without a cnpj" do |
@@ -18,8 +23,16 @@ class PrivateInstitutionTest < ActiveSupport::TestCase | @@ -18,8 +23,16 @@ class PrivateInstitutionTest < ActiveSupport::TestCase | ||
18 | 23 | ||
19 | sec_institution = PrivateInstitution::new :name=>"Another Private Institution", | 24 | sec_institution = PrivateInstitution::new :name=>"Another Private Institution", |
20 | :cnpj=>"00.000.000/0001-00" | 25 | :cnpj=>"00.000.000/0001-00" |
26 | + sec_institution.community = Community.create(:name => "Another Private Institution") | ||
21 | 27 | ||
22 | assert !sec_institution.save | 28 | assert !sec_institution.save |
23 | assert sec_institution.errors.full_messages.include? "Cnpj has already been taken" | 29 | assert sec_institution.errors.full_messages.include? "Cnpj has already been taken" |
24 | end | 30 | end |
25 | -end | ||
26 | \ No newline at end of file | 31 | \ No newline at end of file |
32 | + | ||
33 | + should "save without fantasy name" do | ||
34 | + @institution.acronym = nil | ||
35 | + @institution.community.save | ||
36 | + | ||
37 | + assert @institution.save | ||
38 | + end | ||
39 | +end |
test/unit/public_institution_test.rb
@@ -4,22 +4,26 @@ class PublicInstitutionTest < ActiveSupport::TestCase | @@ -4,22 +4,26 @@ class PublicInstitutionTest < ActiveSupport::TestCase | ||
4 | def setup | 4 | def setup |
5 | govPower = GovernmentalPower.create(:name=>"Some Gov Power") | 5 | govPower = GovernmentalPower.create(:name=>"Some Gov Power") |
6 | govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | 6 | govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") |
7 | + juriNature = JuridicalNature.create(:name => "Some jurid nature") | ||
8 | + community = Community.create(:name => "Simple Public Institution") | ||
7 | 9 | ||
8 | @institution = PublicInstitution::new :name=>"Simple Public Institution", :acronym=>"SPI", | 10 | @institution = PublicInstitution::new :name=>"Simple Public Institution", :acronym=>"SPI", |
9 | - :governmental_power=>govPower, :governmental_sphere=>govSphere | 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" | ||
10 | end | 17 | end |
11 | 18 | ||
12 | should "save without a cnpj" do | 19 | should "save without a cnpj" do |
13 | @institution.cnpj = nil | 20 | @institution.cnpj = nil |
14 | - | ||
15 | - assert @institution.save | 21 | + assert @institution.save |
16 | end | 22 | end |
17 | 23 | ||
18 | - should "Not save institution without an acronym" do | 24 | + should "save institution without an acronym" do |
19 | @institution.acronym = nil | 25 | @institution.acronym = nil |
20 | - | ||
21 | - assert !@institution.save | ||
22 | - assert @institution.errors.full_messages.include? "Acronym can't be blank" | 26 | + assert @institution.save |
23 | end | 27 | end |
24 | 28 | ||
25 | should "Not save institution without a governmental_power" do | 29 | should "Not save institution without a governmental_power" do |
@@ -35,4 +39,11 @@ class PublicInstitutionTest < ActiveSupport::TestCase | @@ -35,4 +39,11 @@ class PublicInstitutionTest < ActiveSupport::TestCase | ||
35 | assert !@institution.save | 39 | assert !@institution.save |
36 | assert @institution.errors.full_messages.include? "Governmental sphere can't be blank" | 40 | assert @institution.errors.full_messages.include? "Governmental sphere can't be blank" |
37 | end | 41 | end |
38 | -end | ||
39 | \ No newline at end of file | 42 | \ No newline at end of file |
43 | + | ||
44 | + should "not save institution without juridical nature" do | ||
45 | + @institution.juridical_nature = nil | ||
46 | + | ||
47 | + assert !@institution.save | ||
48 | + assert @institution.errors.full_messages.include? "Juridical nature can't be blank" | ||
49 | + end | ||
50 | +end |