aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/generators/db_system_change_generator_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test/generators/db_system_change_generator_test.rb')
-rw-r--r--railties/test/generators/db_system_change_generator_test.rb78
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