Commit f8e47f31c4dbbeb2b980a98928318ca91b005fdf

Authored by Dylan Guedes
1 parent e238fd93

Fixes broken tests due to relationship changes, adds new polymorphic for externa…

…l_person to be followable

Signed-off-by: DylanGuedes <djmgguedes@gmail.com>
Signed-off-by: DylanGuedes <djmgguedes@gmail.com>
app/controllers/public/profile_controller.rb
@@ -69,6 +69,8 @@ class ProfileController &lt; PublicController @@ -69,6 +69,8 @@ class ProfileController &lt; PublicController
69 69
70 def following 70 def following
71 @followed_people = profile.followed_profiles.paginate(:per_page => per_page, :page => params[:npage], :total_entries => profile.followed_profiles.count) 71 @followed_people = profile.followed_profiles.paginate(:per_page => per_page, :page => params[:npage], :total_entries => profile.followed_profiles.count)
  72 + puts "FOLLOWED_PEOPLE: #{@followed_people.map(&:name)}"
  73 + return @followed_people
72 end 74 end
73 75
74 def followed 76 def followed
app/models/circle.rb
1 class Circle < ApplicationRecord 1 class Circle < ApplicationRecord
2 #TODO -> n:m with profile, item in the circle 2 #TODO -> n:m with profile, item in the circle
3 - has_many :profile, :through => :profile_follower 3 + has_many :profile_followers
4 #TODO -> owner 4 #TODO -> owner
5 belongs_to :owner, polymorphic: true 5 belongs_to :owner, polymorphic: true
6 6
app/models/concerns/follower.rb
@@ -11,7 +11,7 @@ module Follower @@ -11,7 +11,7 @@ module Follower
11 11
12 def follows?(profile) 12 def follows?(profile)
13 return false if profile.nil? 13 return false if profile.nil?
14 - profile.followed_by?(self) 14 + p profile.followed_by?(self)
15 end 15 end
16 16
17 def unfollow(profile) 17 def unfollow(profile)
app/models/external_person.rb
@@ -261,7 +261,7 @@ class ExternalPerson &lt; ActiveRecord::Base @@ -261,7 +261,7 @@ class ExternalPerson &lt; ActiveRecord::Base
261 {}, followed_by?: false, display_private_info_to?: true, can_view_field?: 261 {}, followed_by?: false, display_private_info_to?: true, can_view_field?:
262 true, remove_from_suggestion_list: nil, layout_template: 'default', 262 true, remove_from_suggestion_list: nil, layout_template: 'default',
263 is_admin?: false, add_friend: false, is_a_friend?: false, 263 is_admin?: false, add_friend: false, is_a_friend?: false,
264 - already_request_friendship?: false 264 + already_request_friendship?: false, tracked_actions: ActionTracker::Record.none
265 } 265 }
266 266
267 derivated_methods = generate_derivated_methods(methods_and_responses) 267 derivated_methods = generate_derivated_methods(methods_and_responses)
app/models/profile_follower.rb
@@ -32,5 +32,4 @@ class ProfileFollower &lt; ApplicationRecord @@ -32,5 +32,4 @@ class ProfileFollower &lt; ApplicationRecord
32 where(:circle => circle) 32 where(:circle => circle)
33 } 33 }
34 34
35 -  
36 end 35 end
app/views/followers/_profile_list.html.erb
1 <ul class="profile-list"> 1 <ul class="profile-list">
  2 + <h1>Aqui</h1>
2 <% profiles.each do |followed_profile| %> 3 <% profiles.each do |followed_profile| %>
3 <li> 4 <li>
4 <%= link_to_profile profile_image(followed_profile) + tag('br') + followed_profile.short_name, 5 <%= link_to_profile profile_image(followed_profile) + tag('br') + followed_profile.short_name,
test/functional/circles_controller_test.rb
@@ -10,8 +10,8 @@ class CirclesControllerTest &lt; ActionController::TestCase @@ -10,8 +10,8 @@ class CirclesControllerTest &lt; ActionController::TestCase
10 end 10 end
11 11
12 should 'return all circles of a profile' do 12 should 'return all circles of a profile' do
13 - circle1 = Circle.create!(:name => "circle1", :person => @person, :profile_type => 'Person')  
14 - circle2 = Circle.create!(:name => "circle2", :person => @person, :profile_type => 'Person') 13 + circle1 = Circle.create!(:name => "circle1", :owner => @person, :profile_type => 'Person')
  14 + circle2 = Circle.create!(:name => "circle2", :owner => @person, :profile_type => 'Person')
