aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2014-12-05 15:32:58 -0700
committerSean Griffin <sean@thoughtbot.com>2014-12-05 15:34:30 -0700
commit670e7941d5482f7124420965d4fbd7bea45a3155 (patch)
treeefcd8f1da3b25692ecb0f7af55fbce99578b8946 /activerecord/test/cases
parenta78736bd48408976459b7ff4279d5e6f356a970f (diff)
downloadrails-670e7941d5482f7124420965d4fbd7bea45a3155.tar.gz
rails-670e7941d5482f7124420965d4fbd7bea45a3155.tar.bz2
rails-670e7941d5482f7124420965d4fbd7bea45a3155.zip
Correctly respect subtypes for PG arrays and ranges
The type registration was simply looking for the OID, and eagerly fetching/constructing the sub type when it was registered. However, numeric types have additional parameters which are extracted from the actual SQL string of the type during lookup, and can have their behavior change based on the result. We simply need to use the block form of registration, and look up the subtype lazily instead. Fixes #17935
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/adapters/postgresql/type_lookup_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/type_lookup_test.rb b/activerecord/test/cases/adapters/postgresql/type_lookup_test.rb
index 23817198b1..c88259d274 100644
--- a/activerecord/test/cases/adapters/postgresql/type_lookup_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/type_lookup_test.rb
@@ -12,4 +12,22 @@ class PostgresqlTypeLookupTest < ActiveRecord::TestCase
assert_equal ';', box_array.delimiter
assert_equal ',', int_array.delimiter
end
+
+ test "array types correctly respect registration of subtypes" do
+ int_array = @connection.type_map.lookup(1007, -1, "integer[]")
+ bigint_array = @connection.type_map.lookup(1016, -1, "bigint[]")
+ big_array = [123456789123456789]
+
+ assert_raises(RangeError) { int_array.type_cast_from_user(big_array) }
+ assert_equal big_array, bigint_array.type_cast_from_user(big_array)
+ end
+
+ test "range types correctly respect registration of subtypes" do
+ int_range = @connection.type_map.lookup(3904, -1, "int4range")
+ bigint_range = @connection.type_map.lookup(3926, -1, "int8range")
+ big_range = 0..123456789123456789
+
+ assert_raises(RangeError) { int_range.type_cast_for_database(big_range) }
+ assert_equal "[0,123456789123456789]", bigint_range.type_cast_for_database(big_range)
+ end
end