chronological 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
@@ -58,15 +58,15 @@ module Chronological
|
|
58
58
|
in_progress.any?
|
59
59
|
end
|
60
60
|
|
61
|
+
###
|
62
|
+
# Aliases
|
63
|
+
#
|
64
|
+
# Aliasing date methods to make code more readable
|
61
65
|
instance_eval do
|
62
66
|
alias active? in_progress?
|
63
67
|
alias active in_progress
|
64
68
|
end
|
65
69
|
|
66
|
-
###
|
67
|
-
# Aliases
|
68
|
-
#
|
69
|
-
# Aliasing date methods to make code more readable
|
70
70
|
class_eval do
|
71
71
|
alias_attribute :"starts_at#{start_time_field_utc_suffix}", start_time_field.to_sym
|
72
72
|
alias_attribute :"starting_at#{start_time_field_utc_suffix}", start_time_field.to_sym
|
@@ -31,6 +31,26 @@ module Chronological
|
|
31
31
|
send(base_time_field).present? || send(options[:start]).present? || send(options[:end]).present?
|
32
32
|
end
|
33
33
|
|
34
|
+
###
|
35
|
+
# Scopes
|
36
|
+
#
|
37
|
+
self.class.send(:define_method, :in_progress) do
|
38
|
+
all.select(&:in_progress?)
|
39
|
+
end
|
40
|
+
|
41
|
+
self.class.send(:define_method, :in_progress?) do
|
42
|
+
all.any?(&:in_progress?)
|
43
|
+
end
|
44
|
+
|
45
|
+
###
|
46
|
+
# Aliases
|
47
|
+
#
|
48
|
+
# Aliasing date methods to make code more readable
|
49
|
+
instance_eval do
|
50
|
+
alias active? in_progress?
|
51
|
+
alias active in_progress
|
52
|
+
end
|
53
|
+
|
34
54
|
base_timeframe start_date_field: start_date_field,
|
35
55
|
start_time_field: start_time_field,
|
36
56
|
end_date_field: end_date_field,
|
@@ -3,43 +3,28 @@ require 'spec_helper'
|
|
3
3
|
class AbsoluteChronologicable < ActiveRecord::Base
|
4
4
|
include Chronological::AbsoluteTimeframe
|
5
5
|
|
6
|
-
absolute_timeframe
|
7
|
-
|
6
|
+
absolute_timeframe start_utc: :started_at_utc,
|
7
|
+
end_utc: :ended_at_utc
|
8
8
|
end
|
9
9
|
|
10
10
|
class ChronologicableWithTimeZone < ActiveRecord::Base
|
11
11
|
include Chronological::AbsoluteTimeframe
|
12
12
|
|
13
|
-
absolute_timeframe
|
14
|
-
|
15
|
-
|
13
|
+
absolute_timeframe start_utc: :started_at_utc,
|
14
|
+
end_utc: :ended_at_utc,
|
15
|
+
time_zone: :time_zone
|
16
16
|
end
|
17
17
|
|
18
18
|
describe Chronological::AbsoluteTimeframe, :timecop => true do
|
19
|
-
let(:later)
|
20
|
-
let(:now)
|
21
|
-
let(:past)
|
19
|
+
let(:later) { Time.local(2012, 7, 26, 6, 0, 26) }
|
20
|
+
let(:now) { Time.local(2012, 7, 26, 6, 0, 25) }
|
21
|
+
let(:past) { Time.local(2012, 7, 26, 6, 0, 24) }
|
22
22
|
|
23
|
-
|
23
|
+
let(:start_time) { nil }
|
24
|
+
let(:end_time) { nil }
|
25
|
+
let(:time_zone) { nil }
|
24
26
|
|
25
|
-
|
26
|
-
AbsoluteChronologicable.create(
|
27
|
-
:started_at_utc => start_time,
|
28
|
-
:ended_at_utc => end_time)
|
29
|
-
end
|
30
|
-
|
31
|
-
let(:chronologicable_without_enabled_time_zone) do
|
32
|
-
AbsoluteChronologicable.new(
|
33
|
-
:started_at_utc => start_time,
|
34
|
-
:ended_at_utc => end_time)
|
35
|
-
end
|
36
|
-
|
37
|
-
let(:chronologicable_with_enabled_time_zone) do
|
38
|
-
ChronologicableWithTimeZone.new(
|
39
|
-
:started_at_utc => start_time,
|
40
|
-
:ended_at_utc => end_time,
|
41
|
-
:time_zone => time_zone)
|
42
|
-
end
|
27
|
+
before { Timecop.freeze(now) }
|
43
28
|
|
44
29
|
it { AbsoluteChronologicable.new.respond_to?(:starts_at_utc).should be_true }
|
45
30
|
it { AbsoluteChronologicable.new.respond_to?(:starting_at_utc).should be_true }
|
@@ -130,95 +115,169 @@ describe Chronological::AbsoluteTimeframe, :timecop => true do
|
|
130
115
|
end
|
131
116
|
end
|
132
117
|
|
133
|
-
context 'when
|
134
|
-
let(:
|
118
|
+
context 'when dealing with one chronologicable' do
|
119
|
+
let!(:chronologicable) do
|
120
|
+
AbsoluteChronologicable.create(
|
121
|
+
started_at_utc: start_time,
|
122
|
+
ended_at_utc: end_time)
|
123
|
+
end
|
135
124
|
|
136
|
-
|
137
|
-
|
125
|
+
let!(:chronologicable_without_enabled_time_zone) do
|
126
|
+
AbsoluteChronologicable.new(
|
127
|
+
started_at_utc: start_time,
|
128
|
+
ended_at_utc: end_time)
|
129
|
+
end
|
138
130
|
|
139
|
-
|
140
|
-
|
131
|
+
let!(:chronologicable_with_enabled_time_zone) do
|
132
|
+
ChronologicableWithTimeZone.new(
|
133
|
+
started_at_utc: start_time,
|
134
|
+
ended_at_utc: end_time,
|
135
|
+
time_zone: time_zone)
|
136
|
+
end
|
141
137
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
138
|
+
context 'when a start time is set' do
|
139
|
+
let(:start_time) { Time.now }
|
140
|
+
|
141
|
+
context 'but no end time is set' do
|
142
|
+
let(:end_time) { nil }
|
143
|
+
|
144
|
+
context 'and no time zone is set' do
|
145
|
+
let(:time_zone) { nil }
|
146
|
+
|
147
|
+
describe '#scheduled?' do
|
148
|
+
it 'is correct' do
|
149
|
+
chronologicable_without_enabled_time_zone.should_not be_scheduled
|
150
|
+
chronologicable_with_enabled_time_zone.should_not be_scheduled
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe '#partially_scheduled?' do
|
155
|
+
it 'is correct' do
|
156
|
+
chronologicable_without_enabled_time_zone.should be_partially_scheduled
|
157
|
+
chronologicable_with_enabled_time_zone.should be_partially_scheduled
|
158
|
+
end
|
146
159
|
end
|
147
160
|
end
|
148
161
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
162
|
+
context 'and a time zone is set' do
|
163
|
+
let(:time_zone) { ActiveSupport::TimeZone.new('Alaska') }
|
164
|
+
|
165
|
+
describe '#scheduled?' do
|
166
|
+
it 'is correct' do
|
167
|
+
chronologicable_without_enabled_time_zone.should_not be_scheduled
|
168
|
+
chronologicable_with_enabled_time_zone.should_not be_scheduled
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
describe '#partially_scheduled?' do
|
173
|
+
it 'is correct' do
|
174
|
+
chronologicable_without_enabled_time_zone.should be_partially_scheduled
|
175
|
+
chronologicable_with_enabled_time_zone.should be_partially_scheduled
|
176
|
+
end
|
153
177
|
end
|
154
178
|
end
|
155
179
|
end
|
156
180
|
|
157
|
-
context '
|
158
|
-
let(:
|
181
|
+
context 'an end time is set' do
|
182
|
+
let(:end_time) { Time.now }
|
159
183
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
184
|
+
context 'but no time zone is set' do
|
185
|
+
let(:time_zone) { nil }
|
186
|
+
|
187
|
+
describe '#scheduled?' do
|
188
|
+
it 'is correct' do
|
189
|
+
chronologicable_without_enabled_time_zone.should be_scheduled
|
190
|
+
chronologicable_with_enabled_time_zone.should_not be_scheduled
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
describe '#partially_scheduled?' do
|
195
|
+
it 'is correct' do
|
196
|
+
chronologicable_without_enabled_time_zone.should be_partially_scheduled
|
197
|
+
chronologicable_with_enabled_time_zone.should be_partially_scheduled
|
198
|
+
end
|
164
199
|
end
|
165
200
|
end
|
166
201
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
202
|
+
context 'and a time zone is set' do
|
203
|
+
let(:time_zone) { ActiveSupport::TimeZone.new('Alaska') }
|
204
|
+
|
205
|
+
describe '#scheduled?' do
|
206
|
+
it 'is correct' do
|
207
|
+
chronologicable_without_enabled_time_zone.should be_scheduled
|
208
|
+
chronologicable_with_enabled_time_zone.should be_scheduled
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe '#partially_scheduled?' do
|
213
|
+
it 'is correct' do
|
214
|
+
chronologicable_without_enabled_time_zone.should be_partially_scheduled
|
215
|
+
chronologicable_with_enabled_time_zone.should be_partially_scheduled
|
216
|
+
end
|
171
217
|
end
|
172
218
|
end
|
173
219
|
end
|
174
220
|
end
|
175
221
|
|
176
|
-
context 'an end time is set' do
|
222
|
+
context 'when an end time is set' do
|
177
223
|
let(:end_time) { Time.now }
|
178
224
|
|
179
|
-
context 'but no time
|
180
|
-
let(:
|
225
|
+
context 'but no start time is set' do
|
226
|
+
let(:start_time) { nil }
|
181
227
|
|
182
228
|
describe '#scheduled?' do
|
183
|
-
it 'is
|
184
|
-
|
185
|
-
chronologicable_with_enabled_time_zone.should_not be_scheduled
|
229
|
+
it 'is false' do
|
230
|
+
chronologicable.should_not be_scheduled
|
186
231
|
end
|
187
232
|
end
|
188
233
|
|
189
234
|
describe '#partially_scheduled?' do
|
190
|
-
it 'is
|
191
|
-
|
192
|
-
chronologicable_with_enabled_time_zone.should be_partially_scheduled
|
235
|
+
it 'is true' do
|
236
|
+
chronologicable.should be_partially_scheduled
|
193
237
|
end
|
194
238
|
end
|
195
|
-
end
|
196
239
|
|
197
|
-
|
198
|
-
|
240
|
+
context 'but no time zone is set' do
|
241
|
+
let(:time_zone) { nil }
|
199
242
|
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
243
|
+
describe '#scheduled?' do
|
244
|
+
it 'is correct' do
|
245
|
+
chronologicable_without_enabled_time_zone.should_not be_scheduled
|
246
|
+
chronologicable_with_enabled_time_zone.should_not be_scheduled
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
describe '#partially_scheduled?' do
|
251
|
+
it 'is correct' do
|
252
|
+
chronologicable_without_enabled_time_zone.should be_partially_scheduled
|
253
|
+
chronologicable_with_enabled_time_zone.should be_partially_scheduled
|
254
|
+
end
|
204
255
|
end
|
205
256
|
end
|
206
257
|
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
258
|
+
context 'and a time zone is set' do
|
259
|
+
let(:time_zone) { ActiveSupport::TimeZone.new('Alaska') }
|
260
|
+
|
261
|
+
describe '#scheduled?' do
|
262
|
+
it 'is correct' do
|
263
|
+
chronologicable_without_enabled_time_zone.should_not be_scheduled
|
264
|
+
chronologicable_with_enabled_time_zone.should_not be_scheduled
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
describe '#partially_scheduled?' do
|
269
|
+
it 'is correct' do
|
270
|
+
chronologicable_without_enabled_time_zone.should be_partially_scheduled
|
271
|
+
chronologicable_with_enabled_time_zone.should be_partially_scheduled
|
272
|
+
end
|
211
273
|
end
|
212
274
|
end
|
213
275
|
end
|
214
276
|
end
|
215
|
-
end
|
216
277
|
|
217
|
-
|
218
|
-
let(:end_time) { Time.now }
|
219
|
-
|
220
|
-
context 'but no start time is set' do
|
278
|
+
context 'when neither a start time nor an end time is set' do
|
221
279
|
let(:start_time) { nil }
|
280
|
+
let(:end_time) { nil }
|
222
281
|
|
223
282
|
describe '#scheduled?' do
|
224
283
|
it 'is false' do
|
@@ -227,220 +286,197 @@ describe Chronological::AbsoluteTimeframe, :timecop => true do
|
|
227
286
|
end
|
228
287
|
|
229
288
|
describe '#partially_scheduled?' do
|
230
|
-
it 'is
|
231
|
-
chronologicable.
|
289
|
+
it 'is false' do
|
290
|
+
chronologicable.should_not be_partially_scheduled
|
232
291
|
end
|
233
292
|
end
|
293
|
+
end
|
234
294
|
|
235
|
-
|
236
|
-
|
295
|
+
context 'when there is a chronologicable that has already started' do
|
296
|
+
let(:start_time) { past }
|
237
297
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
298
|
+
context 'and has already ended' do
|
299
|
+
let(:end_time) { past }
|
300
|
+
|
301
|
+
describe '.in_progress?' do
|
302
|
+
it 'is false' do
|
303
|
+
AbsoluteChronologicable.should_not be_in_progress
|
242
304
|
end
|
243
305
|
end
|
244
306
|
|
245
|
-
describe '
|
246
|
-
it '
|
247
|
-
|
248
|
-
chronologicable_with_enabled_time_zone.should be_partially_scheduled
|
307
|
+
describe '.expired' do
|
308
|
+
it 'includes that chronologicable' do
|
309
|
+
AbsoluteChronologicable.expired.should include chronologicable
|
249
310
|
end
|
250
311
|
end
|
251
|
-
end
|
252
312
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
describe '#scheduled?' do
|
257
|
-
it 'is correct' do
|
258
|
-
chronologicable_without_enabled_time_zone.should_not be_scheduled
|
259
|
-
chronologicable_with_enabled_time_zone.should_not be_scheduled
|
313
|
+
describe '.started' do
|
314
|
+
it 'includes that chronologicable' do
|
315
|
+
AbsoluteChronologicable.started.should include chronologicable
|
260
316
|
end
|
261
317
|
end
|
262
318
|
|
263
|
-
describe '
|
264
|
-
it '
|
265
|
-
|
266
|
-
chronologicable_with_enabled_time_zone.should be_partially_scheduled
|
319
|
+
describe '.current' do
|
320
|
+
it 'does not include that chronologicable' do
|
321
|
+
AbsoluteChronologicable.current.should_not include chronologicable
|
267
322
|
end
|
268
323
|
end
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
324
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
it 'is false' do
|
279
|
-
chronologicable.should_not be_scheduled
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
describe '#partially_scheduled?' do
|
284
|
-
it 'is false' do
|
285
|
-
chronologicable.should_not be_partially_scheduled
|
325
|
+
describe '.in_progress' do
|
326
|
+
it 'does not include that chronologicable' do
|
327
|
+
AbsoluteChronologicable.in_progress.should_not include chronologicable
|
328
|
+
end
|
329
|
+
end
|
286
330
|
end
|
287
|
-
end
|
288
|
-
end
|
289
331
|
|
290
|
-
|
291
|
-
|
332
|
+
context 'and ends now' do
|
333
|
+
let(:end_time) { now }
|
292
334
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
it 'is false' do
|
298
|
-
chronologicable
|
299
|
-
AbsoluteChronologicable.should_not be_in_progress
|
335
|
+
describe '.in_progress?' do
|
336
|
+
it 'is false' do
|
337
|
+
AbsoluteChronologicable.should_not be_in_progress
|
338
|
+
end
|
300
339
|
end
|
301
|
-
end
|
302
340
|
|
303
|
-
|
304
|
-
|
305
|
-
|
341
|
+
describe '.expired' do
|
342
|
+
it 'does include that chronologicable' do
|
343
|
+
AbsoluteChronologicable.expired.should include chronologicable
|
344
|
+
end
|
306
345
|
end
|
307
|
-
end
|
308
346
|
|
309
|
-
|
310
|
-
|
311
|
-
|
347
|
+
describe '.started' do
|
348
|
+
it 'includes that chronologicable' do
|
349
|
+
AbsoluteChronologicable.started.should include chronologicable
|
350
|
+
end
|
312
351
|
end
|
313
|
-
end
|
314
352
|
|
315
|
-
|
316
|
-
|
317
|
-
|
353
|
+
describe '.current' do
|
354
|
+
it 'does not include that chronologicable' do
|
355
|
+
AbsoluteChronologicable.current.should_not include chronologicable
|
356
|
+
end
|
318
357
|
end
|
319
|
-
end
|
320
358
|
|
321
|
-
|
322
|
-
|
323
|
-
|
359
|
+
describe '.in_progress' do
|
360
|
+
it 'does not include that chronologicable' do
|
361
|
+
AbsoluteChronologicable.in_progress.should_not include chronologicable
|
362
|
+
end
|
324
363
|
end
|
325
364
|
end
|
326
|
-
end
|
327
365
|
|
328
|
-
|
329
|
-
|
366
|
+
context 'and ends later' do
|
367
|
+
let(:end_time) { later }
|
330
368
|
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
369
|
+
describe '.in_progress?' do
|
370
|
+
it 'is true' do
|
371
|
+
AbsoluteChronologicable.should be_in_progress
|
372
|
+
end
|
335
373
|
end
|
336
|
-
end
|
337
374
|
|
338
|
-
|
339
|
-
|
340
|
-
|
375
|
+
describe '.expired' do
|
376
|
+
it 'does not include that chronologicable' do
|
377
|
+
AbsoluteChronologicable.expired.should_not include chronologicable
|
378
|
+
end
|
341
379
|
end
|
342
|
-
end
|
343
380
|
|
344
|
-
|
345
|
-
|
346
|
-
|
381
|
+
describe '.started' do
|
382
|
+
it 'includes that chronologicable' do
|
383
|
+
AbsoluteChronologicable.started.should include chronologicable
|
384
|
+
end
|
347
385
|
end
|
348
|
-
end
|
349
386
|
|
350
|
-
|
351
|
-
|
352
|
-
|
387
|
+
describe '.current' do
|
388
|
+
it 'includes that chronologicable' do
|
389
|
+
AbsoluteChronologicable.current.should include chronologicable
|
390
|
+
end
|
353
391
|
end
|
354
|
-
end
|
355
392
|
|
356
|
-
|
357
|
-
|
358
|
-
|
393
|
+
describe '.in_progress' do
|
394
|
+
it 'includes that chronologicable' do
|
395
|
+
AbsoluteChronologicable.in_progress.should include chronologicable
|
396
|
+
end
|
359
397
|
end
|
360
398
|
end
|
361
399
|
end
|
362
400
|
|
363
|
-
context '
|
364
|
-
let(:
|
401
|
+
context 'when there is a chronologicable that starts now' do
|
402
|
+
let(:start_time) { now }
|
365
403
|
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
404
|
+
context 'and ends now' do
|
405
|
+
let(:end_time) { now }
|
406
|
+
|
407
|
+
describe '.in_progress?' do
|
408
|
+
it 'is false' do
|
409
|
+
AbsoluteChronologicable.should_not be_in_progress
|
410
|
+
end
|
370
411
|
end
|
371
|
-
end
|
372
412
|
|
373
|
-
|
374
|
-
|
375
|
-
|
413
|
+
describe '.expired' do
|
414
|
+
it 'does include that chronologicable' do
|
415
|
+
AbsoluteChronologicable.expired.should include chronologicable
|
416
|
+
end
|
376
417
|
end
|
377
|
-
end
|
378
418
|
|
379
|
-
|
380
|
-
|
381
|
-
|
419
|
+
describe '.started' do
|
420
|
+
it 'includes that chronologicable' do
|
421
|
+
AbsoluteChronologicable.started.should include chronologicable
|
422
|
+
end
|
382
423
|
end
|
383
|
-
end
|
384
424
|
|
385
|
-
|
386
|
-
|
387
|
-
|
425
|
+
describe '.current' do
|
426
|
+
it 'does not include that chronologicable' do
|
427
|
+
AbsoluteChronologicable.current.should_not include chronologicable
|
428
|
+
end
|
388
429
|
end
|
389
|
-
end
|
390
430
|
|
391
|
-
|
392
|
-
|
393
|
-
|
431
|
+
describe '.in_progress' do
|
432
|
+
it 'does not include that chronologicable' do
|
433
|
+
AbsoluteChronologicable.in_progress.should_not include chronologicable
|
434
|
+
end
|
394
435
|
end
|
395
436
|
end
|
396
|
-
end
|
397
|
-
end
|
398
|
-
|
399
|
-
context 'when there is a chronologicable that starts now' do
|
400
|
-
let(:start_time) { now }
|
401
437
|
|
402
|
-
|
403
|
-
|
438
|
+
context 'and ends later' do
|
439
|
+
let(:end_time) { later }
|
404
440
|
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
441
|
+
describe '.in_progress?' do
|
442
|
+
it 'is true' do
|
443
|
+
AbsoluteChronologicable.should be_in_progress
|
444
|
+
end
|
409
445
|
end
|
410
|
-
end
|
411
446
|
|
412
|
-
|
413
|
-
|
414
|
-
|
447
|
+
describe '.expired' do
|
448
|
+
it 'does not include that chronologicable' do
|
449
|
+
AbsoluteChronologicable.expired.should_not include chronologicable
|
450
|
+
end
|
415
451
|
end
|
416
|
-
end
|
417
452
|
|
418
|
-
|
419
|
-
|
420
|
-
|
453
|
+
describe '.started' do
|
454
|
+
it 'includes that chronologicable' do
|
455
|
+
AbsoluteChronologicable.started.should include chronologicable
|
456
|
+
end
|
421
457
|
end
|
422
|
-
end
|
423
458
|
|
424
|
-
|
425
|
-
|
426
|
-
|
459
|
+
describe '.current' do
|
460
|
+
it 'includes that chronologicable' do
|
461
|
+
AbsoluteChronologicable.current.should include chronologicable
|
462
|
+
end
|
427
463
|
end
|
428
|
-
end
|
429
464
|
|
430
|
-
|
431
|
-
|
432
|
-
|
465
|
+
describe '.in_progress' do
|
466
|
+
it 'includes that chronologicable' do
|
467
|
+
AbsoluteChronologicable.in_progress.should include chronologicable
|
468
|
+
end
|
433
469
|
end
|
434
470
|
end
|
435
471
|
end
|
436
472
|
|
437
|
-
context '
|
438
|
-
let(:
|
473
|
+
context 'when there is a chronologicable that has not yet started' do
|
474
|
+
let(:start_time) { later }
|
475
|
+
let(:end_time) { later }
|
439
476
|
|
440
477
|
describe '.in_progress?' do
|
441
|
-
it 'is
|
442
|
-
|
443
|
-
AbsoluteChronologicable.should be_in_progress
|
478
|
+
it 'is false' do
|
479
|
+
AbsoluteChronologicable.should_not be_in_progress
|
444
480
|
end
|
445
481
|
end
|
446
482
|
|
@@ -451,8 +487,8 @@ describe Chronological::AbsoluteTimeframe, :timecop => true do
|
|
451
487
|
end
|
452
488
|
|
453
489
|
describe '.started' do
|
454
|
-
it '
|
455
|
-
AbsoluteChronologicable.started.
|
490
|
+
it 'does not include that chronologicable' do
|
491
|
+
AbsoluteChronologicable.started.should_not include chronologicable
|
456
492
|
end
|
457
493
|
end
|
458
494
|
|
@@ -463,46 +499,10 @@ describe Chronological::AbsoluteTimeframe, :timecop => true do
|
|
463
499
|
end
|
464
500
|
|
465
501
|
describe '.in_progress' do
|
466
|
-
it '
|
467
|
-
AbsoluteChronologicable.in_progress.
|
502
|
+
it 'does not include that chronologicable' do
|
503
|
+
AbsoluteChronologicable.in_progress.should_not include chronologicable
|
468
504
|
end
|
469
505
|
end
|
470
506
|
end
|
471
507
|
end
|
472
|
-
|
473
|
-
context 'when there is a chronologicable that has not yet started' do
|
474
|
-
let(:start_time) { later }
|
475
|
-
let(:end_time) { later }
|
476
|
-
|
477
|
-
describe '.in_progress?' do
|
478
|
-
it 'is false' do
|
479
|
-
chronologicable
|
480
|
-
AbsoluteChronologicable.should_not be_in_progress
|
481
|
-
end
|
482
|
-
end
|
483
|
-
|
484
|
-
describe '.expired' do
|
485
|
-
it 'does not include that chronologicable' do
|
486
|
-
AbsoluteChronologicable.expired.should_not include chronologicable
|
487
|
-
end
|
488
|
-
end
|
489
|
-
|
490
|
-
describe '.started' do
|
491
|
-
it 'does not include that chronologicable' do
|
492
|
-
AbsoluteChronologicable.started.should_not include chronologicable
|
493
|
-
end
|
494
|
-
end
|
495
|
-
|
496
|
-
describe '.current' do
|
497
|
-
it 'includes that chronologicable' do
|
498
|
-
AbsoluteChronologicable.current.should include chronologicable
|
499
|
-
end
|
500
|
-
end
|
501
|
-
|
502
|
-
describe '.in_progress' do
|
503
|
-
it 'does not include that chronologicable' do
|
504
|
-
AbsoluteChronologicable.in_progress.should_not include chronologicable
|
505
|
-
end
|
506
|
-
end
|
507
|
-
end
|
508
508
|
end
|
@@ -3,97 +3,157 @@ require 'spec_helper'
|
|
3
3
|
class RelativeChronologicable < ActiveRecord::Base
|
4
4
|
include Chronological::RelativeTimeframe
|
5
5
|
|
6
|
-
relative_timeframe
|
7
|
-
|
8
|
-
:
|
6
|
+
relative_timeframe start: :starting_offset,
|
7
|
+
end: :ending_offset,
|
8
|
+
base_utc: :base_datetime_utc
|
9
9
|
end
|
10
10
|
|
11
11
|
describe Chronological::RelativeTimeframe do
|
12
|
-
let(:now)
|
13
|
-
let(:
|
12
|
+
let(:now) { nil }
|
13
|
+
let(:starting_offset) { nil }
|
14
|
+
let(:ending_offset) { nil }
|
15
|
+
let(:base_time) { nil }
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
let(:chronologicable) do
|
17
|
+
let!(:chronologicable) do
|
18
18
|
RelativeChronologicable.create(
|
19
|
-
:starting_offset
|
20
|
-
:ending_offset
|
21
|
-
:
|
19
|
+
starting_offset: starting_offset,
|
20
|
+
ending_offset: ending_offset,
|
21
|
+
base_datetime_utc: base_time)
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
let(:ending_offset) { 'anything' }
|
24
|
+
before { Timecop.freeze(now) }
|
26
25
|
|
27
|
-
|
26
|
+
it { RelativeChronologicable.new.respond_to?(:active?).should be_true }
|
27
|
+
|
28
|
+
it { RelativeChronologicable.respond_to?(:active?).should be_true }
|
29
|
+
it { RelativeChronologicable.respond_to?(:active).should be_true }
|
30
|
+
|
31
|
+
context 'when the base time is not set' do
|
32
|
+
let(:base_time) { nil }
|
33
|
+
|
34
|
+
context 'but the starting offset is set' do
|
28
35
|
let(:starting_offset) { 30 }
|
29
36
|
|
30
|
-
context '
|
31
|
-
let(:
|
37
|
+
context 'and the ending offset is set' do
|
38
|
+
let(:ending_offset) { 0 }
|
39
|
+
|
40
|
+
it 'is not scheduled' do
|
41
|
+
chronologicable.should_not be_scheduled
|
42
|
+
end
|
32
43
|
|
33
|
-
it 'is
|
34
|
-
chronologicable.
|
44
|
+
it 'is partially scheduled' do
|
45
|
+
chronologicable.should be_partially_scheduled
|
35
46
|
end
|
36
|
-
end
|
37
47
|
|
38
|
-
|
39
|
-
|
48
|
+
it 'is not included in the in progress list' do
|
49
|
+
RelativeChronologicable.in_progress.should_not include chronologicable
|
50
|
+
end
|
40
51
|
|
41
|
-
it '
|
42
|
-
|
52
|
+
it 'does not mark the list as in progress' do
|
53
|
+
RelativeChronologicable.should_not be_in_progress
|
43
54
|
end
|
44
55
|
end
|
45
|
-
end
|
46
56
|
|
47
|
-
|
48
|
-
|
57
|
+
context 'and the ending offset is not set' do
|
58
|
+
let(:ending_offset) { nil }
|
59
|
+
|
60
|
+
it 'is not scheduled' do
|
61
|
+
chronologicable.should_not be_scheduled
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'is partially scheduled' do
|
65
|
+
chronologicable.should be_partially_scheduled
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'is not included in the in progress list' do
|
69
|
+
RelativeChronologicable.in_progress.should_not include chronologicable
|
70
|
+
end
|
49
71
|
|
50
|
-
|
72
|
+
it 'does not mark the list as in progress' do
|
73
|
+
RelativeChronologicable.should_not be_in_progress
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'does not have a start time' do
|
51
78
|
chronologicable.started_at_utc.should be_nil
|
52
79
|
end
|
53
80
|
end
|
54
|
-
end
|
55
81
|
|
56
|
-
|
57
|
-
|
82
|
+
context 'and the starting offset is not set' do
|
83
|
+
let(:starting_offset) { nil }
|
58
84
|
|
59
|
-
|
60
|
-
|
85
|
+
context 'but the ending offset is set' do
|
86
|
+
let(:ending_offset) { 0 }
|
61
87
|
|
62
|
-
|
63
|
-
|
88
|
+
it 'is not scheduled' do
|
89
|
+
chronologicable.should_not be_scheduled
|
90
|
+
end
|
64
91
|
|
65
|
-
it 'is
|
66
|
-
chronologicable.
|
92
|
+
it 'is partially scheduled' do
|
93
|
+
chronologicable.should be_partially_scheduled
|
67
94
|
end
|
68
|
-
end
|
69
95
|
|
70
|
-
|
71
|
-
|
96
|
+
it 'is not included in the in progress list' do
|
97
|
+
RelativeChronologicable.in_progress.should_not include chronologicable
|
98
|
+
end
|
72
99
|
|
73
|
-
it '
|
74
|
-
|
100
|
+
it 'does not mark the list as in progress' do
|
101
|
+
RelativeChronologicable.should_not be_in_progress
|
75
102
|
end
|
76
103
|
end
|
104
|
+
|
105
|
+
it 'does not have a start time' do
|
106
|
+
chronologicable.started_at_utc.should be_nil
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'and the ending offset is set' do
|
111
|
+
let(:ending_offset) { 0 }
|
112
|
+
|
113
|
+
it 'does not have a end time' do
|
114
|
+
chronologicable.ended_at_utc.should be_nil
|
115
|
+
end
|
77
116
|
end
|
78
117
|
|
79
|
-
context '
|
118
|
+
context 'and the ending offset is not set' do
|
80
119
|
let(:ending_offset) { nil }
|
81
120
|
|
82
|
-
it '
|
121
|
+
it 'does not have a end time' do
|
83
122
|
chronologicable.ended_at_utc.should be_nil
|
84
123
|
end
|
85
124
|
end
|
125
|
+
|
126
|
+
context 'and neither of the offsets is set' do
|
127
|
+
let(:starting_offset) { nil }
|
128
|
+
let(:ending_offset) { nil }
|
129
|
+
|
130
|
+
it 'is not scheduled' do
|
131
|
+
chronologicable.should_not be_scheduled
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'is not partially scheduled' do
|
135
|
+
chronologicable.should_not be_partially_scheduled
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'is not included in the in progress list' do
|
139
|
+
RelativeChronologicable.in_progress.should_not include chronologicable
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'does not mark the list as in progress' do
|
143
|
+
RelativeChronologicable.should_not be_in_progress
|
144
|
+
end
|
145
|
+
end
|
86
146
|
end
|
87
147
|
|
88
|
-
context 'when the base time is
|
89
|
-
let(:now)
|
90
|
-
let(:base_time)
|
148
|
+
context 'when the base time is set' do
|
149
|
+
let(:now) { Time.local(2012, 7, 26, 6, 0, 0) }
|
150
|
+
let(:base_time) { Time.local(2012, 7, 26, 6, 0, 30) }
|
91
151
|
|
92
|
-
context '
|
93
|
-
let(:starting_offset) {
|
152
|
+
context 'when the starting offset is not set' do
|
153
|
+
let(:starting_offset) { nil }
|
94
154
|
|
95
|
-
context 'and the ending offset is set' do
|
96
|
-
let(:ending_offset) {
|
155
|
+
context 'and the ending offset is not set' do
|
156
|
+
let(:ending_offset) { nil }
|
97
157
|
|
98
158
|
it 'is not scheduled' do
|
99
159
|
chronologicable.should_not be_scheduled
|
@@ -102,10 +162,18 @@ describe Chronological::RelativeTimeframe do
|
|
102
162
|
it 'is partially scheduled' do
|
103
163
|
chronologicable.should be_partially_scheduled
|
104
164
|
end
|
165
|
+
|
166
|
+
it 'is not included in the in progress list' do
|
167
|
+
RelativeChronologicable.in_progress.should_not include chronologicable
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'does not mark the list as in progress' do
|
171
|
+
RelativeChronologicable.should_not be_in_progress
|
172
|
+
end
|
105
173
|
end
|
106
174
|
|
107
|
-
context 'and the ending offset is
|
108
|
-
let(:ending_offset)
|
175
|
+
context 'and the ending offset is set' do
|
176
|
+
let(:ending_offset) { 0 }
|
109
177
|
|
110
178
|
it 'is not scheduled' do
|
111
179
|
chronologicable.should_not be_scheduled
|
@@ -114,14 +182,26 @@ describe Chronological::RelativeTimeframe do
|
|
114
182
|
it 'is partially scheduled' do
|
115
183
|
chronologicable.should be_partially_scheduled
|
116
184
|
end
|
185
|
+
|
186
|
+
it 'is not included in the in progress list' do
|
187
|
+
RelativeChronologicable.in_progress.should_not include chronologicable
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'does not mark the list as in progress' do
|
191
|
+
RelativeChronologicable.should_not be_in_progress
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'does not have a start time' do
|
196
|
+
chronologicable.started_at_utc.should be_nil
|
117
197
|
end
|
118
198
|
end
|
119
199
|
|
120
|
-
context '
|
121
|
-
let(:starting_offset) {
|
200
|
+
context 'when the starting offset is set' do
|
201
|
+
let(:starting_offset) { 30 }
|
122
202
|
|
123
|
-
context '
|
124
|
-
let(:ending_offset) {
|
203
|
+
context 'and the ending offset is not set' do
|
204
|
+
let(:ending_offset) { nil }
|
125
205
|
|
126
206
|
it 'is not scheduled' do
|
127
207
|
chronologicable.should_not be_scheduled
|
@@ -130,77 +210,144 @@ describe Chronological::RelativeTimeframe do
|
|
130
210
|
it 'is partially scheduled' do
|
131
211
|
chronologicable.should be_partially_scheduled
|
132
212
|
end
|
213
|
+
|
214
|
+
it 'is not included in the in progress list' do
|
215
|
+
RelativeChronologicable.in_progress.should_not include chronologicable
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'does not mark the list as in progress' do
|
219
|
+
RelativeChronologicable.should_not be_in_progress
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context 'and the ending offset is set' do
|
224
|
+
let(:ending_offset) { 0 }
|
225
|
+
|
226
|
+
it 'is scheduled' do
|
227
|
+
chronologicable.should be_scheduled
|
228
|
+
end
|
229
|
+
|
230
|
+
it 'is partially scheduled' do
|
231
|
+
chronologicable.should be_partially_scheduled
|
232
|
+
end
|
233
|
+
|
234
|
+
it 'is included in the in progress list' do
|
235
|
+
RelativeChronologicable.in_progress.should include chronologicable
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'marks the list as in progress' do
|
239
|
+
RelativeChronologicable.should be_in_progress
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'calculates the correct start time' do
|
244
|
+
chronologicable.started_at_utc.should eql Time.local(2012, 7, 26, 6, 0, 0)
|
133
245
|
end
|
134
246
|
end
|
135
247
|
|
136
|
-
context 'and
|
137
|
-
let(:
|
138
|
-
let(:ending_offset) { nil }
|
248
|
+
context 'and the ending offset is set' do
|
249
|
+
let(:ending_offset) { 30 }
|
139
250
|
|
140
|
-
it '
|
141
|
-
chronologicable.
|
251
|
+
it 'calculates the correct end time' do
|
252
|
+
chronologicable.ended_at_utc.should eql Time.local(2012, 7, 26, 6, 0, 0)
|
142
253
|
end
|
254
|
+
end
|
143
255
|
|
144
|
-
|
145
|
-
|
256
|
+
context 'and the ending offset is not set' do
|
257
|
+
let(:ending_offset) { nil }
|
258
|
+
|
259
|
+
it 'does not have a end time' do
|
260
|
+
chronologicable.ended_at_utc.should be_nil
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
context 'when it is currently a time before the starting offset' do
|
266
|
+
let(:now) { Time.local(2012, 7, 26, 5, 59, 59) }
|
267
|
+
let(:base_time) { Time.local(2012, 7, 26, 6, 0, 30) }
|
268
|
+
let(:starting_offset) { 30 }
|
269
|
+
|
270
|
+
context 'and before the ending offset' do
|
271
|
+
let(:ending_offset) { 30 }
|
272
|
+
|
273
|
+
it 'is not included in the in progress list' do
|
274
|
+
RelativeChronologicable.in_progress.should_not include chronologicable
|
275
|
+
end
|
276
|
+
|
277
|
+
it 'does not mark the list as in progress' do
|
278
|
+
RelativeChronologicable.should_not be_in_progress
|
146
279
|
end
|
147
280
|
end
|
148
281
|
end
|
149
282
|
|
150
|
-
context 'when the
|
283
|
+
context 'when it is currently a time the same as the starting offset' do
|
151
284
|
let(:now) { Time.local(2012, 7, 26, 6, 0, 0) }
|
152
|
-
let(:
|
285
|
+
let(:base_time) { Time.local(2012, 7, 26, 6, 0, 30) }
|
286
|
+
let(:starting_offset) { 30 }
|
153
287
|
|
154
|
-
context 'and the ending offset
|
155
|
-
let(:ending_offset) {
|
288
|
+
context 'and before the ending offset' do
|
289
|
+
let(:ending_offset) { 29 }
|
156
290
|
|
157
|
-
it 'is
|
158
|
-
|
291
|
+
it 'is included in the in progress list' do
|
292
|
+
RelativeChronologicable.in_progress.should include chronologicable
|
159
293
|
end
|
160
294
|
|
161
|
-
it '
|
162
|
-
|
295
|
+
it 'marks the list as in progress' do
|
296
|
+
RelativeChronologicable.should be_in_progress
|
163
297
|
end
|
164
298
|
end
|
165
299
|
|
166
|
-
context 'and the ending offset
|
167
|
-
let(:ending_offset)
|
300
|
+
context 'and the same as the ending offset' do
|
301
|
+
let(:ending_offset) { 30 }
|
168
302
|
|
169
|
-
it 'is not
|
170
|
-
|
303
|
+
it 'is not included in the in progress list' do
|
304
|
+
RelativeChronologicable.in_progress.should_not include chronologicable
|
171
305
|
end
|
172
306
|
|
173
|
-
it '
|
174
|
-
|
307
|
+
it 'does not mark the list as in progress' do
|
308
|
+
RelativeChronologicable.should_not be_in_progress
|
175
309
|
end
|
176
310
|
end
|
177
311
|
end
|
178
312
|
|
179
|
-
context 'when the starting offset
|
180
|
-
let(:now) { Time.local(2012, 7, 26, 6, 0,
|
313
|
+
context 'when it is currently a time after the starting offset' do
|
314
|
+
let(:now) { Time.local(2012, 7, 26, 6, 0, 2) }
|
315
|
+
let(:base_time) { Time.local(2012, 7, 26, 6, 0, 30) }
|
181
316
|
let(:starting_offset) { 30 }
|
182
317
|
|
183
|
-
context 'and the ending offset
|
184
|
-
let(:ending_offset) {
|
318
|
+
context 'and before the ending offset' do
|
319
|
+
let(:ending_offset) { 27 }
|
185
320
|
|
186
|
-
it 'is
|
187
|
-
|
321
|
+
it 'is included in the in progress list' do
|
322
|
+
RelativeChronologicable.in_progress.should include chronologicable
|
188
323
|
end
|
189
324
|
|
190
|
-
it '
|
191
|
-
|
325
|
+
it 'marks the list as in progress' do
|
326
|
+
RelativeChronologicable.should be_in_progress
|
192
327
|
end
|
193
328
|
end
|
194
329
|
|
195
|
-
context 'and the ending offset
|
196
|
-
let(:ending_offset)
|
330
|
+
context 'and the same as the ending offset' do
|
331
|
+
let(:ending_offset) { 28 }
|
332
|
+
|
333
|
+
it 'is not included in the in progress list' do
|
334
|
+
RelativeChronologicable.in_progress.should_not include chronologicable
|
335
|
+
end
|
336
|
+
|
337
|
+
it 'does not mark the list as in progress' do
|
338
|
+
RelativeChronologicable.should_not be_in_progress
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
context 'and after the ending offset' do
|
343
|
+
let(:ending_offset) { 29 }
|
197
344
|
|
198
|
-
it 'is
|
199
|
-
|
345
|
+
it 'is not included in the in progress list' do
|
346
|
+
RelativeChronologicable.in_progress.should_not include chronologicable
|
200
347
|
end
|
201
348
|
|
202
|
-
it '
|
203
|
-
|
349
|
+
it 'does not mark the list as in progress' do
|
350
|
+
RelativeChronologicable.should_not be_in_progress
|
204
351
|
end
|
205
352
|
end
|
206
353
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chronological
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-10-
|
13
|
+
date: 2012-10-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|