Sha256: 43c38b8fe3008b7e45f4cd820bccf36e1f1f4085b6cbe45878452776dc1a5efa

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

require "cases/helper"

class PostgresqlExtensionMigrationTest < ActiveRecord::TestCase
  self.use_transactional_fixtures = false

  class EnableHstore < ActiveRecord::Migration
    def change
      enable_extension "hstore"
    end
  end

  class DisableHstore < ActiveRecord::Migration
    def change
      disable_extension "hstore"
    end
  end

  def setup
    super

    @connection = ActiveRecord::Base.connection

    unless @connection.supports_extensions?
      return skip("no extension support")
    end

    @old_schema_migration_tabel_name = ActiveRecord::SchemaMigration.table_name
    @old_tabel_name_prefix = ActiveRecord::Base.table_name_prefix
    @old_tabel_name_suffix = ActiveRecord::Base.table_name_suffix

    ActiveRecord::Base.table_name_prefix = "p_"
    ActiveRecord::Base.table_name_suffix = "_s"
    ActiveRecord::SchemaMigration.delete_all rescue nil
    ActiveRecord::SchemaMigration.table_name = "p_schema_migrations_s"
    ActiveRecord::Migration.verbose = false
  end

  def teardown
    ActiveRecord::Base.table_name_prefix = @old_tabel_name_prefix
    ActiveRecord::Base.table_name_suffix = @old_tabel_name_suffix
    ActiveRecord::SchemaMigration.delete_all rescue nil
    ActiveRecord::Migration.verbose = true
    ActiveRecord::SchemaMigration.table_name = @old_schema_migration_tabel_name

    super
  end

  def test_enable_extension_migration_ignores_prefix_and_suffix
    @connection.disable_extension("hstore")

    migrations = [EnableHstore.new(nil, 1)]
    ActiveRecord::Migrator.new(:up, migrations).migrate
    assert @connection.extension_enabled?("hstore"), "extension hstore should be enabled"
  end

  def test_disable_extension_migration_ignores_prefix_and_suffix
    @connection.enable_extension("hstore")

    migrations = [DisableHstore.new(nil, 1)]
    ActiveRecord::Migrator.new(:up, migrations).migrate
    assert_not @connection.extension_enabled?("hstore"), "extension hstore should not be enabled"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activejob-lock-0.0.2 rails/activerecord/test/cases/adapters/postgresql/extension_migration_test.rb
activejob-lock-0.0.1 rails/activerecord/test/cases/adapters/postgresql/extension_migration_test.rb