From 88bf1d7e8d85b07169dca19bcd24565e07a237af Mon Sep 17 00:00:00 2001 From: Adam Wead Date: Tue, 3 Nov 2015 20:16:18 -0500 Subject: [PATCH] Don't try to parse empty dates --- lib/active_fedora/loadable_from_json.rb | 2 +- spec/integration/date_time_properties_spec.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/active_fedora/loadable_from_json.rb b/lib/active_fedora/loadable_from_json.rb index 0968c9d7a..25f430fa4 100644 --- a/lib/active_fedora/loadable_from_json.rb +++ b/lib/active_fedora/loadable_from_json.rb @@ -178,7 +178,7 @@ def date_attribute?(attribute_name) # @param attribute_name [String] the name of the attribute to adapt # @return [Object] the adapted value def adapt_single_attribute_value(value, attribute_name) - if value && date_attribute?(attribute_name) + if (value && !value.empty?) && date_attribute?(attribute_name) DateTime.parse(value) else value diff --git a/spec/integration/date_time_properties_spec.rb b/spec/integration/date_time_properties_spec.rb index 0f5b8f7eb..ce480f82f 100644 --- a/spec/integration/date_time_properties_spec.rb +++ b/spec/integration/date_time_properties_spec.rb @@ -9,6 +9,7 @@ class Foo < ActiveFedora::Base end property :single_date, multiple: false, class_name: 'DateTime', predicate: ::RDF::URI.new('http://www.example.com/single_date') property :missing_date, multiple: false, class_name: 'DateTime', predicate: ::RDF::URI.new('http://www.example.com/missing_date') + property :empty_date, multiple: false, class_name: 'DateTime', predicate: ::RDF::URI.new('http://www.example.com/empty_date') end end @@ -18,7 +19,7 @@ class Foo < ActiveFedora::Base let(:date) { DateTime.parse("2015-10-22T10:20:03.653+01:00") } let(:date2) { DateTime.parse("2015-10-22T15:34:20.323-11:00") } - subject { Foo.create(date: [date], single_date: date2).reload } + subject { Foo.create(date: [date], single_date: date2, empty_date: '').reload } describe "saving and loading in Fedora" do it "loads the correct time" do