diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2019-01-16 22:01:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-16 22:01:10 +0100 |
commit | 90536ebfb3f0ca6971bc3ea4e43f20b8e977539b (patch) | |
tree | 8eb4807d949160d38a3d239ea33d37318d38b5aa /railties/test/commands | |
parent | 7e52e3b1c004eb22521c844b6adf69a2689cc1da (diff) | |
parent | cb3f78aa7c8f14921501703ed0780f2a428bc6a1 (diff) | |
download | rails-90536ebfb3f0ca6971bc3ea4e43f20b8e977539b.tar.gz rails-90536ebfb3f0ca6971bc3ea4e43f20b8e977539b.tar.bz2 rails-90536ebfb3f0ca6971bc3ea4e43f20b8e977539b.zip |
Merge pull request #34832 from gmcgibbon/db_system_change_command
Add rails db:system:change command
Diffstat (limited to 'railties/test/commands')
-rw-r--r-- | railties/test/commands/db_system_change_test.rb | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/railties/test/commands/db_system_change_test.rb b/railties/test/commands/db_system_change_test.rb new file mode 100644 index 0000000000..2ff45a7878 --- /dev/null +++ b/railties/test/commands/db_system_change_test.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +require "isolation/abstract_unit" +require "rails/command" +require "rails/commands/db/system/change/change_command" + +class Rails::Command::Db::System::ChangeCommandTest < ActiveSupport::TestCase + include ActiveSupport::Testing::Isolation + + setup { build_app } + + teardown { teardown_app } + + test "change to existing database" do + change_database(to: "sqlite3") + + output = change_database(to: "sqlite3") + + assert_match "identical config/database.yml", output + assert_match "gsub Gemfile", output + end + + test "change to invalid database" do + output = change_database(to: "invalid-db") + + assert_match <<~MSG.squish, output + Invalid value for --to option. + Supported preconfigurations are: + mysql, postgresql, sqlite3, oracle, frontbase, + ibm_db, sqlserver, jdbcmysql, jdbcsqlite3, + jdbcpostgresql, jdbc. + MSG + end + + test "change to postgresql" do + output = change_database(to: "postgresql") + + assert_match "force config/database.yml", output + assert_match "gsub Gemfile", output + end + + test "change to mysql" do + output = change_database(to: "mysql") + + assert_match "force config/database.yml", output + assert_match "gsub Gemfile", output + end + + test "change to sqlite3" do + change_database(to: "postgresql") + output = change_database(to: "sqlite3") + + assert_match "force config/database.yml", output + assert_match "gsub Gemfile", output + end + + private + def change_database(to:, **options) + args = ["--to", to] + rails "db:system:change", args, **options + end +end |