test: add ORM coverage for BelongsToMany and testing transaction utilities#69
test: add ORM coverage for BelongsToMany and testing transaction utilities#69tmgbedu wants to merge 1 commit into
Conversation
…ities Add sqlite tests for the BelongsToMany relationship (attach/detach, attach_related/detach_related, eager loading, pivot access, timestamps, explicit pivot table) and unit tests for the DatabaseTransaction / RefreshDatabase testing helpers. Support these paths by defining methods that existing relationship code already depended on but were undefined: - QueryBuilder.table() and QueryBuilder.without_global_scopes() - Attribute.delete_attribute() Refactor BelongsToMany pivot attach/detach to build pivot records through the query builder directly. The fillable-guard fix that originally motivated this branch already landed on main. Duplicate post-processor tests (covered by the merged query/processors suite) and the morph relationship tests/source changes (which require a separate MorphOne/MorphToMany registry migration) were dropped from this PR.
48a0355 to
1113554
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
✅ Code review verdict: APPROVE (posting as comment — GitHub blocks self-approval on own PR). APPROVE — review only (not merging). Reproduced gates from
Latent-bug fixes verified (methods main's BelongsToMany already calls but were undefined anywhere):
Pivot refactor (core relationship code) — acceptable risk:
Tests: real sqlite integration with real assertions; net-new (main had zero BelongsToMany/transaction coverage → no duplication vs #147/#154-#161). Transaction unit tests mock DB wiring appropriately (assert_awaited_once), not hollow. Minor (non-blocking): three shallow assertions — |
Rebased onto current main and trimmed to the genuinely net-new, green content.
What this PR adds
test_belongs_to_many.py— sqlite coverage for the BelongsToMany relationship: attach/detach, attach_related/detach_related, eager loading (incl. empty), pivot access,with_timestamps, explicit pivot table, and the query-has helpers.testing/test_transaction.py— unit tests for theDatabaseTransaction/RefreshDatabasetest-helper utilities (previously used by the test infra but never unit-tested).QueryBuilder.table()andQueryBuilder.without_global_scopes()Attribute.delete_attribute()Dropped since this branch was opened
82439510,660698f8,a2d9f847,f2d82f03are all ancestors of main) — nothing left to do there.tests/masoniteorm/query/processors/test_post_processors.py(merged coverage PRs) covering the same four processor classes; the near-identical copy here was removed.MorphOne/MorphMany/MorphToMany) — these were written against the pre-Coverage: masoniteorm relationships (BelongsToMany, Morph*) #159 relationship internals and fail on current main. Making them pass requires completing theMorphOne/MorphToManyregistry/descriptor migration that Coverage: masoniteorm relationships (BelongsToMany, Morph*) #159 applied toMorphManyonly. That is a separate, reviewable change and is tracked as a follow-up rather than bundled here.Gates
uv run pytest --ignore=tests/masoniteorm/postgres --cov→ 1820 passed, 7 skipped, total coverage 79.65% (fail_under 68%).ruff check+ruff format --checkclean.