このコミットが含まれているのは:
2026-09-22 20:33:46 +09:00
コミット 2e25c6e0ba
16個のファイルの変更、593行の追加、266行の削除
+43 -16
ファイルの表示
@@ -29,7 +29,7 @@ RSpec.describe 'nico:sync' do
# 追加される linked tag を準備(nico tag に紐付く一般タグ)
linked = create_tag!('spec_linked', category: 'general')
nico = create_tag!('nico:AAA', category: 'nico')
nico = create_external_tag!('AAA')
link_nico_to_tag!(nico, linked)
# bot / tagme は task 内で使うので作っておく(Tag.bot/tagme がある前提)
@@ -53,7 +53,7 @@ RSpec.describe 'nico:sync' do
active_tag_names = post.tags.joins(:tag_name).pluck('tag_names.name')
expect(active_tag_names).to include('spec_kept')
expect(active_tag_names).to include('nico:AAA')
expect(post.external_tags).to contain_exactly(nico)
expect(active_tag_names).to include('spec_linked')
expect(post.original_created_from).to eq(Time.iso8601('2026-01-01T03:34:00Z'))
@@ -115,12 +115,12 @@ RSpec.describe 'nico:sync' do
)
# 旧nicoタグ(今回の同期結果に含まれない)
old_nico = create_tag!('nico:OLD', category: 'nico')
PostTag.create!(post:, tag: old_nico)
old_nico = create_external_tag!('OLD')
PostExternalTag.create!(post:, external_tag: old_nico)
create_post_version_for!(post)
# 今回は NEW のみ欲しい
new_nico = create_tag!('nico:NEW', category: 'nico')
new_nico = create_external_tag!('NEW')
# bot/tagme 念のため
Tag.bot
@@ -131,23 +131,21 @@ RSpec.describe 'nico:sync' do
run_rake_task('nico:sync')
expect(PostTag.exists?(post:, tag: old_nico)).to be(false)
expect(PostExternalTag.exists?(post:, external_tag: old_nico)).to be(false)
expect(old_nico.reload.post_count).to eq(0)
expect(new_nico.reload.post_count).to eq(1)
versions = post.post_versions.order(:version_no)
expect(versions.first.tags_json.map { |item| item.fetch('id') })
expect(versions.first.tags_json.filter_map { |item| item['external_tag_id'] })
.to include(old_nico.id)
expect(versions.last.tags_json.map { |item| item.fetch('id') })
expect(versions.last.tags_json.filter_map { |item| item['external_tag_id'] })
.to include(new_nico.id)
expect(versions.last.tags_json.map { |item| item.fetch('id') })
expect(versions.last.tags_json.filter_map { |item| item['external_tag_id'] })
.not_to include(old_nico.id)
# NEW は active にいる
post.reload
active_names = post.tags.joins(:tag_name).pluck('tag_names.name')
expect(active_names).to include('nico:NEW')
expect(active_names).not_to include('nico:OLD')
expect(post.external_tags).to contain_exactly(new_nico)
end
def snapshot_tags(post)
@@ -213,7 +211,7 @@ RSpec.describe 'nico:sync' do
create_post_version_for!(post)
linked = create_tag!('spec_linked', category: 'general')
nico = create_tag!('nico:AAA', category: 'nico')
nico = create_external_tag!('AAA')
link_nico_to_tag!(nico, linked)
Tag.bot
@@ -241,7 +239,7 @@ RSpec.describe 'nico:sync' do
end
it '既存 post に差分が無いときは新しい version を作らない' do
nico = create_tag!('nico:AAA', category: 'nico')
nico = create_external_tag!('AAA')
no_deerjikist = create_tag!('ニジラー情報不詳', category: 'meta')
post = Post.create!(
@@ -252,7 +250,7 @@ RSpec.describe 'nico:sync' do
original_created_before: Time.iso8601('2026-01-01T03:35:00Z')
)
PostTag.create!(post: post, tag: nico)
PostExternalTag.create!(post:, external_tag: nico)
PostTag.create!(post: post, tag: no_deerjikist)
create_post_version_for!(post)
@@ -295,7 +293,7 @@ RSpec.describe 'nico:sync' do
run_rake_task('nico:sync')
}.to change(NicoTagVersion, :count).by(1)
nico_tag = Tag.joins(:tag_name).find_by!(tag_names: { name: 'nico:AAA' })
nico_tag = ExternalTag.find_by!(platform: :nico, name: 'AAA')
version = nico_tag.nico_tag_versions.order(:version_no).last
expect(version.version_no).to eq(1)
@@ -408,6 +406,35 @@ RSpec.describe 'nico:sync' do
run_rake_task('nico:sync')
end
it '外部タグだけの変更では bot を付けず,投稿履歴を記録する' do
post = create_nico_sync_post!
PostVersionRecorder.record!(post:, event_type: :create, created_by_user: nil)
expect {
run_nico_sync_with_tags!(['raw tag[]', 'raw tag[]'])
}.to change(PostVersion, :count).by(1)
.and change(ExternalTag, :count).by(1)
.and change(PostExternalTag, :count).by(1)
.and change(NicoTagVersion, :count).by(1)
.and change(TagName, :count).by(0)
external = post.external_tags.sole
expect(external.name).to eq('raw tag[]')
expect(post.tags.map(&:name)).not_to include('bot操作')
expect(post.post_versions.order(:version_no).last.tags_json)
.to include('external_tag_id' => external.id)
expect {
run_nico_sync_with_tags!(['raw tag[]'])
}.to change(PostVersion, :count).by(0).and change(NicoTagVersion, :count).by(0)
expect {
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操作')
end
it '外部タグが新規記載されたとき,その時点の連携タグを記載する' do
post = create_nico_sync_post!