diff options
author | yui-knk <spiketeika@gmail.com> | 2016-01-30 16:47:51 +0900 |
---|---|---|
committer | yui-knk <spiketeika@gmail.com> | 2016-01-30 16:47:51 +0900 |
commit | 444c4d05fea817fcad991e79fa128b640e2e4ff1 (patch) | |
tree | 442c6ef8de128d9828637249d613e1ada0203868 /activerecord/test | |
parent | 6162c49e40582bf058a6bb82ccc0cfb8f92332b6 (diff) | |
download | rails-444c4d05fea817fcad991e79fa128b640e2e4ff1.tar.gz rails-444c4d05fea817fcad991e79fa128b640e2e4ff1.tar.bz2 rails-444c4d05fea817fcad991e79fa128b640e2e4ff1.zip |
Warn if `AR.primary_key` is called for a table who has composite primary key
If `AR.primary_key` is called for a table who has composite primary key,
the method returns `nil`. This behavior sometimes generates invalid SQL.
The first time developers notice to invalid SQL is when they execute
SQL. This commit enables developers to know they are doing something
dangerous as soon as possible.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/primary_keys_test.rb | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/activerecord/test/cases/primary_keys_test.rb b/activerecord/test/cases/primary_keys_test.rb index 7e18313c00..360efd0b2b 100644 --- a/activerecord/test/cases/primary_keys_test.rb +++ b/activerecord/test/cases/primary_keys_test.rb @@ -262,6 +262,13 @@ class CompositePrimaryKeyTest < ActiveRecord::TestCase assert_equal ["region", "code"], @connection.primary_keys("barcodes") end + def test_primary_key_issues_warning + warning = capture(:stderr) do + @connection.primary_key("barcodes") + end + assert_match(/WARNING: Rails does not support composite primary key\./, warning) + end + def test_collectly_dump_composite_primary_key schema = dump_table_schema "barcodes" assert_match %r{create_table "barcodes", primary_key: \["region", "code"\]}, schema |