Commit e238fd93c80e791062730a0b2cdd8bf7fae10869
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>
Showing
8 changed files
with
35 additions
and
35 deletions
Show diff stats
app/jobs/notify_activity_to_profiles_job.rb
@@ -20,7 +20,7 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) | @@ -20,7 +20,7 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) | ||
20 | ActionTrackerNotification.create(:profile_id => tracked_action.user.id, :action_tracker_id => tracked_action.id) | 20 | ActionTrackerNotification.create(:profile_id => tracked_action.user.id, :action_tracker_id => tracked_action.id) |
21 | 21 | ||
22 | # Notify all followers | 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 | if tracked_action.user.is_a? Organization | 25 | if tracked_action.user.is_a? Organization |
26 | ActionTrackerNotification.connection.execute "insert into action_tracker_notifications(profile_id, action_tracker_id) " + | 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 < ApplicationRecord | @@ -8,7 +8,7 @@ class FavoriteEnterprisePerson < ApplicationRecord | ||
8 | belongs_to :person | 8 | belongs_to :person |
9 | 9 | ||
10 | after_create do |favorite| | 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 | end | 12 | end |
13 | 13 | ||
14 | protected | 14 | protected |
app/models/friendship.rb
@@ -12,7 +12,7 @@ class Friendship < ApplicationRecord | @@ -12,7 +12,7 @@ class Friendship < ApplicationRecord | ||
12 | 12 | ||
13 | circles = friendship.group.blank? ? ['friendships'] : friendship.group.split(',').map(&:strip) | 13 | circles = friendship.group.blank? ? ['friendships'] : friendship.group.split(',').map(&:strip) |
14 | circles.each do |circle| | 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 | end | 16 | end |
17 | end | 17 | end |
18 | 18 | ||
@@ -22,7 +22,7 @@ class Friendship < ApplicationRecord | @@ -22,7 +22,7 @@ class Friendship < ApplicationRecord | ||
22 | 22 | ||
23 | groups = friendship.group.blank? ? ['friendships'] : friendship.group.split(',').map(&:strip) | 23 | groups = friendship.group.blank? ? ['friendships'] : friendship.group.split(',').map(&:strip) |
24 | groups.each do |group| | 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 | friendship.person.remove_profile_from_circle(friendship.friend, circle) if circle | 26 | friendship.person.remove_profile_from_circle(friendship.friend, circle) if circle |
27 | end | 27 | end |
28 | end | 28 | end |
app/models/profile.rb
@@ -728,7 +728,7 @@ private :generate_url, :url_options | @@ -728,7 +728,7 @@ private :generate_url, :url_options | ||
728 | else | 728 | else |
729 | self.affiliate(person, Profile::Roles.admin(environment.id), attributes) if members.count == 0 | 729 | self.affiliate(person, Profile::Roles.admin(environment.id), attributes) if members.count == 0 |
730 | self.affiliate(person, Profile::Roles.member(environment.id), attributes) | 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 | end | 732 | end |
733 | person.tasks.pending.of("InviteMember").select { |t| t.data[:community_id] == self.id }.each { |invite| invite.cancel } | 733 | person.tasks.pending.of("InviteMember").select { |t| t.data[:community_id] == self.id }.each { |invite| invite.cancel } |
734 | remove_from_suggestion_list person | 734 | remove_from_suggestion_list person |
test/unit/external_person_test.rb
@@ -137,7 +137,7 @@ class ExternalPersonTest < ActiveSupport::TestCase | @@ -137,7 +137,7 @@ class ExternalPersonTest < ActiveSupport::TestCase | ||
137 | 137 | ||
138 | should 'be able to follow people' do | 138 | should 'be able to follow people' do |
139 | person = fast_create(Person, :environment_id => Environment.default.id) | 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 | assert_difference "@external_person.followed_profiles.count" do | 142 | assert_difference "@external_person.followed_profiles.count" do |
143 | @external_person.follow(person, circle) | 143 | @external_person.follow(person, circle) |
@@ -146,7 +146,7 @@ class ExternalPersonTest < ActiveSupport::TestCase | @@ -146,7 +146,7 @@ class ExternalPersonTest < ActiveSupport::TestCase | ||
146 | 146 | ||
147 | should 'be able to unfolllow people' do | 147 | should 'be able to unfolllow people' do |
148 | person = fast_create(Person, :environment_id => Environment.default.id) | 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 | @external_person.follow(person, circle) | 150 | @external_person.follow(person, circle) |
151 | 151 | ||
152 | assert_difference "@external_person.followed_profiles.count", -1 do | 152 | assert_difference "@external_person.followed_profiles.count", -1 do |
test/unit/follower_test.rb
@@ -6,8 +6,8 @@ class FollowerTest < ActiveSupport::TestCase | @@ -6,8 +6,8 @@ class FollowerTest < ActiveSupport::TestCase | ||
6 | @person1 = create_user('perso-test-1').person | 6 | @person1 = create_user('perso-test-1').person |
7 | @person2 = create_user('person-test-2').person | 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 | @external_person = ExternalPerson.create!(identifier: 'johnlocke', | 12 | @external_person = ExternalPerson.create!(identifier: 'johnlocke', |
13 | name: 'John Locke', | 13 | name: 'John Locke', |
@@ -29,7 +29,7 @@ class FollowerTest < ActiveSupport::TestCase | @@ -29,7 +29,7 @@ class FollowerTest < ActiveSupport::TestCase | ||
29 | 29 | ||
30 | should 'follow a community' do | 30 | should 'follow a community' do |
31 | community = fast_create(Community) | 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 | assert_difference '@person1.followed_profiles.count' do | 34 | assert_difference '@person1.followed_profiles.count' do |
35 | @person1.follow(community, circle) | 35 | @person1.follow(community, circle) |
@@ -37,13 +37,13 @@ class FollowerTest < ActiveSupport::TestCase | @@ -37,13 +37,13 @@ class FollowerTest < ActiveSupport::TestCase | ||
37 | assert @person1.follows?(community) | 37 | assert @person1.follows?(community) |
38 | end | 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 | person3 = create_user('perso-test-3').person | 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 | person3.follow(@person2, @circle1) | 44 | person3.follow(@person2, @circle1) |
45 | end | 45 | end |
46 | - assert_not @circle1.person.follows?(@person2) | 46 | + assert_not @circle1.owner.follows?(@person2) |
47 | end | 47 | end |
48 | 48 | ||
49 | should 'not follow a community if circle profile type does not match' do | 49 | should 'not follow a community if circle profile type does not match' do |
@@ -56,7 +56,7 @@ class FollowerTest < ActiveSupport::TestCase | @@ -56,7 +56,7 @@ class FollowerTest < ActiveSupport::TestCase | ||
56 | end | 56 | end |
57 | 57 | ||
58 | should 'follow person with external user' do | 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 | assert_difference '@external_person.followed_profiles.count' do | 61 | assert_difference '@external_person.followed_profiles.count' do |
62 | @external_person.follow(@person2, @circle1) | 62 | @external_person.follow(@person2, @circle1) |
@@ -74,7 +74,7 @@ class FollowerTest < ActiveSupport::TestCase | @@ -74,7 +74,7 @@ class FollowerTest < ActiveSupport::TestCase | ||
74 | end | 74 | end |
75 | 75 | ||
76 | should 'unfollow person with external user' do | 76 | should 'unfollow person with external user' do |
77 | - @circle1.update_attributes(person: @external_person) | 77 | + @circle1.update_attributes(owner: @external_person) |
78 | @external_person.follow(@person2, @circle1) | 78 | @external_person.follow(@person2, @circle1) |
79 | 79 | ||
80 | assert_difference '@external_person.followed_profiles.count', -1 do | 80 | assert_difference '@external_person.followed_profiles.count', -1 do |
@@ -93,7 +93,7 @@ class FollowerTest < ActiveSupport::TestCase | @@ -93,7 +93,7 @@ class FollowerTest < ActiveSupport::TestCase | ||
93 | 93 | ||
94 | should 'get the followed profiles for an external user' do | 94 | should 'get the followed profiles for an external user' do |
95 | person3 = create_user('person-test-3').person | 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 | @external_person.follow(@person2, @circle1) | 98 | @external_person.follow(@person2, @circle1) |
99 | @external_person.follow(person3, @circle1) | 99 | @external_person.follow(person3, @circle1) |
@@ -101,7 +101,7 @@ class FollowerTest < ActiveSupport::TestCase | @@ -101,7 +101,7 @@ class FollowerTest < ActiveSupport::TestCase | ||
101 | end | 101 | end |
102 | 102 | ||
103 | should 'not follow same person twice even with different circles' do | 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 | @person1.follow(@person2, @circle1) | 106 | @person1.follow(@person2, @circle1) |
107 | @person1.follow(@person2, @circle2) | 107 | @person1.follow(@person2, @circle2) |
@@ -118,28 +118,28 @@ class FollowerTest < ActiveSupport::TestCase | @@ -118,28 +118,28 @@ class FollowerTest < ActiveSupport::TestCase | ||
118 | end | 118 | end |
119 | 119 | ||
120 | should 'update profile circles for a person' do | 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 | @person1.follow(@person2, [@circle1, @circle2]) | 122 | @person1.follow(@person2, [@circle1, @circle2]) |
123 | 123 | ||
124 | @person1.update_profile_circles(@person2, [@circle2, circle3]) | 124 | @person1.update_profile_circles(@person2, [@circle2, circle3]) |
125 | - assert_equivalent [@circle2, circle3], @person2.in_circles | 125 | + assert_equivalent [@circle2, circle3], @person2.circles |
126 | end | 126 | end |
127 | 127 | ||
128 | should 'keep other follower circles after update' do | 128 | should 'keep other follower circles after update' do |
129 | person3 = create_user('person-test-3').person | 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 | @person1.follow(@person2, @circle1) | 131 | @person1.follow(@person2, @circle1) |
132 | person3.follow(@person2, circle3) | 132 | person3.follow(@person2, circle3) |
133 | 133 | ||
134 | @person1.update_profile_circles(@person2, [@circle1, @circle2]) | 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 | end | 136 | end |
137 | 137 | ||
138 | should 'remove a person from a circle' do | 138 | should 'remove a person from a circle' do |
139 | @person1.follow(@person2, [@circle1, @circle2]) | 139 | @person1.follow(@person2, [@circle1, @circle2]) |
140 | 140 | ||
141 | @person1.remove_profile_from_circle(@person2, @circle2) | 141 | @person1.remove_profile_from_circle(@person2, @circle2) |
142 | - assert_equivalent [@circle1], @person2.in_circles | 142 | + assert_equivalent [@circle1], @person2.circles |
143 | end | 143 | end |
144 | 144 | ||
145 | should 'not remove a person from a circle if the user is not the owner' do | 145 | should 'not remove a person from a circle if the user is not the owner' do |
@@ -147,6 +147,6 @@ class FollowerTest < ActiveSupport::TestCase | @@ -147,6 +147,6 @@ class FollowerTest < ActiveSupport::TestCase | ||
147 | @person1.follow(@person2, [@circle1, @circle2]) | 147 | @person1.follow(@person2, [@circle1, @circle2]) |
148 | 148 | ||
149 | person3.remove_profile_from_circle(@person2, @circle2) | 149 | person3.remove_profile_from_circle(@person2, @circle2) |
150 | - assert_equivalent [@circle1, @circle2], @person2.in_circles | 150 | + assert_equivalent [@circle1, @circle2], @person2.circles |
151 | end | 151 | end |
152 | end | 152 | end |
test/unit/person_test.rb
@@ -843,8 +843,8 @@ class PersonTest < ActiveSupport::TestCase | @@ -843,8 +843,8 @@ class PersonTest < ActiveSupport::TestCase | ||
843 | p3 = fast_create(Person) | 843 | p3 = fast_create(Person) |
844 | p4 = fast_create(Person) | 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 | p2.follow(p1, circle2) | 849 | p2.follow(p1, circle2) |
850 | assert p2.follows?(p1) | 850 | assert p2.follows?(p1) |
@@ -889,8 +889,8 @@ class PersonTest < ActiveSupport::TestCase | @@ -889,8 +889,8 @@ class PersonTest < ActiveSupport::TestCase | ||
889 | p3 = fast_create(Person) | 889 | p3 = fast_create(Person) |
890 | p4 = fast_create(Person) | 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 | p2.follow(p1, circle2) | 894 | p2.follow(p1, circle2) |
895 | assert p2.follows?(p1) | 895 | assert p2.follows?(p1) |
896 | refute p3.follows?(p1) | 896 | refute p3.follows?(p1) |
test/unit/profile_test.rb
@@ -2237,15 +2237,15 @@ class ProfileTest < ActiveSupport::TestCase | @@ -2237,15 +2237,15 @@ class ProfileTest < ActiveSupport::TestCase | ||
2237 | person1 = create_user('testperson-1').person | 2237 | person1 = create_user('testperson-1').person |
2238 | person2 = create_user('testperson-2').person | 2238 | person2 = create_user('testperson-2').person |
2239 | person3 = create_user('testperson-3').person | 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 | person1.follow(person3, circle1) | 2244 | person1.follow(person3, circle1) |
2245 | person1.follow(person3, circle2) | 2245 | person1.follow(person3, circle2) |
2246 | person2.follow(person3, circle3) | 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 | assert_equivalent person3.followers, [person1, person2] | 2249 | assert_equivalent person3.followers, [person1, person2] |
2250 | end | 2250 | end |
2251 | 2251 | ||
@@ -2253,8 +2253,8 @@ class ProfileTest < ActiveSupport::TestCase | @@ -2253,8 +2253,8 @@ class ProfileTest < ActiveSupport::TestCase | ||
2253 | person1 = create_user('testperson-1').person | 2253 | person1 = create_user('testperson-1').person |
2254 | person2 = create_user('testperson-2').person | 2254 | person2 = create_user('testperson-2').person |
2255 | community = fast_create(Community) | 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 | person1.follow(person2, circle1) | 2259 | person1.follow(person2, circle1) |
2260 | person1.follow(community, circle2) | 2260 | person1.follow(community, circle2) |
@@ -2267,8 +2267,8 @@ class ProfileTest < ActiveSupport::TestCase | @@ -2267,8 +2267,8 @@ class ProfileTest < ActiveSupport::TestCase | ||
2267 | created_at: Date.yesterday) | 2267 | created_at: Date.yesterday) |
2268 | person = create_user('testperson-2').person | 2268 | person = create_user('testperson-2').person |
2269 | community = fast_create(Community) | 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 | external_person.follow(person, circle1) | 2273 | external_person.follow(person, circle1) |
2274 | external_person.follow(community, circle2) | 2274 | external_person.follow(community, circle2) |