diff --git a/app/models/add_friend.rb b/app/models/add_friend.rb index 2e2a96d..df18fca 100644 --- a/app/models/add_friend.rb +++ b/app/models/add_friend.rb @@ -14,6 +14,11 @@ class AddFriend < Task alias :friend :target alias :friend= :target= + after_create do |task| + TaskMailer.invitation_notification(task).deliver unless task.friend + remove_from_suggestion_list(task) + end + def perform target.add_friend(requestor, group_for_friend) requestor.add_friend(target, group_for_person) @@ -48,4 +53,8 @@ class AddFriend < Task {:type => :profile_image, :profile => requestor, :url => requestor.url} end + def remove_from_suggestion_list(task) + suggestion = task.requestor.profile_suggestions.find_by_suggestion_id task.target.id + suggestion.disable if suggestion + end end diff --git a/app/models/profile.rb b/app/models/profile.rb index c546163..bbec988 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -631,6 +631,7 @@ private :generate_url, :url_options self.affiliate(person, Profile::Roles.admin(environment.id)) if members.count == 0 self.affiliate(person, Profile::Roles.member(environment.id)) end + remove_from_suggestion_list person else raise _("%s can't have members") % self.class.name end @@ -959,4 +960,10 @@ private :generate_url, :url_options def preferred_login_redirection redirection_after_login.blank? ? environment.redirection_after_login : redirection_after_login end + + def remove_from_suggestion_list(person) + suggestion = person.profile_suggestions.find_by_suggestion_id self.id + suggestion.disable if suggestion + end + end diff --git a/test/unit/add_friend_test.rb b/test/unit/add_friend_test.rb index 3cf18a5..859dfc2 100644 --- a/test/unit/add_friend_test.rb +++ b/test/unit/add_friend_test.rb @@ -137,4 +137,11 @@ class AddFriendTest < ActiveSupport::TestCase assert_match(/#{task.requestor.name} wants to be your friend/, email.subject) end + should 'disable suggestion if profile requested friendship' do + suggestion = ProfileSuggestion.create(:person => person1, :suggestion => person2, :enabled => true) + + task = AddFriend.create(:person => person1, :friend => person2) + assert_equal false, ProfileSuggestion.find(suggestion.id).enabled + end + end diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index f925c53..3d53911 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -1458,4 +1458,67 @@ class PersonTest < ActiveSupport::TestCase person.reload end end + + should 'have a list of suggested people to be friend' do + person = create_user('person').person + suggested_friend = fast_create(Person) + + ProfileSuggestion.create(:person => person, :suggestion => suggested_friend) + assert_equal [suggested_friend], person.suggested_people + end + + should 'have a list of suggested communities to be member' do + person = create_user('person').person + suggested_community = fast_create(Community) + + ProfileSuggestion.create(:person => person, :suggestion => suggested_community) + assert_equal [suggested_community], person.suggested_communities + end + + should 'remove profile suggestion when person is destroyed' do + person = create_user('person').person + suggested_community = fast_create(Community) + + suggestion = ProfileSuggestion.create(:person => person, :suggestion => suggested_community) + + person.destroy + assert_raise ActiveRecord::RecordNotFound do + ProfileSuggestion.find suggestion.id + end + end + + should 'remove profile suggestion when suggested profile is destroyed' do + person = create_user('person').person + suggested_community = fast_create(Community) + + suggestion = ProfileSuggestion.create(:person => person, :suggestion => suggested_community) + + suggested_community.destroy + assert_raise ActiveRecord::RecordNotFound do + ProfileSuggestion.find suggestion.id + end + end + + should 'not suggest disabled suggestion of people' do + person = create_user('person').person + suggested_person = fast_create(Person) + disabled_suggested_person = fast_create(Person) + + enabled_suggestion = ProfileSuggestion.create(:person => person, :suggestion => suggested_person) + disabled_suggestion = ProfileSuggestion.create(:person => person, :suggestion => disabled_suggested_person, :enabled => false) + + assert_equal [suggested_person], person.suggested_people + end + + should 'not suggest disabled suggestion of communities' do + person = create_user('person').person + suggested_community = fast_create(Community) + disabled_suggested_community = fast_create(Community) + + enabled_suggestion = ProfileSuggestion.create(:person => person, :suggestion => suggested_community) + disabled_suggestion = ProfileSuggestion.create(:person => person, :suggestion => disabled_suggested_community, :enabled => false) + + assert_equal [suggested_community], person.suggested_communities + end + end -- libgit2 0.21.2