[Git][noosfero/noosfero][stable-1.8] Merge branch 'fix_profile_suggestions' into 'master'
Rodrigo Souto
gitlab at mg.gitlab.com
Fri Jun 16 10:56:07 BRT 2017
Rodrigo Souto pushed to branch stable-1.8 at Noosfero / noosfero
Commits:
45fd5187 by Rodrigo Souto at 2017-06-16T13:55:59+00:00
Merge branch 'fix_profile_suggestions' into 'master'
Fix suggestions of profiles that a user is already related
Closes #74
See merge request !1237
- - - - -
2 changed files:
- app/models/profile_suggestion.rb
- test/unit/profile_suggestion_test.rb
Changes:
=====================================
app/models/profile_suggestion.rb
=====================================
--- a/app/models/profile_suggestion.rb
+++ b/app/models/profile_suggestion.rb
@@ -115,8 +115,10 @@ class ProfileSuggestion < ApplicationRecord
suggested_profiles = all_suggestions(person)
return if suggested_profiles.nil?
- already_suggested_profiles = person.suggested_profiles.map(&:suggestion_id).join(',')
- suggested_profiles = suggested_profiles.where("profiles.id NOT IN (#{already_suggested_profiles})") if already_suggested_profiles.present?
+ # Filter communities that person has already join and people that are already his friends.
+ suggested_profiles = suggested_profiles.where.not(id: person.memberships.map { |p| p.id } | person.friends.map { |f| f.id })
+ already_suggested_profiles = person.suggested_profiles
+ suggested_profiles = suggested_profiles.where.not(id: already_suggested_profiles)
#TODO suggested_profiles = suggested_profiles.order('score DESC')
suggested_profiles = suggested_profiles.limit(N_SUGGESTIONS)
return if suggested_profiles.blank?
=====================================
test/unit/profile_suggestion_test.rb
=====================================
--- a/test/unit/profile_suggestion_test.rb
+++ b/test/unit/profile_suggestion_test.rb
@@ -59,8 +59,12 @@ class ProfileSuggestionTest < ActiveSupport::TestCase
suggestions = ProfileSuggestion.calculate_suggestions(p1)
- assert_includes suggestions, p5
- assert_includes suggestions, p6
+ assert_not_includes suggestions, p2
+ assert_not_includes suggestions, p3
+ assert_not_includes suggestions, p4
+
+ assert_includes suggestions, p5
+ assert_includes suggestions, p6
end
should 'calculate people with common_communities' do
@@ -84,10 +88,13 @@ class ProfileSuggestionTest < ActiveSupport::TestCase
c3.add_member(p4)
c4.add_member(p5)
+ p1.add_friend(p2)
+ p2.add_friend(p1)
+
suggestions = ProfileSuggestion.calculate_suggestions(p1)
- assert_includes suggestions, p2
- assert_includes suggestions, p4
+ assert_not_includes suggestions, p2
+ assert_includes suggestions, p4
end
should 'calculate people with common_tags' do
@@ -127,10 +134,13 @@ class ProfileSuggestionTest < ActiveSupport::TestCase
a52.tag_list = ['onivorism', 'facism']
a52.save!
+ p1.add_friend(p2)
+ p2.add_friend(p1)
+
suggestions = ProfileSuggestion.calculate_suggestions(p1)
- assert_includes suggestions, p2
- assert_includes suggestions, p3
+ assert_not_includes suggestions, p2
+ assert_includes suggestions, p3
end
should 'calculate communities with common_friends' do
@@ -155,10 +165,12 @@ class ProfileSuggestionTest < ActiveSupport::TestCase
c3.add_member(p2)
c4.add_member(p3)
+ c1.add_member(p1)
+
suggestions = ProfileSuggestion.calculate_suggestions(p1)
- assert_includes suggestions, c1
- assert_includes suggestions, c2
+ assert_not_includes suggestions, c1
+ assert_includes suggestions, c2
end
should 'calculate communities with common_tags' do
View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/45fd5187b4b094665a37179abcb9fcae81c30380
---
View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/45fd5187b4b094665a37179abcb9fcae81c30380
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170616/054585f7/attachment-0001.html>
More information about the Noosfero-dev
mailing list