Skip to content

Commit afad196

Browse files
committed
fixed rails_test_app/create_app.rb - don't require rails/version or bundler! it messes up any rails commands
1 parent d562739 commit afad196

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

rails_test_app/create_app.rb

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
rails_version = latest_version
2626
end
2727

28+
2829
# Get currently installed Rails versions
2930
rails_gems = `gem list rails -l`
3031
installed_versions = rails_gems.scan(/rails \(([^)]+)\)/).flatten.first&.split(", ") || []
3132

33+
3234
# Check if we need to install this version
3335
if !installed_versions.include?(rails_version)
3436
puts "Rails #{rails_version} not found. Installing..."
@@ -37,13 +39,16 @@
3739
puts "Rails #{rails_version} already installed"
3840
end
3941

40-
require "bundler/setup"
42+
43+
# Don't require bundler/setup - we want to avoid loading our project's Gemfile
4144

4245
require "fileutils"
43-
require "rails/version"
4446
require "erb"
4547
require "sorbet-runtime"
4648

49+
# Make the rails_version available as an instance variable for the ERB templates
50+
@rails_version = rails_version
51+
4752
# Path constants
4853
ROOT_DIR = File.expand_path("..", __dir__)
4954
TEMPLATE_DIR = File.expand_path("templates", __dir__)
@@ -54,6 +59,8 @@
5459
"PATH" => ENV["PATH"],
5560
"HOME" => ENV["HOME"],
5661
"RAILS_ENV" => "development",
62+
"RAILS_VERSION" => nil,
63+
"RUBY_VERSION" => nil,
5764
"BUNDLE_GEMFILE" => nil,
5865
"GEM_HOME" => nil,
5966
"GEM_PATH" => nil,
@@ -114,6 +121,8 @@ def copy_template(file, target_path = nil)
114121
if !skip_app_creation
115122
# Use rails new to create a new application
116123
puts "Creating new Rails application with version #{rails_version}..."
124+
125+
# Try using gem's exec command with proper version specification
117126
rails_new_command = "rails _#{rails_version}_ new #{RAILS_APP_DIR} --skip-git --skip-keeps --skip-action-cable " \
118127
"--skip-sprockets --skip-javascript --skip-hotwire --skip-jbuilder --skip-asset-pipeline " \
119128
"--skip-bootsnap --api -T"
@@ -124,6 +133,30 @@ def copy_template(file, target_path = nil)
124133
puts "=> Deleting default .rubocop.yml"
125134
FileUtils.rm_f(File.join(RAILS_APP_DIR, ".rubocop.yml"))
126135

136+
# Verify we're using the correct Rails version defaults
137+
if rails_version.start_with?("8.0")
138+
defaults_dir = File.join(RAILS_APP_DIR, "config/initializers")
139+
rails72_defaults = File.join(defaults_dir, "new_framework_defaults_7_2.rb")
140+
rails80_defaults = File.join(defaults_dir, "new_framework_defaults_8_0.rb")
141+
142+
# Check if we have the wrong defaults file
143+
if File.exist?(rails72_defaults) && !File.exist?(rails80_defaults)
144+
abort(<<~ERROR)
145+
ERROR: Expected Rails 8.0 but found Rails 7.2 defaults file!
146+
147+
This indicates a serious problem with how Rails is being executed.
148+
You have Rails 8.0.1 installed, but the generator is using Rails 7.2 behavior.
149+
150+
Possible solutions to try:
151+
1. Make sure your Ruby environment is set up correctly
152+
2. Try using a direct path to the rails executable
153+
3. Try running the command manually outside of this script
154+
155+
Command attempted: #{rails_new_command}
156+
ERROR
157+
end
158+
end
159+
127160
# Update Gemfile to include the local logstruct gem and test gems
128161
gemfile_path = File.join(RAILS_APP_DIR, "Gemfile")
129162
gemfile_content = File.read(gemfile_path)
@@ -179,11 +212,6 @@ def copy_template(file, target_path = nil)
179212
copy_template(relative_path)
180213
end
181214

182-
# # Run bundle install again to ensure all dependencies are correctly resolved
183-
# puts "Running final bundle install..."
184-
# Dir.chdir(RAILS_APP_DIR) do
185-
# system(clean_env, "bundle install") || abort("Bundle install failed")
186-
# end
187215

188216
# Set up the database
189217
puts "Setting up Rails application in #{RAILS_APP_DIR}..."

rails_test_app/templates/app/controllers/logging_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_custom
5252
message: "Custom log message #{i}",
5353
level: LogStruct::Level::Info,
5454
source: LogStruct::Source::App,
55-
data: {
55+
additional_data: {
5656
iteration: i,
5757
timestamp: Time.now.to_f,
5858
random: rand(100)

rails_test_app/templates/app/jobs/test_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def perform(arg)
2323
source: LogStruct::Source::Job,
2424
err_class: e.class,
2525
message: e.message,
26-
data: {job_class: self.class.name, job_id: job_id}
26+
additional_data: {job_class: self.class.name, job_id: job_id}
2727
)
2828
logger.error(exception_log)
2929
end

0 commit comments

Comments
 (0)