aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-06-06 15:53:33 +0200
committerYves Senn <yves.senn@gmail.com>2014-06-06 15:53:33 +0200
commit8fa8b7124b4a28591c47883199f9d6bdd77a827e (patch)
treebed981ca043f7fa5c69c110c141433fe7ab5e384 /activerecord/test
parentd23cbbb3ee8f49441873b713ee0255c22895e332 (diff)
downloadrails-8fa8b7124b4a28591c47883199f9d6bdd77a827e.tar.gz
rails-8fa8b7124b4a28591c47883199f9d6bdd77a827e.tar.bz2
rails-8fa8b7124b4a28591c47883199f9d6bdd77a827e.zip
`ActiveRecord::SchemaMigration` has no primary key.
Before this patch, using `ActiveRecord::Base.primary_key_prefix_type` with `:table_name_with_underscore` would change the `SchemaMigration` model to have a primary key. This resulted in broken queries for PG because it tried to return the inserted PK (which does not exist). Closes #15051. Closes #15419.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/ar_schema_test.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/cases/ar_schema_test.rb b/activerecord/test/cases/ar_schema_test.rb
index 7290cd53b1..8700b20dee 100644
--- a/activerecord/test/cases/ar_schema_test.rb
+++ b/activerecord/test/cases/ar_schema_test.rb
@@ -17,6 +17,20 @@ if ActiveRecord::Base.connection.supports_migrations?
ActiveRecord::SchemaMigration.delete_all rescue nil
end
+ def test_has_no_primary_key
+ old_primary_key_prefix_type = ActiveRecord::Base.primary_key_prefix_type
+ ActiveRecord::Base.primary_key_prefix_type = :table_name_with_underscore
+ assert_nil ActiveRecord::SchemaMigration.primary_key
+
+ ActiveRecord::SchemaMigration.create_table
+ assert_difference "ActiveRecord::SchemaMigration.count", 1 do
+ ActiveRecord::SchemaMigration.create version: 12
+ end
+ ensure
+ ActiveRecord::SchemaMigration.drop_table
+ ActiveRecord::Base.primary_key_prefix_type = old_primary_key_prefix_type
+ end
+
def test_schema_define
ActiveRecord::Schema.define(:version => 7) do
create_table :fruits do |t|