dgp-schedule_attributes 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/CODE_OF_CONDUCT.md +22 -0
- data/Gemfile.lock +31 -17
- data/gemfiles/rails_3.2.gemfile.lock +7 -0
- data/gemfiles/rails_4.0.gemfile.lock +7 -0
- data/gemfiles/rails_4.1.gemfile.lock +7 -0
- data/gemfiles/rails_4.2.gemfile.lock +7 -0
- data/gemfiles/rails_edge.gemfile.lock +7 -0
- data/lib/schedule_attributes/core.rb +18 -0
- data/lib/schedule_attributes/input.rb +7 -2
- data/lib/schedule_attributes/version.rb +1 -1
- data/schedule_attributes.gemspec +1 -0
- data/spec/active_record_integration_spec.rb +11 -10
- data/spec/schedule_attributes/configuration_spec.rb +4 -4
- data/spec/schedule_attributes/input_spec.rb +34 -34
- data/spec/schedule_attributes/rule_parser/day_spec.rb +21 -21
- data/spec/schedule_attributes/rule_parser/month_spec.rb +9 -9
- data/spec/schedule_attributes/rule_parser/week_spec.rb +6 -6
- data/spec/schedule_attributes/rule_parser/year_spec.rb +10 -10
- data/spec/schedule_attributes/rule_parser_spec.rb +1 -1
- data/spec/schedule_attributes/time_helpers_spec.rb +5 -5
- data/spec/schedule_attributes_spec.rb +63 -63
- data/spec/spec_helper.rb +6 -2
- data/spec/support/parser_macros.rb +0 -4
- metadata +17 -1
@@ -14,46 +14,46 @@ describe ScheduleAttributes::RuleParser::Day do
|
|
14
14
|
context 'no arguments', args: {} do
|
15
15
|
let(:every_day) { [t, t+1.day, t+2.days, t+3.days, t+4.days, t+5.days, t+6.days, t+7.days, t+8.days] }
|
16
16
|
|
17
|
-
it {
|
18
|
-
its_occurrences_until(8.days.from_now) {
|
17
|
+
it { is_expected.to eq(IceCube::Rule.daily) }
|
18
|
+
its_occurrences_until(8.days.from_now) { is_expected.to eq(every_day) }
|
19
19
|
end
|
20
20
|
|
21
21
|
context 'interval argument', args: {interval: 2} do
|
22
22
|
let(:every_other_day) { [t, t+2.days, t+4.days, t+6.days, t+8.days] }
|
23
23
|
|
24
|
-
it {
|
25
|
-
its_occurrences_until(8.days.from_now) {
|
24
|
+
it { is_expected.to eq(IceCube::Rule.daily(2)) }
|
25
|
+
its_occurrences_until(8.days.from_now) { is_expected.to eq(every_other_day) }
|
26
26
|
end
|
27
27
|
|
28
28
|
context 'end_date argument', args: {end_date: '2014-01-30'} do
|
29
29
|
let(:t) { Time.new(2014,01,30) }
|
30
30
|
let(:last_5_days) { [t-4.days, t-3.days, t-2.days, t-1.day, t] }
|
31
31
|
|
32
|
-
it {
|
33
|
-
its_occurrences_until(Time.new(2014,02,01)) { subject[-5..-1].
|
32
|
+
it { is_expected.to eq(IceCube::Rule.daily.until(t)) }
|
33
|
+
its_occurrences_until(Time.new(2014,02,01)) { expect(subject[-5..-1]).to eq last_5_days }
|
34
34
|
end
|
35
35
|
|
36
36
|
context 'yearly_start_month and yearly_end_month arguments, whole year', args: {yearly_start_month: 1, yearly_end_month: 12} do
|
37
|
-
it {
|
37
|
+
it { is_expected.to eq(IceCube::Rule.daily) }
|
38
38
|
end
|
39
39
|
|
40
40
|
context 'yearly_start_month and yearly_end_month arguments, less than a year', args: {yearly_start_month: 6, yearly_end_month: 8} do
|
41
|
-
it {
|
41
|
+
it { is_expected.to eq(IceCube::Rule.daily.month_of_year(6,7,8)) }
|
42
42
|
end
|
43
43
|
|
44
44
|
context 'yearly_start_month and yearly_end_month arguments, jump year', args: {yearly_start_month: 11, yearly_end_month: 1} do
|
45
|
-
it {
|
45
|
+
it { is_expected.to eq(IceCube::Rule.daily.month_of_year(11,12,1)) }
|
46
46
|
end
|
47
47
|
|
48
48
|
context 'yearly_start_month and yearly_end_month arguments, jump year alt', args: {yearly_start_month: 12, yearly_end_month: 2} do
|
49
|
-
it {
|
49
|
+
it { is_expected.to eq(IceCube::Rule.daily.month_of_year(12,1,2)) }
|
50
50
|
end
|
51
51
|
|
52
52
|
context 'yearly_start_month, yearly_start_month_day, yearly_end_month and yearly_end_month_day arguments', args: {
|
53
53
|
yearly_start_month: 3, yearly_start_month_day: 14,
|
54
54
|
yearly_end_month: 3, yearly_end_month_day: 17
|
55
55
|
} do
|
56
|
-
it {
|
56
|
+
it { is_expected.to eq(IceCube::Rule.daily.month_of_year(3)) }
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
@@ -65,48 +65,48 @@ describe ScheduleAttributes::RuleParser::Day do
|
|
65
65
|
yearly_end_month: 3, yearly_end_month_day: 26
|
66
66
|
} do
|
67
67
|
it "returns exceptions for the leading & trailing days" do
|
68
|
-
|
68
|
+
is_expected.to eq([
|
69
69
|
IceCube::Rule.daily.month_of_year(3).day_of_month(*1..3),
|
70
70
|
IceCube::Rule.daily.month_of_year(3).day_of_month(*27..31)
|
71
|
-
]
|
71
|
+
])
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
75
|
context 'yearly_start_month and yearly_end_month arguments', args: {yearly_start_month: 3, yearly_end_month: 3} do
|
76
76
|
it "has no trailing exceptions" do
|
77
|
-
|
77
|
+
is_expected.to eq([])
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
context 'yearly_start_month, yearly_end_month and yearly_end_month_day arguments', args: {yearly_start_month: 3, yearly_end_month: 4, yearly_end_month_day: 25} do
|
82
82
|
it "returns exceptions for the trailing days of the last month only" do
|
83
|
-
|
83
|
+
is_expected.to eq([IceCube::Rule.daily.month_of_year(4).day_of_month(*26..31)])
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
87
|
context 'yearly_start_month, yearly_start_month_day and yearly_end_month arguments', args: {yearly_start_month: 3, yearly_start_month_day: 3, yearly_end_month: 4} do
|
88
88
|
it "returns exceptions for the leading days of the first month" do
|
89
|
-
|
89
|
+
is_expected.to eq([
|
90
90
|
IceCube::Rule.daily.month_of_year(3).day_of_month(*1..2)
|
91
|
-
]
|
91
|
+
])
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
95
|
context 'yearly_start_month, yearly_end_month, yearly_start_month_day and yearly_end_month_day arguments', args: {yearly_start_month: 3, yearly_end_month: 4, yearly_start_month_day: 31, yearly_end_month_day: 1} do
|
96
96
|
it "excepts the first 30 days of first month and last 30 days of last month" do
|
97
|
-
|
97
|
+
is_expected.to eq([
|
98
98
|
IceCube::Rule.daily.month_of_year(3).day_of_month(*1..30),
|
99
99
|
IceCube::Rule.daily.month_of_year(4).day_of_month(*2..31)
|
100
|
-
]
|
100
|
+
])
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
104
|
context 'yearly_start_month, yearly_end_month, yearly_start_month_day and yearly_end_month_day arguments', args: {yearly_start_month: 12, yearly_end_month: 1, yearly_start_month_day: 31, yearly_end_month_day: 1} do
|
105
105
|
it "excepts the first 30 days of first month and last 30 days of last month" do
|
106
|
-
|
106
|
+
is_expected.to eq([
|
107
107
|
IceCube::Rule.daily.month_of_year(12).day_of_month(*1..30),
|
108
108
|
IceCube::Rule.daily.month_of_year(1).day_of_month(*2..31)
|
109
|
-
]
|
109
|
+
])
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
@@ -18,30 +18,30 @@ describe ScheduleAttributes::RuleParser::Month do
|
|
18
18
|
let(:every_14th) { [n, n >> 1, n >> 2, n >> 3].map(&:to_time) }
|
19
19
|
|
20
20
|
context 'no arguments', args: {} do
|
21
|
-
it {
|
22
|
-
its_occurrences_until(3.months.from_now) {
|
21
|
+
it { is_expected.to eq(IceCube::Rule.monthly) }
|
22
|
+
its_occurrences_until(3.months.from_now) { is_expected.to eq(monthly) }
|
23
23
|
end
|
24
24
|
|
25
25
|
context 'start_date and interval arguments', args: {"start_date" => "2000-03-14", "interval" => "2"} do
|
26
|
-
it {
|
27
|
-
its_occurrences_until(6.months.from_now) {
|
26
|
+
it { is_expected.to eq(IceCube::Rule.monthly(2)) }
|
27
|
+
its_occurrences_until(6.months.from_now) { is_expected.to eq(bimonthly) }
|
28
28
|
end
|
29
29
|
|
30
30
|
context 'ordinal_unit and ordinal_day arguments', args: {"ordinal_unit" => "day", "ordinal_day" => "14"} do
|
31
|
-
it {
|
32
|
-
its_occurrences_until(4.months.from_now) {
|
31
|
+
it { is_expected.to eq(IceCube::Rule.monthly.day_of_month(14)) }
|
32
|
+
its_occurrences_until(4.months.from_now) { is_expected.to eq(every_14th) }
|
33
33
|
end
|
34
34
|
|
35
35
|
context 'ordinal_unit, ordinal_week and tuesday arguments', args: {"ordinal_unit" => "week", "ordinal_week" => "2", "tuesday" => "1"} do
|
36
|
-
it {
|
36
|
+
it { is_expected.to eq(IceCube::Rule.monthly.day_of_week(:tuesday => [2])) }
|
37
37
|
end
|
38
38
|
|
39
39
|
context 'ordinal_unit and ordinal_week arguments', args: {"ordinal_unit" => "week", "ordinal_week" => "2"} do
|
40
|
-
it {
|
40
|
+
it { is_expected.to eq(IceCube::Rule.monthly.day_of_week(0=>(w=[2]), 1=>w, 2=>w, 3=>w, 4=>w, 5=>w, 6=>w)) }
|
41
41
|
end
|
42
42
|
|
43
43
|
context 'start_date and end_date arguments', args: {"start_date" => "2000-03-14", "end_date" => "2000-06-14"} do
|
44
|
-
it {
|
44
|
+
it { is_expected.to eq(IceCube::Rule.monthly.until(Time.new(2000,6,14))) }
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -19,18 +19,18 @@ describe ScheduleAttributes::RuleParser::Week do
|
|
19
19
|
subject { parser.rule }
|
20
20
|
|
21
21
|
context 'no arguments', args: {} do
|
22
|
-
it {
|
23
|
-
its_occurrences_until(5.weeks.from_now) {
|
22
|
+
it { is_expected.to eq(IceCube::Rule.weekly) }
|
23
|
+
its_occurrences_until(5.weeks.from_now) { is_expected.to eq(weekly) }
|
24
24
|
end
|
25
25
|
|
26
26
|
context 'interval argument', args: {"interval" => "2"} do
|
27
|
-
it {
|
28
|
-
its_occurrences_until(5.weeks.from_now) {
|
27
|
+
it { is_expected.to eq(IceCube::Rule.weekly(2)) }
|
28
|
+
its_occurrences_until(5.weeks.from_now) { is_expected.to eq(every_2_weeks) }
|
29
29
|
end
|
30
30
|
|
31
31
|
context 'several day name arguments', args: {"monday" => "0", "saturday" => "1", "sunday" => "1"} do
|
32
|
-
it {
|
33
|
-
its_occurrences_until(Date.today.beginning_of_week+3.weeks) { subject[-4..-1].
|
32
|
+
it { is_expected.to eq(IceCube::Rule.weekly.day(0,6)) }
|
33
|
+
its_occurrences_until(Date.today.beginning_of_week+3.weeks) { expect(subject[-4..-1]).to eq weekends[-4..-1] }
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -17,26 +17,26 @@ describe ScheduleAttributes::RuleParser::Year do
|
|
17
17
|
subject { parser.rule }
|
18
18
|
|
19
19
|
context 'no arguments', args: {} do
|
20
|
-
it {
|
21
|
-
its_occurrences_until(4.years.from_now) {
|
20
|
+
it { is_expected.to eq(IceCube::Rule.yearly) }
|
21
|
+
its_occurrences_until(4.years.from_now) { is_expected.to eq(every_year) }
|
22
22
|
end
|
23
23
|
|
24
24
|
context 'interval argument', args: {"interval" => "2"} do
|
25
|
-
it {
|
26
|
-
its_occurrences_until(4.years.from_now) {
|
25
|
+
it { is_expected.to eq(IceCube::Rule.yearly(2)) }
|
26
|
+
its_occurrences_until(4.years.from_now) { is_expected.to eq(every_2nd_year) }
|
27
27
|
end
|
28
28
|
|
29
29
|
context 'start_date argument', args: {"start_date" => "2000-03-14"} do
|
30
|
-
it {
|
30
|
+
it { is_expected.to eq(IceCube::Rule.yearly.month_of_year(3).day_of_month(14)) }
|
31
31
|
end
|
32
32
|
|
33
33
|
context 'start_date argument alt', args: {"start_date" => "2000-01-30"} do
|
34
|
-
it {
|
34
|
+
it { is_expected.to eq(IceCube::Rule.yearly.month_of_year(1).day_of_month(30)) }
|
35
35
|
end
|
36
36
|
|
37
37
|
context 'start_date and end_date arguments', args: {"start_date" => "2000-03-14", "end_date" => "#{Date.current.year+4}-03-14"} do
|
38
|
-
it {
|
39
|
-
its_occurrences_until(10.years.from_now) {
|
38
|
+
it { is_expected.to eq(IceCube::Rule.yearly.month_of_year(3).day_of_month(14).until(Date.new(Date.current.year+4,3,14).to_time)) }
|
39
|
+
its_occurrences_until(10.years.from_now) { is_expected.to eq(every_pi_day) }
|
40
40
|
end
|
41
41
|
|
42
42
|
context "ignoring yearly_start and end limits", args: {
|
@@ -46,8 +46,8 @@ describe ScheduleAttributes::RuleParser::Year do
|
|
46
46
|
"yearly_end_month" => "5",
|
47
47
|
"yearly_end_month_day" => "20"
|
48
48
|
} do
|
49
|
-
it {
|
50
|
-
its_occurrences_until(Date.new(Date.current.year+4,12,31)) {
|
49
|
+
it { is_expected.to eq(IceCube::Rule.yearly.month_of_year(3).day_of_month(14)) }
|
50
|
+
its_occurrences_until(Date.new(Date.current.year+4,12,31)) { is_expected.to eq(every_pi_day) }
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -11,7 +11,7 @@ describe ScheduleAttributes::RuleParser do
|
|
11
11
|
}. each do |key,parser_class|
|
12
12
|
|
13
13
|
it "returns parser for #{key} interval units" do
|
14
|
-
ScheduleAttributes::RuleParser[key].
|
14
|
+
expect(ScheduleAttributes::RuleParser[key]).to eq(parser_class)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
@@ -9,17 +9,17 @@ describe ScheduleAttributes::TimeHelpers do
|
|
9
9
|
before { Time.zone = 'UTC' }
|
10
10
|
|
11
11
|
it "returns a time from a date string" do
|
12
|
-
subject.parse_in_zone("2000-12-31").
|
12
|
+
expect(subject.parse_in_zone("2000-12-31")).to eq(Time.zone.parse("2000-12-31"))
|
13
13
|
end
|
14
14
|
|
15
15
|
it "returns a time from a time" do
|
16
16
|
local_offset = "-08:00"
|
17
17
|
local_time = Time.new(2000,12,31,0,0,0,local_offset)
|
18
|
-
subject.parse_in_zone(local_time).
|
18
|
+
expect(subject.parse_in_zone(local_time)).to eq(Time.zone.parse("2000-12-31 08:00:00"))
|
19
19
|
end
|
20
20
|
|
21
21
|
it "returns a time from a date" do
|
22
|
-
subject.parse_in_zone(Date.new(2000,12,31)).
|
22
|
+
expect(subject.parse_in_zone(Date.new(2000,12,31))).to eq(Time.zone.parse("2000-12-31"))
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
@@ -27,11 +27,11 @@ describe ScheduleAttributes::TimeHelpers do
|
|
27
27
|
before { Time.zone = nil }
|
28
28
|
|
29
29
|
it "returns a time from a date string" do
|
30
|
-
subject.parse_in_zone("2000-12-31").
|
30
|
+
expect(subject.parse_in_zone("2000-12-31")).to eq(Time.parse("2000-12-31"))
|
31
31
|
end
|
32
32
|
|
33
33
|
it "returns a time from a time" do
|
34
|
-
subject.parse_in_zone(Time.new(2000,12,31)).
|
34
|
+
expect(subject.parse_in_zone(Time.new(2000,12,31))).to eq(Time.parse("2000-12-31"))
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -7,11 +7,11 @@ describe ScheduledModel do
|
|
7
7
|
subject(:schedule) { ScheduledModel.new.schedule }
|
8
8
|
|
9
9
|
it "should default to a daily schedule" do
|
10
|
-
schedule.
|
11
|
-
schedule.rtimes.
|
12
|
-
schedule.start_time.
|
13
|
-
schedule.end_time.
|
14
|
-
schedule.rrules.
|
10
|
+
expect(schedule).to be_a(IceCube::Schedule)
|
11
|
+
expect(schedule.rtimes).to eq([])
|
12
|
+
expect(schedule.start_time).to eq(Date.today.to_time)
|
13
|
+
expect(schedule.end_time).to be nil
|
14
|
+
expect(schedule.rrules).to eq([IceCube::Rule.daily])
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -21,80 +21,80 @@ describe ScheduledModel do
|
|
21
21
|
subject(:schedule) { scheduled_model.schedule }
|
22
22
|
|
23
23
|
context args: {repeat: '0', date: '1-1-1985', interval: '5 (ignore this)'} do
|
24
|
-
it { subject.start_time.
|
25
|
-
it { subject.all_occurrences.
|
26
|
-
it { subject.rrules.
|
24
|
+
it { expect(subject.start_time).to eq(Time.new(1985,1,1)) }
|
25
|
+
it { expect(subject.all_occurrences).to eq([Time.new(1985,1,1)]) }
|
26
|
+
it { expect(subject.rrules).to be_blank }
|
27
27
|
end
|
28
28
|
|
29
29
|
context args: {repeat: '0', dates: ['1-1-1985', '31-12-1985'], interval: '5 (ignore this)'} do
|
30
|
-
it { subject.start_time.
|
31
|
-
it { subject.all_occurrences.
|
32
|
-
it { subject.rrules.
|
30
|
+
it { expect(subject.start_time).to eq(Time.new(1985,1,1)) }
|
31
|
+
it { expect(subject.all_occurrences).to eq([Time.new(1985,1,1), Time.new(1985,12,31)]) }
|
32
|
+
it { expect(subject.rrules).to be_blank }
|
33
33
|
end
|
34
34
|
|
35
35
|
context args: {repeat: '0', dates: ['1-1-1985', '31-12-1985'], start_time: '12:00', end_time: '14:00', interval: '5 (ignore this)'} do
|
36
|
-
it { subject.start_time.
|
37
|
-
it { subject.duration.
|
38
|
-
it { subject.all_occurrences.
|
39
|
-
it { subject.rrules.
|
40
|
-
specify { schedule.occurring_between?(helpers.parse_in_zone('1985-1-1 12:00'), helpers.parse_in_zone('1985-6-25 14:00')).
|
41
|
-
specify { schedule.occurs_at?(helpers.parse_in_zone('1985-1-1 12:00')).
|
42
|
-
specify { schedule.occurs_at?(helpers.parse_in_zone('1985-6-6 15:00')).
|
36
|
+
it { expect(subject.start_time).to eq(Time.new(1985,1,1,12,0)) }
|
37
|
+
it { expect(subject.duration).to eq(7200) }
|
38
|
+
it { expect(subject.all_occurrences).to eq([Time.new(1985,1,1,12,0), Time.new(1985,12,31,12,0)]) }
|
39
|
+
it { expect(subject.rrules).to be_blank }
|
40
|
+
specify { expect(schedule.occurring_between?(helpers.parse_in_zone('1985-1-1 12:00'), helpers.parse_in_zone('1985-6-25 14:00'))).to be_truthy }
|
41
|
+
specify { expect(schedule.occurs_at?(helpers.parse_in_zone('1985-1-1 12:00'))).to be_truthy }
|
42
|
+
specify { expect(schedule.occurs_at?(helpers.parse_in_zone('1985-6-6 15:00'))).to be_falsey }
|
43
43
|
end
|
44
44
|
|
45
45
|
context args: {repeat: '1'} do
|
46
|
-
it { subject.start_time.
|
47
|
-
it { subject.rrules.
|
46
|
+
it { expect(subject.start_time).to eq(Date.today.to_time) }
|
47
|
+
it { expect(subject.rrules).to eq([IceCube::Rule.daily]) }
|
48
48
|
end
|
49
49
|
|
50
50
|
context args: {repeat: '1', start_date: '1-1-1985', interval_unit: 'day', interval: '3'} do
|
51
|
-
it { subject.start_time.
|
52
|
-
it { subject.rrules.
|
53
|
-
specify { schedule.first(3).
|
51
|
+
it { expect(subject.start_time).to eq(Date.new(1985,1,1).to_time) }
|
52
|
+
it { expect(subject.rrules).to eq([IceCube::Rule.daily(3)]) }
|
53
|
+
specify { expect(schedule.first(3)).to eq([Date.civil(1985,1,1), Date.civil(1985,1,4), Date.civil(1985,1,7)].map(&:to_time)) }
|
54
54
|
end
|
55
55
|
|
56
56
|
context args: {repeat: "1", start_date: "1-1-1985", interval_unit: "day", interval: "3", end_date: "29-12-1985", ends: "eventually"} do
|
57
|
-
it { subject.start_time.
|
57
|
+
it { expect(subject.start_time).to eq(Date.new(1985,1,1).to_time) }
|
58
58
|
# Rails 4.1 removes Date.current.to_time_in_current_zone in favour of Date.in_time_zone
|
59
59
|
it do
|
60
60
|
if Date.current.respond_to?(:in_time_zone)
|
61
|
-
subject.rrules.
|
61
|
+
expect(subject.rrules).to eq([ IceCube::Rule.daily(3).until(Date.new(1985,12,29).in_time_zone) ])
|
62
62
|
else
|
63
|
-
subject.rrules.
|
63
|
+
expect(subject.rrules).to eq([ IceCube::Rule.daily(3).until(Date.new(1985,12,29).to_time_in_current_zone) ])
|
64
64
|
end
|
65
65
|
end
|
66
|
-
specify { schedule.first(3).
|
66
|
+
specify { expect(schedule.first(3)).to eq([Date.civil(1985,1,1), Date.civil(1985,1,4), Date.civil(1985,1,7)].map(&:to_time)) }
|
67
67
|
end
|
68
68
|
|
69
69
|
context args: {repeat: '1', start_date: '1-1-1985', interval_unit: 'day', interval: '3', until_date: '29-12-1985', ends: 'never'} do
|
70
|
-
it { subject.start_time.
|
71
|
-
it { subject.rrules.
|
72
|
-
specify { schedule.first(3).
|
70
|
+
it { expect(subject.start_time).to eq(Date.new(1985,1,1).to_time) }
|
71
|
+
it { expect(subject.rrules).to eq([IceCube::Rule.daily(3)]) }
|
72
|
+
specify { expect(schedule.first(3)).to eq([Date.civil(1985,1,1), Date.civil(1985,1,4), Date.civil(1985,1,7)].map(&:to_time)) }
|
73
73
|
end
|
74
74
|
|
75
75
|
context args: {repeat: '1', start_date: '1-1-1985', interval_unit: 'week', interval: '3', monday: '1', wednesday: '1', friday: '1'} do
|
76
|
-
it { subject.start_time.
|
77
|
-
it { subject.rrules.
|
78
|
-
specify { schedule.occurs_at?(helpers.parse_in_zone('1985-1-2')).
|
79
|
-
specify { schedule.occurs_at?(helpers.parse_in_zone('1985-1-4')).
|
80
|
-
specify { schedule.occurs_at?(helpers.parse_in_zone('1985-1-7')).
|
81
|
-
specify { schedule.occurs_at?(helpers.parse_in_zone('1985-1-21')).
|
76
|
+
it { expect(subject.start_time).to eq(Date.new(1985,1,1).to_time) }
|
77
|
+
it { expect(subject.rrules).to eq([IceCube::Rule.weekly(3).day(:monday, :wednesday, :friday)]) }
|
78
|
+
specify { expect(schedule.occurs_at?(helpers.parse_in_zone('1985-1-2'))).to be_truthy }
|
79
|
+
specify { expect(schedule.occurs_at?(helpers.parse_in_zone('1985-1-4'))).to be_truthy }
|
80
|
+
specify { expect(schedule.occurs_at?(helpers.parse_in_zone('1985-1-7'))).to be_falsey }
|
81
|
+
specify { expect(schedule.occurs_at?(helpers.parse_in_zone('1985-1-21'))).to be_truthy }
|
82
82
|
end
|
83
83
|
|
84
84
|
context args: {repeat: '1', start_date: '1-1-1985', interval_unit: 'day'} do
|
85
|
-
it { subject.rrules.
|
85
|
+
it { expect(subject.rrules).to eq([IceCube::Rule.daily(1)]) }
|
86
86
|
end
|
87
87
|
|
88
88
|
context args: {repeat: '1', start_date: '1-1-1985', interval_unit: 'year'} do
|
89
|
-
it { subject.start_time.
|
90
|
-
it { subject.rrules.
|
91
|
-
specify { schedule.first(3).
|
89
|
+
it { expect(subject.start_time).to eq(Date.new(1985,1,1).to_time) }
|
90
|
+
it { expect(subject.rrules).to eq([IceCube::Rule.yearly.day_of_month(1).month_of_year(1)]) }
|
91
|
+
specify { expect(schedule.first(3)).to eq([Date.civil(1985,1,1), Date.civil(1986,1,1), Date.civil(1987,1,1)].map(&:to_time)) }
|
92
92
|
end
|
93
93
|
|
94
94
|
context args: {repeat: '1', interval_unit: 'day', start_date: '2012-09-27', yearly_start_month: '12', yearly_start_month_day: '1', yearly_end_month: '4', yearly_end_month_day: '21'} do
|
95
|
-
it { subject.start_time.
|
96
|
-
it { subject.rrules.
|
97
|
-
it { subject.exrules.
|
95
|
+
it { expect(subject.start_time).to eq(Time.new(2012,9,27)) }
|
96
|
+
it { expect(subject.rrules).to eq([IceCube::Rule.daily.month_of_year(12,1,2,3,4)]) }
|
97
|
+
it { expect(subject.exrules).to eq([IceCube::Rule.daily.month_of_year(4).day_of_month(*22..31)]) }
|
98
98
|
end
|
99
99
|
|
100
100
|
context "all_day", pending: "Work in progress"
|
@@ -104,7 +104,7 @@ describe ScheduledModel do
|
|
104
104
|
let(:scheduled_model) { ScheduledModel.new.tap { |m| m.schedule_attributes = RSpec.current_example.metadata[:args] } }
|
105
105
|
subject { scheduled_model }
|
106
106
|
|
107
|
-
it { subject.schedule.
|
107
|
+
it { expect(subject.schedule).to eq(IceCube::Schedule.new(Date.new(1985,1,1).to_time).tap { |s| s.add_recurrence_rule IceCube::Rule.daily(3) }) }
|
108
108
|
end
|
109
109
|
|
110
110
|
end
|
@@ -117,25 +117,25 @@ describe ScheduledModel do
|
|
117
117
|
|
118
118
|
context "for a single date" do
|
119
119
|
before { schedule.add_recurrence_time(Date.tomorrow.to_time) }
|
120
|
-
it {
|
121
|
-
it { subject.date.
|
120
|
+
it { is_expected.to eq(OpenStruct.new(repeat: 0, interval: 1, date: Date.tomorrow, dates: [Date.tomorrow], start_date: Date.today, all_day: true)) }
|
121
|
+
it { expect(subject.date).to be_a(Date) }
|
122
122
|
end
|
123
123
|
|
124
124
|
context "when it repeats daily" do
|
125
125
|
before do
|
126
126
|
schedule.add_recurrence_rule(IceCube::Rule.daily(4))
|
127
127
|
end
|
128
|
-
it {
|
129
|
-
it { subject.start_date.
|
128
|
+
it { is_expected.to eq(OpenStruct.new(repeat: 1, start_date: Date.tomorrow, interval_unit: 'day', interval: 4, ends: 'never', date: Date.today, all_day: true)) }
|
129
|
+
it { expect(subject.start_date).to be_a(Date) }
|
130
130
|
end
|
131
131
|
|
132
132
|
context "when it repeats with an end date" do
|
133
133
|
before do
|
134
134
|
schedule.add_recurrence_rule(IceCube::Rule.daily(4).until((Date.today+10).to_time))
|
135
135
|
end
|
136
|
-
it {
|
137
|
-
it { subject.start_date.
|
138
|
-
it { subject.end_date.
|
136
|
+
it { is_expected.to eq(OpenStruct.new(repeat: 1, start_date: Date.tomorrow, interval_unit: 'day', interval: 4, ends: 'eventually', end_date: Date.today+10, date: Date.today, all_day: true)) }
|
137
|
+
it { expect(subject.start_date).to be_a(Date) }
|
138
|
+
it { expect(subject.end_date).to be_a(Date) }
|
139
139
|
end
|
140
140
|
|
141
141
|
context "when it repeats weekly" do
|
@@ -144,7 +144,7 @@ describe ScheduledModel do
|
|
144
144
|
schedule.add_recurrence_rule(IceCube::Rule.weekly(4).day(:monday, :wednesday, :friday))
|
145
145
|
end
|
146
146
|
it do
|
147
|
-
|
147
|
+
is_expected.to eq(OpenStruct.new(
|
148
148
|
:repeat => 1,
|
149
149
|
:start_date => Date.tomorrow,
|
150
150
|
:interval_unit => 'week',
|
@@ -156,7 +156,7 @@ describe ScheduledModel do
|
|
156
156
|
:all_day => true,
|
157
157
|
|
158
158
|
:date => Date.today #for the form
|
159
|
-
)
|
159
|
+
))
|
160
160
|
end
|
161
161
|
end
|
162
162
|
|
@@ -166,7 +166,7 @@ describe ScheduledModel do
|
|
166
166
|
schedule.add_recurrence_rule(IceCube::Rule.yearly)
|
167
167
|
end
|
168
168
|
it do
|
169
|
-
|
169
|
+
is_expected.to eq(OpenStruct.new(
|
170
170
|
:repeat => 1,
|
171
171
|
:start_date => Date.tomorrow,
|
172
172
|
:interval_unit => 'year',
|
@@ -175,7 +175,7 @@ describe ScheduledModel do
|
|
175
175
|
:all_day => true,
|
176
176
|
|
177
177
|
:date => Date.today #for the form
|
178
|
-
)
|
178
|
+
))
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
@@ -183,37 +183,37 @@ describe ScheduledModel do
|
|
183
183
|
it "should have yearly start and end months" do
|
184
184
|
schedule.add_recurrence_rule(IceCube::Rule.daily.month_of_year(12,1,2))
|
185
185
|
|
186
|
-
subject.yearly_start_month.
|
187
|
-
subject.yearly_end_month.
|
186
|
+
expect(subject.yearly_start_month).to eq(12)
|
187
|
+
expect(subject.yearly_end_month).to eq(2)
|
188
188
|
end
|
189
189
|
|
190
190
|
it "should have a yearly start date" do
|
191
191
|
schedule.add_recurrence_rule(IceCube::Rule.daily.month_of_year(11,12,1,2))
|
192
192
|
schedule.add_exception_rule(IceCube::Rule.daily.month_of_year(11).day_of_month(*1..6))
|
193
193
|
|
194
|
-
subject.yearly_start_month.
|
195
|
-
subject.yearly_start_month_day.
|
194
|
+
expect(subject.yearly_start_month).to eq(11)
|
195
|
+
expect(subject.yearly_start_month_day).to eq(7)
|
196
196
|
end
|
197
197
|
|
198
198
|
it "should have a yearly end date" do
|
199
199
|
schedule.add_recurrence_rule(IceCube::Rule.daily.month_of_year(1,2,3))
|
200
200
|
schedule.add_exception_rule(IceCube::Rule.daily.month_of_year(3).day_of_month(*26..31))
|
201
201
|
|
202
|
-
subject.yearly_end_month.
|
203
|
-
subject.yearly_end_month_day.
|
202
|
+
expect(subject.yearly_end_month).to eq(3)
|
203
|
+
expect(subject.yearly_end_month_day).to eq(25)
|
204
204
|
end
|
205
205
|
|
206
206
|
it "should have no yearly start day for months only" do
|
207
207
|
schedule.add_recurrence_rule(IceCube::Rule.daily.month_of_year(1,2,3))
|
208
208
|
|
209
|
-
subject.yearly_start_month_day.
|
209
|
+
expect(subject.yearly_start_month_day).to be_nil
|
210
210
|
end
|
211
211
|
|
212
212
|
it "should have a yearly start day on the first when end day is set" do
|
213
213
|
schedule.add_recurrence_rule(IceCube::Rule.daily.month_of_year(1,2,3))
|
214
214
|
schedule.add_exception_rule(IceCube::Rule.daily.month_of_year(3).day_of_month(*26..31))
|
215
215
|
|
216
|
-
subject.yearly_start_month_day.
|
216
|
+
expect(subject.yearly_start_month_day).to eq(1)
|
217
217
|
end
|
218
218
|
end
|
219
219
|
|