about summary refs log tree commit diff
path: root/spec/services/post_status_service_spec.rb
diff options
context:
space:
mode:
authorChad Pytel <chad@thoughtbot.com>2017-04-07 12:50:43 -0400
committerChad Pytel <chad@thoughtbot.com>2017-04-07 12:50:43 -0400
commit38bec798117446603b304c0d14ca39bae5ee8be8 (patch)
tree527a7fbe6535f59a02650220fa99783c9578fc04 /spec/services/post_status_service_spec.rb
parent4e41cd9ab8f51120d558b70528b163c98993be53 (diff)
Add specs for media attachment validations
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.
Diffstat (limited to 'spec/services/post_status_service_spec.rb')
-rw-r--r--spec/services/post_status_service_spec.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/services/post_status_service_spec.rb b/spec/services/post_status_service_spec.rb
index 9ee4daf6f..acb922d64 100644
--- a/spec/services/post_status_service_spec.rb
+++ b/spec/services/post_status_service_spec.rb
@@ -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