Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear scores of empty feedback on submission select #4333

Merged
merged 1 commit into from
Jan 19, 2023
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
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