Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/school_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class SchoolProject < ApplicationRecord
belongs_to :school
belongs_to :project
has_many :feedback, dependent: :destroy
has_many :school_project_transitions, autosave: false, dependent: :nullify
has_many :school_project_transitions, autosave: false, dependent: :destroy

include Statesman::Adapters::ActiveRecordQueries[
transition_class: ::SchoolProjectTransition,
Expand Down
2 changes: 1 addition & 1 deletion spec/models/school_project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
it { is_expected.to belong_to(:school) }
it { is_expected.to belong_to(:project) }
it { is_expected.to have_many(:feedback).dependent(:destroy) }
it { is_expected.to have_many(:school_project_transitions).dependent(:nullify) }
it { is_expected.to have_many(:school_project_transitions).dependent(:destroy) }

describe '#status' do
it 'defaults to unsubmitted' do
Expand Down
16 changes: 16 additions & 0 deletions spec/services/student_removal_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@
# Other student's project should remain
expect(Project.exists?(other_school_project.id)).to be true
end

it 'deletes school project transitions when deleting projects' do
project = create(:project, user_id: student.id, school: school)
school_project = project.school_project

# Transition the project to create SchoolProjectTransition records
school_project.transition_status_to!(:submitted, student.id)
school_project.transition_status_to!(:returned, teacher.id)

results = service.remove_students

expect(results.first[:error]).to be_nil
expect(Project.exists?(project.id)).to be false
expect(SchoolProject.exists?(school_project.id)).to be false
expect(SchoolProjectTransition.where(school_project_id: school_project.id).count).to eq(0)
end
end

context 'when student does not have a role in the school' do
Expand Down