aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/migration/logger_test.rb
blob: 431047f957bf947c295d3d0e49e7ecf0351c9255 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

require "cases/helper"

module ActiveRecord
  class Migration
    class LoggerTest < ActiveRecord::TestCase
      # MySQL can't roll back ddl changes
      self.use_transactional_tests = false

      Migration = Struct.new(:name, :version) do
        def disable_ddl_transaction; false end
        def migrate(direction)
          # do nothing
        end
      end

      def setup
        super
        @schema_migration = ActiveRecord::Base.connection.schema_migration
        @schema_migration.create_table
        @schema_migration.delete_all
      end

      teardown do
        @schema_migration.drop_table
      end

      def test_migration_should_be_run_without_logger
        previous_logger = ActiveRecord::Base.logger
        ActiveRecord::Base.logger = nil
        migrations = [Migration.new("a", 1), Migration.new("b", 2), Migration.new("c", 3)]
        ActiveRecord::Migrator.new(:up, migrations, @schema_migration).migrate
      ensure
        ActiveRecord::Base.logger = previous_logger
      end
    end
  end
end