I successfully migrated the application from rails 6.0.7 and ruby 2.6.7 to rails 7.2.0 and ruby 3.3.5. The application is running successfully, however when I run the unit tests using Rspec, I am getting the following error:
An error occurred while loading ./spec/requests/webhooks_spec.rb.
Failure/Error: require File.expand_path("../../config/environment", __FILE__)
FrozenError:
can't modify frozen Array: [#<Pathname:/home/ptms/monroneylabels.com/lib>, #<Pathname:/home/ptms/monroneylabels.com/app/middleware>, #<Pathname:/home/ptms/monroneylabels.com/app/models/no-activerecord>, #<Pathname:/home/ptms/monroneylabels.com/app/models/data_sources>, #<Pathname:/home/ptms/monroneylabels.com/app/models/data_sources/inactive>, #<Pathname:/home/ptms/monroneylabels.com/app/models/data_sources/chrome_data>, #<Pathname:/home/ptms/monroneylabels.com/app/models/admin_only>, #<Pathname:/home/ptms/monroneylabels.com/app/models/jobs>, "/home/ptms/monroneylabels.com/vendor/gems/active_utils-3.2.0/lib", "/home/ptms/monroneylabels.com/vendor/gems/activemerchant-1.57.0/lib", "/home/ptms/monroneylabels.com/app/controllers", "/home/ptms/monroneylabels.com/app/helpers", "/home/ptms/monroneylabels.com/app/mailboxes", "/home/ptms/monroneylabels.com/app/mailers", "/home/ptms/monroneylabels.com/app/middleware", "/home/ptms/monroneylabels.com/app/models", "/home/ptms/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/doorkeeper-5.6.9/app/controllers", "/home/ptms/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/doorkeeper-5.6.9/app/helpers", "/home/ptms/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/inherited_resources-1.14.0/app/controllers", "/home/ptms/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/actionmailbox-7.2.0/app/controllers", "/home/ptms/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/actionmailbox-7.2.0/app/jobs", "/home/ptms/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/actionmailbox-7.2.0/app/models", "/home/ptms/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/activestorage-7.2.0/app/controllers", "/home/ptms/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/activestorage-7.2.0/app/controllers/concerns", "/home/ptms/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/activestorage-7.2.0/app/jobs", "/home/ptms/.rbenv/versions/3.3.5/lib/ruby/gems/3.3.0/gems/activestorage-7.2.0/app/models"]
# ./config/environment.rb:6:in `<top (required)>'
# ./spec/spec_helper.rb:27:in `<top (required)>'
# ./spec/requests/webhooks_spec.rb:1:in `<top (required)>'
No examples found.
Following is the list of gems I am using:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '3.3.5'
gem "bundler"
gem 'rails', '7.2.0'
gem 'httparty'
gem 'sprockets-rails', '~> 3.4' # Required for assets pipeline in Rails 7.2
# Keep the existing asset pipeline for now
group :assets do
gem 'sass-rails', "~> 6.0"
gem 'coffee-rails', "~> 4.2"
gem 'uglifier', '~>4.2'
end
group :development do
gem "factory_bot_rails"
gem "pry"
#gem 'rb-readline' #see https://github.com/rails/rails/issues/26658
end
gem 'bootsnap', '>= 1.1.0', require: false
gem "curb"#
gem "rake"
gem "settingslogic", "~> 2.0"
gem "inherited_resources", "~> 1.14"
gem "authlogic"#, "~> 3.6"
gem "resque-scheduler" #for Action Mailbox
gem "handsoap", "~> 1.4"
gem "factory_bot", "~> 6.2"
gem "rspec"
gem "rspec-rails"
# Removed soap4r-ruby1.9 as it's deprecated and not compatible with Ruby 3
gem 'mechanize', "~> 2.8"
gem 'will_paginate', "~>3.3"
# Replaced aws-sdk-v1 with aws-sdk-s3 for Ruby 3.3.5 compatibility
gem 'aws-sdk-s3', '~> 1.196'
gem "resque", "~> 2.4"
gem "bcrypt", "~> 3.1" #for password hashing
gem 'ey_config', "=0.0.7" #Engineyard gem to read config/ey.yml
gem 'rqrcode_png', git: "https://github.com/DCarper/rqrcode_png.git" #see https://github.com/DCarper/rqrcode_png/issues/16
gem "airbrake", "~>12.0"
gem "resque_mailer"#, "~> 2.4"
gem "memcache-client", "~> 1.8.5"
gem "rchardet", "~> 1.8"
gem 'test-unit'
group :test do
gem 'vcr'
gem 'webmock'
gem 'simplecov', :require => false
gem 'simplecov-rcov'
end
gem 'wicked_pdf', "~> 1.3"
gem "i18n-js", "~>3.9"
gem "itunes_receipt_validator" #for verifying iOS purchases
gem 'fastimage', "~>2.2" #for getting image dimensions for instavin
gem "stripe", "~>12.2"
gem 'newrelic_rpm', "~>7.0" #free tier
gem 'rack-attack', "~>6.6" #i.e. for ratelimiting only; use Cloudflare to ban IP's
gem "payday", git: 'https://github.com/CompanyMood/payday' #i.e. fix for BigDecimal error
gem "acts_as_list"#, "~>0.9" #i.e. for addendum items
gem 'open_uri_redirections', "~>0.2" #i.e. to handle redirects from https to http
gem 'savon', '~> 2.12.0' #i.e. used by ChromeData and ChromeSelect
gem "engineyard", "= 3.2.1" #i.e. supports Rails 4.2 but no v5 cookbooks format
gem 'paperclip', git: 'https://github.com/sd/paperclip', branch: 'remove-mimemagic'
gem "pg", "~> 1.4"
gem "memoist"
gem "byebug"
gem "geokit", "~>1.13" #for map in admin area; IP geolocation is done by Matomo app
#gem 'twilio-ruby'
gem "audited", "~> 5.0"
gem "lograge"
gem "colorize" #for colorizing log files
gem 'jwt' #for ToyotaData encryption
gem "sendgrid-actionmailer"
gem 'descriptive_statistics', '~> 2.4.0', :require => 'descriptive_statistics/safe' # i.e. for calculating std deviation for car-locator
gem 'rails-controller-testing' #i.e. to get @assigns var
gem 'activemerchant', '~> 1.137.0'
gem "doorkeeper", "~> 5.6.0"#, i.e. Oauth initializer, controllers and models
gem 'pkce_challenge' #i.e. for testing Oauth client
gem "spreadsheet" #i.e. for creating spreadsheets for capstone partners
gem "docsplit" #for withclutch
gem "rack-cors" #i.e. for web-browser extension so they can access our API through browser
# gem "lockup" #i.e. require password for QA environment entry - temporarily disabled for Rails 7.2 upgrade
gem 'trix-rails', require: 'trix' #Trix WYSIWYG text editor
gem "mini_magick" #i.e. for previews of inline images in ticket replies
gem "image_processing"
#ready for Rails 6.1
gem 'activeadmin', '~> 3.2'
gem 'kaminari', '~> 1.2' # Required for ActiveAdmin pagination
gem 'deathbycaptcha', '~> 6.0.0'
gem "activejob-status"
gem "dalli"
gem "aws-sdk-mturk", "~> 1.50"
gem "pdf-reader"
gem "recaptcha"
gem 'select2-rails'
gem "redis", "~> 5.0" # Updated for Ruby 3.3.5 compatibility
gem "mutex_m" # Required for Ruby 3.3.5 compatibility
gem "ostruct" # Required for Ruby 3.3.5 compatibility
gem "net-ftp" # Required for Ruby 3.3.5 compatibility
From my debugging, I suspect that the issue is occuring because of the way autoloader works in the new version of rails. I tried replacing the places where I’ve imported the files wherein previouly += operator was used and now I am using .join() method to append the files list. Please refer below:
# -- all .rb files in that directory are automatically loaded.
- config.autoload_paths += [config.root.join('lib')]
- #config.load_paths += Dir["#{Rails.root}/vendor/gems/**"].map do |dir|
- # File.directory?(lib = "#{dir}/lib") ? lib : dir
- #end
- config.autoload_paths += %W( #{Rails.root}/app/middleware )
- config.autoload_paths += Dir["#{Rails.root}/vendor/gems/**"].map do |dir|
- File.directory?(lib = "#{dir}/lib") ? lib : dir
- end
- config.autoload_paths += %W( #{Rails.root}/app/models/no-activerecord )
- config.autoload_paths += %W( #{Rails.root}/app/models/data_sources )
- config.autoload_paths += %W( #{Rails.root}/app/models/data_sources/inactive )
- config.autoload_paths += %W( #{Rails.root}/app/models/data_sources/chrome_data )
- config.autoload_paths += %W( #{Rails.root}/app/models/admin_only )
- config.autoload_paths += %W( #{Rails.root}/app/models/jobs )
+ # Rails 7.2 autoload paths configuration
+ # Use the proper Rails 7.2 way to configure autoload paths
+ config.autoload_paths += [
+ config.root.join('lib'),
+ config.root.join('app/middleware'),
+ config.root.join('app/models/no-activerecord'),
+ config.root.join('app/models/data_sources'),
+ config.root.join('app/models/data_sources/inactive'),
+ config.root.join('app/models/data_sources/chrome_data'),
+ config.root.join('app/models/admin_only'),
+ config.root.join('app/models/jobs')
+ ]
+
+ # Add vendor gem paths
+ config.autoload_paths += Dir["#{Rails.root}/vendor/gems/**"].select do |dir|
+ File.directory?("#{dir}/lib")
+ end.map { |dir| "#{dir}/lib" }
However, still I am getting the same error. Any help regarding to why this must be happening and if there are any possible ways to resolves this will be highly appritiated, as I’ve spent a lot of time to resolve this but still no luck.
Also, please let me know if any more details are required.