diff options
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb | 3 | ||||
-rw-r--r-- | activerecord/test/empty_date_time_test.rb | 25 |
3 files changed, 29 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 082fdd620a..b8452543ca 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Dates and times interpret empty strings as nil rather than 2000-01-01. #4830 [kajism@yahoo.com] + * Allow :uniq => true with has_many :through associations. [Jeremy Kemper] * Ensure that StringIO is always available for the Schema dumper. [Marcel Molina Jr.] diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index 16a41446a8..6e80707528 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -115,6 +115,7 @@ module ActiveRecord def self.string_to_dummy_time(string) return string unless string.is_a?(String) + return nil if string.empty? time_array = ParseDate.parsedate(string) # pad the resulting array with dummy date information time_array[0] = 2000; time_array[1] = 1; time_array[2] = 1; @@ -175,7 +176,7 @@ module ActiveRecord private def type_to_sql(name, limit) base.type_to_sql(name, limit) rescue name - end + end def add_column_options!(sql, options) base.add_column_options!(sql, options.merge(:column => self)) diff --git a/activerecord/test/empty_date_time_test.rb b/activerecord/test/empty_date_time_test.rb new file mode 100644 index 0000000000..0b50b0949a --- /dev/null +++ b/activerecord/test/empty_date_time_test.rb @@ -0,0 +1,25 @@ +require 'abstract_unit' +require 'fixtures/topic' +require 'fixtures/task' + +class EmptyDateTimeTest < Test::Unit::TestCase + def test_assign_empty_date_time + task = Task.new + task.starting = '' + task.ending = nil + assert_nil task.starting + assert_nil task.ending + end + + def test_assign_empty_date + topic = Topic.new + topic.last_read = '' + assert_nil topic.last_read + end + + def test_assign_empty_time + topic = Topic.new + topic.bonus_time = '' + assert_nil topic.bonus_time + end +end |