15 get :index, :profile => @person.identifier 15 get :index, :profile => @person.identifier
16 16
17 assert_equivalent [circle1, circle2], assigns[:circles] 17 assert_equivalent [circle1, circle2], assigns[:circles]
@@ -24,7 +24,7 @@ class CirclesControllerTest &lt; ActionController::TestCase @@ -24,7 +24,7 @@ class CirclesControllerTest &lt; ActionController::TestCase
24 end 24 end
25 25
26 should 'create a new circle' do 26 should 'create a new circle' do
27 - assert_difference '@person.circles.count' do 27 + assert_difference '@person.owned_circles.count' do
28 post :create, :profile => @person.identifier, 28 post :create, :profile => @person.identifier,
29 :circle => { :name => 'circle' , :profile_type => Person.name} 29 :circle => { :name => 'circle' , :profile_type => Person.name}
30 end 30 end
@@ -32,14 +32,14 @@ class CirclesControllerTest &lt; ActionController::TestCase @@ -32,14 +32,14 @@ class CirclesControllerTest &lt; ActionController::TestCase
32 end 32 end
33 33
34 should 'not create a circle without a name' do 34 should 'not create a circle without a name' do
35 - assert_no_difference '@person.circles.count' do 35 + assert_no_difference '@person.owned_circles.count' do
36 post :create, :profile => @person.identifier, :circle => { :name => nil } 36 post :create, :profile => @person.identifier, :circle => { :name => nil }
37 end 37 end
38 assert_template :new 38 assert_template :new
39 end 39 end
40 40
41 should 'retrieve an existing circle when editing' do 41 should 'retrieve an existing circle when editing' do
42 - circle = Circle.create!(:name => "circle", :person => @person, :profile_type => 'Person') 42 + circle = Circle.create!(:name => "circle", :owner => @person, :profile_type => 'Person')
43 get :edit, :profile => @person.identifier, :id => circle.id 43 get :edit, :profile => @person.identifier, :id => circle.id
44 assert_equal circle.name, assigns[:circle].name 44 assert_equal circle.name, assigns[:circle].name
45 end 45 end
@@ -50,7 +50,7 @@ class CirclesControllerTest &lt; ActionController::TestCase @@ -50,7 +50,7 @@ class CirclesControllerTest &lt; ActionController::TestCase
50 end 50 end
51 51
52 should 'update an existing circle' do 52 should 'update an existing circle' do
53 - circle = Circle.create!(:name => "circle", :person => @person, :profile_type => 'Person') 53 + circle = Circle.create!(:name => "circle", :owner => @person, :profile_type => 'Person')
54 post :update, :profile => @person.identifier, :id => circle.id, 54 post :update, :profile => @person.identifier, :id => circle.id,
55 :circle => { :name => "new name" } 55 :circle => { :name => "new name" }
56 56
@@ -60,7 +60,7 @@ class CirclesControllerTest &lt; ActionController::TestCase @@ -60,7 +60,7 @@ class CirclesControllerTest &lt; ActionController::TestCase
60 end 60 end
61 61
62 should 'not update an existing circle without a name' do 62 should 'not update an existing circle without a name' do
63 - circle = Circle.create!(:name => "circle", :person => @person, :profile_type => 'Person') 63 + circle = Circle.create!(:name => "circle", :owner => @person, :profile_type => 'Person')
64 post :update, :profile => @person.identifier, :id => circle.id, 64 post :update, :profile => @person.identifier, :id => circle.id,
65 :circle => { :name => nil } 65 :circle => { :name => nil }
66 66
@@ -75,18 +75,18 @@ class CirclesControllerTest &lt; ActionController::TestCase @@ -75,18 +75,18 @@ class CirclesControllerTest &lt; ActionController::TestCase
75 end 75 end
76 76
77 should 'destroy an existing circle and remove related profiles' do 77 should 'destroy an existing circle and remove related profiles' do
78 - circle = Circle.create!(:name => "circle", :person => @person, :profile_type => 'Person') 78 + circle = Circle.create!(:name => "circle", :owner => @person, :profile_type => 'Person')
79 fast_create(ProfileFollower, :profile_id => fast_create(Person).id, :circle_id => circle.id) 79 fast_create(ProfileFollower, :profile_id => fast_create(Person).id, :circle_id => circle.id)
80 80
81 - assert_difference ["@person.circles.count", 'ProfileFollower.count'], -1 do 81 + assert_difference ["@person.owned_circles.count", 'ProfileFollower.count'], -1 do
82 post :destroy, :profile => @person.identifier, :id => circle.id 82 post :destroy, :profile => @person.identifier, :id => circle.id
83 end 83 end
84 end 84 end
85 85
86 should 'not destroy an existing circle if action is not post' do 86 should 'not destroy an existing circle if action is not post' do
87 - circle = Circle.create!(:name => "circle", :person => @person, :profile_type => 'Person') 87 + circle = Circle.create!(:name => "circle", :owner => @person, :profile_type => 'Person')
88 88
89 - assert_no_difference "@person.circles.count" do 89 + assert_no_difference "@person.owned_circles.count" do
90 get :destroy, :profile => @person.identifier, :id => circle.id 90 get :destroy, :profile => @person.identifier, :id => circle.id
91 end 91 end
92 assert_response 404 92 assert_response 404
test/functional/followers_controller_test.rb
@@ -9,7 +9,7 @@ class FollowersControllerTest &lt; ActionController::TestCase @@ -9,7 +9,7 @@ class FollowersControllerTest &lt; ActionController::TestCase
9 should 'return followed people list' do 9 should 'return followed people list' do
10 login_as(@profile.identifier) 10 login_as(@profile.identifier)
11 person = fast_create(Person) 11 person = fast_create(Person)
12 - circle = Circle.create!(:person=> @profile, :name => "Zombies", :profile_type => 'Person') 12 + circle = Circle.create!(:owner=> @profile, :name => "Zombies", :profile_type => 'Person')
13 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id) 13 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id)
14 14
15 get :index, :profile => @profile.identifier 15 get :index, :profile => @profile.identifier
@@ -20,8 +20,8 @@ class FollowersControllerTest &lt; ActionController::TestCase @@ -20,8 +20,8 @@ class FollowersControllerTest &lt; ActionController::TestCase
20 login_as(@profile.identifier) 20 login_as(@profile.identifier)
21 person = fast_create(Person) 21 person = fast_create(Person)
22 community = fast_create(Community) 22 community = fast_create(Community)
23 - circle = Circle.create!(:person=> @profile, :name => "Zombies", :profile_type => 'Person')  
24 - circle2 = Circle.create!(:person=> @profile, :name => "Teams", :profile_type => 'Community') 23 + circle = Circle.create!(:owner=> @profile, :name => "Zombies", :profile_type => 'Person')
  24 + circle2 = Circle.create!(:owner=> @profile, :name => "Teams", :profile_type => 'Community')
