chronological 1.0.0beta8 → 1.0.0beta9

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.
@@ -0,0 +1,62 @@
1
+ module Chronological
2
+ class DurationFromStartStrategy < BaseStrategy
3
+ def ending_time(object, options = {})
4
+ return nil unless object.send(field_names[:starting_time]).present? &&
5
+ object.send(field_names[:duration]).present?
6
+
7
+ object.send(field_names[:starting_time]) +
8
+ object.send(field_names[:duration])
9
+ end
10
+
11
+ def scheduled?(object)
12
+ object.send(field_names[:starting_time]).present? &&
13
+ object.send(field_names[:duration]).present? &&
14
+ scheduled_time_zone(object, true).present?
15
+ end
16
+
17
+ def partially_scheduled?(object)
18
+ object.send(field_names[:starting_time]).present? ||
19
+ object.send(field_names[:duration]).present? ||
20
+ scheduled_time_zone(object, false).present?
21
+ end
22
+
23
+ def self.in_progress(object, field_names)
24
+ object.all.select(&:in_progress?)
25
+ end
26
+
27
+ def self.in_progress?(object, field_names)
28
+ object.all.any?(&:in_progress?)
29
+ end
30
+
31
+ def has_absolute_start?
32
+ true
33
+ end
34
+
35
+ def has_absolute_end?
36
+ false
37
+ end
38
+
39
+ private
40
+ def self.started_at_sql(field_names)
41
+ field_names[:starting_time]
42
+ end
43
+
44
+ def self.ended_at_sql(field_names)
45
+ "#{field_names[:starting_time]} + (#{field_names[:duration]} * INTERVAL '1 seconds')"
46
+ end
47
+
48
+ def self.duration_sql(field_names)
49
+ field_names[:duration]
50
+ end
51
+
52
+ def duration_in_seconds(object)
53
+ return nil unless object.send(field_names[:duration]).present?
54
+
55
+ object.send(field_names[:duration])
56
+ end
57
+
58
+ def has_absolute_timeframe?(object)
59
+ object.scheduled?
60
+ end
61
+ end
62
+ end
@@ -1,3 +1,4 @@
1
1
  require 'chronological/strategies/base'
2
2
  require 'chronological/strategies/absolute'
3
3
  require 'chronological/strategies/relative'
4
+ require 'chronological/strategies/duration_from_start'
@@ -1,3 +1,3 @@
1
1
  module Chronological
2
- VERSION = '1.0.0beta8'
2
+ VERSION = '1.0.0beta9'
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  require 'pg'
2
2
  require 'active_record'
3
- require 'timecop'
4
3
  require 'chronological'
5
4
 
6
- Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
5
+ require 'rspectacular'
7
6
 
8
- RSpec.configure do |config|
9
- end
7
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
@@ -17,7 +17,7 @@ class AbsoluteChronologicableWithTimeZone < ActiveRecord::Base
17
17
  time_zone: :time_zone
18
18
  end
19
19
 
20
- describe Chronological::AbsoluteStrategy, :timecop => true do
20
+ describe Chronological::AbsoluteStrategy do
21
21
  let(:later) { Time.local(2012, 7, 26, 6, 0, 26) }
22
22
  let(:now) { Time.local(2012, 7, 26, 6, 0, 25) }
23
23
  let(:past) { Time.local(2012, 7, 26, 6, 0, 24) }
@@ -164,7 +164,7 @@ describe Chronological::BaseStrategy do
164
164
  end
165
165
  end
166
166
 
167
- describe '#in_progress?', :timecop => true do
167
+ describe '#in_progress?' do
168
168
  let(:later) { Time.local(2012, 7, 26, 6, 0, 26) }
169
169
  let(:now) { Time.local(2012, 7, 26, 6, 0, 25) }
170
170
  let(:past) { Time.local(2012, 7, 26, 6, 0, 24) }
