Commit 10b1a6da87c1046b67a2fb80a38742c4d1cb4f4f

Authored by Marcos Pereira
1 parent 08bf9a98

fixes tests

test/unit/article_test.rb
... ... @@ -1099,9 +1099,9 @@ class ArticleTest < ActiveSupport::TestCase
1099 1099 assert_equal 3, ActionTrackerNotification.where(action_tracker_id: second_activity.id).count
1100 1100 end
1101 1101  
1102   - should 'create notifications to friends when creating an article' do
  1102 + should 'create notifications to followers when creating an article' do
1103 1103 friend = fast_create(Person)
1104   - profile.add_friend(friend)
  1104 + friend.follow(profile)
1105 1105 Article.destroy_all
1106 1106 ActionTracker::Record.destroy_all
1107 1107 ActionTrackerNotification.destroy_all
... ... @@ -1112,9 +1112,9 @@ class ArticleTest < ActiveSupport::TestCase
1112 1112 assert_equal friend, ActionTrackerNotification.last.profile
1113 1113 end
1114 1114  
1115   - should 'create the notification to the friend when one friend has the notification and the other no' do
  1115 + should 'create the notification to the follower when one follower has the notification and the other no' do
1116 1116 f1 = fast_create(Person)
1117   - profile.add_friend(f1)
  1117 + f1.follow(profile)
1118 1118  
1119 1119 User.current = profile.user
1120 1120 article = create TinyMceArticle, :name => 'Tracked Article 1', :profile_id => profile.id
... ... @@ -1123,16 +1123,17 @@ class ArticleTest < ActiveSupport::TestCase
1123 1123 assert_equal 2, ActionTrackerNotification.where(action_tracker_id: article.activity.id).count
1124 1124  
1125 1125 f2 = fast_create(Person)
1126   - profile.add_friend(f2)
  1126 + f2.follow(profile)
  1127 +
1127 1128 article2 = create TinyMceArticle, :name => 'Tracked Article 2', :profile_id => profile.id
1128 1129 assert_equal 2, ActionTracker::Record.where(verb: 'create_article').count
1129 1130 process_delayed_job_queue
1130 1131 assert_equal 3, ActionTrackerNotification.where(action_tracker_id: article2.activity.id).count
1131 1132 end
1132 1133  
1133   - should 'destroy activity and notifications of friends when destroying an article' do
  1134 + should 'destroy activity and notifications of followers when destroying an article' do
1134 1135 friend = fast_create(Person)
1135   - profile.add_friend(friend)
  1136 + friend.follow(profile)
1136 1137 Article.destroy_all
1137 1138 ActionTracker::Record.destroy_all
1138 1139 ActionTrackerNotification.destroy_all
... ...
test/unit/notify_activity_to_profiles_job_test.rb
... ... @@ -24,15 +24,15 @@ class NotifyActivityToProfilesJobTest < ActiveSupport::TestCase
24 24 end
25 25 end
26 26  
27   - should 'notify just the users and his friends tracking user actions' do
  27 + should 'notify just the users and his followers tracking user actions' do
28 28 person = fast_create(Person)
29 29 community = fast_create(Community)
30 30 action_tracker = fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person.id, :target_type => 'Profile', :verb => 'create_article')
31 31 refute NotifyActivityToProfilesJob::NOTIFY_ONLY_COMMUNITY.include?(action_tracker.verb)
32 32 p1, p2, m1, m2 = fast_create(Person), fast_create(Person), fast_create(Person), fast_create(Person)
33   - fast_create(Friendship, :person_id => person.id, :friend_id => p1.id)
34   - fast_create(Friendship, :person_id => person.id, :friend_id => p2.id)
35   - fast_create(Friendship, :person_id => p1.id, :friend_id => m1.id)
  33 + fast_create(ProfileFollower, :profile_id => person.id, :follower_id => p1.id)
  34 + fast_create(ProfileFollower, :profile_id => person.id, :follower_id => p2.id)
  35 + fast_create(ProfileFollower, :profile_id => m1.id, :follower_id => person.id)
36 36 fast_create(RoleAssignment, :accessor_id => m2.id, :role_id => 3, :resource_id => community.id)
37 37 ActionTrackerNotification.delete_all
38 38 job = NotifyActivityToProfilesJob.new(action_tracker.id)
... ... @@ -66,23 +66,21 @@ class NotifyActivityToProfilesJobTest < ActiveSupport::TestCase
66 66 end
67 67 end
68 68  
69   - should 'notify users its friends, the community and its members' do
  69 + should 'notify users its followers, the community and its members' do
