diff --git a/app/models/planting.rb b/app/models/planting.rb index ab312f122..b28b11491 100644 --- a/app/models/planting.rb +++ b/app/models/planting.rb @@ -42,6 +42,6 @@ class Planting < ActiveRecord::Base end def planted_at_string=(str) - self.planted_at = Time.parse(str) + self.planted_at = str == '' ? nil : Time.parse(str) end end diff --git a/spec/models/planting_spec.rb b/spec/models/planting_spec.rb index 8dcffbdbd..00e4c7bb1 100644 --- a/spec/models/planting_spec.rb +++ b/spec/models/planting_spec.rb @@ -39,6 +39,11 @@ describe Planting do @planting.planted_at.should == Time.local(2013, 03, 01) end + it 'should accept blank dates' do + @planting.planted_at_string = '' + @planting.planted_at.should == nil + end + it "should output dates in ISO format" do @planting.planted_at = Time.local(2013, 03, 01) @planting.planted_at_string.should == "2013-03-01"