Include ActiveRecord::TestFixtures in the fixtures RBI - #2707
Open
mokevnin wants to merge 1 commit into
Open
Conversation
Rails mixes `ActiveRecord::TestFixtures` into `ActiveSupport::TestCase` from the `active_record.test_fixtures` railtie initializer. Initializers do not run during gem RBI generation, so the include is missing from the gem RBI and Sorbet never sees the class methods the module contributes through `mixes_in_class_methods` — most visibly `fixtures`, so `fixtures :all` in a test case is an error under `srb tc` unless every app shims it by hand. The compiler already targets `ActiveSupport::TestCase` and knows Rails is loaded, so it is the natural place to make the include explicit.
mokevnin
force-pushed
the
fixtures-include
branch
from
August 28, 2026 17:10
5c44031 to
adf8bf5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Rails mixes
ActiveRecord::TestFixturesintoActiveSupport::TestCasefrom theactive_record.test_fixturesrailtie initializer. Initializers don't run during gem RBI generation, so that include never makes it into the gem RBI, and Sorbet doesn't see the class methods the module contributes throughmixes_in_class_methods— most visiblyfixtures:Today every Rails app using fixtures shims this by hand (a
sorbet/rbi/shimsentry, or a local DSL compiler that emits nothing but the include).ActiveRecordFixturesalready targetsActiveSupport::TestCaseand already knows Rails is loaded, so it's the natural place to make the include explicit.Implementation
One line in
decorate—mod.create_include("ActiveRecord::TestFixtures")— placed inside the existingcreate_path, after the "no fixtures, nothing to do" early return. Apps with no fixture files keep generating no RBI at all, so the existing behaviour for them is unchanged.Tests
Existing specs updated for the extra line; all of
spec/tapioca/dsl/compilers/active_record_fixtures_spec.rbpasses,bin/typecheckandrubocopare clean, andmanual/is regenerated viabin/docs.