Skip to content

Commit

Permalink
Incorrect customer attribute returned by Ruby Gem [ch21317] (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorchukhantsev authored Aug 19, 2020
1 parent 196bbf3 commit 6816e3d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
/tmp/
*.swp
vendor/bundle
/.idea
10 changes: 9 additions & 1 deletion lib/chartmogul/utils/json_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/chartmogul/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ChartMogul
VERSION = '1.6.5'
VERSION = '1.6.6'
end
7 changes: 6 additions & 1 deletion spec/chartmogul/utils/json_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6816e3d

Please sign in to comment.