From d0a254fccce62be4c0b0cdf50402d285ca3f10dd Mon Sep 17 00:00:00 2001 From: James Williams Date: Mon, 3 Aug 2015 07:57:45 -0600 Subject: [PATCH] don't leave unresolved link placeholders on migration failure closes #CNVS-22242 Change-Id: Ie3fc503ae2439ffc63f90ba35dabc07ef4716d1f Reviewed-on: https://gerrit.instructure.com/59815 Tested-by: Jenkins Reviewed-by: Jeremy Stanley Product-Review: James Williams QA-Review: James Williams --- app/models/content_migration.rb | 1 + .../content_migration/course_copy_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/models/content_migration.rb b/app/models/content_migration.rb index d86cb8a06467..32daf067a93d 100644 --- a/app/models/content_migration.rb +++ b/app/models/content_migration.rb @@ -253,6 +253,7 @@ def fail_with_error!(exception_or_info) self.workflow_state = :failed job_progress.fail if job_progress && !skip_job_progress save + resolve_content_links! # don't leave placeholders end # deprecated warning format diff --git a/spec/models/content_migration/course_copy_spec.rb b/spec/models/content_migration/course_copy_spec.rb index 4347e0344b30..b6d363904798 100644 --- a/spec/models/content_migration/course_copy_spec.rb +++ b/spec/models/content_migration/course_copy_spec.rb @@ -461,5 +461,24 @@ expect(cal2_2.end_at.to_i).to eq cal2.end_at.to_i expect(cal2_2.description).to eq '' end + + it "should not leave link placeholders on catastrophic failure" do + att = Attachment.create!(:filename => 'test.txt', :display_name => "testing.txt", + :uploaded_data => StringIO.new('file'), :folder => Folder.root_folders(@copy_from).first, :context => @copy_from) + topic = @copy_from.discussion_topics.create!(:title => "some topic", :message => "") + + Importers::WikiPageImporter.stubs(:process_migration).raises(ArgumentError) + + expect{ + run_course_copy + }.to raise_error(ArgumentError) + + new_att = @copy_to.attachments.where(migration_id: CC::CCHelper.create_key(att)).first + expect(new_att).not_to be_nil + + new_topic = @copy_to.discussion_topics.where(migration_id: CC::CCHelper.create_key(topic)).first + expect(new_topic).not_to be_nil + expect(new_topic.message).to match(Regexp.new("/courses/#{@copy_to.id}/files/#{new_att.id}/preview")) + end end end