chronological 1.0.0beta1 → 1.0.0beta2

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,13 +3,13 @@ module Chronological
3
3
  def scheduled?(object)
4
4
  object.send(field_names[:starting_time]).present? &&
5
5
  object.send(field_names[:ending_time]).present? &&
6
- super
6
+ scheduled_time_zone(object, true).present?
7
7
  end
8
8
 
9
9
  def partially_scheduled?(object)
10
10
  object.send(field_names[:starting_time]).present? ||
11
11
  object.send(field_names[:ending_time]).present? ||
12
- super
12
+ scheduled_time_zone(object, false).present?
13
13
  end
14
14
 
15
15
  def has_absolute_start?
@@ -21,15 +21,15 @@ module Chronological
21
21
  end
22
22
 
23
23
  private
24
- def self.started_at_sql_calculation(field_names)
24
+ def self.started_at_sql(field_names)
25
25
  field_names[:starting_time]
26
26
  end
27
27
 
28
- def self.ended_at_sql_calculation(field_names)
28
+ def self.ended_at_sql(field_names)
29
29
  field_names[:ending_time]
30
30
  end
31
31
 
32
- def self.duration_sql_calculation(field_names)
32
+ def self.duration_sql(field_names)
33
33
  "extract ('epoch' from (#{field_names[:ending_time]} - #{field_names[:starting_time]}))"
34
34
  end
35
35
 
@@ -34,14 +34,6 @@ module Chronological
34
34
  { :hours => hours, :minutes => minutes, :seconds => seconds }
35
35
  end
36
36
 
37
- def scheduled?(object)
38
- !field_names[:time_zone].nil? ? object.send(field_names[:time_zone]) : true
39
- end
40
-
41
- def partially_scheduled?(object)
42
- !field_names[:time_zone].nil? ? object.send(field_names[:time_zone]) : false
43
- end
44
-
45
37
  def in_progress?(object)
46
38
  return false unless has_absolute_timeframe?(object)
47
39
 
@@ -52,15 +44,15 @@ module Chronological
52
44
  # Scopes
53
45
  #
54
46
  def self.started(object, field_names)
55
- object.where "#{started_at_sql_calculation(field_names)} <= :as_of", :as_of => Time.now.utc
47
+ object.where "#{started_at_sql(field_names)} <= :as_of", :as_of => Time.now.utc
56
48
  end
57
49
 
58
50
  def self.ended(object, field_names)
59
- object.where "#{ended_at_sql_calculation(field_names)} <= :as_of", :as_of => Time.now.utc
51
+ object.where "#{ended_at_sql(field_names)} <= :as_of", :as_of => Time.now.utc
60
52
  end
61
53
 
62
54
  def self.not_yet_ended(object, field_names)
63
- object.where "#{ended_at_sql_calculation(field_names)} > :as_of", :as_of => Time.now.utc
55
+ object.where "#{ended_at_sql(field_names)} > :as_of", :as_of => Time.now.utc
64
56
  end
65
57
 
66
58
  def self.in_progress(object, field_names)
@@ -72,11 +64,16 @@ module Chronological
72
64
  end
73
65
 
74
66
  def self.by_date(object, field_names, direction)
75
- object.order "#{object.table_name}.#{started_at_sql_calculation(field_names)} #{direction}, #{object.table_name}.#{ended_at_sql_calculation(field_names)} #{direction}"
67
+ object.order "#{object.table_name}.#{started_at_sql(field_names)} #{direction}, #{object.table_name}.#{ended_at_sql(field_names)} #{direction}"
76
68
  end
77
69
 
78
70
  def self.by_duration(object, field_names, direction)
79
- object.order "#{duration_sql_calculation(field_names)} #{direction}"
71
+ object.order "#{duration_sql(field_names)} #{direction}"
72
+ end
73
+
74
+ private
75
+ def scheduled_time_zone(object, default)
76
+ !field_names[:time_zone].nil? ? object.send(field_names[:time_zone]) : default
80
77
  end
81
78
  end
82
79
  end
@@ -16,14 +16,14 @@ module Chronological
16
16
  object.send(field_names[:base_of_offset]).present? &&
17
17
  object.send(field_names[:starting_offset]).present? &&
18
18
  object.send(field_names[:ending_offset]).present? &&
19
- super
19
+ scheduled_time_zone(object, true).present?
20
20
  end
21
21
 
22
22
  def partially_scheduled?(object)
23
23
  object.send(field_names[:base_of_offset]).present? ||
24
24
  object.send(field_names[:starting_offset]).present? ||
25
25
  object.send(field_names[:ending_offset]).present? ||
26
- super
26
+ scheduled_time_zone(object, false).present?
27
27
  end
28
28
 
29
29
  def self.in_progress(object, field_names)
@@ -43,15 +43,15 @@ module Chronological
43
43
  end
