amistad 0.9.2 → 0.10.0
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/Gemfile.lock +81 -68
- data/README.markdown +1 -1
- data/amistad.gemspec +6 -6
- data/lib/amistad/active_record_friend_model.rb +7 -25
- data/lib/amistad/mongo_mapper_friend_model.rb +0 -11
- data/lib/amistad/mongoid_friend_model.rb +0 -10
- data/lib/amistad/version.rb +1 -1
- data/spec/activerecord/activerecord_spec_helper.rb +0 -3
- data/spec/activerecord/friend_spec.rb +0 -3
- data/spec/support/activerecord/friendship_examples.rb +29 -29
- data/spec/support/friend_examples.rb +226 -226
- metadata +48 -84
@@ -1,407 +1,407 @@
|
|
1
1
|
shared_examples_for "a friend model" do
|
2
2
|
context "when creating friendships" do
|
3
3
|
it "should invite other users to friends" do
|
4
|
-
@john.invite(@jane).
|
5
|
-
@victoria.invite(@john).
|
4
|
+
expect(@john.invite(@jane)).to eq(true)
|
5
|
+
expect(@victoria.invite(@john)).to eq(true)
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should approve only friendships requested by other users" do
|
9
|
-
@john.invite(@jane).
|
10
|
-
@jane.approve(@john).
|
11
|
-
@victoria.invite(@john).
|
12
|
-
@john.approve(@victoria).
|
9
|
+
expect(@john.invite(@jane)).to eq(true)
|
10
|
+
expect(@jane.approve(@john)).to eq(true)
|
11
|
+
expect(@victoria.invite(@john)).to eq(true)
|
12
|
+
expect(@john.approve(@victoria)).to eq(true)
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should not invite an already invited user" do
|
16
|
-
@john.invite(@jane).
|
17
|
-
@john.invite(@jane).
|
18
|
-
@jane.invite(@john).
|
16
|
+
expect(@john.invite(@jane)).to eq(true)
|
17
|
+
expect(@john.invite(@jane)).to eq(false)
|
18
|
+
expect(@jane.invite(@john)).to eq(false)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should not invite an already approved user" do
|
22
|
-
@john.invite(@jane).
|
23
|
-
@jane.approve(@john).
|
24
|
-
@jane.invite(@john).
|
25
|
-
@john.invite(@jane).
|
22
|
+
expect(@john.invite(@jane)).to eq(true)
|
23
|
+
expect(@jane.approve(@john)).to eq(true)
|
24
|
+
expect(@jane.invite(@john)).to eq(false)
|
25
|
+
expect(@john.invite(@jane)).to eq(false)
|
26
26
|
end
|
27
27
|
|
28
28
|
it "should not invite an already blocked user" do
|
29
|
-
@john.invite(@jane).
|
30
|
-
@jane.block(@john).
|
31
|
-
@jane.invite(@john).
|
32
|
-
@john.invite(@jane).
|
29
|
+
expect(@john.invite(@jane)).to eq(true)
|
30
|
+
expect(@jane.block(@john)).to eq(true)
|
31
|
+
expect(@jane.invite(@john)).to eq(false)
|
32
|
+
expect(@john.invite(@jane)).to eq(false)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should not approve a self requested friendship" do
|
36
|
-
@john.invite(@jane).
|
37
|
-
@john.approve(@jane).
|
38
|
-
@victoria.invite(@john).
|
39
|
-
@victoria.approve(@john).
|
36
|
+
expect(@john.invite(@jane)).to eq(true)
|
37
|
+
expect(@john.approve(@jane)).to eq(false)
|
38
|
+
expect(@victoria.invite(@john)).to eq(true)
|
39
|
+
expect(@victoria.approve(@john)).to eq(false)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should not create a friendship with himself" do
|
43
|
-
@john.invite(@john).
|
43
|
+
expect(@john.invite(@john)).to eq(false)
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should not approve a non-existent friendship" do
|
47
|
-
@peter.approve(@john).
|
47
|
+
expect(@peter.approve(@john)).to eq(false)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
context "when listing friendships" do
|
52
52
|
before(:each) do
|
53
|
-
@john.invite(@jane).
|
54
|
-
@peter.invite(@john).
|
55
|
-
@john.invite(@james).
|
56
|
-
@james.approve(@john).
|
57
|
-
@mary.invite(@john).
|
58
|
-
@john.approve(@mary).
|
53
|
+
expect(@john.invite(@jane)).to eq(true)
|
54
|
+
expect(@peter.invite(@john)).to eq(true)
|
55
|
+
expect(@john.invite(@james)).to eq(true)
|
56
|
+
expect(@james.approve(@john)).to eq(true)
|
57
|
+
expect(@mary.invite(@john)).to eq(true)
|
58
|
+
expect(@john.approve(@mary)).to eq(true)
|
59
59
|
end
|
60
60
|
|
61
61
|
it "should list all the friends" do
|
62
|
-
@john.friends.
|
62
|
+
expect(@john.friends).to match_array([@mary, @james])
|
63
63
|
end
|
64
64
|
|
65
65
|
it "should not list non-friended users" do
|
66
|
-
@victoria.friends.
|
67
|
-
@john.friends.
|
68
|
-
@john.friends.
|
69
|
-
@john.friends.
|
66
|
+
expect(@victoria.friends).to be_empty
|
67
|
+
expect(@john.friends).to match_array([@mary, @james])
|
68
|
+
expect(@john.friends).to_not include(@peter)
|
69
|
+
expect(@john.friends).to_not include(@victoria)
|
70
70
|
end
|
71
71
|
|
72
72
|
it "should list the friends who invited him" do
|
73
|
-
@john.invited_by.
|
73
|
+
expect(@john.invited_by).to eq([@mary])
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should list the friends who were invited by him" do
|
77
|
-
@john.invited.
|
77
|
+
expect(@john.invited).to eq([@james])
|
78
78
|
end
|
79
79
|
|
80
80
|
it "should list the pending friends who invited him" do
|
81
|
-
@john.pending_invited_by.
|
81
|
+
expect(@john.pending_invited_by).to eq([@peter])
|
82
82
|
end
|
83
83
|
|
84
84
|
it "should list the pending friends who were invited by him" do
|
85
|
-
@john.pending_invited.
|
85
|
+
expect(@john.pending_invited).to eq([@jane])
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should list the friends he has in common with another user" do
|
89
|
-
@james.common_friends_with(@mary).
|
89
|
+
expect(@james.common_friends_with(@mary)).to eq([@john])
|
90
90
|
end
|
91
91
|
|
92
92
|
it "should not list the friends he does not have in common" do
|
93
|
-
@john.common_friends_with(@mary).count.
|
94
|
-
@john.common_friends_with(@mary).
|
95
|
-
@john.common_friends_with(@peter).count.
|
96
|
-
@john.common_friends_with(@peter).
|
93
|
+
expect(@john.common_friends_with(@mary).count).to eq(0)
|
94
|
+
expect(@john.common_friends_with(@mary)).to_not include(@james)
|
95
|
+
expect(@john.common_friends_with(@peter).count).to eq(0)
|
96
|
+
expect(@john.common_friends_with(@peter)).to_not include(@jane)
|
97
97
|
end
|
98
98
|
|
99
99
|
it "should check if a user is a friend" do
|
100
|
-
@john.friend_with?(@mary).
|
101
|
-
@mary.friend_with?(@john).
|
102
|
-
@john.friend_with?(@james).
|
103
|
-
@james.friend_with?(@john).
|
100
|
+
expect(@john.friend_with?(@mary)).to eq(true)
|
101
|
+
expect(@mary.friend_with?(@john)).to eq(true)
|
102
|
+
expect(@john.friend_with?(@james)).to eq(true)
|
103
|
+
expect(@james.friend_with?(@john)).to eq(true)
|
104
104
|
end
|
105
105
|
|
106
106
|
it "should check if a user is not a friend" do
|
107
|
-
@john.friend_with?(@jane).
|
108
|
-
@jane.friend_with?(@john).
|
109
|
-
@john.friend_with?(@peter).
|
110
|
-
@peter.friend_with?(@john).
|
107
|
+
expect(@john.friend_with?(@jane)).to eq(false)
|
108
|
+
expect(@jane.friend_with?(@john)).to eq(false)
|
109
|
+
expect(@john.friend_with?(@peter)).to eq(false)
|
110
|
+
expect(@peter.friend_with?(@john)).to eq(false)
|
111
111
|
end
|
112
112
|
|
113
113
|
it "should check if a user has any connections with another user" do
|
114
|
-
@john.connected_with?(@jane).
|
115
|
-
@jane.connected_with?(@john).
|
116
|
-
@john.connected_with?(@peter).
|
117
|
-
@peter.connected_with?(@john).
|
114
|
+
expect(@john.connected_with?(@jane)).to eq(true)
|
115
|
+
expect(@jane.connected_with?(@john)).to eq(true)
|
116
|
+
expect(@john.connected_with?(@peter)).to eq(true)
|
117
|
+
expect(@peter.connected_with?(@john)).to eq(true)
|
118
118
|
end
|
119
119
|
|
120
120
|
it "should check if a user does not have any connections with another user" do
|
121
|
-
@victoria.connected_with?(@john).
|
122
|
-
@john.connected_with?(@victoria).
|
121
|
+
expect(@victoria.connected_with?(@john)).to eq(false)
|
122
|
+
expect(@john.connected_with?(@victoria)).to eq(false)
|
123
123
|
end
|
124
124
|
|
125
125
|
it "should check if a user was invited by another" do
|
126
|
-
@jane.invited_by?(@john).
|
127
|
-
@james.invited_by?(@john).
|
126
|
+
expect(@jane.invited_by?(@john)).to eq(true)
|
127
|
+
expect(@james.invited_by?(@john)).to eq(true)
|
128
128
|
end
|
129
129
|
|
130
130
|
it "should check if a user was not invited by another" do
|
131
|
-
@john.invited_by?(@jane).
|
132
|
-
@victoria.invited_by?(@john).
|
131
|
+
expect(@john.invited_by?(@jane)).to eq(false)
|
132
|
+
expect(@victoria.invited_by?(@john)).to eq(false)
|
133
133
|
end
|
134
134
|
|
135
135
|
it "should check if a user has invited another user" do
|
136
|
-
@john.invited?(@jane).
|
137
|
-
@john.invited?(@james).
|
136
|
+
expect(@john.invited?(@jane)).to eq(true)
|
137
|
+
expect(@john.invited?(@james)).to eq(true)
|
138
138
|
end
|
139
139
|
|
140
140
|
it "should check if a user did not invite another user" do
|
141
|
-
@jane.invited?(@john).
|
142
|
-
@james.invited?(@john).
|
143
|
-
@john.invited?(@victoria).
|
144
|
-
@victoria.invited?(@john).
|
141
|
+
expect(@jane.invited?(@john)).to eq(false)
|
142
|
+
expect(@james.invited?(@john)).to eq(false)
|
143
|
+
expect(@john.invited?(@victoria)).to eq(false)
|
144
|
+
expect(@victoria.invited?(@john)).to eq(false)
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
148
|
context "when removing friendships" do
|
149
149
|
before(:each) do
|
150
|
-
@jane.invite(@james).
|
151
|
-
@james.approve(@jane).
|
152
|
-
@james.invite(@victoria).
|
153
|
-
@victoria.approve(@james).
|
154
|
-
@victoria.invite(@mary).
|
155
|
-
@mary.approve(@victoria).
|
156
|
-
@victoria.invite(@john).
|
157
|
-
@john.approve(@victoria).
|
158
|
-
@peter.invite(@victoria).
|
159
|
-
@victoria.invite(@elisabeth).
|
150
|
+
expect(@jane.invite(@james)).to eq(true)
|
151
|
+
expect(@james.approve(@jane)).to eq(true)
|
152
|
+
expect(@james.invite(@victoria)).to eq(true)
|
153
|
+
expect(@victoria.approve(@james)).to eq(true)
|
154
|
+
expect(@victoria.invite(@mary)).to eq(true)
|
155
|
+
expect(@mary.approve(@victoria)).to eq(true)
|
156
|
+
expect(@victoria.invite(@john)).to eq(true)
|
157
|
+
expect(@john.approve(@victoria)).to eq(true)
|
158
|
+
expect(@peter.invite(@victoria)).to eq(true)
|
159
|
+
expect(@victoria.invite(@elisabeth)).to eq(true)
|
160
160
|
end
|
161
161
|
|
162
162
|
it "should remove the friends invited by him" do
|
163
|
-
@victoria.friends.size.
|
164
|
-
@victoria.friends.
|
165
|
-
@victoria.invited.
|
166
|
-
@mary.friends.size.
|
167
|
-
@mary.friends.
|
168
|
-
@mary.invited_by.
|
169
|
-
|
170
|
-
@victoria.remove_friendship(@mary).
|
171
|
-
@victoria.friends.size.
|
172
|
-
@victoria.friends.
|
173
|
-
@victoria.invited.
|
174
|
-
@mary.friends.size.
|
175
|
-
@mary.friends.
|
176
|
-
@mary.invited_by.
|
163
|
+
expect(@victoria.friends.size).to eq(3)
|
164
|
+
expect(@victoria.friends).to include(@mary)
|
165
|
+
expect(@victoria.invited).to include(@mary)
|
166
|
+
expect(@mary.friends.size).to eq(1)
|
167
|
+
expect(@mary.friends).to include(@victoria)
|
168
|
+
expect(@mary.invited_by).to include(@victoria)
|
169
|
+
|
170
|
+
expect(@victoria.remove_friendship(@mary)).to eq(true)
|
171
|
+
expect(@victoria.friends.size).to eq(2)
|
172
|
+
expect(@victoria.friends).to_not include(@mary)
|
173
|
+
expect(@victoria.invited).to_not include(@mary)
|
174
|
+
expect(@mary.friends.size).to eq(0)
|
175
|
+
expect(@mary.friends).to_not include(@victoria)
|
176
|
+
expect(@mary.invited_by).to_not include(@victoria)
|
177
177
|
end
|
178
178
|
|
179
179
|
it "should remove the friends who invited him" do
|
180
|
-
@victoria.friends.size.
|
181
|
-
@victoria.friends.
|
182
|
-
@victoria.invited_by.
|
183
|
-
@james.friends.size.
|
184
|
-
@james.friends.
|
185
|
-
@james.invited.
|
186
|
-
|
187
|
-
@victoria.remove_friendship(@james).
|
188
|
-
@victoria.friends.size.
|
189
|
-
@victoria.friends.
|
190
|
-
@victoria.invited_by.
|
191
|
-
@james.friends.size.
|
192
|
-
@james.friends.
|
193
|
-
@james.invited.
|
180
|
+
expect(@victoria.friends.size).to eq(3)
|
181
|
+
expect(@victoria.friends).to include(@james)
|
182
|
+
expect(@victoria.invited_by).to include(@james)
|
183
|
+
expect(@james.friends.size).to eq(2)
|
184
|
+
expect(@james.friends).to include(@victoria)
|
185
|
+
expect(@james.invited).to include(@victoria)
|
186
|
+
|
187
|
+
expect(@victoria.remove_friendship(@james)).to eq(true)
|
188
|
+
expect(@victoria.friends.size).to eq(2)
|
189
|
+
expect(@victoria.friends).to_not include(@james)
|
190
|
+
expect(@victoria.invited_by).to_not include(@james)
|
191
|
+
expect(@james.friends.size).to eq(1)
|
192
|
+
expect(@james.friends).to_not include(@victoria)
|
193
|
+
expect(@james.invited).to_not include(@victoria)
|
194
194
|
end
|
195
195
|
|
196
196
|
it "should remove the pending friends invited by him" do
|
197
|
-
@victoria.pending_invited.size.
|
198
|
-
@victoria.pending_invited.
|
199
|
-
@elisabeth.pending_invited_by.size.
|
200
|
-
@elisabeth.pending_invited_by.
|
201
|
-
@victoria.remove_friendship(@elisabeth).
|
197
|
+
expect(@victoria.pending_invited.size).to eq(1)
|
198
|
+
expect(@victoria.pending_invited).to include(@elisabeth)
|
199
|
+
expect(@elisabeth.pending_invited_by.size).to eq(1)
|
200
|
+
expect(@elisabeth.pending_invited_by).to include(@victoria)
|
201
|
+
expect(@victoria.remove_friendship(@elisabeth)).to eq(true)
|
202
202
|
[@victoria, @elisabeth].map(&:reload)
|
203
|
-
@victoria.pending_invited.size.
|
204
|
-
@victoria.pending_invited.
|
205
|
-
@elisabeth.pending_invited_by.size.
|
206
|
-
@elisabeth.pending_invited_by.
|
203
|
+
expect(@victoria.pending_invited.size).to eq(0)
|
204
|
+
expect(@victoria.pending_invited).to_not include(@elisabeth)
|
205
|
+
expect(@elisabeth.pending_invited_by.size).to eq(0)
|
206
|
+
expect(@elisabeth.pending_invited_by).to_not include(@victoria)
|
207
207
|
end
|
208
208
|
|
209
209
|
it "should remove the pending friends who invited him" do
|
210
|
-
@victoria.pending_invited_by.count.
|
211
|
-
@victoria.pending_invited_by.
|
212
|
-
@peter.pending_invited.count.
|
213
|
-
@peter.pending_invited.
|
214
|
-
@victoria.remove_friendship(@peter).
|
210
|
+
expect(@victoria.pending_invited_by.count).to eq(1)
|
211
|
+
expect(@victoria.pending_invited_by).to include(@peter)
|
212
|
+
expect(@peter.pending_invited.count).to eq(1)
|
213
|
+
expect(@peter.pending_invited).to include(@victoria)
|
214
|
+
expect(@victoria.remove_friendship(@peter)).to eq(true)
|
215
215
|
[@victoria, @peter].map(&:reload)
|
216
|
-
@victoria.pending_invited_by.count.
|
217
|
-
@victoria.pending_invited_by.
|
218
|
-
@peter.pending_invited.count.
|
219
|
-
@peter.pending_invited.
|
216
|
+
expect(@victoria.pending_invited_by.count).to eq(0)
|
217
|
+
expect(@victoria.pending_invited_by).to_not include(@peter)
|
218
|
+
expect(@peter.pending_invited.count).to eq(0)
|
219
|
+
expect(@peter.pending_invited).to_not include(@victoria)
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
223
223
|
context "when blocking friendships" do
|
224
224
|
before(:each) do
|
225
|
-
@john.invite(@james).
|
226
|
-
@james.approve(@john).
|
227
|
-
@james.block(@john).
|
228
|
-
@mary.invite(@victoria).
|
229
|
-
@victoria.approve(@mary).
|
230
|
-
@victoria.block(@mary).
|
231
|
-
@victoria.invite(@david).
|
232
|
-
@david.block(@victoria).
|
233
|
-
@john.invite(@david).
|
234
|
-
@david.block(@john).
|
235
|
-
@peter.invite(@elisabeth).
|
236
|
-
@elisabeth.block(@peter).
|
237
|
-
@jane.invite(@john).
|
238
|
-
@jane.invite(@james).
|
239
|
-
@james.approve(@jane).
|
240
|
-
@victoria.invite(@jane).
|
241
|
-
@victoria.invite(@james).
|
242
|
-
@james.approve(@victoria).
|
225
|
+
expect(@john.invite(@james)).to eq(true)
|
226
|
+
expect(@james.approve(@john)).to eq(true)
|
227
|
+
expect(@james.block(@john)).to eq(true)
|
228
|
+
expect(@mary.invite(@victoria)).to eq(true)
|
229
|
+
expect(@victoria.approve(@mary)).to eq(true)
|
230
|
+
expect(@victoria.block(@mary)).to eq(true)
|
231
|
+
expect(@victoria.invite(@david)).to eq(true)
|
232
|
+
expect(@david.block(@victoria)).to eq(true)
|
233
|
+
expect(@john.invite(@david)).to eq(true)
|
234
|
+
expect(@david.block(@john)).to eq(true)
|
235
|
+
expect(@peter.invite(@elisabeth)).to eq(true)
|
236
|
+
expect(@elisabeth.block(@peter)).to eq(true)
|
237
|
+
expect(@jane.invite(@john)).to eq(true)
|
238
|
+
expect(@jane.invite(@james)).to eq(true)
|
239
|
+
expect(@james.approve(@jane)).to eq(true)
|
240
|
+
expect(@victoria.invite(@jane)).to eq(true)
|
241
|
+
expect(@victoria.invite(@james)).to eq(true)
|
242
|
+
expect(@james.approve(@victoria)).to eq(true)
|
243
243
|
end
|
244
244
|
|
245
245
|
it "should allow to block author of the invitation by invited user" do
|
246
|
-
@john.block(@jane).
|
247
|
-
@jane.block(@victoria).
|
246
|
+
expect(@john.block(@jane)).to eq(true)
|
247
|
+
expect(@jane.block(@victoria)).to eq(true)
|
248
248
|
end
|
249
249
|
|
250
250
|
it "should not allow to block invited user by invitation author" do
|
251
|
-
@jane.block(@john).
|
252
|
-
@victoria.block(@jane).
|
251
|
+
expect(@jane.block(@john)).to eq(false)
|
252
|
+
expect(@victoria.block(@jane)).to eq(false)
|
253
253
|
end
|
254
254
|
|
255
255
|
it "should allow to block approved users on both sides" do
|
256
|
-
@james.block(@jane).
|
257
|
-
@victoria.block(@james).
|
256
|
+
expect(@james.block(@jane)).to eq(true)
|
257
|
+
expect(@victoria.block(@james)).to eq(true)
|
258
258
|
end
|
259
259
|
|
260
260
|
it "should not allow to block not connected user" do
|
261
|
-
@david.block(@peter).
|
262
|
-
@peter.block(@david).
|
261
|
+
expect(@david.block(@peter)).to eq(false)
|
262
|
+
expect(@peter.block(@david)).to eq(false)
|
263
263
|
end
|
264
264
|
|
265
265
|
it "should not allow to block already blocked user" do
|
266
|
-
@john.block(@jane).
|
267
|
-
@john.block(@jane).
|
268
|
-
@james.block(@jane).
|
269
|
-
@james.block(@jane).
|
266
|
+
expect(@john.block(@jane)).to eq(true)
|
267
|
+
expect(@john.block(@jane)).to eq(false)
|
268
|
+
expect(@james.block(@jane)).to eq(true)
|
269
|
+
expect(@james.block(@jane)).to eq(false)
|
270
270
|
end
|
271
271
|
|
272
272
|
it "should list the blocked users" do
|
273
|
-
@jane.blocked.
|
274
|
-
@peter.blocked.
|
275
|
-
@james.blocked.
|
276
|
-
@victoria.blocked.
|
277
|
-
@david.blocked.
|
273
|
+
expect(@jane.blocked).to be_empty
|
274
|
+
expect(@peter.blocked).to be_empty
|
275
|
+
expect(@james.blocked).to eq([@john])
|
276
|
+
expect(@victoria.blocked).to eq([@mary])
|
277
|
+
expect(@david.blocked).to match_array([@john, @victoria])
|
278
278
|
end
|
279
279
|
|
280
280
|
it "should not list blocked users in friends" do
|
281
|
-
@james.friends.
|
281
|
+
expect(@james.friends).to match_array([@jane, @victoria])
|
282
282
|
@james.blocked.each do |user|
|
283
|
-
@james.friends.
|
284
|
-
user.friends.
|
283
|
+
expect(@james.friends).to_not include(user)
|
284
|
+
expect(user.friends).to_not include(@james)
|
285
285
|
end
|
286
286
|
end
|
287
287
|
|
288
288
|
it "should not list blocked users in invited" do
|
289
|
-
@victoria.invited.
|
289
|
+
expect(@victoria.invited).to eq([@james])
|
290
290
|
@victoria.blocked.each do |user|
|
291
|
-
@victoria.invited.
|
292
|
-
user.invited_by.
|
291
|
+
expect(@victoria.invited).to_not include(user)
|
292
|
+
expect(user.invited_by).to_not include(@victoria)
|
293
293
|
end
|
294
294
|
end
|
295
295
|
|
296
296
|
it "should not list blocked users in invited pending by" do
|
297
|
-
@david.pending_invited_by.
|
297
|
+
expect(@david.pending_invited_by).to be_empty
|
298
298
|
@david.blocked.each do |user|
|
299
|
-
@david.pending_invited_by.
|
300
|
-
user.pending_invited.
|
299
|
+
expect(@david.pending_invited_by).to_not include(user)
|
300
|
+
expect(user.pending_invited).to_not include(@david)
|
301
301
|
end
|
302
302
|
end
|
303
303
|
|
304
304
|
it "should check if a user is blocked" do
|
305
|
-
@james.blocked?(@john).
|
306
|
-
@victoria.blocked?(@mary).
|
307
|
-
@david.blocked?(@john).
|
308
|
-
@david.blocked?(@victoria).
|
305
|
+
expect(@james.blocked?(@john)).to eq(true)
|
306
|
+
expect(@victoria.blocked?(@mary)).to eq(true)
|
307
|
+
expect(@david.blocked?(@john)).to eq(true)
|
308
|
+
expect(@david.blocked?(@victoria)).to eq(true)
|
309
309
|
end
|
310
310
|
end
|
311
311
|
|
312
312
|
context "when unblocking friendships" do
|
313
313
|
before(:each) do
|
314
|
-
@john.invite(@james).
|
315
|
-
@james.approve(@john).
|
316
|
-
@john.block(@james).
|
317
|
-
@john.unblock(@james).
|
318
|
-
@mary.invite(@victoria).
|
319
|
-
@victoria.approve(@mary).
|
320
|
-
@victoria.block(@mary).
|
321
|
-
@victoria.unblock(@mary).
|
322
|
-
@victoria.invite(@david).
|
323
|
-
@david.block(@victoria).
|
324
|
-
@david.unblock(@victoria).
|
325
|
-
@john.invite(@david).
|
326
|
-
@david.block(@john).
|
327
|
-
@peter.invite(@elisabeth).
|
328
|
-
@elisabeth.block(@peter).
|
329
|
-
@jane.invite(@john).
|
330
|
-
@jane.invite(@james).
|
331
|
-
@james.approve(@jane).
|
332
|
-
@victoria.invite(@jane).
|
333
|
-
@victoria.invite(@james).
|
334
|
-
@james.approve(@victoria).
|
314
|
+
expect(@john.invite(@james)).to eq(true)
|
315
|
+
expect(@james.approve(@john)).to eq(true)
|
316
|
+
expect(@john.block(@james)).to eq(true)
|
317
|
+
expect(@john.unblock(@james)).to eq(true)
|
318
|
+
expect(@mary.invite(@victoria)).to eq(true)
|
319
|
+
expect(@victoria.approve(@mary)).to eq(true)
|
320
|
+
expect(@victoria.block(@mary)).to eq(true)
|
321
|
+
expect(@victoria.unblock(@mary)).to eq(true)
|
322
|
+
expect(@victoria.invite(@david)).to eq(true)
|
323
|
+
expect(@david.block(@victoria)).to eq(true)
|
324
|
+
expect(@david.unblock(@victoria)).to eq(true)
|
325
|
+
expect(@john.invite(@david)).to eq(true)
|
326
|
+
expect(@david.block(@john)).to eq(true)
|
327
|
+
expect(@peter.invite(@elisabeth)).to eq(true)
|
328
|
+
expect(@elisabeth.block(@peter)).to eq(true)
|
329
|
+
expect(@jane.invite(@john)).to eq(true)
|
330
|
+
expect(@jane.invite(@james)).to eq(true)
|
331
|
+
expect(@james.approve(@jane)).to eq(true)
|
332
|
+
expect(@victoria.invite(@jane)).to eq(true)
|
333
|
+
expect(@victoria.invite(@james)).to eq(true)
|
334
|
+
expect(@james.approve(@victoria)).to eq(true)
|
335
335
|
end
|
336
336
|
|
337
337
|
it "should allow to unblock prevoiusly blocked user" do
|
338
|
-
@david.unblock(@john).
|
339
|
-
@elisabeth.unblock(@peter).
|
338
|
+
expect(@david.unblock(@john)).to eq(true)
|
339
|
+
expect(@elisabeth.unblock(@peter)).to eq(true)
|
340
340
|
end
|
341
341
|
|
342
342
|
it "should not allow to unblock not prevoiusly blocked user" do
|
343
|
-
@john.unblock(@jane).
|
344
|
-
@james.unblock(@jane).
|
345
|
-
@victoria.unblock(@jane).
|
346
|
-
@james.unblock(@victoria).
|
343
|
+
expect(@john.unblock(@jane)).to eq(false)
|
344
|
+
expect(@james.unblock(@jane)).to eq(false)
|
345
|
+
expect(@victoria.unblock(@jane)).to eq(false)
|
346
|
+
expect(@james.unblock(@victoria)).to eq(false)
|
347
347
|
end
|
348
348
|
|
349
349
|
it "should not allow to unblock blocked user by himself" do
|
350
|
-
@john.unblock(@david).
|
351
|
-
@peter.unblock(@elisabeth).
|
350
|
+
expect(@john.unblock(@david)).to eq(false)
|
351
|
+
expect(@peter.unblock(@elisabeth)).to eq(false)
|
352
352
|
end
|
353
353
|
|
354
354
|
it "should list unblocked users in friends" do
|
355
|
-
@john.friends.
|
356
|
-
@mary.friends.
|
357
|
-
@victoria.friends.
|
358
|
-
@james.friends.
|
355
|
+
expect(@john.friends).to eq([@james])
|
356
|
+
expect(@mary.friends).to eq([@victoria])
|
357
|
+
expect(@victoria.friends).to match_array([@mary, @james])
|
358
|
+
expect(@james.friends).to match_array([@john, @jane, @victoria])
|
359
359
|
end
|
360
360
|
|
361
361
|
it "should list unblocked users in invited" do
|
362
|
-
@john.invited.
|
363
|
-
@mary.invited.
|
362
|
+
expect(@john.invited).to eq([@james])
|
363
|
+
expect(@mary.invited).to eq([@victoria])
|
364
364
|
end
|
365
365
|
|
366
366
|
it "should list unblocked users in invited by" do
|
367
|
-
@victoria.invited_by.
|
368
|
-
@james.invited_by.
|
367
|
+
expect(@victoria.invited_by).to eq([@mary])
|
368
|
+
expect(@james.invited_by).to match_array([@john, @jane, @victoria])
|
369
369
|
end
|
370
370
|
|
371
371
|
it "should list unblocked users in pending invited" do
|
372
|
-
@victoria.pending_invited.
|
372
|
+
expect(@victoria.pending_invited).to match_array([@jane, @david])
|
373
373
|
end
|
374
374
|
|
375
375
|
it "should list unblocked users in pending invited by" do
|
376
|
-
@david.pending_invited_by.
|
376
|
+
expect(@david.pending_invited_by).to eq([@victoria])
|
377
377
|
end
|
378
378
|
end
|
379
379
|
|
380
380
|
context "when counting friendships and blocks" do
|
381
381
|
before do
|
382
|
-
@john.invite(@james).
|
383
|
-
@james.approve(@john).
|
384
|
-
@john.invite(@victoria).
|
385
|
-
@victoria.approve(@john).
|
386
|
-
@elisabeth.invite(@john).
|
387
|
-
@john.approve(@elisabeth).
|
382
|
+
expect(@john.invite(@james)).to eq(true)
|
383
|
+
expect(@james.approve(@john)).to eq(true)
|
384
|
+
expect(@john.invite(@victoria)).to eq(true)
|
385
|
+
expect(@victoria.approve(@john)).to eq(true)
|
386
|
+
expect(@elisabeth.invite(@john)).to eq(true)
|
387
|
+
expect(@john.approve(@elisabeth)).to eq(true)
|
388
388
|
|
389
|
-
@victoria.invite(@david).
|
390
|
-
@david.block(@victoria).
|
391
|
-
@mary.invite(@victoria).
|
392
|
-
@victoria.block(@mary).
|
389
|
+
expect(@victoria.invite(@david)).to eq(true)
|
390
|
+
expect(@david.block(@victoria)).to eq(true)
|
391
|
+
expect(@mary.invite(@victoria)).to eq(true)
|
392
|
+
expect(@victoria.block(@mary)).to eq(true)
|
393
393
|
end
|
394
394
|
|
395
395
|
it "should return the correct count for total_friends" do
|
396
|
-
@john.total_friends.
|
397
|
-
@elisabeth.total_friends.
|
398
|
-
@james.total_friends.
|
399
|
-
@victoria.total_friends.
|
396
|
+
expect(@john.total_friends).to eq(3)
|
397
|
+
expect(@elisabeth.total_friends).to eq(1)
|
398
|
+
expect(@james.total_friends).to eq(1)
|
399
|
+
expect(@victoria.total_friends).to eq(1)
|
400
400
|
end
|
401
401
|
|
402
402
|
it "should return the correct count for total_blocked" do
|
403
|
-
@david.total_blocked.
|
404
|
-
@victoria.total_blocked.
|
403
|
+
expect(@david.total_blocked).to eq(1)
|
404
|
+
expect(@victoria.total_blocked).to eq(1)
|
405
405
|
end
|
406
406
|
end
|
407
407
|
end
|