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 12, 2015
1 parent 7b8c795 commit 304b918
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/active_fedora/loadable_from_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion spec/integration/date_time_properties_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

0 comments on commit 304b918

Please sign in to comment.