Commit a0c06c26d2d35f38a9b71ddc0c5f0cbfe417a11b
1 parent
4596ef42
Fixes tests for external persons.
Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com> Signed-off-by: DylanGuedes <djmgguedes@gmail.com>
Showing
5 changed files
with
46 additions
and
22 deletions
Show diff stats
app/models/concerns/follower.rb
@@ -13,4 +13,28 @@ module Follower | @@ -13,4 +13,28 @@ module Follower | ||
13 | profile.followed_by?(self) | 13 | profile.followed_by?(self) |
14 | end | 14 | end |
15 | 15 | ||
16 | + def unfollow(profile) | ||
17 | + ProfileFollower.with_follower(self).with_profile(profile).destroy_all | ||
18 | + end | ||
19 | + | ||
20 | + def followed_profiles | ||
21 | + Profile.followed_by self | ||
22 | + end | ||
23 | + | ||
24 | + def update_profile_circles(profile, new_circles) | ||
25 | + profile_circles = ProfileFollower.with_profile(profile).with_follower(self).map(&:circle) | ||
26 | + circles_to_add = new_circles - profile_circles | ||
27 | + circles_to_remove = profile_circles - new_circles | ||
28 | + circles_to_add.each do |new_circle| | ||
29 | + ProfileFollower.create(profile: profile, circle: new_circle) | ||
30 | + end | ||
31 | + | ||
32 | + ProfileFollower.where('circle_id IN (?) AND profile_id = ?', | ||
33 | + circles_to_remove.map(&:id), profile.id).destroy_all | ||
34 | + end | ||
35 | + | ||
36 | + def remove_profile_from_circle(profile, circle) | ||
37 | + ProfileFollower.with_profile(profile).with_circle(circle).destroy_all | ||
38 | + end | ||
39 | + | ||
16 | end | 40 | end |
app/models/external_person.rb
@@ -200,7 +200,8 @@ class ExternalPerson < ActiveRecord::Base | @@ -200,7 +200,8 @@ class ExternalPerson < ActiveRecord::Base | ||
200 | relationships_cache_key: '', is_member_of?: false, | 200 | relationships_cache_key: '', is_member_of?: false, |
201 | each_friend: nil, is_last_admin?: false, is_last_admin_leaving?: false, | 201 | each_friend: nil, is_last_admin?: false, is_last_admin_leaving?: false, |
202 | leave: nil, last_notification: nil, notification_time: 0, notifier: nil, | 202 | leave: nil, last_notification: nil, notification_time: 0, notifier: nil, |
203 | - remove_suggestion: nil, allow_invitation_from?: false | 203 | + remove_suggestion: nil, allow_invitation_from?: false, in_social_circle?: false, |
204 | + allow_followers: false, in_circles: Circle.none, followers: [], in_circle?: false | ||
204 | } | 205 | } |
205 | 206 | ||
206 | derivated_methods = generate_derivated_methods(methods_and_responses) | 207 | derivated_methods = generate_derivated_methods(methods_and_responses) |
app/models/person.rb
@@ -182,26 +182,6 @@ class Person < Profile | @@ -182,26 +182,6 @@ class Person < Profile | ||
182 | end | 182 | end |
183 | end | 183 | end |
184 | 184 | ||
185 | - def update_profile_circles(profile, new_circles) | ||
186 | - profile_circles = ProfileFollower.with_profile(profile).with_follower(self).map(&:circle) | ||
187 | - circles_to_add = new_circles - profile_circles | ||
188 | - circles_to_remove = profile_circles - new_circles | ||
189 | - circles_to_add.each do |new_circle| | ||
190 | - ProfileFollower.create(profile: profile, circle: new_circle) | ||
191 | - end | ||
192 | - | ||
193 | - ProfileFollower.where('circle_id IN (?) AND profile_id = ?', | ||
194 | - circles_to_remove.map(&:id), profile.id).destroy_all | ||
195 | - end | ||
196 | - | ||
197 | - def unfollow(profile) | ||
198 | - ProfileFollower.with_follower(self).with_profile(profile).destroy_all | ||
199 | - end | ||
200 | - | ||
201 | - def remove_profile_from_circle(profile, circle) | ||
202 | - ProfileFollower.with_profile(profile).with_circle(circle).destroy_all | ||
203 | - end | ||
204 | - | ||
205 | def already_request_friendship?(person) | 185 | def already_request_friendship?(person) |
206 | person.tasks.where(requestor_id: self.id, type: 'AddFriend', status: Task::Status::ACTIVE).first | 186 | person.tasks.where(requestor_id: self.id, type: 'AddFriend', status: Task::Status::ACTIVE).first |
207 | end | 187 | end |
app/models/profile.rb
@@ -1027,7 +1027,6 @@ private :generate_url, :url_options | @@ -1027,7 +1027,6 @@ private :generate_url, :url_options | ||
1027 | end | 1027 | end |
1028 | 1028 | ||
1029 | def followed_by?(person) | 1029 | def followed_by?(person) |
1030 | - p "self: #{self}" | ||
1031 | (person == self) || (person.in? self.followers) | 1030 | (person == self) || (person.in? self.followers) |
1032 | end | 1031 | end |
1033 | 1032 |
test/unit/external_person_test.rb
@@ -134,4 +134,24 @@ class ExternalPersonTest < ActiveSupport::TestCase | @@ -134,4 +134,24 @@ class ExternalPersonTest < ActiveSupport::TestCase | ||
134 | assert_respond_to ExternalPerson.new, method.to_sym unless method =~ /^autosave_.*|validate_.*|^before_.*|^after_.*|^assignment_.*|^(city|state)_.*/ | 134 | assert_respond_to ExternalPerson.new, method.to_sym unless method =~ /^autosave_.*|validate_.*|^before_.*|^after_.*|^assignment_.*|^(city|state)_.*/ |
135 | end | 135 | end |
136 | end | 136 | end |
137 | + | ||
138 | + should 'be able to follow people' do | ||
139 | + person = fast_create(Person, :environment_id => Environment.default.id) | ||
140 | + circle = Circle.create(person: @external_person, profile_type: "Person", name: "FRIENDSSS") | ||
141 | + | ||
142 | + assert_difference "@external_person.followed_profiles.count" do | ||
143 | + @external_person.follow(person, circle) | ||
144 | + end | ||
145 | + end | ||
146 | + | ||
147 | + should 'be able to unfolllow people' do | ||
148 | + person = fast_create(Person, :environment_id => Environment.default.id) | ||
149 | + circle = Circle.create(person: @external_person, profile_type: "Person", name: "FRIENDSSS") | ||
150 | + @external_person.follow(person, circle) | ||
151 | + | ||
152 | + assert_difference "@external_person.followed_profiles.count", -1 do | ||
153 | + @external_person.unfollow(person) | ||
154 | + end | ||
155 | + end | ||
156 | + | ||
137 | end | 157 | end |