Skip to content

Commit

Permalink
Fix scheduled toot with media immediately creating a toot (mastodon#9894
Browse files Browse the repository at this point in the history
)

* 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.
  • Loading branch information
ClearlyClaire authored and hiyuki2578 committed Oct 2, 2019
1 parent 43343b0 commit 386c6cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/services/post_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ def process_status!
end

def schedule_status!
if @account.statuses.build(status_attributes).valid?
status_for_validation = @account.statuses.build(status_attributes)
if status_for_validation.valid?
status_for_validation.destroy

# The following transaction block is needed to wrap the UPDATEs to
# the media attachments when the scheduled status is created

Expand Down
14 changes: 14 additions & 0 deletions spec/services/post_status_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@
expect(status.params['text']).to eq 'Hi future!'
end

it 'does not immediately create a status when scheduling a status' do
account = Fabricate(:account)
media = Fabricate(:media_attachment)
future = Time.now.utc + 2.hours

status = subject.call(account, text: 'Hi future!', media_ids: [media.id], scheduled_at: future)

expect(status).to be_a ScheduledStatus
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

it 'creates response to the original status of boost' do
boosted_status = Fabricate(:status)
in_reply_to_status = Fabricate(:status, reblog: boosted_status)
Expand Down

0 comments on commit 386c6cd

Please sign in to comment.