From c05492ed5a549e483bb15f968402a2af98178477 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 16 Mar 2026 10:31:58 -0400 Subject: [PATCH] Use `JSON.generate` call for fan out service (#38222) --- app/services/fan_out_on_write_service.rb | 6 +++--- spec/services/fan_out_on_write_service_spec.rb | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/services/fan_out_on_write_service.rb b/app/services/fan_out_on_write_service.rb index 727a6a63c4..d97e3e0fb2 100644 --- a/app/services/fan_out_on_write_service.rb +++ b/app/services/fan_out_on_write_service.rb @@ -171,10 +171,10 @@ class FanOutOnWriteService < BaseService end def anonymous_payload - @anonymous_payload ||= Oj.dump( + @anonymous_payload ||= JSON.generate({ event: update? ? :'status.update' : :update, - payload: rendered_status - ) + payload: rendered_status, + }.as_json) end def rendered_status diff --git a/spec/services/fan_out_on_write_service_spec.rb b/spec/services/fan_out_on_write_service_spec.rb index 79ecd06c8d..efc70d84c6 100644 --- a/spec/services/fan_out_on_write_service_spec.rb +++ b/spec/services/fan_out_on_write_service_spec.rb @@ -54,11 +54,18 @@ RSpec.describe FanOutOnWriteService do .and be_in(home_feed_of(bob)) .and be_in(home_feed_of(tom)) - expect(redis).to have_received(:publish).with('timeline:hashtag:hoge', anything) - expect(redis).to have_received(:publish).with('timeline:hashtag:hoge:local', anything) - expect(redis).to have_received(:publish).with('timeline:public', anything) - expect(redis).to have_received(:publish).with('timeline:public:local', anything) - expect(redis).to have_received(:publish).with('timeline:public:media', anything) + expected_payload = { event: 'update', payload: include(id: status.id.to_s, created_at: status.created_at.iso8601(3), content: /

Hello/) } + + expect(redis) + .to have_received(:publish).with('timeline:hashtag:hoge', match_json_values(expected_payload)) + expect(redis) + .to have_received(:publish).with('timeline:hashtag:hoge:local', match_json_values(expected_payload)) + expect(redis) + .to have_received(:publish).with('timeline:public', match_json_values(expected_payload)) + expect(redis) + .to have_received(:publish).with('timeline:public:local', match_json_values(expected_payload)) + expect(redis) + .to have_received(:publish).with('timeline:public:media', match_json_values(expected_payload)) end context 'with silenced_account_ids' do