couch_scheduler 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/features/couch_publish_integration.feature +136 -27
- data/features/couch_visible_and_couch_publish_integration.feature +142 -38
- data/features/couch_visible_integration.feature +135 -27
- data/features/scheduling.feature +337 -37
- data/features/step_definitions/couch_publish_integration.rb +4 -71
- data/features/step_definitions/scheduling.rb +12 -96
- data/features/support/env.rb +6 -0
- data/lib/couch_scheduler.rb +2 -2
- data/lib/couch_scheduler/conditions.rb +23 -0
- data/lib/couch_scheduler/couch_publish_and_couch_visible_integration.rb +3 -18
- data/lib/couch_scheduler/couch_publish_integration.rb +4 -16
- data/lib/couch_scheduler/couch_scheduler.rb +24 -18
- data/lib/couch_scheduler/couch_visible_integration.rb +3 -16
- data/lib/couch_scheduler/map.rb +28 -42
- data/readme.markdown +24 -22
- metadata +21 -5
- data/lib/couch_scheduler/options.rb +0 -33
data/features/scheduling.feature
CHANGED
@@ -3,53 +3,353 @@ Feature: Scheduling
|
|
3
3
|
I want the ability to schedule my documents
|
4
4
|
So that I can control when they are accessible
|
5
5
|
|
6
|
+
|
6
7
|
Scenario: Setting valid start and end dates
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
|
9
|
+
Given an instance of a model that includes CouchScheduler:
|
10
|
+
"""
|
11
|
+
class Article < CouchRest::Model::Base
|
12
|
+
include CouchScheduler
|
13
|
+
end
|
14
|
+
|
15
|
+
@article = Article.new
|
16
|
+
"""
|
17
|
+
|
18
|
+
When I set "start" to now:
|
19
|
+
"""
|
20
|
+
@article.start = Time.now
|
21
|
+
"""
|
22
|
+
|
23
|
+
And I set "end" to a day from now:
|
24
|
+
"""
|
25
|
+
@article.end = 1.day.from_now
|
26
|
+
"""
|
27
|
+
|
28
|
+
Then I should be able to save my document:
|
29
|
+
"""
|
30
|
+
@article.save
|
31
|
+
@article.errors.should be_empty
|
32
|
+
Article.all.count.should == 1
|
33
|
+
"""
|
34
|
+
|
11
35
|
|
12
36
|
Scenario: Setting invalid start and end dates
|
13
|
-
Given an instance of a model that includes CouchScheduler
|
14
|
-
When I set "start" to now
|
15
|
-
And I set "end" to yesterday
|
16
|
-
Then I should not be able to save my document
|
17
|
-
And I should get an error message that the end "must be greater than start"
|
18
37
|
|
38
|
+
Given an instance of a model that includes CouchScheduler:
|
39
|
+
"""
|
40
|
+
class Article < CouchRest::Model::Base
|
41
|
+
include CouchScheduler
|
42
|
+
end
|
43
|
+
|
44
|
+
@article = Article.new
|
45
|
+
"""
|
46
|
+
|
47
|
+
When I set "start" to now:
|
48
|
+
"""
|
49
|
+
@article.start = Time.now
|
50
|
+
"""
|
51
|
+
|
52
|
+
And I set "end" to yesterday:
|
53
|
+
"""
|
54
|
+
@article.end = 1.day.ago
|
55
|
+
"""
|
56
|
+
|
57
|
+
Then I should not be able to save my document:
|
58
|
+
"""
|
59
|
+
@article.save
|
60
|
+
@article.errors.should_not be_empty
|
61
|
+
Article.all.count.should == 0
|
62
|
+
"""
|
63
|
+
|
64
|
+
|
19
65
|
Scenario: Determining if a document is within it's schedule
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
66
|
+
|
67
|
+
Given an instance of a model that includes CouchScheduler:
|
68
|
+
"""
|
69
|
+
class Article < CouchRest::Model::Base
|
70
|
+
include CouchScheduler
|
71
|
+
end
|
72
|
+
|
73
|
+
@article = Article.new
|
74
|
+
"""
|
75
|
+
|
76
|
+
When I set "start" to now:
|
77
|
+
"""
|
78
|
+
@article.start = Time.now
|
79
|
+
"""
|
80
|
+
|
81
|
+
And I set "end" to tomorrow:
|
82
|
+
"""
|
83
|
+
@article.end = 1.day.from_now
|
84
|
+
"""
|
85
|
+
|
86
|
+
Then "within_schedule?" should return true on my instance:
|
87
|
+
"""
|
88
|
+
@article.within_schedule?.should be(true)
|
89
|
+
"""
|
90
|
+
|
91
|
+
When I wait two days:
|
92
|
+
"""
|
93
|
+
Timecop.freeze 2.days.from_now
|
94
|
+
"""
|
95
|
+
|
96
|
+
Then "within_schedule?" should return false on my instance:
|
97
|
+
"""
|
98
|
+
@article.within_schedule?
|
99
|
+
"""
|
100
|
+
|
26
101
|
|
27
102
|
Scenario: Determining if a document is within it's schedule for a document that has only a start date
|
28
|
-
Given an instance of a model that includes CouchScheduler
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
103
|
+
Given an instance of a model that includes CouchScheduler:
|
104
|
+
"""
|
105
|
+
class Article < CouchRest::Model::Base
|
106
|
+
include CouchScheduler
|
107
|
+
end
|
108
|
+
|
109
|
+
@article = Article.new
|
110
|
+
"""
|
111
|
+
|
112
|
+
When I set "start" to now:
|
113
|
+
"""
|
114
|
+
@article.start = Time.now
|
115
|
+
"""
|
116
|
+
|
117
|
+
Then "within_schedule?" should return true on my instance:
|
118
|
+
"""
|
119
|
+
@article.within_schedule?.should be(true)
|
120
|
+
"""
|
121
|
+
|
122
|
+
When I wait two days:
|
123
|
+
"""
|
124
|
+
Timecop.freeze 2.days.from_now
|
125
|
+
"""
|
33
126
|
|
127
|
+
Then "within_schedule?" should return true on my instance:
|
128
|
+
"""
|
129
|
+
@article.within_schedule?.should be(true)
|
130
|
+
"""
|
131
|
+
|
132
|
+
|
133
|
+
@focus
|
34
134
|
Scenario: Determining if a document is within it's schedule for a document that has only an end date
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
135
|
+
|
136
|
+
Given an instance of a model that includes CouchScheduler:
|
137
|
+
"""
|
138
|
+
class Article < CouchRest::Model::Base
|
139
|
+
include CouchScheduler
|
140
|
+
end
|
141
|
+
|
142
|
+
@article = Article.new
|
143
|
+
"""
|
144
|
+
|
145
|
+
When I set "end" to tomorrow:
|
146
|
+
"""
|
147
|
+
@article.end = 1.day.from_now
|
148
|
+
"""
|
149
|
+
|
150
|
+
Then "within_schedule?" should return true on my instance:
|
151
|
+
"""
|
152
|
+
@article.within_schedule?.should be(true)
|
153
|
+
"""
|
154
|
+
|
155
|
+
When I wait two days:
|
156
|
+
"""
|
157
|
+
Timecop.freeze 2.days.from_now
|
158
|
+
"""
|
159
|
+
|
160
|
+
Then "within_schedule?" should return false on my instance:
|
161
|
+
"""
|
162
|
+
@article.within_schedule?.should be(false)
|
163
|
+
"""
|
40
164
|
|
165
|
+
|
166
|
+
@focus
|
41
167
|
Scenario: Getting all documents that are within schedule on a given date
|
42
|
-
Given there are several documents currently scheduled
|
43
|
-
And there are several documents scheduled in the future
|
44
|
-
Then "by_schedule" should return the documents currently within schedule
|
45
|
-
And "by_schedule" should not return the documents scheduled in the future
|
46
168
|
|
169
|
+
Given an instance of a model that includes CouchScheduler:
|
170
|
+
"""
|
171
|
+
class Article < CouchRest::Model::Base
|
172
|
+
include CouchScheduler
|
173
|
+
end
|
174
|
+
|
175
|
+
@article = Article.new
|
176
|
+
"""
|
177
|
+
|
178
|
+
And there are several documents currently scheduled:
|
179
|
+
"""
|
180
|
+
@current_articles = [].tap {|a| 10.times { a << Article.create(:start => Time.now, :end => 1.day.from_now) }}
|
181
|
+
@current_articles.length.should == 10
|
182
|
+
"""
|
183
|
+
|
184
|
+
And there are several documents scheduled in the future:
|
185
|
+
"""
|
186
|
+
@future_articles = [].tap {|a| 10.times { a << Article.create(:start => 2.days.from_now, :end => 3.days.from_now) }}
|
187
|
+
@future_articles.length.should == 10
|
188
|
+
Article.all.count.should == 20
|
189
|
+
"""
|
190
|
+
|
191
|
+
Then "map_within_schedule!" should return the documents currently within schedule:
|
192
|
+
"""
|
193
|
+
Article.map_within_schedule!.all? {|a| @current_articles.collect(&:id).include? a.id }
|
194
|
+
"""
|
195
|
+
|
196
|
+
And "map_within_schedule!" should not return the documents scheduled in the future:
|
197
|
+
"""
|
198
|
+
Article.map_within_schedule!.all? {|a| !@future_articles.collect(&:id).include? a.id }
|
199
|
+
"""
|
200
|
+
|
201
|
+
Then "map_within_schedule.key(2.days.from_now.to_date).get!" should return the documents scheduled in the future:
|
202
|
+
"""
|
203
|
+
Article.map_within_schedule.key(2.days.from_now.to_date).get!.all? {|a| @future_articles.collect(&:id).include? a.id }
|
204
|
+
"""
|
205
|
+
|
206
|
+
And "map_within_schedule.key(2.days.from_now.to_date).get!" should not return the documents currently scheduled:
|
207
|
+
"""
|
208
|
+
Article.map_within_schedule.key(2.days.from_now.to_date).get!.all? {|a| !@current_articles.collect(&:id).include? a.id }
|
209
|
+
"""
|
210
|
+
|
211
|
+
|
212
|
+
@focus
|
47
213
|
Scenario: Counting documents
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
214
|
+
|
215
|
+
Given a model that includes CouchScheduler:
|
216
|
+
"""
|
217
|
+
class Article < CouchRest::Model::Base
|
218
|
+
include CouchScheduler
|
219
|
+
end
|
220
|
+
"""
|
221
|
+
|
222
|
+
And there are 3 documents scheduled between now and tomorrow:
|
223
|
+
"""
|
224
|
+
3.times { Article.create :start => Time.now, :end => 1.day.from_now}
|
225
|
+
"""
|
226
|
+
|
227
|
+
And there are 10 documents scheduled between tomorrow and two days from now:
|
228
|
+
"""
|
229
|
+
10.times { Article.create :start => 1.day.from_now, :end => 2.days.from_now }
|
230
|
+
"""
|
231
|
+
|
232
|
+
Then "count_within_schedule!" should return 3:
|
233
|
+
"""
|
234
|
+
Article.count_within_schedule!.should == 3
|
235
|
+
"""
|
236
|
+
|
237
|
+
And "count_within_schedule.key(1.day.from_now.to_date).get!" should return 10:
|
238
|
+
"""
|
239
|
+
Article.count_within_schedule.key(1.day.from_now.to_date).get!.should == 10
|
240
|
+
"""
|
241
|
+
|
242
|
+
When I wait a day:
|
243
|
+
"""
|
244
|
+
Timecop.freeze 1.day.from_now
|
245
|
+
"""
|
246
|
+
|
247
|
+
Then "count_within_schedule!" should return 10:
|
248
|
+
"""
|
249
|
+
Article.count_within_schedule!.should == 10
|
250
|
+
"""
|
251
|
+
|
252
|
+
When I wait another day:
|
253
|
+
"""
|
254
|
+
Timecop.freeze 1.day.from_now
|
255
|
+
"""
|
256
|
+
|
257
|
+
Then "count_within_schedule!" should return 0:
|
258
|
+
"""
|
259
|
+
Article.count_within_schedule!.should == 0
|
260
|
+
"""
|
261
|
+
|
262
|
+
@focus
|
263
|
+
Scenario: Generating the correct date key index for scheduled documents
|
264
|
+
|
265
|
+
Given a model that includes CouchScheduler:
|
266
|
+
"""
|
267
|
+
class Article < CouchRest::Model::Base
|
268
|
+
include CouchScheduler
|
269
|
+
end
|
270
|
+
"""
|
271
|
+
|
272
|
+
And the date is January 1st, 2011:
|
273
|
+
"""
|
274
|
+
Timecop.freeze Time.parse("2011/01/01")
|
275
|
+
"""
|
276
|
+
|
277
|
+
And there are 3 documents scheduled between now and one month and a day from now:
|
278
|
+
"""
|
279
|
+
3.times { Article.create :start => Time.now, :end => (1.month.from_now + 1.day)}
|
280
|
+
"""
|
281
|
+
|
282
|
+
And there are 10 documents scheduled between one month and a day from now and two months from now:
|
283
|
+
"""
|
284
|
+
10.times { Article.create :start => (1.month.from_now + 1.day), :end => 2.months.from_now }
|
285
|
+
"""
|
286
|
+
|
287
|
+
Then "count_within_schedule!" should return 3:
|
288
|
+
"""
|
289
|
+
Article.count_within_schedule!.should == 3
|
290
|
+
"""
|
291
|
+
|
292
|
+
And "count_within_schedule.key('2011-01-01').get!" should return 3:
|
293
|
+
"""
|
294
|
+
Article.count_within_schedule.key('2011-01-01').get!.should == 3
|
295
|
+
"""
|
296
|
+
|
297
|
+
And "count_within_schedule.key('2011-02-02).get!" should return 10:
|
298
|
+
"""
|
299
|
+
Article.count_within_schedule.key('2011-02-02').get!.should == 10
|
300
|
+
"""
|
301
|
+
|
302
|
+
When I wait a month and a day:
|
303
|
+
"""
|
304
|
+
Timecop.freeze(1.month.from_now + 1.day)
|
305
|
+
"""
|
306
|
+
|
307
|
+
Then "count_within_schedule!" should return 10:
|
308
|
+
"""
|
309
|
+
Article.count_within_schedule!.should == 10
|
310
|
+
"""
|
311
|
+
|
312
|
+
@focus
|
313
|
+
Scenario: Default start within the "schedule" index to the current date
|
314
|
+
|
315
|
+
Given a model that includes CouchScheduler:
|
316
|
+
"""
|
317
|
+
class Article < CouchRest::Model::Base
|
318
|
+
include CouchScheduler
|
319
|
+
end
|
320
|
+
"""
|
321
|
+
|
322
|
+
And there are 3 documents scheduled to end one month and a day from now:
|
323
|
+
"""
|
324
|
+
3.times { Article.create :end => (1.month.from_now + 1.day)}
|
325
|
+
"""
|
326
|
+
|
327
|
+
And there are 10 documents scheduled to start one month and a day from now:
|
328
|
+
"""
|
329
|
+
10.times { Article.create :start => (1.month.from_now + 1.day)}
|
330
|
+
"""
|
331
|
+
|
332
|
+
Then "count_within_schedule!" should return 3:
|
333
|
+
"""
|
334
|
+
Article.count_within_schedule!.should == 3
|
335
|
+
"""
|
336
|
+
|
337
|
+
And "count_within_schedule.key(Time.now.to_date).get!" should return 3:
|
338
|
+
"""
|
339
|
+
Article.count_within_schedule.key(Time.now.to_date).get!.should == 3
|
340
|
+
"""
|
341
|
+
|
342
|
+
And "count_within_schedule.key((1.month.from_now + 1.day).to_date).get!" should return 10:
|
343
|
+
"""
|
344
|
+
Article.count_within_schedule.key((1.month.from_now + 1.day).to_date).get!.should == 10
|
345
|
+
"""
|
346
|
+
|
347
|
+
When I wait a month and a day:
|
348
|
+
"""
|
349
|
+
Timecop.freeze(1.month.from_now + 1.day)
|
350
|
+
"""
|
351
|
+
|
352
|
+
Then "count_within_schedule!" should return 10:
|
353
|
+
"""
|
354
|
+
Article.count_within_schedule!.should == 10
|
355
|
+
"""
|
@@ -1,74 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class Article < CouchRest::Model::Base
|
4
|
-
include CouchPublish
|
5
|
-
include CouchScheduler
|
6
|
-
end
|
7
|
-
end
|
1
|
+
When /^I create.*:$/ do |code|
|
2
|
+
eval code
|
8
3
|
end
|
9
4
|
|
10
|
-
When /^I
|
11
|
-
|
12
|
-
@published_future = []
|
13
|
-
|
14
|
-
5.times { @published_now << Article.create(:start => Time.now, :end => 1.day.from_now).tap {|a| a.publish! } }
|
15
|
-
5.times { @published_future << Article.create(:start => 1.day.from_now, :end => 2.days.from_now).tap {|a| a.publish! } }
|
16
|
-
end
|
17
|
-
|
18
|
-
When /^I create several unpublished articles scheduled now and in the future$/ do
|
19
|
-
@unpublished_now = []
|
20
|
-
@unpublished_future = []
|
21
|
-
|
22
|
-
5.times { @unpublished_now << Article.create(:start => Time.now, :end => 1.day.from_now) }
|
23
|
-
5.times { @unpublished_future << Article.create(:start => 1.day.from_now, :end => 2.days.from_now) }
|
24
|
-
end
|
25
|
-
|
26
|
-
When /^I call "([^"]*)"$/ do |code|
|
27
|
-
@result = eval code
|
28
|
-
end
|
29
|
-
|
30
|
-
Then /^I should receive the published documents scheduled now$/ do
|
31
|
-
@result.collect(&:id).sort.should == @published_now.collect(&:id).sort
|
32
|
-
end
|
33
|
-
|
34
|
-
Then /^I should receive the unpublished documents scheduled now$/ do
|
35
|
-
@result.collect(&:id).sort.should == @unpublished_now.collect(&:id).sort
|
36
|
-
end
|
37
|
-
|
38
|
-
When /^I wait till the future$/ do
|
39
|
-
Timecop.freeze 1.day.from_now
|
40
|
-
end
|
41
|
-
|
42
|
-
Then /^I should receive the published documents scheduled in the future$/ do
|
43
|
-
@result.collect(&:id).sort.should == @published_future.collect(&:id).sort
|
5
|
+
When /^I call ".*":$/ do |code|
|
6
|
+
eval code
|
44
7
|
end
|
45
|
-
|
46
|
-
Then /^I should receive the unpublished documents scheduled in the future$/ do
|
47
|
-
@result.collect(&:id).sort.should == @unpublished_future.collect(&:id).sort
|
48
|
-
end
|
49
|
-
|
50
|
-
When /^I create (\d+) published articles scheduled now$/ do |num|
|
51
|
-
@published_now = []
|
52
|
-
num.to_i.times { @published_now << Article.create(:start => Time.now, :end => 1.day.from_now).tap {|a| a.publish!}}
|
53
|
-
end
|
54
|
-
|
55
|
-
When /^I create (\d+) published articles schedule in the future$/ do |num|
|
56
|
-
@published_future = []
|
57
|
-
num.to_i.times { @published_future << Article.create(:start => 1.day.from_now, :end => 2.days.from_now).tap {|a| a.publish!}}
|
58
|
-
end
|
59
|
-
|
60
|
-
When /^I create (\d+) unpublished articles scheduled now$/ do |num|
|
61
|
-
@unpublished_now = []
|
62
|
-
num.to_i.times { @unpublished_now << Article.create(:start => Time.now, :end => 1.day.from_now)}
|
63
|
-
end
|
64
|
-
|
65
|
-
When /^I create (\d+) unpublished articles schedule in the future$/ do |num|
|
66
|
-
@unpublished_future = []
|
67
|
-
num.to_i.times { @unpublished_future << Article.create(:start => 1.day.from_now, :end => 2.days.from_now)}
|
68
|
-
end
|
69
|
-
|
70
|
-
Then /^I should receive (\d+)$/ do |count|
|
71
|
-
@result.should == count.to_i
|
72
|
-
end
|
73
|
-
|
74
|
-
|