mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-08 08:44:27 +00:00
media_ids is an array of strings (#31709)
This commit is contained in:
parent
c1795ee963
commit
a5bbe83dfd
|
@ -134,7 +134,7 @@ class PostStatusService < BaseService
|
||||||
|
|
||||||
@media = @account.media_attachments.where(status_id: nil).where(id: @options[:media_ids].take(Status::MEDIA_ATTACHMENTS_LIMIT).map(&:to_i))
|
@media = @account.media_attachments.where(status_id: nil).where(id: @options[:media_ids].take(Status::MEDIA_ATTACHMENTS_LIMIT).map(&:to_i))
|
||||||
|
|
||||||
not_found_ids = @options[:media_ids] - @media.map(&:id)
|
not_found_ids = @options[:media_ids].map(&:to_i) - @media.map(&:id)
|
||||||
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.not_found', ids: not_found_ids.join(', ')) if not_found_ids.any?
|
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.not_found', ids: not_found_ids.join(', ')) if not_found_ids.any?
|
||||||
|
|
||||||
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.images_and_video') if @media.size > 1 && @media.find(&:audio_or_video?)
|
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.images_and_video') if @media.size > 1 && @media.find(&:audio_or_video?)
|
||||||
|
|
|
@ -73,7 +73,7 @@ class UpdateStatusService < BaseService
|
||||||
|
|
||||||
media_attachments = @status.account.media_attachments.where(status_id: [nil, @status.id]).where(scheduled_status_id: nil).where(id: @options[:media_ids].take(Status::MEDIA_ATTACHMENTS_LIMIT).map(&:to_i)).to_a
|
media_attachments = @status.account.media_attachments.where(status_id: [nil, @status.id]).where(scheduled_status_id: nil).where(id: @options[:media_ids].take(Status::MEDIA_ATTACHMENTS_LIMIT).map(&:to_i)).to_a
|
||||||
|
|
||||||
not_found_ids = @options[:media_ids] - media_attachments.map(&:id)
|
not_found_ids = @options[:media_ids].map(&:to_i) - media_attachments.map(&:id)
|
||||||
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.not_found', ids: not_found_ids.join(', ')) if not_found_ids.any?
|
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.not_found', ids: not_found_ids.join(', ')) if not_found_ids.any?
|
||||||
|
|
||||||
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.images_and_video') if media_attachments.size > 1 && media_attachments.find(&:audio_or_video?)
|
raise Mastodon::ValidationError, I18n.t('media_attachments.validations.images_and_video') if media_attachments.size > 1 && media_attachments.find(&:audio_or_video?)
|
||||||
|
|
|
@ -34,7 +34,7 @@ RSpec.describe PostStatusService do
|
||||||
|
|
||||||
it 'schedules a status for future creation and does not create one immediately' do
|
it 'schedules a status for future creation and does not create one immediately' do
|
||||||
media = Fabricate(:media_attachment, account: account)
|
media = Fabricate(:media_attachment, account: account)
|
||||||
status = subject.call(account, text: 'Hi future!', media_ids: [media.id], scheduled_at: future)
|
status = subject.call(account, text: 'Hi future!', media_ids: [media.id.to_s], scheduled_at: future)
|
||||||
|
|
||||||
expect(status)
|
expect(status)
|
||||||
.to be_a(ScheduledStatus)
|
.to be_a(ScheduledStatus)
|
||||||
|
@ -42,7 +42,7 @@ RSpec.describe PostStatusService do
|
||||||
scheduled_at: eq(future),
|
scheduled_at: eq(future),
|
||||||
params: include(
|
params: include(
|
||||||
'text' => eq('Hi future!'),
|
'text' => eq('Hi future!'),
|
||||||
'media_ids' => contain_exactly(media.id)
|
'media_ids' => contain_exactly(media.id.to_s)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
expect(media.reload.status).to be_nil
|
expect(media.reload.status).to be_nil
|
||||||
|
@ -219,7 +219,7 @@ RSpec.describe PostStatusService do
|
||||||
status = subject.call(
|
status = subject.call(
|
||||||
account,
|
account,
|
||||||
text: 'test status update',
|
text: 'test status update',
|
||||||
media_ids: [media.id]
|
media_ids: [media.id.to_s]
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(media.reload.status).to eq status
|
expect(media.reload.status).to eq status
|
||||||
|
@ -233,7 +233,7 @@ RSpec.describe PostStatusService do
|
||||||
subject.call(
|
subject.call(
|
||||||
account,
|
account,
|
||||||
text: 'test status update',
|
text: 'test status update',
|
||||||
media_ids: [media.id]
|
media_ids: [media.id.to_s]
|
||||||
)
|
)
|
||||||
end.to raise_error(
|
end.to raise_error(
|
||||||
Mastodon::ValidationError,
|
Mastodon::ValidationError,
|
||||||
|
@ -249,7 +249,7 @@ RSpec.describe PostStatusService do
|
||||||
subject.call(
|
subject.call(
|
||||||
account,
|
account,
|
||||||
text: 'test status update',
|
text: 'test status update',
|
||||||
media_ids: Array.new(2) { Fabricate(:media_attachment, account: account) }.map(&:id)
|
media_ids: Array.new(2) { Fabricate(:media_attachment, account: account) }.map { |m| m.id.to_s }
|
||||||
)
|
)
|
||||||
end.to raise_error(
|
end.to raise_error(
|
||||||
Mastodon::ValidationError,
|
Mastodon::ValidationError,
|
||||||
|
@ -271,7 +271,7 @@ RSpec.describe PostStatusService do
|
||||||
media_ids: [
|
media_ids: [
|
||||||
video,
|
video,
|
||||||
image,
|
image,
|
||||||
].map(&:id)
|
].map { |m| m.id.to_s }
|
||||||
)
|
)
|
||||||
end.to raise_error(
|
end.to raise_error(
|
||||||
Mastodon::ValidationError,
|
Mastodon::ValidationError,
|
||||||
|
|
|
@ -69,7 +69,7 @@ RSpec.describe UpdateStatusService do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
status.media_attachments << detached_media_attachment
|
status.media_attachments << detached_media_attachment
|
||||||
subject.call(status, status.account_id, text: 'Foo', media_ids: [attached_media_attachment.id])
|
subject.call(status, status.account_id, text: 'Foo', media_ids: [attached_media_attachment.id.to_s])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'updates media attachments' do
|
it 'updates media attachments' do
|
||||||
|
@ -95,7 +95,7 @@ RSpec.describe UpdateStatusService do
|
||||||
|
|
||||||
before do
|
before do
|
||||||
status.media_attachments << media_attachment
|
status.media_attachments << media_attachment
|
||||||
subject.call(status, status.account_id, text: 'Foo', media_ids: [media_attachment.id], media_attributes: [{ id: media_attachment.id, description: 'New description' }])
|
subject.call(status, status.account_id, text: 'Foo', media_ids: [media_attachment.id.to_s], media_attributes: [{ id: media_attachment.id, description: 'New description' }])
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not detach media attachment' do
|
it 'does not detach media attachment' do
|
||||||
|
|
Loading…
Reference in a new issue