Commit 6b6deb8d03473c25cea822c69697a60685b5e2dd
Committed by
Daniela Feitosa
1 parent
1b7ba1f1
Exists in
master
and in
9 other branches
Fixes institution states
Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com> Signed-off-by: Eduardo Vital <vitaldu@gmail.com> Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com> Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> Signed-off-by: Daniela Feitosa <danielafeitosa@colivre.coop.br>
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 @@ | @@ -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,3 +33,16 @@ Feature: Institution Field | ||
| 33 | Then I should see "Governmental Sphere" | 33 | Then I should see "Governmental Sphere" |
| 34 | And I should see "Governmental Power" | 34 | And I should see "Governmental Power" |
| 35 | And I should see "Juridical Nature" | 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,8 +27,8 @@ Feature: rate_community | ||
| 27 | And Institutions has initial default values on database | 27 | And Institutions has initial default values on database |
| 28 | And the following public institutions | 28 | And the following public institutions |
| 29 | | name | acronym | country | state | city | cnpj | juridical_nature | governmental_power | governmental_sphere | corporate_name | | 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 | Scenario: display message on task when a rating with the same institution exists on the same software | 33 | Scenario: display message on task when a rating with the same institution exists on the same software |
| 34 | Given the following organization ratings | 34 | Given the following organization ratings |
| @@ -38,7 +38,7 @@ Feature: rate_community | @@ -38,7 +38,7 @@ Feature: rate_community | ||
| 38 | And I go to mycommunity's control panel | 38 | And I go to mycommunity's control panel |
| 39 | And I follow "Process requests" within ".pending-tasks" | 39 | And I follow "Process requests" within ".pending-tasks" |
| 40 | And I choose "Accept" within ".task_decisions" | 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 | Scenario: do not display message on task when a rating with the same institution does not exist on the same software | 43 | Scenario: do not display message on task when a rating with the same institution does not exist on the same software |
| 44 | Given the following organization ratings | 44 | Given the following organization ratings |
src/noosfero-spb/gov_user/features/steps_definitions/gov_user_steps_backup.rb
| @@ -1,93 +0,0 @@ | @@ -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,9 +24,9 @@ Feature: Institution Field | ||
| 24 | And Institutions has initial default values on database | 24 | And Institutions has initial default values on database |
| 25 | And the following public institutions | 25 | And the following public institutions |
| 26 | | name | acronym | country | state | city | cnpj | juridical_nature | governmental_power | governmental_sphere | corporate_name | | 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 | @selenium | 31 | @selenium |
| 32 | Scenario: Go to control panel when clicked on 'Complete your profile' link | 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 | class Institution < ActiveRecord::Base | 3 | class Institution < ActiveRecord::Base |
| 2 | has_many :comments | 4 | has_many :comments |
| 3 | 5 | ||
| @@ -8,6 +10,12 @@ class Institution < ActiveRecord::Base | @@ -8,6 +10,12 @@ class Institution < ActiveRecord::Base | ||
| 8 | 10 | ||
| 9 | CNPJ_FORMAT = /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/ | 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 | def self.default_search_display | 19 | def self.default_search_display |
| 12 | 'compact' | 20 | 'compact' |
| 13 | end | 21 | end |
| @@ -76,12 +84,12 @@ class Institution < ActiveRecord::Base | @@ -76,12 +84,12 @@ class Institution < ActiveRecord::Base | ||
| 76 | end | 84 | end |
| 77 | 85 | ||
| 78 | def validate_state | 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 | return false | 93 | return false |
| 86 | end | 94 | end |
| 87 | end | 95 | end |
src/noosfero-spb/gov_user/public/views/create-institution.js
| @@ -284,9 +284,10 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | @@ -284,9 +284,10 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | ||
| 284 | 284 | ||
| 285 | function show_hide_cnpj_city(country) { | 285 | function show_hide_cnpj_city(country) { |
| 286 | var cnpj = $("#institutions_cnpj").parent().parent(); | 286 | var cnpj = $("#institutions_cnpj").parent().parent(); |
| 287 | - var city = $("#community_city").parent(); | 287 | + var city = $("#community_city"); |
| 288 | var city_label = $('label[for="community_city"]'); | 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 | var inst_type = $("input[name='institutions[type]']:checked").val(); | 291 | var inst_type = $("input[name='institutions[type]']:checked").val(); |
| 291 | 292 | ||
| 292 | institution_type_actions(inst_type); | 293 | institution_type_actions(inst_type); |
| @@ -298,13 +299,17 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | @@ -298,13 +299,17 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | ||
| 298 | 299 | ||
| 299 | if ( country !== "BR" ) { | 300 | if ( country !== "BR" ) { |
| 300 | cnpj.hide(); | 301 | cnpj.hide(); |
| 301 | - city.find('input').val(''); city.hide(); | 302 | + city.val(''); |
| 303 | + city.hide(); | ||
| 302 | city_label.hide(); | 304 | city_label.hide(); |
| 305 | + state.val(""); | ||
| 303 | state.hide(); | 306 | state.hide(); |
| 307 | + state_label.hide(); | ||
| 304 | } else { | 308 | } else { |
| 305 | cnpj.show(); | 309 | cnpj.show(); |
| 306 | city.show(); | 310 | city.show(); |
| 307 | city_label.show(); | 311 | city_label.show(); |
| 312 | + state_label.show(); | ||
| 308 | state.show(); | 313 | state.show(); |
| 309 | } | 314 | } |
| 310 | } | 315 | } |
| @@ -318,33 +323,6 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | @@ -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 | function autoCompleteCity() { | 326 | function autoCompleteCity() { |
| 349 | var country_selected = $('#community_country').val(); | 327 | var country_selected = $('#community_country').val(); |
| 350 | 328 | ||
| @@ -416,7 +394,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | @@ -416,7 +394,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] | ||
| 416 | 394 | ||
| 417 | 395 | ||
| 418 | function init_module() { | 396 | function init_module() { |
| 419 | - set_form_count_custom_data(); | 397 | + show_hide_cnpj_city($('#community_country').val()); |
| 420 | set_events(); | 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,7 +26,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
| 26 | "Ministerio Publico da Uniao", | 26 | "Ministerio Publico da Uniao", |
| 27 | "MPU", | 27 | "MPU", |
| 28 | "BR", | 28 | "BR", |
| 29 | - "DF", | 29 | + "Distrito Federal", |
| 30 | "Gama", | 30 | "Gama", |
| 31 | @juridical_nature, | 31 | @juridical_nature, |
| 32 | @gov_power, | 32 | @gov_power, |
| @@ -37,7 +37,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -37,7 +37,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
| 37 | "Tribunal Regional da Uniao", | 37 | "Tribunal Regional da Uniao", |
| 38 | "TRU", | 38 | "TRU", |
| 39 | "BR", | 39 | "BR", |
| 40 | - "DF", | 40 | + "Distrito Federal", |
| 41 | "Brasilia", | 41 | "Brasilia", |
| 42 | @juridical_nature, | 42 | @juridical_nature, |
| 43 | @gov_power, | 43 | @gov_power, |
| @@ -84,7 +84,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -84,7 +84,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
| 84 | fields = InstitutionTestHelper.generate_form_fields( | 84 | fields = InstitutionTestHelper.generate_form_fields( |
| 85 | "foo bar", | 85 | "foo bar", |
| 86 | "BR", | 86 | "BR", |
| 87 | - "DF", | 87 | + "Distrito Federal", |
| 88 | "Brasilia", | 88 | "Brasilia", |
| 89 | "12.234.567/8900-10", | 89 | "12.234.567/8900-10", |
| 90 | "PublicInstitution" | 90 | "PublicInstitution" |
| @@ -100,14 +100,14 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -100,14 +100,14 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
| 100 | assert json_response["success"] | 100 | assert json_response["success"] |
| 101 | end | 101 | end |
| 102 | 102 | ||
| 103 | - should "create a institution without cnpj" do | 103 | + should "not create a private institution without cnpj" do |
| 104 | @controller.stubs(:verify_recaptcha).returns(true) | 104 | @controller.stubs(:verify_recaptcha).returns(true) |
| 105 | 105 | ||
| 106 | fields = InstitutionTestHelper.generate_form_fields( | 106 | fields = InstitutionTestHelper.generate_form_fields( |
| 107 | "Some Private Institution", | 107 | "Some Private Institution", |
| 108 | - "EN", | ||
| 109 | - "NY", | ||
| 110 | - "New York", | 108 | + "BR", |
| 109 | + "Distrito Federal", | ||
| 110 | + "Brasilia", | ||
| 111 | "", | 111 | "", |
| 112 | "PrivateInstitution" | 112 | "PrivateInstitution" |
| 113 | ) | 113 | ) |
| @@ -117,6 +117,29 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -117,6 +117,29 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
| 117 | 117 | ||
| 118 | json_response = ActiveSupport::JSON.decode(@response.body) | 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 | assert json_response["success"] | 143 | assert json_response["success"] |
| 121 | end | 144 | end |
| 122 | 145 | ||
| @@ -144,7 +167,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -144,7 +167,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
| 144 | fields = InstitutionTestHelper.generate_form_fields( | 167 | fields = InstitutionTestHelper.generate_form_fields( |
| 145 | "Some Private Institution", | 168 | "Some Private Institution", |
| 146 | "BR", | 169 | "BR", |
| 147 | - "DF", | 170 | + "Distrito Federal", |
| 148 | "Brasilia", | 171 | "Brasilia", |
| 149 | "12.345.567/8900-10", | 172 | "12.345.567/8900-10", |
| 150 | "PrivateInstitution" | 173 | "PrivateInstitution" |
| @@ -162,7 +185,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -162,7 +185,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
| 162 | fields = InstitutionTestHelper.generate_form_fields( | 185 | fields = InstitutionTestHelper.generate_form_fields( |
| 163 | "Some Private Institution", | 186 | "Some Private Institution", |
| 164 | "BR", | 187 | "BR", |
| 165 | - "DF", | 188 | + "Distrito Federal", |
| 166 | "Brasilia", | 189 | "Brasilia", |
| 167 | "56.366.790/0001-88", | 190 | "56.366.790/0001-88", |
| 168 | "PrivateInstitution" | 191 | "PrivateInstitution" |
| @@ -221,7 +244,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | @@ -221,7 +244,7 @@ class GovUserPluginControllerTest < ActionController::TestCase | ||
| 221 | fields = InstitutionTestHelper.generate_form_fields( | 244 | fields = InstitutionTestHelper.generate_form_fields( |
| 222 | "Private Institution", | 245 | "Private Institution", |
| 223 | "BR", | 246 | "BR", |
| 224 | - "DF", | 247 | + "Distrito Federal", |
| 225 | "Brasilia", | 248 | "Brasilia", |
| 226 | "12.323.557/8900-10", | 249 | "12.323.557/8900-10", |
| 227 | "PrivateInstitution" | 250 | "PrivateInstitution" |
src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb
| @@ -25,7 +25,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase | @@ -25,7 +25,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase | ||
| 25 | "Ministerio Publico da Uniao", | 25 | "Ministerio Publico da Uniao", |
| 26 | "MPU", | 26 | "MPU", |
| 27 | "BR", | 27 | "BR", |
| 28 | - "DF", | 28 | + "Distrito Federal", |
| 29 | "Gama", | 29 | "Gama", |
| 30 | juridical_nature, | 30 | juridical_nature, |
| 31 | gov_power, | 31 | gov_power, |
| @@ -46,7 +46,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase | @@ -46,7 +46,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase | ||
| 46 | fields = InstitutionTestHelper.generate_form_fields( | 46 | fields = InstitutionTestHelper.generate_form_fields( |
| 47 | "institution new name", | 47 | "institution new name", |
| 48 | "BR", | 48 | "BR", |
| 49 | - "DF", | 49 | + "Distrito Federal", |
| 50 | "Gama", | 50 | "Gama", |
| 51 | "12.345.678/9012-45", | 51 | "12.345.678/9012-45", |
| 52 | "PrivateInstitution" | 52 | "PrivateInstitution" |
| @@ -68,7 +68,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase | @@ -68,7 +68,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase | ||
| 68 | fields = InstitutionTestHelper.generate_form_fields( | 68 | fields = InstitutionTestHelper.generate_form_fields( |
| 69 | "institution new name", | 69 | "institution new name", |
| 70 | "BR", | 70 | "BR", |
| 71 | - "DF", | 71 | + "Distrito Federal", |
| 72 | "Gama", | 72 | "Gama", |
| 73 | "12.345.678/9012-45", | 73 | "12.345.678/9012-45", |
| 74 | "PrivateInstitution" | 74 | "PrivateInstitution" |
| @@ -91,7 +91,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase | @@ -91,7 +91,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase | ||
| 91 | fields = InstitutionTestHelper.generate_form_fields( | 91 | fields = InstitutionTestHelper.generate_form_fields( |
| 92 | "", | 92 | "", |
| 93 | "BR", | 93 | "BR", |
| 94 | - "DF", | 94 | + "Distrito Federal", |
| 95 | "Gama", | 95 | "Gama", |
| 96 | "6465465465", | 96 | "6465465465", |
| 97 | "PrivateInstitution" | 97 | "PrivateInstitution" |
src/noosfero-spb/gov_user/test/functional/profile_editor_controller_test.rb
| @@ -38,7 +38,7 @@ class ProfileEditorControllerTest < ActionController::TestCase | @@ -38,7 +38,7 @@ class ProfileEditorControllerTest < ActionController::TestCase | ||
| 38 | "Ministerio Publico da Uniao", | 38 | "Ministerio Publico da Uniao", |
| 39 | "MPU", | 39 | "MPU", |
| 40 | "BR", | 40 | "BR", |
| 41 | - "DF", | 41 | + "Distrito Federal", |
| 42 | "Gama", | 42 | "Gama", |
| 43 | @juridical_nature, | 43 | @juridical_nature, |
| 44 | @govPower, | 44 | @govPower, |
| @@ -50,7 +50,7 @@ class ProfileEditorControllerTest < ActionController::TestCase | @@ -50,7 +50,7 @@ class ProfileEditorControllerTest < ActionController::TestCase | ||
| 50 | "Tribunal Regional da Uniao", | 50 | "Tribunal Regional da Uniao", |
| 51 | "TRU", | 51 | "TRU", |
| 52 | "BR", | 52 | "BR", |
| 53 | - "DF", | 53 | + "Distrito Federal", |
| 54 | "Brasilia", | 54 | "Brasilia", |
| 55 | @juridical_nature, | 55 | @juridical_nature, |
| 56 | @govPower, | 56 | @govPower, |
src/noosfero-spb/gov_user/test/unit/api_test.rb
| @@ -1,51 +0,0 @@ | @@ -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 @@ | @@ -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
| @@ -8,7 +8,7 @@ class PrivateInstitutionTest < ActiveSupport::TestCase | @@ -8,7 +8,7 @@ class PrivateInstitutionTest < ActiveSupport::TestCase | ||
| 8 | "Simple Private Institution", | 8 | "Simple Private Institution", |
| 9 | "SPI", | 9 | "SPI", |
| 10 | "BR", | 10 | "BR", |
| 11 | - "DF", | 11 | + "Distrito Federal", |
| 12 | "Gama", | 12 | "Gama", |
| 13 | "00.000.000/0001-00" | 13 | "00.000.000/0001-00" |
| 14 | ) | 14 | ) |
src/noosfero-spb/gov_user/test/unit/public_institution_test.rb
| @@ -12,7 +12,7 @@ class PublicInstitutionTest < ActiveSupport::TestCase | @@ -12,7 +12,7 @@ class PublicInstitutionTest < ActiveSupport::TestCase | ||
| 12 | "Ministerio Publico da Uniao", | 12 | "Ministerio Publico da Uniao", |
| 13 | "MPU", | 13 | "MPU", |
| 14 | "BR", | 14 | "BR", |
| 15 | - "DF", | 15 | + "Distrito Federal", |
| 16 | "Gama", | 16 | "Gama", |
| 17 | @juridical_nature, | 17 | @juridical_nature, |
| 18 | @gov_power, | 18 | @gov_power, |
src/noosfero-spb/gov_user/views/gov_user_plugin/_institution.html.erb
| @@ -80,7 +80,7 @@ | @@ -80,7 +80,7 @@ | ||
| 80 | <span class="required-field">(*)</span> | 80 | <span class="required-field">(*)</span> |
| 81 | </label> | 81 | </label> |
| 82 | 82 | ||
| 83 | - <%= select("community", "country", [[_('Select a country'), nil]] + country_helper.countries, {:class => "type-select #{flash[:error_community_country]}"}) %> | 83 | + <%= select("community", "country", [[_('Select a country'), -1]] + country_helper.countries, {:class => "type-select #{flash[:error_community_country]}"}) %> |
| 84 | </div> | 84 | </div> |
| 85 | 85 | ||
| 86 | <div class="spb-col spb-col-2"> | 86 | <div class="spb-col spb-col-2"> |
| @@ -89,7 +89,7 @@ | @@ -89,7 +89,7 @@ | ||
| 89 | <span class="required-field">(*)</span> | 89 | <span class="required-field">(*)</span> |
| 90 | </label> | 90 | </label> |
| 91 | 91 | ||
| 92 | - <%= f.select(:state, @state_options, {:selected => params[:community][:state]}, {:class => flash[:error_community_state]}) %> | 92 | + <%= select("community", "state", [[_('Select a state'), '']] + @state_options, {:class => "type-select #{flash[:error_community_state]}"}) %> |
| 93 | </div> | 93 | </div> |
| 94 | 94 | ||
| 95 | <div class="spb-col spb-col-5"> | 95 | <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,14 +44,11 @@ | ||
| 44 | 44 | ||
| 45 | <%= labelled_form_field(_('Fantasy name'), inst.text_field(:corporate_name, :value => @institution.corporate_name)) %> | 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 | <%= required f.text_field(:city, :value => @institution.community.city) %> | 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,29 +41,6 @@ Given /^I type in "([^"]*)" in autocomplete list "([^"]*)" and I choose "([^"]*) | ||
| 41 | sleep 1 | 41 | sleep 1 |
| 42 | end | 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 | Given /^the following organization ratings$/ do |table| | 44 | Given /^the following organization ratings$/ do |table| |
| 68 | table.hashes.each do |item| | 45 | table.hashes.each do |item| |
| 69 | person = User.where(login: item[:user_login]).first.person | 46 | person = User.where(login: item[:user_login]).first.person |