@@ -0,0 +1,794 @@
1
+ require 'spec_helper'
2
+
3
+ class DurationFromStartChronologicable < ActiveRecord::Base
4
+ extend Chronological
5
+
6
+ timeframe type: :duration_from_start,
7
+ starting_time: :started_at,
8
+ duration: :duration_in_seconds
9
+ end
10
+
11
+ class DurationFromStartChronologicableWithTimeZone < ActiveRecord::Base
12
+ extend Chronological
13
+
14
+ timeframe type: :duration_from_start,
15
+ starting_time: :started_at,
16
+ duration: :duration_in_seconds,
17
+ time_zone: :time_zone
18
+ end
19
+
20
+ class DurationFromStartChronologicalWithOverriddenTime < ActiveRecord::Base
21
+ extend Chronological
22
+
23
+ set_table_name 'duration_from_start_chronologicables'
24
+
25
+ timeframe type: :duration_from_start,
26
+ starting_time: :started_at,
27
+ duration: :duration_in_seconds,
28
+ ending_time: :foobar_ending_time,
29
+ starting_date: :foobar_starting_date,
30
+ ending_date: :foobar_ending_date
31
+ end
32
+
33
+ describe Chronological::DurationFromStartStrategy do
34
+ let(:later) { Time.local(2012, 7, 26, 6, 0, 26) }
35
+ let(:now) { Time.local(2012, 7, 26, 6, 0, 25) }
36
+ let(:past) { Time.local(2012, 7, 26, 6, 0, 24) }
37
+
38
+ let(:started_at) { nil }
39
+ let(:duration_in_seconds) { nil }
40
+ let(:time_zone) { nil }
41
+
42
+ before(:each) { Timecop.freeze(now) }
43
+ after(:each) { Timecop.return }
44
+
45
+ let!(:chronologicable) do
46
+ DurationFromStartChronologicable.create(
47
+ started_at: started_at,
48
+ duration_in_seconds: duration_in_seconds)
49
+ end
50
+
51
+ let!(:chronologicable_without_enabled_time_zone) do
52
+ DurationFromStartChronologicable.new(
53
+ started_at: started_at,
54
+ duration_in_seconds: duration_in_seconds)
55
+ end
56
+
57
+ let!(:chronologicable_with_enabled_time_zone) do
58
+ DurationFromStartChronologicableWithTimeZone.new(
59
+ started_at: started_at,
60
+ duration_in_seconds: duration_in_seconds,
61
+ time_zone: time_zone)
62
+ end
63
+
64
+ let(:chronologicable_with_overridden_time) do
65
+ DurationFromStartChronologicalWithOverriddenTime.new
66
+ end
67
+
68
+ it { chronologicable_with_overridden_time.should respond_to(:foobar_ending_time) }
69
+ it { chronologicable_with_overridden_time.should respond_to(:foobar_starting_date) }
70
+ it { chronologicable_with_overridden_time.should respond_to(:foobar_ending_date) }
71
+
72
+ describe '.by_date' do
73
+ before { DurationFromStartChronologicable.delete_all }
74
+
75
+ context 'when there are two chronologicables that start at the same time' do
76
+ context 'but end at different times' do
77
+ let!(:chronologicable_1) { DurationFromStartChronologicable.create(:started_at => now, :duration_in_seconds => 1) }
78
+ let!(:chronologicable_2) { DurationFromStartChronologicable.create(:started_at => now, :duration_in_seconds => 2) }
79
+
80
+ context 'when no option is passed' do
81
+ it 'properly sorts them in ascending order' do
82
+ DurationFromStartChronologicable.by_date.first.should eql chronologicable_1
83
+ DurationFromStartChronologicable.by_date.last.should eql chronologicable_2
84
+ end
85
+ end
86
+
87
+ context 'when the :desc option is passed' do
88
+ it 'sorts them backwards by the start date' do
89
+ DurationFromStartChronologicable.by_date(:desc).first.should eql chronologicable_2
90
+ DurationFromStartChronologicable.by_date(:desc).last.should eql chronologicable_1
91
+ end
92
+ end
93
+ end
94
+
95
+ context 'and end at the same time' do
96
+ let!(:chronologicable_1) { DurationFromStartChronologicable.create(:started_at => now, :duration_in_seconds => 1) }
97
+ let!(:chronologicable_2) { DurationFromStartChronologicable.create(:started_at => now, :duration_in_seconds => 1) }
98
+
99
+ describe '.by_date' do
100
+ context 'when in ascending order' do
101
+ it 'does not matter what order they are in as long as they are all there' do
102
+ DurationFromStartChronologicable.by_date.should include chronologicable_1
103
+ DurationFromStartChronologicable.by_date.should include chronologicable_2
104
+ end
105
+ end
106
+
107
+ context 'when in descending order' do
108
+ it 'does not matter what order they are in as long as they are all there' do
109
+ DurationFromStartChronologicable.by_date(:desc).should include chronologicable_1
110
+ DurationFromStartChronologicable.by_date(:desc).should include chronologicable_2
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+
117
+ context 'when there are two chronologicables that start at different times' do
118
+ context 'and end at different times' do
119
+ let!(:chronologicable_1) { DurationFromStartChronologicable.create(:started_at => now, :duration_in_seconds => 2) }
120
+ let!(:chronologicable_2) { DurationFromStartChronologicable.create(:started_at => past, :duration_in_seconds => 1) }
121
+
122
+ context 'when in ascending order' do
123
+ it 'sorts them by the start date' do
124
+ DurationFromStartChronologicable.by_date.first.should eql chronologicable_2
125
+ DurationFromStartChronologicable.by_date.last.should eql chronologicable_1
126
+ end
127
+ end
128
+
129
+ context 'when in descending order' do
130
+ it 'sorts them backwards by the start date' do
131
+ DurationFromStartChronologicable.by_date(:desc).first.should eql chronologicable_1
132
+ DurationFromStartChronologicable.by_date(:desc).last.should eql chronologicable_2
133
+ end
134
+ end
135
+ end
136
+
137
+ context 'but end at the same time' do
138
+ let!(:chronologicable_1) { DurationFromStartChronologicable.create(:started_at => now, :duration_in_seconds => 1) }
139
+ let!(:chronologicable_2) { DurationFromStartChronologicable.create(:started_at => past, :duration_in_seconds => 2) }
140
+
141
+ context 'when in ascending order' do
142
+ it 'sorts them by the start date' do
143
+ DurationFromStartChronologicable.by_date.first.should eql chronologicable_2
144
+ DurationFromStartChronologicable.by_date.last.should eql chronologicable_1
145
+ end
146
+ end
147
+
148
+ context 'when in descending order' do
149
+ it 'sorts them backwards by the start date' do
150
+ DurationFromStartChronologicable.by_date(:desc).first.should eql chronologicable_1
151
+ DurationFromStartChronologicable.by_date(:desc).last.should eql chronologicable_2
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
157
+
158
+ describe '.by_duration' do
159
+ before { DurationFromStartChronologicable.delete_all }
160
+
161
+ context 'when there are two chronologicables that are different durations' do
162
+ let!(:chronologicable_1) { DurationFromStartChronologicable.create(:started_at => now, :duration_in_seconds => 1) }
163
+ let!(:chronologicable_2) { DurationFromStartChronologicable.create(:started_at => now, :duration_in_seconds => 2) }
164
+
165
+ context 'when no option is passed' do
166
+ it 'properly sorts them in ascending order' do
167
+ DurationFromStartChronologicable.by_date.first.should eql chronologicable_1
168
+ DurationFromStartChronologicable.by_date.last.should eql chronologicable_2
169
+ end
170
+ end
171
+
172
+ context 'when the :desc option is passed' do
173
+ it 'sorts them backwards by the start date' do
174
+ DurationFromStartChronologicable.by_date(:desc).first.should eql chronologicable_2
175
+ DurationFromStartChronologicable.by_date(:desc).last.should eql chronologicable_1
176
+ end
177
+ end
178
+ end
179
+
180
+ context 'when there are two chronologicables that are the same duration' do
181
+ let!(:chronologicable_1) { DurationFromStartChronologicable.create(:started_at => now, :duration_in_seconds => 1) }
182
+ let!(:chronologicable_2) { DurationFromStartChronologicable.create(:started_at => now, :duration_in_seconds => 1) }
183
+
184
+ context 'when no option is passed' do
185
+ it 'does not matter what order they are in' do
186
+ DurationFromStartChronologicable.by_date.should include chronologicable_1
187
+ DurationFromStartChronologicable.by_date.should include chronologicable_2
188
+ end
189
+ end
190
+
191
+ context 'when the :desc option is passed' do
192
+ it 'does not matter what order they are in' do
193
+ DurationFromStartChronologicable.by_date(:desc).should include chronologicable_1
194
+ DurationFromStartChronologicable.by_date(:desc).should include chronologicable_2
195
+ end
196
+ end
197
+ end
198
+ end
199
+
200
+ context 'when the start time is not set' do
201
+ let(:started_at) { nil }
202
+
203
+ context 'but the duration is set' do
204
+ let(:duration_in_seconds) { 30 }
205
+
206
+ context 'when the time zone is not set' do
207
+ let(:time_zone) { nil }
208
+
209
+ context 'and the time zone check is enabled' do
210
+ it 'is not scheduled' do
211
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
212
+ end
213
+
214
+ it 'is partially scheduled' do
215
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
216
+ end
217
+ end
218
+
219
+ context 'and the time zone check is not enabled' do
220
+ it 'is not scheduled' do
221
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
222
+ end
223
+
224
+ it 'is partially scheduled' do
225
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
226
+ end
227
+ end
228
+ end
229
+
230
+ context 'when the time zone is blank' do
231
+ let(:time_zone) { '' }
232
+
233
+ context 'and the time zone check is enabled' do
234
+ it 'is not scheduled' do
235
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
236
+ end
237
+
238
+ it 'is partially scheduled' do
239
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
240
+ end
241
+ end
242
+
243
+ context 'and the time zone check is not enabled' do
244
+ it 'is not scheduled' do
245
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
246
+ end
247
+
248
+ it 'is partially scheduled' do
249
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
250
+ end
251
+ end
252
+ end
253
+
254
+ context 'when the time zone is set' do
255
+ let(:time_zone) { 'Alaska' }
256
+
257
+ context 'and the time zone check is enabled' do
258
+ it 'is not scheduled' do
259
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
260
+ end
261
+
262
+ it 'is partially scheduled' do
263
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
264
+ end
265
+ end
266
+
267
+ context 'and the time zone check is not enabled' do
268
+ it 'is not scheduled' do
269
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
270
+ end
271
+
272
+ it 'is partially scheduled' do
273
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
274
+ end
275
+ end
276
+ end
277
+
278
+ it 'is not included in the in progress list' do
279
+ DurationFromStartChronologicable.in_progress.should_not include chronologicable
280
+ end
281
+
282
+ it 'does not mark the list as in progress' do
283
+ DurationFromStartChronologicable.should_not be_in_progress
284
+ end
285
+ end
286
+
287
+ context 'and the duration is not set' do
288
+ let(:duration_in_seconds) { nil }
289
+
290
+ context 'when the time zone is not set' do
291
+ let(:time_zone) { nil }
292
+
293
+ context 'and the time zone check is enabled' do
294
+ it 'is not scheduled' do
295
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
296
+ end
297
+
298
+ it 'is partially scheduled' do
299
+ chronologicable_with_enabled_time_zone.should_not be_partially_scheduled
300
+ end
301
+ end
302
+
303
+ context 'and the time zone check is not enabled' do
304
+ it 'is not scheduled' do
305
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
306
+ end
307
+
308
+ it 'is partially scheduled' do
309
+ chronologicable_without_enabled_time_zone.should_not be_partially_scheduled
310
+ end
311
+ end
312
+ end
313
+
314
+ context 'when the time zone is blank' do
315
+ let(:time_zone) { '' }
316
+
317
+ context 'and the time zone check is enabled' do
318
+ it 'is not scheduled' do
319
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
320
+ end
321
+
322
+ it 'is partially scheduled' do
323
+ chronologicable_with_enabled_time_zone.should_not be_partially_scheduled
324
+ end
325
+ end
326
+
327
+ context 'and the time zone check is not enabled' do
328
+ it 'is not scheduled' do
329
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
330
+ end
331
+
332
+ it 'is partially scheduled' do
333
+ chronologicable_without_enabled_time_zone.should_not be_partially_scheduled
334
+ end
335
+ end
336
+ end
337
+
338
+ context 'when the time zone is set' do
339
+ let(:time_zone) { 'Alaska' }
340
+
341
+ context 'and the time zone check is enabled' do
342
+ it 'is not scheduled' do
343
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
344
+ end
345
+
346
+ it 'is partially scheduled' do
347
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
348
+ end
349
+ end
350
+
351
+ context 'and the time zone check is not enabled' do
352
+ it 'is not scheduled' do
353
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
354
+ end
355
+
356
+ it 'is partially scheduled' do
357
+ chronologicable_without_enabled_time_zone.should_not be_partially_scheduled
358
+ end
359
+ end
360
+ end
361
+
362
+ it 'is not included in the in progress list' do
363
+ DurationFromStartChronologicable.in_progress.should_not include chronologicable
364
+ end
365
+
366
+ it 'does not mark the list as in progress' do
367
+ DurationFromStartChronologicable.should_not be_in_progress
368
+ end
369
+ end
370
+ end
371
+
372
+ context 'when the start time is set' do
373
+ let(:started_at) { now }
374
+
375
+ context 'and the duration is set' do
376
+ let(:duration_in_seconds) { 30 }
377
+
378
+ context 'when the time zone is not set' do
379
+ let(:time_zone) { nil }
380
+
381
+ context 'and the time zone check is enabled' do
382
+ it 'is not scheduled' do
383
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
384
+ end
385
+
386
+ it 'is partially scheduled' do
387
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
388
+ end
389
+ end
390
+
391
+ context 'and the time zone check is not enabled' do
392
+ it 'is scheduled' do
393
+ chronologicable_without_enabled_time_zone.should be_scheduled
394
+ end
395
+
396
+ it 'is partially scheduled' do
397
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
398
+ end
399
+ end
400
+ end
401
+
402
+ context 'when the time zone is blank' do
403
+ let(:time_zone) { '' }
404
+
405
+ context 'and the time zone check is enabled' do
406
+ it 'is not scheduled' do
407
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
408
+ end
409
+
410
+ it 'is partially scheduled' do
411
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
412
+ end
413
+ end
414
+
415
+ context 'and the time zone check is not enabled' do
416
+ it 'is scheduled' do
417
+ chronologicable_without_enabled_time_zone.should be_scheduled
418
+ end
419
+
420
+ it 'is partially scheduled' do
421
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
422
+ end
423
+ end
424
+ end
425
+
426
+ context 'when the time zone is set' do
427
+ let(:time_zone) { 'Alaska' }
428
+
429
+ context 'and the time zone check is enabled' do
430
+ it 'is scheduled' do
431
+ chronologicable_with_enabled_time_zone.should be_scheduled
432
+ end
433
+
434
+ it 'is partially scheduled' do
435
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
436
+ end
437
+ end
438
+
439
+ context 'and the time zone check is not enabled' do
440
+ it 'is scheduled' do
441
+ chronologicable_without_enabled_time_zone.should be_scheduled
442
+ end
443
+
444
+ it 'is partially scheduled' do
445
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
446
+ end
447
+ end
448
+ end
449
+
450
+ it 'is included in the in progress list' do
451
+ DurationFromStartChronologicable.in_progress.should include chronologicable
452
+ end
453
+
454
+ it 'does mark the list as in progress' do
455
+ DurationFromStartChronologicable.should be_in_progress
456
+ end
457
+ end
458
+
459
+ context 'and the duration is not set' do
460
+ let(:duration_in_seconds) { nil }
461
+
462
+ context 'when the time zone is not set' do
463
+ let(:time_zone) { nil }
464
+
465
+ context 'and the time zone check is enabled' do
466
+ it 'is not scheduled' do
467
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
468
+ end
469
+
470
+ it 'is partially scheduled' do
471
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
472
+ end
473
+ end
474
+
475
+ context 'and the time zone check is not enabled' do
476
+ it 'is not scheduled' do
477
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
478
+ end
479
+
480
+ it 'is partially scheduled' do
481
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
482
+ end
483
+ end
484
+ end
485
+
486
+ context 'when the time zone is blank' do
487
+ let(:time_zone) { '' }
488
+
489
+ context 'and the time zone check is enabled' do
490
+ it 'is not scheduled' do
491
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
492
+ end
493
+
494
+ it 'is partially scheduled' do
495
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
496
+ end
497
+ end
498
+
499
+ context 'and the time zone check is not enabled' do
500
+ it 'is not scheduled' do
501
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
502
+ end
503
+
504
+ it 'is partially scheduled' do
505
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
506
+ end
507
+ end
508
+ end
509
+
510
+ context 'when the time zone is set' do
511
+ let(:time_zone) { 'Alaska' }
512
+
513
+ context 'and the time zone check is enabled' do
514
+ it 'is not scheduled' do
515
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
516
+ end
517
+
518
+ it 'is partially scheduled' do
519
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
520
+ end
521
+ end
522
+
523
+ context 'and the time zone check is not enabled' do
524
+ it 'is not scheduled' do
525
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
526
+ end
527
+
528
+ it 'is partially scheduled' do
529
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
530
+ end
531
+ end
532
+ end
533
+
534
+ it 'is not included in the in progress list' do
535
+ DurationFromStartChronologicable.in_progress.should_not include chronologicable
536
+ end
537
+
538
+ it 'does not mark the list as in progress' do
539
+ DurationFromStartChronologicable.should_not be_in_progress
540
+ end
541
+ end
542
+ end
543
+
544
+ context 'when the base time is set' do
545
+ let(:started_at) { Time.local(2012, 7, 26, 6, 0, 0) }
546
+
547
+ context 'and the duration is set' do
548
+ let(:duration_in_seconds) { 30 }
549
+
550
+ it 'calculates the correct end time when called directly' do
551
+ chronologicable.ended_at.should eql Time.local(2012, 7, 26, 6, 0, 30)
552
+ end
553
+ end
554
+
555
+ context 'and the duration is not set' do
556
+ let(:duration_in_seconds) { nil }
557
+
558
+ it 'does not have a end time when called directly' do
559
+ chronologicable.ended_at.should be_nil
560
+ end
561
+ end
562
+ end
563
+
564
+ context 'when it is currently a time before the start date' do
565
+ let(:now) { Time.local(2012, 7, 26, 5, 59, 59) }
566
+ let(:started_at) { Time.local(2012, 7, 26, 6, 0, 0) }
567
+
568
+ context 'and before the calculated end date' do
569
+ let(:duration_in_seconds) { 30 }
570
+
571
+ it 'is not started when called directly' do
572
+ chronologicable.should_not be_started
573
+ end
574
+
575
+ it 'is not ended when called directly' do
576
+ chronologicable.should_not be_ended
577
+ end
578
+
579
+ it 'is not yet ended when called directly' do
580
+ chronologicable.should be_not_yet_ended
581
+ end
582
+
583
+ it 'is not included in the started list' do
584
+ DurationFromStartChronologicable.started.should_not include chronologicable
585
+ end
586
+
587
+ it 'is not included in the ended list' do
588
+ DurationFromStartChronologicable.ended.should_not include chronologicable
589
+ end
590
+
591
+ it 'is included in the not yet ended list' do
592
+ DurationFromStartChronologicable.not_yet_ended.should include chronologicable
593
+ end
594
+
595
+ it 'is not included in the in progress list' do
596
+ DurationFromStartChronologicable.in_progress.should_not include chronologicable
597
+ end
598
+
599
+ it 'does not mark the list as in progress' do
600
+ DurationFromStartChronologicable.should_not be_in_progress
601
+ end
602
+ end
603
+ end
604
+
605
+ context 'when it is currently a time the same as the start time' do
606
+ let(:now) { Time.local(2012, 7, 26, 6, 0, 0) }
607
+ let(:started_at) { Time.local(2012, 7, 26, 6, 0, 0) }
608
+
609
+ context 'and before the calculated end date' do
610
+ let(:duration_in_seconds) { 1 }
611
+
612
+ it 'is not started when called directly' do
613
+ chronologicable.should be_started
614
+ end
615
+
616
+ it 'is not ended when called directly' do
617
+ chronologicable.should_not be_ended
618
+ end
619
+
620
+ it 'is not yet ended when called directly' do
621
+ chronologicable.should be_not_yet_ended
622
+ end
623
+
624
+ it 'is included in the started list' do
625
+ DurationFromStartChronologicable.started.should include chronologicable
626
+ end
627
+
628
+ it 'is not included in the ended list' do
629
+ DurationFromStartChronologicable.ended.should_not include chronologicable
630
+ end
631
+
632
+ it 'is included in the not yet ended list' do
633
+ DurationFromStartChronologicable.not_yet_ended.should include chronologicable
634
+ end
635
+
636
+ it 'is included in the in progress list' do
637
+ DurationFromStartChronologicable.in_progress.should include chronologicable
638
+ end
639
+
640
+ it 'marks the list as in progress' do
641
+ DurationFromStartChronologicable.should be_in_progress
642
+ end
643
+ end
644
+
645
+ context 'and the same as the calculated end date' do
646
+ let(:duration_in_seconds) { 0 }
647
+
648
+ it 'is not started when called directly' do
649
+ chronologicable.should be_started
650
+ end
651
+
652
+ it 'is not ended when called directly' do
653
+ chronologicable.should be_ended
654
+ end
655
+
656
+ it 'is not yet ended when called directly' do
657
+ chronologicable.should_not be_not_yet_ended
658
+ end
659
+
660
+ it 'is included in the started list' do
661
+ DurationFromStartChronologicable.started.should include chronologicable
662
+ end
663
+
664
+ it 'is included in the ended list' do
665
+ DurationFromStartChronologicable.ended.should include chronologicable
666
+ end
667
+
668
+ it 'is not included in the not yet ended list' do
669
+ DurationFromStartChronologicable.not_yet_ended.should_not include chronologicable
670
+ end
671
+
672
+ it 'is not included in the in progress list' do
673
+ DurationFromStartChronologicable.in_progress.should_not include chronologicable
674
+ end
675
+
676
+ it 'does not mark the list as in progress' do
677
+ DurationFromStartChronologicable.should_not be_in_progress
678
+ end
679
+ end
680
+ end
681
+
682
+ context 'when it is currently a time after the start time' do
683
+ let(:now) { Time.local(2012, 7, 26, 6, 0, 2) }
684
+ let(:started_at) { Time.local(2012, 7, 26, 6, 0, 1) }
685
+
686
+ context 'and before the calculated end date' do
687
+ let(:duration_in_seconds) { 2 }
688
+
689
+ it 'is not started when called directly' do
690
+ chronologicable.should be_started
691
+ end
692
+
693
+ it 'is not ended when called directly' do
694
+ chronologicable.should_not be_ended
695
+ end
696
+
697
+ it 'is not yet ended when called directly' do
698
+ chronologicable.should be_not_yet_ended
699
+ end
700
+
701
+ it 'is included in the started list' do
702
+ DurationFromStartChronologicable.started.should include chronologicable
703
+ end
704
+
705
+ it 'is not included in the ended list' do
706
+ DurationFromStartChronologicable.ended.should_not include chronologicable
707
+ end
708
+
709
+ it 'is included in the not yet ended list' do
710
+ DurationFromStartChronologicable.not_yet_ended.should include chronologicable
711
+ end
712
+
713
+ it 'is included in the in progress list' do
714
+ DurationFromStartChronologicable.in_progress.should include chronologicable
715
+ end
716
+
717
+ it 'marks the list as in progress' do
718
+ DurationFromStartChronologicable.should be_in_progress
719
+ end
720
+ end
721
+
722
+ context 'and the same as the calculated end date' do
723
+ let(:duration_in_seconds) { 1 }
724
+
725
+ it 'is not started when called directly' do
726
+ chronologicable.should be_started
727
+ end
728
+
729
+ it 'is not ended when called directly' do
730
+ chronologicable.should be_ended
731
+ end
732
+
733
+ it 'is not yet ended when called directly' do
734
+ chronologicable.should_not be_not_yet_ended
735
+ end
736
+
737
+ it 'is included in the started list' do
738
+ DurationFromStartChronologicable.started.should include chronologicable
739
+ end
740
+
741
+ it 'is included in the ended list' do
742
+ DurationFromStartChronologicable.ended.should include chronologicable
743
+ end
744
+
745
+ it 'is not included in the not yet ended list' do
746
+ DurationFromStartChronologicable.not_yet_ended.should_not include chronologicable
747
+ end
748
+
749
+ it 'is not included in the in progress list' do
750
+ DurationFromStartChronologicable.in_progress.should_not include chronologicable
751
+ end
752
+
753
+ it 'does not mark the list as in progress' do
754
+ DurationFromStartChronologicable.should_not be_in_progress
755
+ end
756
+ end
757
+
758
+ context 'and after the calculated end date' do
759
+ let(:duration_in_seconds) { 0 }
760
+
761
+ it 'is not started when called directly' do
762
+ chronologicable.should be_started
763
+ end
764
+
765
+ it 'is not ended when called directly' do
766
+ chronologicable.should be_ended
767
+ end
768
+
769
+ it 'is not yet ended when called directly' do
770
+ chronologicable.should_not be_not_yet_ended
771
+ end
772
+
773
+ it 'is included in the started list' do
774
+ DurationFromStartChronologicable.started.should include chronologicable
775
+ end
776
+
777
+ it 'is included in the ended list' do
778
+ DurationFromStartChronologicable.ended.should include chronologicable
779
+ end
780
+
781
+ it 'is not included in the not yet ended list' do
782
+ DurationFromStartChronologicable.not_yet_ended.should_not include chronologicable
783
+ end
784
+
785
+ it 'is not included in the in progress list' do
786
+ DurationFromStartChronologicable.in_progress.should_not include chronologicable
787
+ end
788
+
789
+ it 'does not mark the list as in progress' do
790
+ DurationFromStartChronologicable.should_not be_in_progress
791
+ end
792
+ end
793
+ end
794
+ end
@@ -45,7 +45,7 @@ class RelativeChronologicableWithDynamicBase < ActiveRecord::Base
45
45
  attr_accessor :base_datetime_utc
