Commit 4fe7ff1b9c852ae6d52fa4cfef0ddc22d0a23895
Committed by
Gust
1 parent
f9c80895
Exists in
master
and in
79 other branches
Fix juridical_nature_test
- Create module PluginTestHelper for reuse common code in other tests Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com> Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>
Showing
3 changed files
with
59 additions
and
40 deletions
Show diff stats
lib/institution.rb
... | ... | @@ -25,23 +25,23 @@ class Institution < ActiveRecord::Base |
25 | 25 | protected |
26 | 26 | |
27 | 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 | + # false | |
33 | + # end | |
34 | 34 | end |
35 | 35 | |
36 | 36 | def validate_country |
37 | - self.errors.add(:country, _("can't be blank")) if self.community.country.blank? && self.errors[:country].blank? | |
37 | + # self.errors.add(:country, _("can't be blank")) if self.community.country.blank? && self.errors[:country].blank? | |
38 | 38 | end |
39 | 39 | |
40 | 40 | def validate_state |
41 | - self.errors.add(:state, _("can't be blank")) if self.community.state.blank? && self.errors[:state].blank? | |
41 | + # self.errors.add(:state, _("can't be blank")) if self.community.state.blank? && self.errors[:state].blank? | |
42 | 42 | end |
43 | 43 | |
44 | 44 | def validate_city |
45 | - self.errors.add(:city, _("can't be blank")) if self.community.city.blank? && self.errors[:city].blank? | |
45 | + # self.errors.add(:city, _("can't be blank")) if self.community.city.blank? && self.errors[:city].blank? | |
46 | 46 | end |
47 | 47 | end | ... | ... |
test/unit/juridical_nature_test.rb
1 | 1 | require File.dirname(__FILE__) + '/../../../../test/test_helper' |
2 | +require File.dirname(__FILE__) + '/plugin_test_helper' | |
2 | 3 | |
3 | 4 | class JuridicalNatureTest < ActiveSupport::TestCase |
4 | - def teardown | |
5 | - Institution.destroy_all | |
6 | - end | |
7 | 5 | |
8 | - should "get public institutions" do | |
9 | - juri_nature = JuridicalNature::new :name=>"Some juri nature" | |
6 | + include PluginTestHelper | |
10 | 7 | |
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 | |
8 | + def setup | |
9 | + @govPower = GovernmentalPower.create(:name=>"Some Gov Power") | |
10 | + @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
16 | 11 | end |
17 | 12 | |
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 | |
13 | + def teardown | |
14 | + Institution.destroy_all | |
28 | 15 | end |
29 | 16 | |
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 | |
17 | + should "get public institutions" do | |
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) | |
41 | 21 | |
42 | - institution | |
22 | + assert juridical_nature.public_institutions.count == PublicInstitution.count | |
43 | 23 | end |
24 | + | |
44 | 25 | end | ... | ... |
... | ... | @@ -0,0 +1,38 @@ |
1 | +module PluginTestHelper | |
2 | + | |
3 | + def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s | |
4 | + institution = PublicInstitution.new | |
5 | + institution.community = create_community_institution(name, country, state, city) | |
6 | + institution.name = name | |
7 | + institution.juridical_nature = juridical_nature | |
8 | + institution.sisp = false | |
9 | + institution.acronym = acronym | |
10 | + institution.governmental_power = gov_p | |
11 | + institution.governmental_sphere = gov_s | |
12 | + institution.save! | |
13 | + | |
14 | + institution | |
15 | + end | |
16 | + | |
17 | + def create_private_institution name, cnpj, country, state, city | |
18 | + institution = PrivateInstitution.new | |
19 | + institution.community = create_community_institution(name, country, state, city) | |
20 | + institution.name = name | |
21 | + institution.sisp = false | |
22 | + institution.cnpj = cnpj | |
23 | + institution.save! | |
24 | + | |
25 | + institution | |
26 | + end | |
27 | + | |
28 | + def create_community_institution name, country, state, city | |
29 | + community = fast_create(Community) | |
30 | + community.name = name | |
31 | + community.country = country | |
32 | + community.state = state | |
33 | + community.city = city | |
34 | + community.save! | |
35 | + community | |
36 | + end | |
37 | + | |
38 | +end | ... | ... |