aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-05-07 07:52:08 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-05-07 07:52:08 +0000
commitd08d89c09285ac6c65273c935a1afbbc983f7544 (patch)
treef81cdd5bbc2539eeeb04069c44ca175d1bc86273
parentd59f3a78a423064f53dadd9f55d05b5f7b2b240e (diff)
downloadrails-d08d89c09285ac6c65273c935a1afbbc983f7544.tar.gz
rails-d08d89c09285ac6c65273c935a1afbbc983f7544.tar.bz2
rails-d08d89c09285ac6c65273c935a1afbbc983f7544.zip
Dates and times interpret empty strings as nil rather than 2000-01-01. Closes #4830.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4327 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--activerecord/CHANGELOG2
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb3
-rw-r--r--activerecord/test/empty_date_time_test.rb25
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