46
46
  end
47
47
 
48
- describe Chronological::RelativeStrategy, :timecop => true do
48
+ describe Chronological::RelativeStrategy do
49
49
  let(:now) { nil }
50
50
  let(:starting_offset) { nil }
51
51
  let(:ending_offset) { nil }
@@ -26,6 +26,17 @@ ActiveRecord::Base.connection.create_table :base_chronologicables do |t|
26
26
  t.datetime :ended_at
27
27
  end
28
28
 
29
+ ActiveRecord::Base.connection.create_table :duration_from_start_chronologicables do |t|
30
+ t.datetime :started_at
31
+ t.integer :duration_in_seconds
32
+ end
33
+
34
+ ActiveRecord::Base.connection.create_table :duration_from_start_chronologicable_with_time_zones do |t|
35
+ t.datetime :started_at
36
+ t.integer :duration_in_seconds
37
+ t.string :time_zone
38
+ end
39
+
29
40
  ActiveRecord::Base.connection.create_table :relative_chronologicables do |t|
30
41
  t.integer :starting_offset
31
42
  t.integer :ending_offset
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: 1.0.0beta8
4
+ version: 1.0.0beta9
5
5
  prerelease: 5
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-11-19 00:00:00.000000000 Z
13
+ date: 2013-06-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -19,7 +19,7 @@ dependencies:
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: '2.11'
22
+ version: '2.13'
23
23
  type: :development
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,15 +27,15 @@ dependencies:
27
27
  requirements:
