diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-05-21 10:11:30 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-05-21 10:11:30 -0700 |
commit | b871b3fab5f0e82e80310cde8476ab7234b7b6f6 (patch) | |
tree | ad378b7b3ec443158e81db5b18cd1cd2fd03b3ec | |
parent | b042f21c93959e0247d447f37644815bdc6d5851 (diff) | |
download | rails-b871b3fab5f0e82e80310cde8476ab7234b7b6f6.tar.gz rails-b871b3fab5f0e82e80310cde8476ab7234b7b6f6.tar.bz2 rails-b871b3fab5f0e82e80310cde8476ab7234b7b6f6.zip |
Rename `oid_type` to `cast_type` to make PG columns consistent
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql/column.rb | 9 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/array_test.rb | 11 |
2 files changed, 5 insertions, 15 deletions
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 |