Skip to content

Commit 70a4144

Browse files
committed
only run citext_test if the connection supports_extensions?.
This will keep the test suite passing with older PG installations.
1 parent 73b3afe commit 70a4144

File tree

1 file changed

+54
-52
lines changed

1 file changed

+54
-52
lines changed

activerecord/test/cases/adapters/postgresql/citext_test.rb

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,76 @@
44
require 'active_record/base'
55
require 'active_record/connection_adapters/postgresql_adapter'
66

7-
class PostgresqlCitextTest < ActiveRecord::TestCase
8-
class Citext < ActiveRecord::Base
9-
self.table_name = 'citexts'
10-
end
7+
if ActiveRecord::Base.connection.supports_extensions?
8+
class PostgresqlCitextTest < ActiveRecord::TestCase
9+
class Citext < ActiveRecord::Base
10+
self.table_name = 'citexts'
11+
end
1112

12-
def setup
13-
@connection = ActiveRecord::Base.connection
13+
def setup
14+
@connection = ActiveRecord::Base.connection
1415

15-
unless @connection.extension_enabled?('citext')
16-
@connection.enable_extension 'citext'
17-
@connection.commit_db_transaction
18-
end
16+
unless @connection.extension_enabled?('citext')
17+
@connection.enable_extension 'citext'
18+
@connection.commit_db_transaction
19+
end
1920

20-
@connection.reconnect!
21+
@connection.reconnect!
2122

22-
@connection.create_table('citexts') do |t|
23-
t.citext 'cival'
23+
@connection.create_table('citexts') do |t|
24+
t.citext 'cival'
25+
end
26+
@column = Citext.columns_hash['cival']
2427
end
25-
@column = Citext.columns_hash['cival']
26-
end
2728

28-
teardown do
29-
@connection.execute 'DROP TABLE IF EXISTS citexts;'
30-
@connection.execute 'DROP EXTENSION IF EXISTS citext CASCADE;'
31-
end
29+
teardown do
30+
@connection.execute 'DROP TABLE IF EXISTS citexts;'
31+
@connection.execute 'DROP EXTENSION IF EXISTS citext CASCADE;'
32+
end
3233

33-
def test_citext_enabled
34-
assert @connection.extension_enabled?('citext')
35-
end
34+
def test_citext_enabled
35+
assert @connection.extension_enabled?('citext')
36+
end
3637

37-
def test_column_type
38-
assert_equal :citext, @column.type
39-
end
38+
def test_column_type
39+
assert_equal :citext, @column.type
40+
end
4041

41-
def test_column_sql_type
42-
assert_equal 'citext', @column.sql_type
43-
end
42+
def test_column_sql_type
43+
assert_equal 'citext', @column.sql_type
44+
end
45+
46+
def test_change_table_supports_json
47+
@connection.transaction do
48+
@connection.change_table('citexts') do |t|
49+
t.citext 'username'
50+
end
51+
Citext.reset_column_information
52+
column = Citext.columns.find { |c| c.name == 'username' }
53+
assert_equal :citext, column.type
4454

45-
def test_change_table_supports_json
46-
@connection.transaction do
47-
@connection.change_table('citexts') do |t|
48-
t.citext 'username'
55+
raise ActiveRecord::Rollback # reset the schema change
4956
end
57+
ensure
5058
Citext.reset_column_information
51-
column = Citext.columns.find { |c| c.name == 'username' }
52-
assert_equal :citext, column.type
53-
54-
raise ActiveRecord::Rollback # reset the schema change
5559
end
56-
ensure
57-
Citext.reset_column_information
58-
end
5960

60-
def test_write
61-
x = Citext.new(cival: 'Some CI Text')
62-
x.save!
63-
citext = Citext.first
64-
assert_equal "Some CI Text", citext.cival
61+
def test_write
62+
x = Citext.new(cival: 'Some CI Text')
63+
x.save!
64+
citext = Citext.first
65+
assert_equal "Some CI Text", citext.cival
6566

66-
citext.cival = "Some NEW CI Text"
67-
citext.save!
67+
citext.cival = "Some NEW CI Text"
68+
citext.save!
6869

69-
assert_equal "Some NEW CI Text", citext.reload.cival
70-
end
70+
assert_equal "Some NEW CI Text", citext.reload.cival
71+
end
7172

72-
def test_select_case_insensitive
73-
@connection.execute "insert into citexts (cival) values('Cased Text')"
74-
x = Citext.where(cival: 'cased text').first
75-
assert_equal 'Cased Text', x.cival
73+
def test_select_case_insensitive
74+
@connection.execute "insert into citexts (cival) values('Cased Text')"
75+
x = Citext.where(cival: 'cased text').first
76+
assert_equal 'Cased Text', x.cival
77+
end
7678
end
7779
end

0 commit comments

Comments
 (0)