diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-09-04 20:22:42 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-09-04 20:26:03 +0900 |
commit | 9551bad98fc7604d460427946183bdfca7a2f8d4 (patch) | |
tree | 8ffea5e01e19f5c652f4edb7ba19913e4e26a06f /activerecord/test | |
parent | 07bac9ef93d98a1e31cd5b2ce2aabc1e57816604 (diff) | |
download | rails-9551bad98fc7604d460427946183bdfca7a2f8d4.tar.gz rails-9551bad98fc7604d460427946183bdfca7a2f8d4.tar.bz2 rails-9551bad98fc7604d460427946183bdfca7a2f8d4.zip |
Should quote composite primary key names
Otherwise using reserved words as composite primary key names will be
failed as an invalid SQL.
Fixes #30518.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/primary_keys_test.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/test/cases/primary_keys_test.rb b/activerecord/test/cases/primary_keys_test.rb index e0888f5fe9..a36d786b40 100644 --- a/activerecord/test/cases/primary_keys_test.rb +++ b/activerecord/test/cases/primary_keys_test.rb @@ -334,16 +334,26 @@ class CompositePrimaryKeyTest < ActiveRecord::TestCase t.string :region t.integer :code end + @connection.create_table(:travels, primary_key: ["from", "to"], force: true) do |t| + t.string :from + t.string :to + end end def teardown - @connection.drop_table(:uber_barcodes, if_exists: true) + @connection.drop_table :uber_barcodes, if_exists: true + @connection.drop_table :barcodes_reverse, if_exists: true + @connection.drop_table :travels, if_exists: true end def test_composite_primary_key assert_equal ["region", "code"], @connection.primary_keys("uber_barcodes") end + def test_composite_primary_key_with_reserved_words + assert_equal ["from", "to"], @connection.primary_keys("travels") + end + def test_composite_primary_key_out_of_order skip if current_adapter?(:SQLite3Adapter) assert_equal ["code", "region"], @connection.primary_keys("barcodes_reverse") |