Commit fbc6e195533b36a0cf680cc4ee0da2f54e4fed69
Exists in
master
and in
5 other branches
Merge branch 'institution_fields'
Conflicts: views/institution_editor_extras.html.erb views/mpog_software_plugin/create_institution.html.erb
Showing
5 changed files
with
139 additions
and
49 deletions
Show diff stats
test/functional/account_controller_test.rb
... | ... | @@ -12,15 +12,15 @@ class AccountControllerTest < ActionController::TestCase |
12 | 12 | |
13 | 13 | @govPower = GovernmentalPower.create(:name=>"Some Gov Power") |
14 | 14 | @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") |
15 | + @juridical_nature = JuridicalNature.create(:name => "Autarquia") | |
15 | 16 | |
16 | 17 | @controller = AccountController.new |
17 | 18 | @request = ActionController::TestRequest.new |
18 | 19 | @response = ActionController::TestResponse.new |
19 | 20 | |
20 | 21 | @institution_list = [] |
21 | - @institution_list << create_institution("Ministerio Publico da Uniao", "MPU") | |
22 | - @institution_list << create_institution("Tribunal Regional da Uniao", "TRU") | |
23 | - | |
22 | + @institution_list << create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @govPower, @govSphere) | |
23 | + @institution_list << create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", @juridical_nature, @govPower, @govSphere) | |
24 | 24 | @user_info = { |
25 | 25 | :login=>"novo_usuario", |
26 | 26 | :password=>"nova_senha", |
... | ... | @@ -91,15 +91,22 @@ class AccountControllerTest < ActionController::TestCase |
91 | 91 | |
92 | 92 | private |
93 | 93 | |
94 | - def create_institution name, acronym | |
95 | - institution_community = Community::create :name=>name | |
94 | + def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s | |
95 | + institution_community = fast_create(Community) | |
96 | + institution_community.name = name | |
97 | + institution_community.country = country | |
98 | + institution_community.state = state | |
99 | + institution_community.city = city | |
100 | + institution_community.save! | |
101 | + | |
96 | 102 | institution = PublicInstitution.new |
97 | 103 | institution.community = institution_community |
98 | 104 | institution.name = name |
99 | - institution.acronym = acronym | |
100 | - institution.governmental_power = @govPower | |
101 | - institution.governmental_sphere = @govSphere | |
102 | - institution.save | |
105 | + institution.juridical_nature = juridical_nature | |
106 | + institution.acronym = acronym | |
107 | + institution.governmental_power = gov_p | |
108 | + institution.governmental_sphere = gov_s | |
109 | + institution.save! | |
103 | 110 | institution |
104 | 111 | end |
105 | 112 | ... | ... |
... | ... | @@ -0,0 +1,68 @@ |
1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
2 | +require File.dirname(__FILE__) + '/../../controllers/mpog_software_plugin_controller' | |
3 | + | |
4 | + | |
5 | +class InstitutionEditorTest < ActionController::TestCase | |
6 | + | |
7 | + def setup | |
8 | + @controller = ProfileEditorController.new | |
9 | + @request = ActionController::TestRequest.new | |
10 | + @response = ActionController::TestResponse.new | |
11 | + | |
12 | + @environment = Environment.default | |
13 | + @environment.enabled_plugins = ['MpogSoftwarePlugin'] | |
14 | + @environment.save | |
15 | + | |
16 | + @govPower = GovernmentalPower.create(:name=>"Some Gov Power") | |
17 | + @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
18 | + @juridical_nature = JuridicalNature.create(:name => "Autarquia") | |
19 | + | |
20 | + | |
21 | + @institution_list = [] | |
22 | + @institution_list << create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @govPower, @govSphere) | |
23 | + @institution_list << create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", @juridical_nature, @govPower, @govSphere) | |
24 | + end | |
25 | + | |
26 | + | |
27 | + should ' enable edition of sisp field for enviroment admin' do | |
28 | + admin = create_user("adminuser").person | |
29 | + admin.stubs(:has_permission?).returns("true") | |
30 | + login_as('adminuser') | |
31 | + @environment.add_admin(admin) | |
32 | + get :edit, :profile => @institution_list[0].community.identifier, :id => @institution_list[0].community.id | |
33 | + assert_tag :tag => 'span', :descendant => {:tag => "input", :attributes => { :type => 'radio', :name => "institution[sisp]"}} | |
34 | + end | |
35 | + | |
36 | + should 'enable only visulization of sisp field for institution admin' do | |
37 | + ze = create_user("ze").person | |
38 | + login_as('ze') | |
39 | + @institution_list[0].community.add_admin(ze) | |
40 | + get :edit, :profile => @institution_list[0].community.identifier, :id => @institution_list[0].community.id | |
41 | + assert_tag :tag => 'span', :descendant => {:tag => "label", :attributes => {:for => "SISP"}} | |
42 | + end | |
43 | + | |
44 | + | |
45 | + private | |
46 | + | |
47 | + def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s | |
48 | + institution_community = fast_create(Community) | |
49 | + institution_community.name = name | |
50 | + institution_community.country = country | |
51 | + institution_community.state = state | |
52 | + institution_community.city = city | |
53 | + institution_community.save! | |
54 | + | |
55 | + institution = PublicInstitution.new | |
56 | + institution.community = institution_community | |
57 | + institution.name = name | |
58 | + institution.juridical_nature = juridical_nature | |
59 | + institution.sisp = false | |
60 | + institution.acronym = acronym | |
61 | + institution.governmental_power = gov_p | |
62 | + institution.governmental_sphere = gov_s | |
63 | + institution.save! | |
64 | + | |
65 | + institution | |
66 | + end | |
67 | + | |
68 | +end | ... | ... |
test/functional/mpog_software_plugin_controller_test.rb
... | ... | @@ -16,11 +16,12 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase |
16 | 16 | |
17 | 17 | @govPower = GovernmentalPower.create(:name=>"Some Gov Power") |
18 | 18 | @govSphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") |
19 | + @juridical_nature = JuridicalNature.create(:name => "Autarquia") | |
19 | 20 | @response = ActionController::TestResponse.new |
20 | 21 | |
21 | 22 | @institution_list = [] |
22 | - @institution_list << create_public_institution("Ministerio Publico da Uniao", "MPU", @govPower, @govSphere) | |
23 | - @institution_list << create_public_institution("Tribunal Regional da Uniao", "TRU", @govPower, @govSphere) | |
23 | + @institution_list << create_public_institution("Ministerio Publico da Uniao", "MPU", "BR", "DF", "Gama", @juridical_nature, @govPower, @govSphere) | |
24 | + @institution_list << create_public_institution("Tribunal Regional da Uniao", "TRU", "BR", "DF", "Brasilia", @juridical_nature, @govPower, @govSphere) | |
24 | 25 | end |
25 | 26 | |
26 | 27 | should "Search for institution with acronym" do |
... | ... | @@ -58,11 +59,14 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase |
58 | 59 | |
59 | 60 | xhr :get, :new_institution, |
60 | 61 | :authenticity_token=>"dsa45a6das52sd", |
61 | - :community=>{:name=>"foo bar"}, | |
62 | - :institution => {:cnpj=>"12.234.567/8900-10", :acronym=>"fb", :type=>"PublicInstitution"}, | |
62 | + :name => "foo bar", | |
63 | + :community=>{:name=>"foo bar", :country => "BR", :state => "DF", :city => "Brasilia"}, | |
63 | 64 | :governmental=>{:power=>@govPower.id, :sphere=>@govSphere.id}, |
65 | + :juridical => {:nature => @juridical_nature.id}, | |
66 | + :institution => {:cnpj=>"12.234.567/8900-10", :acronym=>"fb", :type=>"PublicInstitution"}, | |
64 | 67 | :recaptcha_response_field=>'' |
65 | 68 | |
69 | + | |
66 | 70 | json_response = ActiveSupport::JSON.decode(@response.body) |
67 | 71 | |
68 | 72 | assert json_response["success"] |
... | ... | @@ -73,9 +77,11 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase |
73 | 77 | |
74 | 78 | xhr :get, :new_institution, |
75 | 79 | :authenticity_token=>"dsa45a6das52sd", |
76 | - :community=>{:name=>"Ministerio Publico da Uniao"}, | |
77 | - :institution => {:cnpj=>"12.234.567/8900-10", :acronym=>"fb", :type=>"PublicInstitution"}, | |
80 | + :name => "Ministerio Publico da Uniao", | |
81 | + :community=>{:name=>"Ministerio Publico da Uniao", :country => "BR", :state => "DF", :city => "Brasilia"}, | |
78 | 82 | :governmental=>{:power=>@govPower.id, :sphere=>@govSphere.id}, |
83 | + :juridical => {:nature => @juridical_nature.id}, | |
84 | + :institution => {:cnpj=>"12.234.567/8900-10", :acronym=>"fb", :type=>"PublicInstitution"}, | |
79 | 85 | :recaptcha_response_field=>'' |
80 | 86 | |
81 | 87 | json_response = ActiveSupport::JSON.decode(@response.body) |
... | ... | @@ -83,24 +89,6 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase |
83 | 89 | assert !json_response["success"] |
84 | 90 | end |
85 | 91 | |
86 | - should "set the environment admin as institution community admin" do | |
87 | - @controller.stubs(:verify_recaptcha).returns(true) | |
88 | - | |
89 | - xhr :get, :new_institution, | |
90 | - :authenticity_token=>"dsa45a6das52sd", | |
91 | - :community=>{:name=>"Another instituon community"}, | |
92 | - :institution => {:cnpj=>"10.254.577/8910-12", :acronym=>"aic", :type=>"PublicInstitution"}, | |
93 | - :governmental=>{:power=>@govPower.id, :sphere=>@govSphere.id}, | |
94 | - :recaptcha_response_field=>'' | |
95 | - | |
96 | - json_response = ActiveSupport::JSON.decode(@response.body) | |
97 | - | |
98 | - assert json_response["success"] | |
99 | - | |
100 | - assert Community.last.admins.include?(@environment.admins.first) | |
101 | - assert_equal Community.last.name, "Another instituon community" | |
102 | - end | |
103 | - | |
104 | 92 | should "verify if institution name already exists" do |
105 | 93 | xhr :get, :institution_already_exists, :name=>"Ministerio Publico da Uniao" |
106 | 94 | assert_equal "true", @response.body |
... | ... | @@ -135,9 +123,11 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase |
135 | 123 | |
136 | 124 | xhr :get, :new_institution, |
137 | 125 | :authenticity_token=>"dsa45a6das52sd", |
138 | - :community=>{:name=>"foo bar"}, | |
139 | - :institution => {:cnpj=>"12.234.567/8900-10", :acronym=>"fb", :type=>"PublicInstitution"}, | |
126 | + :name => "foo bar", | |
127 | + :community=>{:name=>"foo bar", :country => "BR", :state => "DF", :city => "Brasilia"}, | |
140 | 128 | :governmental=>{:power=>@govPower.id, :sphere=>@govSphere.id}, |
129 | + :juridical => {:nature => @juridical_nature.id}, | |
130 | + :institution => {:cnpj=>"12.234.567/8900-10", :acronym=>"fb", :type=>"PublicInstitution"}, | |
141 | 131 | :recaptcha_response_field=>'' |
142 | 132 | |
143 | 133 | date = Time.now.day.to_s + "/" + Time.now.month.to_s + "/" + Time.now.year.to_s |
... | ... | @@ -147,15 +137,23 @@ class MpogSoftwarePluginControllerTest < ActionController::TestCase |
147 | 137 | |
148 | 138 | private |
149 | 139 | |
150 | - def create_public_institution name, acronym, gov_p, gov_s | |
151 | - institution_community = Community::new :name=>name | |
140 | + def create_public_institution name, acronym, country, state, city, juridical_nature, gov_p, gov_s | |
141 | + institution_community = fast_create(Community) | |
142 | + institution_community.name = name | |
143 | + institution_community.country = country | |
144 | + institution_community.state = state | |
145 | + institution_community.city = city | |
146 | + institution_community.save! | |
147 | + | |
152 | 148 | institution = PublicInstitution.new |
153 | 149 | institution.community = institution_community |
154 | 150 | institution.name = name |
155 | - institution.acronym = acronym | |
151 | + institution.juridical_nature = juridical_nature | |
152 | + institution.acronym = acronym | |
156 | 153 | institution.governmental_power = gov_p |
157 | 154 | institution.governmental_sphere = gov_s |
158 | - institution.save | |
155 | + institution.save! | |
159 | 156 | institution |
160 | 157 | end |
158 | + | |
161 | 159 | end | ... | ... |
views/institution_editor_extras.html.erb
... | ... | @@ -34,15 +34,18 @@ |
34 | 34 | <%= label_tag('juridical_nature', _("Juridical Nature")) %> |
35 | 35 | <%= select_tag(:juridical_nature, options_for_select(JuridicalNature.all.map {|j| [j.name, j.id]}, :selected => context.profile.institution.juridical_nature_id), :class=>"formlabel") %> |
36 | 36 | </div> |
37 | -</span> | |
38 | - | |
37 | + </span> | |
38 | + | |
39 | + <span class= 'public-institutions-fields'> | |
40 | + <div class="formfieldline"> | |
39 | 41 | <% if @show_sisp_field %> |
40 | - <span class= 'public-institutions-fields'> | |
41 | - <div class="formfieldline"> | |
42 | - <%= _("SISP?") %> | |
43 | - <%= labelled_radio_button(_('Yes'), 'institution[sisp]', 'true', context.profile.institution.sisp)%> | |
44 | - <%= labelled_radio_button(_('No'), 'institution[sisp]', 'false', !context.profile.institution.sisp)%> | |
45 | - </div> | |
46 | - </span> | |
42 | + <%= _("SISP?") %> | |
43 | + <%= labelled_radio_button(_('Yes'), 'institution[sisp]', 'true', context.profile.institution.sisp)%> | |
44 | + <%= labelled_radio_button(_('No'), 'institution[sisp]', 'false', !context.profile.institution.sisp)%> | |
45 | + <% else %> | |
46 | + <%= _("SISP?") %> | |
47 | + <%= label_tag('SISP', context.profile.institution.sisp ? "YES" : "NO") %> | |
47 | 48 | <% end %> |
49 | + </div> | |
50 | + </span> | |
48 | 51 | <% end %> | ... | ... |
views/mpog_software_plugin/create_institution.html.erb
... | ... | @@ -75,8 +75,22 @@ |
75 | 75 | <%= inst.select(:juridical_nature, [[_("Select a Juridical Nature"), 0]]|JuridicalNature.all.map {|j| [j.name, j.id]}, {:selected=>0})%> |
76 | 76 | </div> |
77 | 77 | </span> |
78 | + | |
79 | + <span class='required-field public-institutions-fields'> | |
80 | + <div class="formfield type-text"> | |
81 | + <%= _("SISP?") %> | |
82 | + <% if @show_sisp_field %> | |
83 | + <%= inst.label("sisp" ,_("Yes")) %> | |
84 | + <%= inst.radio_button(:sisp, true) %> | |
85 | + <%= inst.label("sisp" ,_("No")) %> | |
86 | + <%= inst.radio_button(:sisp, false) %> | |
87 | + <% else %> | |
88 | + <%= inst.label("sisp", _("No")) %> | |
89 | + <% end %> | |
90 | + </div> | |
91 | + </span> | |
78 | 92 | <br /> |
79 | - | |
93 | + | |
80 | 94 | <div> |
81 | 95 | <p><%= recaptcha_tags :ajax => true, :display => {:theme => 'clean'} %> </p> |
82 | 96 | <%= link_to(_('Save'), '#', :id=>'save_institution_button', :class=>'button with-text icon-add') %> | ... | ... |