Fix: 同じ投稿を返信かつ参照している時、同じ投稿がcontext
に複数含まれる問題 (#210)
* Add: #198 `context`のAPIについて`with_references`対応 * Fix: 同じ投稿を参照かつ返信していると、`context`に同じ投稿が複数含まれる問題
This commit is contained in:
parent
99511ee1b5
commit
77a1cabb97
2 changed files with 26 additions and 5 deletions
|
@ -49,7 +49,9 @@ class Api::V1::StatusesController < Api::BaseController
|
||||||
loaded_descendants = cache_collection(descendants_results, Status)
|
loaded_descendants = cache_collection(descendants_results, Status)
|
||||||
loaded_references = cache_collection(references_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_ancestors = (loaded_ancestors + loaded_references).uniq(&:id)
|
||||||
loaded_references = []
|
loaded_references = []
|
||||||
end
|
end
|
||||||
|
|
|
@ -97,15 +97,34 @@ RSpec.describe Api::V1::StatusesController do
|
||||||
describe 'GET #context' do
|
describe 'GET #context' do
|
||||||
let(:scopes) { 'read:statuses' }
|
let(:scopes) { 'read:statuses' }
|
||||||
let(:status) { Fabricate(:status, account: user.account) }
|
let(:status) { Fabricate(:status, account: user.account) }
|
||||||
|
let!(:thread) { Fabricate(:status, account: user.account, thread: status) }
|
||||||
before do
|
|
||||||
Fabricate(:status, account: user.account, thread: status)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns http success' do
|
it 'returns http success' do
|
||||||
get :context, params: { id: status.id }
|
get :context, params: { id: status.id }
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'with reference' do
|
context 'with reference' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue