rails/actionmailbox/test/migrations_test.rb
Jean Boussier 7263da542b Deprecate ConnectionPool#connection
Replaced by `#lease_connection` to better reflect what it does.

`ActiveRecord::Base#connection` is deprecated in the same way
but without a removal timeline nor a deprecation warning.

Inside the Active Record test suite, we do remove `Base.connection`
to ensure it's not used internally.

Some callsites have been converted to use `with_connection`,
some other have been more simply migrated to `lease_connection`
and will serve as a list of callsites to convert for
https://github.com/rails/rails/pull/50793
2024-03-01 14:32:55 +01:00

53 lines
1.5 KiB
Ruby

# frozen_string_literal: true
require "test_helper"
require ActionMailbox::Engine.root.join("db/migrate/20180917164000_create_action_mailbox_tables.rb").to_s
class ActionMailbox::MigrationsTest < ActiveSupport::TestCase
setup do
@original_verbose = ActiveRecord::Migration.verbose
ActiveRecord::Migration.verbose = false
@connection = ActiveRecord::Base.lease_connection
@original_options = Rails.configuration.generators.options.deep_dup
end
teardown do
Rails.configuration.generators.options = @original_options
rerun_migration
ActiveRecord::Migration.verbose = @original_verbose
end
test "migration creates tables with default primary key type" do
action_mailbox_tables.each do |table|
assert_equal :integer, primary_key(table).type
end
end
test "migration creates tables with configured primary key type" do
Rails.configuration.generators do |g|
g.orm :active_record, primary_key_type: :string
end
rerun_migration
action_mailbox_tables.each do |table|
assert_equal :string, primary_key(table).type
end
end
private
def rerun_migration
CreateActionMailboxTables.migrate(:down)
CreateActionMailboxTables.migrate(:up)
end
def action_mailbox_tables
@action_mailbox_tables ||= ActionMailbox::Record.descendants.map { |klass| klass.table_name.to_sym }
end
def primary_key(table)
@connection.columns(table).find { |c| c.name == "id" }
end
end