28
28
  - - ~>
29
29
  - !ruby/object:Gem::Version
30
- version: '2.11'
30
+ version: '2.13'
31
31
  - !ruby/object:Gem::Dependency
32
- name: fuubar
32
+ name: rspectacular
33
33
  requirement: !ruby/object:Gem::Requirement
34
34
  none: false
35
35
  requirements:
36
36
  - - ~>
37
37
  - !ruby/object:Gem::Version
38
- version: '1.0'
38
+ version: '0.13'
39
39
  type: :development
40
40
  prerelease: false
41
41
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,63 +43,15 @@ dependencies:
43
43
  requirements:
44
44
  - - ~>
45
45
  - !ruby/object:Gem::Version
46
- version: '1.0'
46
+ version: '0.13'
47
47
  - !ruby/object:Gem::Dependency
48
- name: guard
49
- requirement: !ruby/object:Gem::Requirement
50
- none: false
51
- requirements:
52
- - - ~>
53
- - !ruby/object:Gem::Version
54
- version: 1.4.0
55
- type: :development
56
- prerelease: false
57
- version_requirements: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ~>
61
- - !ruby/object:Gem::Version
62
- version: 1.4.0
63
- - !ruby/object:Gem::Dependency
64
- name: guard-rspec
65
- requirement: !ruby/object:Gem::Requirement
66
- none: false
67
- requirements:
68
- - - ~>
69
- - !ruby/object:Gem::Version
70
- version: 2.0.0
71
- type: :development
72
- prerelease: false
73
- version_requirements: !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ~>
77
- - !ruby/object:Gem::Version
78
- version: 2.0.0
79
- - !ruby/object:Gem::Dependency
80
- name: rb-fsevent
81
- requirement: !ruby/object:Gem::Requirement
82
- none: false
83
- requirements:
84
- - - ~>
85
- - !ruby/object:Gem::Version
86
- version: 0.9.1
87
- type: :development
88
- prerelease: false
89
- version_requirements: !ruby/object:Gem::Requirement
90
- none: false
91
- requirements:
92
- - - ~>
93
- - !ruby/object:Gem::Version
94
- version: 0.9.1
95
- - !ruby/object:Gem::Dependency
96
- name: awesome_print
48
+ name: activerecord
97
49
  requirement: !ruby/object:Gem::Requirement
