Skip to content

Commit 2483112

Browse files
ClearlyClairekedamaDQ
authored andcommitted
Fix scheduled toot with media immediately creating a toot (mastodon#9894)
* Add test for not persisting status when attaching media to scheduled toot * Prevent status used for validation from being persisted to the database Fixes mastodon#9893 Thanks to tateisu for the help investigating this.
1 parent ec65338 commit 2483112

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

app/services/post_status_service.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ def process_status!
6666
end
6767

6868
def schedule_status!
69-
if @account.statuses.build(status_attributes).valid?
69+
status_for_validation = @account.statuses.build(status_attributes)
70+
if status_for_validation.valid?
71+
status_for_validation.destroy
72+
7073
# The following transaction block is needed to wrap the UPDATEs to
7174
# the media attachments when the scheduled status is created
7275

spec/services/post_status_service_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@
3636
expect(status.params['text']).to eq 'Hi future!'
3737
end
3838

39+
it 'does not immediately create a status when scheduling a status' do
40+
account = Fabricate(:account)
41+
media = Fabricate(:media_attachment)
42+
future = Time.now.utc + 2.hours
43+
44+
status = subject.call(account, text: 'Hi future!', media_ids: [media.id], scheduled_at: future)
45+
46+
expect(status).to be_a ScheduledStatus
47+
expect(status.scheduled_at).to eq future
48+
expect(status.params['text']).to eq 'Hi future!'
49+
expect(media.reload.status).to be_nil
50+
expect(Status.where(text: 'Hi future!').exists?).to be_falsey
51+
end
52+
3953
it 'creates response to the original status of boost' do
4054
boosted_status = Fabricate(:status)
4155
in_reply_to_status = Fabricate(:status, reblog: boosted_status)

0 commit comments

Comments
 (0)