mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Added enable_extension! to helper
This commit is contained in:
parent
7025d7769d
commit
0ab9301f2a
7 changed files with 25 additions and 26 deletions
|
@ -12,12 +12,7 @@ class PostgresqlArrayTest < ActiveRecord::TestCase
|
|||
def setup
|
||||
@connection = ActiveRecord::Base.connection
|
||||
|
||||
unless @connection.extension_enabled?('hstore')
|
||||
@connection.enable_extension 'hstore'
|
||||
@connection.commit_db_transaction
|
||||
end
|
||||
|
||||
@connection.reconnect!
|
||||
enable_extension!('hstore', @connection)
|
||||
|
||||
@connection.transaction do
|
||||
@connection.create_table('pg_arrays') do |t|
|
||||
|
@ -32,6 +27,7 @@ class PostgresqlArrayTest < ActiveRecord::TestCase
|
|||
|
||||
teardown do
|
||||
@connection.execute 'drop table if exists pg_arrays'
|
||||
disable_extension!('hstore', @connection)
|
||||
end
|
||||
|
||||
def test_column
|
||||
|
|
|
@ -10,12 +10,7 @@ if ActiveRecord::Base.connection.supports_extensions?
|
|||
def setup
|
||||
@connection = ActiveRecord::Base.connection
|
||||
|
||||
unless @connection.extension_enabled?('citext')
|
||||
@connection.enable_extension 'citext'
|
||||
@connection.commit_db_transaction
|
||||
end
|
||||
|
||||
@connection.reconnect!
|
||||
enable_extension!('citext', @connection)
|
||||
|
||||
@connection.create_table('citexts') do |t|
|
||||
t.citext 'cival'
|
||||
|
@ -24,7 +19,7 @@ if ActiveRecord::Base.connection.supports_extensions?
|
|||
|
||||
teardown do
|
||||
@connection.execute 'DROP TABLE IF EXISTS citexts;'
|
||||
@connection.execute 'DROP EXTENSION IF EXISTS citext CASCADE;'
|
||||
disable_extension!('citext', @connection)
|
||||
end
|
||||
|
||||
def test_citext_enabled
|
||||
|
|
|
@ -9,9 +9,7 @@ class PostgresqlLtreeTest < ActiveRecord::TestCase
|
|||
def setup
|
||||
@connection = ActiveRecord::Base.connection
|
||||
|
||||
unless @connection.extension_enabled?('ltree')
|
||||
@connection.enable_extension 'ltree'
|
||||
end
|
||||
enable_extension!('ltree', @connection)
|
||||
|
||||
@connection.transaction do
|
||||
@connection.create_table('ltrees') do |t|
|
||||
|
|
|
@ -118,7 +118,7 @@ class PostgresqlUUIDGenerationTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
setup do
|
||||
enable_uuid_ossp!(connection)
|
||||
enable_extension!('uuid-ossp', connection)
|
||||
|
||||
connection.create_table('pg_uuids', id: :uuid, default: 'uuid_generate_v1()') do |t|
|
||||
t.string 'name'
|
||||
|
@ -144,6 +144,7 @@ class PostgresqlUUIDGenerationTest < ActiveRecord::TestCase
|
|||
drop_table "pg_uuids"
|
||||
drop_table 'pg_uuids_2'
|
||||
connection.execute 'DROP FUNCTION IF EXISTS my_uuid_generator();'
|
||||
disable_extension!('uuid-ossp', connection)
|
||||
end
|
||||
|
||||
if ActiveRecord::Base.connection.supports_extensions?
|
||||
|
@ -189,7 +190,7 @@ class PostgresqlUUIDTestNilDefault < ActiveRecord::TestCase
|
|||
include PostgresqlUUIDHelper
|
||||
|
||||
setup do
|
||||
enable_uuid_ossp!(connection)
|
||||
enable_extension!('uuid-ossp', connection)
|
||||
|
||||
connection.create_table('pg_uuids', id: false) do |t|
|
||||
t.primary_key :id, :uuid, default: nil
|
||||
|
@ -199,6 +200,7 @@ class PostgresqlUUIDTestNilDefault < ActiveRecord::TestCase
|
|||
|
||||
teardown do
|
||||
drop_table "pg_uuids"
|
||||
disable_extension!('uuid-ossp', connection)
|
||||
end
|
||||
|
||||
if ActiveRecord::Base.connection.supports_extensions?
|
||||
|
@ -226,7 +228,7 @@ class PostgresqlUUIDTestInverseOf < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
setup do
|
||||
enable_uuid_ossp!(connection)
|
||||
enable_extension!('uuid-ossp', connection)
|
||||
|
||||
connection.transaction do
|
||||
connection.create_table('pg_uuid_posts', id: :uuid) do |t|
|
||||
|
@ -240,10 +242,9 @@ class PostgresqlUUIDTestInverseOf < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
teardown do
|
||||
connection.transaction do
|
||||
drop_table "pg_uuid_comments"
|
||||
drop_table "pg_uuid_posts"
|
||||
end
|
||||
disable_extension!('uuid-ossp', connection)
|
||||
end
|
||||
|
||||
if ActiveRecord::Base.connection.supports_extensions?
|
||||
|
|
|
@ -119,15 +119,23 @@ def verify_default_timezone_config
|
|||
end
|
||||
end
|
||||
|
||||
def enable_uuid_ossp!(connection)
|
||||
def enable_extension!(extension, connection)
|
||||
return false unless connection.supports_extensions?
|
||||
return connection.reconnect! if connection.extension_enabled?('uuid-ossp')
|
||||
return connection.reconnect! if connection.extension_enabled?(extension)
|
||||
|
||||
connection.enable_extension 'uuid-ossp'
|
||||
connection.enable_extension extension
|
||||
connection.commit_db_transaction
|
||||
connection.reconnect!
|
||||
end
|
||||
|
||||
def disable_extension!(extension, connection)
|
||||
return false unless connection.supports_extensions?
|
||||
return true unless connection.extension_enabled?(extension)
|
||||
|
||||
connection.disable_extension extension
|
||||
connection.reconnect!
|
||||
end
|
||||
|
||||
unless ENV['FIXTURE_DEBUG']
|
||||
module ActiveRecord::TestFixtures::ClassMethods
|
||||
def try_to_load_dependency_with_silence(*args)
|
||||
|
|
|
@ -78,11 +78,12 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def test_renaming_table_doesnt_attempt_to_rename_non_existent_sequences
|
||||
enable_uuid_ossp!(connection)
|
||||
enable_extension!('uuid-ossp', connection)
|
||||
connection.create_table :cats, id: :uuid
|
||||
assert_nothing_raised { rename_table :cats, :felines }
|
||||
assert connection.table_exists? :felines
|
||||
ensure
|
||||
disable_extension!('uuid-ossp', connection)
|
||||
connection.drop_table :cats if connection.table_exists? :cats
|
||||
connection.drop_table :felines if connection.table_exists? :felines
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ ActiveRecord::Schema.define do
|
|||
#put adapter specific setup here
|
||||
case adapter_name
|
||||
when "PostgreSQL"
|
||||
enable_uuid_ossp!(ActiveRecord::Base.connection)
|
||||
enable_extension!('uuid-ossp', ActiveRecord::Base.connection)
|
||||
create_table :uuid_parents, id: :uuid, force: true do |t|
|
||||
t.string :name
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue