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 | 1 | class FriendsController < MyProfileController |
2 | - | |
2 | + | |
3 | 3 | protect 'manage_friends', :profile |
4 | - | |
4 | + | |
5 | 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 | 7 | if is_cache_expired?(profile.manage_friends_cache_key(params)) |
8 | 8 | @friends = profile.friends.paginate(:per_page => per_page, :page => params[:npage]) |
9 | 9 | end |
... | ... | @@ -18,7 +18,7 @@ class FriendsController < MyProfileController |
18 | 18 | end |
19 | 19 | |
20 | 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 | 22 | end |
23 | 23 | |
24 | 24 | def remove_suggestion |
... | ... | @@ -26,13 +26,13 @@ class FriendsController < MyProfileController |
26 | 26 | redirect_to :action => 'suggest' unless @person |
27 | 27 | if @person && request.post? |
28 | 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 | 30 | render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => @suggestions, :collection => :friends_suggestions, :per_page => params[:per_page] || per_page } |
31 | 31 | end |
32 | 32 | end |
33 | 33 | |
34 | 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 | 36 | if @suggestion |
37 | 37 | @tags = @suggestion.tag_connections |
38 | 38 | @profiles = @suggestion.profile_connections | ... | ... |
app/controllers/my_profile/memberships_controller.rb
... | ... | @@ -40,7 +40,7 @@ class MembershipsController < MyProfileController |
40 | 40 | end |
41 | 41 | |
42 | 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 | 44 | end |
45 | 45 | |
46 | 46 | def remove_suggestion |
... | ... | @@ -49,13 +49,13 @@ class MembershipsController < MyProfileController |
49 | 49 | redirect_to :action => 'suggest' unless @community |
50 | 50 | if @community && request.post? |
51 | 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 | 53 | render :partial => 'shared/profile_suggestions_list', :locals => { :suggestions => @suggestions, :collection => :communities_suggestions, :per_page => custom_per_page} |
54 | 54 | end |
55 | 55 | end |
56 | 56 | |
57 | 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 | 59 | if @suggestion |
60 | 60 | @tags = @suggestion.tag_connections |
61 | 61 | @profiles = @suggestion.profile_connections | ... | ... |
app/models/add_friend.rb
... | ... | @@ -54,7 +54,7 @@ class AddFriend < Task |
54 | 54 | end |
55 | 55 | |
56 | 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 | 58 | suggestion.disable if suggestion |
59 | 59 | end |
60 | 60 | end | ... | ... |
app/models/person.rb
... | ... | @@ -84,9 +84,9 @@ roles] } |
84 | 84 | has_and_belongs_to_many :acepted_forums, :class_name => 'Forum', :join_table => 'terms_forum_people' |
85 | 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 | 91 | scope :more_popular, :order => 'friends_count DESC' |
92 | 92 | |
... | ... | @@ -524,7 +524,7 @@ roles] } |
524 | 524 | end |
525 | 525 | |
526 | 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 | 528 | suggestion.disable if suggestion |
529 | 529 | end |
530 | 530 | ... | ... |
app/models/profile.rb
... | ... | @@ -1033,7 +1033,7 @@ private :generate_url, :url_options |
1033 | 1033 | end |
1034 | 1034 | |
1035 | 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 | 1037 | suggestion.disable if suggestion |
1038 | 1038 | end |
1039 | 1039 | ... | ... |
app/models/profile_suggestion.rb
... | ... | @@ -113,14 +113,14 @@ class ProfileSuggestion < ActiveRecord::Base |
113 | 113 | suggested_profiles = all_suggestions(person) |
114 | 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 | 117 | suggested_profiles = suggested_profiles.where("profiles.id NOT IN (#{already_suggested_profiles})") if already_suggested_profiles.present? |
118 | 118 | #TODO suggested_profiles = suggested_profiles.order('score DESC') |
119 | 119 | suggested_profiles = suggested_profiles.limit(N_SUGGESTIONS) |
120 | 120 | return if suggested_profiles.blank? |
121 | 121 | |
122 | 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 | 124 | RULES.each do |rule, options| |
125 | 125 | begin |
126 | 126 | value = suggested_profile.send("#{rule}_count").to_i |
... | ... | @@ -273,7 +273,7 @@ class ProfileSuggestion < ActiveRecord::Base |
273 | 273 | end |
274 | 274 | |
275 | 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 | 277 | Delayed::Job.enqueue ProfileSuggestionsJob.new(person.id) unless ProfileSuggestionsJob.exists?(person.id) |
278 | 278 | end |
279 | 279 | ... | ... |
test/functional/friends_controller_test.rb
... | ... | @@ -46,7 +46,7 @@ class FriendsControllerTest < ActionController::TestCase |
46 | 46 | |
47 | 47 | should 'display find people button' do |
48 | 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 | 50 | end |
51 | 51 | |
52 | 52 | should 'not display invite friends button if any plugin tells not to' do |
... | ... | @@ -76,25 +76,25 @@ class FriendsControllerTest < ActionController::TestCase |
76 | 76 | end |
77 | 77 | |
78 | 78 | should 'display people suggestions' do |
79 | - profile.profile_suggestions.create(:suggestion => friend) | |
79 | + profile.suggested_profiles.create(:suggestion => friend) | |
80 | 80 | get :suggest, :profile => 'testuser' |
81 | 81 | assert_tag :tag => 'a', :content => "+ #{friend.name}", :attributes => { :href => "/profile/#{friend.identifier}/add" } |
82 | 82 | end |
83 | 83 | |
84 | 84 | should 'display button to add friend suggestion' do |
85 | - profile.profile_suggestions.create(:suggestion => friend) | |
85 | + profile.suggested_profiles.create(:suggestion => friend) | |
86 | 86 | get :suggest, :profile => 'testuser' |
87 | 87 | assert_tag :tag => 'a', :attributes => { :href => "/profile/#{friend.identifier}/add" } |
88 | 88 | end |
89 | 89 | |
90 | 90 | should 'display button to remove people suggestion' do |
91 | - profile.profile_suggestions.create(:suggestion => friend) | |
91 | + profile.suggested_profiles.create(:suggestion => friend) | |
92 | 92 | get :suggest, :profile => 'testuser' |
93 | 93 | assert_tag :tag => 'a', :attributes => { :href => /\/myprofile\/testuser\/friends\/remove_suggestion\/#{friend.identifier}/ } |
94 | 94 | end |
95 | 95 | |
96 | 96 | should 'remove suggestion of friend' do |
97 | - suggestion = profile.profile_suggestions.create(:suggestion => friend) | |
97 | + suggestion = profile.suggested_profiles.create(:suggestion => friend) | |
98 | 98 | post :remove_suggestion, :profile => 'testuser', :id => friend.identifier |
99 | 99 | |
100 | 100 | assert_response :success | ... | ... |
test/functional/memberships_controller_test.rb
... | ... | @@ -331,35 +331,35 @@ class MembershipsControllerTest < ActionController::TestCase |
331 | 331 | |
332 | 332 | should 'display list suggestions button' do |
333 | 333 | community = fast_create(Community) |
334 | - profile.profile_suggestions.create(:suggestion => community) | |
334 | + profile.suggested_profiles.create(:suggestion => community) | |
335 | 335 | get :index, :profile => 'testuser' |
336 | 336 | assert_tag :tag => 'a', :content => 'See some suggestions of communities...', :attributes => { :href => "/myprofile/testuser/memberships/suggest" } |
337 | 337 | end |
338 | 338 | |
339 | 339 | should 'display communities suggestions' do |
340 | 340 | community = fast_create(Community) |
341 | - profile.profile_suggestions.create(:suggestion => community) | |
341 | + profile.suggested_profiles.create(:suggestion => community) | |
342 | 342 | get :suggest, :profile => 'testuser' |
343 | 343 | assert_tag :tag => 'a', :content => "+ #{community.name}", :attributes => { :href => "/profile/#{community.identifier}/join" } |
344 | 344 | end |
345 | 345 | |
346 | 346 | should 'display button to join on community suggestion' do |
347 | 347 | community = fast_create(Community) |
348 | - profile.profile_suggestions.create(:suggestion => community) | |
348 | + profile.suggested_profiles.create(:suggestion => community) | |
349 | 349 | get :suggest, :profile => 'testuser' |
350 | 350 | assert_tag :tag => 'a', :attributes => { :href => "/profile/#{community.identifier}/join" } |
351 | 351 | end |
352 | 352 | |
353 | 353 | should 'display button to remove community suggestion' do |
354 | 354 | community = fast_create(Community) |
355 | - profile.profile_suggestions.create(:suggestion => community) | |
355 | + profile.suggested_profiles.create(:suggestion => community) | |
356 | 356 | get :suggest, :profile => 'testuser' |
357 | 357 | assert_tag :tag => 'a', :attributes => { :href => /\/myprofile\/testuser\/memberships\/remove_suggestion\/#{community.identifier}/ } |
358 | 358 | end |
359 | 359 | |
360 | 360 | should 'remove suggestion of community' do |
361 | 361 | community = fast_create(Community) |
362 | - suggestion = profile.profile_suggestions.create(:suggestion => community) | |
362 | + suggestion = profile.suggested_profiles.create(:suggestion => community) | |
363 | 363 | post :remove_suggestion, :profile => 'testuser', :id => community.identifier |
364 | 364 | |
365 | 365 | assert_response :success | ... | ... |
test/unit/profile_suggestion_test.rb
... | ... | @@ -142,7 +142,7 @@ class ProfileSuggestionTest < ActiveSupport::TestCase |
142 | 142 | p2 = create_user('testuser2').person |
143 | 143 | p3 = create_user('testuser3').person |
144 | 144 | p4 = create_user('testuser4').person |
145 | - p5 = create_user('testuser4').person | |
145 | + p5 = create_user('testuser5').person | |
146 | 146 | |
147 | 147 | p1.add_friend(p2) |
148 | 148 | p1.add_friend(p3) |
... | ... | @@ -212,8 +212,8 @@ class ProfileSuggestionTest < ActiveSupport::TestCase |
212 | 212 | |
213 | 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 | 217 | process_delayed_job_queue |
218 | 218 | end |
219 | 219 | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -2139,6 +2139,16 @@ class ProfileTest < ActiveSupport::TestCase |
2139 | 2139 | assert_equal false, ProfileSuggestion.find(suggestion.id).enabled |
2140 | 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 | 2152 | should 'enable profile visibility' do |
2143 | 2153 | profile = fast_create(Profile) |
2144 | 2154 | ... | ... |