From 77a1cabb97fce68915b49ae90842d10132402687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?KMY=EF=BC=88=E9=9B=AA=E3=81=82=E3=81=99=E3=81=8B=EF=BC=89?= Date: Wed, 1 Nov 2023 10:34:28 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=E5=90=8C=E3=81=98=E6=8A=95=E7=A8=BF?= =?UTF-8?q?=E3=82=92=E8=BF=94=E4=BF=A1=E3=81=8B=E3=81=A4=E5=8F=82=E7=85=A7?= =?UTF-8?q?=E3=81=97=E3=81=A6=E3=81=84=E3=82=8B=E6=99=82=E3=80=81=E5=90=8C?= =?UTF-8?q?=E3=81=98=E6=8A=95=E7=A8=BF=E3=81=8C`context`=E3=81=AB=E8=A4=87?= =?UTF-8?q?=E6=95=B0=E5=90=AB=E3=81=BE=E3=82=8C=E3=82=8B=E5=95=8F=E9=A1=8C?= =?UTF-8?q?=20(#210)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add: #198 `context`のAPIについて`with_references`対応 * Fix: 同じ投稿を参照かつ返信していると、`context`に同じ投稿が複数含まれる問題 --- app/controllers/api/v1/statuses_controller.rb | 4 ++- .../api/v1/statuses_controller_spec.rb | 27 ++++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/statuses_controller.rb b/app/controllers/api/v1/statuses_controller.rb index 44ae3aae19c2e9..b3aaafe82cf930 100644 --- a/app/controllers/api/v1/statuses_controller.rb +++ b/app/controllers/api/v1/statuses_controller.rb @@ -49,7 +49,9 @@ def context loaded_descendants = cache_collection(descendants_results, Status) loaded_references = cache_collection(references_results, Status) - unless params[:with_reference] + if params[:with_reference] + loaded_references.reject! { |status| loaded_ancestors.any? { |ancestor| ancestor.id == status.id } } + else loaded_ancestors = (loaded_ancestors + loaded_references).uniq(&:id) loaded_references = [] end diff --git a/spec/controllers/api/v1/statuses_controller_spec.rb b/spec/controllers/api/v1/statuses_controller_spec.rb index 952a2e3b4045dd..28f1d9d58ea13b 100644 --- a/spec/controllers/api/v1/statuses_controller_spec.rb +++ b/spec/controllers/api/v1/statuses_controller_spec.rb @@ -97,15 +97,34 @@ describe 'GET #context' do let(:scopes) { 'read:statuses' } let(:status) { Fabricate(:status, account: user.account) } - - before do - Fabricate(:status, account: user.account, thread: status) - end + let!(:thread) { Fabricate(:status, account: user.account, thread: status) } it 'returns http success' do get :context, params: { id: status.id } expect(response).to have_http_status(200) end + + context 'when has also reference' do + before do + Fabricate(:status_reference, status: thread, target_status: status) + end + + it 'returns unique ancestors' do + get :context, params: { id: thread.id } + status_ids = body_as_json[:ancestors].map { |ref| ref[:id].to_i } + + expect(status_ids).to eq [status.id] + end + + it 'returns unique references' do + get :context, params: { id: thread.id, with_reference: true } + ancestor_status_ids = body_as_json[:ancestors].map { |ref| ref[:id].to_i } + reference_status_ids = body_as_json[:references].map { |ref| ref[:id].to_i } + + expect(ancestor_status_ids).to eq [status.id] + expect(reference_status_ids).to eq [] + end + end end context 'with reference' do