Fix logic error in MediaObject.ensure_attachment

closes LA-431
flag=none

test plan:
  - spec/models/media_object_spec.rb passes

Change-Id: I42b1138e9f6a89b2b7fda4b1749f70145c439c37
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/222360
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
QA-Review: Jeremy Stanley <jeremy@instructure.com>
Product-Review: Ed Schiebel <eschiebel@instructure.com>
This commit is contained in:
Ed Schiebel 2020-01-08 09:06:00 -05:00
parent 6f906bfc53
commit 7f250ea705
2 changed files with 9 additions and 1 deletions

View File

@ -298,7 +298,7 @@ class MediaObject < ActiveRecord::Base
def ensure_attachment
return if self.attachment_id
sources = self.media_sources
return unless sources&.length
return unless sources.present?
attachment = build_attachment({
"context" => context,

View File

@ -268,6 +268,14 @@ describe MediaObject do
mo.retrieve_details
expect(mo.media_type).to eql("")
end
it "doesn't create the attachment until media_sources exist" do
allow(@mock_kaltura).to receive(:media_sources).and_return([])
mo = @media_object
mo.process_retrieved_details(@mock_entry, @media_type, @assets)
att = Attachment.where(:media_entry_id => mo[:media_id])
expect(att).to be_empty
end
end
describe ".guaranteed_title" do