chronological 1.0.0beta6 → 1.0.0beta7
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/README.md +5 -0
- data/lib/chronological/strategies/base.rb +12 -0
- data/lib/chronological/strategies/relative.rb +10 -6
- data/lib/chronological/version.rb +1 -1
- data/lib/chronological.rb +36 -6
- data/spec/strategies/absolute_spec.rb +180 -0
- data/spec/strategies/relative_spec.rb +186 -10
- metadata +2 -2
data/README.md
CHANGED
@@ -252,6 +252,11 @@ default behavior which is `Time.now.utc`. Using this option you can more easily
|
|
252
252
|
see if an instance (or instances) would be started, ended, etc as of a given
|
253
253
|
date.
|
254
254
|
|
255
|
+
All range status methods can also take a `:base_of` option _this is only
|
256
|
+
meaningful for strategies which utilize an offset for either the start
|
257
|
+
time or the end time_ which will calculate the absolute time based on
|
258
|
+
that time rather than any time stored within the instance.
|
259
|
+
|
255
260
|
Affected methods:
|
256
261
|
|
257
262
|
* `started?`
|
@@ -56,6 +56,18 @@ module Chronological
|
|
56
56
|
(object.send(field_names[:starting_time]) <= Time.now.utc) && object.send(field_names[:ending_time]).future?
|
57
57
|
end
|
58
58
|
|
59
|
+
def started?(object, options = {})
|
60
|
+
Time.now >= object.send(field_names[:starting_time], options)
|
61
|
+
end
|
62
|
+
|
63
|
+
def ended?(object, options = {})
|
64
|
+
Time.now >= object.send(field_names[:ending_time], options)
|
65
|
+
end
|
66
|
+
|
67
|
+
def not_yet_ended?(object, options = {})
|
68
|
+
!ended?(object, options)
|
69
|
+
end
|
70
|
+
|
59
71
|
###
|
60
72
|
# Scopes
|
61
73
|
#
|
@@ -1,15 +1,19 @@
|
|
1
1
|
module Chronological
|
2
2
|
class RelativeStrategy < BaseStrategy
|
3
|
-
def starting_time(object)
|
4
|
-
|
3
|
+
def starting_time(object, options = {})
|
4
|
+
base_of_offset = options[:base_of] || object.send(field_names[:base_of_offset])
|
5
5
|
|
6
|
-
|
6
|
+
return nil unless base_of_offset.present? && object.send(field_names[:starting_offset]).present?
|
7
|
+
|
8
|
+
base_of_offset - object.send(field_names[:starting_offset])
|
7
9
|
end
|
8
10
|
|
9
|
-
def ending_time(object)
|
10
|
-
|
11
|
+
def ending_time(object, options = {})
|
12
|
+
base_of_offset = options[:base_of] || object.send(field_names[:base_of_offset])
|
13
|
+
|
14
|
+
return nil unless base_of_offset.present? && object.send(field_names[:ending_offset]).present?
|
11
15
|
|
12
|
-
|
16
|
+
base_of_offset - object.send(field_names[:ending_offset])
|
13
17
|
end
|
14
18
|
|
15
19
|
def scheduled?(object)
|
data/lib/chronological.rb
CHANGED
@@ -15,18 +15,48 @@ module Chronological
|
|
15
15
|
columns_hash[strategy.field_names[:ending_date].to_s] ||= ActiveRecord::ConnectionAdapters::Column.new(strategy.field_names[:ending_date], nil, 'date')
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
define_method(strategy.field_names[:starting_time]) do
|
20
|
-
|
18
|
+
if strategy.has_absolute_start?
|
19
|
+
define_method(strategy.field_names[:starting_time]) do |*args|
|
20
|
+
super()
|
21
|
+
end
|
22
|
+
else
|
23
|
+
define_method(strategy.field_names[:starting_time]) do |*args|
|
24
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
25
|
+
|
26
|
+
strategy.starting_time(self, options)
|
21
27
|
end
|
22
28
|
end
|
23
29
|
|
24
|
-
|
25
|
-
define_method(strategy.field_names[:ending_time]) do
|
26
|
-
|
30
|
+
if strategy.has_absolute_end?
|
31
|
+
define_method(strategy.field_names[:ending_time]) do |*args|
|
32
|
+
super()
|
33
|
+
end
|
34
|
+
else
|
35
|
+
define_method(strategy.field_names[:ending_time]) do |*args|
|
36
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
37
|
+
|
38
|
+
strategy.ending_time(self, options)
|
27
39
|
end
|
28
40
|
end
|
29
41
|
|
42
|
+
define_method(:started?) do |*args|
|
43
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
44
|
+
|
45
|
+
strategy.started?(self, options)
|
46
|
+
end
|
47
|
+
|
48
|
+
define_method(:ended?) do |*args|
|
49
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
50
|
+
|
51
|
+
strategy.ended?(self, options)
|
52
|
+
end
|
53
|
+
|
54
|
+
define_method(:not_yet_ended?) do |*args|
|
55
|
+
options = args.last.is_a?(Hash) ? args.last : {}
|
56
|
+
|
57
|
+
strategy.not_yet_ended?(self, options)
|
58
|
+
end
|
59
|
+
|
30
60
|
define_method(:scheduled?) do
|
31
61
|
strategy.scheduled?(self)
|
32
62
|
end
|
@@ -407,6 +407,36 @@ describe Chronological::AbsoluteStrategy, :timecop => true do
|
|
407
407
|
context 'and has already ended' do
|
408
408
|
let(:end_time) { past }
|
409
409
|
|
410
|
+
describe '#started?' do
|
411
|
+
it 'is started when called directly' do
|
412
|
+
chronologicable.should be_started
|
413
|
+
end
|
414
|
+
|
415
|
+
it 'ignores any passed in base time' do
|
416
|
+
chronologicable.should be_started(:base_of => 100.years.from_now)
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
describe '#ended?' do
|
421
|
+
it 'is ended when called directly' do
|
422
|
+
chronologicable.should be_ended
|
423
|
+
end
|
424
|
+
|
425
|
+
it 'ignores any passed in base time' do
|
426
|
+
chronologicable.should be_ended(:base_of => 100.years.from_now)
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
describe '#not_yet_ended?' do
|
431
|
+
it 'is not_yet_ended when called directly' do
|
432
|
+
chronologicable.should_not be_not_yet_ended
|
433
|
+
end
|
434
|
+
|
435
|
+
it 'ignores any passed in base time' do
|
436
|
+
chronologicable.should_not be_not_yet_ended(:base_of => 100.years.from_now)
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
410
440
|
describe '.in_progress?' do
|
411
441
|
it 'is false' do
|
412
442
|
AbsoluteChronologicable.should_not be_in_progress
|
@@ -441,6 +471,36 @@ describe Chronological::AbsoluteStrategy, :timecop => true do
|
|
441
471
|
context 'and ends now' do
|
442
472
|
let(:end_time) { now }
|
443
473
|
|
474
|
+
describe '#started?' do
|
475
|
+
it 'is started when called directly' do
|
476
|
+
chronologicable.should be_started
|
477
|
+
end
|
478
|
+
|
479
|
+
it 'ignores any passed in base time' do
|
480
|
+
chronologicable.should be_started(:base_of => 100.years.from_now)
|
481
|
+
end
|
482
|
+
end
|
483
|
+
|
484
|
+
describe '#ended?' do
|
485
|
+
it 'is ended when called directly' do
|
486
|
+
chronologicable.should be_ended
|
487
|
+
end
|
488
|
+
|
489
|
+
it 'ignores any passed in base time' do
|
490
|
+
chronologicable.should be_ended(:base_of => 100.years.from_now)
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
describe '#not_yet_ended?' do
|
495
|
+
it 'is not_yet_ended when called directly' do
|
496
|
+
chronologicable.should_not be_not_yet_ended
|
497
|
+
end
|
498
|
+
|
499
|
+
it 'ignores any passed in base time' do
|
500
|
+
chronologicable.should_not be_not_yet_ended(:base_of => 100.years.from_now)
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
444
504
|
describe '.in_progress?' do
|
445
505
|
it 'is false' do
|
446
506
|
AbsoluteChronologicable.should_not be_in_progress
|
@@ -475,6 +535,36 @@ describe Chronological::AbsoluteStrategy, :timecop => true do
|
|
475
535
|
context 'and ends later' do
|
476
536
|
let(:end_time) { later }
|
477
537
|
|
538
|
+
describe '#started?' do
|
539
|
+
it 'is started when called directly' do
|
540
|
+
chronologicable.should be_started
|
541
|
+
end
|
542
|
+
|
543
|
+
it 'ignores any passed in base time' do
|
544
|
+
chronologicable.should be_started(:base_of => 100.years.from_now)
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
describe '#ended?' do
|
549
|
+
it 'is ended when called directly' do
|
550
|
+
chronologicable.should_not be_ended
|
551
|
+
end
|
552
|
+
|
553
|
+
it 'ignores any passed in base time' do
|
554
|
+
chronologicable.should_not be_ended(:base_of => 100.years.ago)
|
555
|
+
end
|
556
|
+
end
|
557
|
+
|
558
|
+
describe '#not_yet_ended?' do
|
559
|
+
it 'is not_yet_ended when called directly' do
|
560
|
+
chronologicable.should be_not_yet_ended
|
561
|
+
end
|
562
|
+
|
563
|
+
it 'ignores any passed in base time' do
|
564
|
+
chronologicable.should be_not_yet_ended(:base_of => 100.years.ago)
|
565
|
+
end
|
566
|
+
end
|
567
|
+
|
478
568
|
describe '.in_progress?' do
|
479
569
|
it 'is true' do
|
480
570
|
AbsoluteChronologicable.should be_in_progress
|
@@ -513,6 +603,36 @@ describe Chronological::AbsoluteStrategy, :timecop => true do
|
|
513
603
|
context 'and ends now' do
|
514
604
|
let(:end_time) { now }
|
515
605
|
|
606
|
+
describe '#started?' do
|
607
|
+
it 'is started when called directly' do
|
608
|
+
chronologicable.should be_started
|
609
|
+
end
|
610
|
+
|
611
|
+
it 'ignores any passed in base time' do
|
612
|
+
chronologicable.should be_started(:base_of => 100.years.from_now)
|
613
|
+
end
|
614
|
+
end
|
615
|
+
|
616
|
+
describe '#ended?' do
|
617
|
+
it 'is ended when called directly' do
|
618
|
+
chronologicable.should be_ended
|
619
|
+
end
|
620
|
+
|
621
|
+
it 'ignores any passed in base time' do
|
622
|
+
chronologicable.should be_ended(:base_of => 100.years.from_now)
|
623
|
+
end
|
624
|
+
end
|
625
|
+
|
626
|
+
describe '#not_yet_ended?' do
|
627
|
+
it 'is not_yet_ended when called directly' do
|
628
|
+
chronologicable.should_not be_not_yet_ended
|
629
|
+
end
|
630
|
+
|
631
|
+
it 'ignores any passed in base time' do
|
632
|
+
chronologicable.should_not be_not_yet_ended(:base_of => 100.years.from_now)
|
633
|
+
end
|
634
|
+
end
|
635
|
+
|
516
636
|
describe '.in_progress?' do
|
517
637
|
it 'is false' do
|
518
638
|
AbsoluteChronologicable.should_not be_in_progress
|
@@ -547,6 +667,36 @@ describe Chronological::AbsoluteStrategy, :timecop => true do
|
|
547
667
|
context 'and ends later' do
|
548
668
|
let(:end_time) { later }
|
549
669
|
|
670
|
+
describe '#started?' do
|
671
|
+
it 'is started when called directly' do
|
672
|
+
chronologicable.should be_started
|
673
|
+
end
|
674
|
+
|
675
|
+
it 'ignores any passed in base time' do
|
676
|
+
chronologicable.should be_started(:base_of => 100.years.from_now)
|
677
|
+
end
|
678
|
+
end
|
679
|
+
|
680
|
+
describe '#ended?' do
|
681
|
+
it 'is ended when called directly' do
|
682
|
+
chronologicable.should_not be_ended
|
683
|
+
end
|
684
|
+
|
685
|
+
it 'ignores any passed in base time' do
|
686
|
+
chronologicable.should_not be_ended(:base_of => 100.years.ago)
|
687
|
+
end
|
688
|
+
end
|
689
|
+
|
690
|
+
describe '#not_yet_ended?' do
|
691
|
+
it 'is not_yet_ended when called directly' do
|
692
|
+
chronologicable.should be_not_yet_ended
|
693
|
+
end
|
694
|
+
|
695
|
+
it 'ignores any passed in base time' do
|
696
|
+
chronologicable.should be_not_yet_ended(:base_of => 100.years.ago)
|
697
|
+
end
|
698
|
+
end
|
699
|
+
|
550
700
|
describe '.in_progress?' do
|
551
701
|
it 'is true' do
|
552
702
|
AbsoluteChronologicable.should be_in_progress
|
@@ -583,6 +733,36 @@ describe Chronological::AbsoluteStrategy, :timecop => true do
|
|
583
733
|
let(:start_time) { later }
|
584
734
|
let(:end_time) { later }
|
585
735
|
|
736
|
+
describe '#started?' do
|
737
|
+
it 'is started when called directly' do
|
738
|
+
chronologicable.should_not be_started
|
739
|
+
end
|
740
|
+
|
741
|
+
it 'ignores any passed in base time' do
|
742
|
+
chronologicable.should_not be_started(:base_of => 100.years.ago)
|
743
|
+
end
|
744
|
+
end
|
745
|
+
|
746
|
+
describe '#ended?' do
|
747
|
+
it 'is ended when called directly' do
|
748
|
+
chronologicable.should_not be_ended
|
749
|
+
end
|
750
|
+
|
751
|
+
it 'ignores any passed in base time' do
|
752
|
+
chronologicable.should_not be_ended(:base_of => 100.years.ago)
|
753
|
+
end
|
754
|
+
end
|
755
|
+
|
756
|
+
describe '#not_yet_ended?' do
|
757
|
+
it 'is not_yet_ended when called directly' do
|
758
|
+
chronologicable.should be_not_yet_ended
|
759
|
+
end
|
760
|
+
|
761
|
+
it 'ignores any passed in base time' do
|
762
|
+
chronologicable.should be_not_yet_ended(:base_of => 100.years.ago)
|
763
|
+
end
|
764
|
+
end
|
765
|
+
|
586
766
|
describe '.in_progress?' do
|
587
767
|
it 'is false' do
|
588
768
|
AbsoluteChronologicable.should_not be_in_progress
|
@@ -376,9 +376,13 @@ describe Chronological::RelativeStrategy, :timecop => true do
|
|
376
376
|
end
|
377
377
|
end
|
378
378
|
|
379
|
-
it 'does not have a start time' do
|
379
|
+
it 'does not have a start time when called directly' do
|
380
380
|
chronologicable.started_at.should be_nil
|
381
381
|
end
|
382
|
+
|
383
|
+
it 'has the proper start time when a base is passed in' do
|
384
|
+
chronologicable.started_at(:base_of => Time.local(2012, 7, 26, 12, 0, 0)).should eql Time.local(2012, 7, 26, 11, 59, 30)
|
385
|
+
end
|
382
386
|
end
|
383
387
|
|
384
388
|
context 'and the starting offset is not set' do
|
@@ -468,25 +472,37 @@ describe Chronological::RelativeStrategy, :timecop => true do
|
|
468
472
|
end
|
469
473
|
end
|
470
474
|
|
471
|
-
it 'does not have a start time' do
|
475
|
+
it 'does not have a start time when called directly' do
|
472
476
|
chronologicable.started_at.should be_nil
|
473
477
|
end
|
478
|
+
|
479
|
+
it 'does not have a start time when a base is passed in' do
|
480
|
+
chronologicable.started_at(:base_of => Time.local(2012, 7, 26, 12, 0, 0)).should be_nil
|
481
|
+
end
|
474
482
|
end
|
475
483
|
|
476
484
|
context 'and the ending offset is set' do
|
477
485
|
let(:ending_offset) { 0 }
|
478
486
|
|
479
|
-
it 'does not have an end time' do
|
487
|
+
it 'does not have an end time when called directly' do
|
480
488
|
chronologicable.ended_at.should be_nil
|
481
489
|
end
|
490
|
+
|
491
|
+
it 'calculates the correct end time when a base is passed in' do
|
492
|
+
chronologicable.ended_at(:base_of => Time.local(2012, 7, 26, 12, 0, 0)).should eql Time.local(2012, 7, 26, 12, 0, 0)
|
493
|
+
end
|
482
494
|
end
|
483
495
|
|
484
496
|
context 'and the ending offset is not set' do
|
485
497
|
let(:ending_offset) { nil }
|
486
498
|
|
487
|
-
it 'does not have an end time' do
|
499
|
+
it 'does not have an end time when called directly' do
|
488
500
|
chronologicable.ended_at.should be_nil
|
489
501
|
end
|
502
|
+
|
503
|
+
it 'does not have an end time when a base is passed in' do
|
504
|
+
chronologicable.ended_at(:base_of => Time.local(2012, 7, 26, 12, 0, 0)).should be_nil
|
505
|
+
end
|
490
506
|
end
|
491
507
|
|
492
508
|
context 'and neither of the offsets is set' do
|
@@ -750,9 +766,13 @@ describe Chronological::RelativeStrategy, :timecop => true do
|
|
750
766
|
end
|
751
767
|
end
|
752
768
|
|
753
|
-
it 'does not have a start time' do
|
769
|
+
it 'does not have a start time when called directly' do
|
754
770
|
chronologicable.started_at.should be_nil
|
755
771
|
end
|
772
|
+
|
773
|
+
it 'does not have a start time when a base is passed in' do
|
774
|
+
chronologicable.started_at(:base_of => Time.local(2012, 7, 26, 12, 0, 0)).should be_nil
|
775
|
+
end
|
756
776
|
end
|
757
777
|
|
758
778
|
context 'when the starting offset is set' do
|
@@ -926,25 +946,37 @@ describe Chronological::RelativeStrategy, :timecop => true do
|
|
926
946
|
end
|
927
947
|
end
|
928
948
|
|
929
|
-
it 'calculates the correct start time' do
|
949
|
+
it 'calculates the correct start time when called directly' do
|
930
950
|
chronologicable.started_at.should eql Time.local(2012, 7, 26, 6, 0, 0)
|
931
951
|
end
|
952
|
+
|
953
|
+
it 'calculates the correct start time when a base is passed in' do
|
954
|
+
chronologicable.started_at(:base_of => Time.local(2012, 7, 26, 12, 0, 0)).should eql Time.local(2012, 7, 26, 11, 59, 30)
|
955
|
+
end
|
932
956
|
end
|
933
957
|
|
934
958
|
context 'and the ending offset is set' do
|
935
959
|
let(:ending_offset) { 30 }
|
936
960
|
|
937
|
-
it 'calculates the correct end time' do
|
961
|
+
it 'calculates the correct end time when called directly' do
|
938
962
|
chronologicable.ended_at.should eql Time.local(2012, 7, 26, 6, 0, 0)
|
939
963
|
end
|
964
|
+
|
965
|
+
it 'calculates the correct end time when a base is passed in' do
|
966
|
+
chronologicable.ended_at(:base_of => Time.local(2012, 7, 26, 12, 0, 0)).should eql Time.local(2012, 7, 26, 11, 59, 30)
|
967
|
+
end
|
940
968
|
end
|
941
969
|
|
942
970
|
context 'and the ending offset is not set' do
|
943
971
|
let(:ending_offset) { nil }
|
944
972
|
|
945
|
-
it 'does not have a end time' do
|
973
|
+
it 'does not have a end time when called directly' do
|
946
974
|
chronologicable.ended_at.should be_nil
|
947
975
|
end
|
976
|
+
|
977
|
+
it 'does not have an end time when a base is passed in' do
|
978
|
+
chronologicable.ended_at(:base_of => Time.local(2012, 7, 26, 12, 0, 0)).should be_nil
|
979
|
+
end
|
948
980
|
end
|
949
981
|
end
|
950
982
|
|
@@ -956,6 +988,30 @@ describe Chronological::RelativeStrategy, :timecop => true do
|
|
956
988
|
context 'and before the ending offset' do
|
957
989
|
let(:ending_offset) { 30 }
|
958
990
|
|
991
|
+
it 'is not started when called directly' do
|
992
|
+
chronologicable.should_not be_started
|
993
|
+
end
|
994
|
+
|
995
|
+
it 'is started if the base time is overridden to a time before the offset plus "now"' do
|
996
|
+
chronologicable.should be_started(:base_of => Time.local(2012, 7, 26, 6, 0, 29))
|
997
|
+
end
|
998
|
+
|
999
|
+
it 'is not ended when called directly' do
|
1000
|
+
chronologicable.should_not be_ended
|
1001
|
+
end
|
1002
|
+
|
1003
|
+
it 'is ended if the base time is overridden to a time on or after the offset plus "now"' do
|
1004
|
+
chronologicable.should be_ended(:base_of => Time.local(2012, 7, 26, 6, 0, 29))
|
1005
|
+
end
|
1006
|
+
|
1007
|
+
it 'is not yet ended when called directly' do
|
1008
|
+
chronologicable.should be_not_yet_ended
|
1009
|
+
end
|
1010
|
+
|
1011
|
+
it 'is not not yet ended if the base time is overridden to a time on or after the offset plus "now"' do
|
1012
|
+
chronologicable.should_not be_not_yet_ended(:base_of => Time.local(2012, 7, 26, 6, 0, 29))
|
1013
|
+
end
|
1014
|
+
|
959
1015
|
it 'is not included in the started list' do
|
960
1016
|
RelativeChronologicable.started.should_not include chronologicable
|
961
1017
|
end
|
@@ -979,13 +1035,37 @@ describe Chronological::RelativeStrategy, :timecop => true do
|
|
979
1035
|
end
|
980
1036
|
|
981
1037
|
context 'when it is currently a time the same as the starting offset' do
|
982
|
-
let(:now) { Time.local(2012, 7, 26, 6,
|
1038
|
+
let(:now) { Time.local(2012, 7, 26, 6, 0, 0) }
|
983
1039
|
let(:base_time) { Time.local(2012, 7, 26, 6, 0, 30) }
|
984
1040
|
let(:starting_offset) { 30 }
|
985
1041
|
|
986
1042
|
context 'and before the ending offset' do
|
987
1043
|
let(:ending_offset) { 29 }
|
988
1044
|
|
1045
|
+
it 'is not started when called directly' do
|
1046
|
+
chronologicable.should be_started
|
1047
|
+
end
|
1048
|
+
|
1049
|
+
it 'is not started if the base time is overridden to a time after the offset plus "now"' do
|
1050
|
+
chronologicable.should_not be_started(:base_of => Time.local(2012, 7, 26, 6, 0, 31))
|
1051
|
+
end
|
1052
|
+
|
1053
|
+
it 'is not ended when called directly' do
|
1054
|
+
chronologicable.should_not be_ended
|
1055
|
+
end
|
1056
|
+
|
1057
|
+
it 'is ended if the base time is overridden to a time on or after the offset plus "now"' do
|
1058
|
+
chronologicable.should be_ended(:base_of => Time.local(2012, 7, 26, 6, 0, 29))
|
1059
|
+
end
|
1060
|
+
|
1061
|
+
it 'is not yet ended when called directly' do
|
1062
|
+
chronologicable.should be_not_yet_ended
|
1063
|
+
end
|
1064
|
+
|
1065
|
+
it 'is not not yet ended if the base time is overridden to a time on or after the offset plus "now"' do
|
1066
|
+
chronologicable.should_not be_not_yet_ended(:base_of => Time.local(2012, 7, 26, 6, 0, 29))
|
1067
|
+
end
|
1068
|
+
|
989
1069
|
it 'is included in the started list' do
|
990
1070
|
RelativeChronologicable.started.should include chronologicable
|
991
1071
|
end
|
@@ -1010,6 +1090,30 @@ describe Chronological::RelativeStrategy, :timecop => true do
|
|
1010
1090
|
context 'and the same as the ending offset' do
|
1011
1091
|
let(:ending_offset) { 30 }
|
1012
1092
|
|
1093
|
+
it 'is not started when called directly' do
|
1094
|
+
chronologicable.should be_started
|
1095
|
+
end
|
1096
|
+
|
1097
|
+
it 'is not started if the base time is overridden to a time after the offset plus "now"' do
|
1098
|
+
chronologicable.should_not be_started(:base_of => Time.local(2012, 7, 26, 6, 0, 31))
|
1099
|
+
end
|
1100
|
+
|
1101
|
+
it 'is not ended when called directly' do
|
1102
|
+
chronologicable.should be_ended
|
1103
|
+
end
|
1104
|
+
|
1105
|
+
it 'is ended if the base time is overridden to a time on or after the offset plus "now"' do
|
1106
|
+
chronologicable.should_not be_ended(:base_of => Time.local(2012, 7, 26, 6, 0, 31))
|
1107
|
+
end
|
1108
|
+
|
1109
|
+
it 'is not yet ended when called directly' do
|
1110
|
+
chronologicable.should_not be_not_yet_ended
|
1111
|
+
end
|
1112
|
+
|
1113
|
+
it 'is not not yet ended if the base time is overridden to a time on or after the offset plus "now"' do
|
1114
|
+
chronologicable.should be_not_yet_ended(:base_of => Time.local(2012, 7, 26, 6, 0, 31))
|
1115
|
+
end
|
1116
|
+
|
1013
1117
|
it 'is included in the started list' do
|
1014
1118
|
RelativeChronologicable.started.should include chronologicable
|
1015
1119
|
end
|
@@ -1033,13 +1137,37 @@ describe Chronological::RelativeStrategy, :timecop => true do
|
|
1033
1137
|
end
|
1034
1138
|
|
1035
1139
|
context 'when it is currently a time after the starting offset' do
|
1036
|
-
let(:now) { Time.local(2012, 7, 26, 6,
|
1140
|
+
let(:now) { Time.local(2012, 7, 26, 6, 0, 2) }
|
1037
1141
|
let(:base_time) { Time.local(2012, 7, 26, 6, 0, 30) }
|
1038
1142
|
let(:starting_offset) { 30 }
|
1039
1143
|
|
1040
1144
|
context 'and before the ending offset' do
|
1041
1145
|
let(:ending_offset) { 27 }
|
1042
1146
|
|
1147
|
+
it 'is not started when called directly' do
|
1148
|
+
chronologicable.should be_started
|
1149
|
+
end
|
1150
|
+
|
1151
|
+
it 'is not started if the base time is overridden to a time after the offset plus "now"' do
|
1152
|
+
chronologicable.should_not be_started(:base_of => Time.local(2012, 7, 26, 6, 0, 33))
|
1153
|
+
end
|
1154
|
+
|
1155
|
+
it 'is not ended when called directly' do
|
1156
|
+
chronologicable.should_not be_ended
|
1157
|
+
end
|
1158
|
+
|
1159
|
+
it 'is ended if the base time is overridden to a time on or after the offset plus "now"' do
|
1160
|
+
chronologicable.should be_ended(:base_of => Time.local(2012, 7, 26, 6, 0, 29))
|
1161
|
+
end
|
1162
|
+
|
1163
|
+
it 'is not yet ended when called directly' do
|
1164
|
+
chronologicable.should be_not_yet_ended
|
1165
|
+
end
|
1166
|
+
|
1167
|
+
it 'is not not yet ended if the base time is overridden to a time on or after the offset plus "now"' do
|
1168
|
+
chronologicable.should_not be_not_yet_ended(:base_of => Time.local(2012, 7, 26, 6, 0, 29))
|
1169
|
+
end
|
1170
|
+
|
1043
1171
|
it 'is included in the started list' do
|
1044
1172
|
RelativeChronologicable.started.should include chronologicable
|
1045
1173
|
end
|
@@ -1064,6 +1192,30 @@ describe Chronological::RelativeStrategy, :timecop => true do
|
|
1064
1192
|
context 'and the same as the ending offset' do
|
1065
1193
|
let(:ending_offset) { 28 }
|
1066
1194
|
|
1195
|
+
it 'is not started when called directly' do
|
1196
|
+
chronologicable.should be_started
|
1197
|
+
end
|
1198
|
+
|
1199
|
+
it 'is not started if the base time is overridden to a time after the offset plus "now"' do
|
1200
|
+
chronologicable.should_not be_started(:base_of => Time.local(2012, 7, 26, 6, 0, 33))
|
1201
|
+
end
|
1202
|
+
|
1203
|
+
it 'is not ended when called directly' do
|
1204
|
+
chronologicable.should be_ended
|
1205
|
+
end
|
1206
|
+
|
1207
|
+
it 'is ended if the base time is overridden to a time on or after the offset plus "now"' do
|
1208
|
+
chronologicable.should_not be_ended(:base_of => Time.local(2012, 7, 26, 6, 0, 31))
|
1209
|
+
end
|
1210
|
+
|
1211
|
+
it 'is not yet ended when called directly' do
|
1212
|
+
chronologicable.should_not be_not_yet_ended
|
1213
|
+
end
|
1214
|
+
|
1215
|
+
it 'is not not yet ended if the base time is overridden to a time on or after the offset plus "now"' do
|
1216
|
+
chronologicable.should be_not_yet_ended(:base_of => Time.local(2012, 7, 26, 6, 0, 31))
|
1217
|
+
end
|
1218
|
+
|
1067
1219
|
it 'is included in the started list' do
|
1068
1220
|
RelativeChronologicable.started.should include chronologicable
|
1069
1221
|
end
|
@@ -1088,6 +1240,30 @@ describe Chronological::RelativeStrategy, :timecop => true do
|
|
1088
1240
|
context 'and after the ending offset' do
|
1089
1241
|
let(:ending_offset) { 29 }
|
1090
1242
|
|
1243
|
+
it 'is not started when called directly' do
|
1244
|
+
chronologicable.should be_started
|
1245
|
+
end
|
1246
|
+
|
1247
|
+
it 'is not started if the base time is overridden to a time after the offset plus "now"' do
|
1248
|
+
chronologicable.should_not be_started(:base_of => Time.local(2012, 7, 26, 6, 0, 33))
|
1249
|
+
end
|
1250
|
+
|
1251
|
+
it 'is not ended when called directly' do
|
1252
|
+
chronologicable.should be_ended
|
1253
|
+
end
|
1254
|
+
|
1255
|
+
it 'is ended if the base time is overridden to a time on or after the offset plus "now"' do
|
1256
|
+
chronologicable.should_not be_ended(:base_of => Time.local(2012, 7, 26, 6, 0, 32))
|
1257
|
+
end
|
1258
|
+
|
1259
|
+
it 'is not yet ended when called directly' do
|
1260
|
+
chronologicable.should_not be_not_yet_ended
|
1261
|
+
end
|
1262
|
+
|
1263
|
+
it 'is not not yet ended if the base time is overridden to a time on or after the offset plus "now"' do
|
1264
|
+
chronologicable.should be_not_yet_ended(:base_of => Time.local(2012, 7, 26, 6, 0, 32))
|
1265
|
+
end
|
1266
|
+
|
1091
1267
|
it 'is included in the started list' do
|
1092
1268
|
RelativeChronologicable.started.should include chronologicable
|
1093
1269
|
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: 1.0.
|
4
|
+
version: 1.0.0beta7
|
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-
|
13
|
+
date: 2012-11-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|