hoodoo 1.16.1 → 1.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c9903a7189fc118fdbc3deae1277da2602c64b9
4
- data.tar.gz: b5b04be6a1c82e1958cf70863270a282256a51bc
3
+ metadata.gz: a11d0bed3dc977f5aab127f4ed139e715a9f2431
4
+ data.tar.gz: 42706658a33e920162e734ad3f0891a8e703e845
5
5
  SHA512:
6
- metadata.gz: 333ed5e667ade4ab94ee3f16dfb37e84351ab8678a09d5ffc325021b07e56e6bd3c95f820cec9ede6586c542de8abcad1746418f99e17c1ded693afb873efc51
7
- data.tar.gz: 912f44dce0110b695c2815f969aa3a6a00e5ad88caf48e65578cb6097ef45f91446b59748523a8d8a65770b0d60f203f462ad5b479382feee4058e5e7a96d2a7
6
+ metadata.gz: d3f795bff6b580fe090f46a624461fac52939941e18564074e68c37e5d3fc757c5da9a34efbbad6ce3c435e0701c021e07c8a157f77f0e268541bbe78180c1f9
7
+ data.tar.gz: f3fec8a2305e6c815d309c0442724f4fee7a6541606058421a1e473797f50e666dbe40b7540cc34cbb12baa1e8af2cdaa2052c13601e69b182a303feca31bc7e
@@ -29,7 +29,7 @@ module Hoodoo
29
29
  # return a single line string representing the "flattened" log data.
30
30
  #
31
31
  def flatten( log_level, component, code, data )
32
- "#{ log_level.to_s.upcase } [#{ Time.now.iso8601( 6 ) }] #{ component } - #{ code }: #{ data.inspect }"
32
+ "#{ log_level.to_s.upcase } [#{ Hoodoo::Utilities.standard_datetime( Time.now ) }] #{ component } - #{ code }: #{ data.inspect }"
33
33
  end
34
34
  end
35
35
  end
@@ -114,7 +114,7 @@ module Hoodoo
114
114
  target.merge!( {
115
115
  'id' => uuid,
116
116
  'kind' => kind,
117
- 'created_at' => Time.parse( created_at.to_s ).utc.iso8601
117
+ 'created_at' => Hoodoo::Utilities.standard_datetime( created_at.to_datetime )
118
118
  } )
119
119
 
120
120
  target[ 'language' ] = language if self.is_internationalised?()
@@ -160,7 +160,7 @@ module Hoodoo; module Services
160
160
  #
