AI: address review on PR #488
このコミットが含まれているのは:
@@ -479,6 +479,41 @@ RSpec.describe 'Tags API', type: :request do
|
||||
end
|
||||
|
||||
describe 'GET /tags/autocomplete' do
|
||||
context 'when q contains wildcards' do
|
||||
let(:names) { ['wildend', 'wildXend', 'wildABend', 'otherwildXend'] }
|
||||
|
||||
before do
|
||||
names.each_with_index do |name, index|
|
||||
create(:tag, primary_name: name, post_count: 1)
|
||||
alias_target = create(:tag, primary_name: "target_#{ index }", post_count: 1)
|
||||
create(:tag_name, :alias, name: "#{ name }_alias", tag: alias_target)
|
||||
create(:external_tag, name:, post_count: 1)
|
||||
end
|
||||
end
|
||||
|
||||
{
|
||||
'wild*end' => [0, 1, 2],
|
||||
'wild?end' => [1],
|
||||
'not:wild?end' => [1],
|
||||
'nico:wild?end' => [1] }.each do |query, indices|
|
||||
it "matches primary, alias, and external names with #{ query.inspect }" do
|
||||
get '/tags/autocomplete', params: { q: query }
|
||||
|
||||
expected_names = indices.flat_map do |index|
|
||||
name = names[index]
|
||||
query.start_with?('nico:') ? ["nico:#{ name }"] :
|
||||
[name, "target_#{ index }", "nico:#{ name }"]
|
||||
end
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json.map { |row| row.fetch('name') }).to match_array(expected_names)
|
||||
unless query.start_with?('nico:')
|
||||
row = json.find { |item| item.fetch('name') == "target_#{ indices.first }" }
|
||||
expect(row.fetch('matched_alias')).to eq("#{ names[indices.first] }_alias")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'combines internal and external matches without conflating equal ids' do
|
||||
internal = create(:tag, category: :general, primary_name: 'mixed_internal', post_count: 2)
|
||||
external = create(:external_tag, id: internal.id,
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする