Skip to content

Commit

Permalink
Merge pull request #4333 from dodona-edu/fix/clear-empty-scores-on-su…
Browse files Browse the repository at this point in the history
…bmission

Clear scores of empty feedback on submission select
  • Loading branch information
chvp authored Jan 19, 2023
2 parents b19eb9d + 4e59e82 commit bc892fd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/feedback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ def uncomplete
end

def reset_feedback_after_submission_update
return unless will_save_change_to_submission_id? && submission_id_in_database.present?
return unless will_save_change_to_submission_id?

Submission.find(submission_id_in_database).annotations.where(evaluation_id: evaluation_id).destroy_all
Submission.find(submission_id_in_database).annotations.where(evaluation_id: evaluation_id).destroy_all if submission_id_in_database.present?
scores.each(&:destroy)
end

Expand Down
17 changes: 17 additions & 0 deletions test/controllers/feedbacks_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class FeedbacksControllerTest < ActionDispatch::IntegrationTest

def setup
@evaluation = create :evaluation, :with_submissions
@evaluation.update(users: @evaluation.users + [users(:student)])
exercise = @evaluation.evaluation_exercises.first
@score_item1 = create :score_item, evaluation_exercise: exercise,
description: 'First item',
Expand Down Expand Up @@ -57,6 +58,22 @@ def setup
assert_equal 0, @feedback.scores.count
end

test 'scores are reset when a submission is changed from empty' do
feedback = @evaluation.feedbacks.find_by(submission_id: nil, evaluation_exercise: @evaluation.evaluation_exercises.first)
assert_not_empty feedback.scores

s = create :submission, exercise: feedback.exercise, user: feedback.user, course: feedback.evaluation.series.course

patch evaluation_feedback_path(@evaluation, feedback), params: {
feedback: {
submission_id: s.id
}
}
feedback.reload
assert_equal s.id, feedback.submission_id
assert_empty feedback.scores
end

test 'A lot of scores are reset when a submission is changed' do
score_items = (1..10).map do |i|
create :score_item, evaluation_exercise: @feedback.evaluation_exercise,
Expand Down

0 comments on commit bc892fd

Please sign in to comment.