Skip to content

Commit fc30176

Browse files
justin808claude
andcommitted
Fix test failure with nil Rails constant
Use safe navigation operator (&.) when checking Rails.root to handle cases where Rails constant exists but is set to nil (e.g., via stub_const). This prevents NoMethodError when defined?(Rails) is true but Rails is nil. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 730b90a commit fc30176

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

lib/shakapacker/instance.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ class Shakapacker::Instance
77

88
def initialize(root_path: nil, config_path: nil)
99
# Use Rails.root if Rails is defined and no root_path is provided
10-
@root_path = root_path || (defined?(Rails) && Rails.root) || Pathname.new(Dir.pwd)
10+
@root_path = root_path || (defined?(Rails) && Rails&.root) || Pathname.new(Dir.pwd)
1111

1212
# Use Rails.root.join for config_path if Rails is defined and no config_path is provided
13-
default_config_path = if defined?(Rails) && Rails.root
13+
default_config_path = if defined?(Rails) && Rails&.root
1414
Rails.root.join("config/shakapacker.yml")
1515
else
1616
Pathname.new(File.join(Dir.pwd, "config/shakapacker.yml"))

0 commit comments

Comments
 (0)