hoodoo 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWM1YWFkNDAxZGQ1MGUyZTNmNTIyZjk3MGYxMzNmYjRlYzZiYmRmYw==
4
+ ZDIzZWU2OWE2MmEyY2RiZjRjMDk1OTlmZGFhM2YyNzA3ZTE0NDQ5MA==
5
5
  data.tar.gz: !binary |-
6
- YjRmZDVjYjk1YzBkMjU2ODczMGU3YTJjYzZhMjdjYTE1ZDgyYzE1NA==
6
+ MDc4NDgwNjM1MDcwZmE3OWE0NTAzYjExN2Y0MzMxYmJhYzQyZmI0OQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTRiOGNkNjYzOTE3YjJkYWE0N2M4ZjdkZTllM2JhMTkwMTFjMTM1NWJjYTU5
10
- YTVkMThjYjZkMmU3ZGJiMTk0NzM1YmRlNWZiZTk4ZTgxYTQwMGNlMTE2YjAy
11
- ZTc4OTNiNGY5Mjg3MDc0NGI1MDg5OTg2MmU5YzFlNzczZTM1NTA=
9
+ M2IyM2U5ZGI3NjBiMzRhYjUyOTBhZDk5ODE4YmY2N2RlOGUyNTA0ODgxODdk
10
+ N2Y2OGYxNTE0NjYwOWRiMmZkOGJkMTUyMzQ2Yzk1YmE0ZGY0ZTE2ODkyN2Nj
11
+ MDg3NjQwZjI0NTUxODRhODIzNTFhOTg3Yzg1MzFiYzk0OWYwNTE=
12
12
  data.tar.gz: !binary |-
13
- ZmFiZTNiZDZhZGI4NzA0NzAyYWM4ZTI3YTAxM2E5OTRlYzNlN2NkZWM4ZDUx
14
- Y2NkNmJmZTA4Njg3N2EyNmQwMmY3YThmOGM4NWFiNmI3MTRmMDEzNWQ4MmFj
15
- ZjI3NTJmNzVmYTgxOGNkYWEwOTA3OWExNGFlZDkzYzQzMDFmZmI=
13
+ MGU2ZDA2Yzg3NmRmNGE3MTRiMzczOWU0N2JmZDc0ZmFmNmJlNTc5NGE3ZWJl
14
+ YmY2Mjk1YWZkNzY2NjEwNjIwYTFiYzhkM2Y0MTExZmVjMmRmOWIxNDRkOGY5
15
+ OWE3MjZkODUwYjEzZjM4MzU3MWQ1MDNjYTk5ZmNiMTA4YjE2MzI=
@@ -310,6 +310,13 @@ module Hoodoo
310
310
  #
311
311
  module ManuallyDated
312
312
 
313
+ # Rounding resolution, in terms of number of decimal places to which
314
+ # seconds are rounded. Excessive accuracy makes for difficult, large
315
+ # indices in the database and may fall foul of system / database
316
+ # clock accuracy mismatches.
317
+ #
318
+ SECONDS_DECIMAL_PLACES = 2 # An Integer from 0 upwards
319
+
313
320
  # In order for indices to work properly on +effective_end+ dates, +NULL+
314
321
  # values cannot be permitted as SQL +NULL+ is magic and means "has no
315
322
  # value", so such a value in a column prohibits indexing.
@@ -330,14 +337,7 @@ module Hoodoo
330
337
  # ActiveRecord::Base.connection.quoted_date( Hoodoo::ActiveRecord::ManuallyDated::DATE_MAXIMUM )
331
338
  # # => returns "9999-12-31 23:59:59.000000" for PostgreSQL 9.4.
332
339
  #
333
- DATE_MAXIMUM = Time.parse( '9999-12-31T23:59:59.0Z' )
334
-
335
- # Rounding resolution, in terms of number of decimal places to which
336
- # seconds are rounded. Excessive accuracy makes for difficult, large
337
- # indices in the database and may fall foul of system / database
338
- # clock accuracy mismatches.
339
- #
340
- SECONDS_DECIMAL_PLACES = 2 # An Integer from 0 upwards
340
+ DATE_MAXIMUM = Time.parse( '9999-12-31T23:59:59.0Z' ).round( SECONDS_DECIMAL_PLACES )
341
341
 
342
342
  # Instantiates this module when it is included.
343
343
  #
@@ -408,6 +408,10 @@ module Hoodoo
408
408
  def manual_dating_enabled
409
409
  self.nz_co_loyalty_hoodoo_manually_dated = true
410
410
 
411
+ rounder = Proc.new do | timelike |
412
+ timelike.to_time.round( SECONDS_DECIMAL_PLACES )
413
+ end
414
+
411
415
  # This is the 'tightest'/innermost callback available for creation.
412
416
  # Intentionally have nothing for updates/deletes as the high level
413
417
  # API here must be used; we don't want to introduce any more magic.
@@ -419,6 +423,13 @@ module Hoodoo
419
423
  self.updated_at ||= now
420
424
  self.effective_start ||= self.created_at
421
425
  self.effective_end ||= DATE_MAXIMUM
426
+
427
+ %i{ created_at updated_at effective_start effective_end }.each do | attr |
428
+ value = self.send( attr )
429
+ rounded = value.to_time.round( SECONDS_DECIMAL_PLACES )
430
+
431
+ self.send( "#{ attr }=", rounded ) if rounded != value
432
+ end
422
433
  end
423
434
 
424
435
  # This is very similar to the UUID mixin, but works on the 'uuid'
@@ -12,6 +12,6 @@ module Hoodoo
12
12
  # The Hoodoo gem version. If this changes, ensure that the date in
13
13
  # "hoodoo.gemspec" is correct and run "bundle install" (or "update").
14
14
  #
15
- VERSION = '1.2.1'
15
+ VERSION = '1.2.2'
16
16
 
17
17
  end
@@ -643,6 +643,38 @@ describe Hoodoo::ActiveRecord::ManuallyDated do
643
643
  end
644
644
  end
645
645
 
646
+ context 'inbound date-time rounding' do
647
+ it 'rounds ActiveRecord-assigned timestamps' do
648
+ record = RSpecModelManualDateTest.new( {
649
+ :data => Hoodoo::UUID.generate()
650
+ } )
651
+
652
+ record.save!
653
+
654
+ %i{ created_at updated_at effective_start effective_end }.each do | attr |
655
+ value = record.send( attr )
656
+ expect( value.utc.round( Hoodoo::ActiveRecord::ManuallyDated::SECONDS_DECIMAL_PLACES ) ).to eq( value )
657
+ end
658
+ end
659
+
660
+ it 'rounds explicitly assigned timestamps' do
661
+ record = RSpecModelManualDateTest.new( {
662
+ :data => Hoodoo::UUID.generate(),
663
+ :created_at => Time.now - 2.seconds,
664
+ :updated_at => Time.now - 1.seconds,
665
+ :effective_start => Time.now - 2.seconds,
666
+ :effective_end => Time.now - 1.seconds
667
+ } )
668
+
669
+ record.save!
670
+
671
+ %i{ created_at updated_at effective_start effective_end }.each do | attr |
672
+ value = record.send( attr )
673
+ expect( value.utc.round( Hoodoo::ActiveRecord::ManuallyDated::SECONDS_DECIMAL_PLACES ) ).to eq( value )
674
+ end
675
+ end
676
+ end
677
+
646
678
  # Rapid updates within configured date resolution might not be resolvable
647
679
  # as individual history items via API, but they should still exist and
648
680
  # things like uuid/start/end uniqueness constraint columns ought to still
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hoodoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Loyalty New Zealand