44
44
 
45
45
  private
46
- def self.started_at_sql_calculation(field_names)
46
+ def self.started_at_sql(field_names)
47
47
  "#{field_names[:base_of_offset]} - (#{field_names[:starting_offset]} * INTERVAL '1 seconds')"
48
48
  end
49
49
 
50
- def self.ended_at_sql_calculation(field_names)
50
+ def self.ended_at_sql(field_names)
51
51
  "#{field_names[:base_of_offset]} - (#{field_names[:ending_offset]} * INTERVAL '1 seconds')"
52
52
  end
53
53
 
54
- def self.duration_sql_calculation(field_names)
54
+ def self.duration_sql(field_names)
55
55
  "#{field_names[:starting_offset]} - #{field_names[:ending_offset]}"
56
56
  end
57
57
 
@@ -1,3 +1,3 @@
1
1
  module Chronological
2
- VERSION = '1.0.0beta1'
2
+ VERSION = '1.0.0beta2'
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- class ChronologicableStrategyClass
3
+ class ChronologicableStrategyClass < ActiveRecord::Base
4
4
  extend Chronological
5
5
  end
6
6
 
@@ -9,15 +9,49 @@ describe Chronological do
9
9
  context 'when it is called with a symbol representing a strategy' do
10
10
  before do
11
11
  ChronologicableStrategyClass.class_eval do
12
- timeframe type: :absolute,
13
- start_utc: :started_at_utc,
14
- end_utc: :ended_at_utc
12
+ timeframe type: :relative
15
13
  end
16
14
  end
17
15
 
16
+ let(:chronologicable) { ChronologicableStrategyClass.new }
17
+
18
18
  pit 'is translated properly' do
19
19
  ChronologicableStrategyClass.class_variable_get(:@@chronological_strategy).should eql Chronological::AbsoluteStrategy
20
20
  end
21
+
22
+ it { chronologicable.should respond_to :scheduled? }
23
+ it { chronologicable.should respond_to :partially_scheduled? }
24
+ it { chronologicable.should respond_to :inactive? }
25
+ it { chronologicable.should respond_to :in_progress? }
26
+ it { chronologicable.should respond_to :active? }
27
+ it { chronologicable.should respond_to :duration }
28
+ it { chronologicable.should respond_to :started_on }
29
+ it { chronologicable.should respond_to :ended_on }
30
+
31
+ it { ChronologicableStrategyClass.should respond_to :by_date }
32
+ it { ChronologicableStrategyClass.should respond_to :ended }
33
+ it { ChronologicableStrategyClass.should respond_to :not_yet_ended }
34
+ it { ChronologicableStrategyClass.should respond_to :in_progress }
35
+ it { ChronologicableStrategyClass.should respond_to :active }
36
+ it { ChronologicableStrategyClass.should respond_to :started }
37
+ it { ChronologicableStrategyClass.should respond_to :in_progress? }
38
+ it { ChronologicableStrategyClass.should respond_to :active? }
39
+
40
+ it 'tells ActiveRecord that the dynamic starting date field is a datetime' do
41
+ ChronologicableStrategyClass.columns_hash[:started_at].type.should eql :datetime
42
+ end
43
+
44
+ it 'tells ActiveRecord that the dynamic ending date field is a datetime' do
45
+ ChronologicableStrategyClass.columns_hash[:ended_at].type.should eql :datetime
46
+ end
47
+
48
+ it 'tells ActiveRecord that the dynamic starting date field is a datetime' do
49
+ ChronologicableStrategyClass.columns_hash[:started_on].type.should eql :date
50
+ end
51
+
52
+ it 'tells ActiveRecord that the dynamic ending date field is a datetime' do
53
+ ChronologicableStrategyClass.columns_hash[:ended_on].type.should eql :date
54
+ end
21
55
  end
22
56
 
23
57
  context 'when it is called with a symbol that does not represent a strategy' do
@@ -8,7 +8,7 @@ class AbsoluteChronologicable < ActiveRecord::Base
8
8
  ending_time: :ended_at_utc
9
9
  end
10
10
 
11
- class ChronologicableWithTimeZone < ActiveRecord::Base
11
+ class AbsoluteChronologicableWithTimeZone < ActiveRecord::Base
12
12
  extend Chronological
13
13
 
14
14
  timeframe type: :absolute,
@@ -166,7 +166,7 @@ describe Chronological::AbsoluteStrategy, :timecop => true do
166
166
  end
167
167
 
168
168
  let!(:chronologicable_with_enabled_time_zone) do
