aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-05-05 13:40:42 -0700
committerJon Leighton <j@jonathanleighton.com>2012-05-05 13:40:42 -0700
commit3af9e721b46d04512653ec356385bcd9e90c3212 (patch)
treea652d8b3e980b0a29385030c848318e27ad4a6dd /activerecord/test
parent06c787d2359660529ff5b927d3d34f22379eef00 (diff)
parent7f160b06a24547a41a59994a736d6b11beb0c30e (diff)
downloadrails-3af9e721b46d04512653ec356385bcd9e90c3212.tar.gz
rails-3af9e721b46d04512653ec356385bcd9e90c3212.tar.bz2
rails-3af9e721b46d04512653ec356385bcd9e90c3212.zip
Merge pull request #6054 from flexoid/column-fix
Prevent creating valid time-like objects from blank string from db
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/column_test.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/activerecord/test/cases/column_test.rb b/activerecord/test/cases/column_test.rb
index 4fcf8a33a4..4111a5f808 100644
--- a/activerecord/test/cases/column_test.rb
+++ b/activerecord/test/cases/column_test.rb
@@ -48,6 +48,34 @@ module ActiveRecord
column.type_cast(false)
end
end
+
+ def test_type_cast_time
+ column = Column.new("field", nil, "time")
+ assert_equal nil, column.type_cast('')
+ assert_equal nil, column.type_cast(' ')
+
+ time_string = Time.now.utc.strftime("%T")
+ assert_equal time_string, column.type_cast(time_string).strftime("%T")
+ end
+
+ def test_type_cast_datetime_and_timestamp
+ [Column.new("field", nil, "datetime"), Column.new("field", nil, "timestamp")].each do |column|
+ assert_equal nil, column.type_cast('')
+ assert_equal nil, column.type_cast(' ')
+
+ datetime_string = Time.now.utc.strftime("%FT%T")
+ assert_equal datetime_string, column.type_cast(datetime_string).strftime("%FT%T")
+ end
+ end
+
+ def test_type_cast_date
+ column = Column.new("field", nil, "date")
+ assert_equal nil, column.type_cast('')
+ assert_equal nil, column.type_cast(' ')
+
+ date_string = Time.now.utc.strftime("%F")
+ assert_equal date_string, column.type_cast(date_string).strftime("%F")
+ end
end
end
end