profile_followers_test.rb
1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require_relative "../test_helper"
class ProfileFollowersTest < ActiveSupport::TestCase
should 'a person follow another' do
p1 = create_user('person_test').person
p2 = create_user('person_test_2').person
assert_difference 'ProfileFollower.count' do
p1.follow(p2)
end
assert_includes p2.followers(true), p1
assert_not_includes p1.followers(true), p2
end
should 'a person unfollow another person' do
p1 = create_user('person_test').person
p2 = create_user('person_test_2').person
p1.follow(p2)
assert_difference 'ProfileFollower.count', -1 do
p1.unfollow(p2)
end
assert_not_includes p2.followers(true), p1
end
should 'get the followed persons for a profile' do
p1 = create_user('person_test').person
p2 = create_user('person_test_2').person
p3 = create_user('person_test_3').person
p1.follow(p2)
p1.follow(p3)
assert_equivalent p1.following_profiles, [p2,p3]
assert_equivalent Profile.following_profiles(p1), [p2,p3]
end
should 'not follow same person twice' do
p1 = create_user('person_test').person
p2 = create_user('person_test_2').person
assert_difference 'ProfileFollower.count' do
p1.follow(p2)
p1.follow(p2)
end
assert_equivalent p1.following_profiles, [p2]
assert_equivalent p2.followers, [p1]
end
should 'show the correct message when a profile is followed by the same person' do
p1 = create_user('person_test').person
p2 = create_user('person_test_2').person
p1.follow(p2)
profile_follower = ProfileFollower.new
profile_follower.follower = p1
profile_follower.profile = p2
profile_follower.valid?
assert_includes profile_follower.errors.messages[:profile_id],
"can't follow the same profile twice"
end
end