From 6816e3dad8c0ef5c44fa7d951026e6d72cfecb99 Mon Sep 17 00:00:00 2001 From: Viktor Chukhantsev Date: Wed, 19 Aug 2020 14:42:59 +0700 Subject: [PATCH] Incorrect customer attribute returned by Ruby Gem [ch21317] (#85) --- .gitignore | 1 + lib/chartmogul/utils/json_parser.rb | 10 +++++++++- lib/chartmogul/version.rb | 2 +- spec/chartmogul/utils/json_parser_spec.rb | 7 ++++++- 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index a7057fc..5657b8e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ /tmp/ *.swp vendor/bundle +/.idea \ No newline at end of file diff --git a/lib/chartmogul/utils/json_parser.rb b/lib/chartmogul/utils/json_parser.rb index a4e0806..d94d313 100644 --- a/lib/chartmogul/utils/json_parser.rb +++ b/lib/chartmogul/utils/json_parser.rb @@ -20,7 +20,15 @@ def typecast_custom_attributes(custom_attributes) def opt_string_to_time(value) return value unless value.instance_of?(String) - Time.iso8601(value) rescue Time.rfc2822(value) rescue value + parse_timestamp(value) + rescue ArgumentError + value + end + + def parse_timestamp(value) + Time.iso8601(value) + rescue ArgumentError + Time.rfc2822(value) end end end diff --git a/lib/chartmogul/version.rb b/lib/chartmogul/version.rb index a8b39ee..7c32121 100644 --- a/lib/chartmogul/version.rb +++ b/lib/chartmogul/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ChartMogul - VERSION = '1.6.5' + VERSION = '1.6.6' end diff --git a/spec/chartmogul/utils/json_parser_spec.rb b/spec/chartmogul/utils/json_parser_spec.rb index 7087362..c91a463 100644 --- a/spec/chartmogul/utils/json_parser_spec.rb +++ b/spec/chartmogul/utils/json_parser_spec.rb @@ -14,9 +14,14 @@ expect(result[:attr]).to be_instance_of(Time) end - it "doesn't parse string vaguely looking like a date" do + it 'doesn\'t parse string vaguely looking like a date' do result = described_class.typecast_custom_attributes(attr: 'May the force be with you.') expect(result[:attr]).to be_instance_of(String) end + + it 'return string if parse of timestamp failed' do + result = described_class.typecast_custom_attributes(attr: '2016-02-01T0000:00.000Z') + expect(result[:attr]).to be_instance_of(String) + end end end