Commit 444063e9533855ce6b34e185a825979c4dff284f

Authored by Gabriel Silva
1 parent 14995a0e

Fixes unit tests

Signed-off-by: DylanGuedes <djmgguedes@gmail.com>
Signed-off-by: Gabriel Silva <gabriel93.silva@gmail.com>
app/models/add_member.rb
... ... @@ -22,7 +22,7 @@ class AddMember &lt; Task
22 22 self.roles = [Profile::Roles.member(organization.environment.id).id]
23 23 end
24 24 target.affiliate(requestor, self.roles.select{|r| !r.to_i.zero? }.map{|i| Role.find(i)})
25   - person.follow(organization, Circle.find_or_create_by(:person => person, :name =>_('memberships'), :profile_type => 'Community'))
  25 + person.follow(organization, Circle.find_or_create_by(:owner => person, :name =>_('memberships'), :profile_type => 'Community'))
26 26 end
27 27  
28 28 def title
... ...
app/models/circle.rb
... ... @@ -25,7 +25,8 @@ class Circle &lt; ApplicationRecord
25 25 {
26 26 _("Person") => Person.name,
27 27 _("Community") => Community.name,
28   - _("Enterprise") => Enterprise.name
  28 + _("Enterprise") => Enterprise.name,
  29 + _("Organization") => Organization.name
29 30 }
30 31 end
31 32  
... ...
test/unit/article_test.rb
... ... @@ -1101,7 +1101,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1101 1101  
1102 1102 should 'create notifications to followers when creating an article' do
1103 1103 friend = fast_create(Person)
1104   - circle = Circle.create!(:person=> friend, :name => "Zombies", :profile_type => 'Person')
  1104 + circle = Circle.create!(:owner=> friend, :name => "Zombies", :profile_type => 'Person')
1105 1105 friend.follow(profile, circle)
1106 1106 Article.destroy_all
1107 1107 ActionTracker::Record.destroy_all
... ... @@ -1115,7 +1115,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1115 1115  
1116 1116 should 'create the notification to the follower when one follower has the notification and the other no' do
1117 1117 f1 = fast_create(Person)
1118   - circle = Circle.create!(:person=> f1, :name => "Zombies", :profile_type => 'Person')
  1118 + circle = Circle.create!(:owner=> f1, :name => "Zombies", :profile_type => 'Person')
1119 1119 f1.follow(profile, circle)
1120 1120  
1121 1121 User.current = profile.user
... ... @@ -1125,7 +1125,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1125 1125 assert_equal 2, ActionTrackerNotification.where(action_tracker_id: article.activity.id).count
1126 1126  
1127 1127 f2 = fast_create(Person)
1128   - circle2 = Circle.create!(:person=> f2, :name => "Zombies", :profile_type => 'Person')
  1128 + circle2 = Circle.create!(:owner=> f2, :name => "Zombies", :profile_type => 'Person')
1129 1129 f2.follow(profile, circle2)
1130 1130  
1131 1131 article2 = create TinyMceArticle, :name => 'Tracked Article 2', :profile_id => profile.id
... ... @@ -1137,7 +1137,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
1137 1137 should 'destroy activity and notifications of followers when destroying an article' do
1138 1138 friend = fast_create(Person)
1139 1139  
1140   - circle = Circle.create!(:person=> friend, :name => "Zombies", :profile_type => 'Person')
  1140 + circle = Circle.create!(:owner=> friend, :name => "Zombies", :profile_type => 'Person')
1141 1141  
1142 1142 friend.follow(profile, circle)
1143 1143  
... ...
test/unit/follower_test.rb
... ... @@ -8,6 +8,7 @@ class FollowerTest &lt; ActiveSupport::TestCase
8 8  
9 9 @circle1 = Circle.create!(owner: @person1, name: "Zombies", profile_type: 'Person')
10 10 @circle2 = Circle.create!(owner: @person1, name: "Humans", profile_type: 'Person')
  11 + @circle3 = Circle.create!(owner: @person1, name: "Crypt", profile_type: 'Community')
