aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/mysql2/auto_increment_test.rb
blob: 4c67633946a6a4feb603dffee9c0ef9aef8ee66d (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
# frozen_string_literal: true

require "cases/helper"
require "support/schema_dumping_helper"

class Mysql2AutoIncrementTest < ActiveRecord::Mysql2TestCase
  include SchemaDumpingHelper

  def setup
    @connection = ActiveRecord::Base.connection
  end

  def teardown
    @connection.drop_table :auto_increments, if_exists: true
  end

  def test_auto_increment_without_primary_key
    @connection.create_table :auto_increments, id: false, force: true do |t|
      t.integer :id, null: false, auto_increment: true
      t.index :id
    end
    output = dump_table_schema("auto_increments")
    assert_match(/t\.integer\s+"id",\s+null: false,\s+auto_increment: true$/, output)
  end

  def test_auto_increment_with_composite_primary_key
    @connection.create_table :auto_increments, primary_key: [:id, :created_at], force: true do |t|
      t.integer :id, null: false, auto_increment: true
      t.datetime :created_at, null: false
    end
    output = dump_table_schema("auto_increments")
    assert_match(/t\.integer\s+"id",\s+null: false,\s+auto_increment: true$/, output)
  end
end