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/generators/db_system_change_generator_test.rb | |
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/generators/db_system_change_generator_test.rb')
-rw-r--r-- | railties/test/generators/db_system_change_generator_test.rb | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/railties/test/generators/db_system_change_generator_test.rb b/railties/test/generators/db_system_change_generator_test.rb new file mode 100644 index 0000000000..d476bfd2dc --- /dev/null +++ b/railties/test/generators/db_system_change_generator_test.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +require "generators/generators_test_helper" +require "rails/generators/rails/db/system/change/change_generator" + +module Rails + module Generators + module Db + module System + class ChangeGeneratorTest < Rails::Generators::TestCase + include GeneratorsTestHelper + + setup do + copy_gemfile( + GemfileEntry.new("sqlite3", nil, "Use sqlite3 as the database for Active Record") + ) + end + + test "change to invalid database" do + output = capture(:stderr) do + run_generator ["--to", "invalid-db"] + end + + 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 + run_generator ["--to", "postgresql"] + + assert_file("config/database.yml") do |content| + assert_match "adapter: postgresql", content + assert_match "database: test_app", content + end + + assert_file("Gemfile") do |content| + assert_match "# Use pg as the database for Active Record", content + assert_match "gem 'pg'", content + end + end + + test "change to mysql" do + run_generator ["--to", "mysql"] + + assert_file("config/database.yml") do |content| + assert_match "adapter: mysql2", content + assert_match "database: test_app", content + end + + assert_file("Gemfile") do |content| + assert_match "# Use mysql2 as the database for Active Record", content + assert_match "gem 'mysql2'", content + end + end + + test "change to sqlite3" do + run_generator ["--to", "sqlite3"] + + assert_file("config/database.yml") do |content| + assert_match "adapter: sqlite3", content + assert_match "db/development.sqlite3", content + end + + assert_file("Gemfile") do |content| + assert_match "# Use sqlite3 as the database for Active Record", content + assert_match "gem 'sqlite3'", content + end + end + end + end + end + end +end |