AI: address review on PR #488

このコミットが含まれているのは:
Codex Night Worker
2026-11-23 00:25:10 +09:00
コミット 6ca18a1f48
2個のファイルの変更、36行の追加、1行の削除
+1 -1
ファイルの表示
@@ -219,7 +219,7 @@ class TagsController < ApplicationController
locale = resolve_locale!
q = params[:q].to_s.strip.sub(/\Anot:/i, '')
prefix = "#{ ActiveRecord::Base.sanitize_sql_like(q) }%"
prefix = "#{ ActiveRecord::Base.sanitize_sql_like(q).tr('*?', '%_') }%"
with_nico = bool?(:nico, default: true)
present_only = bool?(:present, default: true)
+35
ファイルの表示
@@ -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,