Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

column_types hash is used for doing typecasting

  • Loading branch information...
commit dd1eb78d767d3272f951a240a171b841a5ebd356 1 parent 9bcb9cd
@tenderlove tenderlove authored
Showing with 21 additions and 1 deletion.
  1. +21 −1 activerecord/test/cases/base_test.rb
View
22 activerecord/test/cases/base_test.rb
@@ -1960,7 +1960,27 @@ def test_table_name_with_2_abstract_subclasses
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
Please sign in to comment.
Something went wrong with that request. Please try again.