Commit 6ffbb1ae9712a5f7c1bbd88bff55e0f37b8c123b
Exists in
master
and in
9 other branches
Merge branch 'fix_institutions_state' into 'master'
Fix institutions states Correções nos estados das instituições - Siglas dos estados migrados para nomes completos - Correções no JavaScript dos formulários de criação/edição de instituições - Validação na criação de instituições (apenas nomes completos estados brasileiros são válidos) See merge request !169
Showing
17 changed files
with
158 additions
and
237 deletions
Show diff stats
src/noosfero-spb/gov_user/db/migrate/20160120185910_fix_communities_with_wrong_state.rb
0 → 100644
... | ... | @@ -0,0 +1,18 @@ |
1 | +class FixCommunitiesWithWrongState < ActiveRecord::Migration | |
2 | + def up | |
3 | + select_all("SELECT id, data FROM profiles WHERE type = 'Community'").each do |community| | |
4 | + settings = YAML.load(community['data'] || {}.to_yaml) | |
5 | + new_state = Institution::VALID_STATES[settings[:state].upcase] if settings[:state].present? | |
6 | + | |
7 | + if new_state.present? | |
8 | + settings[:state] = new_state | |
9 | + assignments = ActiveRecord::Base.send(:sanitize_sql_for_assignment, {:data => settings.to_yaml}) | |
10 | + update("UPDATE profiles SET %s WHERE id = %d" % [assignments, community['id']]) | |
11 | + end | |
12 | + end | |
13 | + end | |
14 | + | |
15 | + def down | |
16 | + say "This migration can't be reverted." | |
17 | + end | |
18 | +end | ... | ... |
src/noosfero-spb/gov_user/features/institution_registration.feature
... | ... | @@ -33,3 +33,16 @@ Feature: Institution Field |
33 | 33 | Then I should see "Governmental Sphere" |
34 | 34 | And I should see "Governmental Power" |
35 | 35 | And I should see "Juridical Nature" |
36 | + | |
37 | + @selenium | |
38 | + Scenario: Clean state and city values when country is diferent of Brazil | |
39 | + Given I follow "Edit Profile" | |
40 | + When I follow "Create new institution" | |
41 | + And I select "Brazil" from "community_country" | |
42 | + And I select "Distrito Federal" from "community_state" | |
43 | + And I fill in "community_city" with "Gama" | |
44 | + And I select "United States" from "community_country" | |
45 | + Then I should not see "community_state" | |
46 | + And I should not see "community_city" | |
47 | + And I select "Brazil" from "community_country" | |
48 | + Then I should not see "Gama" | ... | ... |
src/noosfero-spb/gov_user/features/rate_community.feature
... | ... | @@ -27,8 +27,8 @@ Feature: rate_community |
27 | 27 | And Institutions has initial default values on database |
28 | 28 | And the following public institutions |
29 | 29 | | name | acronym | country | state | city | cnpj | juridical_nature | governmental_power | governmental_sphere | corporate_name | |
30 | - | Ministerio das Cidades | MC | BR | DF | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal | Ministerio das Cidades | | |
31 | - | Ministerio do Planejamento | MP | BR | DF | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | Ministerio do Planejamento | | |
30 | + | Ministerio das Cidades | MC | BR | Distrito Federal | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal | Ministerio das Cidades | | |
31 | + | Ministerio do Planejamento | MP | BR | Distrito Federal | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | Ministerio do Planejamento | | |
32 | 32 | |
33 | 33 | Scenario: display message on task when a rating with the same institution exists on the same software |
34 | 34 | Given the following organization ratings |
... | ... | @@ -38,7 +38,7 @@ Feature: rate_community |
38 | 38 | And I go to mycommunity's control panel |
39 | 39 | And I follow "Process requests" within ".pending-tasks" |
40 | 40 | And I choose "Accept" within ".task_decisions" |
41 | - Then I should see "This institution already has an accepted rating." in the page | |
41 | + Then I should see "This institution already has an accepted rating" in the page | |
42 | 42 | |
43 | 43 | Scenario: do not display message on task when a rating with the same institution does not exist on the same software |
44 | 44 | Given the following organization ratings | ... | ... |
src/noosfero-spb/gov_user/features/steps_definitions/gov_user_steps_backup.rb
... | ... | @@ -1,93 +0,0 @@ |
1 | -Given /^Institutions has initial default values on database$/ do | |
2 | - GovernmentalPower.create(:name => "Executivo") | |
3 | - GovernmentalPower.create(:name => "Legislativo") | |
4 | - GovernmentalPower.create(:name => "Judiciario") | |
5 | - | |
6 | - GovernmentalSphere.create(:name => "Federal") | |
7 | - | |
8 | - JuridicalNature.create(:name => "Autarquia") | |
9 | - JuridicalNature.create(:name => "Administracao Direta") | |
10 | - JuridicalNature.create(:name => "Empresa Publica") | |
11 | - JuridicalNature.create(:name => "Fundacao") | |
12 | - JuridicalNature.create(:name => "Orgao Autonomo") | |
13 | - JuridicalNature.create(:name => "Sociedade") | |
14 | - JuridicalNature.create(:name => "Sociedade Civil") | |
15 | - JuridicalNature.create(:name => "Sociedade de Economia Mista") | |
16 | - | |
17 | - national_region = NationalRegion.new | |
18 | - national_region.name = "Distrito Federal" | |
19 | - national_region.national_region_code = '35' | |
20 | - national_region.national_region_type_id = NationalRegionType::STATE | |
21 | - national_region.save | |
22 | -end | |
23 | - | |
24 | -Given /^I type in "([^"]*)" in autocomplete list "([^"]*)" and I choose "([^"]*)"$/ do |typed, input_field_selector, should_select| | |
25 | -# Wait the page javascript load | |
26 | -sleep 1 | |
27 | -# Basicaly it, search for the input field, type something, wait for ajax end select an item | |
28 | -page.driver.browser.execute_script %Q{ | |
29 | - var search_query = "#{input_field_selector}.ui-autocomplete-input"; | |
30 | - var input = jQuery(search_query).first(); | |
31 | - | |
32 | - input.trigger('click'); | |
33 | - input.val('#{typed}'); | |
34 | - input.trigger('keydown'); | |
35 | - | |
36 | - window.setTimeout(function(){ | |
37 | - search_query = ".ui-menu-item a:contains('#{should_select}')"; | |
38 | - var typed = jQuery(search_query).first(); | |
39 | - | |
40 | - typed.trigger('mouseenter').trigger('click'); | |
41 | - console.log(jQuery('#license_info_id')); | |
42 | - }, 1000); | |
43 | - } | |
44 | - sleep 1 | |
45 | -end | |
46 | - | |
47 | -Given /^the following public institutions?$/ do |table| | |
48 | - # table is a Cucumber::Ast::Table | |
49 | - table.hashes.each do |item| | |
50 | - community = Community.new | |
51 | - community.name = item[:name] | |
52 | - community.country = item[:country] | |
53 | - community.state = item[:state] | |
54 | - community.city = item[:city] | |
55 | - community.save! | |
56 | - | |
57 | - governmental_power = GovernmentalPower.where(:name => item[:governmental_power]).first | |
58 | - governmental_sphere = GovernmentalSphere.where(:name => item[:governmental_sphere]).first | |
59 | - | |
60 | - juridical_nature = JuridicalNature.create(:name => item[:juridical_nature]) | |
61 | - | |
62 | - institution = PublicInstitution.new(:name => item[:name], :type => "PublicInstitution", :acronym => item[:acronym], :cnpj => item[:cnpj], :juridical_nature => juridical_nature, :governmental_power => governmental_power, :governmental_sphere => governmental_sphere) | |
63 | - institution.community = community | |
64 | - institution.corporate_name = item[:corporate_name] | |
65 | - institution.save! | |
66 | - end | |
67 | -end | |
68 | - | |
69 | -Given /^I sleep for (\d+) seconds$/ do |time| | |
70 | - sleep time.to_i | |
71 | -end | |
72 | - | |
73 | -Given /^I am logged in as mpog_admin$/ do | |
74 | - visit('/account/logout') | |
75 | - | |
76 | - user = User.new(:login => 'admin_user', :password => '123456', :password_confirmation => '123456', :email => 'admin_user@example.com') | |
77 | - person = Person.new :name=>"Mpog Admin", :identifier=>"mpog-admin" | |
78 | - user.person = person | |
79 | - user.save! | |
80 | - | |
81 | - user.activate | |
82 | - e = Environment.default | |
83 | - e.add_admin(user.person) | |
84 | - | |
85 | - visit('/account/login') | |
86 | - fill_in("Username", :with => user.login) | |
87 | - fill_in("Password", :with => '123456') | |
88 | - click_button("Log in") | |
89 | -end | |
90 | - | |
91 | -Given /^I click on anything with selector "([^"]*)"$/ do |selector| | |
92 | - evaluate_script "jQuery('#{selector}').trigger('click') && true" | |
93 | -end |
src/noosfero-spb/gov_user/features/user_profile_edition.feature
... | ... | @@ -24,9 +24,9 @@ Feature: Institution Field |
24 | 24 | And Institutions has initial default values on database |
25 | 25 | And the following public institutions |
26 | 26 | | name | acronym | country | state | city | cnpj | juridical_nature | governmental_power | governmental_sphere | corporate_name | |
27 | - | Ministerio das Cidades | MC | BR | DF | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal | Ministerio das Cidades | | |
28 | - | Governo do DF | GDF | BR | DF | Taguatinga | 12.645.166/0001-44 | Autarquia | Legislativo | Federal | Governo do DF | | |
29 | - | Ministerio do Planejamento | MP | BR | DF | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | Ministerio do Planejamento | | |
27 | + | Ministerio das Cidades | MC | BR | Distrito Federal | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal | Ministerio das Cidades | | |
28 | + | Governo do DF | GDF | BR | Distrito Federal | Taguatinga | 12.645.166/0001-44 | Autarquia | Legislativo | Federal | Governo do DF | | |
29 | + | Ministerio do Planejamento | MP | BR | Distrito Federal | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | Ministerio do Planejamento | | |
30 | 30 | |
31 | 31 | @selenium |
32 | 32 | Scenario: Go to control panel when clicked on 'Complete your profile' link | ... | ... |
src/noosfero-spb/gov_user/lib/institution.rb
1 | +#encoding: utf-8 | |
2 | + | |
1 | 3 | class Institution < ActiveRecord::Base |
2 | 4 | has_many :comments |
3 | 5 | |
... | ... | @@ -8,6 +10,12 @@ class Institution < ActiveRecord::Base |
8 | 10 | |
9 | 11 | CNPJ_FORMAT = /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/ |
10 | 12 | |
13 | + VALID_STATES = { "AC"=>"Acre", "AL"=>"Alagoas", "AM"=>"Amazonas", "AP"=>"Amapá", "BA"=>"Bahia", "CE"=>"Ceará", | |
14 | + "DF"=>"Distrito Federal", "ES"=>"Espírito Santo", "GO"=>"Goiás", "MA"=>"Maranhão", "MT"=>"Mato Grosso", | |
15 | + "MS"=>"Mato Grosso do Sul", "MG"=>"Minas Gerais", "PA"=>"Pará", "PB"=>"Paraíba", "PR"=>"Paraná", | |
16 | + "PE"=>"Pernambuco", "PI"=>"Piauí", "RJ"=>"Rio de Janeiro", "RN"=>"Rio Grande do Norte", "RO"=>"Rondônia", | |
17 | + "RS"=>"Rio Grande do Sul", "RR"=>"Roraima", "SC"=>"Santa Catarina", "SE"=>"Sergipe", "SP"=>"São Paulo", "TO"=>"Tocantins" } | |
18 | + | |
11 | 19 | def self.default_search_display |
12 | 20 | 'compact' |
13 | 21 | end |
... | ... | @@ -76,12 +84,12 @@ class Institution < ActiveRecord::Base |
76 | 84 | end |
77 | 85 | |
78 | 86 | def validate_state |
79 | - unless self.community.blank? | |
80 | - if self.community.country == "BR" && | |
81 | - (self.community.state.blank? || self.community.state == "-1") && | |
82 | - self.errors[:state].blank? | |
83 | - | |
84 | - self.errors.add(:state, _("can't be blank")) | |
87 | + if self.community.present? && self.community.country == "BR" | |
88 | + if self.community.state.blank? | |
89 | + self.errors.add(:state, _("can't be blank")) if self.errors[:state].blank? | |
90 | + return false | |
91 | + elsif !VALID_STATES.values.include?(self.community.state) | |
92 | + self.errors.add(:state, _("invalid state")) if self.errors[:state].blank? | |
85 | 93 | return false |
86 | 94 | end |
87 | 95 | end | ... | ... |
src/noosfero-spb/gov_user/public/views/create-institution.js
... | ... | @@ -284,9 +284,10 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
284 | 284 | |
285 | 285 | function show_hide_cnpj_city(country) { |
286 | 286 | var cnpj = $("#institutions_cnpj").parent().parent(); |
287 | - var city = $("#community_city").parent(); | |
287 | + var city = $("#community_city"); | |
288 | 288 | var city_label = $('label[for="community_city"]'); |
289 | - var state = $("#community_state").parent(); | |
289 | + var state = $("#community_state"); | |
290 | + var state_label = $('label[for="community_state"]'); | |
290 | 291 | var inst_type = $("input[name='institutions[type]']:checked").val(); |
291 | 292 | |
292 | 293 | institution_type_actions(inst_type); |
... | ... | @@ -298,13 +299,17 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
298 | 299 | |
299 | 300 | if ( country !== "BR" ) { |
300 | 301 | cnpj.hide(); |
301 | - city.find('input').val(''); city.hide(); | |
302 | + city.val(''); | |
303 | + city.hide(); | |
302 | 304 | city_label.hide(); |
305 | + state.val(""); | |
303 | 306 | state.hide(); |
307 | + state_label.hide(); | |
304 | 308 | } else { |
305 | 309 | cnpj.show(); |
306 | 310 | city.show(); |
307 | 311 | city_label.show(); |
312 | + state_label.show(); | |
308 | 313 | state.show(); |
309 | 314 | } |
310 | 315 | } |
... | ... | @@ -318,33 +323,6 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
318 | 323 | } |
319 | 324 | } |
320 | 325 | |
321 | - | |
322 | - function set_form_count_custom_data() { | |
323 | - var divisor_option = SelectElement.generateOption("-1", "--------------------------------"); | |
324 | - var default_option = SelectElement.generateOption("BR", "Brazil"); | |
325 | - | |
326 | - var inst_type = $("input[name='institutions[type]']:checked").val(); | |
327 | - var country = $("#community_country").val(); | |
328 | - | |
329 | - institution_type_actions(inst_type); | |
330 | - show_hide_cnpj_city(country); | |
331 | - | |
332 | - if( $('#community_country').find("option[value='']").length === 1 ) { | |
333 | - $('#community_country').find("option[value='']").remove(); | |
334 | - $('#community_country').prepend(divisor_option); | |
335 | - $('#community_country').prepend(default_option); | |
336 | - | |
337 | - if ($('#add_institution_link').length > 0) { | |
338 | - $('#add_institution_link').hide(); | |
339 | - } | |
340 | - | |
341 | - if($("#edit_institution_page").val() === "false") { | |
342 | - $('#community_country').val("BR"); | |
343 | - show_hide_cnpj_city($('#community_country').val()); | |
344 | - } | |
345 | - } | |
346 | - } | |
347 | - | |
348 | 326 | function autoCompleteCity() { |
349 | 327 | var country_selected = $('#community_country').val(); |
350 | 328 | |
... | ... | @@ -416,7 +394,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
416 | 394 | |
417 | 395 | |
418 | 396 | function init_module() { |
419 | - set_form_count_custom_data(); | |
397 | + show_hide_cnpj_city($('#community_country').val()); | |
420 | 398 | set_events(); |
421 | 399 | } |
422 | 400 | ... | ... |
src/noosfero-spb/gov_user/test/functional/gov_user_plugin_controller_test.rb
... | ... | @@ -26,7 +26,7 @@ class GovUserPluginControllerTest < ActionController::TestCase |
26 | 26 | "Ministerio Publico da Uniao", |
27 | 27 | "MPU", |
28 | 28 | "BR", |
29 | - "DF", | |
29 | + "Distrito Federal", | |
30 | 30 | "Gama", |
31 | 31 | @juridical_nature, |
32 | 32 | @gov_power, |
... | ... | @@ -37,7 +37,7 @@ class GovUserPluginControllerTest < ActionController::TestCase |
37 | 37 | "Tribunal Regional da Uniao", |
38 | 38 | "TRU", |
39 | 39 | "BR", |
40 | - "DF", | |
40 | + "Distrito Federal", | |
41 | 41 | "Brasilia", |
42 | 42 | @juridical_nature, |
43 | 43 | @gov_power, |
... | ... | @@ -84,7 +84,7 @@ class GovUserPluginControllerTest < ActionController::TestCase |
84 | 84 | fields = InstitutionTestHelper.generate_form_fields( |
85 | 85 | "foo bar", |
86 | 86 | "BR", |
87 | - "DF", | |
87 | + "Distrito Federal", | |
88 | 88 | "Brasilia", |
89 | 89 | "12.234.567/8900-10", |
90 | 90 | "PublicInstitution" |
... | ... | @@ -100,14 +100,14 @@ class GovUserPluginControllerTest < ActionController::TestCase |
100 | 100 | assert json_response["success"] |
101 | 101 | end |
102 | 102 | |
103 | - should "create a institution without cnpj" do | |
103 | + should "not create a private institution without cnpj" do | |
104 | 104 | @controller.stubs(:verify_recaptcha).returns(true) |
105 | 105 | |
106 | 106 | fields = InstitutionTestHelper.generate_form_fields( |
107 | 107 | "Some Private Institution", |
108 | - "EN", | |
109 | - "NY", | |
110 | - "New York", | |
108 | + "BR", | |
109 | + "Distrito Federal", | |
110 | + "Brasilia", | |
111 | 111 | "", |
112 | 112 | "PrivateInstitution" |
113 | 113 | ) |
... | ... | @@ -117,6 +117,29 @@ class GovUserPluginControllerTest < ActionController::TestCase |
117 | 117 | |
118 | 118 | json_response = ActiveSupport::JSON.decode(@response.body) |
119 | 119 | |
120 | + assert_false json_response["success"] | |
121 | + assert json_response["errors"].include? "Cnpj can't be blank" | |
122 | + end | |
123 | + | |
124 | + should "create public institution without cnpj" do | |
125 | + @controller.stubs(:verify_recaptcha).returns(true) | |
126 | + | |
127 | + fields = InstitutionTestHelper.generate_form_fields( | |
128 | + "Some Private Institution", | |
129 | + "BR", | |
130 | + "Distrito Federal", | |
131 | + "Brasilia", | |
132 | + "56.366.790/0001-88", | |
133 | + "PublicInstitution" | |
134 | + ) | |
135 | + fields[:institutions][:governmental_power] = @gov_power.id | |
136 | + fields[:institutions][:governmental_sphere] = @gov_sphere.id | |
137 | + fields[:institutions][:juridical_nature] = @juridical_nature.id | |
138 | + | |
139 | + xhr :get, :new_institution, fields | |
140 | + | |
141 | + json_response = ActiveSupport::JSON.decode(@response.body) | |
142 | + | |
120 | 143 | assert json_response["success"] |
121 | 144 | end |
122 | 145 | |
... | ... | @@ -144,7 +167,7 @@ class GovUserPluginControllerTest < ActionController::TestCase |
144 | 167 | fields = InstitutionTestHelper.generate_form_fields( |
145 | 168 | "Some Private Institution", |
146 | 169 | "BR", |
147 | - "DF", | |
170 | + "Distrito Federal", | |
148 | 171 | "Brasilia", |
149 | 172 | "12.345.567/8900-10", |
150 | 173 | "PrivateInstitution" |
... | ... | @@ -162,7 +185,7 @@ class GovUserPluginControllerTest < ActionController::TestCase |
162 | 185 | fields = InstitutionTestHelper.generate_form_fields( |
163 | 186 | "Some Private Institution", |
164 | 187 | "BR", |
165 | - "DF", | |
188 | + "Distrito Federal", | |
166 | 189 | "Brasilia", |
167 | 190 | "56.366.790/0001-88", |
168 | 191 | "PrivateInstitution" |
... | ... | @@ -221,7 +244,7 @@ class GovUserPluginControllerTest < ActionController::TestCase |
221 | 244 | fields = InstitutionTestHelper.generate_form_fields( |
222 | 245 | "Private Institution", |
223 | 246 | "BR", |
224 | - "DF", | |
247 | + "Distrito Federal", | |
225 | 248 | "Brasilia", |
226 | 249 | "12.323.557/8900-10", |
227 | 250 | "PrivateInstitution" | ... | ... |
src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb
... | ... | @@ -25,7 +25,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase |
25 | 25 | "Ministerio Publico da Uniao", |
26 | 26 | "MPU", |
27 | 27 | "BR", |
28 | - "DF", | |
28 | + "Distrito Federal", | |
29 | 29 | "Gama", |
30 | 30 | juridical_nature, |
31 | 31 | gov_power, |
... | ... | @@ -46,7 +46,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase |
46 | 46 | fields = InstitutionTestHelper.generate_form_fields( |
47 | 47 | "institution new name", |
48 | 48 | "BR", |
49 | - "DF", | |
49 | + "Distrito Federal", | |
50 | 50 | "Gama", |
51 | 51 | "12.345.678/9012-45", |
52 | 52 | "PrivateInstitution" |
... | ... | @@ -68,7 +68,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase |
68 | 68 | fields = InstitutionTestHelper.generate_form_fields( |
69 | 69 | "institution new name", |
70 | 70 | "BR", |
71 | - "DF", | |
71 | + "Distrito Federal", | |
72 | 72 | "Gama", |
73 | 73 | "12.345.678/9012-45", |
74 | 74 | "PrivateInstitution" |
... | ... | @@ -91,7 +91,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase |
91 | 91 | fields = InstitutionTestHelper.generate_form_fields( |
92 | 92 | "", |
93 | 93 | "BR", |
94 | - "DF", | |
94 | + "Distrito Federal", | |
95 | 95 | "Gama", |
96 | 96 | "6465465465", |
97 | 97 | "PrivateInstitution" | ... | ... |
src/noosfero-spb/gov_user/test/functional/profile_editor_controller_test.rb
... | ... | @@ -38,7 +38,7 @@ class ProfileEditorControllerTest < ActionController::TestCase |
38 | 38 | "Ministerio Publico da Uniao", |
39 | 39 | "MPU", |
40 | 40 | "BR", |
41 | - "DF", | |
41 | + "Distrito Federal", | |
42 | 42 | "Gama", |
43 | 43 | @juridical_nature, |
44 | 44 | @govPower, |
... | ... | @@ -50,7 +50,7 @@ class ProfileEditorControllerTest < ActionController::TestCase |
50 | 50 | "Tribunal Regional da Uniao", |
51 | 51 | "TRU", |
52 | 52 | "BR", |
53 | - "DF", | |
53 | + "Distrito Federal", | |
54 | 54 | "Brasilia", |
55 | 55 | @juridical_nature, |
56 | 56 | @govPower, | ... | ... |
src/noosfero-spb/gov_user/test/unit/api_test.rb
... | ... | @@ -1,51 +0,0 @@ |
1 | -require File.dirname(__FILE__) + '/../../../../test/unit/api/test_helper' | |
2 | -require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' | |
3 | - | |
4 | -class GovUserApiTest < ActiveSupport::TestCase | |
5 | - | |
6 | - include PluginTestHelper | |
7 | - | |
8 | - def setup | |
9 | - login_api | |
10 | - environment = Environment.default | |
11 | - environment.enable_plugin(GovUserPlugin) | |
12 | - @gov_power = GovernmentalPower.create(:name=>"Some Gov Power") | |
13 | - @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
14 | - @juridical_nature = JuridicalNature.create(:name => "Autarquia") | |
15 | - @institution = create_public_institution( | |
16 | - "Ministerio Publico da Uniao", | |
17 | - "MPU", | |
18 | - "BR", | |
19 | - "DF", | |
20 | - "Gama", | |
21 | - @juridical_nature, | |
22 | - @gov_power, | |
23 | - @gov_sphere, | |
24 | - "11.222.333/4444-55") | |
25 | - end | |
26 | - | |
27 | - should 'list all institutions' do | |
28 | - @institution1 = create_public_institution( | |
29 | - "Instituicao bacana", | |
30 | - "IB", | |
31 | - "BR", | |
32 | - "DF", | |
33 | - "Gama", | |
34 | - @juridical_nature, | |
35 | - @gov_power, | |
36 | - @gov_sphere, | |
37 | - "11.222.333/4444-56" | |
38 | - ) | |
39 | - | |
40 | - get "/api/v1/gov_user/institutions?#{params.to_query}" | |
41 | - json = JSON.parse(last_response.body) | |
42 | - assert_equivalent [@institution.id, @institution1.id], json['institutions'].map {|c| c['id']} | |
43 | - end | |
44 | - | |
45 | - should 'get institution by id' do | |
46 | - get "/api/v1/gov_user/institutions/#{@institution.id}?#{params.to_query}" | |
47 | - json = JSON.parse(last_response.body) | |
48 | - assert_equal @institution.id, json["institution"]["id"] | |
49 | - end | |
50 | - | |
51 | -end |
src/noosfero-spb/gov_user/test/unit/gov_user_plugin_api_test.rb
0 → 100644
... | ... | @@ -0,0 +1,51 @@ |
1 | +require File.dirname(__FILE__) + '/../../../../test/unit/api/test_helper' | |
2 | +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' | |
3 | + | |
4 | +class GovUserPlugin::ApiTest < ActiveSupport::TestCase | |
5 | + | |
6 | + include PluginTestHelper | |
7 | + | |
8 | + def setup | |
9 | + login_api | |
10 | + environment = Environment.default | |
11 | + environment.enable_plugin(GovUserPlugin) | |
12 | + @gov_power = GovernmentalPower.create(:name=>"Some Gov Power") | |
13 | + @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") | |
14 | + @juridical_nature = JuridicalNature.create(:name => "Autarquia") | |
15 | + @institution = create_public_institution( | |
16 | + "Ministerio Publico da Uniao", | |
17 | + "MPU", | |
18 | + "BR", | |
19 | + "Distrito Federal", | |
20 | + "Gama", | |
21 | + @juridical_nature, | |
22 | + @gov_power, | |
23 | + @gov_sphere, | |
24 | + "11.222.333/4444-55") | |
25 | + end | |
26 | + | |
27 | + should 'list all institutions' do | |
28 | + @institution1 = create_public_institution( | |
29 | + "Instituicao bacana", | |
30 | + "IB", | |
31 | + "BR", | |
32 | + "Distrito Federal", | |
33 | + "Gama", | |
34 | + @juridical_nature, | |
35 | + @gov_power, | |
36 | + @gov_sphere, | |
37 | + "11.222.333/4444-56" | |
38 | + ) | |
39 | + | |
40 | + get "/api/v1/gov_user/institutions?#{params.to_query}" | |
41 | + json = JSON.parse(last_response.body) | |
42 | + assert_equivalent [@institution.id, @institution1.id], json['institutions'].map {|c| c['id']} | |
43 | + end | |
44 | + | |
45 | + should 'get institution by id' do | |
46 | + get "/api/v1/gov_user/institutions/#{@institution.id}?#{params.to_query}" | |
47 | + json = JSON.parse(last_response.body) | |
48 | + assert_equal @institution.id, json["institution"]["id"] | |
49 | + end | |
50 | + | |
51 | +end | ... | ... |
src/noosfero-spb/gov_user/test/unit/private_institution_test.rb
src/noosfero-spb/gov_user/test/unit/public_institution_test.rb
src/noosfero-spb/gov_user/views/gov_user_plugin/_institution.html.erb
... | ... | @@ -72,7 +72,7 @@ |
72 | 72 | <span class="required-field">(*)</span> |
73 | 73 | </label> |
74 | 74 | |
75 | - <%= select("community", "country", [[_('Select a country'), nil]] + country_helper.countries, {:class => "type-select #{flash[:error_community_country]}"}) %> | |
75 | + <%= select("community", "country", [[_('Select a country'), -1]] + country_helper.countries, {:class => "type-select #{flash[:error_community_country]}"}) %> | |
76 | 76 | </div> |
77 | 77 | |
78 | 78 | <div class="spb-col spb-col-2"> |
... | ... | @@ -81,7 +81,7 @@ |
81 | 81 | <span class="required-field">(*)</span> |
82 | 82 | </label> |
83 | 83 | |
84 | - <%= f.select(:state, @state_options, {:selected => params[:community][:state]}, {:class => flash[:error_community_state]}) %> | |
84 | + <%= select("community", "state", [[_('Select a state'), '']] + @state_options, {:class => "type-select #{flash[:error_community_state]}"}) %> | |
85 | 85 | </div> |
86 | 86 | |
87 | 87 | <div class="spb-col spb-col-5"> | ... | ... |
src/noosfero-spb/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb
... | ... | @@ -44,14 +44,11 @@ |
44 | 44 | |
45 | 45 | <%= labelled_form_field(_('Fantasy name'), inst.text_field(:corporate_name, :value => @institution.corporate_name)) %> |
46 | 46 | |
47 | - <%= required select_country(_('Country'), 'community', 'country', {:class => 'type-select', :id => "community_country"}, :selected => @institution.community.country) %> | |
47 | + <%= required labelled_form_field(_('Country'), select("community", "country", [[_('Select a country'), -1]] + country_helper.countries, | |
48 | + {:selected => @institution.community.country, :class => "type-select #{flash[:error_community_country]}"})) %> | |
48 | 49 | |
49 | - <span class='required-field'> | |
50 | - <div class="formfield"> | |
51 | - <label for="community_state" class="formlabel"><%= _("State") %></label> | |
52 | - <%= f.select(:state, @state_list.collect {|state| [state.name, state.name]}, :selected => @institution.community.state) %> | |
53 | - </div> | |
54 | - </span> | |
50 | + <%= required labelled_form_field(_('State'), select("community", "state", [[_('Select a state'), '']] + @state_list.collect {|state| [state.name, state.name]}, | |
51 | + {:selected => @institution.community.state, :class => "type-select #{flash[:error_community_state]}"})) %> | |
55 | 52 | |
56 | 53 | <%= required f.text_field(:city, :value => @institution.community.city) %> |
57 | 54 | ... | ... |
src/noosfero-spb/software_communities/features/step_definitions/software_communities_steps.rb
... | ... | @@ -41,29 +41,6 @@ Given /^I type in "([^"]*)" in autocomplete list "([^"]*)" and I choose "([^"]*) |
41 | 41 | sleep 1 |
42 | 42 | end |
43 | 43 | |
44 | -Given /^Institutions has initial default values on database$/ do | |
45 | - GovernmentalPower.create(:name => "Executivo") | |
46 | - GovernmentalPower.create(:name => "Legislativo") | |
47 | - GovernmentalPower.create(:name => "Judiciario") | |
48 | - | |
49 | - GovernmentalSphere.create(:name => "Federal") | |
50 | - | |
51 | - JuridicalNature.create(:name => "Autarquia") | |
52 | - JuridicalNature.create(:name => "Administracao Direta") | |
53 | - JuridicalNature.create(:name => "Empresa Publica") | |
54 | - JuridicalNature.create(:name => "Fundacao") | |
55 | - JuridicalNature.create(:name => "Orgao Autonomo") | |
56 | - JuridicalNature.create(:name => "Sociedade") | |
57 | - JuridicalNature.create(:name => "Sociedade Civil") | |
58 | - JuridicalNature.create(:name => "Sociedade de Economia Mista") | |
59 | - | |
60 | - national_region = NationalRegion.new | |
61 | - national_region.name = "Distrito Federal" | |
62 | - national_region.national_region_code = '35' | |
63 | - national_region.national_region_type_id = NationalRegionType::STATE | |
64 | - national_region.save | |
65 | -end | |
66 | - | |
67 | 44 | Given /^the following organization ratings$/ do |table| |
68 | 45 | table.hashes.each do |item| |
69 | 46 | person = User.where(login: item[:user_login]).first.person | ... | ... |