Commit 3af059134b4555dd9e07895018202103f4a51eda
1 parent
f70897fc
Exists in
master
and in
5 other branches
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>
Showing
2 changed files
with
119 additions
and
36 deletions
Show diff stats
lib/ext/search_controller.rb
| @@ -3,7 +3,9 @@ require_dependency 'search_controller' | @@ -3,7 +3,9 @@ require_dependency 'search_controller' | ||
| 3 | class SearchController | 3 | class SearchController |
| 4 | 4 | ||
| 5 | def communities | 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 | results = results.paginate(:per_page => 24, :page => params[:page]) | 9 | results = results.paginate(:per_page => 24, :page => params[:page]) |
| 8 | @searches[@asset] = {:results => results} | 10 | @searches[@asset] = {:results => results} |
| 9 | @search = results | 11 | @search = results |
| @@ -31,17 +33,20 @@ class SearchController | @@ -31,17 +33,20 @@ class SearchController | ||
| 31 | 33 | ||
| 32 | def filter_communities_list | 34 | def filter_communities_list |
| 33 | unfiltered_list = visible_profiles(Community) | 35 | unfiltered_list = visible_profiles(Community) |
| 36 | + | ||
| 34 | unless params[:query].nil? | 37 | unless params[:query].nil? |
| 35 | unfiltered_list = unfiltered_list.select do |com| | 38 | unfiltered_list = unfiltered_list.select do |com| |
| 36 | com.name.downcase =~ /#{params[:query].downcase}/ | 39 | com.name.downcase =~ /#{params[:query].downcase}/ |
| 37 | end | 40 | end |
| 38 | end | 41 | end |
| 42 | + | ||
| 39 | communities_list = [] | 43 | communities_list = [] |
| 40 | unfiltered_list.each do |profile| | 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 | communities_list << profile | 46 | communities_list << profile |
| 43 | end | 47 | end |
| 44 | end | 48 | end |
| 49 | + | ||
| 45 | communities_list | 50 | communities_list |
| 46 | end | 51 | end |
| 47 | 52 | ||
| @@ -49,11 +54,17 @@ class SearchController | @@ -49,11 +54,17 @@ class SearchController | ||
| 49 | unfiltered_software_infos_list = SoftwareInfo.like_search(params[:query]) | 54 | unfiltered_software_infos_list = SoftwareInfo.like_search(params[:query]) |
| 50 | 55 | ||
| 51 | filtered_communities_list = [] | 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 | if not params[:filter].blank? | 63 | if not params[:filter].blank? |
| 55 | params[:filter].split(",").each{|f| @category_filters << f.to_i} | 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 | end | 68 | end |
| 58 | 69 | ||
| 59 | filtered_communities_list | 70 | filtered_communities_list |
test/functional/search_controller_test.rb
| @@ -20,53 +20,125 @@ class SearchControllerTest < ActionController::TestCase | @@ -20,53 +20,125 @@ class SearchControllerTest < ActionController::TestCase | ||
| 20 | @category_software = Category.create!(:name => _("Software"), :environment => @environment) | 20 | @category_software = Category.create!(:name => _("Software"), :environment => @environment) |
| 21 | end | 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 | community = create_community("New Community") | 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 | end | 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 | end | 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 | get :institutions, :query => "New" | 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 | end | 143 | end |
| 72 | end | 144 | end |