Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't try to parse empty dates #939

Merged
merged 1 commit into from
Nov 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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