Skip to content

Commit

Permalink
Merge pull request rails#52705 from thejonroberts/devcontainer-genera…
Browse files Browse the repository at this point in the history
…tor-dev-flag-error

Fix Devcontainer generator with --dev option path error
  • Loading branch information
rafaelfranca authored Aug 27, 2024
2 parents 4bb2227 + cd6e5d6 commit 63a532e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
4 changes: 4 additions & 0 deletions railties/lib/rails/generators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ module Generators
}
}

# We need to store the RAILS_DEV_PATH in a constant, otherwise the path
# can change when we FileUtils.cd.
RAILS_DEV_PATH = File.expand_path("../../..", __dir__) # :nodoc:

class << self
def configure!(config) # :nodoc:
api_only! if config.api_only
Expand Down
4 changes: 0 additions & 4 deletions railties/lib/rails/generators/rails/app/app_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,6 @@ def devcontainer
end

module Generators
# We need to store the RAILS_DEV_PATH in a constant, otherwise the path
# can change in Ruby 1.8.7 when we FileUtils.cd.
RAILS_DEV_PATH = File.expand_path("../../../../../..", __dir__)

class AppGenerator < AppBase
# :stopdoc:

Expand Down
40 changes: 40 additions & 0 deletions railties/test/generators/devcontainer_generator_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# frozen_string_literal: true

require "generators/generators_test_helper"
require "rails/generators/rails/devcontainer/devcontainer_generator"

module Rails
module Generators
class DevcontainerGeneratorTest < Rails::Generators::TestCase
include GeneratorsTestHelper

def test_generates_devcontainer_files
run_generator

assert_file ".devcontainer/compose.yaml"
assert_file ".devcontainer/Dockerfile"
assert_file ".devcontainer/devcontainer.json"
end

def test_default_json_has_no_mounts
run_generator

assert_devcontainer_json_file do |devcontainer_config|
assert_nil devcontainer_config["mounts"]
end
end

def test_dev_option_devcontainer_json_mounts_local_rails
run_generator ["--dev"]

assert_devcontainer_json_file do |devcontainer_json|
mounts = devcontainer_json["mounts"].sole

assert_equal "bind", mounts["type"]
assert_equal Rails::Generators::RAILS_DEV_PATH, mounts["source"]
assert_equal Rails::Generators::RAILS_DEV_PATH, mounts["target"]
end
end
end
end
end

0 comments on commit 63a532e

Please sign in to comment.