25 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id) 25 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id)
26 fast_create(ProfileFollower, :profile_id => community.id, :circle_id => circle2.id) 26 fast_create(ProfileFollower, :profile_id => community.id, :circle_id => circle2.id)
27 27
@@ -47,8 +47,8 @@ class FollowersControllerTest &lt; ActionController::TestCase @@ -47,8 +47,8 @@ class FollowersControllerTest &lt; ActionController::TestCase
47 should 'update followed person category' do 47 should 'update followed person category' do
48 login_as(@profile.identifier) 48 login_as(@profile.identifier)
49 person = fast_create(Person) 49 person = fast_create(Person)
50 - circle = Circle.create!(:person=> @profile, :name => "Zombies", :profile_type => 'Person')  
51 - circle2 = Circle.create!(:person=> @profile, :name => "DotA", :profile_type => 'Person') 50 + circle = Circle.create!(:owner=> @profile, :name => "Zombies", :profile_type => 'Person')
  51 + circle2 = Circle.create!(:owner=> @profile, :name => "DotA", :profile_type => 'Person')
52 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id) 52 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id)
53 53
54 post :update_category, :profile => @profile.identifier, :circles => {"DotA"=> circle2.id}, :followed_profile_id => person.id 54 post :update_category, :profile => @profile.identifier, :circles => {"DotA"=> circle2.id}, :followed_profile_id => person.id
test/functional/profile_controller_test.rb
@@ -772,7 +772,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -772,7 +772,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
772 end 772 end
773 773
774 should 'not see the followers activities in the current profile' do 774 should 'not see the followers activities in the current profile' do
775 - circle = Circle.create!(:person=> profile, :name => "Zombies", :profile_type => 'Person') 775 + circle = Circle.create!(:owner=> profile, :name => "Zombies", :profile_type => 'Person')
776 776
777 p2 = create_user.person 777 p2 = create_user.person
778 refute profile.follows?(p2) 778 refute profile.follows?(p2)
@@ -968,7 +968,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -968,7 +968,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
968 login_as(profile.identifier) 968 login_as(profile.identifier)
969 p1= fast_create(Person) 969 p1= fast_create(Person)
970 970
971 - circle = Circle.create!(:person=> profile, :name => "Zombies", :profile_type => 'Person') 971 + circle = Circle.create!(:owner=> profile, :name => "Zombies", :profile_type => 'Person')
972 972
973 profile.follow(p1, circle) 973 profile.follow(p1, circle)
974 974
@@ -1992,7 +1992,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -1992,7 +1992,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1992 login_as(@profile.identifier) 1992 login_as(@profile.identifier)
1993 person = fast_create(Person) 1993 person = fast_create(Person)
1994 1994
1995 - circle = Circle.create!(:person=> @profile, :name => "Zombies", :profile_type => 'Person') 1995 + circle = Circle.create!(:owner=> @profile, :name => "Zombies", :profile_type => 'Person')
1996 1996
1997 assert_difference 'ProfileFollower.count' do 1997 assert_difference 'ProfileFollower.count' do
1998 post :follow, :profile => person.identifier, :circles => {"Zombies" => circle.id} 1998 post :follow, :profile => person.identifier, :circles => {"Zombies" => circle.id}
@@ -2003,8 +2003,8 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -2003,8 +2003,8 @@ class ProfileControllerTest &lt; ActionController::TestCase
2003 login_as(@profile.identifier) 2003 login_as(@profile.identifier)
2004 person = fast_create(Person) 2004 person = fast_create(Person)
2005 2005
2006 - circle = Circle.create!(:person=> @profile, :name => "Zombies", :profile_type => 'Person')  
2007 - circle2 = Circle.create!(:person=> @profile, :name => "Brainsss", :profile_type => 'Person') 2006 + circle = Circle.create!(:owner=> @profile, :name => "Zombies", :profile_type => 'Person')
  2007 + circle2 = Circle.create!(:owner=> @profile, :name => "Brainsss", :profile_type => 'Person')
