このコミットが含まれているのは:
2026-09-21 04:55:02 +09:00
コミット b217a307fe
6個のファイルの変更264行の追加147行の削除
+14 -6
ファイルの表示
@@ -108,7 +108,7 @@ RSpec.describe 'nico:sync' do
expect(calls).to eq(2)
end
it '既存 post にあった古い nico tag は active から外され、履歴として discard される' do
it '古い nico tag の関連を物理削除し、変更前後の履歴を version に残す' do
post = Post.create!(
title: 'old',
url: 'https://www.nicovideo.jp/watch/sm9',
@@ -117,8 +117,8 @@ RSpec.describe 'nico:sync' do
# 旧nicoタグ(今回の同期結果に含まれない)
old_nico = create_tag!('nico:OLD', category: 'nico')
old_pt = PostTag.create!(post: post, tag: old_nico)
expect(old_pt.discarded_at).to be_nil
PostTag.create!(post:, tag: old_nico)
create_post_version_for!(post)
# 今回は NEW のみ欲しい
new_nico = create_tag!('nico:NEW', category: 'nico')
@@ -132,9 +132,17 @@ RSpec.describe 'nico:sync' do
run_rake_task('nico:sync')
# OLD は active から外れる(discarded_at が入る)
old_pts = PostTag.where(post_id: post.id, tag_id: old_nico.id).order(:id).to_a
expect(old_pts.last.discarded_at).to be_present
expect(PostTag.exists?(post:, 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') })
.to include(old_nico.id)
expect(versions.last.tags_json.map { |item| item.fetch('id') })
.to include(new_nico.id)
expect(versions.last.tags_json.map { |item| item.fetch('id') })
.not_to include(old_nico.id)
# NEW は active にいる
post.reload