save attachment before copy to new namespace

fixes CNVS-35913

test plan
 - copy attachment to course in different root_account
 - it should work

Change-Id: I1b4e99331b2299960522ac628ff3a2cbce27873c
Reviewed-on: https://gerrit.instructure.com/107024
Tested-by: Jenkins
Reviewed-by: Cody Cutrer <cody@instructure.com>
Product-Review: Rob Orton <rob@instructure.com>
QA-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
Rob Orton 2017-03-30 14:33:00 -06:00
parent 801bf38274
commit 5a8a764d7c
2 changed files with 2 additions and 0 deletions

View File

@ -279,6 +279,7 @@ class Attachment < ActiveRecord::Base
context.log_merge_result("File \"#{dup.folder && dup.folder.full_name}/#{dup.display_name}\" created")
end
if context.respond_to?(:root_account_id) && self.namespace != context.root_account.file_namespace
dup.save_without_broadcasting!
dup.make_rootless
dup.change_namespace(context.root_account.file_namespace)
end

View File

@ -580,6 +580,7 @@ describe Attachment do
@context = courseb = course_factory(account: Account.create)
b = a.clone_for(courseb, nil, overwrite: true)
expect(b.id).not_to be_nil
b.save
expect(b.root_attachment_id).to eq nil
expect(b.namespace).to eq courseb.root_account.file_namespace