From e238fd93c80e791062730a0b2cdd8bf7fae10869 Mon Sep 17 00:00:00 2001 From: DylanGuedes Date: Tue, 23 Aug 2016 09:53:36 -0300 Subject: [PATCH] Fixes tests to use new circle relationships --- app/jobs/notify_activity_to_profiles_job.rb | 2 +- app/models/favorite_enterprise_person.rb | 2 +- app/models/friendship.rb | 4 ++-- app/models/profile.rb | 2 +- test/unit/external_person_test.rb | 4 ++-- test/unit/follower_test.rb | 32 ++++++++++++++++---------------- test/unit/person_test.rb | 8 ++++---- test/unit/profile_test.rb | 16 ++++++++-------- 8 files changed, 35 insertions(+), 35 deletions(-) diff --git a/app/jobs/notify_activity_to_profiles_job.rb b/app/jobs/notify_activity_to_profiles_job.rb index 42d6f88..4b80ff6 100644 --- a/app/jobs/notify_activity_to_profiles_job.rb +++ b/app/jobs/notify_activity_to_profiles_job.rb @@ -20,7 +20,7 @@ class NotifyActivityToProfilesJob < Struct.new(:tracked_action_id) ActionTrackerNotification.create(:profile_id => tracked_action.user.id, :action_tracker_id => tracked_action.id) # Notify all followers - 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}))") + 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}))") if tracked_action.user.is_a? Organization ActionTrackerNotification.connection.execute "insert into action_tracker_notifications(profile_id, action_tracker_id) " + diff --git a/app/models/favorite_enterprise_person.rb b/app/models/favorite_enterprise_person.rb index 7312ff0..56ff15a 100644 --- a/app/models/favorite_enterprise_person.rb +++ b/app/models/favorite_enterprise_person.rb @@ -8,7 +8,7 @@ class FavoriteEnterprisePerson < ApplicationRecord belongs_to :person after_create do |favorite| - favorite.person.follow(favorite.enterprise, Circle.find_or_create_by(:person => favorite.person, :name =>_('favorites'), :profile_type => 'Enterprise')) + favorite.person.follow(favorite.enterprise, Circle.find_or_create_by(:owner => favorite.person, :name =>_('favorites'), :profile_type => 'Enterprise')) end protected diff --git a/app/models/friendship.rb b/app/models/friendship.rb index 7a6927b..d751fe4 100644 --- a/app/models/friendship.rb +++ b/app/models/friendship.rb @@ -12,7 +12,7 @@ class Friendship < ApplicationRecord circles = friendship.group.blank? ? ['friendships'] : friendship.group.split(',').map(&:strip) circles.each do |circle| - friendship.person.follow(friendship.friend, Circle.find_or_create_by(:person => friendship.person, :name => circle, :profile_type => 'Person')) + friendship.person.follow(friendship.friend, Circle.find_or_create_by(:owner => friendship.person, :name => circle, :profile_type => 'Person')) end end @@ -22,7 +22,7 @@ class Friendship < ApplicationRecord groups = friendship.group.blank? ? ['friendships'] : friendship.group.split(',').map(&:strip) groups.each do |group| - circle = Circle.find_by(:person => friendship.person, :name => group ) + circle = Circle.find_by(:owner => friendship.person, :name => group ) friendship.person.remove_profile_from_circle(friendship.friend, circle) if circle end end diff --git a/app/models/profile.rb b/app/models/profile.rb index 7cf9cab..e085fa3 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -728,7 +728,7 @@ private :generate_url, :url_options else self.affiliate(person, Profile::Roles.admin(environment.id), attributes) if members.count == 0 self.affiliate(person, Profile::Roles.member(environment.id), attributes) - person.follow(self, Circle.find_or_create_by(:person => person, :name =>_('memberships'), :profile_type => 'Community')) + person.follow(self, Circle.find_or_create_by(:owner => person, :name =>_('memberships'), :profile_type => self.class.name)) end person.tasks.pending.of("InviteMember").select { |t| t.data[:community_id] == self.id }.each { |invite| invite.cancel } remove_from_suggestion_list person diff --git a/test/unit/external_person_test.rb b/test/unit/external_person_test.rb index 2e59cc8..4d0ac7b 100644 --- a/test/unit/external_person_test.rb +++ b/test/unit/external_person_test.rb @@ -137,7 +137,7 @@ class ExternalPersonTest < ActiveSupport::TestCase should 'be able to follow people' do person = fast_create(Person, :environment_id => Environment.default.id) - circle = Circle.create(person: @external_person, profile_type: "Person", name: "FRIENDSSS") + circle = Circle.create(owner: @external_person, profile_type: "Person", name: "FRIENDSSS") assert_difference "@external_person.followed_profiles.count" do @external_person.follow(person, circle) @@ -146,7 +146,7 @@ class ExternalPersonTest < ActiveSupport::TestCase should 'be able to unfolllow people' do person = fast_create(Person, :environment_id => Environment.default.id) - circle = Circle.create(person: @external_person, profile_type: "Person", name: "FRIENDSSS") + circle = Circle.create(owner: @external_person, profile_type: "Person", name: "FRIENDSSS") @external_person.follow(person, circle) assert_difference "@external_person.followed_profiles.count", -1 do diff --git a/test/unit/follower_test.rb b/test/unit/follower_test.rb index 5f18e07..a1b8e49 100644 --- a/test/unit/follower_test.rb +++ b/test/unit/follower_test.rb @@ -6,8 +6,8 @@ class FollowerTest < ActiveSupport::TestCase @person1 = create_user('perso-test-1').person @person2 = create_user('person-test-2').person - @circle1 = Circle.create!(person: @person1, name: "Zombies", profile_type: 'Person') - @circle2 = Circle.create!(person: @person1, name: "Humans", profile_type: 'Person') + @circle1 = Circle.create!(owner: @person1, name: "Zombies", profile_type: 'Person') + @circle2 = Circle.create!(owner: @person1, name: "Humans", profile_type: 'Person') @external_person = ExternalPerson.create!(identifier: 'johnlocke', name: 'John Locke', @@ -29,7 +29,7 @@ class FollowerTest < ActiveSupport::TestCase should 'follow a community' do community = fast_create(Community) - circle = Circle.create!(person: @person1, name: "Terminus", profile_type: 'Community') + circle = Circle.create!(owner: @person1, name: "Terminus", profile_type: 'Community') assert_difference '@person1.followed_profiles.count' do @person1.follow(community, circle) @@ -37,13 +37,13 @@ class FollowerTest < ActiveSupport::TestCase assert @person1.follows?(community) end - should 'not follow person if the user is not the ownner of the circle' do + should 'not follow person if the user is not the owner of the circle' do person3 = create_user('perso-test-3').person - assert_no_difference '@circle1.person.followed_profiles.count' do + assert_no_difference '@circle1.owner.followed_profiles.count' do person3.follow(@person2, @circle1) end - assert_not @circle1.person.follows?(@person2) + assert_not @circle1.owner.follows?(@person2) end should 'not follow a community if circle profile type does not match' do @@ -56,7 +56,7 @@ class FollowerTest < ActiveSupport::TestCase end should 'follow person with external user' do - @circle1.update_attributes(person: @external_person) + @circle1.update_attributes(owner: @external_person) assert_difference '@external_person.followed_profiles.count' do @external_person.follow(@person2, @circle1) @@ -74,7 +74,7 @@ class FollowerTest < ActiveSupport::TestCase end should 'unfollow person with external user' do - @circle1.update_attributes(person: @external_person) + @circle1.update_attributes(owner: @external_person) @external_person.follow(@person2, @circle1) assert_difference '@external_person.followed_profiles.count', -1 do @@ -93,7 +93,7 @@ class FollowerTest < ActiveSupport::TestCase should 'get the followed profiles for an external user' do person3 = create_user('person-test-3').person - @circle1.update_attributes(person: @external_person) + @circle1.update_attributes(owner: @external_person) @external_person.follow(@person2, @circle1) @external_person.follow(person3, @circle1) @@ -101,7 +101,7 @@ class FollowerTest < ActiveSupport::TestCase end should 'not follow same person twice even with different circles' do - circle3 = Circle.create!(person: @person1, name: "Free Folk", profile_type: 'Person') + circle3 = Circle.create!(owner: @person1, name: "Free Folk", profile_type: 'Person') @person1.follow(@person2, @circle1) @person1.follow(@person2, @circle2) @@ -118,28 +118,28 @@ class FollowerTest < ActiveSupport::TestCase end should 'update profile circles for a person' do - circle3 = Circle.create!(person: @person1, name: "Brains", profile_type: 'Person') + circle3 = Circle.create!(owner: @person1, name: "Brains", profile_type: 'Person') @person1.follow(@person2, [@circle1, @circle2]) @person1.update_profile_circles(@person2, [@circle2, circle3]) - assert_equivalent [@circle2, circle3], @person2.in_circles + assert_equivalent [@circle2, circle3], @person2.circles end should 'keep other follower circles after update' do person3 = create_user('person-test-3').person - circle3 = Circle.create!(person: person3, name: "Humans", profile_type: 'Person') + circle3 = Circle.create!(owner: person3, name: "Humans", profile_type: 'Person') @person1.follow(@person2, @circle1) person3.follow(@person2, circle3) @person1.update_profile_circles(@person2, [@circle1, @circle2]) - assert_equivalent [@circle1, @circle2, circle3], @person2.in_circles + assert_equivalent [@circle1, @circle2, circle3], @person2.circles end should 'remove a person from a circle' do @person1.follow(@person2, [@circle1, @circle2]) @person1.remove_profile_from_circle(@person2, @circle2) - assert_equivalent [@circle1], @person2.in_circles + assert_equivalent [@circle1], @person2.circles end should 'not remove a person from a circle if the user is not the owner' do @@ -147,6 +147,6 @@ class FollowerTest < ActiveSupport::TestCase @person1.follow(@person2, [@circle1, @circle2]) person3.remove_profile_from_circle(@person2, @circle2) - assert_equivalent [@circle1, @circle2], @person2.in_circles + assert_equivalent [@circle1, @circle2], @person2.circles end end diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index ae68fd0..1d5231a 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -843,8 +843,8 @@ class PersonTest < ActiveSupport::TestCase p3 = fast_create(Person) p4 = fast_create(Person) - circle2 = Circle.create!(:person=> p2, :name => "Zombies", :profile_type => 'Person') - circle4 = Circle.create!(:person=> p4, :name => "Zombies", :profile_type => 'Person') + circle2 = Circle.create!(:owner => p2, :name => "Zombies", :profile_type => 'Person') + circle4 = Circle.create!(:owner => p4, :name => "Zombies", :profile_type => 'Person') p2.follow(p1, circle2) assert p2.follows?(p1) @@ -889,8 +889,8 @@ class PersonTest < ActiveSupport::TestCase p3 = fast_create(Person) p4 = fast_create(Person) - circle2 = Circle.create!(:person=> p2, :name => "Zombies", :profile_type => 'Person') - circle4 = Circle.create!(:person=> p4, :name => "Zombies", :profile_type => 'Person') + circle2 = Circle.create!(:owner => p2, :name => "Zombies", :profile_type => 'Person') + circle4 = Circle.create!(:owner => p4, :name => "Zombies", :profile_type => 'Person') p2.follow(p1, circle2) assert p2.follows?(p1) refute p3.follows?(p1) diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index e493e05..ff48e6f 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -2237,15 +2237,15 @@ class ProfileTest < ActiveSupport::TestCase person1 = create_user('testperson-1').person person2 = create_user('testperson-2').person person3 = create_user('testperson-3').person - circle1 = Circle.create!(:person => person1, :name => "Night's Watch", :profile_type => 'Person') - circle2 = Circle.create!(:person => person1, :name => "Free Folk", :profile_type => 'Person') - circle3 = Circle.create!(:person => person2, :name => "The Unsullied", :profile_type => 'Person') + circle1 = Circle.create!(:owner => person1, :name => "Night's Watch", :profile_type => 'Person') + circle2 = Circle.create!(:owner => person1, :name => "Free Folk", :profile_type => 'Person') + circle3 = Circle.create!(:owner => person2, :name => "The Unsullied", :profile_type => 'Person') person1.follow(person3, circle1) person1.follow(person3, circle2) person2.follow(person3, circle3) - assert_equivalent person3.in_circles, [circle1, circle2, circle3] + assert_equivalent person3.circles, [circle1, circle2, circle3] assert_equivalent person3.followers, [person1, person2] end @@ -2253,8 +2253,8 @@ class ProfileTest < ActiveSupport::TestCase person1 = create_user('testperson-1').person person2 = create_user('testperson-2').person community = fast_create(Community) - circle1 = Circle.create!(:person => person1, :name => "Night's Watch", :profile_type => 'Person') - circle2 = Circle.create!(:person => person1, :name => "Free Folk", :profile_type => 'Community') + circle1 = Circle.create!(:owner => person1, :name => "Night's Watch", :profile_type => 'Person') + circle2 = Circle.create!(:owner => person1, :name => "Free Folk", :profile_type => 'Community') person1.follow(person2, circle1) person1.follow(community, circle2) @@ -2267,8 +2267,8 @@ class ProfileTest < ActiveSupport::TestCase created_at: Date.yesterday) person = create_user('testperson-2').person community = fast_create(Community) - circle1 = Circle.create!(:person => external_person, :name => "Night's Watch", :profile_type => 'Person') - circle2 = Circle.create!(:person => external_person, :name => "Free Folk", :profile_type => 'Community') + circle1 = Circle.create!(:owner => external_person, :name => "Night's Watch", :profile_type => 'Person') + circle2 = Circle.create!(:owner => external_person, :name => "Free Folk", :profile_type => 'Community') external_person.follow(person, circle1) external_person.follow(community, circle2) -- libgit2 0.21.2