interest 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +26 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +329 -0
- data/Rakefile +2 -0
- data/interest.gemspec +29 -0
- data/lib/generators/interest_generator.rb +18 -0
- data/lib/generators/templates/migrations/blockings.rb +14 -0
- data/lib/generators/templates/migrations/followings.rb +15 -0
- data/lib/generators/templates/models/blocking.rb +3 -0
- data/lib/generators/templates/models/following.rb +4 -0
- data/lib/interest.rb +49 -0
- data/lib/interest/base.rb +49 -0
- data/lib/interest/blockable.rb +25 -0
- data/lib/interest/blockable/blockee.rb +40 -0
- data/lib/interest/blockable/blocker.rb +69 -0
- data/lib/interest/blockable/blocking.rb +48 -0
- data/lib/interest/blockable/exceptions.rb +12 -0
- data/lib/interest/definition.rb +45 -0
- data/lib/interest/exception.rb +10 -0
- data/lib/interest/follow_requestable.rb +25 -0
- data/lib/interest/follow_requestable/exceptions.rb +12 -0
- data/lib/interest/follow_requestable/follow_request.rb +45 -0
- data/lib/interest/follow_requestable/follow_requestee.rb +45 -0
- data/lib/interest/follow_requestable/follow_requester.rb +92 -0
- data/lib/interest/followable.rb +25 -0
- data/lib/interest/followable/exceptions.rb +12 -0
- data/lib/interest/followable/followee.rb +41 -0
- data/lib/interest/followable/follower.rb +68 -0
- data/lib/interest/followable/following.rb +62 -0
- data/lib/interest/utils.rb +29 -0
- data/lib/interest/version.rb +3 -0
- data/spec/blockable_spec.rb +127 -0
- data/spec/database.yml.example +3 -0
- data/spec/follow_requestable_spec.rb +126 -0
- data/spec/followable_spec.rb +171 -0
- data/spec/models/blocking_spec.rb +42 -0
- data/spec/models/following_spec.rb +120 -0
- data/spec/spec_helper.rb +103 -0
- data/spec/support/database.rb +10 -0
- data/spec/support/models/blockable_user.rb +8 -0
- data/spec/support/models/blocking.rb +4 -0
- data/spec/support/models/collection.rb +6 -0
- data/spec/support/models/follow_requestable_and_blockable_user.rb +8 -0
- data/spec/support/models/follow_requestable_user.rb +9 -0
- data/spec/support/models/followable_and_blockable_user.rb +9 -0
- data/spec/support/models/followable_user.rb +8 -0
- data/spec/support/models/following.rb +4 -0
- data/spec/support/models/stuff.rb +6 -0
- data/spec/support/schema.rb +26 -0
- metadata +211 -0
@@ -0,0 +1,126 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "FollowRequestable" do
|
4
|
+
it "should follow request" do
|
5
|
+
user = FollowRequestableUser.create!
|
6
|
+
other_user = FollowRequestableUser.create!
|
7
|
+
|
8
|
+
user.request_to_follow(other_user)
|
9
|
+
|
10
|
+
expect(user).to have_requested_to_follow(other_user)
|
11
|
+
expect(other_user).to have_been_requested_to_follow(user)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should not duplicate follow request" do
|
15
|
+
user = FollowRequestableUser.create!
|
16
|
+
other_user = FollowRequestableUser.create!
|
17
|
+
|
18
|
+
user.request_to_follow(other_user)
|
19
|
+
user.request_to_follow(other_user)
|
20
|
+
|
21
|
+
expect(user.outgoing_follow_requests.count).to eq(1)
|
22
|
+
expect(user.follow_requestee_follow_requestable_users.count).to eq(1)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be a Following" do
|
26
|
+
user = FollowRequestableUser.create!
|
27
|
+
other_user = FollowRequestableUser.create!
|
28
|
+
|
29
|
+
user.request_to_follow(other_user)
|
30
|
+
|
31
|
+
expect(user.outgoing_follow_requests.of(FollowRequestableUser)).to be_present.and all be_a Following
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should be a model is requested to follow" do
|
35
|
+
user = FollowRequestableUser.create!
|
36
|
+
other_user = FollowRequestableUser.create!
|
37
|
+
collection = Collection.create!
|
38
|
+
|
39
|
+
user.request_to_follow(other_user)
|
40
|
+
user.request_to_follow(collection)
|
41
|
+
|
42
|
+
expect(user.follow_requestee_follow_requestable_users).to be_present.and all be_a FollowRequestableUser
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should cancel follow request" do
|
46
|
+
user = FollowRequestableUser.create!
|
47
|
+
other_user = FollowRequestableUser.create!
|
48
|
+
|
49
|
+
user.request_to_follow(other_user)
|
50
|
+
user.cancel_request_to_follow(other_user)
|
51
|
+
|
52
|
+
expect(user).not_to have_requested_to_follow(other_user)
|
53
|
+
expect(other_user).not_to have_been_requested_to_follow(user)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should not follow request self" do
|
57
|
+
user = FollowRequestableUser.create!
|
58
|
+
|
59
|
+
user.request_to_follow(user)
|
60
|
+
|
61
|
+
expect(user).not_to have_been_requested_to_follow(user)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should not follow request self and raise exception" do
|
65
|
+
user = FollowRequestableUser.create!
|
66
|
+
|
67
|
+
expect { user.request_to_follow!(user) }.to raise_error(Interest::FollowRequestable::Rejected)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not follow request if already following" do
|
71
|
+
user = FollowRequestableUser.create!
|
72
|
+
other_user = FollowRequestableUser.create!
|
73
|
+
|
74
|
+
user.follow(other_user)
|
75
|
+
|
76
|
+
expect { user.request_to_follow!(other_user) }.to raise_error(Interest::FollowRequestable::Rejected)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should not follow request if blocked" do
|
80
|
+
user = FollowRequestableAndBlockableUser.create!
|
81
|
+
other_user = FollowRequestableAndBlockableUser.create!
|
82
|
+
|
83
|
+
other_user.block(user)
|
84
|
+
|
85
|
+
expect { user.request_to_follow!(other_user) }.to raise_error(Interest::FollowRequestable::Rejected)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should follow or request to follow" do
|
89
|
+
user = FollowRequestableUser.create!
|
90
|
+
other_user = FollowRequestableUser.create!
|
91
|
+
|
92
|
+
allow(user).to receive(:requires_request_to_follow?).and_return(true)
|
93
|
+
allow(other_user).to receive(:requires_request_to_follow?).and_return(false)
|
94
|
+
|
95
|
+
expect(user.follow_or_request_to_follow!(other_user).followed?).to eq(true)
|
96
|
+
expect(other_user.follow_or_request_to_follow!(user).requested_to_follow?).to eq(true)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should find outgoing follow request of specified type" do
|
100
|
+
user = FollowRequestableUser.create!
|
101
|
+
other_user1 = FollowRequestableUser.create!
|
102
|
+
other_user2 = FollowRequestableUser.create!
|
103
|
+
collection = Collection.create!
|
104
|
+
|
105
|
+
user.request_to_follow(other_user1)
|
106
|
+
user.request_to_follow(other_user2)
|
107
|
+
user.request_to_follow(collection)
|
108
|
+
|
109
|
+
expect(user.outgoing_follow_requests.of(FollowRequestableUser)).to have_exactly(2).items
|
110
|
+
expect(user.outgoing_follow_requests.of(Collection)).to have_exactly(1).items
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should find incoming follow request of specified type" do
|
114
|
+
user = FollowRequestableUser.create!
|
115
|
+
other_user1 = FollowRequestableUser.create!
|
116
|
+
other_user2 = FollowRequestableUser.create!
|
117
|
+
collection = Collection.create!
|
118
|
+
|
119
|
+
other_user1.request_to_follow(user)
|
120
|
+
other_user2.request_to_follow(user)
|
121
|
+
collection.request_to_follow(user)
|
122
|
+
|
123
|
+
expect(user.incoming_follow_requests.of(FollowRequestableUser)).to have_exactly(2).items
|
124
|
+
expect(user.incoming_follow_requests.of(Collection)).to have_exactly(1).items
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Followable" do
|
4
|
+
it "should follow other" do
|
5
|
+
user = FollowableUser.create!
|
6
|
+
other_user = FollowableUser.create!
|
7
|
+
|
8
|
+
user.follow(other_user)
|
9
|
+
|
10
|
+
expect(user).to be_following(other_user)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should not follow self and raise exception" do
|
14
|
+
user = FollowableUser.create!
|
15
|
+
|
16
|
+
expect { user.follow!(user) }.to raise_error(Interest::Followable::Rejected)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should not follow self" do
|
20
|
+
user = FollowableUser.create!
|
21
|
+
|
22
|
+
user.follow(user)
|
23
|
+
|
24
|
+
expect(user.following_followable_users).to be_empty
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not duplicate followee" do
|
28
|
+
user = FollowableUser.create!
|
29
|
+
other_user = FollowableUser.create!
|
30
|
+
|
31
|
+
user.follow(other_user)
|
32
|
+
user.follow(other_user)
|
33
|
+
|
34
|
+
expect(user.following_relationships.count).to eq(1)
|
35
|
+
expect(user.following_followable_users.count).to eq(1)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be a Following" do
|
39
|
+
user = FollowableUser.create!
|
40
|
+
other_user = FollowableUser.create!
|
41
|
+
|
42
|
+
user.follow(other_user)
|
43
|
+
|
44
|
+
expect(user.following_relationships.of(FollowableUser)).to be_present.and all be_a Following
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should be a model is followed" do
|
48
|
+
user = FollowableUser.create!
|
49
|
+
other_user = FollowableUser.create!
|
50
|
+
stuff = Stuff.create!
|
51
|
+
|
52
|
+
user.follow(other_user)
|
53
|
+
user.follow(stuff)
|
54
|
+
|
55
|
+
expect(user.following_followable_users).to be_present.and all be_a FollowableUser
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should follow several types" do
|
59
|
+
user = FollowableUser.create!
|
60
|
+
other_user = FollowableUser.create!
|
61
|
+
stuff = Stuff.create!
|
62
|
+
|
63
|
+
user.follow(other_user)
|
64
|
+
user.follow(stuff)
|
65
|
+
|
66
|
+
expect(user).to be_following(other_user)
|
67
|
+
expect(user).to be_following(stuff)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should unfollow" do
|
71
|
+
user = FollowableUser.create!
|
72
|
+
other_user = FollowableUser.create!
|
73
|
+
|
74
|
+
user.follow(other_user)
|
75
|
+
user.unfollow(other_user)
|
76
|
+
|
77
|
+
expect(user).not_to be_following(other_user)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should determine if self is followed by other" do
|
81
|
+
user = FollowableUser.create!
|
82
|
+
other_user = FollowableUser.create!
|
83
|
+
indifferent_user = FollowableUser.create!
|
84
|
+
|
85
|
+
other_user.follow(user)
|
86
|
+
|
87
|
+
expect(user).to be_followed_by(other_user)
|
88
|
+
expect(user).not_to be_followed_by(indifferent_user)
|
89
|
+
end
|
90
|
+
|
91
|
+
context "following several types" do
|
92
|
+
let(:user) { FollowableUser.create! }
|
93
|
+
let(:popular_user) { FollowableUser.create! }
|
94
|
+
|
95
|
+
before do
|
96
|
+
other_user = FollowableUser.create!
|
97
|
+
stuff = Stuff.create!
|
98
|
+
collection = Collection.create!
|
99
|
+
|
100
|
+
user.following_relationships.destroy_all
|
101
|
+
popular_user.follower_relationships.destroy_all
|
102
|
+
|
103
|
+
user.follow(other_user)
|
104
|
+
user.follow(stuff)
|
105
|
+
user.follow(collection)
|
106
|
+
user.follow(popular_user)
|
107
|
+
other_user.follow(popular_user)
|
108
|
+
collection.follow(popular_user)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should count following" do
|
112
|
+
expect(user.following_relationships.count).to eq(4)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should count each type of followings" do
|
116
|
+
expect(user.following_followable_users.count).to eq(2)
|
117
|
+
expect(user.following_stuffs.count).to eq(1)
|
118
|
+
expect(user.following_collections.count).to eq(1)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should count followers" do
|
122
|
+
expect(popular_user.follower_relationships.count).to eq(3)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should count each type of followers" do
|
126
|
+
expect(popular_user.follower_followable_users.count).to eq(2)
|
127
|
+
expect(popular_user.follower_collections.count).to eq(1)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should destroy their follow requests when either requester or requestee follows other" do
|
132
|
+
user = FollowRequestableUser.create!
|
133
|
+
other_user = FollowRequestableUser.create!
|
134
|
+
|
135
|
+
user.request_to_follow(other_user)
|
136
|
+
other_user.request_to_follow(user)
|
137
|
+
|
138
|
+
user.follow(other_user)
|
139
|
+
|
140
|
+
expect(user).not_to have_requested_to_follow(other_user)
|
141
|
+
expect(other_user).not_to have_been_requested_to_follow(user)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should find outgoing following of specified type" do
|
145
|
+
user = FollowableUser.create!
|
146
|
+
other_user1 = FollowableUser.create!
|
147
|
+
other_user2 = FollowableUser.create!
|
148
|
+
collection = Collection.create!
|
149
|
+
|
150
|
+
user.follow(other_user1)
|
151
|
+
user.follow(other_user2)
|
152
|
+
user.follow(collection)
|
153
|
+
|
154
|
+
expect(user.following_relationships.of(FollowableUser)).to have_exactly(2).items
|
155
|
+
expect(user.following_relationships.of(Collection)).to have_exactly(1).items
|
156
|
+
end
|
157
|
+
|
158
|
+
it "should find incoming following of specified type" do
|
159
|
+
user = FollowableUser.create!
|
160
|
+
other_user1 = FollowableUser.create!
|
161
|
+
other_user2 = FollowableUser.create!
|
162
|
+
collection = Collection.create!
|
163
|
+
|
164
|
+
other_user1.follow(user)
|
165
|
+
other_user2.follow(user)
|
166
|
+
collection.follow(user)
|
167
|
+
|
168
|
+
expect(user.follower_relationships.of(FollowableUser)).to have_exactly(2).items
|
169
|
+
expect(user.follower_relationships.of(Collection)).to have_exactly(1).items
|
170
|
+
end
|
171
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Blocking do
|
4
|
+
it "should be invalid if blocker and blockee are not set" do
|
5
|
+
expect { Blocking.create! }.to raise_error(ActiveRecord::RecordInvalid)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be invalid" do
|
9
|
+
user = BlockableUser.create!
|
10
|
+
other_user = FollowableUser.create!
|
11
|
+
|
12
|
+
expect { Blocking.create! blocker: user, blockee: other_user }.to raise_error(ActiveRecord::RecordInvalid)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should destroy relationships between a and b" do
|
16
|
+
a = BlockableUser.create!
|
17
|
+
b = BlockableUser.create!
|
18
|
+
|
19
|
+
a.block(b)
|
20
|
+
b.block(a)
|
21
|
+
|
22
|
+
Blocking.destroy_relationships_between(a, b)
|
23
|
+
|
24
|
+
expect(Blocking.between(a, b)).to have_exactly(0).items
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "between scope" do
|
28
|
+
let(:a) { BlockableUser.create! }
|
29
|
+
let(:b) { BlockableUser.create! }
|
30
|
+
|
31
|
+
before do
|
32
|
+
Blocking.destroy_relationships_between(a, b)
|
33
|
+
|
34
|
+
a.block(b)
|
35
|
+
b.block(a)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should get relationships between a and b" do
|
39
|
+
expect(Blocking.between(a, b)).to have_exactly(2).items
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Following do
|
4
|
+
it "should be invalid if follower and followee are not set" do
|
5
|
+
expect { Following.create! }.to raise_error(ActiveRecord::RecordInvalid)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be invalid" do
|
9
|
+
user = FollowRequestableAndBlockableUser.create!
|
10
|
+
other_user = FollowRequestableAndBlockableUser.create!
|
11
|
+
|
12
|
+
other_user.block(user)
|
13
|
+
|
14
|
+
expect { Following.create! follower: user, followee: other_user, status: "pending" }.to raise_error(ActiveRecord::RecordInvalid)
|
15
|
+
expect { Following.create! follower: user, followee: other_user, status: "accepted" }.to raise_error(ActiveRecord::RecordInvalid)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should let requester follow requestee when accepted request" do
|
19
|
+
user = FollowRequestableUser.create!
|
20
|
+
other_user = FollowRequestableUser.create!
|
21
|
+
|
22
|
+
user.request_to_follow(other_user).accept!
|
23
|
+
|
24
|
+
expect(user).to be_following(other_user)
|
25
|
+
expect(other_user).not_to be_following(user)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should change status when accepted request" do
|
29
|
+
user = FollowRequestableUser.create!
|
30
|
+
other_user = FollowRequestableUser.create!
|
31
|
+
|
32
|
+
follow_request = user.request_to_follow(other_user)
|
33
|
+
follow_request.accept!
|
34
|
+
|
35
|
+
expect(follow_request).to be_accepted
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should destroy when rejected request" do
|
39
|
+
user = FollowRequestableUser.create!
|
40
|
+
other_user = FollowRequestableUser.create!
|
41
|
+
|
42
|
+
follow_request = user.request_to_follow(other_user)
|
43
|
+
follow_request.reject!
|
44
|
+
|
45
|
+
expect(follow_request).to be_destroyed
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should accept to follow and follow each other" do
|
49
|
+
user = FollowRequestableUser.create!
|
50
|
+
other_user = FollowRequestableUser.create!
|
51
|
+
|
52
|
+
request = user.request_to_follow(other_user)
|
53
|
+
request.accept_mutual_follow!
|
54
|
+
|
55
|
+
expect(user).to be_following(other_user)
|
56
|
+
expect(other_user).to be_following(user)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should follow each other" do
|
60
|
+
user = FollowRequestableUser.create!
|
61
|
+
other_user = FollowRequestableUser.create!
|
62
|
+
|
63
|
+
user.follow(other_user).mutual
|
64
|
+
|
65
|
+
expect(user).to be_following(other_user)
|
66
|
+
expect(other_user).to be_following(user)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should destroy relationships between a and b" do
|
70
|
+
a = FollowRequestableUser.create!
|
71
|
+
b = FollowRequestableUser.create!
|
72
|
+
|
73
|
+
a.follow(b).mutual
|
74
|
+
|
75
|
+
Following.destroy_relationships_between(a, b)
|
76
|
+
|
77
|
+
expect(Following.between(a, b)).to have_exactly(0).items
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "accepted and pending scopes" do
|
81
|
+
before :all do
|
82
|
+
Following.destroy_all
|
83
|
+
|
84
|
+
2.times { FollowRequestableUser.create!.follow!(FollowRequestableUser.create!) }
|
85
|
+
2.times { FollowRequestableUser.create!.request_to_follow!(FollowRequestableUser.create!) }
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should get all following" do
|
89
|
+
expect(Following.accepted).to be_present.and all be_accepted
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should get all follow requests" do
|
93
|
+
expect(Following.pending).to be_present.and all be_pending
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "between scope" do
|
98
|
+
let(:a) { FollowRequestableUser.create! }
|
99
|
+
let(:b) { FollowRequestableUser.create! }
|
100
|
+
|
101
|
+
before do
|
102
|
+
Following.destroy_relationships_between(a, b)
|
103
|
+
|
104
|
+
a.follow(b)
|
105
|
+
b.request_to_follow(a)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should get all relationships between a and b" do
|
109
|
+
expect(Following.between(a, b)).to have_exactly(2).items
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should get accepted relationship" do
|
113
|
+
expect(Following.between(a, b).accepted).to have_exactly(1).items
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should get pending relationship" do
|
117
|
+
expect(Following.between(a, b).pending).to have_exactly(1).items
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|