このコミットが含まれているのは:
@@ -253,6 +253,93 @@ RSpec.describe 'Posts API', type: :request do
|
||||
end
|
||||
end
|
||||
|
||||
context 'with legacy external tag name searches' do
|
||||
let!(:external_tag) { create(:external_tag, id: tag.id, name: 'search_external') }
|
||||
let!(:both_post) do
|
||||
create(:post).tap do |post|
|
||||
PostTag.create!(post:, tag:)
|
||||
PostExternalTag.create!(post:, external_tag:)
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
PostExternalTag.create!(post: miss_post, external_tag:)
|
||||
end
|
||||
|
||||
it 'keeps internal name searches independent of colliding external ids' do
|
||||
get '/posts', params: { tags: tag.name }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json.fetch('count')).to eq(3)
|
||||
expect(json.fetch('posts').map { _1.fetch('id') })
|
||||
.to contain_exactly(post_record.id, hit_post.id, both_post.id)
|
||||
end
|
||||
|
||||
it 'finds posts through PostExternalTag by the qualified legacy name' do
|
||||
get '/posts', params: { tags: 'nico:search_external' }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json.fetch('count')).to eq(2)
|
||||
expect(json.fetch('posts').map { _1.fetch('id') })
|
||||
.to contain_exactly(miss_post.id, both_post.id)
|
||||
end
|
||||
|
||||
[nil, 'all'].each do |match|
|
||||
it "intersects internal and external matches with match=#{ match || 'omitted' }" do
|
||||
params = { tags: "#{ tag.name } nico:search_external" }
|
||||
params[:match] = match if match
|
||||
|
||||
get '/posts', params: params
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json.fetch('count')).to eq(1)
|
||||
expect(json.fetch('posts').map { _1.fetch('id') }).to eq([both_post.id])
|
||||
end
|
||||
end
|
||||
|
||||
it 'unions internal alias and external matches without duplicate posts' do
|
||||
get '/posts', params: { tags: 'manko nico:search_external', match: 'any' }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json.fetch('count')).to eq(4)
|
||||
expect(json.fetch('posts').map { _1.fetch('id') })
|
||||
.to contain_exactly(post_record.id, hit_post.id, miss_post.id, both_post.id)
|
||||
end
|
||||
|
||||
it 'excludes external matches from an internal tag search' do
|
||||
get '/posts', params: { tags: "#{ tag.name } not:nico:search_external" }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json.fetch('count')).to eq(2)
|
||||
expect(json.fetch('posts').map { _1.fetch('id') })
|
||||
.to contain_exactly(post_record.id, hit_post.id)
|
||||
end
|
||||
|
||||
it 'unions an external match with a negated internal match' do
|
||||
get '/posts', params: { tags: "nico:search_external not:#{ tag.name }", match: 'any' }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json.fetch('count')).to eq(2)
|
||||
expect(json.fetch('posts').map { _1.fetch('id') })
|
||||
.to contain_exactly(miss_post.id, both_post.id)
|
||||
end
|
||||
|
||||
it 'keeps a missing qualified external name empty' do
|
||||
get '/posts', params: { tags: 'nico:missing_search_external' }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json.fetch('count')).to eq(0)
|
||||
expect(json.fetch('posts')).to be_empty
|
||||
end
|
||||
|
||||
it 'applies the same mixed name search to the existing random endpoint' do
|
||||
get '/posts/random', params: { tags: "#{ tag.name } nico:search_external", match: 'all' }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json.fetch('id')).to eq(both_post.id)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when tags contain not:' do
|
||||
let!(:foo_tag_name) { TagName.create!(name: 'not_spec_foo') }
|
||||
let!(:foo_tag) { Tag.create!(tag_name: foo_tag_name, category: :general) }
|
||||
@@ -2286,7 +2373,8 @@ RSpec.describe 'Posts API', type: :request do
|
||||
a_hash_including('post_id' => external_post.id, 'version_no' => 1))
|
||||
end
|
||||
|
||||
context 'without an internal Tag with the external id' do
|
||||
# Temporary compatibility shim until the frontend sends external_tag explicitly.
|
||||
context 'with legacy tag fallback and no internal Tag with the external id' do
|
||||
let(:external_id) { Tag.maximum(:id).to_i + 10_000 }
|
||||
|
||||
it 'falls back to ExternalTag for the legacy tag parameter' do
|
||||
@@ -2301,7 +2389,7 @@ RSpec.describe 'Posts API', type: :request do
|
||||
end
|
||||
|
||||
[:tag, :external_tag].each do |parameter|
|
||||
it "includes external tag removal history through #{ parameter }" do
|
||||
it "includes external removal history through the legacy API's #{ parameter }" do
|
||||
external_post.post_external_tags.destroy_all
|
||||
PostVersionRecorder.record!(
|
||||
post: external_post.reload, event_type: :update, created_by_user: member)
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする