Commit ce3b9daa65e92213f91da43524959f7648f74361

Authored by Luciano Prestes
1 parent 211d2087

Fix bug on filter communities

lib/ext/communities_block.rb
@@ -4,10 +4,6 @@ class CommunitiesBlock @@ -4,10 +4,6 @@ class CommunitiesBlock
4 4
5 def profile_list 5 def profile_list
6 result = get_visible_profiles 6 result = get_visible_profiles
7 - valid_communities_string = Community.get_valid_communities_string  
8 -  
9 - result.each{|community| result.delete(community) unless eval(valid_communities_string)}  
10 -  
11 result.slice(0..get_limit-1) 7 result.slice(0..get_limit-1)
12 end 8 end
13 9
@@ -21,6 +17,13 @@ class CommunitiesBlock @@ -21,6 +17,13 @@ class CommunitiesBlock
21 visible_profiles = profiles.visible.includes( 17 visible_profiles = profiles.visible.includes(
22 [:image,:domains,:preferred_domain,:environment] 18 [:image,:domains,:preferred_domain,:environment]
23 ) 19 )
  20 +
  21 + delete_communities = []
  22 + valid_communities_string = Community.get_valid_communities_string
  23 + Community.all.each{|community| delete_communities << community.id unless eval(valid_communities_string)}
  24 +
  25 + visible_profiles = visible_profiles.where(["profiles.id NOT IN (?)", delete_communities])
  26 +
24 if !prioritize_profiles_with_image 27 if !prioritize_profiles_with_image
25 return visible_profiles.all( 28 return visible_profiles.all(
26 :limit => get_limit, 29 :limit => get_limit,
@@ -32,10 +35,11 @@ class CommunitiesBlock @@ -32,10 +35,11 @@ class CommunitiesBlock
32 :order => 'profiles.updated_at DESC' 35 :order => 'profiles.updated_at DESC'
33 ).sort_by {rand} 36 ).sort_by {rand}
34 else 37 else
35 - return visible_profiles.with_image.sort_by {rand} + 38 + visible_profiles = visible_profiles.with_image.sort_by {rand} +
36 visible_profiles.without_image.all( 39 visible_profiles.without_image.all(
37 :limit => get_limit * 5, :order => 'profiles.updated_at DESC' 40 :limit => get_limit * 5, :order => 'profiles.updated_at DESC'
38 ).sort_by {rand} 41 ).sort_by {rand}
  42 + return visible_profiles
39 end 43 end
40 end 44 end
41 end 45 end
lib/ext/community.rb
@@ -28,11 +28,14 @@ class Community @@ -28,11 +28,14 @@ class Community
28 28
29 def self.get_valid_communities_string 29 def self.get_valid_communities_string
30 remove_of_communities_methods = Community.instance_methods.select{|m| m =~ /remove_of_community_search/} 30 remove_of_communities_methods = Community.instance_methods.select{|m| m =~ /remove_of_community_search/}
31 - valid_communities_string = "" 31 + valid_communities_string = "!("
32 remove_of_communities_methods.each do |method| 32 remove_of_communities_methods.each do |method|
33 - valid_communities_string += "!community.send('#{method}') && " 33 + valid_communities_string += "community.send('#{method}') || "
34 end 34 end
35 - valid_communities_string[0..-5] 35 + valid_communities_string = valid_communities_string[0..-5]
  36 + valid_communities_string += ")"
  37 +
  38 + valid_communities_string
36 end 39 end
37 40
38 def software? 41 def software?
lib/ext/search_controller.rb
@@ -3,10 +3,12 @@ require_dependency &#39;search_controller&#39; @@ -3,10 +3,12 @@ require_dependency &#39;search_controller&#39;
3 class SearchController 3 class SearchController
4 4
5 def communities 5 def communities
  6 + delete_communities = []
6 valid_communities_string = Community.get_valid_communities_string 7 valid_communities_string = Community.get_valid_communities_string
  8 + Community.all.each{|community| delete_communities << community.id unless eval(valid_communities_string)}
7 9
8 @scope = visible_profiles(Community) 10 @scope = visible_profiles(Community)
9 - @scope.each{|community| @scope.delete(community) unless eval(valid_communities_string)} 11 + @scope = @scope.where(["id NOT IN (?)", delete_communities]) unless delete_communities.empty?
10 12
11 full_text_search 13 full_text_search
12 end 14 end
test/unit/communities_block_test.rb
@@ -24,7 +24,8 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase @@ -24,7 +24,8 @@ class CommunitiesBlockTest &lt; ActiveSupport::TestCase
24 @software_info = nil 24 @software_info = nil
25 end 25 end
26 should "not have community of software or institution in block" do 26 should "not have community of software or institution in block" do
27 - assert_equal 1, @comminities_block.profile_list.count 27 + assert_includes @comminities_block.profile_list, @community
  28 + assert_not_includes @comminities_block.profile_list, @software_info.community
28 end 29 end
29 30
30 end 31 end