Commit 2fba64786c7663f93eb2f5bb8c7a1a8f2569b57a

Authored by Gabriel Silva
1 parent 0a3a013b

Tests institution edit without permission

Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
Signed-off-by: Omar Junior <omarroinuj@gmail.com>
src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb
@@ -18,30 +18,30 @@ class GovUserPluginMyprofileControllerTest &lt; ActionController::TestCase @@ -18,30 +18,30 @@ class GovUserPluginMyprofileControllerTest &lt; ActionController::TestCase
18 @offer_1 = create_user('Ana de Souza') 18 @offer_1 = create_user('Ana de Souza')
19 @offer_2 = create_user('Angelo Roberto') 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 juridical_nature = JuridicalNature.create(:name => "Autarquia") 23 juridical_nature = JuridicalNature.create(:name => "Autarquia")
30 -  
31 - institution = InstitutionTestHelper.create_public_institution( 24 + @institution = InstitutionTestHelper.create_public_institution(
32 "Ministerio Publico da Uniao", 25 "Ministerio Publico da Uniao",
33 "MPU", 26 "MPU",
34 "BR", 27 "BR",
35 "DF", 28 "DF",
36 "Gama", 29 "Gama",
37 juridical_nature, 30 juridical_nature,
38 - govPower,  
39 - govSphere, 31 + gov_power,
  32 + gov_sphere,
40 "12.345.678/9012-45" 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 fields = InstitutionTestHelper.generate_form_fields( 46 fields = InstitutionTestHelper.generate_form_fields(
47 "institution new name", 47 "institution new name",
@@ -54,7 +54,7 @@ class GovUserPluginMyprofileControllerTest &lt; ActionController::TestCase @@ -54,7 +54,7 @@ class GovUserPluginMyprofileControllerTest &lt; ActionController::TestCase
54 54
55 post( 55 post(
56 :edit_institution, 56 :edit_institution,
57 - :profile=>institution.community.identifier, 57 + :profile=>@institution.community.identifier,
58 :community=>fields[:community], 58 :community=>fields[:community],
59 :institutions=>fields[:institutions] 59 :institutions=>fields[:institutions]
60 ) 60 )
@@ -63,25 +63,31 @@ class GovUserPluginMyprofileControllerTest &lt; ActionController::TestCase @@ -63,25 +63,31 @@ class GovUserPluginMyprofileControllerTest &lt; ActionController::TestCase
63 assert_not_equal "Ministerio Publico da Uniao", institution.community.name 63 assert_not_equal "Ministerio Publico da Uniao", institution.community.name
64 end 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 "BR", 70 "BR",
75 "DF", 71 "DF",
76 "Gama", 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 fields = InstitutionTestHelper.generate_form_fields( 91 fields = InstitutionTestHelper.generate_form_fields(
86 "", 92 "",
87 "BR", 93 "BR",
@@ -93,7 +99,7 @@ class GovUserPluginMyprofileControllerTest &lt; ActionController::TestCase @@ -93,7 +99,7 @@ class GovUserPluginMyprofileControllerTest &lt; ActionController::TestCase
93 99
94 post( 100 post(
95 :edit_institution, 101 :edit_institution,
96 - :profile=>institution.community.identifier, 102 + :profile=>@institution.community.identifier,
97 :community=>fields[:community], 103 :community=>fields[:community],
98 :institutions=>fields[:institutions] 104 :institutions=>fields[:institutions]
99 ) 105 )