ice_cube_cron 0.0.5 → 1.0.0

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.
@@ -3,58 +3,62 @@ require 'spec_helper'
3
3
  describe ::IceCubeCron do
4
4
  context 'repeat options' do
5
5
  describe 'monthly' do
6
- let(:ice_cube_model) { ::IceCube::Schedule.from_cron(::Date.new(2015, 7, 1), :repeat_day => '1') }
6
+ let(:schedule) { ::IceCube::Schedule.from_cron(::Date.new(2015, 7, 1), :day_of_month => '1', :hour => 0, :minute => 0) }
7
7
 
8
8
  it 'for same day' do
9
- expect(ice_cube_model.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 1))).to eq([::Date.new(2015, 7, 1)])
9
+ expect(schedule.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 1))).to eq([::Date.new(2015, 7, 1)])
10
10
  end
11
11
 
12
12
  it 'for multiple months' do
13
- expect(ice_cube_model.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 9, 1))).to eq([::Date.new(2015, 7, 1), ::Date.new(2015, 8, 1), ::Date.new(2015, 9, 1)])
13
+ expect(schedule.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 9, 1))).to eq([::Date.new(2015, 7, 1), ::Date.new(2015, 8, 1), ::Date.new(2015, 9, 1)])
14
14
  end
15
15
  end
16
16
 
17
17
  describe 'twice monthly' do
18
- let(:ice_cube_model) { ::IceCube::Schedule.from_cron(::Date.new(2015, 7, 1), :repeat_day => '1,15') }
18
+ let(:schedule) { ::IceCube::Schedule.from_cron(::Date.new(2015, 7, 1), :day_of_month => '1,15', :hour => 0, :minute => 0) }
19
19
 
20
20
  it 'for one month' do
21
- expect(ice_cube_model.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 31))).to eq([::Date.new(2015, 7, 1), ::Date.new(2015, 7, 15)])
21
+ expect(schedule.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 31))).to eq([::Date.new(2015, 7, 1), ::Date.new(2015, 7, 15)])
22
22
  end
23
23
 
24
24
  it 'for two months' do
25
- expect(ice_cube_model.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 8, 31))).to eq([::Date.new(2015, 7, 1), ::Date.new(2015, 7, 15), ::Date.new(2015, 8, 1), ::Date.new(2015, 8, 15)])
25
+ expect(schedule.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 8, 31))).to eq([::Date.new(2015, 7, 1), ::Date.new(2015, 7, 15), ::Date.new(2015, 8, 1), ::Date.new(2015, 8, 15)])
26
26
  end
27
27
  end
28
28
 
29
29
  describe 'bi-monthly' do
30
- let(:ice_cube_model) do
30
+ let(:schedule) do
31
31
  ::IceCube::Schedule.from_cron(
32
32
  ::Date.new(2015, 5, 1),
33
- :repeat_day => '1',
34
- :repeat_interval => '2'
33
+ :day_of_month => '1',
34
+ :repeat_interval => '2',
35
+ :hour => 0,
36
+ :minute => 0
35
37
  )
36
38
  end
37
39
 
38
40
  it 'for one month' do
39
- expect(ice_cube_model.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 31))).to eq([::Date.new(2015, 7, 1)])
41
+ expect(schedule.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 31))).to eq([::Date.new(2015, 7, 1)])
40
42
  end
41
43
 
42
44
  it 'for multiple months' do
43
- expect(ice_cube_model.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 10, 31))).to eq([::Date.new(2015, 7, 1), ::Date.new(2015, 9, 1)])
45
+ expect(schedule.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 10, 31))).to eq([::Date.new(2015, 7, 1), ::Date.new(2015, 9, 1)])
44
46
  end
45
47
  end
46
48
 
47
49
  describe 'every week' do
48
- let(:ice_cube_model) do
50
+ let(:schedule) do
49
51
  ::IceCube::Schedule.from_cron(
50
52
  ::Date.new(2015, 7, 6),
51
- :repeat_weekday => '1'
53
+ :day_of_week => '1',
54
+ :hour => 0,
55
+ :minute => 0
52
56
  )