98
50
  none: false
99
51
  requirements:
100
52
  - - ~>
101
53
  - !ruby/object:Gem::Version
102
- version: 1.1.0
54
+ version: 3.1.8
103
55
  type: :development
104
56
  prerelease: false
105
57
  version_requirements: !ruby/object:Gem::Requirement
@@ -107,15 +59,15 @@ dependencies:
107
59
  requirements:
108
60
  - - ~>
109
61
  - !ruby/object:Gem::Version
110
- version: 1.1.0
62
+ version: 3.1.8
111
63
  - !ruby/object:Gem::Dependency
112
- name: activerecord
64
+ name: database_cleaner
113
65
  requirement: !ruby/object:Gem::Requirement
114
66
  none: false
115
67
  requirements:
116
68
  - - ~>
117
69
  - !ruby/object:Gem::Version
118
- version: 3.1.8
70
+ version: '1.0'
119
71
  type: :development
120
72
  prerelease: false
121
73
  version_requirements: !ruby/object:Gem::Requirement
@@ -123,7 +75,7 @@ dependencies:
123
75
  requirements:
124
76
  - - ~>
125
77
  - !ruby/object:Gem::Version
126
- version: 3.1.8
78
+ version: '1.0'
127
79
  - !ruby/object:Gem::Dependency
