cache_method 0.2.3 → 0.2.4
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.
- data/CHANGELOG +6 -0
- data/Gemfile +2 -0
- data/README.markdown +126 -55
- data/lib/cache_method/cached_result.rb +34 -59
- data/lib/cache_method/config.rb +8 -3
- data/lib/cache_method/debug.rb +4 -13
- data/lib/cache_method/generation.rb +28 -28
- data/lib/cache_method/version.rb +1 -1
- data/lib/cache_method.rb +47 -13
- data/test/helper.rb +6 -8
- data/test/test_cache_method.rb +236 -236
- metadata +2 -2
data/test/test_cache_method.rb
CHANGED
@@ -2,415 +2,416 @@ require 'helper'
|
|
2
2
|
|
3
3
|
require 'dalli'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
describe CacheMethod do
|
6
|
+
before do
|
7
7
|
Blog2.request_count = 0
|
8
8
|
CopyCat2.echo_count = 0
|
9
9
|
CopyCat1.say_count = 0
|
10
10
|
CopyCat2.say_count = 0
|
11
|
+
BlogM.request_count = 0
|
11
12
|
my_cache = Dalli::Client.new '127.0.0.1:11211'
|
12
13
|
my_cache.flush
|
13
14
|
CacheMethod.config.storage = my_cache
|
14
15
|
CacheMethod.config.generational = true
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
+
it %{cache_instance_method_with_args} do
|
18
19
|
a = CopyCat1.new 'mimo'
|
19
20
|
|
20
21
|
if RUBY_VERSION >= '1.9'
|
21
|
-
|
22
|
-
|
22
|
+
a.echo('hi').must_equal ['hi']
|
23
|
+
a.echo_count.must_equal 1
|
23
24
|
|
24
|
-
|
25
|
-
|
25
|
+
a.echo('hi').must_equal ['hi']
|
26
|
+
a.echo_count.must_equal 1
|
26
27
|
else
|
27
|
-
|
28
|
-
|
28
|
+
a.echo('hi').must_equal 'hi'
|
29
|
+
a.echo_count.must_equal 1
|
29
30
|
|
30
|
-
|
31
|
-
|
31
|
+
a.echo('hi').must_equal 'hi'
|
32
|
+
a.echo_count.must_equal 1
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
|
36
|
+
it %{cache_instance_method_with_nil_args} do
|
36
37
|
a = CopyCat1.new 'mimo'
|
37
38
|
|
38
39
|
if RUBY_VERSION >= '1.9'
|
39
|
-
|
40
|
-
|
40
|
+
a.echo.must_equal []
|
41
|
+
a.echo_count.must_equal 1
|
41
42
|
|
42
|
-
|
43
|
-
|
43
|
+
a.echo.must_equal []
|
44
|
+
a.echo_count.must_equal 1
|
44
45
|
|
45
|
-
|
46
|
-
|
46
|
+
a.echo(nil).must_equal [nil]
|
47
|
+
a.echo_count.must_equal 2
|
47
48
|
|
48
|
-
|
49
|
-
|
49
|
+
a.echo(nil).must_equal [nil]
|
50
|
+
a.echo_count.must_equal 2
|
50
51
|
else
|
51
|
-
|
52
|
-
|
52
|
+
a.echo.must_equal nil
|
53
|
+
a.echo_count.must_equal 1
|
53
54
|
|
54
|
-
|
55
|
-
|
55
|
+
a.echo.must_equal nil
|
56
|
+
a.echo_count.must_equal 1
|
56
57
|
|
57
|
-
|
58
|
-
|
58
|
+
a.echo(nil).must_equal nil
|
59
|
+
a.echo_count.must_equal 2
|
59
60
|
|
60
|
-
|
61
|
-
|
61
|
+
a.echo(nil).must_equal nil
|
62
|
+
a.echo_count.must_equal 2
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
65
|
-
|
66
|
+
it %{cache_instance_method_with_array_args} do
|
66
67
|
a = CopyCat1.new 'mimo'
|
67
68
|
|
68
69
|
if RUBY_VERSION >= '1.9'
|
69
|
-
|
70
|
-
|
70
|
+
a.echo(['hi']).must_equal [['hi']]
|
71
|
+
a.echo_count.must_equal 1
|
71
72
|
|
72
|
-
|
73
|
-
|
73
|
+
a.echo(['hi']).must_equal [['hi']]
|
74
|
+
a.echo_count.must_equal 1
|
74
75
|
|
75
|
-
|
76
|
-
|
76
|
+
a.echo(['bye']).must_equal [['bye']]
|
77
|
+
a.echo_count.must_equal 2
|
77
78
|
|
78
|
-
|
79
|
-
|
79
|
+
a.echo(['bye']).must_equal [['bye']]
|
80
|
+
a.echo_count.must_equal 2
|
80
81
|
|
81
|
-
|
82
|
-
|
82
|
+
a.echo([]).must_equal [[]]
|
83
|
+
a.echo_count.must_equal 3
|
83
84
|
|
84
|
-
|
85
|
-
|
85
|
+
a.echo([]).must_equal [[]]
|
86
|
+
a.echo_count.must_equal 3
|
86
87
|
else
|
87
|
-
|
88
|
-
|
88
|
+
a.echo(['hi']).must_equal ['hi']
|
89
|
+
a.echo_count.must_equal 1
|
89
90
|
|
90
|
-
|
91
|
-
|
91
|
+
a.echo(['hi']).must_equal ['hi']
|
92
|
+
a.echo_count.must_equal 1
|
92
93
|
|
93
|
-
|
94
|
-
|
94
|
+
a.echo(['bye']).must_equal ['bye']
|
95
|
+
a.echo_count.must_equal 2
|
95
96
|
|
96
|
-
|
97
|
-
|
97
|
+
a.echo(['bye']).must_equal ['bye']
|
98
|
+
a.echo_count.must_equal 2
|
98
99
|
|
99
|
-
|
100
|
-
|
100
|
+
a.echo([]).must_equal []
|
101
|
+
a.echo_count.must_equal 3
|
101
102
|
|
102
|
-
|
103
|
-
|
103
|
+
a.echo([]).must_equal []
|
104
|
+
a.echo_count.must_equal 3
|
104
105
|
end
|
105
106
|
end
|
106
107
|
|
107
|
-
|
108
|
+
it %{cache_instance_method_with_array_args_splat} do
|
108
109
|
a = CopyCat1.new 'mimo'
|
109
110
|
|
110
111
|
if RUBY_VERSION >= '1.9'
|
111
|
-
|
112
|
-
|
112
|
+
a.echo(['hi', 'there']).must_equal [['hi', 'there']]
|
113
|
+
a.echo_count.must_equal 1
|
113
114
|
|
114
|
-
|
115
|
-
|
115
|
+
a.echo('hi', 'there').must_equal ['hi', 'there']
|
116
|
+
a.echo_count.must_equal 2
|
116
117
|
else
|
117
|
-
|
118
|
-
|
118
|
+
a.echo(['hi', 'there']).must_equal ['hi', 'there']
|
119
|
+
a.echo_count.must_equal 1
|
119
120
|
|
120
|
-
|
121
|
-
|
121
|
+
a.echo('hi', 'there').must_equal ['hi', 'there']
|
122
|
+
a.echo_count.must_equal 2
|
122
123
|
end
|
123
124
|
end
|
124
125
|
|
125
|
-
|
126
|
-
|
127
|
-
|
126
|
+
it %{cache_class_method_with_args} do
|
127
|
+
CopyCat2.echo('hi').must_equal 'hi'
|
128
|
+
CopyCat2.echo_count.must_equal 1
|
128
129
|
|
129
|
-
|
130
|
-
|
130
|
+
CopyCat2.echo('hi').must_equal 'hi'
|
131
|
+
CopyCat2.echo_count.must_equal 1
|
131
132
|
end
|
132
133
|
|
133
|
-
|
134
|
-
|
135
|
-
|
134
|
+
it %{cache_class_method_with_nil_args} do
|
135
|
+
CopyCat2.echo.must_equal nil
|
136
|
+
CopyCat2.echo_count.must_equal 1
|
136
137
|
|
137
|
-
|
138
|
-
|
138
|
+
CopyCat2.echo.must_equal nil
|
139
|
+
CopyCat2.echo_count.must_equal 1
|
139
140
|
|
140
|
-
|
141
|
-
|
141
|
+
CopyCat2.echo(nil).must_equal nil
|
142
|
+
CopyCat2.echo_count.must_equal 2
|
142
143
|
|
143
|
-
|
144
|
-
|
144
|
+
CopyCat2.echo(nil).must_equal nil
|
145
|
+
CopyCat2.echo_count.must_equal 2
|
145
146
|
end
|
146
147
|
|
147
|
-
|
148
|
-
|
149
|
-
|
148
|
+
it %{cache_class_method_with_array_args} do
|
149
|
+
CopyCat2.echo(['hi']).must_equal ['hi']
|
150
|
+
CopyCat2.echo_count.must_equal 1
|
150
151
|
|
151
|
-
|
152
|
-
|
152
|
+
CopyCat2.echo(['hi']).must_equal ['hi']
|
153
|
+
CopyCat2.echo_count.must_equal 1
|
153
154
|
|
154
|
-
|
155
|
-
|
155
|
+
CopyCat2.echo(['bye']).must_equal ['bye']
|
156
|
+
CopyCat2.echo_count.must_equal 2
|
156
157
|
|
157
|
-
|
158
|
-
|
158
|
+
CopyCat2.echo(['bye']).must_equal ['bye']
|
159
|
+
CopyCat2.echo_count.must_equal 2
|
159
160
|
|
160
|
-
|
161
|
-
|
161
|
+
CopyCat2.echo([]).must_equal []
|
162
|
+
CopyCat2.echo_count.must_equal 3
|
162
163
|
|
163
|
-
|
164
|
-
|
164
|
+
CopyCat2.echo([]).must_equal []
|
165
|
+
CopyCat2.echo_count.must_equal 3
|
165
166
|
end
|
166
167
|
|
167
|
-
|
168
|
+
it %{cache_class_method_with_array_args_splat} do
|
168
169
|
if RUBY_VERSION >= '1.9'
|
169
|
-
|
170
|
-
|
170
|
+
CopyCat2.echo(['hi', 'there']).must_equal ['hi', 'there']
|
171
|
+
CopyCat2.echo_count.must_equal 1
|
171
172
|
|
172
|
-
|
173
|
-
|
173
|
+
CopyCat2.echo('hi', 'there').must_equal ['hi', 'there']
|
174
|
+
CopyCat2.echo_count.must_equal 2
|
174
175
|
else
|
175
|
-
|
176
|
-
|
176
|
+
CopyCat2.echo(['hi', 'there']).must_equal ['hi', 'there']
|
177
|
+
CopyCat2.echo_count.must_equal 1
|
177
178
|
|
178
|
-
|
179
|
-
|
179
|
+
CopyCat2.echo('hi', 'there').must_equal ['hi', 'there']
|
180
|
+
CopyCat2.echo_count.must_equal 2
|
180
181
|
end
|
181
182
|
end
|
182
183
|
|
183
|
-
|
184
|
+
it %{cache_instance_method} do
|
184
185
|
a = new_instance_of_my_blog
|
185
|
-
|
186
|
-
|
186
|
+
a.get_latest_entries.must_equal ["hello from #{a.name}"]
|
187
|
+
a.request_count.must_equal 1
|
187
188
|
a = new_instance_of_my_blog
|
188
|
-
|
189
|
-
|
189
|
+
a.get_latest_entries.must_equal ["hello from #{a.name}"]
|
190
|
+
a.request_count.must_equal 0
|
190
191
|
xxx = new_instance_of_another_blog
|
191
|
-
|
192
|
-
|
192
|
+
xxx.get_latest_entries.must_equal ["hello from #{xxx.name}"]
|
193
|
+
xxx.request_count.must_equal 1
|
193
194
|
end
|
194
195
|
|
195
|
-
|
196
|
+
it %{clear_instance_method} do
|
196
197
|
a = new_instance_of_my_blog
|
197
|
-
|
198
|
-
|
198
|
+
a.get_latest_entries.must_equal ["hello from #{a.name}"]
|
199
|
+
a.request_count.must_equal 1
|
199
200
|
a.cache_method_clear :get_latest_entries
|
200
|
-
|
201
|
-
|
201
|
+
a.get_latest_entries.must_equal ["hello from #{a.name}"]
|
202
|
+
a.request_count.must_equal 2
|
202
203
|
end
|
203
204
|
|
204
|
-
|
205
|
+
it %{clear_correct_instance_method} do
|
205
206
|
a = new_instance_of_my_blog
|
206
|
-
|
207
|
-
|
207
|
+
a.get_latest_entries.must_equal ["hello from #{a.name}"]
|
208
|
+
a.request_count.must_equal 1
|
208
209
|
a.cache_method_clear :foobar
|
209
|
-
|
210
|
-
|
210
|
+
a.get_latest_entries.must_equal ["hello from #{a.name}"]
|
211
|
+
a.request_count.must_equal 1
|
211
212
|
end
|
212
213
|
|
213
|
-
|
214
|
+
it %{clear_instance_method_from_correct_instance} do
|
214
215
|
a = new_instance_of_my_blog
|
215
|
-
|
216
|
-
|
216
|
+
a.get_latest_entries.must_equal ["hello from #{a.name}"]
|
217
|
+
a.request_count.must_equal 1
|
217
218
|
xxx = new_instance_of_another_blog
|
218
|
-
|
219
|
-
|
219
|
+
xxx.get_latest_entries.must_equal ["hello from #{xxx.name}"]
|
220
|
+
xxx.request_count.must_equal 1
|
220
221
|
xxx.cache_method_clear :get_latest_entries
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
222
|
+
a.get_latest_entries.must_equal ["hello from #{a.name}"]
|
223
|
+
a.request_count.must_equal 1
|
224
|
+
xxx.get_latest_entries.must_equal ["hello from #{xxx.name}"]
|
225
|
+
xxx.request_count.must_equal 2
|
225
226
|
end
|
226
227
|
|
227
|
-
|
228
|
+
it %{cache_instance_method_ttl} do
|
228
229
|
a = new_instance_of_my_blog
|
229
|
-
|
230
|
-
|
230
|
+
a.get_latest_entries2.must_equal ["voo vaa #{a.name}"]
|
231
|
+
a.request_count.must_equal 1
|
231
232
|
sleep 2
|
232
|
-
|
233
|
-
|
233
|
+
a.get_latest_entries2.must_equal ["voo vaa #{a.name}"]
|
234
|
+
a.request_count.must_equal 2
|
234
235
|
end
|
235
236
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
237
|
+
it %{cache_class_method} do
|
238
|
+
Blog2.request_count.must_equal 0
|
239
|
+
Blog2.get_latest_entries.must_equal 'danke schoen'
|
240
|
+
Blog2.request_count.must_equal 1
|
241
|
+
Blog2.get_latest_entries.must_equal 'danke schoen'
|
242
|
+
Blog2.request_count.must_equal 1
|
242
243
|
end
|
243
244
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
245
|
+
it %{clear_class_method} do
|
246
|
+
Blog2.request_count.must_equal 0
|
247
|
+
Blog2.get_latest_entries.must_equal 'danke schoen'
|
248
|
+
Blog2.request_count.must_equal 1
|
248
249
|
Blog2.cache_method_clear :get_latest_entries
|
249
|
-
|
250
|
-
|
250
|
+
Blog2.get_latest_entries.must_equal 'danke schoen'
|
251
|
+
Blog2.request_count.must_equal 2
|
251
252
|
end
|
252
253
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
254
|
+
it %{clear_correct_class_method} do
|
255
|
+
Blog2.request_count.must_equal 0
|
256
|
+
Blog2.get_latest_entries.must_equal 'danke schoen'
|
257
|
+
Blog2.request_count.must_equal 1
|
257
258
|
|
258
259
|
Blog2.cache_method_clear :foobar
|
259
|
-
|
260
|
-
|
260
|
+
Blog2.get_latest_entries.must_equal 'danke schoen'
|
261
|
+
Blog2.request_count.must_equal 1
|
261
262
|
|
262
263
|
Blog2.cache_method_clear :get_latest_entries
|
263
|
-
|
264
|
-
|
264
|
+
Blog2.get_latest_entries.must_equal 'danke schoen'
|
265
|
+
Blog2.request_count.must_equal 2
|
265
266
|
end
|
266
267
|
|
267
|
-
|
268
|
+
it %{never_set_storage} do
|
268
269
|
CacheMethod.config.instance_variable_set :@storage, nil
|
269
270
|
a = CopyCat1.new 'mimo'
|
270
271
|
|
271
272
|
if RUBY_VERSION >= '1.9'
|
272
|
-
|
273
|
-
|
273
|
+
a.echo('hi').must_equal ['hi']
|
274
|
+
a.echo_count.must_equal 1
|
274
275
|
|
275
|
-
|
276
|
-
|
276
|
+
a.echo('hi').must_equal ['hi']
|
277
|
+
a.echo_count.must_equal 1
|
277
278
|
else
|
278
|
-
|
279
|
-
|
279
|
+
a.echo('hi').must_equal 'hi'
|
280
|
+
a.echo_count.must_equal 1
|
280
281
|
|
281
|
-
|
282
|
-
|
282
|
+
a.echo('hi').must_equal 'hi'
|
283
|
+
a.echo_count.must_equal 1
|
283
284
|
end
|
284
285
|
end
|
285
286
|
|
286
|
-
|
287
|
+
it %{set_storage_to_nil} do
|
287
288
|
CacheMethod.config.storage = nil
|
288
289
|
a = CopyCat1.new 'mimo'
|
289
290
|
|
290
291
|
if RUBY_VERSION >= '1.9'
|
291
|
-
|
292
|
-
|
292
|
+
a.echo('hi').must_equal ['hi']
|
293
|
+
a.echo_count.must_equal 1
|
293
294
|
|
294
|
-
|
295
|
-
|
295
|
+
a.echo('hi').must_equal ['hi']
|
296
|
+
a.echo_count.must_equal 1
|
296
297
|
else
|
297
|
-
|
298
|
-
|
298
|
+
a.echo('hi').must_equal 'hi'
|
299
|
+
a.echo_count.must_equal 1
|
299
300
|
|
300
|
-
|
301
|
-
|
301
|
+
a.echo('hi').must_equal 'hi'
|
302
|
+
a.echo_count.must_equal 1
|
302
303
|
end
|
303
304
|
end
|
304
305
|
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
306
|
+
it %{cache_module_method} do
|
307
|
+
BlogM.request_count.must_equal 0
|
308
|
+
BlogM.get_latest_entries.must_equal 'danke schoen'
|
309
|
+
BlogM.request_count.must_equal 1
|
310
|
+
BlogM.get_latest_entries.must_equal 'danke schoen'
|
311
|
+
BlogM.request_count.must_equal 1
|
311
312
|
end
|
312
313
|
|
313
|
-
|
314
|
-
|
314
|
+
it %{as_cache_key} do
|
315
|
+
lambda do
|
315
316
|
a = CopyCat1a.new 'mimo'
|
316
317
|
a.echo 'hi'
|
317
|
-
end
|
318
|
+
end.must_raise(RuntimeError, /Used as_cache_key/)
|
318
319
|
end
|
319
320
|
|
320
|
-
|
321
|
-
|
321
|
+
it %{to_cache_key} do
|
322
|
+
lambda do
|
322
323
|
a = CopyCat1b.new 'mimo'
|
323
324
|
a.echo 'hi'
|
324
|
-
end
|
325
|
+
end.must_raise(RuntimeError, /Used to_cache_key/)
|
325
326
|
end
|
326
327
|
|
327
|
-
|
328
|
-
|
329
|
-
|
328
|
+
it %{method_added_by_extension} do
|
329
|
+
CopyCat2.say('hi').must_equal 'hi'
|
330
|
+
CopyCat2.say_count.must_equal 1
|
330
331
|
|
331
|
-
|
332
|
-
|
332
|
+
CopyCat2.say('hi').must_equal 'hi'
|
333
|
+
CopyCat2.say_count.must_equal 1
|
333
334
|
end
|
334
335
|
|
335
|
-
|
336
|
+
it %{method_added_by_inclusion} do
|
336
337
|
a = CopyCat1.new 'sayer'
|
337
338
|
|
338
|
-
|
339
|
-
|
339
|
+
a.say('hi').must_equal 'hi'
|
340
|
+
a.say_count.must_equal 1
|
340
341
|
|
341
|
-
|
342
|
-
|
342
|
+
a.say('hi').must_equal 'hi'
|
343
|
+
a.say_count.must_equal 1
|
343
344
|
end
|
344
345
|
|
345
|
-
|
346
|
-
|
347
|
-
|
346
|
+
it %{not_confused_by_module} do
|
347
|
+
CopyCat2.say('hi').must_equal 'hi'
|
348
|
+
CopyCat2.say_count.must_equal 1
|
348
349
|
|
349
|
-
|
350
|
-
|
350
|
+
CopyCat2.say('hi').must_equal 'hi'
|
351
|
+
CopyCat2.say_count.must_equal 1
|
351
352
|
|
352
|
-
|
353
|
-
|
353
|
+
CopyCat1.say('hi').must_equal 'hi'
|
354
|
+
CopyCat1.say_count.must_equal 1
|
354
355
|
|
355
|
-
|
356
|
-
|
356
|
+
CopyCat1.say('hi').must_equal 'hi'
|
357
|
+
CopyCat1.say_count.must_equal 1
|
357
358
|
end
|
358
359
|
|
359
|
-
|
360
|
+
it %{disable_generational_caching} do
|
360
361
|
CacheMethod.config.generational = false
|
361
362
|
|
362
363
|
a = CopyCat1.new 'mimo'
|
363
364
|
|
364
365
|
if RUBY_VERSION >= '1.9'
|
365
|
-
|
366
|
-
|
366
|
+
a.echo('hi').must_equal ['hi']
|
367
|
+
a.echo_count.must_equal 1
|
367
368
|
|
368
|
-
|
369
|
-
|
369
|
+
a.echo('hi').must_equal ['hi']
|
370
|
+
a.echo_count.must_equal 1
|
370
371
|
else
|
371
|
-
|
372
|
-
|
372
|
+
a.echo('hi').must_equal 'hi'
|
373
|
+
a.echo_count.must_equal 1
|
373
374
|
|
374
|
-
|
375
|
-
|
375
|
+
a.echo('hi').must_equal 'hi'
|
376
|
+
a.echo_count.must_equal 1
|
376
377
|
end
|
377
378
|
end
|
378
379
|
|
379
|
-
|
380
|
+
it %{cant_cache_method_clear_without_generational_caching} do
|
380
381
|
CacheMethod.config.generational = false
|
381
382
|
|
382
383
|
a = new_instance_of_my_blog
|
383
|
-
|
384
|
-
|
384
|
+
a.get_latest_entries.must_equal ["hello from #{a.name}"]
|
385
|
+
a.request_count.must_equal 1
|
385
386
|
|
386
387
|
assert_raises(::RuntimeError) do
|
387
388
|
a.cache_method_clear :get_latest_entries
|
388
389
|
end
|
389
390
|
|
390
|
-
|
391
|
-
|
391
|
+
a.get_latest_entries.must_equal ["hello from #{a.name}"]
|
392
|
+
a.request_count.must_equal 1
|
392
393
|
end
|
393
394
|
|
394
|
-
|
395
|
+
it %{doesnt_rely_on_to_s_for_args_digest} do
|
395
396
|
hello = DontStringifyMe.new("hello")
|
396
397
|
world = DontStringifyMe.new("world")
|
397
398
|
|
398
399
|
a = CopyCat1.new 'mimo'
|
399
400
|
|
400
401
|
a.echo(hello)
|
401
|
-
|
402
|
+
a.echo_count.must_equal 1
|
402
403
|
|
403
404
|
a.echo(hello)
|
404
|
-
|
405
|
+
a.echo_count.must_equal 1
|
405
406
|
|
406
407
|
a.echo(world)
|
407
|
-
|
408
|
+
a.echo_count.must_equal 2
|
408
409
|
|
409
410
|
a.echo(world)
|
410
|
-
|
411
|
+
a.echo_count.must_equal 2
|
411
412
|
end
|
412
413
|
|
413
|
-
|
414
|
+
it %{doesnt_marshal_if_as_cache_key_defined} do
|
414
415
|
hello = DontMarshalMe.new("hello")
|
415
416
|
world = DontMarshalMe.new("world")
|
416
417
|
|
@@ -436,47 +437,46 @@ class TestCacheMethod < Test::Unit::TestCase
|
|
436
437
|
ack_count += 1
|
437
438
|
5.times do
|
438
439
|
a.ack(nasty)
|
439
|
-
|
440
|
-
|
440
|
+
a.ack_count.must_equal ack_count
|
441
441
|
a.ack(nasty)
|
442
|
-
|
442
|
+
a.ack_count.must_equal ack_count
|
443
443
|
end
|
444
444
|
end
|
445
445
|
end
|
446
446
|
|
447
|
-
|
447
|
+
it %{cached_query} do
|
448
448
|
a = CopyCat1.new 'mimo'
|
449
|
-
|
450
|
-
|
449
|
+
a.cache_method_cached?(:echo, 'hi').must_equal false
|
450
|
+
a.cache_method_cached?(:echo, 'there').must_equal false
|
451
451
|
a.echo('hi')
|
452
|
-
|
453
|
-
|
452
|
+
a.cache_method_cached?(:echo, 'hi').must_equal true
|
453
|
+
a.cache_method_cached?(:echo, 'there').must_equal false
|
454
454
|
|
455
|
-
|
456
|
-
|
455
|
+
BlogM.cache_method_cached?(:get_latest_entries).must_equal false
|
456
|
+
BlogM.cache_method_cached?(:get_latest_entries, 'there').must_equal false
|
457
457
|
BlogM.get_latest_entries
|
458
|
-
|
459
|
-
|
458
|
+
BlogM.cache_method_cached?(:get_latest_entries).must_equal true
|
459
|
+
BlogM.cache_method_cached?(:get_latest_entries, 'there').must_equal false
|
460
460
|
end
|
461
461
|
|
462
|
-
|
462
|
+
it %{class_name_automatically_appended_to_cache_key} do
|
463
463
|
jek = DrJekyll.new
|
464
464
|
hyde = MrHyde.new
|
465
465
|
|
466
|
-
|
466
|
+
hyde.as_cache_key.must_equal jek.as_cache_key
|
467
467
|
|
468
468
|
a = CopyCat1.new 'mimo'
|
469
469
|
|
470
470
|
a.ack(jek)
|
471
|
-
|
471
|
+
a.ack_count.must_equal 1
|
472
472
|
|
473
473
|
a.ack(hyde)
|
474
|
-
|
474
|
+
a.ack_count.must_equal 2
|
475
475
|
|
476
476
|
a.ack(jek)
|
477
|
-
|
477
|
+
a.ack_count.must_equal 2
|
478
478
|
|
479
479
|
a.ack(hyde)
|
480
|
-
|
480
|
+
a.ack_count.must_equal 2
|
481
481
|
end
|
482
482
|
end
|