From dd1eb78d767d3272f951a240a171b841a5ebd356 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 31 Jan 2012 17:49:53 -0800 Subject: column_types hash is used for doing typecasting --- activerecord/test/cases/base_test.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'activerecord') diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index c4e719f35d..276244295d 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1960,7 +1960,27 @@ class BasicsTest < ActiveRecord::TestCase assert_equal "photos", Photo.table_name end - def test_rawr + def test_column_types_typecast + topic = Topic.first + refute_equal 't.lo', topic.author_name + + attrs = topic.attributes.dup + attrs.delete 'id' + + typecast = Class.new { + def type_cast value + "t.lo" + end + } + + types = { 'author_name' => typecast.new } + topic = Topic.allocate.init_with 'attributes' => attrs, + 'column_types' => types + + assert_equal 't.lo', topic.author_name + end + + def test_typecasting_aliases assert_equal 10, Topic.select('10 as tenderlove').first.tenderlove end end -- cgit v1.2.3