128
80
  name: pg
129
81
  requirement: !ruby/object:Gem::Requirement
@@ -147,7 +99,7 @@ dependencies:
147
99
  requirements:
148
100
  - - ~>
149
101
  - !ruby/object:Gem::Version
150
- version: 0.5.2
102
+ version: 0.6.1
151
103
  type: :development
152
104
  prerelease: false
153
105
  version_requirements: !ruby/object:Gem::Requirement
@@ -155,7 +107,7 @@ dependencies:
155
107
  requirements:
156
108
  - - ~>
157
109
  - !ruby/object:Gem::Version
158
- version: 0.5.2
110
+ version: 0.6.1
159
111
  description: ''
160
112
  email: support@chirrpy.com
161
113
  executables: []
@@ -167,6 +119,7 @@ files:
167
119
  - lib/chronological/errors.rb
168
120
  - lib/chronological/strategies/absolute.rb
169
121
  - lib/chronological/strategies/base.rb
122
+ - lib/chronological/strategies/duration_from_start.rb
170
123
  - lib/chronological/strategies/relative.rb
171
124
  - lib/chronological/strategies.rb
172
125
  - lib/chronological/strategy_resolver.rb
@@ -179,12 +132,10 @@ files:
179
132
  - spec/spec_helper.rb
180
133
  - spec/strategies/absolute_spec.rb
