Skip to content

Commit

Permalink
don't leave unresolved link placeholders on migration failure
Browse files Browse the repository at this point in the history
closes #CNVS-22242

Change-Id: Ie3fc503ae2439ffc63f90ba35dabc07ef4716d1f
Reviewed-on: https://gerrit.instructure.com/59815
Tested-by: Jenkins
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
Product-Review: James Williams  <jamesw@instructure.com>
QA-Review: James Williams  <jamesw@instructure.com>
  • Loading branch information
maneframe committed Aug 24, 2015
1 parent 9a788d6 commit d0a254f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/models/content_migration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions spec/models/content_migration/course_copy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 => "<img src='/courses/#{@copy_from.id}/files/#{att.id}/preview'>")

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

0 comments on commit d0a254f

Please sign in to comment.