169
- ChronologicableWithTimeZone.new(
169
+ AbsoluteChronologicableWithTimeZone.new(
170
170
  started_at_utc: start_time,
171
171
  ended_at_utc: end_time,
172
172
  time_zone: time_zone)
@@ -196,6 +196,24 @@ describe Chronological::AbsoluteStrategy, :timecop => true do
196
196
  end
197
197
  end
198
198
 
199
+ context 'and the time zone is blank' do
200
+ let(:time_zone) { '' }
201
+
202
+ describe '#scheduled?' do
203
+ it 'is correct' do
204
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
205
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
206
+ end
207
+ end
208
+
209
+ describe '#partially_scheduled?' do
210
+ it 'is correct' do
211
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
212
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
213
+ end
214
+ end
215
+ end
216
+
199
217
  context 'and a time zone is set' do
200
218
  let(:time_zone) { ActiveSupport::TimeZone.new('Alaska') }
201
219
 
@@ -236,6 +254,24 @@ describe Chronological::AbsoluteStrategy, :timecop => true do
236
254
  end
237
255
  end
238
256
 
257
+ context 'but the time zone is blank' do
258
+ let(:time_zone) { '' }
259
+
260
+ describe '#scheduled?' do
261
+ it 'is correct' do
262
+ chronologicable_without_enabled_time_zone.should be_scheduled
263
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
264
+ end
265
+ end
266
+
267
+ describe '#partially_scheduled?' do
268
+ it 'is correct' do
269
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
270
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
271
+ end
272
+ end
273
+ end
274
+
239
275
  context 'and a time zone is set' do
240
276
  let(:time_zone) { ActiveSupport::TimeZone.new('Alaska') }
241
277
 
@@ -292,6 +328,24 @@ describe Chronological::AbsoluteStrategy, :timecop => true do
292
328
  end
293
329
  end
294
330
 
331
+ context 'but the time zone is blank' do
332
+ let(:time_zone) { '' }
333
+
334
+ describe '#scheduled?' do
335
+ it 'is correct' do
336
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
337
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
338
+ end
339
+ end
340
+
341
+ describe '#partially_scheduled?' do
342
+ it 'is correct' do
343
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
344
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
345
+ end
346
+ end
347
+ end
348
+
295
349
  context 'and a time zone is set' do
296
350
  let(:time_zone) { ActiveSupport::TimeZone.new('Alaska') }
297
351
 
@@ -327,6 +381,24 @@ describe Chronological::AbsoluteStrategy, :timecop => true do
327
381
  chronologicable.should_not be_partially_scheduled
328
382
  end
329
383
  end
384
+
385
+ context 'but the time zone is blank' do
386
+ let(:time_zone) { '' }
387
+
388
+ describe '#scheduled?' do
389
+ it 'is correct' do
390
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
391
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
392
+ end
393
+ end
394
+
395
+ describe '#partially_scheduled?' do
396
+ it 'is correct' do
397
+ chronologicable_without_enabled_time_zone.should_not be_partially_scheduled
398
+ chronologicable_with_enabled_time_zone.should_not be_partially_scheduled
399
+ end
400
+ end
401
+ end
330
402
  end
331
403
 
332
404
  context 'when there is a chronologicable that has already started' do
@@ -234,7 +234,7 @@ describe Chronological::BaseStrategy do
234
234
  end
235
235
  end
236
236
 
237
- describe '#scheduled?' do
237
+ describe '#scheduled_time_zone' do
238
238
  context 'when the time zone option is passed in' do
239
239
  let(:field_names) { { time_zone: :time_zone } }
240
240
 
@@ -242,7 +242,7 @@ describe Chronological::BaseStrategy do
242
242
  let(:fields) { { time_zone: 'Alaska' } }
243
243
 
244
244
  it 'is the time zone' do
245
- strategy.scheduled?(chrono).should eql 'Alaska'
245
+ strategy.send(:scheduled_time_zone, chrono, true).should eql 'Alaska'
246
246
  end
247
247
  end
248
248
 
@@ -250,7 +250,7 @@ describe Chronological::BaseStrategy do
250
250
  let(:fields) { { time_zone: nil } }
251
251
 
252
252
  it 'is the time zone' do
253
- strategy.scheduled?(chrono).should be_nil
253
+ strategy.send(:scheduled_time_zone, chrono, true).should be_nil
254
254
  end
255
255
  end
256
256
  end
@@ -258,38 +258,8 @@ describe Chronological::BaseStrategy do
258
258
  context 'when the time zone option is not passed in' do
259
259
  let(:field_names) { Hash.new }
260
260
 
261
- it 'is always true' do
262
- strategy.scheduled?(chrono).should be_true
263
- end
264
- end
265
- end
266
-
267
- describe '#partially_scheduled?' do
268
- context 'when the time zone option is passed in' do
269
- let(:field_names) { { time_zone: :time_zone } }
270
-
271
- context 'and a time zone exists' do
272
- let(:fields) { { time_zone: 'Alaska' } }
273
-
274
- it 'is the time zone' do
275
- strategy.partially_scheduled?(chrono).should eql 'Alaska'
276
- end
277
- end
278
-
279
- context 'and a time zone does not exist' do
280
- let(:fields) { { time_zone: nil } }
281
-
282
- it 'is the time zone' do
283
- strategy.partially_scheduled?(chrono).should be_nil
284
- end
285
- end
286
- end
287
-
288
- context 'when the time zone option is not passed in' do
289
- let(:field_names) { Hash.new }
290
-
291
- it 'is always false' do
292
- strategy.partially_scheduled?(chrono).should be_false
261
+ it 'is equal to the default' do
262
+ strategy.send(:scheduled_time_zone, chrono, 'blasphemy!').should eql 'blasphemy!'
293
263
  end
294
264
  end
295
265
  end
@@ -9,11 +9,22 @@ class RelativeChronologicable < ActiveRecord::Base
9
9
  base_of_offset: :base_datetime_utc
10
10
  end
11
11
 
12
+ class RelativeChronologicableWithTimeZone < ActiveRecord::Base
13
+ extend Chronological
14
+
15
+ timeframe type: :relative,
16
+ starting_offset: :starting_offset,
17
+ ending_offset: :ending_offset,
18
+ base_of_offset: :base_datetime_utc,
19
+ time_zone: :time_zone
20
+ end
21
+
12
22
  describe Chronological::RelativeStrategy, :timecop => true do
13
23
  let(:now) { nil }
14
24
  let(:starting_offset) { nil }
15
25
  let(:ending_offset) { nil }
16
26
  let(:base_time) { nil }
27
+ let(:time_zone) { nil }
17
28
 
18
29
  let!(:chronologicable) do
19
30
  RelativeChronologicable.create(
@@ -22,6 +33,21 @@ describe Chronological::RelativeStrategy, :timecop => true do
22
33
  base_datetime_utc: base_time)
23
34
  end
24
35
 
36
+ let!(:chronologicable_without_enabled_time_zone) do
37
+ RelativeChronologicable.new(
38
+ starting_offset: starting_offset,
39
+ ending_offset: ending_offset,
40
+ base_datetime_utc: base_time)
41
+ end
42
+
43
+ let!(:chronologicable_with_enabled_time_zone) do
44
+ RelativeChronologicableWithTimeZone.new(
45
+ starting_offset: starting_offset,
46
+ ending_offset: ending_offset,
47
+ base_datetime_utc: base_time,
48
+ time_zone: time_zone)
49
+ end
50
+
25
51
  before { Timecop.freeze(now) }
26
52
 
27
53
  describe '.by_date' do
@@ -161,12 +187,76 @@ describe Chronological::RelativeStrategy, :timecop => true do
161
187
  context 'and the ending offset is set' do
162
188
  let(:ending_offset) { 0 }
163
189
 
164
- it 'is not scheduled' do
165
- chronologicable.should_not be_scheduled
190
+ context 'when the time zone is not set' do
191
+ let(:time_zone) { nil }
192
+
193
+ context 'and the time zone check is enabled' do
194
+ it 'is not scheduled' do
195
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
196
+ end
197
+
198
+ it 'is partially scheduled' do
199
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
200
+ end
201
+ end
202
+
203
+ context 'and the time zone check is not enabled' do
204
+ it 'is not scheduled' do
205
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
206
+ end
207
+
208
+ it 'is partially scheduled' do
209
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
210
+ end
211
+ end
166
212
  end
167
213
 
168
- it 'is partially scheduled' do
169
- chronologicable.should be_partially_scheduled
214
+ context 'when the time zone is blank' do
215
+ let(:time_zone) { '' }
216
+
217
+ context 'and the time zone check is enabled' do
218
+ it 'is not scheduled' do
219
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
220
+ end
221
+
222
+ it 'is partially scheduled' do
223
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
224
+ end
225
+ end
226
+
227
+ context 'and the time zone check is not enabled' do
228
+ it 'is not scheduled' do
229
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
230
+ end
231
+
232
+ it 'is partially scheduled' do
233
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
234
+ end
235
+ end
236
+ end
237
+
238
+ context 'when the time zone is set' do
239
+ let(:time_zone) { 'Alaska' }
240
+
241
+ context 'and the time zone check is enabled' do
242
+ it 'is not scheduled' do
243
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
244
+ end
245
+
246
+ it 'is partially scheduled' do
247
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
248
+ end
249
+ end
250
+
251
+ context 'and the time zone check is not enabled' do
252
+ it 'is not scheduled' do
253
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
254
+ end
255
+
256
+ it 'is partially scheduled' do
257
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
258
+ end
259
+ end
170
260
  end
171
261
 
172
262
  it 'is not included in the in progress list' do
@@ -181,12 +271,76 @@ describe Chronological::RelativeStrategy, :timecop => true do
181
271
  context 'and the ending offset is not set' do
182
272
  let(:ending_offset) { nil }
183
273
 
184
- it 'is not scheduled' do
185
- chronologicable.should_not be_scheduled
274
+ context 'when the time zone is not set' do
275
+ let(:time_zone) { nil }
276
+
277
+ context 'and the time zone check is enabled' do
278
+ it 'is not scheduled' do
279
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
280
+ end
281
+
282
+ it 'is partially scheduled' do
283
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
284
+ end
285
+ end
286
+
287
+ context 'and the time zone check is not enabled' do
288
+ it 'is not scheduled' do
289
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
290
+ end
291
+
292
+ it 'is partially scheduled' do
293
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
294
+ end
295
+ end
186
296
  end
187
297
 
188
- it 'is partially scheduled' do
189
- chronologicable.should be_partially_scheduled
298
+ context 'when the time zone is blank' do
299
+ let(:time_zone) { '' }
300
+
301
+ context 'and the time zone check is enabled' do
302
+ it 'is not scheduled' do
303
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
304
+ end
305
+
306
+ it 'is partially scheduled' do
307
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
308
+ end
309
+ end
310
+
311
+ context 'and the time zone check is not enabled' do
312
+ it 'is not scheduled' do
313
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
314
+ end
315
+
316
+ it 'is partially scheduled' do
317
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
318
+ end
319
+ end
320
+ end
321
+
322
+ context 'when the time zone is set' do
323
+ let(:time_zone) { 'Alaska' }
324
+
325
+ context 'and the time zone check is enabled' do
326
+ it 'is not scheduled' do
327
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
328
+ end
329
+
330
+ it 'is partially scheduled' do
331
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
332
+ end
333
+ end
334
+
335
+ context 'and the time zone check is not enabled' do
336
+ it 'is not scheduled' do
337
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
338
+ end
339
+
340
+ it 'is partially scheduled' do
341
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
342
+ end
343
+ end
190
344
  end
191
345
 
192
346
  it 'is not included in the in progress list' do
@@ -209,12 +363,76 @@ describe Chronological::RelativeStrategy, :timecop => true do
209
363
  context 'but the ending offset is set' do
210
364
  let(:ending_offset) { 0 }
211
365
 
212
- it 'is not scheduled' do
213
- chronologicable.should_not be_scheduled
366
+ context 'when the time zone is not set' do
367
+ let(:time_zone) { nil }
368
+
369
+ context 'and the time zone check is enabled' do
370
+ it 'is not scheduled' do
371
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
372
+ end
373
+
374
+ it 'is partially scheduled' do
375
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
376
+ end
377
+ end
378
+
379
+ context 'and the time zone check is not enabled' do
380
+ it 'is not scheduled' do
381
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
382
+ end
383
+
384
+ it 'is partially scheduled' do
385
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
386
+ end
387
+ end
214
388
  end
215
389
 
216
- it 'is partially scheduled' do
217
- chronologicable.should be_partially_scheduled
390
+ context 'when the time zone is blank' do
391
+ let(:time_zone) { '' }
392
+
393
+ context 'and the time zone check is enabled' do
394
+ it 'is not scheduled' do
395
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
396
+ end
397
+
398
+ it 'is partially scheduled' do
399
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
400
+ end
401
+ end
402
+
403
+ context 'and the time zone check is not enabled' do
404
+ it 'is not scheduled' do
405
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
406
+ end
407
+
408
+ it 'is partially scheduled' do
409
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
410
+ end
411
+ end
412
+ end
413
+
414
+ context 'when the time zone is set' do
415
+ let(:time_zone) { 'Alaska' }
416
+
417
+ context 'and the time zone check is enabled' do
418
+ it 'is not scheduled' do
419
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
420
+ end
421
+
422
+ it 'is partially scheduled' do
423
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
424
+ end
425
+ end
426
+
427
+ context 'and the time zone check is not enabled' do
428
+ it 'is not scheduled' do
429
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
430
+ end
431
+
432
+ it 'is partially scheduled' do
433
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
434
+ end
435
+ end
218
436
  end
219
437
 
220
438
  it 'is not included in the in progress list' do
@@ -234,7 +452,7 @@ describe Chronological::RelativeStrategy, :timecop => true do
234
452
  context 'and the ending offset is set' do
235
453
  let(:ending_offset) { 0 }
236
454
 
237
- it 'does not have a end time' do
455
+ it 'does not have an end time' do
238
456
  chronologicable.ended_at.should be_nil
239
457
  end
240
458
  end
@@ -242,7 +460,7 @@ describe Chronological::RelativeStrategy, :timecop => true do
242
460
  context 'and the ending offset is not set' do
243
461
  let(:ending_offset) { nil }
244
462
 
245
- it 'does not have a end time' do
463
+ it 'does not have an end time' do
246
464
  chronologicable.ended_at.should be_nil
247
465
  end
248
466
  end
@@ -251,12 +469,76 @@ describe Chronological::RelativeStrategy, :timecop => true do
251
469
  let(:starting_offset) { nil }
252
470
  let(:ending_offset) { nil }
253
471
 
254
- it 'is not scheduled' do
255
- chronologicable.should_not be_scheduled
472
+ context 'when the time zone is not set' do
473
+ let(:time_zone) { nil }
474
+
475
+ context 'and the time zone check is enabled' do
476
+ it 'is not scheduled' do
477
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
478
+ end
479
+
480
+ it 'is partially scheduled' do
481
+ chronologicable_with_enabled_time_zone.should_not be_partially_scheduled
482
+ end
483
+ end
484
+
485
+ context 'and the time zone check is not enabled' do
486
+ it 'is not scheduled' do
487
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
488
+ end
489
+
490
+ it 'is partially scheduled' do
491
+ chronologicable_without_enabled_time_zone.should_not be_partially_scheduled
492
+ end
493
+ end
256
494
  end
257
495
 
258
- it 'is not partially scheduled' do
259
- chronologicable.should_not be_partially_scheduled
496
+ context 'when the time zone is blank' do
497
+ let(:time_zone) { '' }
498
+
499
+ context 'and the time zone check is enabled' do
500
+ it 'is not scheduled' do
501
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
502
+ end
503
+
504
+ it 'is partially scheduled' do
505
+ chronologicable_with_enabled_time_zone.should_not be_partially_scheduled
506
+ end
507
+ end
508
+
509
+ context 'and the time zone check is not enabled' do
510
+ it 'is not scheduled' do
511
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
512
+ end
513
+
514
+ it 'is partially scheduled' do
515
+ chronologicable_without_enabled_time_zone.should_not be_partially_scheduled
516
+ end
517
+ end
518
+ end
519
+
520
+ context 'when the time zone is set' do
521
+ let(:time_zone) { 'Alaska' }
522
+
523
+ context 'and the time zone check is enabled' do
524
+ it 'is not scheduled' do
525
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
526
+ end
527
+
528
+ it 'is partially scheduled' do
529
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
530
+ end
531
+ end
532
+
533
+ context 'and the time zone check is not enabled' do
534
+ it 'is not scheduled' do
535
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
536
+ end
537
+
538
+ it 'is partially scheduled' do
539
+ chronologicable_without_enabled_time_zone.should_not be_partially_scheduled
540
+ end
541
+ end
260
542
  end
261
543
 
262
544
  it 'is not included in the in progress list' do
@@ -279,12 +561,76 @@ describe Chronological::RelativeStrategy, :timecop => true do
279
561
  context 'and the ending offset is not set' do
280
562
  let(:ending_offset) { nil }
281
563
 
282
- it 'is not scheduled' do
283
- chronologicable.should_not be_scheduled
564
+ context 'when the time zone is not set' do
565
+ let(:time_zone) { nil }
566
+
567
+ context 'and the time zone check is enabled' do
568
+ it 'is not scheduled' do
569
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
570
+ end
571
+
572
+ it 'is partially scheduled' do
573
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
574
+ end
575
+ end
576
+
577
+ context 'and the time zone check is not enabled' do
578
+ it 'is not scheduled' do
579
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
580
+ end
581
+
582
+ it 'is partially scheduled' do
583
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
584
+ end
585
+ end
284
586
  end
285
587
 
286
- it 'is partially scheduled' do
287
- chronologicable.should be_partially_scheduled
588
+ context 'when the time zone is blank' do
589
+ let(:time_zone) { '' }
590
+
591
+ context 'and the time zone check is enabled' do
592
+ it 'is not scheduled' do
593
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
594
+ end
595
+
596
+ it 'is partially scheduled' do
597
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
598
+ end
599
+ end
600
+
601
+ context 'and the time zone check is not enabled' do
602
+ it 'is not scheduled' do
603
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
604
+ end
605
+
606
+ it 'is partially scheduled' do
607
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
608
+ end
609
+ end
610
+ end
611
+
612
+ context 'when the time zone is set' do
613
+ let(:time_zone) { 'Alaska' }
614
+
615
+ context 'and the time zone check is enabled' do
616
+ it 'is not scheduled' do
617
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
618
+ end
619
+
620
+ it 'is partially scheduled' do
621
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
622
+ end
623
+ end
624
+
625
+ context 'and the time zone check is not enabled' do
626
+ it 'is not scheduled' do
627
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
628
+ end
629
+
630
+ it 'is partially scheduled' do
631
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
632
+ end
633
+ end
288
634
  end
289
635
 
290
636
  it 'is not included in the in progress list' do
@@ -299,12 +645,76 @@ describe Chronological::RelativeStrategy, :timecop => true do
299
645
  context 'and the ending offset is set' do
300
646
  let(:ending_offset) { 0 }
301
647
 
302
- it 'is not scheduled' do
303
- chronologicable.should_not be_scheduled
648
+ context 'when the time zone is not set' do
649
+ let(:time_zone) { nil }
650
+
651
+ context 'and the time zone check is enabled' do
652
+ it 'is not scheduled' do
653
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
654
+ end
655
+
656
+ it 'is partially scheduled' do
657
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
658
+ end
659
+ end
660
+
661
+ context 'and the time zone check is not enabled' do
662
+ it 'is not scheduled' do
663
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
664
+ end
665
+
666
+ it 'is partially scheduled' do
667
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
668
+ end
669
+ end
304
670
  end
305
671
 
306
- it 'is partially scheduled' do
307
- chronologicable.should be_partially_scheduled
672
+ context 'when the time zone is blank' do
673
+ let(:time_zone) { '' }
674
+
675
+ context 'and the time zone check is enabled' do
676
+ it 'is not scheduled' do
677
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
678
+ end
679
+
680
+ it 'is partially scheduled' do
681
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
682
+ end
683
+ end
684
+
685
+ context 'and the time zone check is not enabled' do
686
+ it 'is not scheduled' do
687
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
688
+ end
689
+
690
+ it 'is partially scheduled' do
691
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
692
+ end
693
+ end
694
+ end
695
+
696
+ context 'when the time zone is set' do
697
+ let(:time_zone) { 'Alaska' }
698
+
699
+ context 'and the time zone check is enabled' do
700
+ it 'is not scheduled' do
701
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
702
+ end
703
+
704
+ it 'is partially scheduled' do
705
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
706
+ end
707
+ end
708
+
709
+ context 'and the time zone check is not enabled' do
710
+ it 'is not scheduled' do
711
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
712
+ end
713
+
714
+ it 'is partially scheduled' do
715
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
716
+ end
717
+ end
308
718
  end
309
719
 
310
720
  it 'is not included in the in progress list' do
@@ -327,12 +737,76 @@ describe Chronological::RelativeStrategy, :timecop => true do
327
737
  context 'and the ending offset is not set' do
328
738
  let(:ending_offset) { nil }
329
739
 
330
- it 'is not scheduled' do
331
- chronologicable.should_not be_scheduled
740
+ context 'when the time zone is not set' do
741
+ let(:time_zone) { nil }
742
+
743
+ context 'and the time zone check is enabled' do
744
+ it 'is not scheduled' do
745
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
746
+ end
747
+
748
+ it 'is partially scheduled' do
749
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
750
+ end
751
+ end
752
+
753
+ context 'and the time zone check is not enabled' do
754
+ it 'is not scheduled' do
755
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
756
+ end
757
+
758
+ it 'is partially scheduled' do
759
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
760
+ end
761
+ end
762
+ end
763
+
764
+ context 'when the time zone is blank' do
765
+ let(:time_zone) { '' }
766
+
767
+ context 'and the time zone check is enabled' do
768
+ it 'is not scheduled' do
769
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
770
+ end
771
+
772
+ it 'is partially scheduled' do
773
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
774
+ end
775
+ end
776
+
777
+ context 'and the time zone check is not enabled' do
778
+ it 'is not scheduled' do
779
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
780
+ end
781
+
782
+ it 'is partially scheduled' do
783
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
784
+ end
785
+ end
332
786
  end
333
787
 
334
- it 'is partially scheduled' do
335
- chronologicable.should be_partially_scheduled
788
+ context 'when the time zone is set' do
789
+ let(:time_zone) { 'Alaska' }
790
+
791
+ context 'and the time zone check is enabled' do
792
+ it 'is not scheduled' do
793
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
794
+ end
795
+
796
+ it 'is partially scheduled' do
797
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
798
+ end
799
+ end
800
+
801
+ context 'and the time zone check is not enabled' do
802
+ it 'is not scheduled' do
803
+ chronologicable_without_enabled_time_zone.should_not be_scheduled
804
+ end
805
+
806
+ it 'is partially scheduled' do
807
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
808
+ end
809
+ end
336
810
  end
337
811
 
338
812
  it 'is not included in the in progress list' do
@@ -347,12 +821,76 @@ describe Chronological::RelativeStrategy, :timecop => true do
347
821
  context 'and the ending offset is set' do
348
822
  let(:ending_offset) { 0 }
349
823
 
350
- it 'is scheduled' do
351
- chronologicable.should be_scheduled
824
+ context 'when the time zone is not set' do
825
+ let(:time_zone) { nil }
826
+
827
+ context 'and the time zone check is enabled' do
828
+ it 'is not scheduled' do
829
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
830
+ end
831
+
832
+ it 'is partially scheduled' do
833
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
834
+ end
835
+ end
836
+
837
+ context 'and the time zone check is not enabled' do
838
+ it 'is not scheduled' do
839
+ chronologicable_without_enabled_time_zone.should be_scheduled
840
+ end
841
+
842
+ it 'is partially scheduled' do
843
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
844
+ end
845
+ end
846
+ end
847
+
848
+ context 'when the time zone is blank' do
849
+ let(:time_zone) { '' }
850
+
851
+ context 'and the time zone check is enabled' do
852
+ it 'is not scheduled' do
853
+ chronologicable_with_enabled_time_zone.should_not be_scheduled
854
+ end
855
+
856
+ it 'is partially scheduled' do
857
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
858
+ end
859
+ end
860
+
861
+ context 'and the time zone check is not enabled' do
862
+ it 'is not scheduled' do
863
+ chronologicable_without_enabled_time_zone.should be_scheduled
864
+ end
865
+
866
+ it 'is partially scheduled' do
867
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
868
+ end
869
+ end
352
870
  end
353
871
 
354
- it 'is partially scheduled' do
355
- chronologicable.should be_partially_scheduled
872
+ context 'when the time zone is set' do
873
+ let(:time_zone) { 'Alaska' }
874
+
875
+ context 'and the time zone check is enabled' do
876
+ it 'is not scheduled' do
877
+ chronologicable_with_enabled_time_zone.should be_scheduled
878
+ end
879
+
880
+ it 'is partially scheduled' do
881
+ chronologicable_with_enabled_time_zone.should be_partially_scheduled
882
+ end
883
+ end
884
+
885
+ context 'and the time zone check is not enabled' do
886
+ it 'is not scheduled' do
887
+ chronologicable_without_enabled_time_zone.should be_scheduled
888
+ end
889
+
890
+ it 'is partially scheduled' do
891
+ chronologicable_without_enabled_time_zone.should be_partially_scheduled
892
+ end
893
+ end
356
894
  end
357
895
 
358
896
  it 'is included in the in progress list' do
@@ -15,6 +15,12 @@ ActiveRecord::Base.connection.create_database postgres_connection_options[:datab
15
15
 
16
16
  ActiveRecord::Base.establish_connection postgres_connection_options
17
17
 
18
+ ActiveRecord::Base.connection.create_table :chronologicable_strategy_classes do |t|
19
+ t.integer :starting_offset
20
+ t.integer :ending_offset
21
+ t.datetime :base_of_offset
22
+ end
23
+
18
24
  ActiveRecord::Base.connection.create_table :base_chronologicables do |t|
19
25
  t.datetime :started_at
20
26
  t.datetime :ended_at
@@ -26,12 +32,19 @@ ActiveRecord::Base.connection.create_table :relative_chronologicables do |t|
26
32
  t.datetime :base_datetime_utc
27
33
  end
28
34
 
35
+ ActiveRecord::Base.connection.create_table :relative_chronologicable_with_time_zones do |t|
36
+ t.integer :starting_offset
37
+ t.integer :ending_offset
38
+ t.datetime :base_datetime_utc
39
+ t.string :time_zone
40
+ end
41
+
29
42
  ActiveRecord::Base.connection.create_table :absolute_chronologicables do |t|
30
43
  t.datetime :started_at_utc
31
44
  t.datetime :ended_at_utc
32
45
  end
33
46
 
34
- ActiveRecord::Base.connection.create_table :chronologicable_with_time_zones do |t|
47
+ ActiveRecord::Base.connection.create_table :absolute_chronologicable_with_time_zones do |t|
35
48
  t.datetime :started_at_utc
36
49
  t.datetime :ended_at_utc
37
50
  t.string :time_zone
@@ -39,9 +52,11 @@ end
39
52
 
40
53
  RSpec.configure do |config|
41
54
  config.before(:each) do
55
+ ActiveRecord::Base.connection.execute 'DELETE FROM chronologicable_strategy_classes'
42
56
  ActiveRecord::Base.connection.execute 'DELETE FROM base_chronologicables'
43
57
  ActiveRecord::Base.connection.execute 'DELETE FROM relative_chronologicables'
58
+ ActiveRecord::Base.connection.execute 'DELETE FROM relative_chronologicable_with_time_zones'
44
59
  ActiveRecord::Base.connection.execute 'DELETE FROM absolute_chronologicables'
45
- ActiveRecord::Base.connection.execute 'DELETE FROM chronologicable_with_time_zones'
60
+ ActiveRecord::Base.connection.execute 'DELETE FROM absolute_chronologicable_with_time_zones'
46
61
  end
47
62
  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.0beta1
4
+ version: 1.0.0beta2
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-10-29 00:00:00.000000000 Z
13
+ date: 2012-10-30 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec