Commit 76e5cf98ca302ed6d1aab487c4597d444c64490c
1 parent
c550c104
Exists in
master
and in
17 other branches
Fixes unit and integration tests
- Fix validations Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> Signed-off-by: Gustavo Coelho <gust.rod.coelho@gmail.com> Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com> Signed-off-by: Omar Junior <omarroinuj@gmail.com> Signed-off-by: Pedro de Lyra <pedrodelyra@gmail.com> Signed-off-by: Tallys Martins <tallysmartins@yahoo.com.br> Signed-off-by: Thiago Ribeiro <thiagitosouza@gmail.com>
Showing
14 changed files
with
81 additions
and
71 deletions
Show diff stats
src/noosfero-spb/gov_user/controllers/gov_user_plugin_controller.rb
... | ... | @@ -65,7 +65,9 @@ class GovUserPluginController < ApplicationController |
65 | 65 | def get_institutions |
66 | 66 | redirect_to "/" if !request.xhr? || params[:query].blank? |
67 | 67 | |
68 | + selected_institutions = Institution.where(id: params[:selected_institutions]).select([:id, :name]) | |
68 | 69 | institutions = Institution.search_institution(params[:query]).select([:id, :name]) |
70 | + institutions -= selected_institutions | |
69 | 71 | institutions_list = institutions.map { |institution| |
70 | 72 | {:value=>institution.name, :id=>institution.id} |
71 | 73 | } | ... | ... |
src/noosfero-spb/gov_user/features/institution_registration.feature
... | ... | @@ -5,9 +5,12 @@ Feature: Institution Field |
5 | 5 | |
6 | 6 | Background: |
7 | 7 | Given "GovUserPlugin" plugin is enabled |
8 | + And "SoftwareCommunitiesPlugin" plugin is enabled | |
8 | 9 | And I am logged in as mpog_admin |
10 | + And I go to /admin/environment_themes/set/noosfero-spb-theme | |
9 | 11 | And I go to /admin/plugins |
10 | 12 | And I check "GovUserPlugin" |
13 | + And I check "SoftwareCommunitiesPlugin" | |
11 | 14 | And I press "Save changes" |
12 | 15 | And Institutions has initial default values on database |
13 | 16 | And I am logged in as mpog_admin |
... | ... | @@ -27,6 +30,6 @@ Feature: Institution Field |
27 | 30 | And I should see "CNPJ" |
28 | 31 | And I should see "Acronym" |
29 | 32 | And I choose "Public Institution" |
30 | - Then I should see "Governmental Sphere:" | |
31 | - And I should see "Governmental Power:" | |
32 | - And I should see "Juridical Nature:" | |
33 | + Then I should see "Governmental Sphere" | |
34 | + And I should see "Governmental Power" | |
35 | + And I should see "Juridical Nature" | ... | ... |
src/noosfero-spb/gov_user/features/rate_community.feature
... | ... | @@ -38,7 +38,7 @@ Feature: rate_community |
38 | 38 | And I go to mycommunity's control panel |
39 | 39 | And I follow "Process requests" within ".pending-tasks" |
40 | 40 | And I choose "Accept" within ".task_decisions" |
41 | - Then I should see "This instiution already has an accepted rating" in the page | |
41 | + Then I should see "This institution already has an accepted rating." in the page | |
42 | 42 | |
43 | 43 | Scenario: do not display message on task when a rating with the same institution does not exist on the same software |
44 | 44 | Given the following organization ratings | ... | ... |
src/noosfero-spb/gov_user/features/rating_institution_registration.feature
... | ... | @@ -8,6 +8,7 @@ Feature: Create institution on user report |
8 | 8 | And "SoftwareCommunitiesPlugin" plugin is enabled |
9 | 9 | And "OrganizationRatings" plugin is enabled |
10 | 10 | And I am logged in as mpog_admin |
11 | + And I go to /admin/environment_themes/set/noosfero-spb-theme | |
11 | 12 | And I go to /admin/plugins |
12 | 13 | And I check "GovUserPlugin" |
13 | 14 | And I check "SoftwareCommunitiesPlugin" |
... | ... | @@ -23,20 +24,20 @@ Feature: Create institution on user report |
23 | 24 | And I should not see "Number of Beneficiaries" |
24 | 25 | And I should not see "Saved resources" |
25 | 26 | And I should not see "Organization name or Enterprise name" |
26 | - When I click on anything with selector "#comments-additional-information" | |
27 | - Then I should see "Number of Beneficiaries" | |
28 | - And I should see "Organization name or Enterprise name" | |
29 | - And I should see "Saved resources" | |
27 | + When I click on anything with selector "comments-additional-information" | |
28 | + Then I should see "Número de beneficiados" | |
29 | + And I should see "Nome do órgão ou empresa" | |
30 | + And I should see "Recursos economizados" | |
30 | 31 | |
31 | 32 | @selenium |
32 | 33 | Scenario: Show new institution fields when clicked in add new institution |
33 | 34 | Given I go to /profile/noosfero/plugin/organization_ratings/new_rating |
34 | - And I click on anything with selector "#comments-additional-information" | |
35 | + And I sleep for 1 seconds | |
36 | + And I click on anything with selector "comments-additional-information" | |
35 | 37 | And I fill in "input_institution" with "None institution" |
36 | 38 | And I sleep for 2 seconds |
37 | 39 | When I follow "Add" |
38 | - Then I should see "New Institution" | |
39 | - And I should see "Public Institution" | |
40 | + Then I should see "Public Institution" | |
40 | 41 | And I should see "Private Institution" |
41 | 42 | And I should see "Corporate Name" |
42 | 43 | And I should see "Name" |
... | ... | @@ -46,33 +47,30 @@ Feature: Create institution on user report |
46 | 47 | And I should see "CNPJ" |
47 | 48 | And I should see "Acronym" |
48 | 49 | And I choose "Public Institution" |
49 | - And I should see "Governmental Sphere:" | |
50 | - And I should see "Governmental Power:" | |
51 | - And I should see "Juridical Nature:" | |
50 | + And I should see "Governmental Sphere" | |
51 | + And I should see "Governmental Power" | |
52 | + And I should see "Juridical Nature" | |
52 | 53 | |
53 | 54 | @selenium |
54 | 55 | Scenario: Create new institution with name changed in the modal |
55 | 56 | Given I go to /profile/noosfero/plugin/organization_ratings/new_rating |
56 | - And I click on anything with selector "#comments-additional-information" | |
57 | + And I sleep for 1 seconds | |
58 | + And I click on anything with selector "comments-additional-information" | |
57 | 59 | And I fill in "input_institution" with "None institution" |
58 | 60 | And I sleep for 2 seconds |
59 | - When I click on anything with selector "#create_institution_link" | |
61 | + When I click on anything with selector "create_institution_link" | |
60 | 62 | And I fill in "community_name" with "Noosfero Institution" |
61 | - And I select "United States" from "#community_country" | |
62 | - And I follow "#save_institution_button" | |
63 | + And I select "United States" from "Country" | |
64 | + And I sleep for 1 seconds | |
65 | + And I follow "Save" | |
63 | 66 | Then I should see "Noosfero Institution" |
64 | 67 | |
65 | 68 | @selenium |
66 | 69 | Scenario: Check new institution name in the modal |
67 | 70 | Given I go to /profile/noosfero/plugin/organization_ratings/new_rating |
68 | - And I click on anything with selector "#comments-additional-information" | |
71 | + And I sleep for 1 seconds | |
72 | + And I click on anything with selector "comments-additional-information" | |
69 | 73 | And I fill in "input_institution" with "None institution" |
70 | 74 | And I sleep for 2 seconds |
71 | - When I click on anything with selector "#create_institution_link" | |
72 | - Then I should see "None Institution" within "community_name" | |
73 | - | |
74 | - | |
75 | - | |
76 | - | |
77 | - | |
78 | - | |
75 | + When I click on anything with selector "create_institution_link" | |
76 | + Then I should see "None institution" in "Corporate Name" field | ... | ... |
src/noosfero-spb/gov_user/features/user_profile_edition.feature
... | ... | @@ -5,12 +5,15 @@ Feature: Institution Field |
5 | 5 | |
6 | 6 | Background: |
7 | 7 | Given "GovUserPlugin" plugin is enabled |
8 | + And "SoftwareCommunitiesPlugin" plugin is enabled | |
8 | 9 | And the following users |
9 | 10 | | login | name | |
10 | 11 | | joao | Joao Silva | |
11 | 12 | And I am logged in as admin |
13 | + And I go to /admin/environment_themes/set/noosfero-spb-theme | |
12 | 14 | And I go to /admin/plugins |
13 | 15 | And I check "GovUserPlugin" |
16 | + And I check "SoftwareCommunitiesPlugin" | |
14 | 17 | And I press "Save changes" |
15 | 18 | And feature "skip_new_user_email_confirmation" is enabled on environment |
16 | 19 | And I go to /admin/features/manage_fields |
... | ... | @@ -25,12 +28,12 @@ Feature: Institution Field |
25 | 28 | | Governo do DF | GDF | BR | DF | Taguatinga | 12.645.166/0001-44 | Autarquia | Legislativo | Federal | Governo do DF | |
26 | 29 | | Ministerio do Planejamento | MP | BR | DF | Brasilia | 41.769.591/0001-43 | Autarquia | Judiciario | Federal | Ministerio do Planejamento | |
27 | 30 | |
31 | + @selenium | |
28 | 32 | Scenario: Go to control panel when clicked on 'Complete your profile' link |
29 | 33 | Given I am logged in as "joao" |
30 | 34 | And I am on joao's control panel |
31 | 35 | When I follow "Complete your profile" |
32 | 36 | Then I should see "Profile settings for " |
33 | - And I should see "Personal information" | |
34 | 37 | |
35 | 38 | @selenium |
36 | 39 | Scenario: Verify text information to use governmental e-mail |
... | ... | @@ -44,13 +47,12 @@ Feature: Institution Field |
44 | 47 | Given I am logged in as "joao" |
45 | 48 | And I am on joao's control panel |
46 | 49 | When I follow "Edit Profile" |
47 | - And I follow "Add new institution" | |
48 | 50 | And I type in "Minis" in autocomplete list "#input_institution" and I choose "Ministerio do Planejamento" |
49 | - And I follow "Add new institution" | |
51 | + And I follow "Add institution" | |
50 | 52 | And I type in "Gover" in autocomplete list "#input_institution" and I choose "Governo do DF" |
51 | - And I follow "Add new institution" | |
52 | - Then I should see "Ministerio do Planejamento" within ".institutions_added" | |
53 | - And I should see "Governo do DF" within ".institutions_added" | |
53 | + And I follow "Add institution" | |
54 | + Then I should see "Ministerio do Planejamento" | |
55 | + And I should see "Governo do DF" | |
54 | 56 | |
55 | 57 | @selenium |
56 | 58 | Scenario: Verify if field 'city' is shown when Brazil is selected |
... | ... | @@ -75,3 +77,14 @@ Feature: Institution Field |
75 | 77 | And I fill in "input_institution" with "Some Nonexistent Institution" |
76 | 78 | And I sleep for 1 seconds |
77 | 79 | Then I should see "No institution found" |
80 | + | |
81 | + @selenium | |
82 | + Scenario: Does not suggest institution that already exists | |
83 | + Given I am logged in as "joao" | |
84 | + And I am on joao's control panel | |
85 | + When I follow "Edit Profile" | |
86 | + And I type in "Minis" in autocomplete list "#input_institution" and I choose "Ministerio do Planejamento" | |
87 | + And I follow "Add institution" | |
88 | + And I fill in "input_institution" with "Minis" | |
89 | + And I sleep for 1 seconds | |
90 | + Then I should not see "Ministerio do Planejamento" within "ul.ui-autocomplete" | ... | ... |
src/noosfero-spb/gov_user/lib/private_institution.rb
1 | 1 | class PrivateInstitution < Institution |
2 | 2 | validates :cnpj, |
3 | - :presence=>true, | |
4 | 3 | :format => {with: CNPJ_FORMAT}, |
5 | 4 | :if => :is_a_brazilian_institution? |
6 | 5 | |
7 | 6 | validates :cnpj, |
8 | - :uniqueness=>true, :unless => 'cnpj.blank?' | |
7 | + :uniqueness => true, :unless => 'cnpj.blank?' | |
9 | 8 | |
10 | 9 | private |
11 | 10 | def is_a_brazilian_institution? | ... | ... |
src/noosfero-spb/gov_user/lib/public_institution.rb
src/noosfero-spb/gov_user/public/views/create-institution.js
... | ... | @@ -202,12 +202,13 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
202 | 202 | $.ajax({ |
203 | 203 | type: "GET", |
204 | 204 | url: AJAX_URL.get_institutions, |
205 | - data: {query: request.term}, | |
205 | + data: {query: request.term, selected_institutions: get_selected_institutions()}, | |
206 | 206 | success: function(result){ |
207 | 207 | response(result); |
208 | 208 | |
209 | 209 | if( result.length === 0 ) { |
210 | 210 | $('#institution_empty_ajax_message').switchClass("hide-field", "show-field"); |
211 | + $('#add_institution_link').hide(); | |
211 | 212 | toggle_extra_fields_style_status(true); |
212 | 213 | $("#institution_modal").css({display: "none"}); |
213 | 214 | } |
... | ... | @@ -222,12 +223,22 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
222 | 223 | |
223 | 224 | select : function (event, selected) { |
224 | 225 | $('#institution_empty_ajax_message').switchClass("show-field", "hide-field"); |
225 | - //$("#create_institution_link").remove(); | |
226 | + $('#add_institution_link').show(); | |
226 | 227 | toggle_extra_fields_style_status(false); |
227 | 228 | $("#institution_selected").val(selected.item.id).attr("data-name", selected.item.label); |
228 | 229 | } |
229 | 230 | }); |
230 | 231 | } |
232 | + | |
233 | + function get_selected_institutions() { | |
234 | + var selected_institutions = [] | |
235 | + $('.institutions_added').find('li').each(function() { | |
236 | + selected_institutions.push($(this).attr('data-institution')); | |
237 | + }); | |
238 | + | |
239 | + return selected_institutions; | |
240 | + } | |
241 | + | |
231 | 242 | function add_selected_institution_to_list(id, name) { |
232 | 243 | var selected_institution = "<li data-institution='"+id+"'>"+name; |
233 | 244 | selected_institution += "<a href='#' class='button without-text icon-remove remove-institution'></a></li>"; |
... | ... | @@ -246,6 +257,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
246 | 257 | |
247 | 258 | // Visualy add the selected institution to the list |
248 | 259 | add_selected_institution_to_list(selected.val(), selected.attr("data-name")); |
260 | + $(this).hide(); | |
249 | 261 | |
250 | 262 | // clean the institution flag |
251 | 263 | selected.val("").attr("data-name", ""); |
... | ... | @@ -311,7 +323,6 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
311 | 323 | var divisor_option = SelectElement.generateOption("-1", "--------------------------------"); |
312 | 324 | var default_option = SelectElement.generateOption("BR", "Brazil"); |
313 | 325 | |
314 | - | |
315 | 326 | var inst_type = $("input[name='institutions[type]']:checked").val(); |
316 | 327 | var country = $("#community_country").val(); |
317 | 328 | |
... | ... | @@ -323,6 +334,10 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
323 | 334 | $('#community_country').prepend(divisor_option); |
324 | 335 | $('#community_country').prepend(default_option); |
325 | 336 | |
337 | + if ($('#add_institution_link').length > 0) { | |
338 | + $('#add_institution_link').hide(); | |
339 | + } | |
340 | + | |
326 | 341 | if($("#edit_institution_page").val() === "false") { |
327 | 342 | $('#community_country').val("BR"); |
328 | 343 | show_hide_cnpj_city($('#community_country').val()); |
... | ... | @@ -379,7 +394,7 @@ modulejs.define('CreateInstitution', ['jquery', 'NoosferoRoot', 'SelectElement'] |
379 | 394 | |
380 | 395 | $("#community_name").keyup(institution_already_exists); |
381 | 396 | |
382 | - $("#add_new_institution").click(add_new_institution); | |
397 | + $("#add_institution_link").click(add_new_institution); | |
383 | 398 | |
384 | 399 | $(".remove-institution").click(remove_institution); |
385 | 400 | ... | ... |
src/noosfero-spb/gov_user/test/functional/gov_user_plugin_controller_test.rb
... | ... | @@ -105,9 +105,9 @@ class GovUserPluginControllerTest < ActionController::TestCase |
105 | 105 | |
106 | 106 | fields = InstitutionTestHelper.generate_form_fields( |
107 | 107 | "Some Private Institution", |
108 | - "BR", | |
109 | - "DF", | |
110 | - "Brasilia", | |
108 | + "EN", | |
109 | + "NY", | |
110 | + "New York", | |
111 | 111 | "", |
112 | 112 | "PrivateInstitution" |
113 | 113 | ) | ... | ... |
src/noosfero-spb/gov_user/test/unit/gov_user_person_test.rb
src/noosfero-spb/gov_user/test/unit/organization_rating_test.rb
... | ... | @@ -16,15 +16,14 @@ class OrganizationRatingTest < ActiveSupport::TestCase |
16 | 16 | private_institution = build_private_institution "huehue", "hue", "11.222.333/4444-55" |
17 | 17 | |
18 | 18 | community_rating = OrganizationRating.new(:person => person, :value => 3, :organization => community, :institution => private_institution) |
19 | - assert_equal false, community_rating.valid? | |
20 | 19 | |
21 | - assert_equal true, community_rating.errors[:institution].include?("not found") | |
20 | + assert_equal false, community_rating.valid? | |
22 | 21 | |
23 | 22 | private_institution.save |
24 | 23 | community_rating.institution = private_institution |
25 | 24 | |
26 | 25 | assert_equal true, community_rating.valid? |
27 | - assert_equal false, community_rating.errors[:institution].include?("not found") | |
26 | + assert_equal false, community_rating.errors[:institution].include?("institution not found") | |
28 | 27 | end |
29 | 28 | |
30 | 29 | private | ... | ... |
src/noosfero-spb/gov_user/views/person_editor_extras.html.erb
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | |
4 | 4 | <div class="institution_container"> |
5 | 5 | <%= text_field_tag(:institution, "", :id=>"input_institution") %> |
6 | + <%= link_to(_("Add institution"), "#", :class=>'button with-text icon-add', :id => 'add_institution_link') %> | |
6 | 7 | |
7 | 8 | <% context.profile.user.institutions.each do |institution| %> |
8 | 9 | <%= hidden_field_tag("user[institution_ids][]", institution.id, :class => 'user_institutions') %> | ... | ... |
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 |
18 | 18 | OperatingSystemName.create(:name=>"CentOS") |
19 | 19 | end |
20 | 20 | |
21 | -Given /^Institutions has initial default values on database$/ do | |
22 | - GovernmentalPower.create(:name => "Executivo") | |
23 | - GovernmentalPower.create(:name => "Legislativo") | |
24 | - GovernmentalPower.create(:name => "Judiciario") | |
25 | - | |
26 | - GovernmentalSphere.create(:name => "Federal") | |
27 | - | |
28 | - JuridicalNature.create(:name => "Autarquia") | |
29 | - JuridicalNature.create(:name => "Administracao Direta") | |
30 | - JuridicalNature.create(:name => "Empresa Publica") | |
31 | - JuridicalNature.create(:name => "Fundacao") | |
32 | - JuridicalNature.create(:name => "Orgao Autonomo") | |
33 | - JuridicalNature.create(:name => "Sociedade") | |
34 | - JuridicalNature.create(:name => "Sociedade Civil") | |
35 | - JuridicalNature.create(:name => "Sociedade de Economia Mista") | |
36 | - | |
37 | - national_region = NationalRegion.new | |
38 | - national_region.name = "Distrito Federal" | |
39 | - national_region.national_region_code = '35' | |
40 | - national_region.national_region_type_id = NationalRegionType::STATE | |
41 | - national_region.save | |
42 | -end | |
43 | - | |
44 | 21 | Given /^I type in "([^"]*)" in autocomplete list "([^"]*)" and I choose "([^"]*)"$/ do |typed, input_field_selector, should_select| |
45 | 22 | # Wait the page javascript load |
46 | 23 | sleep 1 |
... | ... | @@ -297,6 +274,10 @@ Then /^there should be (\d+) divs? with class "([^"]*)"$/ do |count, klass| |
297 | 274 | should have_selector("div.#{klass}", :count => count) |
298 | 275 | end |
299 | 276 | |
277 | +Then /^I should see "([^"]*)" in "([^"]*)" field$/ do |content, field| | |
278 | + should have_field(field, :with => content) | |
279 | +end | |
280 | + | |
300 | 281 | Given /^I should see "([^"]*)" in the page/ do |message| |
301 | 282 | assert_match message, page.body |
302 | 283 | end | ... | ... |
src/noosfero-spb/software_communities/test/unit/software_info_test.rb
... | ... | @@ -52,7 +52,7 @@ class SoftwareInfoValidationTest < ActiveSupport::TestCase |
52 | 52 | assert_equal 1, SoftwareInfo.search_by_query("", Environment.default).count |
53 | 53 | assert_equal software_info, SoftwareInfo.search_by_query("", Environment.default).first |
54 | 54 | assert_equal 1, SoftwareInfo.search_by_query("", other_env).count |
55 | - assert_equal true, SoftwareInfo.search_by_query("", other_env).include?(another_software_info) | |
55 | + assert_equal true, SoftwareInfo.search_by_query("", other_env).all.include?(another_software_info) | |
56 | 56 | end |
57 | 57 | |
58 | 58 | should "start another license with default values" do | ... | ... |