From 304b91857e5a6c7a151f02ec14b8da0693a375d3 Mon Sep 17 00:00:00 2001 From: Adam Wead Date: Sat, 7 Nov 2015 10:19:32 -0500 Subject: [PATCH] Don't try to parse empty dates --- lib/active_fedora/loadable_from_json.rb | 1 + spec/integration/date_time_properties_spec.rb | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/active_fedora/loadable_from_json.rb b/lib/active_fedora/loadable_from_json.rb index 0968c9d7a..d97732329 100644 --- a/lib/active_fedora/loadable_from_json.rb +++ b/lib/active_fedora/loadable_from_json.rb @@ -179,6 +179,7 @@ def date_attribute?(attribute_name) # @return [Object] the adapted value def adapt_single_attribute_value(value, attribute_name) if value && date_attribute?(attribute_name) + return nil unless value.present? 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..3dfa274b0 100644 --- a/spec/integration/date_time_properties_spec.rb +++ b/spec/integration/date_time_properties_spec.rb @@ -7,8 +7,12 @@ class Foo < ActiveFedora::Base property :date, predicate: ::RDF::DC.date do |index| index.type :date end + property :integer, predicate: ::RDF::URI.new('http://www.example.com/integer'), multiple: false do |index| + index.type :integer + 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 +22,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: '', integer: 1).reload } describe "saving and loading in Fedora" do it "loads the correct time" do