Repository navigation
Support table(false) for models that set their own table_name - #75
Merged
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The implementation matches the stated behavior and includes comprehensive regression coverage.
0 open findings
What changed in this PR
Adds support for table(false) models that map themselves to existing tables.
Changes:
- Defers missing-table validation until after model configuration.
- Preserves STI validation and limits teardown cleanup to STI subclasses.
- Adds documentation and coverage across all supported test frameworks.
| File | Description |
|---|---|
lib/with_model/model.rb |
Verifies configured models and cleans up failed constants. |
lib/with_model/null_table.rb |
Supports explicitly named tables and adjusts teardown. |
lib/with_model/table.rb |
Adds the shared verification interface. |
lib/with_model/model/dsl.rb |
Documents existing-table behavior. |
spec/table_false_spec.rb |
Covers validation, teardown, and custom table names. |
spec/readme_spec.rb |
Tests the documented example. |
test/own_table_name_test.rb |
Adds Minitest coverage. |
test_unit/own_table_name_test.rb |
Adds Test::Unit coverage. |
README.md |
Documents existing-table usage and cleanup. |
CHANGELOG.md |
Records the new capability. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
nertzy
force-pushed
the
gh-74/table-false-own-table-name
branch
from
October 12, 2026 18:55
82aeb84 to
1c8a8f9
Compare
nertzy
force-pushed
the
gh-74/table-false-own-table-name
branch
2 times, most recently
from
October 12, 2026 19:25
b1df951 to
82747a7
Compare
A table(false) model whose superclass has no table, such as ActiveRecord::Base or an abstract class, raised InvalidSuperclass before its model block ran, so the model could never use an existing table. Check for a missing table after the model block instead, and accept the model when its own table exists: the one the block names with self.table_name, or else the one Active Record names after the model. Accept an abstract model outright, since it needs no table. Treat an abstract superclass as having nothing to inherit even when it has a table, and skip its inheritance-column check: Active Record never applies single table inheritance below an abstract class. Delete rows by type in teardown only for single table inheritance subclasses: a model that is its own base class uses a table the suite owns, which need not have an inheritance column. Fixes #74
nertzy
force-pushed
the
gh-74/table-false-own-table-name
branch
from
October 12, 2026 20:42
82747a7 to
1596f0e
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.

A
table(false)model whose superclass has no table (ActiveRecord::Base, or an abstract class) raisedWithModel::InvalidSuperclassduring setup, before its model block ran, so the model could never use an existing table.self.table_name, or else the one Active Record names after the modelself.table_nametable(false), since it needs no tableThe model's table must exist when the model is set up, unlike an STI superclass's table, which may still be created later. With nothing to inherit, a missing table is far more likely a mistaken attempt at STI than a table yet to come.
Fixes #74
Test plan
bundle exec rake(157 RSpec examples; 14 Minitest runs; 19 Test::Unit tests; StandardRB)