Skip to content

Commit

Permalink
Do not overwrite max_mark in Result.get_total_extra_marks (#7125)
Browse files Browse the repository at this point in the history
Fixes bug in assignment summary view
  • Loading branch information
pretendWhale authored Jun 26, 2024
1 parent 8e0986b commit b0650c6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- Ensure annotation rendering is updated in real-time for Jupyter notebooks (#7084)
- Fix MathJax rendering in annotations for Jupyter notebooks (#7084)
- Fix MathJax rendering of released overall comments (#7084)
- Fix bug in grade display for marks summary (#7125)

### 🔧 Internal changes

Expand Down
1 change: 0 additions & 1 deletion app/models/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ def self.get_total_extra_marks(result_ids, max_mark: nil, user_visibility: :ta_v
max_mark_hash[assessment_id] ||= Assignment.find(assessment_id)&.max_mark(user_visibility)
assignment_max_mark = max_mark_hash[assessment_id]
end
max_mark = max_mark_hash[assessment_id]
extra_marks_hash[id] += (extra_mark * assignment_max_mark / 100).round(2)
end
end
Expand Down
53 changes: 53 additions & 0 deletions spec/controllers/course_summaries_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,59 @@
end
end
end

context 'when there are percentage extra_marks' do
before do
assignments = create_list(:assignment_with_criteria_and_results, 3)
create(:grouping_with_inviter_and_submission, assignment: assignments[0])
create_list(:grade_entry_form_with_data, 2)
create(:grade_entry_form)
create(:marking_scheme, assessments: Assessment.all)
assignments.first.criteria.first.update!(max_mark: 3.0)
assignments.second.criteria.first.update!(max_mark: 2.0)
assignments.third.criteria.first.update!(max_mark: 5.0)
assignments.each do |assignment|
create(:extra_mark, result: assignment.groupings.first.current_result)
end

get_as instructor, :populate, params: { course_id: course.id }, format: :json
@response_data = response.parsed_body.deep_symbolize_keys
@data = @response_data[:data]
end

it 'returns the correct grades' do
expect(@data.length).to eq Student.count
Student.find_each do |student|
expected = {
id: student.id,
id_number: student.id_number,
user_name: student.user_name,
first_name: student.first_name,
last_name: student.last_name,
section_name: student.section_name,
email: student.email,
hidden: student.hidden,
assessment_marks: GradeEntryForm.all.map do |ges|
total_grade = ges.grade_entry_students.find_by(role: student).get_total_grade
out_of = ges.grade_entry_items.sum(:out_of)
percent = total_grade.nil? || out_of.nil? ? nil : (total_grade * 100 / out_of).round(2)
[ges.id.to_s.to_sym, {
mark: total_grade,
percentage: percent
}]
end.to_h
}
student.accepted_groupings.each do |g|
mark = g.current_result.get_total_mark
expected[:assessment_marks][g.assessment_id.to_s.to_sym] = {
mark: mark,
percentage: (mark * 100 / g.assignment.max_mark).round(2).to_s
}
end
expect(@data.map { |h| h.except(:weighted_marks) }).to include expected
end
end
end
end
end

Expand Down

0 comments on commit b0650c6

Please sign in to comment.