Commit 35138b91c33727e7fcbe1da4cc44db6cf90be72d
Committed by
Gabriela Navarro
1 parent
10afab41
Exists in
master
and in
5 other branches
fix_institution: Test for institution edition
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
3 changed files
with
91 additions
and
56 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,44 @@ |
| 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_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 | + institution = PublicInstitution.new | |
| 33 | + institution.community = institution_community | |
| 34 | + institution.name = name | |
| 35 | + institution.juridical_nature = juridical_nature | |
| 36 | + institution.acronym = acronym | |
| 37 | + institution.governmental_power = gov_p | |
| 38 | + institution.governmental_sphere = gov_s | |
| 39 | + institution.cnpj = cnpj | |
| 40 | + institution.corporate_name = "corporate default" | |
| 41 | + institution.save! | |
| 42 | + institution | |
| 43 | + end | |
| 44 | +end | |
| 0 | 45 | \ 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 | 3 | require File.dirname(__FILE__) + '/../../controllers/mpog_software_plugin_controller' |
| 3 | 4 | |
| 4 | 5 | class MpogSoftwarePluginController; def rescue_action(e) raise e end; end |
| ... | ... | @@ -6,12 +7,12 @@ class MpogSoftwarePluginController; def rescue_action(e) raise e end; end |
| 6 | 7 | class MpogSoftwarePluginControllerTest < ActionController::TestCase |
| 7 | 8 | |
| 8 | 9 | def setup |
| 9 | - admin = create_user("adminuser").person | |
| 10 | - admin.stubs(:has_permission?).returns("true") | |
| 10 | + @admin = create_user("adminuser").person | |
| 11 | + @admin.stubs(:has_permission?).returns("true") | |
| 11 | 12 | |
| 12 | 13 | @environment = Environment.default |
| 13 | 14 | @environment.enabled_plugins = ['MpogSoftwarePlugin'] |
| 14 | - @environment.add_admin(admin) | |
| 15 | + @environment.add_admin(@admin) | |
| 15 | 16 | @environment.save |
| 16 | 17 | |
| 17 | 18 | @govPower = GovernmentalPower.create(:name=>"Some Gov Power") |
| ... | ... | @@ -20,8 +21,8 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase |
| 20 | 21 | @response = ActionController::TestResponse.new |
| 21 | 22 | |
| 22 | 23 | @institution_list = [] |
| 23 | - @institution_list << create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @govPower, @govSphere, "12.345.678/9012-45") | |
| 24 | - @institution_list << create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", @juridical_nature, @govPower, @govSphere, "12.345.678/9012-90") | |
| 24 | + @institution_list << InstitutionTestHelper.create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @govPower, @govSphere, "12.345.678/9012-45") | |
| 25 | + @institution_list << InstitutionTestHelper.create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", @juridical_nature, @govPower, @govSphere, "12.345.678/9012-90") | |
| 25 | 26 | end |
| 26 | 27 | |
| 27 | 28 | should "Search for institution with acronym" do |
| ... | ... | @@ -50,6 +51,7 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase |
| 50 | 51 | end |
| 51 | 52 | |
| 52 | 53 | should "method create_institution return the html for modal" do |
| 54 | + @controller.stubs(:current_user).returns(@admin.user) | |
| 53 | 55 | xhr :get, :create_institution |
| 54 | 56 | assert_template 'create_institution' |
| 55 | 57 | end |
| ... | ... | @@ -57,7 +59,7 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase |
| 57 | 59 | should "create new institution with ajax without acronym" do |
| 58 | 60 | @controller.stubs(:verify_recaptcha).returns(true) |
| 59 | 61 | |
| 60 | - fields = generate_form_fields "foo bar", "BR", "DF", "Brasilia", "12.234.567/8900-10", "PublicInstitution" | |
| 62 | + fields = InstitutionTestHelper.generate_form_fields "foo bar", "BR", "DF", "Brasilia", "12.234.567/8900-10", "PublicInstitution" | |
| 61 | 63 | fields[:institutions][:governmental_power] = @govPower.id |
| 62 | 64 | fields[:institutions][:governmental_sphere] = @govSphere.id |
| 63 | 65 | fields[:institutions][:juridical_nature] = @juridical_nature.id |
| ... | ... | @@ -72,7 +74,7 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase |
| 72 | 74 | should "not create a institution that already exists" do |
| 73 | 75 | @controller.stubs(:verify_recaptcha).returns(true) |
| 74 | 76 | |
| 75 | - fields = generate_form_fields "Ministerio Publico da Uniao", "BR", "DF", "Brasilia", "12.234.567/8900-10", "PublicInstitution" | |
| 77 | + fields = InstitutionTestHelper.generate_form_fields "Ministerio Publico da Uniao", "BR", "DF", "Brasilia", "12.234.567/8900-10", "PublicInstitution" | |
| 76 | 78 | fields[:institutions][:governmental_power] = @govPower.id |
| 77 | 79 | fields[:institutions][:governmental_sphere] = @govSphere.id |
| 78 | 80 | fields[:institutions][:juridical_nature] = @juridical_nature.id |
| ... | ... | @@ -87,7 +89,7 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase |
| 87 | 89 | should "not create a institution without cnpj" do |
| 88 | 90 | @controller.stubs(:verify_recaptcha).returns(true) |
| 89 | 91 | |
| 90 | - fields = generate_form_fields "Some Private Institution", "BR", "DF", "Brasilia", "", "PrivateInstitution" | |
| 92 | + fields = InstitutionTestHelper.generate_form_fields "Some Private Institution", "BR", "DF", "Brasilia", "", "PrivateInstitution" | |
| 91 | 93 | fields[:institutions][:acronym] = "SPI" |
| 92 | 94 | |
| 93 | 95 | xhr :get, :new_institution, fields |
| ... | ... | @@ -129,7 +131,7 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase |
| 129 | 131 | should "Create new institution with method post" do |
| 130 | 132 | @controller.stubs(:verify_recaptcha).returns(true) |
| 131 | 133 | |
| 132 | - fields = generate_form_fields "Some Private Institution", "BR", "DF", "Brasilia", "12.345.567/8900-10", "PrivateInstitution" | |
| 134 | + fields = InstitutionTestHelper.generate_form_fields "Some Private Institution", "BR", "DF", "Brasilia", "12.345.567/8900-10", "PrivateInstitution" | |
| 133 | 135 | fields[:institutions][:acronym] = "SPI" |
| 134 | 136 | |
| 135 | 137 | post :new_institution, fields |
| ... | ... | @@ -140,7 +142,7 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase |
| 140 | 142 | should "not create new institution with method post without cnpj" do |
| 141 | 143 | @controller.stubs(:verify_recaptcha).returns(true) |
| 142 | 144 | |
| 143 | - fields = generate_form_fields "Some Private Institution", "BR", "DF", "Brasilia", "", "PrivateInstitution" | |
| 145 | + fields = InstitutionTestHelper.generate_form_fields "Some Private Institution", "BR", "DF", "Brasilia", "", "PrivateInstitution" | |
| 144 | 146 | fields[:institutions][:acronym] = "SPI" |
| 145 | 147 | |
| 146 | 148 | post :new_institution, fields |
| ... | ... | @@ -151,7 +153,7 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase |
| 151 | 153 | should "Create foreign institution without city, state and cnpj by post" do |
| 152 | 154 | @controller.stubs(:verify_recaptcha).returns(true) |
| 153 | 155 | |
| 154 | - fields = generate_form_fields "Foreign institution", "AZ", "", "", "", "PrivateInstitution" | |
| 156 | + fields = InstitutionTestHelper.generate_form_fields "Foreign institution", "AZ", "", "", "", "PrivateInstitution" | |
| 155 | 157 | fields[:institutions][:acronym] = "FI" |
| 156 | 158 | |
| 157 | 159 | post :new_institution, fields |
| ... | ... | @@ -162,7 +164,7 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase |
| 162 | 164 | should "Create foreign institution without city, state and cnpj by ajax" do |
| 163 | 165 | @controller.stubs(:verify_recaptcha).returns(true) |
| 164 | 166 | |
| 165 | - fields = generate_form_fields "Foreign institution", "AZ", "", "", "", "PrivateInstitution" | |
| 167 | + fields = InstitutionTestHelper.generate_form_fields "Foreign institution", "AZ", "", "", "", "PrivateInstitution" | |
| 166 | 168 | fields[:institutions][:acronym] = "FI" |
| 167 | 169 | |
| 168 | 170 | xhr :post, :new_institution, fields |
| ... | ... | @@ -171,48 +173,4 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase |
| 171 | 173 | assert json_response["success"] |
| 172 | 174 | end |
| 173 | 175 | |
| 174 | - private | |
| 175 | - | |
| 176 | - def generate_form_fields name, country, state, city, cnpj, type | |
| 177 | - fields = { | |
| 178 | - :community => { | |
| 179 | - :name => name, | |
| 180 | - :country => country, | |
| 181 | - :state => state, | |
| 182 | - :city => city | |
| 183 | - }, | |
| 184 | - :institutions => { | |
| 185 | - :cnpj=> cnpj, | |
| 186 | - :type => type, | |
| 187 | - :acronym => "", | |
| 188 | - :governmental_power => "", | |
| 189 | - :governmental_sphere => "", | |
| 190 | - :juridical_nature => "", | |
| 191 | - :corporate_name => "coporate default" | |
| 192 | - } | |
| 193 | - } | |
| 194 | - fields | |
| 195 | - end | |
| 196 | - | |
| 197 | - def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s, cnpj | |
| 198 | - institution_community = fast_create(Community) | |
| 199 | - institution_community.name = name | |
| 200 | - institution_community.country = country | |
| 201 | - institution_community.state = state | |
| 202 | - institution_community.city = city | |
| 203 | - institution_community.save! | |
| 204 | - | |
| 205 | - institution = PublicInstitution.new | |
| 206 | - institution.community = institution_community | |
| 207 | - institution.name = name | |
| 208 | - institution.juridical_nature = juridical_nature | |
| 209 | - institution.acronym = acronym | |
| 210 | - institution.governmental_power = gov_p | |
| 211 | - institution.governmental_sphere = gov_s | |
| 212 | - institution.cnpj = cnpj | |
| 213 | - institution.corporate_name = "corporate default" | |
| 214 | - institution.save! | |
| 215 | - institution | |
| 216 | - end | |
| 217 | - | |
| 218 | 176 | 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 | 5 | |
| 5 | 6 | class MpogSoftwarePluginMyprofileController; def rescue_action(e) raise e end; |
| 6 | 7 | end |
| ... | ... | @@ -100,4 +101,36 @@ class MpogSoftwarePluginMyprofileControllerTest < ActionController::TestCase |
| 100 | 101 | assert_equal true, SoftwareInfo.last.public_software? |
| 101 | 102 | end |
| 102 | 103 | |
| 104 | + should "user edit its community institution" do | |
| 105 | + govPower = GovernmentalPower.create(:name=>"Some Gov Power") | |
| 106 | + govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
| 107 | + juridical_nature = JuridicalNature.create(:name => "Autarquia") | |
| 108 | + | |
| 109 | + institution = InstitutionTestHelper.create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", juridical_nature, govPower, govSphere, "12.345.678/9012-45") | |
| 110 | + identifier = institution.community.identifier | |
| 111 | + | |
| 112 | + fields = InstitutionTestHelper.generate_form_fields "institution new name", "BR", "DF", "Gama", "12.345.678/9012-45", "PrivateInstitution" | |
| 113 | + | |
| 114 | + post :edit_institution, :profile=>institution.community.identifier, :community=>fields[:community], :institutions=>fields[:institutions] | |
| 115 | + | |
| 116 | + institution = Community[identifier].institution | |
| 117 | + assert_not_equal "Ministerio Publico da Uniao", institution.community.name | |
| 118 | + end | |
| 119 | + | |
| 120 | + should "not user edit its community institution with wrong values" do | |
| 121 | + govPower = GovernmentalPower.create(:name=>"Some Gov Power") | |
| 122 | + govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
| 123 | + juridical_nature = JuridicalNature.create(:name => "Autarquia") | |
| 124 | + | |
| 125 | + institution = InstitutionTestHelper.create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", juridical_nature, govPower, govSphere, "12.345.678/9012-45") | |
| 126 | + identifier = institution.community.identifier | |
| 127 | + | |
| 128 | + fields = InstitutionTestHelper.generate_form_fields "", "BR", "DF", "Gama", "6465465465", "PrivateInstitution" | |
| 129 | + | |
| 130 | + post :edit_institution, :profile=>institution.community.identifier, :community=>fields[:community], :institutions=>fields[:institutions] | |
| 131 | + | |
| 132 | + institution = Community[identifier].institution | |
| 133 | + assert_equal "Ministerio Publico da Uniao", institution.community.name | |
| 134 | + assert_equal "12.345.678/9012-45", institution.cnpj | |
| 135 | + end | |
| 103 | 136 | end | ... | ... |