aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/migration
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-12-26 18:22:18 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-12-26 18:22:18 +0900
commit6783bcab7ab11f2ced4b711d3518422e35e3dc01 (patch)
tree9fb99caae21443d2150db03901038088ae3a168d /activerecord/test/cases/migration
parent9507b4f02d332cccf76ca803b967dab69ab6bfdd (diff)
downloadrails-6783bcab7ab11f2ced4b711d3518422e35e3dc01.tar.gz
rails-6783bcab7ab11f2ced4b711d3518422e35e3dc01.tar.bz2
rails-6783bcab7ab11f2ced4b711d3518422e35e3dc01.zip
SQLite: Add more test cases for adding primary key
Diffstat (limited to 'activerecord/test/cases/migration')
-rw-r--r--activerecord/test/cases/migration/compatibility_test.rb106
1 files changed, 48 insertions, 58 deletions
diff --git a/activerecord/test/cases/migration/compatibility_test.rb b/activerecord/test/cases/migration/compatibility_test.rb
index eb6d65d1b1..26d3b3e29d 100644
--- a/activerecord/test/cases/migration/compatibility_test.rb
+++ b/activerecord/test/cases/migration/compatibility_test.rb
@@ -179,9 +179,7 @@ module LegacyPrimaryKeyTestCases
@migration.migrate(:up)
- legacy_pk = LegacyPrimaryKey.columns_hash["id"]
- assert_not legacy_pk.bigint?
- assert_not legacy_pk.null
+ assert_legacy_primary_key
legacy_ref = LegacyPrimaryKey.columns_hash["legacy_ref_id"]
assert_not legacy_ref.bigint?
@@ -216,74 +214,50 @@ module LegacyPrimaryKeyTestCases
assert_match %r{create_table "legacy_primary_keys", id: :integer, default: nil}, schema
end
- if current_adapter?(:Mysql2Adapter, :PostgreSQLAdapter)
- def test_legacy_primary_key_in_create_table_should_be_integer
- @migration = Class.new(migration_class) {
- def change
- create_table :legacy_primary_keys, id: false do |t|
- t.primary_key :id
- end
+ def test_legacy_primary_key_in_create_table_should_be_integer
+ @migration = Class.new(migration_class) {
+ def change
+ create_table :legacy_primary_keys, id: false do |t|
+ t.primary_key :id
end
- }.new
+ end
+ }.new
- @migration.migrate(:up)
+ @migration.migrate(:up)
- schema = dump_table_schema "legacy_primary_keys"
- assert_match %r{create_table "legacy_primary_keys", id: :(?:integer|serial), (?!default: nil)}, schema
- end
+ assert_legacy_primary_key
+ end
- def test_legacy_primary_key_in_change_table_should_be_integer
- @migration = Class.new(migration_class) {
- def change
- create_table :legacy_primary_keys, id: false do |t|
- t.integer :dummy
- end
- change_table :legacy_primary_keys do |t|
- t.primary_key :id
- end
+ def test_legacy_primary_key_in_change_table_should_be_integer
+ @migration = Class.new(migration_class) {
+ def change
+ create_table :legacy_primary_keys, id: false do |t|
+ t.integer :dummy
end
- }.new
-
- @migration.migrate(:up)
-
- schema = dump_table_schema "legacy_primary_keys"
- assert_match %r{create_table "legacy_primary_keys", id: :(?:integer|serial), (?!default: nil)}, schema
- end
-
- def test_add_column_with_legacy_primary_key_should_be_integer
- @migration = Class.new(migration_class) {
- def change
- create_table :legacy_primary_keys, id: false do |t|
- t.integer :dummy
- end
- add_column :legacy_primary_keys, :id, :primary_key
+ change_table :legacy_primary_keys do |t|
+ t.primary_key :id
end
- }.new
+ end
+ }.new
- @migration.migrate(:up)
+ @migration.migrate(:up)
- schema = dump_table_schema "legacy_primary_keys"
- assert_match %r{create_table "legacy_primary_keys", id: :(?:integer|serial), (?!default: nil)}, schema
- end
+ assert_legacy_primary_key
end
- if current_adapter?(:SQLite3Adapter)
- def test_add_column_with_legacy_primary_key_should_work
- @migration = Class.new(migration_class) {
- def change
- create_table :legacy_primary_keys, id: false do |t|
- t.integer :dummy
- end
- add_column :legacy_primary_keys, :id, :primary_key
+ def test_add_column_with_legacy_primary_key_should_be_integer
+ @migration = Class.new(migration_class) {
+ def change
+ create_table :legacy_primary_keys, id: false do |t|
+ t.integer :dummy
end
- }.new
+ add_column :legacy_primary_keys, :id, :primary_key
+ end
+ }.new
- @migration.migrate(:up)
+ @migration.migrate(:up)
- assert_equal "id", LegacyPrimaryKey.primary_key
- legacy_pk = LegacyPrimaryKey.columns_hash["id"]
- assert_not legacy_pk.null
- end
+ assert_legacy_primary_key
end
def test_legacy_join_table_foreign_keys_should_be_integer
@@ -352,6 +326,22 @@ module LegacyPrimaryKeyTestCases
assert_match %r{create_table "legacy_primary_keys", id: :bigint, default: nil}, schema
end
end
+
+ private
+ def assert_legacy_primary_key
+ assert_equal "id", LegacyPrimaryKey.primary_key
+
+ legacy_pk = LegacyPrimaryKey.columns_hash["id"]
+
+ assert_equal :integer, legacy_pk.type
+ assert_not legacy_pk.bigint?
+ assert_not legacy_pk.null
+
+ if current_adapter?(:Mysql2Adapter, :PostgreSQLAdapter)
+ schema = dump_table_schema "legacy_primary_keys"
+ assert_match %r{create_table "legacy_primary_keys", id: :(?:integer|serial), (?!default: nil)}, schema
+ end
+ end
end
module LegacyPrimaryKeyTest