Skip to content

Commit 44cf903

Browse files
committed
foreign-key dependent fix
1 parent 5db4210 commit 44cf903

3 files changed

Lines changed: 7 additions & 1 deletion

File tree

app/models/project.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module Types
1414
has_many :remixes, dependent: :nullify, class_name: :Project, foreign_key: :remixed_from_id, inverse_of: :parent
1515
has_many :components, -> { order(default: :desc, name: :asc) }, dependent: :destroy, inverse_of: :project
1616
has_one :scratch_component, dependent: :destroy, inverse_of: :project, required: false
17+
has_many :scratch_assets, dependent: :destroy
1718
has_many :project_errors, dependent: :nullify
1819
has_many_attached :images
1920
has_many_attached :videos

spec/lib/test_seeds_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
create(:teacher_role, user_id: creator_id, school:)
2121
school_class = create(:school_class, school_id: school.id, teacher_ids: [creator_id])
2222
create(:class_student, student_id: student_1, school_class_id: school_class.id)
23-
create(:lesson, school_id: school.id, user_id: creator_id)
23+
lesson = create(:lesson, school_id: school.id, user_id: creator_id)
24+
lesson.project.update!(project_type: Project::Types::CODE_EDITOR_SCRATCH)
25+
create(:scratch_asset, project: lesson.project)
26+
@scratch_project_id = lesson.project.id
2427
end
2528

2629
it 'destroys all seed data' do
@@ -31,6 +34,7 @@
3134
expect(SchoolClass.where(school_id: school.id)).not_to exist
3235
expect(Lesson.where(school_id: school.id)).not_to exist
3336
expect(Project.where(school_id: school.id)).not_to exist
37+
expect(ScratchAsset.where(project_id: @scratch_project_id)).not_to exist
3438
end
3539
end
3640

spec/models/project_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
it { is_expected.to belong_to(:parent).optional(true) }
1212
it { is_expected.to have_many(:remixes).dependent(:nullify) }
1313
it { is_expected.to have_many(:components) }
14+
it { is_expected.to have_many(:scratch_assets).dependent(:destroy) }
1415
it { is_expected.to have_many(:project_errors).dependent(:nullify) }
1516
it { is_expected.to have_many_attached(:images) }
1617
it { is_expected.to have_many_attached(:videos) }

0 commit comments

Comments
 (0)