多言語化の基盤作り (#55) (#421)

Reviewed-on: #421
Co-authored-by: miteruzo <miteruzo@naver.com>
このコミットはプルリクエスト #421 でマージされました。
このコミットが含まれているのは:
2026-10-03 02:00:09 +09:00
committed by みてるぞ
コミット e6ab941774
91個のファイルの変更、3370行の追加、1223行の削除
+29 -15
ファイルの表示
@@ -8,7 +8,7 @@ RSpec.describe 'nico:sync' do
end
def create_tag!(name, category:)
Tag.find_or_create_by_tag_name!(name, category:)
Tag.find_or_create_by_tag_name!(Locale.nipponese, name, category:)
end
def link_nico_to_tag!(nico_tag, tag)
@@ -16,17 +16,22 @@ RSpec.describe 'nico:sync' do
end
def create_nico_sanitisation_rules!
TagNameSanitisationRule.create!(priority: 20,
source_pattern: '\\?',
replacement: '_')
rules = [
[20, '\\?', '_'],
[40, '_$', ''],
[45, '^([^:]+\\:)?_', '\\1']]
TagNameSanitisationRule.create!(priority: 40,
source_pattern: '_$',
replacement: '')
priorities = rules.map(&:first)
source_patterns = rules.map { _1[1] }
TagNameSanitisationRule.create!(priority: 45,
source_pattern: '^([^:]+\\:)?_',
replacement: '\\1')
scope = TagNameSanitisationRule.unscoped
scope.where(priority: priorities)
.or(scope.where(source_pattern: source_patterns))
.delete_all
rules.each do |priority, source_pattern, replacement|
TagNameSanitisationRule.create!(priority:, source_pattern:, replacement:)
end
end
it '既存 post を見つけて、nico tag と linked tag を追加し、差分が出たら bot を付ける' do
@@ -64,7 +69,8 @@ RSpec.describe 'nico:sync' do
run_rake_task('nico:sync')
post.reload
active_tag_names = post.tags.joins(:tag_name).pluck('tag_names.name')
active_tag_names = TagName.where(tag_id: post.tags.select(:id),
language_code: 'ja', primary_flg: true).pluck(:name)
expect(active_tag_names).to include('spec_kept')
expect(post.external_tags).to contain_exactly(nico)
@@ -434,7 +440,9 @@ RSpec.describe 'nico:sync' do
external = post.external_tags.sole
expect(external.name).to eq('raw tag[]')
expect(post.tags.map(&:name)).not_to include('bot操作')
expect(TagName.where(tag_id: post.tags.select(:id),
language_code: 'ja', primary_flg: true).pluck(:name))
.not_to include('bot操作')
expect(post.post_versions.order(:version_no).last.tags_json)
.to include('external_tag_id' => external.id)
@@ -446,7 +454,9 @@ RSpec.describe 'nico:sync' do
run_nico_sync_with_tags!([])
}.to change(PostVersion, :count).by(1)
expect(post.reload.external_tags).to be_empty
expect(post.tags.map(&:name)).not_to include('bot操作')
expect(TagName.where(tag_id: post.tags.select(:id),
language_code: 'ja', primary_flg: true).pluck(:name))
.not_to include('bot操作')
end
it 'サニタイズ後の既存外部タグを再利用し、その連携タグを記載する' do
@@ -563,7 +573,9 @@ RSpec.describe 'nico:sync' do
name: 'AAA')
expect(ExternalTag.exists?(platform: :nico, name: 'AAA?')).to be(false)
expect(post.tags.map(&:name)).not_to include('bot操作')
expect(TagName.where(tag_id: post.tags.select(:id),
language_code: 'ja', primary_flg: true).pluck(:name))
.not_to include('bot操作')
expect(post.post_versions.order(:version_no).last.tags_json)
.to include('external_tag_id' => external.id)
@@ -577,7 +589,9 @@ RSpec.describe 'nico:sync' do
}.to change(PostVersion, :count).by(1)
expect(post.reload.external_tags).to be_empty
expect(post.tags.map(&:name)).not_to include('bot操作')
expect(TagName.where(tag_id: post.tags.select(:id),
language_code: 'ja', primary_flg: true).pluck(:name))
.not_to include('bot操作')
end
it 'nico: prefix を含む従来の規則で外部タグ名をサニタイズする' do
+4 -4
ファイルの表示
@@ -6,10 +6,10 @@ RSpec.describe 'post_similarity:calc' do
it 'calculates similarities from active tags only' do
# 必要最低限のデータ
t1 = Tag.create!(name: "t1")
t2 = Tag.create!(name: "t2")
t3 = Tag.create!(name: "t3")
deprecated_tag = Tag.create!(name: 'deprecated', deprecated_at: Time.current)
t1 = create(:tag, primary_name: 't1')
t2 = create(:tag, primary_name: 't2')
t3 = create(:tag, primary_name: 't3')
deprecated_tag = create(:tag, primary_name: 'deprecated', deprecated_at: Time.current)
p1 = Post.create!(url: "https://example.com/1")
p2 = Post.create!(url: "https://example.com/2")
+4 -4
ファイルの表示
@@ -6,10 +6,10 @@ RSpec.describe 'tag_similarity:calc' do
it 'calculates similarities for active tags only' do
# 必要最低限のデータ
t1 = Tag.create!(name: "t1")
t2 = Tag.create!(name: "t2")
t3 = Tag.create!(name: "t3")
deprecated_tag = Tag.create!(name: 'deprecated', deprecated_at: Time.current)
t1 = create(:tag, primary_name: 't1')
t2 = create(:tag, primary_name: 't2')
t3 = create(:tag, primary_name: 't3')
deprecated_tag = create(:tag, primary_name: 'deprecated', deprecated_at: Time.current)
p1 = Post.create!(url: "https://example.com/1")
p2 = Post.create!(url: "https://example.com/2")