181
134
  - spec/strategies/base_spec.rb
135
+ - spec/strategies/duration_from_start_spec.rb
182
136
  - spec/strategies/relative_spec.rb
183
137
  - spec/strategy_resolver_spec.rb
184
138
  - spec/support/active_record.rb
185
- - spec/support/focused.rb
186
- - spec/support/pending.rb
187
- - spec/support/timecop.rb
188
139
  homepage: https://github.com/chirrpy/chronological
189
140
  licenses: []
190
141
  post_install_message:
@@ -206,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
157
  version: 1.3.1
207
158
  requirements: []
208
159
  rubyforge_project: chronological
209
- rubygems_version: 1.8.24
160
+ rubygems_version: 1.8.23
210
161
  signing_key:
211
162
  specification_version: 3
212
163
  summary: Easy Accessors for ActiveModel Objects
@@ -215,9 +166,8 @@ test_files:
215
166
  - spec/spec_helper.rb
216
167
  - spec/strategies/absolute_spec.rb
217
168
  - spec/strategies/base_spec.rb
169
+ - spec/strategies/duration_from_start_spec.rb
218
170
  - spec/strategies/relative_spec.rb
219
171
  - spec/strategy_resolver_spec.rb
220
172
  - spec/support/active_record.rb
221
- - spec/support/focused.rb
222
- - spec/support/pending.rb
223
- - spec/support/timecop.rb
173
+ has_rdoc:
@@ -1,7 +0,0 @@
1
- RSpec.configure do |config|
2
- # Configure RSpec to run focused specs, and also respect the alias 'fit' for focused specs
3
- config.treat_symbols_as_metadata_keys_with_true_values = true
4
- config.filter_run :focused => true
5
- config.alias_example_to :fit, :focused => true
6
- config.run_all_when_everything_filtered = true
7
- end
@@ -1,4 +0,0 @@
1
- RSpec.configure do |config|
2
- # Configure RSpec to respect the alias 'pit' for pending specs
3
- config.alias_example_to :pit, :pending => true
4
- end
@@ -1,5 +0,0 @@
1
- RSpec.configure do |config|
2
- config.after(:each, :timecop => true) do
3
- Timecop.return
4
- end
5
- end