Commit e238fd93c80e791062730a0b2cdd8bf7fae10869

Authored by Dylan Guedes
1 parent fab2d51b

Fixes tests to use new circle relationships

Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
Signed-off-by: DylanGuedes <djmgguedes@gmail.com>
app/jobs/notify_activity_to_profiles_job.rb
... ... @@ -20,7 +20,7 @@ class NotifyActivityToProfilesJob &lt; Struct.new(:tracked_action_id)
20 20 ActionTrackerNotification.create(:profile_id => tracked_action.user.id, :action_tracker_id => tracked_action.id)
21 21  
22 22 # Notify all followers
23   - ActionTrackerNotification.connection.execute("INSERT INTO action_tracker_notifications(profile_id, action_tracker_id) SELECT DISTINCT c.person_id, #{tracked_action.id} FROM profiles_circles AS p JOIN circles as c ON c.id = p.circle_id WHERE p.profile_id = #{tracked_action.user.id} AND (c.person_id NOT IN (SELECT atn.profile_id FROM action_tracker_notifications AS atn WHERE atn.action_tracker_id = #{tracked_action.id}))")
  23 + ActionTrackerNotification.connection.execute("INSERT INTO action_tracker_notifications(profile_id, action_tracker_id) SELECT DISTINCT c.owner_id, #{tracked_action.id} FROM profiles_circles AS p JOIN circles as c ON c.id = p.circle_id WHERE p.profile_id = #{tracked_action.user.id} AND (c.owner_id NOT IN (SELECT atn.profile_id FROM action_tracker_notifications AS atn WHERE atn.action_tracker_id = #{tracked_action.id}))")
24 24  
25 25 if tracked_action.user.is_a? Organization
26 26 ActionTrackerNotification.connection.execute "insert into action_tracker_notifications(profile_id, action_tracker_id) " +
... ...
app/models/favorite_enterprise_person.rb
... ... @@ -8,7 +8,7 @@ class FavoriteEnterprisePerson &lt; ApplicationRecord
8 8 belongs_to :person
9 9  
10 10 after_create do |favorite|
11   - favorite.person.follow(favorite.enterprise, Circle.find_or_create_by(:person => favorite.person, :name =>_('favorites'), :profile_type => 'Enterprise'))
  11 + favorite.person.follow(favorite.enterprise, Circle.find_or_create_by(:owner => favorite.person, :name =>_('favorites'), :profile_type => 'Enterprise'))
12 12 end
13 13  
14 14 protected
... ...
app/models/friendship.rb
... ... @@ -12,7 +12,7 @@ class Friendship &lt; ApplicationRecord
12 12  
13 13 circles = friendship.group.blank? ? ['friendships'] : friendship.group.split(',').map(&:strip)
14 14 circles.each do |circle|
15   - friendship.person.follow(friendship.friend, Circle.find_or_create_by(:person => friendship.person, :name => circle, :profile_type => 'Person'))
  15 + friendship.person.follow(friendship.friend, Circle.find_or_create_by(:owner => friendship.person, :name => circle, :profile_type => 'Person'))
16 16 end
17 17 end
18 18  
... ... @@ -22,7 +22,7 @@ class Friendship &lt; ApplicationRecord
22 22  
23 23 groups = friendship.group.blank? ? ['friendships'] : friendship.group.split(',').map(&:strip)
24 24 groups.each do |group|
25   - circle = Circle.find_by(:person => friendship.person, :name => group )
  25 + circle = Circle.find_by(:owner => friendship.person, :name => group )
26 26 friendship.person.remove_profile_from_circle(friendship.friend, circle) if circle
27 27 end
28 28 end
... ...
app/models/profile.rb
... ... @@ -728,7 +728,7 @@ private :generate_url, :url_options
728 728 else
729 729 self.affiliate(person, Profile::Roles.admin(environment.id), attributes) if members.count == 0
730 730 self.affiliate(person, Profile::Roles.member(environment.id), attributes)
731   - person.follow(self, Circle.find_or_create_by(:person => person, :name =>_('memberships'), :profile_type => 'Community'))
  731 + person.follow(self, Circle.find_or_create_by(:owner => person, :name =>_('memberships'), :profile_type => self.class.name))
