aboutsummaryrefslogblamecommitdiffstats
path: root/activerecord/test/cases/migration/helper.rb
blob: 768ebc58611f21e334843e4b413c283a4bfaa8ef (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13



                      








                                                 


                                          
                                                                                                                                                                                                                         
 
                                          
                                      













                                                   

                                     



                                                     
 
                                                    


       
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

      CONNECTION_METHODS = %w[add_column remove_column rename_column add_index change_column rename_table column_exists? index_exists? add_reference add_belongs_to remove_reference remove_references remove_belongs_to]

      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

      delegate(*CONNECTION_METHODS, to: :connection)
    end
  end
end