2008 2008
2009 assert_difference 'ProfileFollower.count', 2 do 2009 assert_difference 'ProfileFollower.count', 2 do
2010 post :follow, :profile => person.identifier, :circles => {"Zombies" => circle.id, "Brainsss"=> circle2.id} 2010 post :follow, :profile => person.identifier, :circles => {"Zombies" => circle.id, "Brainsss"=> circle2.id}
@@ -2015,8 +2015,8 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -2015,8 +2015,8 @@ class ProfileControllerTest &lt; ActionController::TestCase
2015 login_as(@profile.identifier) 2015 login_as(@profile.identifier)
2016 person = fast_create(Person) 2016 person = fast_create(Person)
2017 2017
2018 - circle = Circle.create!(:person=> @profile, :name => "Zombies", :profile_type => 'Person')  
2019 - circle2 = Circle.create!(:person=> @profile, :name => "Brainsss", :profile_type => 'Person') 2018 + circle = Circle.create!(:owner=> @profile, :name => "Zombies", :profile_type => 'Person')
  2019 + circle2 = Circle.create!(:owner=> @profile, :name => "Brainsss", :profile_type => 'Person')
2020 2020
2021 assert_no_difference 'ProfileFollower.count' do 2021 assert_no_difference 'ProfileFollower.count' do
2022 post :follow, :profile => person.identifier, :circles => {"Zombies" => "0", "Brainsss" => "0"} 2022 post :follow, :profile => person.identifier, :circles => {"Zombies" => "0", "Brainsss" => "0"}
@@ -2029,7 +2029,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -2029,7 +2029,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
2029 login_as(@profile.identifier) 2029 login_as(@profile.identifier)
2030 person = fast_create(Person) 2030 person = fast_create(Person)
2031 2031
2032 - circle = Circle.create!(:person=> @profile, :name => "Zombies", :profile_type => 'Person') 2032 + circle = Circle.create!(:owner=> @profile, :name => "Zombies", :profile_type => 'Person')
2033 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id) 2033 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id)
2034 2034
2035 assert_no_difference 'ProfileFollower.count' do 2035 assert_no_difference 'ProfileFollower.count' do
@@ -2049,8 +2049,8 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -2049,8 +2049,8 @@ class ProfileControllerTest &lt; ActionController::TestCase
2049 login_as(@profile.identifier) 2049 login_as(@profile.identifier)
2050 person = fast_create(Person) 2050 person = fast_create(Person)
2051 2051
2052 - circle = Circle.create!(:person=> @profile, :name => "Zombies", :profile_type => 'Person')  
2053 - follower = fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id) 2052 + circle = Circle.create!(:owner=> @profile, :name => "Zombies", :profile_type => 'Person')
  2053 + follower = ProfileFollower.create!(:profile => person, circle: circle)
