Skip to content

Commit

Permalink
Merge pull request samvera-deprecated#52 from projecthydra/invalid_ti…
Browse files Browse the repository at this point in the history
…me_serialization

Handle invalid time for Rails 3 ("just merge it,dude")
  • Loading branch information
mjgiarlo committed Jun 5, 2014
2 parents 73c255e + 6175ff1 commit ce8d7d6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/om/xml/term.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ def serialize (val)
when :date, :integer
val.to_s
when :time
time = val.to_time
begin
time = val.to_time
rescue ArgumentError
# In Rails 3, an invalid time raises ArgumentError, in Rails 4 it just returns nil
raise TypeMismatch, "Can't convert `#{val}` to time"
end
raise TypeMismatch, "Can't convert `#{val}` to time" if time.nil?
time.utc.iso8601
when :boolean
Expand Down
4 changes: 4 additions & 0 deletions spec/integration/serialization_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'spec_helper'
require 'active_support/core_ext/string/conversions' # for String#to_time conversion
require 'active_support/core_ext/date_time/conversions' # for String#to_time conversion (only needed for Rails 3)

describe "element values" do
before(:all) do
Expand Down Expand Up @@ -64,6 +65,9 @@ class ElementValueTerminology
it "raises a type mismatch error" do
expect { datastream.my_time = '' }.to raise_error OM::TypeMismatch
end
it "raises a type mismatch error" do
expect { datastream.my_time = 'Foo' }.to raise_error OM::TypeMismatch
end
end
end

Expand Down

0 comments on commit ce8d7d6

Please sign in to comment.