Sha256: c6678aaaeccf55b0aabd69b7544bddabb1fb5876725abb7474cf48d260425cfb

Contents?: true

Size: 1 KB

Versions: 35

Compression:

Stored size: 1 KB

Contents

module Mocks
  module CreateTable
    def mock_create_table
      path = ActiveRecord::Base.connection.method(:create_table).super_method.source_location[0]

      before :all do
        ActiveRecord::ConnectionAdapters::SchemaStatements.send(:define_method, :create_table) do |table_name, **options, &block|
          td = create_table_definition(table_name, **options)

          # Does things as the same as schema statements
          if options[:id] != false && !options[:as]
            pk = options.fetch(:primary_key) do
              ActiveRecord::Base.get_primary_key table_name.to_s.singularize
            end

            if pk.is_a?(Array)
              td.primary_keys pk
            else
              td.primary_key pk, options.fetch(:id, :primary_key), **options
            end
          end

          block.call(td) if block.present?

          # Now generate the SQL and return it
          schema_creation.accept td
        end
      end

      after :all do
        load path
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
torque-postgresql-3.4.1 spec/mocks/create_table.rb
torque-postgresql-2.4.5 spec/mocks/create_table.rb
torque-postgresql-3.4.0 spec/mocks/create_table.rb
torque-postgresql-3.3.3 spec/mocks/create_table.rb
torque-postgresql-2.4.4 spec/mocks/create_table.rb
torque-postgresql-3.3.2 spec/mocks/create_table.rb
torque-postgresql-2.4.3 spec/mocks/create_table.rb
torque-postgresql-3.3.1 spec/mocks/create_table.rb
torque-postgresql-3.3.0 spec/mocks/create_table.rb
torque-postgresql-3.2.2 spec/mocks/create_table.rb
torque-postgresql-2.4.2 spec/mocks/create_table.rb
torque-postgresql-2.4.1 spec/mocks/create_table.rb
torque-postgresql-3.2.1 spec/mocks/create_table.rb
torque-postgresql-2.4.0 spec/mocks/create_table.rb
torque-postgresql-3.2.0 spec/mocks/create_table.rb
torque-postgresql-3.1.0 spec/mocks/create_table.rb
torque-postgresql-2.3.0 spec/mocks/create_table.rb
torque-postgresql-3.0.1 spec/mocks/create_table.rb
torque-postgresql-2.2.4 spec/mocks/create_table.rb
torque-postgresql-3.0.0 spec/mocks/create_table.rb