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 69  
70 70 def following
71 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 74 end
73 75  
74 76 def followed
... ...
app/models/circle.rb
1 1 class Circle < ApplicationRecord
2 2 #TODO -> n:m with profile, item in the circle
3   - has_many :profile, :through => :profile_follower
  3 + has_many :profile_followers
4 4 #TODO -> owner
5 5 belongs_to :owner, polymorphic: true
6 6  
... ...
app/models/concerns/follower.rb
... ... @@ -11,7 +11,7 @@ module Follower
11 11  
12 12 def follows?(profile)
13 13 return false if profile.nil?
14   - profile.followed_by?(self)
  14 + p profile.followed_by?(self)
15 15 end
16 16  
17 17 def unfollow(profile)
... ...
app/models/external_person.rb
... ... @@ -261,7 +261,7 @@ class ExternalPerson &lt; ActiveRecord::Base
261 261 {}, followed_by?: false, display_private_info_to?: true, can_view_field?:
262 262 true, remove_from_suggestion_list: nil, layout_template: 'default',
263 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 267 derivated_methods = generate_derivated_methods(methods_and_responses)
... ...
app/models/profile_follower.rb
... ... @@ -32,5 +32,4 @@ class ProfileFollower &lt; ApplicationRecord
32 32 where(:circle => circle)
33 33 }
34 34  
35   -
36 35 end
... ...
app/views/followers/_profile_list.html.erb
1 1 <ul class="profile-list">
  2 + <h1>Aqui</h1>
2 3 <% profiles.each do |followed_profile| %>
3 4 <li>
4 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 10 end
11 11  
12 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 15 get :index, :profile => @person.identifier
16 16  
17 17 assert_equivalent [circle1, circle2], assigns[:circles]
... ... @@ -24,7 +24,7 @@ class CirclesControllerTest &lt; ActionController::TestCase
24 24 end
25 25  
26 26 should 'create a new circle' do
27   - assert_difference '@person.circles.count' do
  27 + assert_difference '@person.owned_circles.count' do
28 28 post :create, :profile => @person.identifier,
29 29 :circle => { :name => 'circle' , :profile_type => Person.name}
30 30 end
... ... @@ -32,14 +32,14 @@ class CirclesControllerTest &lt; ActionController::TestCase
32 32 end
33 33  
34 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 36 post :create, :profile => @person.identifier, :circle => { :name => nil }
37 37 end
38 38 assert_template :new
39 39 end
40 40  
41 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 43 get :edit, :profile => @person.identifier, :id => circle.id
44 44 assert_equal circle.name, assigns[:circle].name
45 45 end
... ... @@ -50,7 +50,7 @@ class CirclesControllerTest &lt; ActionController::TestCase
50 50 end
51 51  
52 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 54 post :update, :profile => @person.identifier, :id => circle.id,
55 55 :circle => { :name => "new name" }
56 56  
... ... @@ -60,7 +60,7 @@ class CirclesControllerTest &lt; ActionController::TestCase
60 60 end
61 61  
62 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 64 post :update, :profile => @person.identifier, :id => circle.id,
65 65 :circle => { :name => nil }
66 66  
... ... @@ -75,18 +75,18 @@ class CirclesControllerTest &lt; ActionController::TestCase
75 75 end
76 76  
77 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 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 82 post :destroy, :profile => @person.identifier, :id => circle.id
83 83 end
84 84 end
85 85  
86 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 90 get :destroy, :profile => @person.identifier, :id => circle.id
91 91 end
92 92 assert_response 404
... ...
test/functional/followers_controller_test.rb
... ... @@ -9,7 +9,7 @@ class FollowersControllerTest &lt; ActionController::TestCase
9 9 should 'return followed people list' do
10 10 login_as(@profile.identifier)
11 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 13 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id)
14 14  
15 15 get :index, :profile => @profile.identifier
... ... @@ -20,8 +20,8 @@ class FollowersControllerTest &lt; ActionController::TestCase
20 20 login_as(@profile.identifier)
21 21 person = fast_create(Person)
22 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 25 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id)
26 26 fast_create(ProfileFollower, :profile_id => community.id, :circle_id => circle2.id)
27 27  
... ... @@ -47,8 +47,8 @@ class FollowersControllerTest &lt; ActionController::TestCase
47 47 should 'update followed person category' do
48 48 login_as(@profile.identifier)
49 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 52 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id)
53 53  
54 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 772 end
773 773  
774 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 777 p2 = create_user.person
778 778 refute profile.follows?(p2)
... ... @@ -968,7 +968,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
968 968 login_as(profile.identifier)
969 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 973 profile.follow(p1, circle)
974 974  
... ... @@ -1992,7 +1992,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
1992 1992 login_as(@profile.identifier)
1993 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 1997 assert_difference 'ProfileFollower.count' do
1998 1998 post :follow, :profile => person.identifier, :circles => {"Zombies" => circle.id}
... ... @@ -2003,8 +2003,8 @@ class ProfileControllerTest &lt; ActionController::TestCase
2003 2003 login_as(@profile.identifier)
2004 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 2009 assert_difference 'ProfileFollower.count', 2 do
2010 2010 post :follow, :profile => person.identifier, :circles => {"Zombies" => circle.id, "Brainsss"=> circle2.id}
... ... @@ -2015,8 +2015,8 @@ class ProfileControllerTest &lt; ActionController::TestCase
2015 2015 login_as(@profile.identifier)
2016 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 2021 assert_no_difference 'ProfileFollower.count' do
2022 2022 post :follow, :profile => person.identifier, :circles => {"Zombies" => "0", "Brainsss" => "0"}
... ... @@ -2029,7 +2029,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
2029 2029 login_as(@profile.identifier)
2030 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 2033 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id)
2034 2034  
2035 2035 assert_no_difference 'ProfileFollower.count' do
... ... @@ -2049,8 +2049,8 @@ class ProfileControllerTest &lt; ActionController::TestCase
2049 2049 login_as(@profile.identifier)
2050 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 2055 assert_not_nil follower
2056 2056  
... ... @@ -2072,7 +2072,7 @@ class ProfileControllerTest &lt; ActionController::TestCase
2072 2072 login_as(@profile.identifier)
2073 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 2076 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle.id)
2077 2077  
2078 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 149 person3.remove_profile_from_circle(@person2, @circle2)
150 150 assert_equivalent [@circle1, @circle2], @person2.circles
151 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 163 end
... ...