datetime_helper 1.0.2 → 1.0.3

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
- NmZjYmI4OWEwZTBhYzk4ZDBiYTVmZTBmZDhhZGM3N2NiZDlkZTU0OQ==
4
+ OTVhN2M1ZWU0MGQ3OGM1ZDlmNzBlZGFjOTNkOWI1NzU0MmUwMzE1Ng==
5
5
  data.tar.gz: !binary |-
6
- NTJlOGNmYzUzNTU3NTQ4ZWUyNDg3MDMzY2QzZTRiNDU0MTQ3NGEwZQ==
6
+ NmVjMjkyNTJhNzFlYzNiNDcwYWFjZWQxN2VjZWI5ZjRkMjUzMmEzMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NzFiY2VlODg2YzdhNzQ2NmZmNzY0ODRlMDIyODcyNWRlMjkyZmU0NjhiOWVk
10
- NjNjNGFmMGU5MWYzZjdjNmU0Yzg1ZDQ3MmRlMmJlNzJhYjIxZjQwNDgwMjY0
11
- NGYyMzZjNTVhNWI3ZDYzNWIxZWY4NWYzOTkwNTA1YTgzZTg5Y2Y=
9
+ MWY5ZmJhODIwZDg3ZTAyMzQwYWE0MTI1MmY2Zjg0YTY3MGM5NzA0NGViMWQ0
10
+ MGUyMmI4ODg1NzVlNDcwNjBiZGNmMjYyNDVkODAwMzk2NTgwY2I5ODcyNDQ0
11
+ NGFjNjIxOTEzN2RkYTExMDljZTIxY2E1NmZlNGIzNzY5MWQ4OTY=
12
12
  data.tar.gz: !binary |-
13
- OGQ1MWRhNjZlNjMyYzFiMTFiY2ViMTNiMWViZWNjZjA0YTI1Y2ZkZjE5Yzdi
14
- NmIwMWRmOTY1YjhhNmE5ZTAzMzQyYjJhYmUxYTRiOTM4NGI5NWNlM2VmMGZk
15
- MDMyZjRkNmZkNzdmYTkzYTg4ZDAzNmJjNjliMmJlNzkyMjQ5Y2U=
13
+ ODE5MmVkMWJjNzA5ZmE0MzU2MDRkOWIxZjRiNWVjOGE4NzY1MjY0N2YwMDVh
14
+ MDVhY2I1NjViYzY5NDhkM2ExMGIyYzVmZTM5ODg4ZjA5M2RlNDRiZDkwYzJl
15
+ MzM0M2UwNWY1MTk0ODU3NWE2YWE1ODcyNzkxOTFlYzkwMjM2ODY=
@@ -11,7 +11,7 @@ module DatetimeHelper
11
11
  # Enforces that a Date is serialized as iso8601 format
12
12
  def enforce_iso8601_date(attribute)
13
13
  define_method(attribute) do
14
- object.send(attribute).iso8601 unless object.send(attribute).nil?
14
+ object.send(attribute).strftime('%F') unless object.send(attribute).nil?
15
15
  end
16
16
  end
17
17
 
@@ -1,3 +1,3 @@
1
1
  module DatetimeHelper
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -3,18 +3,20 @@ require "datetime_helper/active_model_serialiser"
3
3
 
4
4
  class TestSerialiser < ActiveModel::Serializer
5
5
  extend DatetimeHelper::Serialisers
6
- attributes :updated_at, :enabled_date
6
+ attributes :updated_at, :enabled_date, :enabled_date_time
7
7
 
8
8
  enforce_zulu_time :updated_at
9
9
  enforce_iso8601_date :enabled_date
10
+ enforce_iso8601_date :enabled_date_time
10
11
  end
11
12
 
12
13
  class TestItemNoTime
13
14
  include ActiveModel::SerializerSupport
14
- attr_reader :updated_at, :enabled_date
15
+ attr_reader :updated_at, :enabled_date, :enabled_date_time
15
16
  def initialize(options = {})
16
17
  @updated_at = nil
17
18
  @enabled_date = nil
19
+ @enabled_date_time = nil
18
20
  end
19
21
  end
20
22
 
@@ -22,6 +24,7 @@ class TestItem < TestItemNoTime
22
24
  def initialize(options = {})
23
25
  @updated_at = options[:updated_at] || Time.now.utc
24
26
  @enabled_date = options[:enabled_date] || Time.now.to_date
27
+ @enabled_date_time = options[:enabled_date_time] || Time.now
25
28
  end
26
29
  end
27
30
 
@@ -55,4 +58,14 @@ describe DatetimeHelper::Serialisers do
55
58
  it { expect(subject[:enabled_date]).to be_nil}
56
59
  end
57
60
 
61
+ context 'with a date-time' do
62
+ let(:item) { TestItem.new }
63
+ it { expect(subject[:enabled_date_time]).to be_an_iso_formatted_date }
64
+ end
65
+
66
+ context 'with a nil date-time' do
67
+ let(:item) { TestItemNoTime.new }
68
+ it { expect(subject[:enabled_date_time]).to be_nil}
69
+ end
70
+
58
71
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datetime_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - davesag
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-18 00:00:00.000000000 Z
11
+ date: 2015-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec