aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/commands
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test/commands')
-rw-r--r--railties/test/commands/console_test.rb27
-rw-r--r--railties/test/commands/db_system_change_test.rb62
-rw-r--r--railties/test/commands/dbconsole_test.rb20
3 files changed, 66 insertions, 43 deletions
diff --git a/railties/test/commands/console_test.rb b/railties/test/commands/console_test.rb
index 0b2fe204f8..1941c83d6d 100644
--- a/railties/test/commands/console_test.rb
+++ b/railties/test/commands/console_test.rb
@@ -94,28 +94,7 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
assert_match(/\sspecial-production\s/, output)
end
- def test_rails_env_is_production_when_first_argument_is_p
- assert_deprecated do
- start ["p"]
- assert_match(/\sproduction\s/, output)
- end
- end
-
- def test_rails_env_is_test_when_first_argument_is_t
- assert_deprecated do
- start ["t"]
- assert_match(/\stest\s/, output)
- end
- end
-
- def test_rails_env_is_development_when_argument_is_d
- assert_deprecated do
- start ["d"]
- assert_match(/\sdevelopment\s/, output)
- end
- end
-
- def test_rails_env_is_dev_when_argument_is_dev_and_dev_env_is_present
+ def test_rails_env_is_dev_when_environment_option_is_dev_and_dev_env_is_present
Rails::Command::ConsoleCommand.class_eval do
alias_method :old_environments, :available_environments
@@ -124,9 +103,7 @@ class Rails::ConsoleTest < ActiveSupport::TestCase
end
end
- assert_deprecated do
- assert_match("dev", parse_arguments(["dev"])[:environment])
- end
+ assert_match("dev", parse_arguments(["-e", "dev"])[:environment])
ensure
Rails::Command::ConsoleCommand.class_eval do
undef_method :available_environments
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
diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb
index ce048ac527..adb168f7a3 100644
--- a/railties/test/commands/dbconsole_test.rb
+++ b/railties/test/commands/dbconsole_test.rb
@@ -99,28 +99,12 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase
ENV["RACK_ENV"] = nil
end
- def test_rails_env_is_development_when_argument_is_dev
- assert_deprecated do
- stub_available_environments([ "development", "test" ]) do
- assert_match("development", parse_arguments([ "dev" ])[:environment])
- end
- end
- end
-
def test_rails_env_is_development_when_environment_option_is_dev
stub_available_environments([ "development", "test" ]) do
assert_match("development", parse_arguments([ "-e", "dev" ])[:environment])
end
end
- def test_rails_env_is_dev_when_argument_is_dev_and_dev_env_is_present
- assert_deprecated do
- stub_available_environments([ "dev" ]) do
- assert_match("dev", parse_arguments([ "dev" ])[:environment])
- end
- end
- end
-
def test_mysql
start(adapter: "mysql2", database: "db")
assert_not aborted
@@ -265,14 +249,14 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase
stdout = capture(:stdout) do
Rails::Command.invoke(:dbconsole, ["-h"])
end
- assert_match(/rails dbconsole \[environment\]/, stdout)
+ assert_match(/rails dbconsole \[options\]/, stdout)
end
def test_print_help_long
stdout = capture(:stdout) do
Rails::Command.invoke(:dbconsole, ["--help"])
end
- assert_match(/rails dbconsole \[environment\]/, stdout)
+ assert_match(/rails dbconsole \[options\]/, stdout)
end
attr_reader :aborted, :output