aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/postgresql/type_lookup_test.rb
blob: 77a99ca778cfd1f03676742778ff448eb2f5ddd7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'cases/helper'

class PostgresqlTypeLookupTest < ActiveRecord::PostgreSQLTestCase
  setup do
    @connection = ActiveRecord::Base.connection
  end

  test "array delimiters are looked up correctly" do
    box_array = @connection.type_map.lookup(1020)
    int_array = @connection.type_map.lookup(1007)

    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.serialize(big_array) }
    assert_equal "{123456789123456789}", bigint_array.serialize(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.serialize(big_range) }
    assert_equal "[0,123456789123456789]", bigint_range.serialize(big_range)
  end
end