Set title for ADHOC Checkpoints overrides
closes VICE-4505 flag=discussion_checkpoints Test plan: - Test passes. - Create a Discussion with Checkpoints and set override dates for particular students. - Via the rails console, check the title of the parent and children overrides. - They should be: "1 student" or "N students". Change-Id: Iac9d1338f6dc79e98e0bd1f74a455191ab707a12 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/354896 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Martin Yosifov <martin.yosifov@instructure.com> QA-Review: Caleb Guanzon <cguanzon@instructure.com> Product-Review: Omar Soto-Fortuño <omar.soto@instructure.com>
This commit is contained in:
parent
d169b6dcb0
commit
ec615c1639
|
@ -42,4 +42,8 @@ class Checkpoints::AdhocOverrideCommonService < ApplicationService
|
|||
def existing_parent_override
|
||||
@checkpoint.parent_assignment.active_assignment_overrides.find_by(set_type: AssignmentOverride::SET_TYPE_ADHOC)
|
||||
end
|
||||
|
||||
def get_title(student_ids:)
|
||||
I18n.t({ one: "1 student", other: "%{count} students" }, count: student_ids.size)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -40,7 +40,8 @@ class Checkpoints::AdhocOverrideCreatorService < Checkpoints::AdhocOverrideCommo
|
|||
override = assignment.assignment_overrides.build(
|
||||
set_id: nil,
|
||||
set_type: AssignmentOverride::SET_TYPE_ADHOC,
|
||||
dont_touch_assignment: true
|
||||
dont_touch_assignment: true,
|
||||
title: get_title(student_ids:)
|
||||
)
|
||||
apply_overridden_dates(override, @override, shell_override:)
|
||||
override
|
||||
|
|
|
@ -31,12 +31,14 @@ class Checkpoints::AdhocOverrideUpdaterService < Checkpoints::AdhocOverrideCommo
|
|||
|
||||
apply_overridden_dates(override, @override, shell_override: false)
|
||||
|
||||
override.title = get_title(student_ids: valid_student_ids)
|
||||
build_override_students(override:, student_ids: valid_student_ids)
|
||||
override.save! if override.changed? || override.changed_student_ids.any?
|
||||
|
||||
override.assignment_override_students.where(user_id: student_ids_to_delete).destroy_all if student_ids_to_delete.any?
|
||||
|
||||
parent_override = existing_parent_override
|
||||
parent_override.title = get_title(student_ids: valid_student_ids)
|
||||
build_override_students(override: parent_override, student_ids: valid_student_ids)
|
||||
parent_override.save! if parent_override.changed? || parent_override.changed_student_ids.any?
|
||||
|
||||
|
|
|
@ -160,5 +160,21 @@ describe Checkpoints::AdhocOverrideCreatorService do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "title" do
|
||||
it "is 1 student when there is only one student" do
|
||||
override = { student_ids: [@student1.id], due_at: 2.days.from_now }
|
||||
created_override = service.call(checkpoint: @checkpoint, override:)
|
||||
|
||||
expect(created_override.title).to eq "1 student"
|
||||
end
|
||||
|
||||
it "is n students when there are n students" do
|
||||
override = { student_ids: [@student1.id, @student2.id], due_at: 2.days.from_now }
|
||||
created_override = service.call(checkpoint: @checkpoint, override:)
|
||||
|
||||
expect(created_override.title).to eq "2 students"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -123,6 +123,7 @@ describe Checkpoints::DiscussionCheckpointUpdaterService do
|
|||
expect(original_assignment_override.set_type).to eq "ADHOC"
|
||||
expect(original_assignment_override.due_at).to be_within(1.second).of(original_due_at)
|
||||
expect(original_student_ids).to match_array([students[0].id, students[1].id])
|
||||
expect(original_assignment_override.title).to eq "2 students"
|
||||
|
||||
# Updates the ADHOC override removing student 0, adding 2-4, and updating the due_at
|
||||
|
||||
|
@ -178,7 +179,10 @@ describe Checkpoints::DiscussionCheckpointUpdaterService do
|
|||
points_possible: 6
|
||||
)
|
||||
|
||||
expect(updated_checkpoint3.assignment_overrides.active.count).to eq 1
|
||||
assignment_overrides = updated_checkpoint3.assignment_overrides.active
|
||||
|
||||
expect(assignment_overrides.count).to eq 1
|
||||
expect(assignment_overrides.first.title).to eq "4 students"
|
||||
end
|
||||
|
||||
it "can create section overrides and update them" do
|
||||
|
|
Loading…
Reference in New Issue