70 70 person = fast_create(Person)
71 71 community = fast_create(Community)
72 72 action_tracker = fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person.id, :target_type => 'Profile', :target_id => community.id, :verb => 'create_article')
73 73 refute NotifyActivityToProfilesJob::NOTIFY_ONLY_COMMUNITY.include?(action_tracker.verb)
74 74 p1, p2, m1, m2 = fast_create(Person), fast_create(Person), fast_create(Person), fast_create(Person)
75   - fast_create(Friendship, :person_id => person.id, :friend_id => p1.id)
76   - fast_create(Friendship, :person_id => person.id, :friend_id => p2.id)
  75 + fast_create(ProfileFollower, :profile_id => person.id, :follower_id => p1.id)
77 76 fast_create(RoleAssignment, :accessor_id => m1.id, :role_id => 3, :resource_id => community.id)
78 77 fast_create(RoleAssignment, :accessor_id => m2.id, :role_id => 3, :resource_id => community.id)
79 78 ActionTrackerNotification.delete_all
80 79 job = NotifyActivityToProfilesJob.new(action_tracker.id)
81 80 job.perform
82 81 process_delayed_job_queue
83   -
84   - assert_equal 6, ActionTrackerNotification.count
85   - [person, community, p1, p2, m1, m2].each do |profile|
  82 + assert_equal 5, ActionTrackerNotification.count
  83 + [person, community, p1, m1, m2].each do |profile|
86 84 notification = ActionTrackerNotification.find_by profile_id: profile.id
87 85 assert_equal action_tracker, notification.action_tracker
88 86 end
... ... @@ -119,8 +117,8 @@ class NotifyActivityToProfilesJobTest < ActiveSupport::TestCase
119 117 action_tracker = fast_create(ActionTracker::Record, :user_type => 'Profile', :user_id => person.id, :target_type => 'Profile', :target_id => community.id, :verb => 'join_community')
120 118 refute NotifyActivityToProfilesJob::NOTIFY_ONLY_COMMUNITY.include?(action_tracker.verb)
121 119 p1, p2, m1, m2 = fast_create(Person), fast_create(Person), fast_create(Person), fast_create(Person)
122   - fast_create(Friendship, :person_id => person.id, :friend_id => p1.id)
123   - fast_create(Friendship, :person_id => person.id, :friend_id => p2.id)
  120 + fast_create(ProfileFollower, :profile_id => person.id, :follower_id => p1.id)
  121 + fast_create(ProfileFollower, :profile_id => person.id, :follower_id => p2.id)
124 122 fast_create(RoleAssignment, :accessor_id => m1.id, :role_id => 3, :resource_id => community.id)
125 123 fast_create(RoleAssignment, :accessor_id => m2.id, :role_id => 3, :resource_id => community.id)
126 124 ActionTrackerNotification.delete_all
... ...
test/unit/person_test.rb
... ... @@ -728,7 +728,7 @@ class PersonTest < ActiveSupport::TestCase
728 728 assert_equal [s4], p2.scraps_received.not_replies
729 729 end
730 730  
731   - should "the followed_by method be protected and true to the person friends and herself by default" do
  731 + should "the followed_by method return true to the person friends and herself by default" do
732 732 p1 = fast_create(Person)
733 733 p2 = fast_create(Person)
734 734 p3 = fast_create(Person)
... ... @@ -740,9 +740,9 @@ class PersonTest < ActiveSupport::TestCase
740 740 assert p1.is_a_friend?(p4)
741 741  
742 742 assert_equal true, p1.send(:followed_by?,p1)
743   - assert_equal true, p1.send(:followed_by?,p2)
744   - assert_equal true, p1.send(:followed_by?,p4)
745   - assert_equal false, p1.send(:followed_by?,p3)
  743 + assert_equal true, p2.send(:followed_by?,p1)
  744 + assert_equal true, p4.send(:followed_by?,p1)
  745 + assert_equal false, p3.send(:followed_by?,p1)