11 12  
12 13 @external_person = ExternalPerson.create!(identifier: 'johnlocke',
13 14 name: 'John Locke',
... ... @@ -85,27 +86,32 @@ class FollowerTest &lt; ActiveSupport::TestCase
85 86  
86 87 should 'get the followed profiles for a regular user' do
87 88 person3 = create_user('person-test-3').person
  89 + community = fast_create(Community)
88 90  
89 91 @person1.follow(@person2, @circle1)
90 92 @person1.follow(person3, @circle1)
91   - assert_equivalent [@person2, person3], @person1.followed_profiles
  93 + @person1.follow(community, @circle3)
  94 + assert_equivalent [@person2, person3, community], @person1.followed_profiles
92 95 end
93 96  
94 97 should 'get the followed profiles for an external user' do
95 98 person3 = create_user('person-test-3').person
  99 + community = fast_create(Community)
96 100 @circle1.update_attributes(owner: @external_person)
  101 + @circle3.update_attributes(owner: @external_person)
97 102  
98 103 @external_person.follow(@person2, @circle1)
99 104 @external_person.follow(person3, @circle1)
100   - assert_equivalent [@person2, person3], @external_person.followed_profiles
  105 + @external_person.follow(community, @circle3)
  106 + assert_equivalent [@person2, person3, community], @external_person.followed_profiles
101 107 end
102 108  
103 109 should 'not follow same person twice even with different circles' do
104   - circle3 = Circle.create!(owner: @person1, name: "Free Folk", profile_type: 'Person')
  110 + circle4 = Circle.create!(owner: @person1, name: "Free Folk", profile_type: 'Person')
105 111  
106 112 @person1.follow(@person2, @circle1)
107 113 @person1.follow(@person2, @circle2)
108   - @person1.follow(@person2, circle3)
  114 + @person1.follow(@person2, circle4)
109 115 assert_equivalent [@person2], @person1.followed_profiles
110 116 end
111 117  
... ... @@ -118,21 +124,21 @@ class FollowerTest &lt; ActiveSupport::TestCase
118 124 end
119 125  
120 126 should 'update profile circles for a person' do
121   - circle3 = Circle.create!(owner: @person1, name: "Brains", profile_type: 'Person')
  127 + circle4 = Circle.create!(owner: @person1, name: "Brains", profile_type: 'Person')
122 128 @person1.follow(@person2, [@circle1, @circle2])
123 129  
124   - @person1.update_profile_circles(@person2, [@circle2, circle3])
125   - assert_equivalent [@circle2, circle3], @person2.circles
  130 + @person1.update_profile_circles(@person2, [@circle2, circle4])
  131 + assert_equivalent [@circle2, circle4], @person2.circles
126 132 end
127 133  
128 134 should 'keep other follower circles after update' do
129 135 person3 = create_user('person-test-3').person
130   - circle3 = Circle.create!(owner: person3, name: "Humans", profile_type: 'Person')
  136 + circle4 = Circle.create!(owner: person3, name: "Humans", profile_type: 'Person')
131 137 @person1.follow(@person2, @circle1)
132   - person3.follow(@person2, circle3)
  138 + person3.follow(@person2, circle4)
133 139  
134 140 @person1.update_profile_circles(@person2, [@circle1, @circle2])
135   - assert_equivalent [@circle1, @circle2, circle3], @person2.circles
  141 + assert_equivalent [@circle1, @circle2, circle4], @person2.circles
136 142 end
137 143  
138 144 should 'remove a person from a circle' do
... ...
test/unit/friendship_test.rb
... ... @@ -115,8 +115,8 @@ class FriendshipTest &lt; ActiveSupport::TestCase
115 115 p1 = create_user('testuser1').person
116 116 p2 = create_user('testuser2').person
117 117  
118   - circle1 = Circle.create!(:person=> p1, :name => "Zombies", :profile_type => 'Person')
119   - circle2 = Circle.create!(:person=> p2, :name => "Zombies", :profile_type => 'Person')
  118 + circle1 = Circle.create!(:owner=> p1, :name => "Zombies", :profile_type => 'Person')
  119 + circle2 = Circle.create!(:owner=> p2, :name => "Zombies", :profile_type => 'Person')
120 120 p1.follow(p2, circle1)
121 121 p2.follow(p1, circle2)
122 122  
... ...
test/unit/notify_activity_to_profiles_job_test.rb
... ... @@ -31,9 +31,9 @@ class NotifyActivityToProfilesJobTest &lt; ActiveSupport::TestCase
31 31 refute NotifyActivityToProfilesJob::NOTIFY_ONLY_COMMUNITY.include?(action_tracker.verb)
32 32 p1, p2, m1, m2 = fast_create(Person), fast_create(Person), fast_create(Person), fast_create(Person)
33 33  
34   - circle1 = Circle.create!(:person=> p1, :name => "Zombies", :profile_type => 'Person')
35   - circle2 = Circle.create!(:person=> p2, :name => "Zombies", :profile_type => 'Person')
36   - circle = Circle.create!(:person=> person, :name => "Zombies", :profile_type => 'Person')
  34 + circle1 = Circle.create!(:owner=> p1, :name => "Zombies", :profile_type => 'Person')
  35 + circle2 = Circle.create!(:owner=> p2, :name => "Zombies", :profile_type => 'Person')
  36 + circle = Circle.create!(:owner=> person, :name => "Zombies", :profile_type => 'Person')
37 37  
38 38 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle1.id)
39 39 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle2.id)
... ... @@ -79,7 +79,7 @@ class NotifyActivityToProfilesJobTest &lt; ActiveSupport::TestCase
79 79 refute NotifyActivityToProfilesJob::NOTIFY_ONLY_COMMUNITY.include?(action_tracker.verb)
80 80 p1, p2, m1, m2 = fast_create(Person), fast_create(Person), fast_create(Person), fast_create(Person)
81 81  
82   - circle1 = Circle.create!(:person=> p1, :name => "Zombies", :profile_type => 'Person')
  82 + circle1 = Circle.create!(:owner=> p1, :name => "Zombies", :profile_type => 'Person')
