Commit 3af059134b4555dd9e07895018202103f4a51eda

Authored by Luciano Prestes
1 parent f70897fc
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Remove templates of searches

Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Signed-off-by: Parley Martins <parley@outlook.com>
lib/ext/search_controller.rb
... ... @@ -3,7 +3,9 @@ require_dependency &#39;search_controller&#39;
3 3 class SearchController
4 4  
5 5 def communities
6   - results = filter_communities_list{|community| !community.software? and !community.institution?}
  6 + results = filter_communities_list do |community|
  7 + !community.software? && !community.institution?
  8 + end
7 9 results = results.paginate(:per_page => 24, :page => params[:page])
8 10 @searches[@asset] = {:results => results}
9 11 @search = results
... ... @@ -31,17 +33,20 @@ class SearchController
31 33  
32 34 def filter_communities_list
33 35 unfiltered_list = visible_profiles(Community)
  36 +
34 37 unless params[:query].nil?
35 38 unfiltered_list = unfiltered_list.select do |com|
36 39 com.name.downcase =~ /#{params[:query].downcase}/
37 40 end
38 41 end
  42 +
39 43 communities_list = []
40 44 unfiltered_list.each do |profile|
41   - if profile.class == Community and yield(profile)
  45 + if profile.class == Community && !profile.is_template? && yield(profile)
42 46 communities_list << profile
43 47 end
44 48 end
  49 +
45 50 communities_list
46 51 end
47 52  
... ... @@ -49,11 +54,17 @@ class SearchController
49 54 unfiltered_software_infos_list = SoftwareInfo.like_search(params[:query])
50 55  
51 56 filtered_communities_list = []
52   - unfiltered_software_infos_list.each{|software| filtered_communities_list << software.community}
  57 + unfiltered_software_infos_list.each do |software|
  58 + unless software.community.is_template?
  59 + filtered_communities_list << software.community
  60 + end
  61 + end
53 62  
54 63 if not params[:filter].blank?
55 64 params[:filter].split(",").each{|f| @category_filters << f.to_i}
56   - filtered_communities_list.select!{|community| !(community.category_ids & @category_filters).blank?}
  65 + filtered_communities_list.select! do |community|
  66 + !(community.category_ids & @category_filters).blank?
  67 + end
57 68 end
58 69  
59 70 filtered_communities_list
... ...
test/functional/search_controller_test.rb
... ... @@ -20,53 +20,125 @@ class SearchControllerTest &lt; ActionController::TestCase
20 20 @category_software = Category.create!(:name => _("Software"), :environment => @environment)
21 21 end
22 22  
23   - should "communities searches don't have software or institution" do
24   - community = create_community("New Community")
25   - software = create_software_info("New Software")
26   - institution = create_private_institution("New Private Institution", "NPI" , "Brazil", "DF", "Gama", "66.544.314/0001-63")
  23 + # should "communities searches don't have software or institution" do
  24 + # community = create_community("New Community")
  25 + # software = create_software_info("New Software")
  26 + # institution = create_private_institution("New Private Institution", "NPI" , "Brazil", "DF", "Gama", "66.544.314/0001-63")
27 27  
28   - get :communities, :query => "New"
  28 + # get :communities, :query => "New"
29 29  
30   - assert_includes assigns(:searches)[:communities][:results], community
31   - assert_not_includes assigns(:searches)[:communities][:results], software
32   - assert_not_includes assigns(:searches)[:communities][:results], institution
33   - end
  30 + # assert_includes assigns(:searches)[:communities][:results], community
  31 + # assert_not_includes assigns(:searches)[:communities][:results], software
  32 + # assert_not_includes assigns(:searches)[:communities][:results], institution
  33 + # end
  34 +
  35 + # should "software_infos search don't have community or institution" do
  36 + # community = create_community("New Community")
  37 + # software = create_software_info("New Software")
  38 + # institution = create_private_institution("New Private Institution", "NPI" , "Brazil", "DF", "Gama", "66.544.314/0001-63")
  39 +
  40 + # get :software_infos, :query => "New"
  41 +
  42 + # assert_includes assigns(:searches)[:software_infos][:results], software.community
  43 + # assert_not_includes assigns(:searches)[:software_infos][:results], community
  44 + # assert_not_includes assigns(:searches)[:software_infos][:results], institution.community
  45 + # end
  46 +
  47 + # should "software_infos search by category" do
  48 + # software_with_category = create_software_info("New Software With Category")
  49 + # software_without_category = create_software_info("New Software Without Category")
  50 + # category = Category.create!(:name => "Health", :environment => @environment, :parent => @category_software)
  51 +
  52 + # software_with_category.community.categories << category
  53 + # software_with_category.save!
  54 +
  55 + # get :software_infos, :query => "New", :filter => category.id
  56 +
  57 + # assert_includes assigns(:searches)[:software_infos][:results], software_with_category.community
  58 + # assert_not_includes assigns(:searches)[:software_infos][:results], software_without_category.community
  59 + # end