2054 2054
2055 assert_not_nil follower 2055 assert_not_nil follower
2056 2056
@@ -2072,7 +2072,7 @@ class ProfileControllerTest &lt; ActionController::TestCase @@ -2072,7 +2072,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
2072 login_as(@profile.identifier) 2072 login_as(@profile.identifier)
2073 person = fast_create(Person) 2073 person = fast_create(Person)
2074 2074
2075 - circle = Circle.create!(:person=> @profile, :name => "Zombies", :profile_type => 'Person') 2075 + circle = Circle.create!(:owner=> @profile, :name => "Zombies", :profile_type => 'Person')
2076 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id) 2076 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id)
2077 2077
2078 post :unfollow, :profile => person.identifier, :redirect_to => "/some/url" 2078 post :unfollow, :profile => person.identifier, :redirect_to => "/some/url"
test/unit/follower_test.rb
@@ -149,4 +149,15 @@ class FollowerTest &lt; ActiveSupport::TestCase @@ -149,4 +149,15 @@ class FollowerTest &lt; ActiveSupport::TestCase
149 person3.remove_profile_from_circle(@person2, @circle2) 149 person3.remove_profile_from_circle(@person2, @circle2)
150 assert_equivalent [@circle1, @circle2], @person2.circles 150 assert_equivalent [@circle1, @circle2], @person2.circles
151 end 151 end
  152 +
  153 + should 'external person be followable' do
  154 + person = fast_create(Person, :environment_id => Environment.default.id)
  155 + circle = Circle.create(owner: @external_person, profile_type: "Person", name: "FRIENDSSS")
  156 + pf = ProfileFollower.create(profile: @external_person, circle: circle)
  157 + assert person.follows? @external_person
  158 +
  159 + # assert_difference 'ProfileFollower.all.count' do
  160 + # person.follow(@external_person, circle)
  161 + # end
  162 + end
152 end 163 end