161
161
  DEFAULT_TEST_SESSION.from_h!( {
162
162
  'session_id' => '01234567890123456789012345678901',
163
- 'expires_at' => ( Time.now + 172800 ).utc.iso8601,
163
+ 'expires_at' => Hoodoo::Utilities.standard_datetime( Time.now + 172800 ),
164
164
  'caller_version' => 1,
165
165
  'caller_id' => 'c5ea12fb7f414a46850e73ee1bf6d95e',
166
166
  'caller_identity_name' => 'c5ea12fb7f414a46850e73ee1bf6d95e',
@@ -484,7 +484,7 @@ module Hoodoo
484
484
 
485
485
  ).each do | property |
486
486
  value = self.send( property )
487
- hash[ property ] = value.iso8601() unless value.nil?
487
+ hash[ property ] = Hoodoo::Utilities.standard_datetime( value ) unless value.nil?
488
488
  end
489
489
 
490
490
  %w(
@@ -340,6 +340,16 @@ module Hoodoo
340
340
  return value.is_a?( ::Date ) && value
341
341
  end
342
342
 
343
+ # Returns an ISO 8601 String equivalent of the given Time, Date or
344
+ # DateTime instance as a full date-time with UTC timezone, with
345
+ # "standard high precision" (for rendeirng consistency), subject to
346
+ # Ruby port / OS support abilities. At the time of writing, 6 decimal
347
+ # places are included.
348
+ #
349
+ def self.standard_datetime( date_or_time_or_date_time )
350
+ date_or_time_or_date_time.to_time.utc.iso8601( 6 )
351
+ end
352
+
343
353
  # Returns an ISO 8601 String equivalent of the given Time or DateTime
344
354
  # instance, with nanosecond precision (subject to Ruby port / OS support).
345
355
  # This is nothing more than a standardised central interface on calling
@@ -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.16.1'
15
+ VERSION = '1.17.0'
16
16
 
17
17
  end
@@ -382,7 +382,7 @@ describe Hoodoo::ActiveRecord::Secure do
382
382
  expect(TestPresenterSecure.render_in(@context, data, options)).to eq({
383
383
  'id' => u,
384
384
  'kind' => 'TestPresenterSecure',
385
- 'created_at' => t.iso8601,
385
+ 'created_at' => Hoodoo::Utilities.standard_datetime( t ),
386
386
  'language' => 'en-nz',
387
387
  'three' => 'default_three',
388
388
  'secured_with' => {
@@ -403,7 +403,7 @@ describe Hoodoo::ActiveRecord::Secure do
403
403
  expect(TestPresenterSecure.render_in(@context, data, options)).to eq({
404
404
  'id' => u,
405
405
  'kind' => 'TestPresenterSecure',
406
- 'created_at' => t.iso8601,
406
+ 'created_at' => Hoodoo::Utilities.standard_datetime( t ),
407
407
  'language' => 'en-nz',
408
408
  'three' => 'default_three',
409
409
  'secured_with' => {
@@ -423,7 +423,7 @@ describe Hoodoo::ActiveRecord::Secure do
423
423
  expect(TestPresenterSecure.render_in(@context, data, options)).to eq({
424
424
  'id' => u,
425
425
  'kind' => 'TestPresenterSecure',
426
- 'created_at' => t.iso8601,
426
+ 'created_at' => Hoodoo::Utilities.standard_datetime( t ),
427
427
  'language' => 'en-nz',
428
428
  'three' => 'default_three',
429
429
  'secured_with' => {
@@ -28,10 +28,10 @@ class RSpecClientTestSessionImplementation < Hoodoo::Services::Implementation
28
28
  #
29
29
  context.response.set_resource(
30
30
  'id' => session_id,
31
- 'created_at' => Time.now.utc.iso8601,
31
+ 'created_at' => Hoodoo::Utilities.standard_datetime( Time.now ),
32
32
  'kind' => 'RSpecClientTestSession',
33
33
  'caller_id' => context.request.body[ 'caller_id' ],
34
- 'expires_at' => ( Time.now.utc + 24*60*60 ).iso8601
34
+ 'expires_at' => Hoodoo::Utilities.standard_datetime( Time.now + 24 * 60 * 60 )
35
35
  )
36
36
  end
37
37
  end
@@ -153,7 +153,7 @@ class RSpecClientTestTargetImplementation < Hoodoo::Services::Implementation
153
153
  context.request.body.try( :[], 'id' ) ||
154
154
  Hoodoo::UUID.generate(),
155
155
 
156
- 'created_at' => Time.now.utc.iso8601,
156
+ 'created_at' => Hoodoo::Utilities.standard_datetime( Time.now ),
157
157
  'kind' => 'RSpecClientTestTarget',
158
158
  'language' => context.request.locale,
159
159
 
@@ -95,7 +95,7 @@ describe Hoodoo::Data::Resources::Caller do
95
95
  expect(json).to eq(
96
96
  {
97
97
  'id' => id,
98
- 'created_at' => created_at.utc.iso8601,
98
+ 'created_at' => Hoodoo::Utilities.standard_datetime( created_at ),
99
99
  'kind' => 'Caller',
100
100
  "name" => "Test Caller",
101
101
  "identity" => {
@@ -144,7 +144,7 @@ describe Hoodoo::Data::Resources::Caller do
144
144
  expect(json).to eq(
145
145
  {
146
146
  'id' => id,
147
- 'created_at' => created_at.utc.iso8601,
147
+ 'created_at' => Hoodoo::Utilities.standard_datetime( created_at ),
148
148
  'kind' => 'Caller',
149
149
  "identity" => {},
150
150
  "permissions" => { "resources" => {} },
@@ -681,7 +681,7 @@ describe '#schema' do
681
681
  )).to eq({
682
682
  'id' => uuid,
683
683
  'kind' => 'World',
684
- 'created_at' => time.utc.iso8601,
684
+ 'created_at' => Hoodoo::Utilities.standard_datetime( time ),
685
685
  'language' => 'en-gb',
686
686
  'errors_id' => data['errors_id'],
687
687
  'test_tags' => 'foo,bar,baz',
@@ -797,7 +797,7 @@ describe '#schema' do
797
797
  expect(TestPresenter5.render_in(@con, data, options)).to eq({
798
798
  'id' => u,
799
799
  'kind' => 'TestPresenter5',
800
- 'created_at' => t.iso8601,
800
+ 'created_at' => Hoodoo::Utilities.standard_datetime( t ),
801
801
  'language' => 'de',
802
802
  'three' => 'default_three'
803
803
  })
@@ -811,7 +811,7 @@ describe '#schema' do
811
811
  expect(TestPresenter5.render_in(@con, data, options)).to eq({
812
812
  'id' => u,
813
813
  'kind' => 'TestPresenter5',
814
- 'created_at' => t.iso8601,
814
+ 'created_at' => Hoodoo::Utilities.standard_datetime( t ),
815
815
  'language' => 'fr',
816
816
  'three' => 'default_three'
817
817
  })
@@ -830,7 +830,7 @@ describe '#schema' do
830
830
  expect(TestPresenter5.render_in(@con, data, options)).to eq({
831
831
  'id' => u,
832
832
  'kind' => 'TestPresenter5',
833
- 'created_at' => t.iso8601,
833
+ 'created_at' => Hoodoo::Utilities.standard_datetime( t ),
834
834
  'language' => 'de',
835
835
  'three' => 'default_three',
836
836
  '_embed' => {
@@ -853,7 +853,7 @@ describe '#schema' do
853
853
  expect(TestPresenter5.render_in(@con, data, options)).to eq({
854
854
  'id' => u,
855
855
  'kind' => 'TestPresenter5',
856
- 'created_at' => t.iso8601,
856
+ 'created_at' => Hoodoo::Utilities.standard_datetime( t ),
857
857
  'language' => 'de',
858
858
  'three' => 'default_three',
859
859
  '_reference' => {
@@ -87,7 +87,7 @@ describe Hoodoo::Presenters::Array do
87
87
  'an_array' => [
88
88
  {},
89
89
  { 'an_integer' => 2 },
90
- { 'a_datetime' => Time.now.iso8601 }
90
+ { 'a_datetime' => DateTime.now.iso8601 }
91
91
  ]
92
92
  }
93
93
 
@@ -63,7 +63,7 @@ describe Hoodoo::Services::Session do
63
63
  'caller_id' => '0987',
64
64
  'caller_version' => 2,
65
65
 
66
- 'created_at' => s.created_at.iso8601,
66
+ 'created_at' => Hoodoo::Utilities.standard_datetime( s.created_at ),
67
67
 
68
68
  'identity' => { 'foo' => 'foo', 'bar' => 'bar' },
69
69
  'scoping' => { 'baz' => [ 'foo', 'bar', 'baz' ] },
@@ -81,8 +81,8 @@ describe Hoodoo::Services::Session do
81
81
  'caller_id' => '0987',
82
82
  'caller_version' => 2,
83
83
 
84
- 'created_at' => c.iso8601,
85
- 'expires_at' => e.iso8601,
84
+ 'created_at' => Hoodoo::Utilities.standard_datetime( c ),
85
+ 'expires_at' => Hoodoo::Utilities.standard_datetime( e ),
86
86
 
87
87
  'identity' => { 'foo' => 'foo', 'bar' => 'bar' },
88
88
  'scoping' => { 'baz' => [ 'foo', 'bar', 'baz' ] },
@@ -94,8 +94,8 @@ describe Hoodoo::Services::Session do
94
94
  expect( s.session_id ).to eq( '1234' )
95
95
  expect( s.caller_id ).to eq( '0987' )
96
96
  expect( s.caller_version ).to eq( 2 )
97
- expect( s.created_at ).to eq( Time.parse( c.iso8601 ) )
98
- expect( s.expires_at ).to eq( Time.parse( e.iso8601 ) )
97
+ expect( s.created_at ).to eq( Time.parse( Hoodoo::Utilities.standard_datetime( c ) ) )
98
+ expect( s.expires_at ).to eq( Time.parse( Hoodoo::Utilities.standard_datetime( e ) ) )
99
99
  expect( s.identity.foo ).to eq( 'foo' )
100
100
  expect( s.identity.bar ).to eq( 'bar' )
101
101
  expect( s.scoping.baz ).to eq( [ 'foo', 'bar', 'baz' ] )
@@ -131,8 +131,8 @@ describe Hoodoo::Services::Session do
131
131
  s2 = described_class.new
132
132
  expect( s2.load_from_store!( s1.session_id ) ).to eq( :ok )
133
133
 
134
- expect( s2.created_at ).to eq( Time.parse( s1.created_at.iso8601 ) )
135
- expect( s2.expires_at ).to eq( Time.parse( s1.expires_at.iso8601 ) )
134
+ expect( s2.created_at ).to eq( Time.parse( Hoodoo::Utilities.standard_datetime( s1.created_at ) ) )
135
+ expect( s2.expires_at ).to eq( Time.parse( Hoodoo::Utilities.standard_datetime( s1.expires_at ) ) )
136
136
  expect( s2.session_id ).to eq( s1.session_id )
137
137
  expect( s2.memcached_host ).to be_nil
138
138
  expect( s2.caller_id ).to eq( s1.caller_id )
@@ -321,7 +321,7 @@ describe Hoodoo::Services::Session do
321
321
 
322
322
  expect( s ).to receive( :to_h ).and_wrap_original do | obj, args |
323
323
  h = obj.call( *args )
324
- h[ 'expires_at' ] = ( Time.now - 1 ).utc.iso8601
324
+ h[ 'expires_at' ] = Hoodoo::Utilities.standard_datetime( Time.now - 1 )
325
325
  h
326
326
  end
327
327
 
@@ -485,6 +485,38 @@ describe Hoodoo::Utilities do
485
485
  end
486
486
  end
487
487
 
488
+ describe '#standard_iso8601' do
489
+ before :each do
490
+ @old_tz = ENV[ 'TZ' ]
491
+ ENV[ 'TZ' ] = 'EST'
492
+ end
493
+
494
+ after :each do
495
+ @old_tz.blank? ? ENV.delete( 'TZ' ) : ENV[ 'TZ' ] = @old_tz
496
+ end
497
+
498
+ it 'accepts a non-UTC Time and renders a UTC date-time' do
499
+ now = Time.new( 2017, 7, 28, 8, 41, 15 ) + 0.123456789
500
+ iso = now.utc.iso8601( 6 )
501
+
502
+ expect( Hoodoo::Utilities.standard_datetime( now ) ).to eq( iso )
503
+ end
504
+
505
+ it 'accepts a non-UTC Date and renders a UTC date-time' do
506
+ now = Date.new( 2017, 7, 28 )
507
+ iso = now.to_time.utc.iso8601( 6 )
508
+
509
+ expect( Hoodoo::Utilities.standard_datetime( now ) ).to eq( iso )
510
+ end
511
+
512
+ it 'accepts a non-UTC DateTime and renders a UTC date-time' do
513
+ now = DateTime.new( 2017, 7, 28, 8, 41, 15 ) + 0.123456789
514
+ iso = now.to_time.utc.iso8601( 6 )
515
+
516
+ expect( Hoodoo::Utilities.standard_datetime( now ) ).to eq( iso )
517
+ end
518
+ end
519
+
488
520
  describe '#nanosecond_iso8601' do
489
521
  it 'should convert DateTime to a nanosecond precision String' do
490
522
  now = DateTime.now()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hoodoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.16.1
4
+ version: 1.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Loyalty New Zealand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-11 00:00:00.000000000 Z
11
+ date: 2017-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dalli