From e600ffb6b9039f1e9e93a1cc9f1e34758ab7fc33 Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Fri, 10 Nov 2023 14:02:04 +0100 Subject: [PATCH 1/2] Never remove exercises that are part of an evaluation --- app/jobs/remove_activities_job.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/jobs/remove_activities_job.rb b/app/jobs/remove_activities_job.rb index 14f7a8c612..7026602af7 100644 --- a/app/jobs/remove_activities_job.rb +++ b/app/jobs/remove_activities_job.rb @@ -2,6 +2,7 @@ class RemoveActivitiesJob < ApplicationJob # permanently remove activities that match all of the following criteria: # - status is 'removed' # - updated_at is more than 1 month ago + # - not part of an evaluation # - one of the following is true: # - draft is true (never published) # - series_memberships is empty and less then 25 submissions and latest submission is more than 1 month ago @@ -28,6 +29,8 @@ def perform next if activity.submissions.present? && activity.submissions.reorder(:created_at).last.created_at > 1.month.ago end + next if EvaluationExercise.exists?(exercise_id: activity.id) + # destroy submissions first explicitly, as they are dependent: :restrict_with_error activity.submissions.destroy_all From a29e6e6917035cd05ac34f6ec3d7b8cefd5f8797 Mon Sep 17 00:00:00 2001 From: jorg-vr Date: Fri, 10 Nov 2023 14:09:29 +0100 Subject: [PATCH 2/2] Add test --- test/jobs/remove_activities_job_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/jobs/remove_activities_job_test.rb b/test/jobs/remove_activities_job_test.rb index 9f283fbf58..a64036e1f2 100644 --- a/test/jobs/remove_activities_job_test.rb +++ b/test/jobs/remove_activities_job_test.rb @@ -102,4 +102,13 @@ class RemoveActivitiesJobTest < ActiveJob::TestCase RemoveActivitiesJob.perform_now end end + + test 'should not remove activities that are part of an evaluation' do + e = create :exercise, status: :removed, draft: false, updated_at: 2.months.ago + create :evaluation_exercise, exercise: e + + assert_no_difference 'Exercise.count' do + RemoveActivitiesJob.perform_now + end + end end