Include ActiveRecord::TestFixtures in the fixtures RBI - #2707
Merged
Conversation
mokevnin
force-pushed
the
fixtures-include
branch
from
August 28, 2026 17:10
5c44031 to
adf8bf5
Compare
KaanOzkan
reviewed
Sep 1, 2026
KaanOzkan
left a comment
Contributor
There was a problem hiding this comment.
Thanks, this is a unique change but I think it's beneficial to have it in the compiler as you said.
| # ~~~ | ||
| # | ||
| # The `include` is generated because Rails mixes `ActiveRecord::TestFixtures` into | ||
| # `ActiveSupport::TestCase` from the `active_record.test_fixtures` railtie initializer, which |
Contributor
There was a problem hiding this comment.
I couldn't find that initializer, I think it's being included through this load hook https://github.com/rails/rails/blob/4130768a1b0d95da640ac792920e54988cf2d12f/railties/lib/rails/test_help.rb#L15-L24. Can we change the wording here?
Contributor
Author
There was a problem hiding this comment.
You're right, there is no such initializer — thanks for digging. It's the :active_support_test_case load hook in rails/test_help.rb, which an app requires from test_helper.rb, so it never runs during RBI generation. Reworded here, in manual/ and in the PR description.
KaanOzkan
approved these changes
Sep 2, 2026
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.
…ed fixtures Two fixes from review. The include does not come from a railtie initializer — there is none. It comes from the `:active_support_test_case` load hook in `rails/test_help.rb`, which an app requires from `test_helper.rb`, so it never runs during RBI generation. Reword the comment and the manual accordingly. The early return sat below the `select!` that drops fixture sets whose model constant cannot be resolved, so an app with fixture files but no matching models wrote `fixtures :all` and still got no include. Move the return above the `select!`: apps with no fixture files at all keep generating nothing, everything else gets the include. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
KaanOzkan
force-pushed
the
fixtures-include
branch
from
September 2, 2026 15:03
23685dd to
2eae4fb
Compare
Remove the accessor-dependent early return so the DSL RBI always records the Rails test mixin. Combine the no-fixture output and typechecking coverage, and clarify why the runtime `include` is otherwise missing.
KaanOzkan
force-pushed
the
fixtures-include
branch
from
September 3, 2026 13:29
2eae4fb to
a7de26f
Compare
KaanOzkan
enabled auto-merge
September 3, 2026 13:54
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 the:active_support_test_caseload hook inrails/test_help.rb. That file is required from an app'stest_helper.rb, so the hook never runs during RBI generation, the 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")— inside the existingcreate_path.The early return now sits above the
select!that drops fixture sets whose model constant can't be resolved, so the two cases it used to conflate are separated: an app with no fixture files at all still generates no RBI, while an app that has fixture files but no matching models gets an RBI with just the include (it writesfixtures :alltoo).Tests
spec/tapioca/dsl/compilers/active_record_fixtures_spec.rbupdated for the extra line, plus a new case for fixtures with no associated model at all; the whole file passes.bin/typecheckandrubocopare clean, andmanual/is regenerated viabin/docs.