53
57
  end
54
58
 
55
59
  it 'for one week' do
56
60
  expect(
57
- ice_cube_model.occurrences_between(
61
+ schedule.occurrences_between(
58
62
  ::Date.new(2015, 7, 1),
59
63
  ::Date.new(2015, 7, 7)
60
64
  )
@@ -63,7 +67,7 @@ describe ::IceCubeCron do
63
67
 
64
68
  it 'for one month' do
65
69
  expect(
66
- ice_cube_model.occurrences_between(
70
+ schedule.occurrences_between(
67
71
  ::Date.new(2015, 7, 1),
68
72
  ::Date.new(2015, 8, 31)
69
73
  )
@@ -84,17 +88,19 @@ describe ::IceCubeCron do
84
88
  end
85
89
 
86
90
  describe 'bi-weekly' do
87
- let(:ice_cube_model) do
91
+ let(:schedule) do
88
92
  ::IceCube::Schedule.from_cron(
89
93
  ::Date.new(2015, 7, 6),
90
- :repeat_weekday => '1',
91
- :repeat_interval => '2'
94
+ :day_of_week => '1',
95
+ :repeat_interval => '2',
96
+ :hour => 0,
97
+ :minute => 0
92
98
  )
93
99
  end
94
100
 
95
101
  it 'for one week' do
96
102
  expect(
97
- ice_cube_model.occurrences_between(
103
+ schedule.occurrences_between(
98
104
  ::Date.new(2015, 7, 1),
99
105
  ::Date.new(2015, 7, 7)
100
106
  )
@@ -103,7 +109,7 @@ describe ::IceCubeCron do
103
109
 
104
110
  it 'for two months' do
105
111
  expect(
106
- ice_cube_model.occurrences_between(
112
+ schedule.occurrences_between(
107
113
  ::Date.new(2015, 7, 1),
108
114
  ::Date.new(2015, 8, 31)
109
115
  )
@@ -124,94 +130,107 @@ describe ::IceCubeCron do
124
130
  end
125
131
 
126
132
  describe 'annually' do
127
- let(:ice_cube_model) do
133
+ let(:schedule) do
128
134
  ::IceCube::Schedule.from_cron(
129
135
  ::Date.new(2015, 1, 1),
130
- :repeat_month => 2
136
+ :repeat_month => 2,
137
+ :day_of_month => 1,
138
+ :hour => 0,
139
+ :minute => 0
131
140
  )
132
141
  end
133
142
 
134
143
  it 'for one year' do
135
- expect(ice_cube_model.occurrences_between(::Date.new(2015, 1, 1), ::Date.new(2015, 12, 31))).to eq([::Date.new(2015, 2, 1)])
144
+ expect(schedule.occurrences_between(::Date.new(2015, 1, 1), ::Date.new(2015, 12, 31))).to eq([::Date.new(2015, 2, 1)])
136
145
  end
137
146
 
138
147
  it 'for two years' do
139
- expect(ice_cube_model.occurrences_between(::Date.new(2015, 1, 1), ::Date.new(2016, 12, 31))).to eq([::Date.new(2015, 2, 1), ::Date.new(2016, 2, 1)])
148
+ expect(schedule.occurrences_between(::Date.new(2015, 1, 1), ::Date.new(2016, 12, 31))).to eq([::Date.new(2015, 2, 1), ::Date.new(2016, 2, 1)])
140
149
  end
141
150
  end
142
151
 
143
152
  describe 'bi-annually' do
144
- let(:ice_cube_model) do
153
+ let(:schedule) do
145
154
  ::IceCube::Schedule.from_cron(
146
155
  ::Date.new(2015, 1, 1),
147
156
  :repeat_interval => 2,
148
157
  :repeat_month => 2,
149
- :repeat_day => 1
158
+ :day_of_month => 1,
159
+ :hour => 0,
160
+ :minute => 0
150
161
  )
151
162
  end
152
163
 
153
164
  it 'for two years' do
154
- expect(ice_cube_model.occurrences_between(::Date.new(2015, 1, 1), ::Date.new(2016, 12, 31))).to eq([::Date.new(2015, 2, 1)])
165
+ expect(schedule.occurrences_between(::Date.new(2015, 1, 1), ::Date.new(2016, 12, 31))).to eq([::Date.new(2015, 2, 1)])
155
166
  end
156
167
  end
157
168
 
158
169
  describe 'last weekday of month' do
159
170
  context '31 day month' do
160
- let(:ice_cube_model) do
171
+ let(:schedule) do
161
172
  ::IceCube::Schedule.from_cron(
162
173
  ::Date.new(2015, 1, 1),
163
- :repeat_weekday => '5L'
174
+ :day_of_week => '5L',
175
+ :hour => 0,
176
+ :minute => 0
164
177
  )
165
178
  end
166
179
 
167
180
  it 'for one month' do
168
- expect(ice_cube_model.occurrences_between(::Date.new(2015, 12, 1), ::Date.new(2015, 12, 31))).to eq([::Date.new(2015, 12, 25)])
181
+ expect(schedule.occurrences_between(::Date.new(2015, 12, 1), ::Date.new(2015, 12, 31))).to eq([::Date.new(2015, 12, 25)])
169
182
  end
170
183
  end
171
184
 
172
185
  context '29 day month' do
173
- let(:ice_cube_model) do
186
+ let(:schedule) do
174
187
  ::IceCube::Schedule.from_cron(
175
188
  ::Date.new(2015, 1, 1),
176
- :repeat_weekday => '3L'
189
+ :day_of_week => '3L',
190
+ :hour => 0,
191
+ :minute => 0
177
192
  )
178
193
  end
179
194
 
180
195
  it 'for one month' do
181
- expect(ice_cube_model.occurrences_between(::Date.new(2016, 2, 1), ::Date.new(2016, 2, 29))).to eq([::Date.new(2016, 2, 24)])
196
+ expect(schedule.occurrences_between(::Date.new(2016, 2, 1), ::Date.new(2016, 2, 29))).to eq([::Date.new(2016, 2, 24)])
182
197
  end
183
198
  end
184
199
  end
185
200
 
186
201
  describe 'last day of month' do
187
202
  context '31 day month' do
188
- let(:ice_cube_model) do
203
+ let(:schedule) do
189
204
  ::IceCube::Schedule.from_cron(
190
205
  ::Date.new(2015, 1, 1),
191
- :repeat_day => 'L'
206
+ :day_of_month => 'L',
207
+ :hour => 0,
208
+ :minute => 0
192
209
  )
193
210
  end
194
211
 
195
212
  it 'for one multiple months' do
196
- expect(ice_cube_model.occurrences_between(::Date.new(2015, 12, 1), ::Date.new(2016, 3, 1))).to eq([::Date.new(2015, 12, 31), ::Date.new(2016, 1, 31), ::Date.new(2016, 2, 29)])
213
+ expect(schedule.occurrences_between(::Date.new(2015, 12, 1), ::Date.new(2016, 3, 1))).to eq([::Date.new(2015, 12, 31), ::Date.new(2016, 1, 31), ::Date.new(2016, 2, 29)])
197
214
  end
198
215
  end
199
216
  end
200
217
 
201
218
  describe 'Nth day of week of month' do
202
- let(:ice_cube_model) do
219
+ let(:schedule) do
203
220
  ::IceCube::Schedule.from_cron(
204
221
  ::Date.new(2015, 1, 1),
205
- :repeat_weekday => '1#2'
222
+ :day_of_week => '1#2',
223
+ :hour => 0,
224
+ :minute => 0
206
225
  )
207
226
  end
208
227
 
209
228
  it 'for one month' do
210
- expect(ice_cube_model.occurrences_between(::Date.new(2016, 2, 1), ::Date.new(2016, 2, 29))).to eq([::Date.new(2016, 2, 8)])
229
+ expect(schedule.occurrences_between(::Date.new(2016, 2, 1), ::Date.new(2016, 2, 29))).to eq([::Date.new(2016, 2, 8)])
211
230
  end
212
231
 
213
232
  it 'for mutiple months' do
214
- expect(ice_cube_model.occurrences_between(::Date.new(2016, 2, 1), ::Date.new(2016, 4, 30))).to eq([::Date.new(2016, 2, 8), ::Date.new(2016, 3, 14), ::Date.new(2016, 4, 11)])
233
+ expect(schedule.occurrences_between(::Date.new(2016, 2, 1), ::Date.new(2016, 4, 30))).to eq([::Date.new(2016, 2, 8), ::Date.new(2016, 3, 14), ::Date.new(2016, 4, 11)])
215
234
  end
216
235
  end
217
236
 
@@ -219,8 +238,10 @@ describe ::IceCubeCron do
219
238
  let(:schedule) do
220
239
  ::IceCube::Schedule.from_cron(
221
240
  ::Date.new(2015, 1, 1),
222
- :repeat_day => '1',
223
- :repeat_until => ::Date.new(2015, 3, 1)
241
+ :day_of_month => '1',
242
+ :repeat_until => ::Date.new(2015, 3, 1),
243
+ :hour => 0,
244
+ :minute => 0
224
245
  )
225
246
  end
226
247
 
@@ -231,81 +252,118 @@ describe ::IceCubeCron do
231
252
 
232
253
  context 'year expression support (non-standard)' do
233
254
  context 'in month of a year' do
234
- let(:ice_cube_model) do
255
+ let(:schedule) do
235
256
  ::IceCube::Schedule.from_cron(
236
257
  ::Date.new(2015, 1, 1),
237
258
  :year => '2015',
238
259
  :month => '6',
239
- :day => '10'
260
+ :day_of_month => '10',
261
+ :hour => 0,
262
+ :minute => 0
240
263
  )
241
264
  end
242
265
 
243
266
  it '#occurrences_between' do
244
- expect(ice_cube_model.occurrences_between(::Date.new(2013, 1, 1), ::Date.new(2017, 12, 31))).to eq([::Date.new(2015, 6, 10)])
267
+ expect(schedule.occurrences_between(::Date.new(2013, 1, 1), ::Date.new(2017, 12, 31))).to eq([::Date.new(2015, 6, 10)])
245
268
  end
246
269
 
247
270
  it '#to_s' do
248
- expect(ice_cube_model.to_s).to eq('Yearly in 2015 in June on the 10th day of the month')
271
+ expect(schedule.to_s).to eq('Yearly in 2015 in June on the 10th day of the month')
249
272
  end
250
273
  end
251
274
 
252
275
  context 'in a month of multiple years' do
253
- let(:ice_cube_model) do
276
+ let(:schedule) do
254
277
  ::IceCube::Schedule.from_cron(
255
278
  ::Date.new(2015, 1, 1),
256
279
  :year => '2015,2017',
257
280
  :month => '6',
258
- :day => '10'
281
+ :day_of_month => '10',
282
+ :hour => 0,
283
+ :minute => 0
259
284
  )
260
285
  end
261
286
 
262
287
  it '#occurrences_between' do
263
- expect(ice_cube_model.occurrences_between(::Date.new(2013, 1, 1), ::Date.new(2018, 12, 31))).to eq([::Date.new(2015, 6, 10), ::Date.new(2017, 6, 10)])
288
+ expect(schedule.occurrences_between(::Date.new(2013, 1, 1), ::Date.new(2018, 12, 31))).to eq([::Date.new(2015, 6, 10), ::Date.new(2017, 6, 10)])
264
289
  end
265
290
 
266
291
  it '#to_s' do
267
- expect(ice_cube_model.to_s).to eq('Yearly in 2015 and 2017 in June on the 10th day of the month')
292
+ expect(schedule.to_s).to eq('Yearly in 2015 and 2017 in June on the 10th day of the month')
268
293
  end
269
294
  end
270
295
 
271
296
  context 'multiple days in month of a year' do
272
- let(:ice_cube_model) do
297
+ let(:schedule) do
273
298
  ::IceCube::Schedule.from_cron(
274
299
  ::Date.new(2015, 1, 1),
275
300
  :year => '2015',
276
301
  :month => '6',
277
- :day => '10,15'
302
+ :day_of_month => '10,15',
303
+ :hour => 0,
304
+ :minute => 0
278
305
  )
279
306
  end
280
307
 
281
308
  it '#occurrences_between' do
282
- expect(ice_cube_model.occurrences_between(::Date.new(2013, 1, 1), ::Date.new(2017, 12, 31))).to eq([::Date.new(2015, 6, 10), ::Date.new(2015, 6, 15)])
309
+ expect(schedule.occurrences_between(::Date.new(2013, 1, 1), ::Date.new(2017, 12, 31))).to eq([::Date.new(2015, 6, 10), ::Date.new(2015, 6, 15)])
283
310
  end
284
311
 
285
312
  it '#to_s' do
286
- expect(ice_cube_model.to_s).to eq('Yearly in 2015 in June on the 10th and 15th days of the month')
313
+ expect(schedule.to_s).to eq('Yearly in 2015 in June on the 10th and 15th days of the month')
287
314
  end
288
315
  end
289
316
  end
317
+
318
+ context 'every hour' do
319
+ let(:schedule) do
320
+ ::IceCube::Schedule.from_cron(
321
+ ::Date.new(2015, 1, 1),
322
+ :minute => '30'
323
+ )
324
+ end
325
+
326
+ it '#occurrences_between' do
327
+ expect(schedule.occurrences_between(::Time.new(2015, 1, 1, 0).utc, ::Time.new(2015, 1, 1, 1, 30).utc)).to eq([::Time.new(2015, 1, 1, 0, 30).utc, ::Time.new(2015, 1, 1, 1, 30).utc])
328
+ end
329
+ end
330
+
331
+ context 'every day' do
332
+ let(:schedule) do
333
+ ::IceCube::Schedule.from_cron(
334
+ ::Date.new(2015, 1, 1),
335
+ :hour => '1',
336
+ :minute => '30'
337
+ )
338
+ end
339
+
340
+ it '#occurrences_between' do
341
+ expect(schedule.occurrences_between(::Date.new(2015, 1, 1), ::Date.new(2015, 1, 3))).to eq([::Time.utc(2015, 1, 1, 1, 30), ::Time.utc(2015, 1, 2, 1, 30)])
342
+ end
343
+ end
290
344
  end
291
345
 
292
346
  context 'input types' do
293
347
  it 'handles ::DateTime as input' do
294
- ice_cube_model = ::IceCube::Schedule.from_cron(
348
+ schedule = ::IceCube::Schedule.from_cron(
295
349
  ::DateTime.new(2015, 5, 1),
296
- :repeat_day => '1',
297
- :repeat_interval => '2'
350
+ :day_of_month => '1',
351
+ :repeat_interval => '2',
352
+ :hour => 0,
353
+ :minute => 0
298
354
  )
299
- expect(ice_cube_model.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 31))).to eq([::Date.new(2015, 7, 1)])
355
+ expect(schedule.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 31))).to eq([::Date.new(2015, 7, 1)])
300
356
  end
301
357
 
302
358
  it 'handles integer (epoch) as input' do
303
- ice_cube_model = ::IceCube::Schedule.from_cron(
359
+ schedule = ::IceCube::Schedule.from_cron(
304
360
  1_430_438_400, # Fri, 01 May 2015 00:00:00 GMT
305
- :repeat_day => '1',
306
- :repeat_interval => '2'
361
+ :day_of_month => '1',
362
+ :repeat_interval => '2',
363
+ :hour => 0,
364
+ :minute => 0
307
365
  )
308
- expect(ice_cube_model.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 31))).to eq([::Date.new(2015, 7, 1)])
366
+ expect(schedule.occurrences_between(::Date.new(2015, 7, 1), ::Date.new(2015, 7, 31))).to eq([::Date.new(2015, 7, 1)])
309
367
  end
310
368
  end
311
369
  end