732 732 end
733 733 person.tasks.pending.of("InviteMember").select { |t| t.data[:community_id] == self.id }.each { |invite| invite.cancel }
734 734 remove_from_suggestion_list person
... ...
test/unit/external_person_test.rb
... ... @@ -137,7 +137,7 @@ class ExternalPersonTest &lt; ActiveSupport::TestCase
137 137  
138 138 should 'be able to follow people' do
139 139 person = fast_create(Person, :environment_id => Environment.default.id)
140   - circle = Circle.create(person: @external_person, profile_type: "Person", name: "FRIENDSSS")
  140 + circle = Circle.create(owner: @external_person, profile_type: "Person", name: "FRIENDSSS")
141 141  
142 142 assert_difference "@external_person.followed_profiles.count" do
143 143 @external_person.follow(person, circle)
... ... @@ -146,7 +146,7 @@ class ExternalPersonTest &lt; ActiveSupport::TestCase
146 146  
147 147 should 'be able to unfolllow people' do
148 148 person = fast_create(Person, :environment_id => Environment.default.id)
149   - circle = Circle.create(person: @external_person, profile_type: "Person", name: "FRIENDSSS")
  149 + circle = Circle.create(owner: @external_person, profile_type: "Person", name: "FRIENDSSS")
150 150 @external_person.follow(person, circle)
151 151  
152 152 assert_difference "@external_person.followed_profiles.count", -1 do
... ...
test/unit/follower_test.rb
... ... @@ -6,8 +6,8 @@ class FollowerTest &lt; ActiveSupport::TestCase
6 6 @person1 = create_user('perso-test-1').person
7 7 @person2 = create_user('person-test-2').person
8 8  
9   - @circle1 = Circle.create!(person: @person1, name: "Zombies", profile_type: 'Person')
10   - @circle2 = Circle.create!(person: @person1, name: "Humans", profile_type: 'Person')
  9 + @circle1 = Circle.create!(owner: @person1, name: "Zombies", profile_type: 'Person')
  10 + @circle2 = Circle.create!(owner: @person1, name: "Humans", profile_type: 'Person')
