acts_as_favoritor 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,283 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class ActsAsFollowableTest < ActiveSupport::TestCase
4
-
5
- context "instance methods" do
6
- setup do
7
- @sam = FactoryGirl.create(:sam)
8
- end
9
-
10
- should "be defined" do
11
- assert @sam.respond_to?(:followers_count)
12
- assert @sam.respond_to?(:followers)
13
- assert @sam.respond_to?(:followed_by?)
14
- end
15
- end
16
-
17
- context "acts_as_followable" do
18
- setup do
19
- @sam = FactoryGirl.create(:sam)
20
- @jon = FactoryGirl.create(:jon)
21
- @oasis = FactoryGirl.create(:oasis)
22
- @metallica = FactoryGirl.create(:metallica)
23
- @green_day = FactoryGirl.create(:green_day)
24
- @blink_182 = FactoryGirl.create(:blink_182)
25
- @sam.follow(@jon)
26
- end
27
-
28
- context "followers_count" do
29
- should "return the number of followers" do
30
- assert_equal 0, @sam.followers_count
31
- assert_equal 1, @jon.followers_count
32
- end
33
-
34
- should "return the proper number of multiple followers" do
35
- @bob = FactoryGirl.create(:bob)
36
- @sam.follow(@bob)
37
- assert_equal 0, @sam.followers_count
38
- assert_equal 1, @jon.followers_count
39
- assert_equal 1, @bob.followers_count
40
- end
41
- end
42
-
43
- context "followers" do
44
- should "return users" do
45
- assert_equal [], @sam.followers
46
- assert_equal [@sam], @jon.followers
47
- end
48
-
49
- should "return users (multiple followers)" do
50
- @bob = FactoryGirl.create(:bob)
51
- @sam.follow(@bob)
52
- assert_equal [], @sam.followers
53
- assert_equal [@sam], @jon.followers
54
- assert_equal [@sam], @bob.followers
55
- end
56
-
57
- should "return users (multiple followers, complex)" do
58
- @bob = FactoryGirl.create(:bob)
59
- @sam.follow(@bob)
60
- @jon.follow(@bob)
61
- assert_equal [], @sam.followers
62
- assert_equal [@sam], @jon.followers
63
- assert_equal [@sam, @jon], @bob.followers
64
- end
65
-
66
- should "accept AR options" do
67
- @bob = FactoryGirl.create(:bob)
68
- @bob.follow(@jon)
69
- assert_equal 1, @jon.followers(limit: 1).count
70
- end
71
- end
72
-
73
- context "followed_by" do
74
- should "return_follower_status" do
75
- assert_equal true, @jon.followed_by?(@sam)
76
- assert_equal false, @sam.followed_by?(@jon)
77
- end
78
- end
79
-
80
- context "destroying a followable" do
81
- setup do
82
- @jon.destroy
83
- end
84
-
85
- should_change("follow count", by: -1) { Follow.count }
86
- should_change("@sam.all_following.size", by: -1) { @sam.all_following.size }
87
- end
88
-
89
- context "get follow record" do
90
- setup do
91
- @bob = FactoryGirl.create(:bob)
92
- @follow = @bob.follow(@sam)
93
- end
94
-
95
- should "return follow record" do
96
- assert_equal @follow, @sam.get_follow_for(@bob)
97
- end
98
-
99
- should "return nil" do
100
- assert_nil @sam.get_follow_for(@jon)
101
- end
102
- end
103
-
104
- context "blocks" do
105
- setup do
106
- @bob = FactoryGirl.create(:bob)
107
- @jon.block(@sam)
108
- @jon.block(@bob)
109
- end
110
-
111
- should "accept AR options" do
112
- assert_equal 1, @jon.blocks(limit: 1).count
113
- end
114
- end
115
-
116
- context "blocking a follower" do
117
- context "in my following list" do
118
- setup do
119
- @jon.block(@sam)
120
- end
121
-
122
- should "remove him from followers" do
123
- assert_equal 0, @jon.followers_count
124
- end
125
-
126
- should "add him to the blocked followers" do
127
- assert_equal 1, @jon.blocked_followers_count
128
- end
129
-
130
- should "not be able to follow again" do
131
- @jon.follow(@sam)
132
- assert_equal 0, @jon.followers_count
133
- end
134
-
135
- should "not be present when listing followers" do
136
- assert_equal [], @jon.followers
137
- end
138
-
139
- should "be in the list of blocks" do
140
- assert_equal [@sam], @jon.blocks
141
- end
142
- end
143
-
144
- context "not in my following list" do
145
- setup do
146
- @sam.block(@jon)
147
- end
148
-
149
- should "add him to the blocked followers" do
150
- assert_equal 1, @sam.blocked_followers_count
151
- end
152
-
153
- should "not be able to follow again" do
154
- @sam.follow(@jon)
155
- assert_equal 0, @sam.followers_count
156
- end
157
-
158
- should "not be present when listing followers" do
159
- assert_equal [], @sam.followers
160
- end
161
-
162
- should "be in the list of blocks" do
163
- assert_equal [@jon], @sam.blocks
164
- end
165
- end
166
- end
167
-
168
- context "unblocking a blocked follow" do
169
- setup do
170
- @jon.block(@sam)
171
- @jon.unblock(@sam)
172
- end
173
-
174
- should "not include the unblocked user in the list of followers" do
175
- assert_equal [], @jon.followers
176
- end
177
-
178
- should "remove him from the blocked followers" do
179
- assert_equal 0, @jon.blocked_followers_count
180
- assert_equal [], @jon.blocks
181
- end
182
- end
183
-
184
- context "unblock a non-existent follow" do
185
- setup do
186
- @sam.remove_favorite(@jon)
187
- @jon.unblock(@sam)
188
- end
189
-
190
- should "not be in the list of followers" do
191
- assert_equal [], @jon.followers
192
- end
193
-
194
- should "not be in the blocked followers count" do
195
- assert_equal 0, @jon.blocked_followers_count
196
- end
197
-
198
- should "not be in the blocks list" do
199
- assert_equal [], @jon.blocks
200
- end
201
- end
202
-
203
- context "followers_by_type" do
204
- setup do
205
- @sam.follow(@oasis)
206
- @jon.follow(@oasis)
207
- end
208
-
209
- should "return the followers for given type" do
210
- assert_equal [@sam], @jon.followers_by_type('User')
211
- assert_equal [@sam, @jon], @oasis.followers_by_type('User')
212
- end
213
-
214
- should "not return block followers in the followers for a given type" do
215
- @oasis.block(@jon)
216
- assert_equal [@sam], @oasis.followers_by_type('User')
217
- end
218
-
219
- should "return the count for followers_by_type_count for a given type" do
220
- assert_equal 1, @jon.followers_by_type_count('User')
221
- assert_equal 2, @oasis.followers_by_type_count('User')
222
- end
223
-
224
- should "not count blocked follows in the count" do
225
- @oasis.block(@sam)
226
- assert_equal 1, @oasis.followers_by_type_count('User')
227
- end
228
- end
229
-
230
- context "followers_with_sti" do
231
- setup do
232
- @sam.follow(@green_day)
233
- @sam.follow(@blink_182)
234
- end
235
-
236
- should "return the followers for given type" do
237
- assert_equal @sam.follows_by_type('Band').first.followable, @green_day.becomes(Band)
238
- assert_equal @sam.follows_by_type('Band').second.followable, @blink_182.becomes(Band)
239
- assert @green_day.followers_by_type('User').include?(@sam)
240
- assert @blink_182.followers_by_type('User').include?(@sam)
241
- end
242
- end
243
-
244
- context "method_missing" do
245
- setup do
246
- @sam.follow(@oasis)
247
- @jon.follow(@oasis)
248
- end
249
-
250
- should "return the followers for given type" do
251
- assert_equal [@sam], @jon.user_followers
252
- assert_equal [@sam, @jon], @oasis.user_followers
253
- end
254
-
255
- should "not return block followers in the followers for a given type" do
256
- @oasis.block(@jon)
257
- assert_equal [@sam], @oasis.user_followers
258
- end
259
-
260
- should "return the count for followers_by_type_count for a given type" do
261
- assert_equal 1, @jon.count_user_followers
262
- assert_equal 2, @oasis.count_user_followers
263
- end
264
-
265
- should "not count blocked follows in the count" do
266
- @oasis.block(@sam)
267
- assert_equal 1, @oasis.count_user_followers
268
- end
269
- end
270
-
271
- context "respond_to?" do
272
- should "advertise that it responds to following methods" do
273
- assert @oasis.respond_to?(:user_followers)
274
- assert @oasis.respond_to?(:user_followers_count)
275
- end
276
-
277
- should "return false when called with a nonexistent method" do
278
- assert (not @oasis.respond_to?(:foobar))
279
- end
280
- end
281
-
282
- end
283
- end
@@ -1,224 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class ActsAsFollowerTest < ActiveSupport::TestCase
4
-
5
- context "instance methods" do
6
- setup do
7
- @sam = FactoryGirl.create(:sam)
8
- end
9
-
10
- should "be defined" do
11
- assert @sam.respond_to?(:following?)
12
- assert @sam.respond_to?(:follow_count)
13
- assert @sam.respond_to?(:follow)
14
- assert @sam.respond_to?(:remove_favorite)
15
- assert @sam.respond_to?(:follows_by_type)
16
- assert @sam.respond_to?(:all_follows)
17
- end
18
- end
19
-
20
- context "acts_as_follower" do
21
- setup do
22
- @sam = FactoryGirl.create(:sam)
23
- @jon = FactoryGirl.create(:jon)
24
- @oasis = FactoryGirl.create(:oasis)
25
- @sam.follow(@jon)
26
- @sam.follow(@oasis)
27
- end
28
-
29
- context "following" do
30
- should "return following_status" do
31
- assert_equal true, @sam.following?(@jon)
32
- assert_equal false, @jon.following?(@sam)
33
- end
34
-
35
- should "return follow_count" do
36
- assert_equal 2, @sam.follow_count
37
- assert_equal 0, @jon.follow_count
38
- end
39
- end
40
-
41
- context "follow a friend" do
42
- setup do
43
- @jon.follow(@sam)
44
- end
45
-
46
- should_change("Follow count", by: 1) { Follow.count }
47
- should_change("@jon.follow_count", by: 1) { @jon.follow_count }
48
-
49
- should "set the follower" do
50
- assert_equal @jon, Follow.last.follower
51
- end
52
-
53
- should "set the followable" do
54
- assert_equal @sam, Follow.last.followable
55
- end
56
- end
57
-
58
- context "follow yourself" do
59
- setup do
60
- @jon.follow(@jon)
61
- end
62
-
63
- should_not_change("Follow count") { Follow.count }
64
- should_not_change("@jon.follow_count") { @jon.follow_count }
65
-
66
- should "not set the follower" do
67
- assert_not_equal @jon, Follow.last.follower
68
- end
69
-
70
- should "not set the followable" do
71
- assert_not_equal @jon, Follow.last.followable
72
- end
73
- end
74
-
75
- context "remove_favorite" do
76
- setup do
77
- @sam.remove_favorite(@jon)
78
- end
79
-
80
- should_change("Follow count", by: -1) { Follow.count }
81
- should_change("@sam.follow_count", by: -1) { @sam.follow_count }
82
- end
83
-
84
- context "follows" do
85
- setup do
86
- @band_follow = Follow.where("follower_id = ? and follower_type = 'User' and followable_id = ? and followable_type = 'Band'", @sam.id, @oasis.id).first
87
- @user_follow = Follow.where("follower_id = ? and follower_type = 'User' and followable_id = ? and followable_type = 'User'", @sam.id, @jon.id).first
88
- end
89
-
90
- context "follows_by_type" do
91
- should "only return requested follows" do
92
- assert_equal [@band_follow], @sam.follows_by_type('Band')
93
- assert_equal [@user_follow], @sam.follows_by_type('User')
94
- end
95
-
96
- should "accept AR options" do
97
- @metallica = FactoryGirl.create(:metallica)
98
- @sam.follow(@metallica)
99
- assert_equal 1, @sam.follows_by_type('Band', limit: 1).count
100
- end
101
- end
102
-
103
- context "following_by_type_count" do
104
- should "return the count of the requested type" do
105
- @metallica = FactoryGirl.create(:metallica)
106
- @sam.follow(@metallica)
107
- assert_equal 2, @sam.following_by_type_count('Band')
108
- assert_equal 1, @sam.following_by_type_count('User')
109
- assert_equal 0, @jon.following_by_type_count('Band')
110
- @jon.block(@sam)
111
- assert_equal 0, @sam.following_by_type_count('User')
112
- end
113
- end
114
-
115
- context "all_follows" do
116
- should "return all follows" do
117
- assert_equal 2, @sam.all_follows.size
118
- assert @sam.all_follows.include?(@band_follow)
119
- assert @sam.all_follows.include?(@user_follow)
120
- assert_equal [], @jon.all_follows
121
- end
122
-
123
- should "accept AR options" do
124
- assert_equal 1, @sam.all_follows(limit: 1).count
125
- end
126
- end
127
- end
128
-
129
- context "all_following" do
130
- should "return the actual follow records" do
131
- assert_equal 2, @sam.all_following.size
132
- assert @sam.all_following.include?(@oasis)
133
- assert @sam.all_following.include?(@jon)
134
- assert_equal [], @jon.all_following
135
- end
136
-
137
- should "accept AR limit option" do
138
- assert_equal 1, @sam.all_following(limit: 1).count
139
- end
140
-
141
- should "accept AR where option" do
142
- assert_equal 1, @sam.all_following(where: { id: @oasis.id }).count
143
- end
144
- end
145
-
146
- context "following_by_type" do
147
- should "return only requested records" do
148
- assert_equal [@oasis], @sam.following_by_type('Band')
149
- assert_equal [@jon], @sam.following_by_type('User')
150
- end
151
-
152
- should "accept AR options" do
153
- @metallica = FactoryGirl.create(:metallica)
154
- @sam.follow(@metallica)
155
- assert_equal 1, @sam.following_by_type('Band', limit: 1).to_a.size
156
- end
157
- end
158
-
159
- context "method_missing" do
160
- should "call following_by_type" do
161
- assert_equal [@oasis], @sam.following_bands
162
- assert_equal [@jon], @sam.following_users
163
- end
164
-
165
- should "call following_by_type_count" do
166
- @metallica = FactoryGirl.create(:metallica)
167
- @sam.follow(@metallica)
168
- assert_equal 2, @sam.following_bands_count
169
- assert_equal 1, @sam.following_users_count
170
- assert_equal 0, @jon.following_bands_count
171
- @jon.block(@sam)
172
- assert_equal 0, @sam.following_users_count
173
- end
174
-
175
- should "raise on no method" do
176
- assert_raises (NoMethodError){ @sam.foobar }
177
- end
178
- end
179
-
180
- context "respond_to?" do
181
- should "advertise that it responds to following methods" do
182
- assert @sam.respond_to?(:following_users)
183
- assert @sam.respond_to?(:following_users_count)
184
- end
185
-
186
- should "return false when called with a nonexistent method" do
187
- assert (not @sam.respond_to?(:foobar))
188
- end
189
- end
190
-
191
- context "destroying follower" do
192
- setup do
193
- @jon.destroy
194
- end
195
-
196
- should_change("Follow.count", by: -1) { Follow.count }
197
- should_change("@sam.follow_count", by: -1) { @sam.follow_count }
198
- end
199
-
200
- context "blocked by followable" do
201
- setup do
202
- @jon.block(@sam)
203
- end
204
-
205
- should "return following_status" do
206
- assert_equal false, @sam.following?(@jon)
207
- end
208
-
209
- should "return follow_count" do
210
- assert_equal 1, @sam.follow_count
211
- end
212
-
213
- should "not return record of the blocked follows" do
214
- assert_equal 1, @sam.all_follows.size
215
- assert !@sam.all_follows.include?(@user_follow)
216
- assert !@sam.all_following.include?(@jon)
217
- assert_equal [], @sam.following_by_type('User')
218
- assert_equal [], @sam.follows_by_type('User')
219
- assert_equal [], @sam.following_users
220
- end
221
- end
222
- end
223
-
224
- end