Skip to content

Commit b119d58

Browse files
committed
[postgres] ColumnDefinition.array? method is used by SchemaCreation
all credits to @leogavidia - closes #474 : undefined method array? in ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::ColumnDefinition
1 parent e01f313 commit b119d58

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/arjdbc/postgresql/adapter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,7 @@ def initialize(*args)
12571257

12581258
class ColumnDefinition < ActiveRecord::ConnectionAdapters::ColumnDefinition
12591259
attr_accessor :array
1260+
def array?; !!@array; end
12601261
end
12611262

12621263
module ColumnMethods

test/db/postgresql/simple_test.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,30 @@ def test_create_table_with_limits
8989
connection.drop_table :testings rescue nil
9090
end
9191

92+
def test_create_table_with_array
93+
connection.create_table :my_posts do |t|
94+
t.string :name; t.text :description
95+
t.string :tags, :array => true, :default => []
96+
t.timestamps
97+
end
98+
99+
columns = connection.columns(:my_posts)
100+
tags = columns.detect { |c| c.name == "tags" }
101+
102+
if ar_version('4.0')
103+
assert_equal :string, tags.type
104+
assert_true tags.array?
105+
106+
name = columns.detect { |c| c.name == "name" }
107+
assert_false name.array?
108+
else
109+
assert_equal :string, tags.type
110+
assert_match /char/, tags.sql_type # character varying (255)
111+
end
112+
ensure
113+
connection.drop_table :my_posts rescue nil
114+
end
115+
92116
def test_resolves_correct_columns_default
93117
assert column = DbType.columns.find { |col| col.name == 'sample_small_decimal' }
94118
assert_equal 3.14, column.default

0 commit comments

Comments
 (0)