diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-10-15 23:22:33 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-15 23:22:33 +0900 |
commit | 8877492df2853cba92d95dabdfcdee7244e7d8f0 (patch) | |
tree | 4984505322d0a3451d4a6bb99e7ad30558a45ca1 /activerecord/test/cases | |
parent | 26f995459cdfce5c8231f47b369d224e00c7a22c (diff) | |
download | rails-8877492df2853cba92d95dabdfcdee7244e7d8f0.tar.gz rails-8877492df2853cba92d95dabdfcdee7244e7d8f0.tar.bz2 rails-8877492df2853cba92d95dabdfcdee7244e7d8f0.zip |
Fix longer sequence name detection for serial columns (#28339)
We already found the longer sequence name, but we could not consider
whether it was the sequence name created by serial type due to missed a
max identifier length limitation. I've addressed the sequence name
consideration to respect the max identifier length.
Fixes #28332.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/serial_test.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/serial_test.rb b/activerecord/test/cases/adapters/postgresql/serial_test.rb index df7875dbf2..6a99323be5 100644 --- a/activerecord/test/cases/adapters/postgresql/serial_test.rb +++ b/activerecord/test/cases/adapters/postgresql/serial_test.rb @@ -121,4 +121,36 @@ module SequenceNameDetectionTestCases assert_match %r{t\.bigserial\s+"bar_baz_id",\s+null: false$}, output end end + + class LongerSequenceNameDetectionTest < ActiveRecord::PostgreSQLTestCase + include SchemaDumpingHelper + + def setup + @table_name = "long_table_name_to_test_sequence_name_detection_for_serial_cols" + @connection = ActiveRecord::Base.connection + @connection.create_table @table_name, force: true do |t| + t.serial :seq + t.bigserial :bigseq + end + end + + def teardown + @connection.drop_table @table_name, if_exists: true + end + + def test_serial_columns + columns = @connection.columns(@table_name) + columns.each do |column| + assert_equal :integer, column.type + assert column.serial? + end + end + + def test_schema_dump_with_long_table_name + output = dump_table_schema @table_name + assert_match %r{create_table "#{@table_name}", force: :cascade}, output + assert_match %r{t\.serial\s+"seq",\s+null: false$}, output + assert_match %r{t\.bigserial\s+"bigseq",\s+null: false$}, output + end + end end |