]> cat aescling's git repositories - mastodon.git/commitdiff
Add specs for media attachment validations
authorChad Pytel <chad@thoughtbot.com>
Fri, 7 Apr 2017 16:50:43 +0000 (12:50 -0400)
committerChad Pytel <chad@thoughtbot.com>
Fri, 7 Apr 2017 16:50:43 +0000 (12:50 -0400)
There are currently not specs for the two media validations that are performed
by `PostStatusService`. This adds specs for the validations that ensure that you
cannot attach more than four files, and that a status cannot have both image and
video attachments.

spec/fabricators/media_attachment_fabricator.rb
spec/services/post_status_service_spec.rb

index 59db2440d6ae5584912450b6b4126b9bc92113f2..dc91d708f3347d946688947506520ad6844415ed 100644 (file)
@@ -1,3 +1,3 @@
 Fabricator(:media_attachment) do
-
+  account
 end
index 9ee4daf6f5f2e2fde4e60ef5b9cf79550b8ccfca..acb922d641abae5299cb93c81a97e1890fb902cf 100644 (file)
@@ -7,4 +7,45 @@ RSpec.describe PostStatusService do
   it 'creates a new response status'
   it 'processes mentions'
   it 'pings PuSH hubs'
+
+  it 'does not allow attaching more than 4 files' do
+    account = Fabricate(:account)
+
+    expect do
+      PostStatusService.new.call(
+      account,
+      "test status update",
+      nil,
+      media_ids: [
+        Fabricate(:media_attachment, account: account),
+        Fabricate(:media_attachment, account: account),
+        Fabricate(:media_attachment, account: account),
+        Fabricate(:media_attachment, account: account),
+        Fabricate(:media_attachment, account: account),
+      ].map(&:id),
+    )
+    end.to raise_error(
+      Mastodon::ValidationError,
+      'Cannot attach more than 4 files',
+    )
+  end
+
+  it 'does not allow attaching both videos and images' do
+    account = Fabricate(:account)
+
+    expect do
+      PostStatusService.new.call(
+      account,
+      "test status update",
+      nil,
+      media_ids: [
+        Fabricate(:media_attachment, type: :video, account: account),
+        Fabricate(:media_attachment, type: :image, account: account),
+      ].map(&:id),
+    )
+    end.to raise_error(
+      Mastodon::ValidationError,
+      'Cannot attach a video to a toot that already contains images',
+    )
+  end
 end