aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/migration/helper.rb
blob: fe53510ba2ccc983664a32d8b07c60c073a13519 (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
54
55
56
57
58
59
60
61
62
63
64
require "cases/helper"

module ActiveRecord
  class Migration
    class << self
      attr_accessor :message_count
    end

    def puts(text="")
      ActiveRecord::Migration.message_count ||= 0
      ActiveRecord::Migration.message_count += 1
    end

    module TestHelper
      attr_reader :connection, :table_name

      class TestModel < ActiveRecord::Base
        self.table_name = 'test_models'
      end

      def setup
        super
        @connection = ActiveRecord::Base.connection
        connection.create_table :test_models do |t|
          t.timestamps
        end

        TestModel.reset_column_information
      end

      def teardown
        super
        TestModel.reset_table_name
        TestModel.reset_sequence_name
        connection.drop_table :test_models rescue nil
      end

      private
      def add_column(*args)
        connection.add_column(*args)
      end

      def remove_column(*args)
        connection.remove_column(*args)
      end

      def rename_column(*args)
        connection.rename_column(*args)
      end

      def add_index(*args)
        connection.add_index(*args)
      end

      def change_column(*args)
        connection.change_column(*args)
      end

      def rename_table(*args)
        connection.rename_table(*args)
      end
    end
  end
end