Skip to content

Commit

Permalink
Fix Idempotency-Key ignored when scheduling a post (mastodon#30084)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and Ember-ruby committed Jun 9, 2024
1 parent e8b707c commit 7ebb6f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/services/post_status_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def idempotency_given?

def idempotency_duplicate
if scheduled?
@account.schedule_statuses.find(@idempotency_duplicate)
@account.scheduled_statuses.find(@idempotency_duplicate)
else
@account.statuses.find(@idempotency_duplicate)
end
Expand Down Expand Up @@ -228,7 +228,7 @@ def poll_attributes
end

def scheduled_options
@options.tap do |options_hash|
@options.dup.tap do |options_hash|
options_hash[:in_reply_to_id] = options_hash.delete(:thread)&.id
options_hash[:application_id] = options_hash.delete(:application)&.id
options_hash[:scheduled_at] = nil
Expand Down
7 changes: 7 additions & 0 deletions spec/services/post_status_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
.to not_change { account.statuses_count }
.and(not_change { previous_status.replies_count })
end

it 'returns existing status when used twice with idempotency key' do
account = Fabricate(:account)
status1 = subject.call(account, text: 'test', idempotency: 'meepmeep', scheduled_at: future)
status2 = subject.call(account, text: 'test', idempotency: 'meepmeep', scheduled_at: future)
expect(status2.id).to eq status1.id
end
end

it 'creates response to the original status of boost' do
Expand Down

0 comments on commit 7ebb6f1

Please sign in to comment.