Commit d8b660b26b7751d089b66a94dcec7eeae3c04a45
1 parent
016d233a
Exists in
master
and in
22 other branches
profile-suggestions: remove from list after ask friendship
Also added some tests (ActionItem3234)
Showing
4 changed files
with
86 additions
and
0 deletions
Show diff stats
app/models/add_friend.rb
| @@ -14,6 +14,11 @@ class AddFriend < Task | @@ -14,6 +14,11 @@ class AddFriend < Task | ||
| 14 | alias :friend :target | 14 | alias :friend :target |
| 15 | alias :friend= :target= | 15 | alias :friend= :target= |
| 16 | 16 | ||
| 17 | + after_create do |task| | ||
| 18 | + TaskMailer.invitation_notification(task).deliver unless task.friend | ||
| 19 | + remove_from_suggestion_list(task) | ||
| 20 | + end | ||
| 21 | + | ||
| 17 | def perform | 22 | def perform |
| 18 | target.add_friend(requestor, group_for_friend) | 23 | target.add_friend(requestor, group_for_friend) |
| 19 | requestor.add_friend(target, group_for_person) | 24 | requestor.add_friend(target, group_for_person) |
| @@ -48,4 +53,8 @@ class AddFriend < Task | @@ -48,4 +53,8 @@ class AddFriend < Task | ||
| 48 | {:type => :profile_image, :profile => requestor, :url => requestor.url} | 53 | {:type => :profile_image, :profile => requestor, :url => requestor.url} |
| 49 | end | 54 | end |
| 50 | 55 | ||
| 56 | + def remove_from_suggestion_list(task) | ||
| 57 | + suggestion = task.requestor.profile_suggestions.find_by_suggestion_id task.target.id | ||
| 58 | + suggestion.disable if suggestion | ||
| 59 | + end | ||
| 51 | end | 60 | end |
app/models/profile.rb
| @@ -631,6 +631,7 @@ private :generate_url, :url_options | @@ -631,6 +631,7 @@ private :generate_url, :url_options | ||
| 631 | self.affiliate(person, Profile::Roles.admin(environment.id)) if members.count == 0 | 631 | self.affiliate(person, Profile::Roles.admin(environment.id)) if members.count == 0 |
| 632 | self.affiliate(person, Profile::Roles.member(environment.id)) | 632 | self.affiliate(person, Profile::Roles.member(environment.id)) |
| 633 | end | 633 | end |
| 634 | + remove_from_suggestion_list person | ||
| 634 | else | 635 | else |
| 635 | raise _("%s can't have members") % self.class.name | 636 | raise _("%s can't have members") % self.class.name |
| 636 | end | 637 | end |
| @@ -959,4 +960,10 @@ private :generate_url, :url_options | @@ -959,4 +960,10 @@ private :generate_url, :url_options | ||
| 959 | def preferred_login_redirection | 960 | def preferred_login_redirection |
| 960 | redirection_after_login.blank? ? environment.redirection_after_login : redirection_after_login | 961 | redirection_after_login.blank? ? environment.redirection_after_login : redirection_after_login |
| 961 | end | 962 | end |
| 963 | + | ||
| 964 | + def remove_from_suggestion_list(person) | ||
| 965 | + suggestion = person.profile_suggestions.find_by_suggestion_id self.id | ||
| 966 | + suggestion.disable if suggestion | ||
| 967 | + end | ||
| 968 | + | ||
| 962 | end | 969 | end |
test/unit/add_friend_test.rb
| @@ -137,4 +137,11 @@ class AddFriendTest < ActiveSupport::TestCase | @@ -137,4 +137,11 @@ class AddFriendTest < ActiveSupport::TestCase | ||
| 137 | assert_match(/#{task.requestor.name} wants to be your friend/, email.subject) | 137 | assert_match(/#{task.requestor.name} wants to be your friend/, email.subject) |
| 138 | end | 138 | end |
| 139 | 139 | ||
| 140 | + should 'disable suggestion if profile requested friendship' do | ||
| 141 | + suggestion = ProfileSuggestion.create(:person => person1, :suggestion => person2, :enabled => true) | ||
| 142 | + | ||
| 143 | + task = AddFriend.create(:person => person1, :friend => person2) | ||
| 144 | + assert_equal false, ProfileSuggestion.find(suggestion.id).enabled | ||
| 145 | + end | ||
| 146 | + | ||
| 140 | end | 147 | end |
test/unit/person_test.rb
| @@ -1458,4 +1458,67 @@ class PersonTest < ActiveSupport::TestCase | @@ -1458,4 +1458,67 @@ class PersonTest < ActiveSupport::TestCase | ||
| 1458 | person.reload | 1458 | person.reload |
| 1459 | end | 1459 | end |
| 1460 | end | 1460 | end |
| 1461 | + | ||
| 1462 | + should 'have a list of suggested people to be friend' do | ||
| 1463 | + person = create_user('person').person | ||
| 1464 | + suggested_friend = fast_create(Person) | ||
| 1465 | + | ||
| 1466 | + ProfileSuggestion.create(:person => person, :suggestion => suggested_friend) | ||
| 1467 | + assert_equal [suggested_friend], person.suggested_people | ||
| 1468 | + end | ||
| 1469 | + | ||
| 1470 | + should 'have a list of suggested communities to be member' do | ||
| 1471 | + person = create_user('person').person | ||
| 1472 | + suggested_community = fast_create(Community) | ||
| 1473 | + | ||
| 1474 | + ProfileSuggestion.create(:person => person, :suggestion => suggested_community) | ||
| 1475 | + assert_equal [suggested_community], person.suggested_communities | ||
| 1476 | + end | ||
| 1477 | + | ||
| 1478 | + should 'remove profile suggestion when person is destroyed' do | ||
| 1479 | + person = create_user('person').person | ||
| 1480 | + suggested_community = fast_create(Community) | ||
| 1481 | + | ||
| 1482 | + suggestion = ProfileSuggestion.create(:person => person, :suggestion => suggested_community) | ||
| 1483 | + | ||
| 1484 | + person.destroy | ||
| 1485 | + assert_raise ActiveRecord::RecordNotFound do | ||
| 1486 | + ProfileSuggestion.find suggestion.id | ||
| 1487 | + end | ||
| 1488 | + end | ||
| 1489 | + | ||
| 1490 | + should 'remove profile suggestion when suggested profile is destroyed' do | ||
| 1491 | + person = create_user('person').person | ||
| 1492 | + suggested_community = fast_create(Community) | ||
| 1493 | + | ||
| 1494 | + suggestion = ProfileSuggestion.create(:person => person, :suggestion => suggested_community) | ||
| 1495 | + | ||
| 1496 | + suggested_community.destroy | ||
| 1497 | + assert_raise ActiveRecord::RecordNotFound do | ||
| 1498 | + ProfileSuggestion.find suggestion.id | ||
| 1499 | + end | ||
| 1500 | + end | ||
| 1501 | + | ||
| 1502 | + should 'not suggest disabled suggestion of people' do | ||
| 1503 | + person = create_user('person').person | ||
| 1504 | + suggested_person = fast_create(Person) | ||
| 1505 | + disabled_suggested_person = fast_create(Person) | ||
| 1506 | + | ||
| 1507 | + enabled_suggestion = ProfileSuggestion.create(:person => person, :suggestion => suggested_person) | ||
| 1508 | + disabled_suggestion = ProfileSuggestion.create(:person => person, :suggestion => disabled_suggested_person, :enabled => false) | ||
| 1509 | + | ||
| 1510 | + assert_equal [suggested_person], person.suggested_people | ||
| 1511 | + end | ||
| 1512 | + | ||
| 1513 | + should 'not suggest disabled suggestion of communities' do | ||
| 1514 | + person = create_user('person').person | ||
| 1515 | + suggested_community = fast_create(Community) | ||
| 1516 | + disabled_suggested_community = fast_create(Community) | ||
| 1517 | + | ||
| 1518 | + enabled_suggestion = ProfileSuggestion.create(:person => person, :suggestion => suggested_community) | ||
| 1519 | + disabled_suggestion = ProfileSuggestion.create(:person => person, :suggestion => disabled_suggested_community, :enabled => false) | ||
| 1520 | + | ||
| 1521 | + assert_equal [suggested_community], person.suggested_communities | ||
| 1522 | + end | ||
| 1523 | + | ||
| 1461 | end | 1524 | end |