aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-05-22 09:12:23 -0700
committerSean Griffin <sean@thoughtbot.com>2014-05-22 09:14:15 -0700
commitecf4ad7cca206e2cf99ca16e57e17648e726877a (patch)
tree0a8e826707d2b8b2441972e35e6c90f35c8ac1bf /activerecord/test
parent110d3d0c0bceddd05cab86c0463f0aa71df815cb (diff)
downloadrails-ecf4ad7cca206e2cf99ca16e57e17648e726877a.tar.gz
rails-ecf4ad7cca206e2cf99ca16e57e17648e726877a.tar.bz2
rails-ecf4ad7cca206e2cf99ca16e57e17648e726877a.zip
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
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/connection_adapters/type/type_map_test.rb17
1 files changed, 17 insertions, 0 deletions
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