Skip to content

Generate model-aware fixtures for configured tables - #113

Draft
nertzy wants to merge 1 commit into
with-model-test-unit-harnessfrom
resolve-configured-table-name-rdy
Draft

nertzy wants to merge 1 commit into
with-model-test-unit-harnessfrom
resolve-configured-table-name-rdy

Conversation

@nertzy

@nertzy nertzy commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

Fixture generation infers model constants from conventional table names. Models with a configured table_name can therefore fall back to raw SQL, bypassing model-backed serialization. Generated fixture filenames also do not necessarily tell Rails which model to use when loading them.

Extract model selection into ModelResolver, retaining conventional autoloading while matching loaded models by their actual table and connection pool. Collapse STI descendants to their eligible root, retain SQL fallback for tables without a usable model, and raise on ambiguous independent models before replacing fixture YAML.

Every model-backed fixture file now declares its resolved class through Rails’ native _fixture.model_class metadata, including conventionally named models. Rails can consume the generated files without a separate class map. Metadata-free conventionally named legacy fixture files remain compatible with Rails’ conventional fixture loading. Empty-file behavior still depends on actual rows, and the reserved _fixture record label is rejected rather than silently overwritten.

The README describes Rails’ existing mapping precedence, native loading transformations, and raw-table limitations. This adds no eager-loading requirement, public mapping API, or custom mapping cache.

@nertzy nertzy changed the title resolve configured table name rdy Resolve models by configured table name Sep 5, 2026
@nertzy
nertzy force-pushed the resolve-configured-table-name-rdy branch 2 times, most recently from 4f487c8 to 83554cd Compare September 7, 2026 00:55
@nertzy nertzy changed the title Resolve models by configured table name Generate model-aware fixtures for configured tables Sep 7, 2026
@nertzy
nertzy force-pushed the resolve-configured-table-name-rdy branch 3 times, most recently from f893e65 to 59033c0 Compare September 7, 2026 17:18
@nertzy
nertzy marked this pull request as draft September 7, 2026 21:41
Resolve eligible models by configured table names and write
Rails-native metadata so generated fixtures reload through their
selected model. Preserve conventional metadata-free legacy input
compatibility and document valid setup defaults.
@nertzy
nertzy force-pushed the resolve-configured-table-name-rdy branch from 59033c0 to 5995579 Compare September 8, 2026 19:46
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