aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/migration/pending_migrations_test.rb
blob: 517ee695ced7449e1a2e168c4c556e011177cbd9 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
require 'cases/helper'
require "minitest/mock"

module ActiveRecord
  class Migration
    class PendingMigrationsTest < ActiveRecord::TestCase
      def setup
        super
        @connection = MiniTest::Mock.new
        @app = MiniTest::Mock.new
        conn = @connection
        @pending = Class.new(CheckPending) {
          define_method(:connection) { conn }
        }.new(@app)
        @pending.instance_variable_set :@last_check, -1 # Force checking
      end

      def teardown
        assert @connection.verify
        assert @app.verify
        super
      end

      def test_errors_if_pending
        @connection.expect :supports_migrations?, true

        ActiveRecord::Migrator.stub :needs_migration?, true do
          assert_raise ActiveRecord::PendingMigrationError do
            @pending.call(nil)
          end
        end
      end

      def test_checks_if_supported
        @connection.expect :supports_migrations?, true
        @app.expect :call, nil, [:foo]

        ActiveRecord::Migrator.stub :needs_migration?, false do
          @pending.call(:foo)
        end
      end

      def test_doesnt_check_if_unsupported
        @connection.expect :supports_migrations?, false
        @app.expect :call, nil, [:foo]

        ActiveRecord::Migrator.stub :needs_migration?, true do
          @pending.call(:foo)
        end
      end
    end
  end
end