Skip to content

Commit 63a532e

Browse files
authored
Merge pull request rails#52705 from thejonroberts/devcontainer-generator-dev-flag-error
Fix Devcontainer generator with --dev option path error
2 parents 4bb2227 + cd6e5d6 commit 63a532e

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

railties/lib/rails/generators.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ module Generators
6060
}
6161
}
6262

63+
# We need to store the RAILS_DEV_PATH in a constant, otherwise the path
64+
# can change when we FileUtils.cd.
65+
RAILS_DEV_PATH = File.expand_path("../../..", __dir__) # :nodoc:
66+
6367
class << self
6468
def configure!(config) # :nodoc:
6569
api_only! if config.api_only

railties/lib/rails/generators/rails/app/app_generator.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,6 @@ def devcontainer
283283
end
284284

285285
module Generators
286-
# We need to store the RAILS_DEV_PATH in a constant, otherwise the path
287-
# can change in Ruby 1.8.7 when we FileUtils.cd.
288-
RAILS_DEV_PATH = File.expand_path("../../../../../..", __dir__)
289-
290286
class AppGenerator < AppBase
291287
# :stopdoc:
292288

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# frozen_string_literal: true
2+
3+
require "generators/generators_test_helper"
4+
require "rails/generators/rails/devcontainer/devcontainer_generator"
5+
6+
module Rails
7+
module Generators
8+
class DevcontainerGeneratorTest < Rails::Generators::TestCase
9+
include GeneratorsTestHelper
10+
11+
def test_generates_devcontainer_files
12+
run_generator
13+
14+
assert_file ".devcontainer/compose.yaml"
15+
assert_file ".devcontainer/Dockerfile"
16+
assert_file ".devcontainer/devcontainer.json"
17+
end
18+
19+
def test_default_json_has_no_mounts
20+
run_generator
21+
22+
assert_devcontainer_json_file do |devcontainer_config|
23+
assert_nil devcontainer_config["mounts"]
24+
end
25+
end
26+
27+
def test_dev_option_devcontainer_json_mounts_local_rails
28+
run_generator ["--dev"]
29+
30+
assert_devcontainer_json_file do |devcontainer_json|
31+
mounts = devcontainer_json["mounts"].sole
32+
33+
assert_equal "bind", mounts["type"]
34+
assert_equal Rails::Generators::RAILS_DEV_PATH, mounts["source"]
35+
assert_equal Rails::Generators::RAILS_DEV_PATH, mounts["target"]
36+
end
37+
end
38+
end
39+
end
40+
end

0 commit comments

Comments
 (0)