Skip to content

Commit

Permalink
Don't try to parse empty dates
Browse files Browse the repository at this point in the history
  • Loading branch information
awead committed Nov 4, 2015
1 parent 608140a commit 88bf1d7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/active_fedora/loadable_from_json.rb
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion spec/integration/date_time_properties_spec.rb
Expand Up @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 88bf1d7

Please sign in to comment.