From 5925a31b78f9eadd8daeb8e316bd6728fde547a9 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 7 Nov 2022 15:38:55 +0100 Subject: Fix followers count not being updated when migrating follows (#19998) Fixes #19900 --- spec/workers/move_worker_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'spec') diff --git a/spec/workers/move_worker_spec.rb b/spec/workers/move_worker_spec.rb index be02d3192..3ca6aaf4d 100644 --- a/spec/workers/move_worker_spec.rb +++ b/spec/workers/move_worker_spec.rb @@ -74,6 +74,18 @@ describe MoveWorker do end end + shared_examples 'followers count handling' do + it 'updates the source account followers count' do + subject.perform(source_account.id, target_account.id) + expect(source_account.reload.followers_count).to eq(source_account.passive_relationships.count) + end + + it 'updates the target account followers count' do + subject.perform(source_account.id, target_account.id) + expect(target_account.reload.followers_count).to eq(target_account.passive_relationships.count) + end + end + context 'both accounts are distant' do describe 'perform' do it 'calls UnfollowFollowWorker' do @@ -83,6 +95,7 @@ describe MoveWorker do include_examples 'user note handling' include_examples 'block and mute handling' + include_examples 'followers count handling' end end @@ -97,6 +110,7 @@ describe MoveWorker do include_examples 'user note handling' include_examples 'block and mute handling' + include_examples 'followers count handling' end end @@ -112,6 +126,7 @@ describe MoveWorker do include_examples 'user note handling' include_examples 'block and mute handling' + include_examples 'followers count handling' it 'does not fail when a local user is already following both accounts' do double_follower = Fabricate(:account) -- cgit From 3114c826a7a6b2b10bff722c59cca57abe7f819f Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 7 Nov 2022 19:47:48 +0100 Subject: Fix filter handling in status cache hydration (#19963) --- app/lib/status_cache_hydrator.rb | 4 ++-- spec/lib/status_cache_hydrator_spec.rb | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'spec') diff --git a/app/lib/status_cache_hydrator.rb b/app/lib/status_cache_hydrator.rb index ffe813ee9..298d7851a 100644 --- a/app/lib/status_cache_hydrator.rb +++ b/app/lib/status_cache_hydrator.rb @@ -19,7 +19,7 @@ class StatusCacheHydrator payload[:muted] = false payload[:bookmarked] = false payload[:pinned] = false if @status.account_id == account_id - payload[:filtered] = CustomFilter.apply_cached_filters(CustomFilter.cached_filters_for(@status.reblog_of_id), @status.reblog).map { |filter| ActiveModelSerializers::SerializableResource.new(filter, serializer: REST::FilterResultSerializer).as_json } + payload[:filtered] = CustomFilter.apply_cached_filters(CustomFilter.cached_filters_for(account_id), @status.reblog).map { |filter| ActiveModelSerializers::SerializableResource.new(filter, serializer: REST::FilterResultSerializer).as_json } # If the reblogged status is being delivered to the author who disabled the display of the application # used to create the status, we need to hydrate it here too @@ -51,7 +51,7 @@ class StatusCacheHydrator payload[:muted] = ConversationMute.where(account_id: account_id, conversation_id: @status.conversation_id).exists? payload[:bookmarked] = Bookmark.where(account_id: account_id, status_id: @status.id).exists? payload[:pinned] = StatusPin.where(account_id: account_id, status_id: @status.id).exists? if @status.account_id == account_id - payload[:filtered] = CustomFilter.apply_cached_filters(CustomFilter.cached_filters_for(@status.id), @status).map { |filter| ActiveModelSerializers::SerializableResource.new(filter, serializer: REST::FilterResultSerializer).as_json } + payload[:filtered] = CustomFilter.apply_cached_filters(CustomFilter.cached_filters_for(account_id), @status).map { |filter| ActiveModelSerializers::SerializableResource.new(filter, serializer: REST::FilterResultSerializer).as_json } if payload[:poll] payload[:poll][:voted] = @status.account_id == account_id diff --git a/spec/lib/status_cache_hydrator_spec.rb b/spec/lib/status_cache_hydrator_spec.rb index c9d8d0fe1..5c78de711 100644 --- a/spec/lib/status_cache_hydrator_spec.rb +++ b/spec/lib/status_cache_hydrator_spec.rb @@ -28,6 +28,18 @@ describe StatusCacheHydrator do end end + context 'when handling a filtered status' do + let(:status) { Fabricate(:status, text: 'this toot is about that banned word') } + + before do + account.custom_filters.create!(phrase: 'filter1', context: %w(home), action: :hide, keywords_attributes: [{ keyword: 'banned' }, { keyword: 'irrelevant' }]) + end + + it 'renders the same attributes as a full render' do + expect(subject).to eql(compare_to_hash) + end + end + context 'when handling a reblog' do let(:reblog) { Fabricate(:status) } let(:status) { Fabricate(:status, reblog: reblog) } @@ -99,6 +111,18 @@ describe StatusCacheHydrator do expect(subject).to eql(compare_to_hash) end end + + context 'that matches account filters' do + let(:reblog) { Fabricate(:status, text: 'this toot is about that banned word') } + + before do + account.custom_filters.create!(phrase: 'filter1', context: %w(home), action: :hide, keywords_attributes: [{ keyword: 'banned' }, { keyword: 'irrelevant' }]) + end + + it 'renders the same attributes as a full render' do + expect(subject).to eql(compare_to_hash) + end + end end end -- cgit