undelete assignment override on child undelete
When a deleted AssignmentOverrideStudent is undeleted, also undelete the parent AssignmentOverride if it is deleted. fixes GRADE-849 Test plan: - Create a course with at least one student. - Add an assignment, but assign it to only one student. - Unenroll that student from the course. - Reenroll the student. - Edit the assignment from above; check that it is still listed as assigned to the student from before, and that changing any parameters of the assignment (such as the due date) completes successfully instead of throwing an error. Change-Id: I7cf56adeb2479dc5f7dec225aebb84ef9d1d0145 Reviewed-on: https://gerrit.instructure.com/141873 Tested-by: Jenkins Reviewed-by: Shahbaz Javeed <sjaveed@instructure.com> Reviewed-by: Keith T. Garner <kgarner@instructure.com> Reviewed-by: Spencer Olson <solson@instructure.com> QA-Review: Indira Pai <ipai@instructure.com> Product-Review: Keith T. Garner <kgarner@instructure.com>
This commit is contained in:
parent
cb01b493e4
commit
3b79d2c15a
|
@ -165,6 +165,12 @@ class AssignmentOverride < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def undestroy(active_state: 'active')
|
||||
self.workflow_state = active_state
|
||||
save!
|
||||
true
|
||||
end
|
||||
|
||||
scope :active, -> { where(:workflow_state => 'active') }
|
||||
|
||||
scope :visible_students_only, -> (visible_ids) do
|
||||
|
|
|
@ -27,6 +27,7 @@ class AssignmentOverrideStudent < ActiveRecord::Base
|
|||
after_create :update_cached_due_dates
|
||||
after_destroy :update_cached_due_dates
|
||||
after_destroy :destroy_override_if_needed
|
||||
after_update :undelete_override_if_deleted
|
||||
before_validation :default_values
|
||||
before_validation :clean_up_assignment_if_override_student_orphaned
|
||||
|
||||
|
@ -82,6 +83,11 @@ class AssignmentOverrideStudent < ActiveRecord::Base
|
|||
end
|
||||
protected :destroy_override_if_needed
|
||||
|
||||
def undelete_override_if_deleted
|
||||
assignment_override.undestroy if workflow_state_was == 'deleted' && active? && assignment_override&.deleted?
|
||||
end
|
||||
protected :undelete_override_if_deleted
|
||||
|
||||
def self.clean_up_for_assignment(assignment)
|
||||
return unless assignment.context_type == "Course"
|
||||
return if assignment.new_record?
|
||||
|
|
|
@ -146,6 +146,16 @@ describe AssignmentOverrideStudent do
|
|||
expect(@ao.reload).to be_deleted
|
||||
end
|
||||
|
||||
it 'undeletes its override if it is undeletd and the override is deleted' do
|
||||
adhoc_override_with_student
|
||||
|
||||
@override_student.destroy
|
||||
@ao.reload
|
||||
|
||||
@override_student.undestroy
|
||||
expect(@ao.reload).not_to be_deleted
|
||||
end
|
||||
|
||||
describe "clean_up_for_assignment" do
|
||||
it "if callbacks aren't run clean_up_for_assignment should delete invalid overrides" do
|
||||
adhoc_override_with_student
|
||||
|
|
Loading…
Reference in New Issue