Skip to content
Snippets Groups Projects
Commit 38bec798 authored by Chad Pytel's avatar Chad Pytel
Browse files

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.
parent 4e41cd9a
No related branches found
No related tags found
No related merge requests found
Fabricator(:media_attachment) do Fabricator(:media_attachment) do
account
end end
...@@ -7,4 +7,45 @@ RSpec.describe PostStatusService do ...@@ -7,4 +7,45 @@ RSpec.describe PostStatusService do
it 'creates a new response status' it 'creates a new response status'
it 'processes mentions' it 'processes mentions'
it 'pings PuSH hubs' 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 end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment