aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-01-31 17:49:53 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2012-02-07 13:51:53 -0800
commitdd1eb78d767d3272f951a240a171b841a5ebd356 (patch)
treeb86d6a6aba9c739ecf38ba9db557ea31284e8cbc /activerecord
parent9bcb9cd55f92fb0252b3ab93d068e0b336727af0 (diff)
downloadrails-dd1eb78d767d3272f951a240a171b841a5ebd356.tar.gz
rails-dd1eb78d767d3272f951a240a171b841a5ebd356.tar.bz2
rails-dd1eb78d767d3272f951a240a171b841a5ebd356.zip
column_types hash is used for doing typecasting
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/base_test.rb22
1 files changed, 21 insertions, 1 deletions
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