Skip to content

Commit

Permalink
Merge scores last_updated_by
Browse files Browse the repository at this point in the history
  • Loading branch information
jorg-vr committed Oct 28, 2024
1 parent eb69759 commit bc8b877
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ def merge_into(other, force: false, force_institution: false)
annotations.each { |a| a.update!(user: other) }
Annotation.where(last_updated_by_id: id).find_each { |a| a.update!(last_updated_by: other) }
questions.each { |q| q.update!(user: other) }
Score.where(last_updated_by_id: id).find_each { |s| s.update!(last_updated_by: other) }

evaluation_users.each do |eu|
if other.evaluation_users.find { |oeu| oeu.evaluation_id == eu.evaluation_id }
Expand Down
19 changes: 19 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,25 @@ def setup
assert_equal u2, a2.reload.last_updated_by
end

test 'merge should transfer scores last updated by' do
u1 = create :user
u2 = create :user

evaluation = create :evaluation, :with_submissions
exercise = evaluation.evaluation_exercises.first
score_item1 = create :score_item, evaluation_exercise: exercise,
description: 'First item',
maximum: '10.0'
feedback = evaluation.feedbacks.first
s = create :score, last_updated_by: u1, score_item: score_item1, score: 5, feedback: feedback

result = u1.merge_into(u2)

assert result
assert_not u1.persisted?
assert_equal u2, s.reload.last_updated_by
end

test 'jump back in should return most recent incomplete activity' do
user = create :user

Expand Down

0 comments on commit bc8b877

Please sign in to comment.