83 83 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle1.id)
84 84  
85 85 fast_create(RoleAssignment, :accessor_id => m1.id, :role_id => 3, :resource_id => community.id)
... ... @@ -127,8 +127,8 @@ class NotifyActivityToProfilesJobTest &lt; ActiveSupport::TestCase
127 127 refute NotifyActivityToProfilesJob::NOTIFY_ONLY_COMMUNITY.include?(action_tracker.verb)
128 128 p1, p2, m1, m2 = fast_create(Person), fast_create(Person), fast_create(Person), fast_create(Person)
129 129  
130   - circle1 = Circle.create!(:person=> p1, :name => "Zombies", :profile_type => 'Person')
131   - circle2 = Circle.create!(:person=> p2, :name => "Zombies", :profile_type => 'Person')
  130 + circle1 = Circle.create!(:owner=> p1, :name => "Zombies", :profile_type => 'Person')
  131 + circle2 = Circle.create!(:owner=> p2, :name => "Zombies", :profile_type => 'Person')
132 132  
133 133 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle1.id)
134 134 fast_create(ProfileFollower, :profile_id => person.id, :circle_id => circle2.id)
... ...
test/unit/organization_test.rb
... ... @@ -267,9 +267,9 @@ class OrganizationTest &lt; ActiveSupport::TestCase
267 267 o.add_member(p3)
268 268 assert p3.is_member_of?(o)
269 269  
270   - assert_equal true, o.send(:followed_by?,p1)
271   - assert_equal true, o.send(:followed_by?,p3)
272   - assert_equal false, o.send(:followed_by?,p2)
  270 + assert o.followed_by? p1
  271 + assert o.followed_by? p3
  272 + refute o.followed_by? p2
273 273 end
274 274  
275 275 should "compose bare jabber id by identifier plus 'conference' and default hostname" do
... ...
test/unit/profile_test.rb
... ... @@ -2249,30 +2249,4 @@ class ProfileTest &lt; ActiveSupport::TestCase
2249 2249 assert_equivalent person3.followers, [person1, person2]
2250 2250 end
2251 2251  
2252   - should 'return all profiles followed by a regular person' do
2253   - person1 = create_user('testperson-1').person
2254   - person2 = create_user('testperson-2').person
2255   - community = fast_create(Community)
2256   - circle1 = Circle.create!(:owner => person1, :name => "Night's Watch", :profile_type => 'Person')
2257   - circle2 = Circle.create!(:owner => person1, :name => "Free Folk", :profile_type => 'Community')
2258   -
2259   - person1.follow(person2, circle1)
2260   - person1.follow(community, circle2)
2261   - assert_equivalent [person2, community], Profile.followed_by(person1)
2262   - end
2263   -
2264   - should 'return all profiles followed by an external person' do
2265   - external_person = ExternalPerson.create!(identifier: 'johnlocke', name: 'John Locke',
2266   - source: 'anerenvironment.org', email: 'locke@island.org',
2267   - created_at: Date.yesterday)
2268   - person = create_user('testperson-2').person
2269   - community = fast_create(Community)
2270   - circle1 = Circle.create!(:owner => external_person, :name => "Night's Watch", :profile_type => 'Person')
2271   - circle2 = Circle.create!(:owner => external_person, :name => "Free Folk", :profile_type => 'Community')
2272   -
2273   - external_person.follow(person, circle1)
2274   - external_person.follow(community, circle2)
2275   - assert_equivalent [person, community], Profile.followed_by(external_person)
2276   - end
2277   -
2278 2252 end
... ...