Permalink
Browse files

WORKING

  • Loading branch information...
smartinez87 committed May 5, 2011
1 parent 11db2ae commit 15d8172f3f2f1ed845b19534086a68a3f4b49b1d
Showing with 64 additions and 0 deletions.
  1. +64 −0 activerecord/test/cases/adapters/mysql/quoting_test.rb
@@ -19,6 +19,70 @@ def test_type_cast_false
assert_equal 0, @conn.type_cast(false, nil)
assert_equal 0, @conn.type_cast(false, c)
end
+
+ def test_type_cast_symbol
+ assert_equal 'foo', @conn.type_cast(:foo, nil)
+ end
+
+ def test_type_cast_date
+ date = Date.today
+ expected = @conn.quoted_date(date)
+ assert_equal expected, @conn.type_cast(date, nil)
+ end
+
+ def test_type_cast_time
+ time = Time.now
+ expected = @conn.quoted_date(time)
+ assert_equal expected, @conn.type_cast(time, nil)
+ end
+
+ def test_type_cast_numeric
+ assert_equal 10, @conn.type_cast(10, nil)
+ assert_equal 2.2, @conn.type_cast(2.2, nil)
+ end
+
+ def test_type_cast_nil
+ assert_equal nil, @conn.type_cast(nil, nil)
+ end
+
+ def test_type_cast_string
+ assert_equal '10', @conn.type_cast('10', nil)
+
+ c = Column.new(nil, 1, 'int')
+ assert_equal 10, @conn.type_cast('10', c)
+
+ c = Column.new(nil, 1, 'float')
+ assert_equal 10.1, @conn.type_cast('10.1', c)
+
+ c = Column.new(nil, 1, 'binary')
+ assert_equal '10.1', @conn.type_cast('10.1', c)
+
+ c = Column.new(nil, 1, 'date')
+ assert_equal '10.1', @conn.type_cast('10.1', c)
+ end
+
+ def test_type_cast_bigdecimal
+ bd = BigDecimal.new '10.0'
+ assert_equal bd.to_s('F'), @conn.type_cast(bd, nil)
+ end
+
+ def test_type_cast_unknown
+ obj = Class.new.new
+ assert_equal YAML.dump(obj), @conn.type_cast(obj, nil)
+ end
+
+ def test_quoted_id
+ quoted_id_obj = Class.new {
+ def quoted_id
+ "'zomg'"
+ end
+
+ def id
+ 10
+ end
+ }.new
+ assert_equal 10, @conn.type_cast(quoted_id_obj, nil)
+ end
end
end
end

0 comments on commit 15d8172

Please sign in to comment.