diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-01-31 15:10:32 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-01 14:25:46 -0800 |
commit | 65f11ff7894ace0e762921a36489de46bd22c724 (patch) | |
tree | a0cd616f8517e7123f44a7867aa62c6b39f3e096 | |
parent | a7c2f6be3050b035865a48accb102568c961c1bf (diff) | |
download | rails-65f11ff7894ace0e762921a36489de46bd22c724.tar.gz rails-65f11ff7894ace0e762921a36489de46bd22c724.tar.bz2 rails-65f11ff7894ace0e762921a36489de46bd22c724.zip |
column will use coder to typecase value when it is available
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/column_definition_test.rb | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb index e2582f7f15..d115ef8fb6 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb @@ -72,6 +72,8 @@ module ActiveRecord # Casts value (which is a String) to an appropriate instance. def type_cast(value) return nil if value.nil? + return coder.load(value) if encoded? + klass = self.class case type diff --git a/activerecord/test/cases/column_definition_test.rb b/activerecord/test/cases/column_definition_test.rb index a80deee93e..d1dddd4c2c 100644 --- a/activerecord/test/cases/column_definition_test.rb +++ b/activerecord/test/cases/column_definition_test.rb @@ -24,6 +24,12 @@ module ActiveRecord assert column.encoded? end + def test_type_case_coded_column + column = Column.new("title", nil, "varchar(20)") + column.coder = YAML + assert_equal "hello", column.type_cast("--- hello") + end + # Avoid column definitions in create table statements like: # `title` varchar(255) DEFAULT NULL def test_should_not_include_default_clause_when_default_is_null |