746 746 end
747 747  
748 748 should "the person follows her friends and herself by default" do
... ... @@ -757,9 +757,9 @@ class PersonTest < ActiveSupport::TestCase
757 757 assert p4.is_a_friend?(p1)
758 758  
759 759 assert_equal true, p1.follows?(p1)
760   - assert_equal true, p1.follows?(p2)
761   - assert_equal true, p1.follows?(p4)
762   - assert_equal false, p1.follows?(p3)
  760 + assert_equal true, p2.follows?(p1)
  761 + assert_equal true, p4.follows?(p1)
  762 + assert_equal false, p3.follows?(p1)
763 763 end
764 764  
765 765 should "a person member of a community follows the community" do
... ... @@ -836,18 +836,18 @@ class PersonTest < ActiveSupport::TestCase
836 836 assert_nil Scrap.find_by(id: scrap.id)
837 837 end
838 838  
839   - should "the tracked action be notified to person friends and herself" do
  839 + should "the tracked action be notified to person followers and herself" do
840 840 Person.destroy_all
841 841 p1 = fast_create(Person)
842 842 p2 = fast_create(Person)
843 843 p3 = fast_create(Person)
844 844 p4 = fast_create(Person)
845 845  
846   - p1.add_friend(p2)
847   - assert p1.is_a_friend?(p2)
848   - refute p1.is_a_friend?(p3)
849   - p1.add_friend(p4)
850   - assert p1.is_a_friend?(p4)
  846 + p2.follow(p1)
  847 + assert p2.follows?(p1)
  848 + refute p3.follows?(p1)
  849 + p4.follow(p1)
  850 + assert p4.follows?(p1)
851 851  
852 852 action_tracker = fast_create(ActionTracker::Record, :user_id => p1.id)
853 853 ActionTrackerNotification.delete_all
... ... @@ -880,17 +880,17 @@ class PersonTest < ActiveSupport::TestCase
880 880 end
881 881 end
882 882  
883   - should "the tracked action notify friends with one delayed job process" do
  883 + should "the tracked action notify followers with one delayed job process" do
884 884 p1 = fast_create(Person)
885 885 p2 = fast_create(Person)
886 886 p3 = fast_create(Person)
887 887 p4 = fast_create(Person)
888 888  
889   - p1.add_friend(p2)
890   - assert p1.is_a_friend?(p2)
891   - refute p1.is_a_friend?(p3)
892   - p1.add_friend(p4)
893   - assert p1.is_a_friend?(p4)
  889 + p2.follow(p1)
  890 + assert p2.follows?(p1)
  891 + refute p3.follows?(p1)
  892 + p4.follow(p1)
  893 + assert p4.follows?(p1)
894 894  
895 895 action_tracker = fast_create(ActionTracker::Record, :user_id => p1.id)
896 896  
... ... @@ -1039,6 +1039,7 @@ class PersonTest < ActiveSupport::TestCase
1039 1039 process_delayed_job_queue
1040 1040 c.add_member(p3)
1041 1041 process_delayed_job_queue
  1042 +
1042 1043 assert_equal 4, ActionTracker::Record.count
1043 1044 assert_equal 5, ActionTrackerNotification.count
1044 1045 has_add_member_notification = false
... ...
test/unit/scrap_test.rb
... ... @@ -125,11 +125,11 @@ class ScrapTest < ActiveSupport::TestCase
125 125 assert_equal c, ta.target
126 126 end
127 127  
128   - should "notify leave_scrap action tracker verb to friends and itself" do
  128 + should "notify leave_scrap action tracker verb to followers and itself" do
129 129 User.current = create_user
130 130 p1 = User.current.person
131 131 p2 = create_user.person
132   - p1.add_friend(p2)
  132 + p2.add_friend(p1)
133 133 process_delayed_job_queue
134 134 s = Scrap.new
135 135 s.sender= p1
... ... @@ -180,11 +180,11 @@ class ScrapTest < ActiveSupport::TestCase
180 180 assert_equal p, ta.user
181 181 end
182 182  
183   - should "notify leave_scrap_to_self action tracker verb to friends and itself" do
  183 + should "notify leave_scrap_to_self action tracker verb to followers and itself" do
184 184 User.current = create_user
185 185 p1 = User.current.person
186 186 p2 = create_user.person
187   - p1.add_friend(p2)
  187 + p2.add_friend(p1)
188 188 ActionTrackerNotification.delete_all
189 189 Delayed::Job.delete_all
190 190 s = Scrap.new
... ...