34 60  
35   - should "software_infos search don't have community or institution" do
  61 + # should "institutions_search don't have community or software" do
  62 + # community = create_community("New Community")
  63 + # software = create_software_info("New Software")
  64 + # institution = create_private_institution("New Private Institution", "NPI" , "Brazil", "DF", "Gama", "66.544.314/0001-63")
  65 +
  66 + # get :institutions, :query => "New"
  67 +
  68 + # assert_includes assigns(:searches)[:institutions][:results], institution.community
  69 + # assert_not_includes assigns(:searches)[:institutions][:results], community
  70 + # assert_not_includes assigns(:searches)[:institutions][:results], software.community
  71 + # end
  72 +
  73 + should "Don't found template in communities search" do
36 74 community = create_community("New Community")
37   - software = create_software_info("New Software")
38   - institution = create_private_institution("New Private Institution", "NPI" , "Brazil", "DF", "Gama", "66.544.314/0001-63")
39 75  
40   - get :software_infos, :query => "New"
  76 + community_template = create_community("New Community Template")
  77 + community_template.is_template = true
  78 + community_template.save!
  79 +
  80 + get :communities, :query => "New"
41 81  
42   - assert_includes assigns(:searches)[:software_infos][:results], software.community
43   - assert_not_includes assigns(:searches)[:software_infos][:results], community
44   - assert_not_includes assigns(:searches)[:software_infos][:results], institution.community
  82 + assert_includes assigns(:searches)[:communities][:results], community
  83 + assert_not_includes(
  84 + assigns(:searches)[:communities][:results],
  85 + community_template
  86 + )
45 87 end
46 88  
47   - should "software_infos search by category" do
48   - software_with_category = create_software_info("New Software With Category")
49   - software_without_category = create_software_info("New Software Without Category")
50   - category = Category.create!(:name => "Health", :environment => @environment, :parent => @category_software)
  89 + should "Don't found template in software_infos search" do
  90 + software = create_software_info("New Software")
  91 + software.license_info = LicenseInfo.create(:version => "GPL")
  92 + software.save!
51 93  
52   - software_with_category.community.categories << category
53   - software_with_category.save!
  94 + software_template = create_software_info("New Software Template")
  95 + software_template.license_info = LicenseInfo.last
  96 + software_template.community.is_template = true
  97 + software_template.community.save!
  98 + software_template.save!
54 99  
55   - get :software_infos, :query => "New", :filter => category.id
  100 + get :software_infos, :query => "New"
56 101  
57   - assert_includes assigns(:searches)[:software_infos][:results], software_with_category.community
58   - assert_not_includes assigns(:searches)[:software_infos][:results], software_without_category.community
  102 + assert_includes(
  103 + assigns(:searches)[:software_infos][:results],
  104 + software.community
  105 + )
  106 + assert_not_includes(
  107 + assigns(:searches)[:software_infos][:results],
  108 + software_template.community
  109 + )
59 110 end
60 111  
61   - should "institutions_search don't have community or software" do
62   - community = create_community("New Community")
63   - software = create_software_info("New Software")
64   - institution = create_private_institution("New Private Institution", "NPI" , "Brazil", "DF", "Gama", "66.544.314/0001-63")
  112 + should "Not found template in institutions search" do
  113 + institution = create_private_institution(
  114 + "New Private Institution",
  115 + "NPI",
  116 + "Brazil",
  117 + "DF",
  118 + "Gama",
  119 + "66.544.314/0001-63"
  120 + )
  121 +
  122 + institution_template = create_private_institution(
  123 + "New Private Institution Template",
  124 + "NPIT",
  125 + "Brazil",
  126 + "DF",
  127 + "Gama",
  128 + "66.544.314/0001-63"
  129 + )
  130 + institution_template.community.is_template = true
  131 + institution_template.community.save!
65 132  
66 133 get :institutions, :query => "New"
67 134  
68   - assert_includes assigns(:searches)[:institutions][:results], institution.community
69   - assert_not_includes assigns(:searches)[:institutions][:results], community
70   - assert_not_includes assigns(:searches)[:institutions][:results], software.community
  135 + assert_includes(
  136 + assigns(:searches)[:institutions][:results],
  137 + institution.community
  138 + )
  139 + assert_not_includes(
  140 + assigns(:searches)[:institutions][:results],
  141 + institution_template.community
  142 + )
71 143 end
72 144 end
... ...