Skip to content

Commit 2aa2d8e

Browse files
committed
Fix CI matrix on Ruby 3.x + Rails 5.2/6.0/6.1: require "logger" before rails
Phase 2a's integration test scaffolding (spec/rails_helper.rb and spec/dummy/config/application.rb) both do `require "rails"` eagerly. ActiveSupport 5.2/6.0/6.1 references `Logger::Severity` inside lib/active_support/logger_thread_safe_level.rb without first requiring "logger" — this works on Ruby 2.x (Logger was more eagerly autoloaded) but raises NameError: uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger on Ruby 3.x. Rails 7.0+ fixed this at the ActiveSupport level; older Rails combined with Ruby 3.x needs an explicit `require "logger"` before any AS/Rails code runs. Matrix cells affected (from the 0.5.0 publish cycle's CI run 24290748435): - Ruby 2.7 x Rails 6.0, 6.1 - Ruby 3.0 x Rails 5.2, 6.0, 6.1 - Ruby 3.1 x Rails 6.0, 6.1 - Ruby 3.2 x Rails 6.1 - Ruby 3.3 x Rails 6.1 All Rails 7.0+ cells (all Ruby versions) pass unchanged. Fix is test-support-only — `spec/rails_helper.rb` and `spec/dummy/config/application.rb` both gain a single `require "logger"` at the top, before their `require "rails"`. Zero runtime impact on the shipped gems (these files are not in spec.files for either gem). This is a pure CI cleanup for 0.5.0 — no new release needed.
1 parent 38b7804 commit 2aa2d8e

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

spec/dummy/config/application.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
require_relative "boot"
44

5+
# Ruby 3.x + ActiveSupport 5.2/6.0/6.1 compat: Logger must be loaded before
6+
# any active_support require, otherwise logger_thread_safe_level.rb raises
7+
# `NameError: uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger`.
8+
# Rails 7.0+ includes its own `require "logger"` so this is only needed for
9+
# the older-Rails matrix cells.
10+
require "logger"
11+
512
require "rails"
613
require "action_controller/railtie"
714

spec/rails_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
# Rack::Test for request dispatch. Unit specs continue to use spec_helper.rb
55
# (no Rails boot).
66

7+
# Load stdlib Logger BEFORE any Rails/ActiveSupport require. ActiveSupport
8+
# 5.2/6.0/6.1 references `Logger::Severity` inside
9+
# `lib/active_support/logger_thread_safe_level.rb` without first requiring
10+
# "logger", which works on Ruby 2.x (Logger was autoloaded more eagerly)
11+
# but raises `NameError: uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger`
12+
# on Ruby 3.x. Rails 7.0+ fixed this at the AS level; older Rails combined
13+
# with Ruby 3.x needs this workaround. The matrix cells affected are
14+
# Ruby 3.0-3.3 × Rails 5.2/6.0/6.1 in .github/workflows/ci.yml.
15+
require "logger"
16+
717
# .rspec has `--require spec_helper`, so spec_helper is auto-loaded before
818
# rails_helper. spec_helper calls `require "mysql_genius"` when Rails is not
919
# yet defined, so lib/mysql_genius.rb skips `require "mysql_genius/engine"`

0 commit comments

Comments
 (0)