diff options
author | Andrew White <pixeltrix@users.noreply.github.com> | 2018-11-08 14:44:16 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-08 14:44:16 +0000 |
commit | 4fe27cdc15b88fed5ae725a886b7e96202f649a8 (patch) | |
tree | 29a476831be0fe4574a41b646d903540d8495fde /activerecord/test/cases | |
parent | edea469d2876e73e336411c695f64b7286c58167 (diff) | |
parent | 6e0ff0053702cd1dc0f149f4ca59f968a2560d72 (diff) | |
download | rails-4fe27cdc15b88fed5ae725a886b7e96202f649a8.tar.gz rails-4fe27cdc15b88fed5ae725a886b7e96202f649a8.tar.bz2 rails-4fe27cdc15b88fed5ae725a886b7e96202f649a8.zip |
Merge pull request #31382 from fatkodima/create_table-if_not_exists
Add an :if_not_exists option to create_table
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/migration_test.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/activerecord/test/cases/migration_test.rb b/activerecord/test/cases/migration_test.rb index 5d060c8899..661163b4a1 100644 --- a/activerecord/test/cases/migration_test.rb +++ b/activerecord/test/cases/migration_test.rb @@ -127,6 +127,36 @@ class MigrationTest < ActiveRecord::TestCase assert_equal 20131219224947, migrator.current_version end + def test_create_table_raises_if_already_exists + connection = Person.connection + connection.create_table :testings, force: true do |t| + t.string :foo + end + + assert_raise(ActiveRecord::StatementInvalid) do + connection.create_table :testings do |t| + t.string :foo + end + end + ensure + connection.drop_table :testings, if_exists: true + end + + def test_create_table_with_if_not_exists_true + connection = Person.connection + connection.create_table :testings, force: true do |t| + t.string :foo + end + + assert_nothing_raised do + connection.create_table :testings, if_not_exists: true do |t| + t.string :foo + end + end + ensure + connection.drop_table :testings, if_exists: true + end + def test_create_table_with_force_true_does_not_drop_nonexisting_table # using a copy as we need the drop_table method to # continue to work for the ensure block of the test |