Skip to content

Include ActiveRecord::TestFixtures in the fixtures RBI - #2707

Open
mokevnin wants to merge 1 commit into
Shopify:mainfrom
mokevnin:fixtures-include
Open

Include ActiveRecord::TestFixtures in the fixtures RBI#2707
mokevnin wants to merge 1 commit into
Shopify:mainfrom
mokevnin:fixtures-include

Conversation

@mokevnin

Copy link
Copy Markdown

Motivation

Rails mixes ActiveRecord::TestFixtures into ActiveSupport::TestCase from the active_record.test_fixtures railtie 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 through mixes_in_class_methods — most visibly fixtures:

class PostTest < ActiveSupport::TestCase
  fixtures :all # Method `fixtures` does not exist on `T.class_of(PostTest)` (7003)
end

Today every Rails app using fixtures shims this by hand (a sorbet/rbi/shims entry, or a local DSL compiler that emits nothing but the include). ActiveRecordFixtures already targets ActiveSupport::TestCase and already knows Rails is loaded, so it's the natural place to make the include explicit.

Implementation

One line in decoratemod.create_include("ActiveRecord::TestFixtures") — placed inside the existing create_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.rb passes, bin/typecheck and rubocop are clean, and manual/ is regenerated via bin/docs.

@mokevnin
mokevnin requested a review from a team as a code owner August 28, 2026 17:07
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant