]> cat aescling's git repositories - mastodon.git/commitdiff
Reports spec for media attachments, clean up method (#2660)
authorMatt Jankowski <mjankowski@thoughtbot.com>
Sun, 30 Apr 2017 16:15:49 +0000 (12:15 -0400)
committerEugen Rochko <eugen@zeonfederated.com>
Sun, 30 Apr 2017 16:15:49 +0000 (18:15 +0200)
* Add coverage for Report#media_attachments

* Direct query on media attachment

app/models/report.rb
spec/models/report_spec.rb

index c7d88774580ce0a3bc05dafc0529220d1388832c..d813d0d0d18075110fa14d9383cb09f2fe829648 100644 (file)
@@ -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
index 80b8cc55b55478cd043cf7886b185a69c29f08ef..6c2723845709653afbef837f05d8c222de48140b 100644 (file)
@@ -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