diff --git a/app/models/report.rb b/app/models/report.rb index c7d88774..d813d0d0 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -13,10 +13,6 @@ class Report < ApplicationRecord end def media_attachments - media_attachments = [] - statuses.each do |s| - media_attachments.concat s.media_attachments - end - media_attachments + MediaAttachment.where(status_id: status_ids) end end diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb index 80b8cc55..6c272384 100644 --- a/spec/models/report_spec.rb +++ b/spec/models/report_spec.rb @@ -10,4 +10,15 @@ describe Report do expect(report.statuses).to eq [status] end end + + describe 'media_attachments' do + it 'returns media attachments from statuses' do + status = Fabricate(:status) + media_attachment = Fabricate(:media_attachment, status: status) + _other_media_attachment = Fabricate(:media_attachment) + report = Fabricate(:report, status_ids: [status.id]) + + expect(report.media_attachments).to eq [media_attachment] + end + end end