aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/postgresql/citext_test.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-03-27 11:24:31 +0100
committerYves Senn <yves.senn@gmail.com>2014-03-27 11:24:31 +0100
commit70a4144622d6a43891f43901fec6c05afbd79a3a (patch)
tree0a6eec0eb84c167a8d2ccb16dcb693ae18dbfa3b /activerecord/test/cases/adapters/postgresql/citext_test.rb
parent73b3afe58f3a25efa808a2bd1e5ca9f4bbe5c94a (diff)
downloadrails-70a4144622d6a43891f43901fec6c05afbd79a3a.tar.gz
rails-70a4144622d6a43891f43901fec6c05afbd79a3a.tar.bz2
rails-70a4144622d6a43891f43901fec6c05afbd79a3a.zip
only run citext_test if the connection supports_extensions?.
This will keep the test suite passing with older PG installations.
Diffstat (limited to 'activerecord/test/cases/adapters/postgresql/citext_test.rb')
-rw-r--r--activerecord/test/cases/adapters/postgresql/citext_test.rb106
1 files changed, 54 insertions, 52 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/citext_test.rb b/activerecord/test/cases/adapters/postgresql/citext_test.rb
index 148dc9d07c..0bb2949371 100644
--- a/activerecord/test/cases/adapters/postgresql/citext_test.rb
+++ b/activerecord/test/cases/adapters/postgresql/citext_test.rb
@@ -4,74 +4,76 @@ require 'cases/helper'
require 'active_record/base'
require 'active_record/connection_adapters/postgresql_adapter'
-class PostgresqlCitextTest < ActiveRecord::TestCase
- class Citext < ActiveRecord::Base
- self.table_name = 'citexts'
- end
+if ActiveRecord::Base.connection.supports_extensions?
+ class PostgresqlCitextTest < ActiveRecord::TestCase
+ class Citext < ActiveRecord::Base
+ self.table_name = 'citexts'
+ end
- def setup
- @connection = ActiveRecord::Base.connection
+ def setup
+ @connection = ActiveRecord::Base.connection
- unless @connection.extension_enabled?('citext')
- @connection.enable_extension 'citext'
- @connection.commit_db_transaction
- end
+ unless @connection.extension_enabled?('citext')
+ @connection.enable_extension 'citext'
+ @connection.commit_db_transaction
+ end
- @connection.reconnect!
+ @connection.reconnect!
- @connection.create_table('citexts') do |t|
- t.citext 'cival'
+ @connection.create_table('citexts') do |t|
+ t.citext 'cival'
+ end
+ @column = Citext.columns_hash['cival']
end
- @column = Citext.columns_hash['cival']
- end
- teardown do
- @connection.execute 'DROP TABLE IF EXISTS citexts;'
- @connection.execute 'DROP EXTENSION IF EXISTS citext CASCADE;'
- end
+ teardown do
+ @connection.execute 'DROP TABLE IF EXISTS citexts;'
+ @connection.execute 'DROP EXTENSION IF EXISTS citext CASCADE;'
+ end
- def test_citext_enabled
- assert @connection.extension_enabled?('citext')
- end
+ def test_citext_enabled
+ assert @connection.extension_enabled?('citext')
+ end
- def test_column_type
- assert_equal :citext, @column.type
- end
+ def test_column_type
+ assert_equal :citext, @column.type
+ end
- def test_column_sql_type
- assert_equal 'citext', @column.sql_type
- end
+ def test_column_sql_type
+ assert_equal 'citext', @column.sql_type
+ end
+
+ def test_change_table_supports_json
+ @connection.transaction do
+ @connection.change_table('citexts') do |t|
+ t.citext 'username'
+ end
+ Citext.reset_column_information
+ column = Citext.columns.find { |c| c.name == 'username' }
+ assert_equal :citext, column.type
- def test_change_table_supports_json
- @connection.transaction do
- @connection.change_table('citexts') do |t|
- t.citext 'username'
+ raise ActiveRecord::Rollback # reset the schema change
end
+ ensure
Citext.reset_column_information
- column = Citext.columns.find { |c| c.name == 'username' }
- assert_equal :citext, column.type
-
- raise ActiveRecord::Rollback # reset the schema change
end
- ensure
- Citext.reset_column_information
- end
- def test_write
- x = Citext.new(cival: 'Some CI Text')
- x.save!
- citext = Citext.first
- assert_equal "Some CI Text", citext.cival
+ def test_write
+ x = Citext.new(cival: 'Some CI Text')
+ x.save!
+ citext = Citext.first
+ assert_equal "Some CI Text", citext.cival
- citext.cival = "Some NEW CI Text"
- citext.save!
+ citext.cival = "Some NEW CI Text"
+ citext.save!
- assert_equal "Some NEW CI Text", citext.reload.cival
- end
+ assert_equal "Some NEW CI Text", citext.reload.cival
+ end
- def test_select_case_insensitive
- @connection.execute "insert into citexts (cival) values('Cased Text')"
- x = Citext.where(cival: 'cased text').first
- assert_equal 'Cased Text', x.cival
+ def test_select_case_insensitive
+ @connection.execute "insert into citexts (cival) values('Cased Text')"
+ x = Citext.where(cival: 'cased text').first
+ assert_equal 'Cased Text', x.cival
+ end
end
end