From ecf4ad7cca206e2cf99ca16e57e17648e726877a Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Thu, 22 May 2014 09:12:23 -0700 Subject: Allow additional arguments to be used during type map lookups Determining things like precision and scale in postgresql will require the given blocks to take additional arguments besides the OID. - Adds the ability to handle additional arguments to `TypeMap` - Passes the column type to blocks when looking up PG types --- .../cases/connection_adapters/type/type_map_test.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'activerecord/test') diff --git a/activerecord/test/cases/connection_adapters/type/type_map_test.rb b/activerecord/test/cases/connection_adapters/type/type_map_test.rb index 4b4d9f6b0f..3abd7a276e 100644 --- a/activerecord/test/cases/connection_adapters/type/type_map_test.rb +++ b/activerecord/test/cases/connection_adapters/type/type_map_test.rb @@ -88,6 +88,23 @@ module ActiveRecord assert_equal mapping.lookup('varchar'), binary end + def test_additional_lookup_args + mapping = TypeMap.new + + mapping.register_type(/varchar/i) do |type, limit| + if limit > 255 + 'text' + else + 'string' + end + end + mapping.alias_type(/string/i, 'varchar') + + assert_equal mapping.lookup('varchar', 200), 'string' + assert_equal mapping.lookup('varchar', 400), 'text' + assert_equal mapping.lookup('string', 400), 'text' + end + def test_requires_value_or_block mapping = TypeMap.new -- cgit v1.2.3