Skip to content

Commit cd6e5d6

Browse files
thejonrobertsjeromedalbert
authored andcommitted
Fix rails#52704 rails g devcontainer --dev error
Devcontainer generator errors with uninitialized constant Rails::Generators::RAILS_DEV_PATH, which is defined with AppGenerator in .../generators/rails/app/app_generator.rb. Move definition to rails/generators. Co-authored-by: Jerome Dalbert <[email protected]>
1 parent ec667e5 commit cd6e5d6

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
@@ -61,6 +61,10 @@ module Generators
6161
}
6262
}
6363

64+
# We need to store the RAILS_DEV_PATH in a constant, otherwise the path
65+
# can change when we FileUtils.cd.
66+
RAILS_DEV_PATH = File.expand_path("../../..", __dir__) # :nodoc:
67+
6468
class << self
6569
def configure!(config) # :nodoc:
6670
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)