From 6b6deb8d03473c25cea822c69697a60685b5e2dd Mon Sep 17 00:00:00 2001 From: Gabriel Silva Date: Wed, 20 Jan 2016 18:45:49 +0000 Subject: [PATCH] Fixes institution states --- src/noosfero-spb/gov_user/db/migrate/20160120185910_fix_communities_with_wrong_state.rb | 18 ++++++++++++++++++ src/noosfero-spb/gov_user/features/institution_registration.feature | 13 +++++++++++++ src/noosfero-spb/gov_user/features/rate_community.feature | 6 +++--- src/noosfero-spb/gov_user/features/steps_definitions/gov_user_steps_backup.rb | 93 --------------------------------------------------------------------------------------------- src/noosfero-spb/gov_user/features/user_profile_edition.feature | 6 +++--- src/noosfero-spb/gov_user/lib/institution.rb | 20 ++++++++++++++------ src/noosfero-spb/gov_user/public/views/create-institution.js | 40 +++++++++------------------------------- src/noosfero-spb/gov_user/test/functional/gov_user_plugin_controller_test.rb | 43 +++++++++++++++++++++++++++++++++---------- src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb | 8 ++++---- src/noosfero-spb/gov_user/test/functional/profile_editor_controller_test.rb | 4 ++-- src/noosfero-spb/gov_user/test/unit/api_test.rb | 51 --------------------------------------------------- src/noosfero-spb/gov_user/test/unit/gov_user_plugin_api_test.rb | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/noosfero-spb/gov_user/test/unit/private_institution_test.rb | 2 +- src/noosfero-spb/gov_user/test/unit/public_institution_test.rb | 2 +- src/noosfero-spb/gov_user/views/gov_user_plugin/_institution.html.erb | 4 ++-- src/noosfero-spb/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb | 11 ++++------- src/noosfero-spb/software_communities/features/step_definitions/software_communities_steps.rb | 23 ----------------------- 17 files changed, 158 insertions(+), 237 deletions(-) create mode 100644 src/noosfero-spb/gov_user/db/migrate/20160120185910_fix_communities_with_wrong_state.rb delete mode 100644 src/noosfero-spb/gov_user/features/steps_definitions/gov_user_steps_backup.rb delete mode 100644 src/noosfero-spb/gov_user/test/unit/api_test.rb create mode 100644 src/noosfero-spb/gov_user/test/unit/gov_user_plugin_api_test.rb diff --git a/src/noosfero-spb/gov_user/db/migrate/20160120185910_fix_communities_with_wrong_state.rb b/src/noosfero-spb/gov_user/db/migrate/20160120185910_fix_communities_with_wrong_state.rb new file mode 100644 index 0000000..f42eb54 --- /dev/null +++ b/src/noosfero-spb/gov_user/db/migrate/20160120185910_fix_communities_with_wrong_state.rb @@ -0,0 +1,18 @@ +class FixCommunitiesWithWrongState < ActiveRecord::Migration + def up + select_all("SELECT id, data FROM profiles WHERE type = 'Community'").each do |community| + settings = YAML.load(community['data'] || {}.to_yaml) + new_state = Institution::VALID_STATES[settings[:state].upcase] if settings[:state].present? + + if new_state.present? + settings[:state] = new_state + assignments = ActiveRecord::Base.send(:sanitize_sql_for_assignment, {:data => settings.to_yaml}) + update("UPDATE profiles SET %s WHERE id = %d" % [assignments, community['id']]) + end + end + end + + def down + say "This migration can't be reverted." + end +end diff --git a/src/noosfero-spb/gov_user/features/institution_registration.feature b/src/noosfero-spb/gov_user/features/institution_registration.feature index e3297a9..e4f4854 100644 --- a/src/noosfero-spb/gov_user/features/institution_registration.feature +++ b/src/noosfero-spb/gov_user/features/institution_registration.feature @@ -33,3 +33,16 @@ Feature: Institution Field Then I should see "Governmental Sphere" And I should see "Governmental Power" And I should see "Juridical Nature" + + @selenium + Scenario: Clean state and city values when country is diferent of Brazil + Given I follow "Edit Profile" + When I follow "Create new institution" + And I select "Brazil" from "community_country" + And I select "Distrito Federal" from "community_state" + And I fill in "community_city" with "Gama" + And I select "United States" from "community_country" + Then I should not see "community_state" + And I should not see "community_city" + And I select "Brazil" from "community_country" + Then I should not see "Gama" diff --git a/src/noosfero-spb/gov_user/features/rate_community.feature b/src/noosfero-spb/gov_user/features/rate_community.feature index 79b2894..ba7d2ad 100644 --- a/src/noosfero-spb/gov_user/features/rate_community.feature +++ b/src/noosfero-spb/gov_user/features/rate_community.feature @@ -27,8 +27,8 @@ Feature: rate_community And Institutions has initial default values on database And the following public institutions | name | acronym | country | state | city | cnpj | juridical_nature | governmental_power | governmental_sphere | corporate_name | - | Ministerio das Cidades | MC | BR | DF | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal | Ministerio das Cidades | - | Ministerio do Planejamento | MP | BR | DF | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | Ministerio do Planejamento | + | Ministerio das Cidades | MC | BR | Distrito Federal | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal | Ministerio das Cidades | + | Ministerio do Planejamento | MP | BR | Distrito Federal | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | Ministerio do Planejamento | Scenario: display message on task when a rating with the same institution exists on the same software Given the following organization ratings @@ -38,7 +38,7 @@ Feature: rate_community And I go to mycommunity's control panel And I follow "Process requests" within ".pending-tasks" And I choose "Accept" within ".task_decisions" - Then I should see "This institution already has an accepted rating." in the page + Then I should see "This institution already has an accepted rating" in the page Scenario: do not display message on task when a rating with the same institution does not exist on the same software Given the following organization ratings diff --git a/src/noosfero-spb/gov_user/features/steps_definitions/gov_user_steps_backup.rb b/src/noosfero-spb/gov_user/features/steps_definitions/gov_user_steps_backup.rb deleted file mode 100644 index e61c9ff..0000000 --- a/src/noosfero-spb/gov_user/features/steps_definitions/gov_user_steps_backup.rb +++ /dev/null @@ -1,93 +0,0 @@ -Given /^Institutions has initial default values on database$/ do - GovernmentalPower.create(:name => "Executivo") - GovernmentalPower.create(:name => "Legislativo") - GovernmentalPower.create(:name => "Judiciario") - - GovernmentalSphere.create(:name => "Federal") - - JuridicalNature.create(:name => "Autarquia") - JuridicalNature.create(:name => "Administracao Direta") - JuridicalNature.create(:name => "Empresa Publica") - JuridicalNature.create(:name => "Fundacao") - JuridicalNature.create(:name => "Orgao Autonomo") - JuridicalNature.create(:name => "Sociedade") - JuridicalNature.create(:name => "Sociedade Civil") - JuridicalNature.create(:name => "Sociedade de Economia Mista") - - national_region = NationalRegion.new - national_region.name = "Distrito Federal" - national_region.national_region_code = '35' - national_region.national_region_type_id = NationalRegionType::STATE - national_region.save -end - -Given /^I type in "([^"]*)" in autocomplete list "([^"]*)" and I choose "([^"]*)"$/ do |typed, input_field_selector, should_select| -# Wait the page javascript load -sleep 1 -# Basicaly it, search for the input field, type something, wait for ajax end select an item -page.driver.browser.execute_script %Q{ - var search_query = "#{input_field_selector}.ui-autocomplete-input"; - var input = jQuery(search_query).first(); - - input.trigger('click'); - input.val('#{typed}'); - input.trigger('keydown'); - - window.setTimeout(function(){ - search_query = ".ui-menu-item a:contains('#{should_select}')"; - var typed = jQuery(search_query).first(); - - typed.trigger('mouseenter').trigger('click'); - console.log(jQuery('#license_info_id')); - }, 1000); - } - sleep 1 -end - -Given /^the following public institutions?$/ do |table| - # table is a Cucumber::Ast::Table - table.hashes.each do |item| - community = Community.new - community.name = item[:name] - community.country = item[:country] - community.state = item[:state] - community.city = item[:city] - community.save! - - governmental_power = GovernmentalPower.where(:name => item[:governmental_power]).first - governmental_sphere = GovernmentalSphere.where(:name => item[:governmental_sphere]).first - - juridical_nature = JuridicalNature.create(:name => item[:juridical_nature]) - - 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) - institution.community = community - institution.corporate_name = item[:corporate_name] - institution.save! - end -end - -Given /^I sleep for (\d+) seconds$/ do |time| - sleep time.to_i -end - -Given /^I am logged in as mpog_admin$/ do - visit('/account/logout') - - user = User.new(:login => 'admin_user', :password => '123456', :password_confirmation => '123456', :email => 'admin_user@example.com') - person = Person.new :name=>"Mpog Admin", :identifier=>"mpog-admin" - user.person = person - user.save! - - user.activate - e = Environment.default - e.add_admin(user.person) - - visit('/account/login') - fill_in("Username", :with => user.login) - fill_in("Password", :with => '123456') - click_button("Log in") -end - -Given /^I click on anything with selector "([^"]*)"$/ do |selector| - evaluate_script "jQuery('#{selector}').trigger('click') && true" -end diff --git a/src/noosfero-spb/gov_user/features/user_profile_edition.feature b/src/noosfero-spb/gov_user/features/user_profile_edition.feature index cb401d5..6816ce6 100644 --- a/src/noosfero-spb/gov_user/features/user_profile_edition.feature +++ b/src/noosfero-spb/gov_user/features/user_profile_edition.feature @@ -24,9 +24,9 @@ Feature: Institution Field And Institutions has initial default values on database And the following public institutions | name | acronym | country | state | city | cnpj | juridical_nature | governmental_power | governmental_sphere | corporate_name | - | Ministerio das Cidades | MC | BR | DF | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal | Ministerio das Cidades | - | Governo do DF | GDF | BR | DF | Taguatinga | 12.645.166/0001-44 | Autarquia | Legislativo | Federal | Governo do DF | - | Ministerio do Planejamento | MP | BR | DF | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | Ministerio do Planejamento | + | Ministerio das Cidades | MC | BR | Distrito Federal | Gama | 58.745.189/0001-21 | Autarquia | Executivo | Federal | Ministerio das Cidades | + | Governo do DF | GDF | BR | Distrito Federal | Taguatinga | 12.645.166/0001-44 | Autarquia | Legislativo | Federal | Governo do DF | + | Ministerio do Planejamento | MP | BR | Distrito Federal | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | Ministerio do Planejamento | @selenium Scenario: Go to control panel when clicked on 'Complete your profile' link diff --git a/src/noosfero-spb/gov_user/lib/institution.rb b/src/noosfero-spb/gov_user/lib/institution.rb index 463e818..5773e18 100644 --- a/src/noosfero-spb/gov_user/lib/institution.rb +++ b/src/noosfero-spb/gov_user/lib/institution.rb @@ -1,3 +1,5 @@ +#encoding: utf-8 + class Institution < ActiveRecord::Base has_many :comments @@ -8,6 +10,12 @@ class Institution < ActiveRecord::Base CNPJ_FORMAT = /^\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}$/ + VALID_STATES = { "AC"=>"Acre", "AL"=>"Alagoas", "AM"=>"Amazonas", "AP"=>"Amapá", "BA"=>"Bahia", "CE"=>"Ceará", + "DF"=>"Distrito Federal", "ES"=>"Espírito Santo", "GO"=>"Goiás", "MA"=>"Maranhão", "MT"=>"Mato Grosso", + "MS"=>"Mato Grosso do Sul", "MG"=>"Minas Gerais", "PA"=>"Pará", "PB"=>"Paraíba", "PR"=>"Paraná", + "PE"=>"Pernambuco", "PI"=>"Piauí", "RJ"=>"Rio de Janeiro", "RN"=>"Rio Grande do Norte", "RO"=>"Rondônia", + "RS"=>"Rio Grande do Sul", "RR"=>"Roraima", "SC"=>"Santa Catarina", "SE"=>"Sergipe", "SP"=>"São Paulo", "TO"=>"Tocantins" } + def self.default_search_display 'compact' end @@ -76,12 +84,12 @@ class Institution < ActiveRecord::Base end def validate_state - unless self.community.blank? - if self.community.country == "BR" && - (self.community.state.blank? || self.community.state == "-1") && - self.errors[:state].blank? - - self.errors.add(:state, _("can't be blank")) + if self.community.present? && self.community.country == "BR" + if self.community.state.blank? + self.errors.add(:state, _("can't be blank")) if self.errors[:state].blank? + return false + elsif !VALID_STATES.values.include?(self.community.state) + self.errors.add(:state, _("invalid state")) if self.errors[:state].blank? return false end end diff --git a/src/noosfero-spb/gov_user/public/views/create-institution.js b/src/noosfero-spb/gov_user/public/views/create-institution.js index 8416ac1..38394ef 100644 --- a/src/noosfero-spb/gov_user/public/views/create-institution.js +++ b/src/noosfero-spb/gov_user/public/views/create-institution.js @@ -284,9 +284,10 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] function show_hide_cnpj_city(country) { var cnpj = $("#institutions_cnpj").parent().parent(); - var city = $("#community_city").parent(); + var city = $("#community_city"); var city_label = $('label[for="community_city"]'); - var state = $("#community_state").parent(); + var state = $("#community_state"); + var state_label = $('label[for="community_state"]'); var inst_type = $("input[name='institutions[type]']:checked").val(); institution_type_actions(inst_type); @@ -298,13 +299,17 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] if ( country !== "BR" ) { cnpj.hide(); - city.find('input').val(''); city.hide(); + city.val(''); + city.hide(); city_label.hide(); + state.val(""); state.hide(); + state_label.hide(); } else { cnpj.show(); city.show(); city_label.show(); + state_label.show(); state.show(); } } @@ -318,33 +323,6 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] } } - - function set_form_count_custom_data() { - var divisor_option = SelectElement.generateOption("-1", "--------------------------------"); - var default_option = SelectElement.generateOption("BR", "Brazil"); - - var inst_type = $("input[name='institutions[type]']:checked").val(); - var country = $("#community_country").val(); - - institution_type_actions(inst_type); - show_hide_cnpj_city(country); - - if( $('#community_country').find("option[value='']").length === 1 ) { - $('#community_country').find("option[value='']").remove(); - $('#community_country').prepend(divisor_option); - $('#community_country').prepend(default_option); - - if ($('#add_institution_link').length > 0) { - $('#add_institution_link').hide(); - } - - if($("#edit_institution_page").val() === "false") { - $('#community_country').val("BR"); - show_hide_cnpj_city($('#community_country').val()); - } - } - } - function autoCompleteCity() { var country_selected = $('#community_country').val(); @@ -416,7 +394,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] function init_module() { - set_form_count_custom_data(); + show_hide_cnpj_city($('#community_country').val()); set_events(); } diff --git a/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_controller_test.rb b/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_controller_test.rb index 56ee856..ae22769 100644 --- a/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_controller_test.rb +++ b/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_controller_test.rb @@ -26,7 +26,7 @@ class GovUserPluginControllerTest < ActionController::TestCase "Ministerio Publico da Uniao", "MPU", "BR", - "DF", + "Distrito Federal", "Gama", @juridical_nature, @gov_power, @@ -37,7 +37,7 @@ class GovUserPluginControllerTest < ActionController::TestCase "Tribunal Regional da Uniao", "TRU", "BR", - "DF", + "Distrito Federal", "Brasilia", @juridical_nature, @gov_power, @@ -84,7 +84,7 @@ class GovUserPluginControllerTest < ActionController::TestCase fields = InstitutionTestHelper.generate_form_fields( "foo bar", "BR", - "DF", + "Distrito Federal", "Brasilia", "12.234.567/8900-10", "PublicInstitution" @@ -100,14 +100,14 @@ class GovUserPluginControllerTest < ActionController::TestCase assert json_response["success"] end - should "create a institution without cnpj" do + should "not create a private institution without cnpj" do @controller.stubs(:verify_recaptcha).returns(true) fields = InstitutionTestHelper.generate_form_fields( "Some Private Institution", - "EN", - "NY", - "New York", + "BR", + "Distrito Federal", + "Brasilia", "", "PrivateInstitution" ) @@ -117,6 +117,29 @@ class GovUserPluginControllerTest < ActionController::TestCase json_response = ActiveSupport::JSON.decode(@response.body) + assert_false json_response["success"] + assert json_response["errors"].include? "Cnpj can't be blank" + end + + should "create public institution without cnpj" do + @controller.stubs(:verify_recaptcha).returns(true) + + fields = InstitutionTestHelper.generate_form_fields( + "Some Private Institution", + "BR", + "Distrito Federal", + "Brasilia", + "56.366.790/0001-88", + "PublicInstitution" + ) + fields[:institutions][:governmental_power] = @gov_power.id + fields[:institutions][:governmental_sphere] = @gov_sphere.id + fields[:institutions][:juridical_nature] = @juridical_nature.id + + xhr :get, :new_institution, fields + + json_response = ActiveSupport::JSON.decode(@response.body) + assert json_response["success"] end @@ -144,7 +167,7 @@ class GovUserPluginControllerTest < ActionController::TestCase fields = InstitutionTestHelper.generate_form_fields( "Some Private Institution", "BR", - "DF", + "Distrito Federal", "Brasilia", "12.345.567/8900-10", "PrivateInstitution" @@ -162,7 +185,7 @@ class GovUserPluginControllerTest < ActionController::TestCase fields = InstitutionTestHelper.generate_form_fields( "Some Private Institution", "BR", - "DF", + "Distrito Federal", "Brasilia", "56.366.790/0001-88", "PrivateInstitution" @@ -221,7 +244,7 @@ class GovUserPluginControllerTest < ActionController::TestCase fields = InstitutionTestHelper.generate_form_fields( "Private Institution", "BR", - "DF", + "Distrito Federal", "Brasilia", "12.323.557/8900-10", "PrivateInstitution" diff --git a/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb b/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb index f21b325..0ee21ca 100644 --- a/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb +++ b/src/noosfero-spb/gov_user/test/functional/gov_user_plugin_myprofile_controller.rb @@ -25,7 +25,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase "Ministerio Publico da Uniao", "MPU", "BR", - "DF", + "Distrito Federal", "Gama", juridical_nature, gov_power, @@ -46,7 +46,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase fields = InstitutionTestHelper.generate_form_fields( "institution new name", "BR", - "DF", + "Distrito Federal", "Gama", "12.345.678/9012-45", "PrivateInstitution" @@ -68,7 +68,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase fields = InstitutionTestHelper.generate_form_fields( "institution new name", "BR", - "DF", + "Distrito Federal", "Gama", "12.345.678/9012-45", "PrivateInstitution" @@ -91,7 +91,7 @@ class GovUserPluginMyprofileControllerTest < ActionController::TestCase fields = InstitutionTestHelper.generate_form_fields( "", "BR", - "DF", + "Distrito Federal", "Gama", "6465465465", "PrivateInstitution" diff --git a/src/noosfero-spb/gov_user/test/functional/profile_editor_controller_test.rb b/src/noosfero-spb/gov_user/test/functional/profile_editor_controller_test.rb index 5241483..38465af 100644 --- a/src/noosfero-spb/gov_user/test/functional/profile_editor_controller_test.rb +++ b/src/noosfero-spb/gov_user/test/functional/profile_editor_controller_test.rb @@ -38,7 +38,7 @@ class ProfileEditorControllerTest < ActionController::TestCase "Ministerio Publico da Uniao", "MPU", "BR", - "DF", + "Distrito Federal", "Gama", @juridical_nature, @govPower, @@ -50,7 +50,7 @@ class ProfileEditorControllerTest < ActionController::TestCase "Tribunal Regional da Uniao", "TRU", "BR", - "DF", + "Distrito Federal", "Brasilia", @juridical_nature, @govPower, diff --git a/src/noosfero-spb/gov_user/test/unit/api_test.rb b/src/noosfero-spb/gov_user/test/unit/api_test.rb deleted file mode 100644 index abfead0..0000000 --- a/src/noosfero-spb/gov_user/test/unit/api_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require File.dirname(__FILE__) + '/../../../../test/unit/api/test_helper' -require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' - -class GovUserApiTest < ActiveSupport::TestCase - - include PluginTestHelper - - def setup - login_api - environment = Environment.default - environment.enable_plugin(GovUserPlugin) - @gov_power = GovernmentalPower.create(:name=>"Some Gov Power") - @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") - @juridical_nature = JuridicalNature.create(:name => "Autarquia") - @institution = create_public_institution( - "Ministerio Publico da Uniao", - "MPU", - "BR", - "DF", - "Gama", - @juridical_nature, - @gov_power, - @gov_sphere, - "11.222.333/4444-55") - end - - should 'list all institutions' do - @institution1 = create_public_institution( - "Instituicao bacana", - "IB", - "BR", - "DF", - "Gama", - @juridical_nature, - @gov_power, - @gov_sphere, - "11.222.333/4444-56" - ) - - get "/api/v1/gov_user/institutions?#{params.to_query}" - json = JSON.parse(last_response.body) - assert_equivalent [@institution.id, @institution1.id], json['institutions'].map {|c| c['id']} - end - - should 'get institution by id' do - get "/api/v1/gov_user/institutions/#{@institution.id}?#{params.to_query}" - json = JSON.parse(last_response.body) - assert_equal @institution.id, json["institution"]["id"] - end - -end diff --git a/src/noosfero-spb/gov_user/test/unit/gov_user_plugin_api_test.rb b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin_api_test.rb new file mode 100644 index 0000000..8ba701b --- /dev/null +++ b/src/noosfero-spb/gov_user/test/unit/gov_user_plugin_api_test.rb @@ -0,0 +1,51 @@ +require File.dirname(__FILE__) + '/../../../../test/unit/api/test_helper' +require File.dirname(__FILE__) + '/../helpers/plugin_test_helper' + +class GovUserPlugin::ApiTest < ActiveSupport::TestCase + + include PluginTestHelper + + def setup + login_api + environment = Environment.default + environment.enable_plugin(GovUserPlugin) + @gov_power = GovernmentalPower.create(:name=>"Some Gov Power") + @gov_sphere = GovernmentalSphere.create(:name=>"Some Gov Sphere") + @juridical_nature = JuridicalNature.create(:name => "Autarquia") + @institution = create_public_institution( + "Ministerio Publico da Uniao", + "MPU", + "BR", + "Distrito Federal", + "Gama", + @juridical_nature, + @gov_power, + @gov_sphere, + "11.222.333/4444-55") + end + + should 'list all institutions' do + @institution1 = create_public_institution( + "Instituicao bacana", + "IB", + "BR", + "Distrito Federal", + "Gama", + @juridical_nature, + @gov_power, + @gov_sphere, + "11.222.333/4444-56" + ) + + get "/api/v1/gov_user/institutions?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equivalent [@institution.id, @institution1.id], json['institutions'].map {|c| c['id']} + end + + should 'get institution by id' do + get "/api/v1/gov_user/institutions/#{@institution.id}?#{params.to_query}" + json = JSON.parse(last_response.body) + assert_equal @institution.id, json["institution"]["id"] + end + +end diff --git a/src/noosfero-spb/gov_user/test/unit/private_institution_test.rb b/src/noosfero-spb/gov_user/test/unit/private_institution_test.rb index 0f04532..e2501da 100644 --- a/src/noosfero-spb/gov_user/test/unit/private_institution_test.rb +++ b/src/noosfero-spb/gov_user/test/unit/private_institution_test.rb @@ -8,7 +8,7 @@ class PrivateInstitutionTest < ActiveSupport::TestCase "Simple Private Institution", "SPI", "BR", - "DF", + "Distrito Federal", "Gama", "00.000.000/0001-00" ) diff --git a/src/noosfero-spb/gov_user/test/unit/public_institution_test.rb b/src/noosfero-spb/gov_user/test/unit/public_institution_test.rb index cfb6220..bbaca77 100644 --- a/src/noosfero-spb/gov_user/test/unit/public_institution_test.rb +++ b/src/noosfero-spb/gov_user/test/unit/public_institution_test.rb @@ -12,7 +12,7 @@ class PublicInstitutionTest < ActiveSupport::TestCase "Ministerio Publico da Uniao", "MPU", "BR", - "DF", + "Distrito Federal", "Gama", @juridical_nature, @gov_power, diff --git a/src/noosfero-spb/gov_user/views/gov_user_plugin/_institution.html.erb b/src/noosfero-spb/gov_user/views/gov_user_plugin/_institution.html.erb index 80d4c33..e597109 100644 --- a/src/noosfero-spb/gov_user/views/gov_user_plugin/_institution.html.erb +++ b/src/noosfero-spb/gov_user/views/gov_user_plugin/_institution.html.erb @@ -80,7 +80,7 @@ (*) - <%= select("community", "country", [[_('Select a country'), nil]] + country_helper.countries, {:class => "type-select #{flash[:error_community_country]}"}) %> + <%= select("community", "country", [[_('Select a country'), -1]] + country_helper.countries, {:class => "type-select #{flash[:error_community_country]}"}) %>
@@ -89,7 +89,7 @@ (*) - <%= f.select(:state, @state_options, {:selected => params[:community][:state]}, {:class => flash[:error_community_state]}) %> + <%= select("community", "state", [[_('Select a state'), '']] + @state_options, {:class => "type-select #{flash[:error_community_state]}"}) %>
diff --git a/src/noosfero-spb/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb b/src/noosfero-spb/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb index 1f07a54..f82f3b3 100644 --- a/src/noosfero-spb/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb +++ b/src/noosfero-spb/gov_user/views/gov_user_plugin_myprofile/edit_institution.html.erb @@ -44,14 +44,11 @@ <%= labelled_form_field(_('Fantasy name'), inst.text_field(:corporate_name, :value => @institution.corporate_name)) %> - <%= required select_country(_('Country'), 'community', 'country', {:class => 'type-select', :id => "community_country"}, :selected => @institution.community.country) %> + <%= required labelled_form_field(_('Country'), select("community", "country", [[_('Select a country'), -1]] + country_helper.countries, + {:selected => @institution.community.country, :class => "type-select #{flash[:error_community_country]}"})) %> - -
- - <%= f.select(:state, @state_list.collect {|state| [state.name, state.name]}, :selected => @institution.community.state) %> -
-
+ <%= required labelled_form_field(_('State'), select("community", "state", [[_('Select a state'), '']] + @state_list.collect {|state| [state.name, state.name]}, + {:selected => @institution.community.state, :class => "type-select #{flash[:error_community_state]}"})) %> <%= required f.text_field(:city, :value => @institution.community.city) %> diff --git a/src/noosfero-spb/software_communities/features/step_definitions/software_communities_steps.rb b/src/noosfero-spb/software_communities/features/step_definitions/software_communities_steps.rb index b1c9c5d..588af1c 100644 --- a/src/noosfero-spb/software_communities/features/step_definitions/software_communities_steps.rb +++ b/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 "([^"]*) sleep 1 end -Given /^Institutions has initial default values on database$/ do - GovernmentalPower.create(:name => "Executivo") - GovernmentalPower.create(:name => "Legislativo") - GovernmentalPower.create(:name => "Judiciario") - - GovernmentalSphere.create(:name => "Federal") - - JuridicalNature.create(:name => "Autarquia") - JuridicalNature.create(:name => "Administracao Direta") - JuridicalNature.create(:name => "Empresa Publica") - JuridicalNature.create(:name => "Fundacao") - JuridicalNature.create(:name => "Orgao Autonomo") - JuridicalNature.create(:name => "Sociedade") - JuridicalNature.create(:name => "Sociedade Civil") - JuridicalNature.create(:name => "Sociedade de Economia Mista") - - national_region = NationalRegion.new - national_region.name = "Distrito Federal" - national_region.national_region_code = '35' - national_region.national_region_type_id = NationalRegionType::STATE - national_region.save -end - Given /^the following organization ratings$/ do |table| table.hashes.each do |item| person = User.where(login: item[:user_login]).first.person -- libgit2 0.21.2