11 11  
12 12 @external_person = ExternalPerson.create!(identifier: 'johnlocke',
13 13 name: 'John Locke',
... ... @@ -29,7 +29,7 @@ class FollowerTest &lt; ActiveSupport::TestCase
29 29  
30 30 should 'follow a community' do
31 31 community = fast_create(Community)
32   - circle = Circle.create!(person: @person1, name: "Terminus", profile_type: 'Community')
  32 + circle = Circle.create!(owner: @person1, name: "Terminus", profile_type: 'Community')
33 33  
34 34 assert_difference '@person1.followed_profiles.count' do
35 35 @person1.follow(community, circle)
... ... @@ -37,13 +37,13 @@ class FollowerTest &lt; ActiveSupport::TestCase
37 37 assert @person1.follows?(community)
38 38 end
39 39  
40   - should 'not follow person if the user is not the ownner of the circle' do
  40 + should 'not follow person if the user is not the owner of the circle' do
41 41 person3 = create_user('perso-test-3').person
42 42  
43   - assert_no_difference '@circle1.person.followed_profiles.count' do
  43 + assert_no_difference '@circle1.owner.followed_profiles.count' do
44 44 person3.follow(@person2, @circle1)
45 45 end
46   - assert_not @circle1.person.follows?(@person2)
  46 + assert_not @circle1.owner.follows?(@person2)
47 47 end
48 48  
49 49 should 'not follow a community if circle profile type does not match' do
... ... @@ -56,7 +56,7 @@ class FollowerTest &lt; ActiveSupport::TestCase
56 56 end
57 57  
58 58 should 'follow person with external user' do
59   - @circle1.update_attributes(person: @external_person)
  59 + @circle1.update_attributes(owner: @external_person)
60 60  
61 61 assert_difference '@external_person.followed_profiles.count' do
62 62 @external_person.follow(@person2, @circle1)
... ... @@ -74,7 +74,7 @@ class FollowerTest &lt; ActiveSupport::TestCase
74 74 end
75 75  
76 76 should 'unfollow person with external user' do
77   - @circle1.update_attributes(person: @external_person)
  77 + @circle1.update_attributes(owner: @external_person)
78 78 @external_person.follow(@person2, @circle1)
79 79  
80 80 assert_difference '@external_person.followed_profiles.count', -1 do
... ... @@ -93,7 +93,7 @@ class FollowerTest &lt; ActiveSupport::TestCase
93 93  
94 94 should 'get the followed profiles for an external user' do
95 95 person3 = create_user('person-test-3').person
96   - @circle1.update_attributes(person: @external_person)
  96 + @circle1.update_attributes(owner: @external_person)
97 97  
98 98 @external_person.follow(@person2, @circle1)
99 99 @external_person.follow(person3, @circle1)
... ... @@ -101,7 +101,7 @@ class FollowerTest &lt; ActiveSupport::TestCase
101 101 end
102 102  
103 103 should 'not follow same person twice even with different circles' do
104   - circle3 = Circle.create!(person: @person1, name: "Free Folk", profile_type: 'Person')
  104 + circle3 = Circle.create!(owner: @person1, name: "Free Folk", profile_type: 'Person')
105 105  
106 106 @person1.follow(@person2, @circle1)
107 107 @person1.follow(@person2, @circle2)
... ... @@ -118,28 +118,28 @@ class FollowerTest &lt; ActiveSupport::TestCase
118 118 end
119 119  
120 120 should 'update profile circles for a person' do
121   - circle3 = Circle.create!(person: @person1, name: "Brains", profile_type: 'Person')
  121 + circle3 = Circle.create!(owner: @person1, name: "Brains", profile_type: 'Person')
122 122 @person1.follow(@person2, [@circle1, @circle2])
123 123  
124 124 @person1.update_profile_circles(@person2, [@circle2, circle3])
125   - assert_equivalent [@circle2, circle3], @person2.in_circles
  125 + assert_equivalent [@circle2, circle3], @person2.circles
126 126 end
127 127  
128 128 should 'keep other follower circles after update' do
129 129 person3 = create_user('person-test-3').person
130   - circle3 = Circle.create!(person: person3, name: "Humans", profile_type: 'Person')
  130 + circle3 = Circle.create!(owner: person3, name: "Humans", profile_type: 'Person')
131 131 @person1.follow(@person2, @circle1)
132 132 person3.follow(@person2, circle3)
133 133  
134 134 @person1.update_profile_circles(@person2, [@circle1, @circle2])
135   - assert_equivalent [@circle1, @circle2, circle3], @person2.in_circles
  135 + assert_equivalent [@circle1, @circle2, circle3], @person2.circles
136 136 end
137 137  
138 138 should 'remove a person from a circle' do
139 139 @person1.follow(@person2, [@circle1, @circle2])
140 140  
141 141 @person1.remove_profile_from_circle(@person2, @circle2)
142   - assert_equivalent [@circle1], @person2.in_circles
  142 + assert_equivalent [@circle1], @person2.circles
143 143 end
144 144  
145 145 should 'not remove a person from a circle if the user is not the owner' do
... ... @@ -147,6 +147,6 @@ class FollowerTest &lt; ActiveSupport::TestCase
147 147 @person1.follow(@person2, [@circle1, @circle2])
148 148  
149 149 person3.remove_profile_from_circle(@person2, @circle2)
150   - assert_equivalent [@circle1, @circle2], @person2.in_circles
  150 + assert_equivalent [@circle1, @circle2], @person2.circles
151 151 end
152 152 end
... ...
test/unit/person_test.rb
... ... @@ -843,8 +843,8 @@ class PersonTest &lt; ActiveSupport::TestCase
843 843 p3 = fast_create(Person)
844 844 p4 = fast_create(Person)
845 845  
846   - circle2 = Circle.create!(:person=> p2, :name => "Zombies", :profile_type => 'Person')
847   - circle4 = Circle.create!(:person=> p4, :name => "Zombies", :profile_type => 'Person')
  846 + circle2 = Circle.create!(:owner => p2, :name => "Zombies", :profile_type => 'Person')
  847 + circle4 = Circle.create!(:owner => p4, :name => "Zombies", :profile_type => 'Person')
848 848  
849 849 p2.follow(p1, circle2)
850 850 assert p2.follows?(p1)
... ... @@ -889,8 +889,8 @@ class PersonTest &lt; ActiveSupport::TestCase
889 889 p3 = fast_create(Person)
890 890 p4 = fast_create(Person)
891 891  
892   - circle2 = Circle.create!(:person=> p2, :name => "Zombies", :profile_type => 'Person')
893   - circle4 = Circle.create!(:person=> p4, :name => "Zombies", :profile_type => 'Person')
  892 + circle2 = Circle.create!(:owner => p2, :name => "Zombies", :profile_type => 'Person')
  893 + circle4 = Circle.create!(:owner => p4, :name => "Zombies", :profile_type => 'Person')
894 894 p2.follow(p1, circle2)
895 895 assert p2.follows?(p1)
896 896 refute p3.follows?(p1)
... ...
test/unit/profile_test.rb
... ... @@ -2237,15 +2237,15 @@ class ProfileTest &lt; ActiveSupport::TestCase
2237 2237 person1 = create_user('testperson-1').person
2238 2238 person2 = create_user('testperson-2').person
2239 2239 person3 = create_user('testperson-3').person
2240   - circle1 = Circle.create!(:person => person1, :name => "Night's Watch", :profile_type => 'Person')
2241   - circle2 = Circle.create!(:person => person1, :name => "Free Folk", :profile_type => 'Person')
2242   - circle3 = Circle.create!(:person => person2, :name => "The Unsullied", :profile_type => 'Person')
  2240 + circle1 = Circle.create!(:owner => person1, :name => "Night's Watch", :profile_type => 'Person')
  2241 + circle2 = Circle.create!(:owner => person1, :name => "Free Folk", :profile_type => 'Person')
  2242 + circle3 = Circle.create!(:owner => person2, :name => "The Unsullied", :profile_type => 'Person')
2243 2243  
2244 2244 person1.follow(person3, circle1)
2245 2245 person1.follow(person3, circle2)
2246 2246 person2.follow(person3, circle3)
2247 2247  
2248   - assert_equivalent person3.in_circles, [circle1, circle2, circle3]
  2248 + assert_equivalent person3.circles, [circle1, circle2, circle3]
2249 2249 assert_equivalent person3.followers, [person1, person2]
2250 2250 end
2251 2251  
... ... @@ -2253,8 +2253,8 @@ class ProfileTest &lt; ActiveSupport::TestCase
2253 2253 person1 = create_user('testperson-1').person
2254 2254 person2 = create_user('testperson-2').person
2255 2255 community = fast_create(Community)
2256   - circle1 = Circle.create!(:person => person1, :name => "Night's Watch", :profile_type => 'Person')
2257   - circle2 = Circle.create!(:person => person1, :name => "Free Folk", :profile_type => 'Community')
  2256 + circle1 = Circle.create!(:owner => person1, :name => "Night's Watch", :profile_type => 'Person')
  2257 + circle2 = Circle.create!(:owner => person1, :name => "Free Folk", :profile_type => 'Community')
2258 2258  
2259 2259 person1.follow(person2, circle1)
2260 2260 person1.follow(community, circle2)
... ... @@ -2267,8 +2267,8 @@ class ProfileTest &lt; ActiveSupport::TestCase
2267 2267 created_at: Date.yesterday)
2268 2268 person = create_user('testperson-2').person
2269 2269 community = fast_create(Community)
2270   - circle1 = Circle.create!(:person => external_person, :name => "Night's Watch", :profile_type => 'Person')
2271   - circle2 = Circle.create!(:person => external_person, :name => "Free Folk", :profile_type => 'Community')
  2270 + circle1 = Circle.create!(:owner => external_person, :name => "Night's Watch", :profile_type => 'Person')
  2271 + circle2 = Circle.create!(:owner => external_person, :name => "Free Folk", :profile_type => 'Community')
2272 2272  
2273 2273 external_person.follow(person, circle1)
2274 2274 external_person.follow(community, circle2)
... ...