From 2cf9ebe9b66cffdcf4b9098a66a71353a1372408 Mon Sep 17 00:00:00 2001 From: Christian Schmidt Date: Tue, 22 Aug 2023 19:37:54 +0200 Subject: [PATCH] Publish status when preview card is updated --- app/services/fetch_link_card_service.rb | 1 + spec/services/fetch_link_card_service_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/services/fetch_link_card_service.rb b/app/services/fetch_link_card_service.rb index 13775e63c19..743cf6ac852 100644 --- a/app/services/fetch_link_card_service.rb +++ b/app/services/fetch_link_card_service.rb @@ -67,6 +67,7 @@ class FetchLinkCardService < BaseService @status.preview_cards << @card Rails.cache.delete(@status) Trends.links.register(@status) + DistributionWorker.perform_async(@status.id) end end diff --git a/spec/services/fetch_link_card_service_spec.rb b/spec/services/fetch_link_card_service_spec.rb index f44cbb750c7..8e0938a4d1c 100644 --- a/spec/services/fetch_link_card_service_spec.rb +++ b/spec/services/fetch_link_card_service_spec.rb @@ -6,6 +6,7 @@ RSpec.describe FetchLinkCardService, type: :service do subject { described_class.new } let(:html) { 'Hello world' } + let(:status) { Fabricate(:status, text: 'http://example.com/html') } let(:oembed_cache) { nil } before do @@ -27,11 +28,22 @@ RSpec.describe FetchLinkCardService, type: :service do stub_request(:get, 'http://example.com/koi8-r').to_return(request_fixture('koi8-r.txt')) stub_request(:get, 'http://example.com/windows-1251').to_return(request_fixture('windows-1251.txt')) + allow(DistributionWorker).to receive(:perform_async) + allow(Trends.links).to receive(:register) + Rails.cache.write('oembed_endpoint:example.com', oembed_cache) if oembed_cache subject.call(status) end + it 'registers trends' do + expect(Trends.links).to have_received(:register).with(status) + end + + it 'redistributes status' do + expect(DistributionWorker).to have_received(:perform_async).with(status.id) + end + context 'with a local status' do context 'with URL of a regular HTML page' do let(:status) { Fabricate(:status, text: 'http://example.com/html') }