Fix date formatting to include milliseconds, drop virtus

This commit is contained in:
Steven Bazyl 2015-07-24 22:36:01 -07:00
parent 64852feb47
commit 297db0eb66
3 changed files with 7 additions and 4 deletions

View File

@ -27,5 +27,4 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'googleauth', '~> 0.2'
spec.add_runtime_dependency 'thor', '~> 0.19'
spec.add_runtime_dependency 'memoist', '~> 0.11'
spec.add_runtime_dependency 'virtus', '~> 1.0'
end

View File

@ -14,8 +14,8 @@
require 'representable/json'
require 'representable/json/hash'
require 'representable/coercion'
require 'base64'
require 'date'
module Google
module Apis
@ -72,6 +72,11 @@ module Google
options[:render_filter] = ->(value, _doc, *_args) { Base64.urlsafe_encode64(value) }
options[:parse_filter] = ->(fragment, _doc, *_args) { Base64.urlsafe_decode64(fragment) }
end
if options[:type] == DateTime
options[:render_filter] = ->(value, _doc, *_args) { value.is_a?(DateTime) ? value.rfc3339(3) : value.to_s }
options[:parse_filter] = ->(fragment, _doc, *_args) { DateTime.parse(fragment) }
end
options[:render_nil] = true
options[:getter] = getter_fn(name)
options[:if] = if_fn(name)
@ -114,7 +119,6 @@ module Google
# @see https://github.com/apotonick/representable
class JsonRepresentation < Representable::Decorator
include Representable::JSON
include Representable::Coercion
feature JsonRepresentationSupport
end
end

View File

@ -79,7 +79,7 @@ RSpec.describe Google::Apis::Core::JsonRepresentation do
end
it 'serializes date values' do
expect(json).to be_json_eql(%("2015-05-01T12:00:00+00:00")).at_path('dateValue')
expect(json).to be_json_eql(%("2015-05-01T12:00:00.000+00:00")).at_path('dateValue')
end
it 'serializes byte values to base64' do