mirror of https://github.com/rails/rails
Merge pull request #52175 from y-yagi/correctly_generate_devcontainer_for_mysql2
Correctly generate Devcontainer setting for applications that using mysql2 gem
This commit is contained in:
commit
fc60a394c0
|
@ -22,13 +22,18 @@ module Rails
|
|||
def devcontainer_options
|
||||
@devcontainer_options ||= {
|
||||
app_name: Rails.application.railtie_name.chomp("_application"),
|
||||
database: !!defined?(ActiveRecord) && ActiveRecord::Base.connection_db_config.adapter,
|
||||
database: !!defined?(ActiveRecord) && database,
|
||||
active_storage: !!defined?(ActiveStorage),
|
||||
redis: !!(defined?(ActionCable) || defined?(ActiveJob)),
|
||||
system_test: File.exist?("test/application_system_test_case.rb"),
|
||||
node: File.exist?(".node-version"),
|
||||
}
|
||||
end
|
||||
|
||||
def database
|
||||
adapter = ActiveRecord::Base.connection_db_config.adapter
|
||||
adapter == "mysql2" ? "mysql" : adapter
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,4 +20,28 @@ class Rails::Command::DevcontainerTest < ActiveSupport::TestCase
|
|||
assert_match "system_test: true", output
|
||||
assert_match "node: false", output
|
||||
end
|
||||
|
||||
test "generates devcontainer for using mysql2 app" do
|
||||
build_app
|
||||
|
||||
Dir.chdir(app_path) do
|
||||
use_mysql2
|
||||
|
||||
output = rails "devcontainer"
|
||||
|
||||
assert_match "app_name: app_template", output
|
||||
assert_match "database: mysql", output
|
||||
assert_match "active_storage: true", output
|
||||
assert_match "redis: true", output
|
||||
assert_match "system_test: true", output
|
||||
assert_match "node: false", output
|
||||
|
||||
assert_match "ghcr.io/rails/devcontainer/features/mysql-client", read_file(".devcontainer/devcontainer.json")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def read_file(relative)
|
||||
File.read(app_path(relative))
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue