From b871b3fab5f0e82e80310cde8476ab7234b7b6f6 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Wed, 21 May 2014 10:11:30 -0700 Subject: Rename `oid_type` to `cast_type` to make PG columns consistent --- .../active_record/connection_adapters/postgresql/column.rb | 9 ++++----- activerecord/test/cases/adapters/postgresql/array_test.rb | 11 +---------- 2 files changed, 5 insertions(+), 15 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/column.rb b/activerecord/lib/active_record/connection_adapters/postgresql/column.rb index 95f52312a5..80c79642f3 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/column.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/column.rb @@ -6,16 +6,15 @@ module ActiveRecord class PostgreSQLColumn < Column #:nodoc: attr_accessor :array - def initialize(name, default, oid_type, sql_type = nil, null = true) - @oid_type = oid_type + def initialize(name, default, cast_type, sql_type = nil, null = true) default_value = self.class.extract_value_from_default(default) if sql_type =~ /\[\]$/ @array = true - super(name, default_value, oid_type, sql_type[0..sql_type.length - 3], null) + super(name, default_value, cast_type, sql_type[0..sql_type.length - 3], null) else @array = false - super(name, default_value, oid_type, sql_type, null) + super(name, default_value, cast_type, sql_type, null) end @default_function = default if has_default_function?(default_value, default) @@ -105,7 +104,7 @@ module ActiveRecord end def accessor - @oid_type.accessor + cast_type.accessor end private diff --git a/activerecord/test/cases/adapters/postgresql/array_test.rb b/activerecord/test/cases/adapters/postgresql/array_test.rb index c20030ca64..34c2008ab4 100644 --- a/activerecord/test/cases/adapters/postgresql/array_test.rb +++ b/activerecord/test/cases/adapters/postgresql/array_test.rb @@ -89,16 +89,7 @@ class PostgresqlArrayTest < ActiveRecord::TestCase end def test_type_cast_array - data = '{1,2,3}' - oid_type = @column.instance_variable_get('@oid_type').subtype - # we are getting the instance variable in this test, but in the - # normal use of string_to_array, it's called from the OID::Array - # class and will have the OID instance that will provide the type - # casting - array = @column.class.string_to_array data, oid_type - assert_equal(['1', '2', '3'], array) - assert_equal(['1', '2', '3'], @column.type_cast(data)) - + assert_equal(['1', '2', '3'], @column.type_cast('{1,2,3}')) assert_equal([], @column.type_cast('{}')) assert_equal([nil], @column.type_cast('{NULL}')) end -- cgit v1.2.3