Commit 4aa45dd80513a07f352af8848f1096c725f68805
Committed by
Daniela Feitosa
1 parent
b4000b01
Exists in
master
and in
29 other branches
Handle related suggestions when a profile is destroyed
Showing
10 changed files
with
41 additions
and
31 deletions
Show diff stats
app/controllers/my_profile/friends_controller.rb
1 | class FriendsController < MyProfileController | 1 | class FriendsController < MyProfileController |
2 | - | 2 | + |
3 | protect 'manage_friends', :profile | 3 | protect 'manage_friends', :profile |
4 | - | 4 | + |
5 | def index | 5 | def index |
6 | - @suggestions = profile.profile_suggestions.of_person.enabled.includes(:suggestion).limit(per_page) | 6 | + @suggestions = profile.suggested_profiles.of_person.enabled.includes(:suggestion).limit(per_page) |
7 | if is_cache_expired?(profile.manage_friends_cache_key(params)) | 7 | if is_cache_expired?(profile.manage_friends_cache_key(params)) |
8 | @friends = profile.friends.paginate(:per_page => per_page, :page => params[:npage]) | 8 | @friends = profile.friends.paginate(:per_page => per_page, :page => params[:npage]) |
9 | end | 9 | end |
@@ -18,7 +18,7 @@ class FriendsController < MyProfileController | @@ -18,7 +18,7 @@ class FriendsController < MyProfileController | ||
18 | end | 18 | end |
19 | 19 | ||
20 | def suggest | 20 | def suggest |
21 | - @suggestions = profile.profile_suggestions.of_person.enabled.includes(:suggestion).limit(per_page) | 21 | + @suggestions = profile.suggested_profiles.of_person.enabled.includes(:suggestion).limit(per_page) |
22 | end | 22 | end |
23 | 23 | ||
24 | def remove_suggestion | 24 | def remove_suggestion |
@@ -26,13 +26,13 @@ class FriendsController < MyProfileController | @@ -26,13 +26,13 @@ class FriendsController < MyProfileController | ||
26 | redirect_to :action => 'suggest' unless @person | 26 | redirect_to :action => 'suggest' unless @person |
27 | if @person && request.post? | 27 | if @person && request.post? |
28 | profile.remove_suggestion(@person) | 28 | profile.remove_suggestion(@person) |
29 | - @suggestions = profile.profile_suggestions.of_person.enabled.includes(:suggestion).limit(per_page) | 29 | + @suggestions = profile.suggested_profiles.of_person.enabled.includes(:suggestion).limit(per_page) |
30 | render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => @suggestions, :collection => :friends_suggestions, :per_page => params[:per_page] || per_page } | 30 | render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => @suggestions, :collection => :friends_suggestions, :per_page => params[:per_page] || per_page } |
31 | end | 31 | end |
32 | end | 32 | end |
33 | 33 | ||
34 | def connections | 34 | def connections |
35 | - @suggestion = profile.profile_suggestions.of_person.enabled.find_by_suggestion_id(params[:id]) | 35 | + @suggestion = profile.suggested_profiles.of_person.enabled.find_by_suggestion_id(params[:id]) |
36 | if @suggestion | 36 | if @suggestion |
37 | @tags = @suggestion.tag_connections | 37 | @tags = @suggestion.tag_connections |
38 | @profiles = @suggestion.profile_connections | 38 | @profiles = @suggestion.profile_connections |
app/controllers/my_profile/memberships_controller.rb
@@ -40,7 +40,7 @@ class MembershipsController < MyProfileController | @@ -40,7 +40,7 @@ class MembershipsController < MyProfileController | ||
40 | end | 40 | end |
41 | 41 | ||
42 | def suggest | 42 | def suggest |
43 | - @suggestions = profile.profile_suggestions.of_community.enabled.includes(:suggestion).limit(per_page) | 43 | + @suggestions = profile.suggested_profiles.of_community.enabled.includes(:suggestion).limit(per_page) |
44 | end | 44 | end |
45 | 45 | ||
46 | def remove_suggestion | 46 | def remove_suggestion |
@@ -49,13 +49,13 @@ class MembershipsController < MyProfileController | @@ -49,13 +49,13 @@ class MembershipsController < MyProfileController | ||
49 | redirect_to :action => 'suggest' unless @community | 49 | redirect_to :action => 'suggest' unless @community |
50 | if @community && request.post? | 50 | if @community && request.post? |
51 | profile.remove_suggestion(@community) | 51 | profile.remove_suggestion(@community) |
52 | - @suggestions = profile.profile_suggestions.of_community.enabled.includes(:suggestion).limit(custom_per_page) | 52 | + @suggestions = profile.suggested_profiles.of_community.enabled.includes(:suggestion).limit(custom_per_page) |
53 | render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => @suggestions, :collection => :communities_suggestions, :per_page => custom_per_page} | 53 | render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => @suggestions, :collection => :communities_suggestions, :per_page => custom_per_page} |
54 | end | 54 | end |
55 | end | 55 | end |
56 | 56 | ||
57 | def connections | 57 | def connections |
58 | - @suggestion = profile.profile_suggestions.of_community.enabled.find_by_suggestion_id(params[:id]) | 58 | + @suggestion = profile.suggested_profiles.of_community.enabled.find_by_suggestion_id(params[:id]) |
59 | if @suggestion | 59 | if @suggestion |
60 | @tags = @suggestion.tag_connections | 60 | @tags = @suggestion.tag_connections |
61 | @profiles = @suggestion.profile_connections | 61 | @profiles = @suggestion.profile_connections |
app/models/add_friend.rb
@@ -54,7 +54,7 @@ class AddFriend < Task | @@ -54,7 +54,7 @@ class AddFriend < Task | ||
54 | end | 54 | end |
55 | 55 | ||
56 | def remove_from_suggestion_list(task) | 56 | def remove_from_suggestion_list(task) |
57 | - suggestion = task.requestor.profile_suggestions.find_by_suggestion_id task.target.id | 57 | + suggestion = task.requestor.suggested_profiles.find_by_suggestion_id task.target.id |
58 | suggestion.disable if suggestion | 58 | suggestion.disable if suggestion |
59 | end | 59 | end |
60 | end | 60 | end |
app/models/person.rb
@@ -84,9 +84,9 @@ roles] } | @@ -84,9 +84,9 @@ roles] } | ||
84 | has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people' | 84 | has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people' |
85 | has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions' | 85 | has_and_belongs_to_many :articles_with_access, :class_name => 'Article', :join_table => 'article_privacy_exceptions' |
86 | 86 | ||
87 | - has_many :profile_suggestions, :foreign_key => :person_id, :order => 'score DESC', :dependent => :destroy | ||
88 | - has_many :suggested_people, :through => :profile_suggestions, :source => :suggestion, :conditions => ['profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Person', true] | ||
89 | - has_many :suggested_communities, :through => :profile_suggestions, :source => :suggestion, :conditions => ['profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Community', true] | 87 | + has_many :suggested_profiles, :class_name => 'ProfileSuggestion', :foreign_key => :person_id, :order => 'score DESC', :dependent => :destroy |
88 | + has_many :suggested_people, :through => :suggested_profiles, :source => :suggestion, :conditions => ['profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Person', true] | ||
89 | + has_many :suggested_communities, :through => :suggested_profiles, :source => :suggestion, :conditions => ['profile_suggestions.suggestion_type = ? AND profile_suggestions.enabled = ?', 'Community', true] | ||
90 | 90 | ||
91 | scope :more_popular, :order => 'friends_count DESC' | 91 | scope :more_popular, :order => 'friends_count DESC' |
92 | 92 | ||
@@ -524,7 +524,7 @@ roles] } | @@ -524,7 +524,7 @@ roles] } | ||
524 | end | 524 | end |
525 | 525 | ||
526 | def remove_suggestion(profile) | 526 | def remove_suggestion(profile) |
527 | - suggestion = profile_suggestions.find_by_suggestion_id profile.id | 527 | + suggestion = suggested_profiles.find_by_suggestion_id profile.id |
528 | suggestion.disable if suggestion | 528 | suggestion.disable if suggestion |
529 | end | 529 | end |
530 | 530 |
app/models/profile.rb
@@ -1033,7 +1033,7 @@ private :generate_url, :url_options | @@ -1033,7 +1033,7 @@ private :generate_url, :url_options | ||
1033 | end | 1033 | end |
1034 | 1034 | ||
1035 | def remove_from_suggestion_list(person) | 1035 | def remove_from_suggestion_list(person) |
1036 | - suggestion = person.profile_suggestions.find_by_suggestion_id self.id | 1036 | + suggestion = person.suggested_profiles.find_by_suggestion_id self.id |
1037 | suggestion.disable if suggestion | 1037 | suggestion.disable if suggestion |
1038 | end | 1038 | end |
1039 | 1039 |
app/models/profile_suggestion.rb
@@ -113,14 +113,14 @@ class ProfileSuggestion < ActiveRecord::Base | @@ -113,14 +113,14 @@ class ProfileSuggestion < ActiveRecord::Base | ||
113 | suggested_profiles = all_suggestions(person) | 113 | suggested_profiles = all_suggestions(person) |
114 | return if suggested_profiles.nil? | 114 | return if suggested_profiles.nil? |
115 | 115 | ||
116 | - already_suggested_profiles = person.profile_suggestions.map(&:suggestion_id).join(',') | 116 | + already_suggested_profiles = person.suggested_profiles.map(&:suggestion_id).join(',') |
117 | suggested_profiles = suggested_profiles.where("profiles.id NOT IN (#{already_suggested_profiles})") if already_suggested_profiles.present? | 117 | suggested_profiles = suggested_profiles.where("profiles.id NOT IN (#{already_suggested_profiles})") if already_suggested_profiles.present? |
118 | #TODO suggested_profiles = suggested_profiles.order('score DESC') | 118 | #TODO suggested_profiles = suggested_profiles.order('score DESC') |
119 | suggested_profiles = suggested_profiles.limit(N_SUGGESTIONS) | 119 | suggested_profiles = suggested_profiles.limit(N_SUGGESTIONS) |
120 | return if suggested_profiles.blank? | 120 | return if suggested_profiles.blank? |
121 | 121 | ||
122 | suggested_profiles.each do |suggested_profile| | 122 | suggested_profiles.each do |suggested_profile| |
123 | - suggestion = person.profile_suggestions.find_or_initialize_by_suggestion_id(suggested_profile.id) | 123 | + suggestion = person.suggested_profiles.find_or_initialize_by_suggestion_id(suggested_profile.id) |
124 | RULES.each do |rule, options| | 124 | RULES.each do |rule, options| |
125 | begin | 125 | begin |
126 | value = suggested_profile.send("#{rule}_count").to_i | 126 | value = suggested_profile.send("#{rule}_count").to_i |
@@ -273,7 +273,7 @@ class ProfileSuggestion < ActiveRecord::Base | @@ -273,7 +273,7 @@ class ProfileSuggestion < ActiveRecord::Base | ||
273 | end | 273 | end |
274 | 274 | ||
275 | def self.generate_profile_suggestions(person, force = false) | 275 | def self.generate_profile_suggestions(person, force = false) |
276 | - return if person.profile_suggestions.enabled.count >= MIN_LIMIT && !force | 276 | + return if person.suggested_profiles.enabled.count >= MIN_LIMIT && !force |
277 | Delayed::Job.enqueue ProfileSuggestionsJob.new(person.id) unless ProfileSuggestionsJob.exists?(person.id) | 277 | Delayed::Job.enqueue ProfileSuggestionsJob.new(person.id) unless ProfileSuggestionsJob.exists?(person.id) |
278 | end | 278 | end |
279 | 279 |
test/functional/friends_controller_test.rb
@@ -46,7 +46,7 @@ class FriendsControllerTest < ActionController::TestCase | @@ -46,7 +46,7 @@ class FriendsControllerTest < ActionController::TestCase | ||
46 | 46 | ||
47 | should 'display find people button' do | 47 | should 'display find people button' do |
48 | get :index, :profile => 'testuser' | 48 | get :index, :profile => 'testuser' |
49 | - assert_tag :tag => 'a', :content => 'Find people', :attributes => { :href => '/assets/people' } | 49 | + assert_tag :tag => 'a', :content => 'Find people', :attributes => { :href => '/search/assets?asset=people' } |
50 | end | 50 | end |
51 | 51 | ||
52 | should 'not display invite friends button if any plugin tells not to' do | 52 | should 'not display invite friends button if any plugin tells not to' do |
@@ -76,25 +76,25 @@ class FriendsControllerTest < ActionController::TestCase | @@ -76,25 +76,25 @@ class FriendsControllerTest < ActionController::TestCase | ||
76 | end | 76 | end |
77 | 77 | ||
78 | should 'display people suggestions' do | 78 | should 'display people suggestions' do |
79 | - profile.profile_suggestions.create(:suggestion => friend) | 79 | + profile.suggested_profiles.create(:suggestion => friend) |
80 | get :suggest, :profile => 'testuser' | 80 | get :suggest, :profile => 'testuser' |
81 | assert_tag :tag => 'a', :content => "+ #{friend.name}", :attributes => { :href => "/profile/#{friend.identifier}/add" } | 81 | assert_tag :tag => 'a', :content => "+ #{friend.name}", :attributes => { :href => "/profile/#{friend.identifier}/add" } |
82 | end | 82 | end |
83 | 83 | ||
84 | should 'display button to add friend suggestion' do | 84 | should 'display button to add friend suggestion' do |
85 | - profile.profile_suggestions.create(:suggestion => friend) | 85 | + profile.suggested_profiles.create(:suggestion => friend) |
86 | get :suggest, :profile => 'testuser' | 86 | get :suggest, :profile => 'testuser' |
87 | assert_tag :tag => 'a', :attributes => { :href => "/profile/#{friend.identifier}/add" } | 87 | assert_tag :tag => 'a', :attributes => { :href => "/profile/#{friend.identifier}/add" } |
88 | end | 88 | end |
89 | 89 | ||
90 | should 'display button to remove people suggestion' do | 90 | should 'display button to remove people suggestion' do |
91 | - profile.profile_suggestions.create(:suggestion => friend) | 91 | + profile.suggested_profiles.create(:suggestion => friend) |
92 | get :suggest, :profile => 'testuser' | 92 | get :suggest, :profile => 'testuser' |
93 | assert_tag :tag => 'a', :attributes => { :href => /\/myprofile\/testuser\/friends\/remove_suggestion\/#{friend.identifier}/ } | 93 | assert_tag :tag => 'a', :attributes => { :href => /\/myprofile\/testuser\/friends\/remove_suggestion\/#{friend.identifier}/ } |
94 | end | 94 | end |
95 | 95 | ||
96 | should 'remove suggestion of friend' do | 96 | should 'remove suggestion of friend' do |
97 | - suggestion = profile.profile_suggestions.create(:suggestion => friend) | 97 | + suggestion = profile.suggested_profiles.create(:suggestion => friend) |
98 | post :remove_suggestion, :profile => 'testuser', :id => friend.identifier | 98 | post :remove_suggestion, :profile => 'testuser', :id => friend.identifier |
99 | 99 | ||
100 | assert_response :success | 100 | assert_response :success |
test/functional/memberships_controller_test.rb
@@ -331,35 +331,35 @@ class MembershipsControllerTest < ActionController::TestCase | @@ -331,35 +331,35 @@ class MembershipsControllerTest < ActionController::TestCase | ||
331 | 331 | ||
332 | should 'display list suggestions button' do | 332 | should 'display list suggestions button' do |
333 | community = fast_create(Community) | 333 | community = fast_create(Community) |
334 | - profile.profile_suggestions.create(:suggestion => community) | 334 | + profile.suggested_profiles.create(:suggestion => community) |
335 | get :index, :profile => 'testuser' | 335 | get :index, :profile => 'testuser' |
336 | assert_tag :tag => 'a', :content => 'See some suggestions of communities...', :attributes => { :href => "/myprofile/testuser/memberships/suggest" } | 336 | assert_tag :tag => 'a', :content => 'See some suggestions of communities...', :attributes => { :href => "/myprofile/testuser/memberships/suggest" } |
337 | end | 337 | end |
338 | 338 | ||
339 | should 'display communities suggestions' do | 339 | should 'display communities suggestions' do |
340 | community = fast_create(Community) | 340 | community = fast_create(Community) |
341 | - profile.profile_suggestions.create(:suggestion => community) | 341 | + profile.suggested_profiles.create(:suggestion => community) |
342 | get :suggest, :profile => 'testuser' | 342 | get :suggest, :profile => 'testuser' |
343 | assert_tag :tag => 'a', :content => "+ #{community.name}", :attributes => { :href => "/profile/#{community.identifier}/join" } | 343 | assert_tag :tag => 'a', :content => "+ #{community.name}", :attributes => { :href => "/profile/#{community.identifier}/join" } |
344 | end | 344 | end |
345 | 345 | ||
346 | should 'display button to join on community suggestion' do | 346 | should 'display button to join on community suggestion' do |
347 | community = fast_create(Community) | 347 | community = fast_create(Community) |
348 | - profile.profile_suggestions.create(:suggestion => community) | 348 | + profile.suggested_profiles.create(:suggestion => community) |
349 | get :suggest, :profile => 'testuser' | 349 | get :suggest, :profile => 'testuser' |
350 | assert_tag :tag => 'a', :attributes => { :href => "/profile/#{community.identifier}/join" } | 350 | assert_tag :tag => 'a', :attributes => { :href => "/profile/#{community.identifier}/join" } |
351 | end | 351 | end |
352 | 352 | ||
353 | should 'display button to remove community suggestion' do | 353 | should 'display button to remove community suggestion' do |
354 | community = fast_create(Community) | 354 | community = fast_create(Community) |
355 | - profile.profile_suggestions.create(:suggestion => community) | 355 | + profile.suggested_profiles.create(:suggestion => community) |
356 | get :suggest, :profile => 'testuser' | 356 | get :suggest, :profile => 'testuser' |
357 | assert_tag :tag => 'a', :attributes => { :href => /\/myprofile\/testuser\/memberships\/remove_suggestion\/#{community.identifier}/ } | 357 | assert_tag :tag => 'a', :attributes => { :href => /\/myprofile\/testuser\/memberships\/remove_suggestion\/#{community.identifier}/ } |
358 | end | 358 | end |
359 | 359 | ||
360 | should 'remove suggestion of community' do | 360 | should 'remove suggestion of community' do |
361 | community = fast_create(Community) | 361 | community = fast_create(Community) |
362 | - suggestion = profile.profile_suggestions.create(:suggestion => community) | 362 | + suggestion = profile.suggested_profiles.create(:suggestion => community) |
363 | post :remove_suggestion, :profile => 'testuser', :id => community.identifier | 363 | post :remove_suggestion, :profile => 'testuser', :id => community.identifier |
364 | 364 | ||
365 | assert_response :success | 365 | assert_response :success |
test/unit/profile_suggestion_test.rb
@@ -142,7 +142,7 @@ class ProfileSuggestionTest < ActiveSupport::TestCase | @@ -142,7 +142,7 @@ class ProfileSuggestionTest < ActiveSupport::TestCase | ||
142 | p2 = create_user('testuser2').person | 142 | p2 = create_user('testuser2').person |
143 | p3 = create_user('testuser3').person | 143 | p3 = create_user('testuser3').person |
144 | p4 = create_user('testuser4').person | 144 | p4 = create_user('testuser4').person |
145 | - p5 = create_user('testuser4').person | 145 | + p5 = create_user('testuser5').person |
146 | 146 | ||
147 | p1.add_friend(p2) | 147 | p1.add_friend(p2) |
148 | p1.add_friend(p3) | 148 | p1.add_friend(p3) |
@@ -212,8 +212,8 @@ class ProfileSuggestionTest < ActiveSupport::TestCase | @@ -212,8 +212,8 @@ class ProfileSuggestionTest < ActiveSupport::TestCase | ||
212 | 212 | ||
213 | ProfileSuggestion.expects(:calculate_suggestions) | 213 | ProfileSuggestion.expects(:calculate_suggestions) |
214 | 214 | ||
215 | - person.profile_suggestions.enabled.last.disable | ||
216 | - person.profile_suggestions.enabled.last.destroy | 215 | + person.suggested_profiles.enabled.last.disable |
216 | + person.suggested_profiles.enabled.last.destroy | ||
217 | process_delayed_job_queue | 217 | process_delayed_job_queue |
218 | end | 218 | end |
219 | 219 |
test/unit/profile_test.rb
@@ -2139,6 +2139,16 @@ class ProfileTest < ActiveSupport::TestCase | @@ -2139,6 +2139,16 @@ class ProfileTest < ActiveSupport::TestCase | ||
2139 | assert_equal false, ProfileSuggestion.find(suggestion.id).enabled | 2139 | assert_equal false, ProfileSuggestion.find(suggestion.id).enabled |
2140 | end | 2140 | end |
2141 | 2141 | ||
2142 | + should 'destroy related suggestion if profile is destroyed' do | ||
2143 | + person = fast_create(Person) | ||
2144 | + suggested_person = fast_create(Person) | ||
2145 | + suggestion = ProfileSuggestion.create(:person => person, :suggestion => suggested_person, :enabled => true) | ||
2146 | + | ||
2147 | + assert_difference 'ProfileSuggestion.find_all_by_suggestion_id(suggested_person.id).count', -1 do | ||
2148 | + suggested_person.destroy | ||
2149 | + end | ||
2150 | + end | ||
2151 | + | ||
2142 | should 'enable profile visibility' do | 2152 | should 'enable profile visibility' do |
2143 | profile = fast_create(Profile) | 2153 | profile = fast_create(Profile) |
2144 | 2154 |