Foreign-key dependent fix Project assets, causing issue in reseed task and endpoint (integration)#826
Conversation
Test coverage91.14% line coverage reported by SimpleCov. |
There was a problem hiding this comment.
Pull request overview
Fixes /test/reseed cleanup failures by ensuring Scratch project assets don’t block seeded Project destruction via foreign-key constraints.
Changes:
- Add
Project -> scratch_assetsassociation withdependent: :destroyso associated assets are removed when a project is destroyed. - Extend the
test_seeds:destroyspec to cover the ScratchAsset cleanup case. - Add a model association spec to lock in the new dependency behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| app/models/project.rb | Ensures ScratchAsset rows tied to a project are destroyed when the project is destroyed, preventing FK violations during reseed cleanup. |
| spec/models/project_spec.rb | Verifies the new has_many :scratch_assets, dependent: :destroy association behavior. |
| spec/lib/test_seeds_spec.rb | Reproduces the reseed failure scenario by creating a project-scoped ScratchAsset and asserting it’s removed by the destroy task. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
I think it's hard to decide because we don't have any use cases for deleting scratch projects in production and we're only doing it in test. Think this is a great approach for now. |
Status
Points for consideration:
What's changed?
Fix /test/reseed failures caused by Scratch project assets blocking seeded project cleanup.
The test seed destroy task removes seeded lesson projects with Project.destroy_all, but project-scoped ScratchAsset records still referenced those projects.
Added a test and found is red with same error as sentry.
I only wonder here maybe if we want to make dependent :destroy or dependent nullify. (I guess this doesn't happen manually but it's worht to think if we would like to solve it in other way)