Commit 2fba64786c7663f93eb2f5bb8c7a1a8f2569b57a
1 parent
0a3a013b
Exists in
fix_edit_institution
Tests institution edit without permission
Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com> Signed-off-by: Omar Junior <omarroinuj@gmail.com>
Showing
1 changed file
with
35 additions
and
29 deletions
Show diff stats
src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb
| ... | ... | @@ -18,30 +18,30 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase |
| 18 | 18 | @offer_1 = create_user('Ana de Souza') |
| 19 | 19 | @offer_2 = create_user('Angelo Roberto') |
| 20 | 20 | |
| 21 | - login_as(@person.user_login) | |
| 22 | - @environment = Environment.default | |
| 23 | - @environment.enable_plugin('GovUserPlugin') | |
| 24 | - @environment.save! | |
| 25 | - end | |
| 26 | - should "user edit its community institution" do | |
| 27 | - govPower = GovernmentalPower.create(:name=>"Some Gov Power") | |
| 28 | - govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
| 21 | + gov_power = GovernmentalPower.create(:name=>"Some Gov Power") | |
| 22 | + gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
| 29 | 23 | juridical_nature = JuridicalNature.create(:name => "Autarquia") |
| 30 | - | |
| 31 | - institution = InstitutionTestHelper.create_public_institution( | |
| 24 | + @institution = InstitutionTestHelper.create_public_institution( | |
| 32 | 25 | "Ministerio Publico da Uniao", |
| 33 | 26 | "MPU", |
| 34 | 27 | "BR", |
| 35 | 28 | "DF", |
| 36 | 29 | "Gama", |
| 37 | 30 | juridical_nature, |
| 38 | - govPower, | |
| 39 | - govSphere, | |
| 31 | + gov_power, | |
| 32 | + gov_sphere, | |
| 40 | 33 | "12.345.678/9012-45" |
| 41 | 34 | ) |
| 42 | 35 | |
| 43 | - institution.community.add_admin @person | |
| 44 | - identifier = institution.community.identifier | |
| 36 | + login_as(@person.user_login) | |
| 37 | + @environment = Environment.default | |
| 38 | + @environment.enable_plugin('GovUserPlugin') | |
| 39 | + @environment.save! | |
| 40 | + end | |
| 41 | + | |
| 42 | + should "admin user edit an institution" do | |
| 43 | + @institution.community.add_admin @person | |
| 44 | + identifier = @institution.community.identifier | |
| 45 | 45 | |
| 46 | 46 | fields = InstitutionTestHelper.generate_form_fields( |
| 47 | 47 | "institution new name", |
| ... | ... | @@ -54,7 +54,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase |
| 54 | 54 | |
| 55 | 55 | post( |
| 56 | 56 | :edit_institution, |
| 57 | - :profile=>institution.community.identifier, | |
| 57 | + :profile=>@institution.community.identifier, | |
| 58 | 58 | :community=>fields[:community], |
| 59 | 59 | :institutions=>fields[:institutions] |
| 60 | 60 | ) |
| ... | ... | @@ -63,25 +63,31 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase |
| 63 | 63 | assert_not_equal "Ministerio Publico da Uniao", institution.community.name |
| 64 | 64 | end |
| 65 | 65 | |
| 66 | - should "not user edit its community institution with wrong values" do | |
| 67 | - govPower = GovernmentalPower.create(:name=>"Some Gov Power") | |
| 68 | - govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
| 69 | - juridical_nature = JuridicalNature.create(:name => "Autarquia") | |
| 70 | - | |
| 71 | - institution = InstitutionTestHelper.create_public_institution( | |
| 72 | - "Ministerio Publico da Uniao", | |
| 73 | - "MPU", | |
| 66 | + should "regular user should not edit an institution" do | |
| 67 | + identifier = @institution.community.identifier | |
| 68 | + fields = InstitutionTestHelper.generate_form_fields( | |
| 69 | + "institution new name", | |
| 74 | 70 | "BR", |
| 75 | 71 | "DF", |
| 76 | 72 | "Gama", |
| 77 | - juridical_nature, | |
| 78 | - govPower, | |
| 79 | - govSphere, | |
| 80 | - "12.345.678/9012-45" | |
| 73 | + "12.345.678/9012-45", | |
| 74 | + "PrivateInstitution" | |
| 75 | + ) | |
| 76 | + | |
| 77 | + post( | |
| 78 | + :edit_institution, | |
| 79 | + :profile=>@institution.community.identifier, | |
| 80 | + :community=>fields[:community], | |
| 81 | + :institutions=>fields[:institutions] | |
| 81 | 82 | ) |
| 82 | 83 | |
| 83 | - identifier = institution.community.identifier | |
| 84 | + institution = Community[identifier].institution | |
| 85 | + assert_equal "Ministerio Publico da Uniao", institution.community.name | |
| 86 | + assert_response 403 | |
| 87 | + end | |
| 84 | 88 | |
| 89 | + should "not user edit its community institution with wrong values" do | |
| 90 | + identifier = @institution.community.identifier | |
| 85 | 91 | fields = InstitutionTestHelper.generate_form_fields( |
| 86 | 92 | "", |
| 87 | 93 | "BR", |
| ... | ... | @@ -93,7 +99,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase |
| 93 | 99 | |
| 94 | 100 | post( |
| 95 | 101 | :edit_institution, |
| 96 | - :profile=>institution.community.identifier, | |
| 102 | + :profile=>@institution.community.identifier, | |
| 97 | 103 | :community=>fields[:community], |
| 98 | 104 | :institutions=>fields[:institutions] |
| 99 | 105 | ) | ... | ... |