mirror of
https://framagit.org/tykayn/mastodon.git
synced 2023-08-25 08:33:12 +02:00
Fix scheduled statuses decreasing statuses counts (#16791)
* Add tests * Fix scheduled statuses decreasing statuses counts Fixes #16774
This commit is contained in:
parent
2396c9061a
commit
e63370db19
@ -426,7 +426,7 @@ class Status < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def decrement_counter_caches
|
def decrement_counter_caches
|
||||||
return if direct_visibility?
|
return if direct_visibility? || new_record?
|
||||||
|
|
||||||
account&.decrement_count!(:statuses_count)
|
account&.decrement_count!(:statuses_count)
|
||||||
reblog&.decrement_count!(:reblogs_count) if reblog?
|
reblog&.decrement_count!(:reblogs_count) if reblog?
|
||||||
|
@ -74,6 +74,9 @@ class PostStatusService < BaseService
|
|||||||
status_for_validation = @account.statuses.build(status_attributes)
|
status_for_validation = @account.statuses.build(status_attributes)
|
||||||
|
|
||||||
if status_for_validation.valid?
|
if status_for_validation.valid?
|
||||||
|
# Marking the status as destroyed is necessary to prevent the status from being
|
||||||
|
# persisted when the associated media attachments get updated when creating the
|
||||||
|
# scheduled status.
|
||||||
status_for_validation.destroy
|
status_for_validation.destroy
|
||||||
|
|
||||||
# The following transaction block is needed to wrap the UPDATEs to
|
# The following transaction block is needed to wrap the UPDATEs to
|
||||||
|
@ -25,29 +25,33 @@ RSpec.describe PostStatusService, type: :service do
|
|||||||
expect(status.thread).to eq in_reply_to_status
|
expect(status.thread).to eq in_reply_to_status
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'schedules a status' do
|
context 'when scheduling a status' do
|
||||||
account = Fabricate(:account)
|
let!(:account) { Fabricate(:account) }
|
||||||
future = Time.now.utc + 2.hours
|
let!(:future) { Time.now.utc + 2.hours }
|
||||||
|
let!(:previous_status) { Fabricate(:status, account: account) }
|
||||||
|
|
||||||
status = subject.call(account, text: 'Hi future!', scheduled_at: future)
|
it 'schedules a status' do
|
||||||
|
status = subject.call(account, text: 'Hi future!', scheduled_at: future)
|
||||||
|
expect(status).to be_a ScheduledStatus
|
||||||
|
expect(status.scheduled_at).to eq future
|
||||||
|
expect(status.params['text']).to eq 'Hi future!'
|
||||||
|
end
|
||||||
|
|
||||||
expect(status).to be_a ScheduledStatus
|
it 'does not immediately create a status' do
|
||||||
expect(status.scheduled_at).to eq future
|
media = Fabricate(:media_attachment, account: account)
|
||||||
expect(status.params['text']).to eq 'Hi future!'
|
status = subject.call(account, text: 'Hi future!', media_ids: [media.id], scheduled_at: future)
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not immediately create a status when scheduling a status' do
|
expect(status).to be_a ScheduledStatus
|
||||||
account = Fabricate(:account)
|
expect(status.scheduled_at).to eq future
|
||||||
media = Fabricate(:media_attachment)
|
expect(status.params['text']).to eq 'Hi future!'
|
||||||
future = Time.now.utc + 2.hours
|
expect(status.params['media_ids']).to eq [media.id]
|
||||||
|
expect(media.reload.status).to be_nil
|
||||||
|
expect(Status.where(text: 'Hi future!').exists?).to be_falsey
|
||||||
|
end
|
||||||
|
|
||||||
status = subject.call(account, text: 'Hi future!', media_ids: [media.id], scheduled_at: future)
|
it 'does not change statuses count' do
|
||||||
|
expect { subject.call(account, text: 'Hi future!', scheduled_at: future, thread: previous_status) }.not_to change { [account.statuses_count, previous_status.replies_count] }
|
||||||
expect(status).to be_a ScheduledStatus
|
end
|
||||||
expect(status.scheduled_at).to eq future
|
|
||||||
expect(status.params['text']).to eq 'Hi future!'
|
|
||||||
expect(media.reload.status).to be_nil
|
|
||||||
expect(Status.where(text: 'Hi future!').exists?).to be_falsey
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates response to the original status of boost' do
|
it 'creates response to the original status of boost' do
|
||||||
|
Loading…
Reference in New Issue
Block a user