From a0c06c26d2d35f38a9b71ddc0c5f0cbfe417a11b Mon Sep 17 00:00:00 2001 From: DylanGuedes Date: Mon, 15 Aug 2016 15:23:51 -0300 Subject: [PATCH] Fixes tests for external persons. --- app/models/concerns/follower.rb | 24 ++++++++++++++++++++++++ app/models/external_person.rb | 3 ++- app/models/person.rb | 20 -------------------- app/models/profile.rb | 1 - test/unit/external_person_test.rb | 20 ++++++++++++++++++++ 5 files changed, 46 insertions(+), 22 deletions(-) diff --git a/app/models/concerns/follower.rb b/app/models/concerns/follower.rb index ed8860e..680f3db 100644 --- a/app/models/concerns/follower.rb +++ b/app/models/concerns/follower.rb @@ -13,4 +13,28 @@ module Follower profile.followed_by?(self) end + def unfollow(profile) + ProfileFollower.with_follower(self).with_profile(profile).destroy_all + end + + def followed_profiles + Profile.followed_by self + end + + def update_profile_circles(profile, new_circles) + profile_circles = ProfileFollower.with_profile(profile).with_follower(self).map(&:circle) + circles_to_add = new_circles - profile_circles + circles_to_remove = profile_circles - new_circles + circles_to_add.each do |new_circle| + ProfileFollower.create(profile: profile, circle: new_circle) + end + + ProfileFollower.where('circle_id IN (?) AND profile_id = ?', + circles_to_remove.map(&:id), profile.id).destroy_all + end + + def remove_profile_from_circle(profile, circle) + ProfileFollower.with_profile(profile).with_circle(circle).destroy_all + end + end diff --git a/app/models/external_person.rb b/app/models/external_person.rb index 8a0ad1c..fd67f5d 100644 --- a/app/models/external_person.rb +++ b/app/models/external_person.rb @@ -200,7 +200,8 @@ class ExternalPerson < ActiveRecord::Base relationships_cache_key: '', is_member_of?: false, each_friend: nil, is_last_admin?: false, is_last_admin_leaving?: false, leave: nil, last_notification: nil, notification_time: 0, notifier: nil, - remove_suggestion: nil, allow_invitation_from?: false + remove_suggestion: nil, allow_invitation_from?: false, in_social_circle?: false, + allow_followers: false, in_circles: Circle.none, followers: [], in_circle?: false } derivated_methods = generate_derivated_methods(methods_and_responses) diff --git a/app/models/person.rb b/app/models/person.rb index 355b627..a11864a 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -182,26 +182,6 @@ class Person < Profile end end - def update_profile_circles(profile, new_circles) - profile_circles = ProfileFollower.with_profile(profile).with_follower(self).map(&:circle) - circles_to_add = new_circles - profile_circles - circles_to_remove = profile_circles - new_circles - circles_to_add.each do |new_circle| - ProfileFollower.create(profile: profile, circle: new_circle) - end - - ProfileFollower.where('circle_id IN (?) AND profile_id = ?', - circles_to_remove.map(&:id), profile.id).destroy_all - end - - def unfollow(profile) - ProfileFollower.with_follower(self).with_profile(profile).destroy_all - end - - def remove_profile_from_circle(profile, circle) - ProfileFollower.with_profile(profile).with_circle(circle).destroy_all - end - def already_request_friendship?(person) person.tasks.where(requestor_id: self.id, type: 'AddFriend', status: Task::Status::ACTIVE).first end diff --git a/app/models/profile.rb b/app/models/profile.rb index e7f5837..b96162c 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -1027,7 +1027,6 @@ private :generate_url, :url_options end def followed_by?(person) - p "self: #{self}" (person == self) || (person.in? self.followers) end diff --git a/test/unit/external_person_test.rb b/test/unit/external_person_test.rb index b181b59..2e59cc8 100644 --- a/test/unit/external_person_test.rb +++ b/test/unit/external_person_test.rb @@ -134,4 +134,24 @@ class ExternalPersonTest < ActiveSupport::TestCase assert_respond_to ExternalPerson.new, method.to_sym unless method =~ /^autosave_.*|validate_.*|^before_.*|^after_.*|^assignment_.*|^(city|state)_.*/ end end + + 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") + + assert_difference "@external_person.followed_profiles.count" do + @external_person.follow(person, circle) + end + end + + 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") + @external_person.follow(person, circle) + + assert_difference "@external_person.followed_profiles.count", -1 do + @external_person.unfollow(person) + end + end + end -- libgit2 0.21.2