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 = "