diff --git a/app/models/course_section.rb b/app/models/course_section.rb index 0b26439d5c0..1ae4a8245e0 100644 --- a/app/models/course_section.rb +++ b/app/models/course_section.rb @@ -121,7 +121,8 @@ class CourseSection < ActiveRecord::Base if (self.nonxlist_course.course_sections.active.count == 0 || (self.nonxlist_course.course_sections.active.count == 1 && self.nonxlist_course.course_sections.active.first.enrollments.count == 0)) && - self.nonxlist_course.workflow_state == "created" + (self.nonxlist_course.workflow_state == "created" || + self.nonxlist_course.workflow_state == "claimed") self.nonxlist_course.workflow_state = "deleted" self.nonxlist_course.save! end diff --git a/spec/lib/sis_csv_importer_spec.rb b/spec/lib/sis_csv_importer_spec.rb index f48bf60de0c..08fdd907201 100644 --- a/spec/lib/sis_csv_importer_spec.rb +++ b/spec/lib/sis_csv_importer_spec.rb @@ -798,6 +798,27 @@ describe SIS::SisCsv do xlist_course.workflow_state.should == "claimed" end + it 'should mark the original course deleted if it is made empty due to crosslisting' do + process_csv_data( + "course_id,short_name,long_name,account_id,term_id,status", + "C001,TC 101,Test Course 101,,,active", + "C002,TC 101,Test Course 101,,,active" + ) + process_csv_data( + "section_id,course_id,name,start_date,end_date,status", + "S001,C001,Sec1,2011-1-05 00:00:00,2011-4-14 00:00:00,active", + "S002,C002,Sec2,2012-12-05 00:00:00,2012-12-14 00:00:00,active", + "S003,C002,Sec3,2012-12-05 00:00:00,2012-12-14 00:00:00,active" + ) + process_csv_data( + "xlist_course_id,section_id,status", + "X001,S001,active", + "X001,S002,active" + ) + @account.courses.find_by_sis_source_id("C002").workflow_state.should_not == "deleted" + @account.courses.find_by_sis_source_id("C001").workflow_state.should == "deleted" + end + it 'should work with xlists with an xlist course defined' do process_csv_data( "course_id,short_name,long_name,account_id,term_id,status",