diff --git a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb index 04b94b7..15b9ecd 100644 --- a/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb +++ b/src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb @@ -65,7 +65,9 @@ class GovUserPluginController < ApplicationController def get_institutions redirect_to "/" if !request.xhr? || params[:query].blank? + selected_institutions = Institution.where(id: params[:selected_institutions]).select([:id, :name]) institutions = Institution.search_institution(params[:query]).select([:id, :name]) + institutions -= selected_institutions institutions_list = institutions.map { |institution| {:value=>institution.name, :id=>institution.id} } diff --git a/src/noosfero-spb/gov_user/features/institution_registration.feature b/src/noosfero-spb/gov_user/features/institution_registration.feature index c1fbb4e..e3297a9 100644 --- a/src/noosfero-spb/gov_user/features/institution_registration.feature +++ b/src/noosfero-spb/gov_user/features/institution_registration.feature @@ -5,9 +5,12 @@ Feature: Institution Field Background: Given "GovUserPlugin" plugin is enabled + And "SoftwareCommunitiesPlugin" plugin is enabled And I am logged in as mpog_admin + And I go to /admin/environment_themes/set/noosfero-spb-theme And I go to /admin/plugins And I check "GovUserPlugin" + And I check "SoftwareCommunitiesPlugin" And I press "Save changes" And Institutions has initial default values on database And I am logged in as mpog_admin @@ -27,6 +30,6 @@ Feature: Institution Field And I should see "CNPJ" And I should see "Acronym" And I choose "Public Institution" - Then I should see "Governmental Sphere:" - And I should see "Governmental Power:" - And I should see "Juridical Nature:" + Then I should see "Governmental Sphere" + And I should see "Governmental Power" + And I should see "Juridical Nature" diff --git a/src/noosfero-spb/gov_user/features/rate_community.feature b/src/noosfero-spb/gov_user/features/rate_community.feature index d5d3d87..79b2894 100644 --- a/src/noosfero-spb/gov_user/features/rate_community.feature +++ b/src/noosfero-spb/gov_user/features/rate_community.feature @@ -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 instiution 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/rating_institution_registration.feature b/src/noosfero-spb/gov_user/features/rating_institution_registration.feature index 1979966..7467f43 100644 --- a/src/noosfero-spb/gov_user/features/rating_institution_registration.feature +++ b/src/noosfero-spb/gov_user/features/rating_institution_registration.feature @@ -8,6 +8,7 @@ Feature: Create institution on user report And "SoftwareCommunitiesPlugin" plugin is enabled And "OrganizationRatings" plugin is enabled And I am logged in as mpog_admin + And I go to /admin/environment_themes/set/noosfero-spb-theme And I go to /admin/plugins And I check "GovUserPlugin" And I check "SoftwareCommunitiesPlugin" @@ -23,20 +24,20 @@ Feature: Create institution on user report And I should not see "Number of Beneficiaries" And I should not see "Saved resources" And I should not see "Organization name or Enterprise name" - When I click on anything with selector "#comments-additional-information" - Then I should see "Number of Beneficiaries" - And I should see "Organization name or Enterprise name" - And I should see "Saved resources" + When I click on anything with selector "comments-additional-information" + Then I should see "Número de beneficiados" + And I should see "Nome do órgão ou empresa" + And I should see "Recursos economizados" @selenium Scenario: Show new institution fields when clicked in add new institution Given I go to /profile/noosfero/plugin/organization_ratings/new_rating - And I click on anything with selector "#comments-additional-information" + And I sleep for 1 seconds + And I click on anything with selector "comments-additional-information" And I fill in "input_institution" with "None institution" And I sleep for 2 seconds When I follow "Add" - Then I should see "New Institution" - And I should see "Public Institution" + Then I should see "Public Institution" And I should see "Private Institution" And I should see "Corporate Name" And I should see "Name" @@ -46,33 +47,30 @@ Feature: Create institution on user report And I should see "CNPJ" And I should see "Acronym" And I choose "Public Institution" - And I should see "Governmental Sphere:" - And I should see "Governmental Power:" - And I should see "Juridical Nature:" + And I should see "Governmental Sphere" + And I should see "Governmental Power" + And I should see "Juridical Nature" @selenium Scenario: Create new institution with name changed in the modal Given I go to /profile/noosfero/plugin/organization_ratings/new_rating - And I click on anything with selector "#comments-additional-information" + And I sleep for 1 seconds + And I click on anything with selector "comments-additional-information" And I fill in "input_institution" with "None institution" And I sleep for 2 seconds - When I click on anything with selector "#create_institution_link" + When I click on anything with selector "create_institution_link" And I fill in "community_name" with "Noosfero Institution" - And I select "United States" from "#community_country" - And I follow "#save_institution_button" + And I select "United States" from "Country" + And I sleep for 1 seconds + And I follow "Save" Then I should see "Noosfero Institution" @selenium Scenario: Check new institution name in the modal Given I go to /profile/noosfero/plugin/organization_ratings/new_rating - And I click on anything with selector "#comments-additional-information" + And I sleep for 1 seconds + And I click on anything with selector "comments-additional-information" And I fill in "input_institution" with "None institution" And I sleep for 2 seconds - When I click on anything with selector "#create_institution_link" - Then I should see "None Institution" within "community_name" - - - - - - + When I click on anything with selector "create_institution_link" + Then I should see "None institution" in "Corporate Name" field 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 be7ecfa..cb401d5 100644 --- a/src/noosfero-spb/gov_user/features/user_profile_edition.feature +++ b/src/noosfero-spb/gov_user/features/user_profile_edition.feature @@ -5,12 +5,15 @@ Feature: Institution Field Background: Given "GovUserPlugin" plugin is enabled + And "SoftwareCommunitiesPlugin" plugin is enabled And the following users | login | name | | joao | Joao Silva | And I am logged in as admin + And I go to /admin/environment_themes/set/noosfero-spb-theme And I go to /admin/plugins And I check "GovUserPlugin" + And I check "SoftwareCommunitiesPlugin" And I press "Save changes" And feature "skip_new_user_email_confirmation" is enabled on environment And I go to /admin/features/manage_fields @@ -25,12 +28,12 @@ Feature: Institution Field | 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 | + @selenium Scenario: Go to control panel when clicked on 'Complete your profile' link Given I am logged in as "joao" And I am on joao's control panel When I follow "Complete your profile" Then I should see "Profile settings for " - And I should see "Personal information" @selenium Scenario: Verify text information to use governmental e-mail @@ -44,13 +47,12 @@ Feature: Institution Field Given I am logged in as "joao" And I am on joao's control panel When I follow "Edit Profile" - And I follow "Add new institution" And I type in "Minis" in autocomplete list "#input_institution" and I choose "Ministerio do Planejamento" - And I follow "Add new institution" + And I follow "Add institution" And I type in "Gover" in autocomplete list "#input_institution" and I choose "Governo do DF" - And I follow "Add new institution" - Then I should see "Ministerio do Planejamento" within ".institutions_added" - And I should see "Governo do DF" within ".institutions_added" + And I follow "Add institution" + Then I should see "Ministerio do Planejamento" + And I should see "Governo do DF" @selenium Scenario: Verify if field 'city' is shown when Brazil is selected @@ -75,3 +77,14 @@ Feature: Institution Field And I fill in "input_institution" with "Some Nonexistent Institution" And I sleep for 1 seconds Then I should see "No institution found" + + @selenium + Scenario: Does not suggest institution that already exists + Given I am logged in as "joao" + And I am on joao's control panel + When I follow "Edit Profile" + And I type in "Minis" in autocomplete list "#input_institution" and I choose "Ministerio do Planejamento" + And I follow "Add institution" + And I fill in "input_institution" with "Minis" + And I sleep for 1 seconds + Then I should not see "Ministerio do Planejamento" within "ul.ui-autocomplete" diff --git a/src/noosfero-spb/gov_user/lib/private_institution.rb b/src/noosfero-spb/gov_user/lib/private_institution.rb index 24028d8..9f6792d 100644 --- a/src/noosfero-spb/gov_user/lib/private_institution.rb +++ b/src/noosfero-spb/gov_user/lib/private_institution.rb @@ -1,11 +1,10 @@ class PrivateInstitution < Institution validates :cnpj, - :presence=>true, :format => {with: CNPJ_FORMAT}, :if => :is_a_brazilian_institution? validates :cnpj, - :uniqueness=>true, :unless => 'cnpj.blank?' + :uniqueness => true, :unless => 'cnpj.blank?' private def is_a_brazilian_institution? diff --git a/src/noosfero-spb/gov_user/lib/public_institution.rb b/src/noosfero-spb/gov_user/lib/public_institution.rb index 8f9dd6a..9e49a70 100644 --- a/src/noosfero-spb/gov_user/lib/public_institution.rb +++ b/src/noosfero-spb/gov_user/lib/public_institution.rb @@ -1,6 +1,6 @@ class PublicInstitution < Institution validates :governmental_power, :governmental_sphere, :juridical_nature, - :presence=>true + :presence=>true, :unless=>lambda{self.community.country != "BR"} validates :cnpj, :format => {with: CNPJ_FORMAT}, 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 2e92e92..8416ac1 100644 --- a/src/noosfero-spb/gov_user/public/views/create-institution.js +++ b/src/noosfero-spb/gov_user/public/views/create-institution.js @@ -202,12 +202,13 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] $.ajax({ type: "GET", url: AJAX_URL.get_institutions, - data: {query: request.term}, + data: {query: request.term, selected_institutions: get_selected_institutions()}, success: function(result){ response(result); if( result.length === 0 ) { $('#institution_empty_ajax_message').switchClass("hide-field", "show-field"); + $('#add_institution_link').hide(); toggle_extra_fields_style_status(true); $("#institution_modal").css({display: "none"}); } @@ -222,12 +223,22 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] select : function (event, selected) { $('#institution_empty_ajax_message').switchClass("show-field", "hide-field"); - //$("#create_institution_link").remove(); + $('#add_institution_link').show(); toggle_extra_fields_style_status(false); $("#institution_selected").val(selected.item.id).attr("data-name", selected.item.label); } }); } + + function get_selected_institutions() { + var selected_institutions = [] + $('.institutions_added').find('li').each(function() { + selected_institutions.push($(this).attr('data-institution')); + }); + + return selected_institutions; + } + function add_selected_institution_to_list(id, name) { var selected_institution = "
  • "+name; selected_institution += "
  • "; @@ -246,6 +257,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] // Visualy add the selected institution to the list add_selected_institution_to_list(selected.val(), selected.attr("data-name")); + $(this).hide(); // clean the institution flag selected.val("").attr("data-name", ""); @@ -311,7 +323,6 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] 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(); @@ -323,6 +334,10 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] $('#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()); @@ -379,7 +394,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] $("#community_name").keyup(institution_already_exists); - $("#add_new_institution").click(add_new_institution); + $("#add_institution_link").click(add_new_institution); $(".remove-institution").click(remove_institution); 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 0829b08..56ee856 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 @@ -105,9 +105,9 @@ class GovUserPluginControllerTest < ActionController::TestCase fields = InstitutionTestHelper.generate_form_fields( "Some Private Institution", - "BR", - "DF", - "Brasilia", + "EN", + "NY", + "New York", "", "PrivateInstitution" ) diff --git a/src/noosfero-spb/gov_user/test/unit/gov_user_person_test.rb b/src/noosfero-spb/gov_user/test/unit/gov_user_person_test.rb index 0c58478..f22d80c 100644 --- a/src/noosfero-spb/gov_user/test/unit/gov_user_person_test.rb +++ b/src/noosfero-spb/gov_user/test/unit/gov_user_person_test.rb @@ -14,7 +14,6 @@ class SoftwareCommunitiesPluginPersonTest < ActiveSupport::TestCase "My Name", "user@email.com", "123456", - "123456", "user2@email.com", "Any State", "Some City" diff --git a/src/noosfero-spb/gov_user/test/unit/organization_rating_test.rb b/src/noosfero-spb/gov_user/test/unit/organization_rating_test.rb index 748355f..50c8731 100644 --- a/src/noosfero-spb/gov_user/test/unit/organization_rating_test.rb +++ b/src/noosfero-spb/gov_user/test/unit/organization_rating_test.rb @@ -16,15 +16,14 @@ class OrganizationRatingTest < ActiveSupport::TestCase private_institution = build_private_institution "huehue", "hue", "11.222.333/4444-55" community_rating = OrganizationRating.new(:person => person, :value => 3, :organization => community, :institution => private_institution) - assert_equal false, community_rating.valid? - assert_equal true, community_rating.errors[:institution].include?("not found") + assert_equal false, community_rating.valid? private_institution.save community_rating.institution = private_institution assert_equal true, community_rating.valid? - assert_equal false, community_rating.errors[:institution].include?("not found") + assert_equal false, community_rating.errors[:institution].include?("institution not found") end private diff --git a/src/noosfero-spb/gov_user/views/person_editor_extras.html.erb b/src/noosfero-spb/gov_user/views/person_editor_extras.html.erb index 7c404e7..43855dd 100644 --- a/src/noosfero-spb/gov_user/views/person_editor_extras.html.erb +++ b/src/noosfero-spb/gov_user/views/person_editor_extras.html.erb @@ -3,6 +3,7 @@
    <%= text_field_tag(:institution, "", :id=>"input_institution") %> + <%= link_to(_("Add institution"), "#", :class=>'button with-text icon-add', :id => 'add_institution_link') %> <% context.profile.user.institutions.each do |institution| %> <%= hidden_field_tag("user[institution_ids][]", institution.id, :class => 'user_institutions') %> 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 e6bd128..b1c9c5d 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 @@ -18,29 +18,6 @@ Given /^SoftwareInfo has initial default values on database$/ do OperatingSystemName.create(:name=>"CentOS") 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 /^I type in "([^"]*)" in autocomplete list "([^"]*)" and I choose "([^"]*)"$/ do |typed, input_field_selector, should_select| # Wait the page javascript load sleep 1 @@ -297,6 +274,10 @@ Then /^there should be (\d+) divs? with class "([^"]*)"$/ do |count, klass| should have_selector("div.#{klass}", :count => count) end +Then /^I should see "([^"]*)" in "([^"]*)" field$/ do |content, field| + should have_field(field, :with => content) +end + Given /^I should see "([^"]*)" in the page/ do |message| assert_match message, page.body end diff --git a/src/noosfero-spb/software_communities/test/unit/software_info_test.rb b/src/noosfero-spb/software_communities/test/unit/software_info_test.rb index a99ca50..a008a6d 100644 --- a/src/noosfero-spb/software_communities/test/unit/software_info_test.rb +++ b/src/noosfero-spb/software_communities/test/unit/software_info_test.rb @@ -52,7 +52,7 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase assert_equal 1, SoftwareInfo.search_by_query("", Environment.default).count assert_equal software_info, SoftwareInfo.search_by_query("", Environment.default).first assert_equal 1, SoftwareInfo.search_by_query("", other_env).count - assert_equal true, SoftwareInfo.search_by_query("", other_env).include?(another_software_info) + assert_equal true, SoftwareInfo.search_by_query("", other_env).all.include?(another_software_info) end should "start another license with default values" do -- libgit2 0.21.2