このコミットが含まれているのは:
2026-09-22 20:33:46 +09:00
コミット 2e25c6e0ba
16個のファイルの変更593行の追加266行の削除
+42 -14
ファイルの表示
@@ -17,7 +17,7 @@ RSpec.describe 'Posts API', type: :request do
end
def create_nico_tag!(name)
Tag.find_or_create_by_tag_name!(name, category: :nico)
ExternalTag.find_or_create_by!(platform: :nico, name: name.delete_prefix('nico:'))
end
def dummy_upload
@@ -1250,9 +1250,9 @@ RSpec.describe 'Posts API', type: :request do
)
end
context 'when nico tag already exists in tags' do
context 'when the external nico tag already exists' do
before do
Tag.find_or_create_by_tag_name!('nico:nico_tag', category: :nico)
create(:external_tag, name: 'nico_tag')
end
it 'returns 422 with tag field errors' do
@@ -1530,9 +1530,9 @@ RSpec.describe 'Posts API', type: :request do
versions = post_record.post_versions.order(:version_no)
expect(versions.first.tags_json).to include(
a_hash_including('id' => tag.id,
a_hash_including('tag_id' => tag.id,
'sections' => [{ 'begin_ms' => 1000, 'end_ms' => 2000 }]))
expect(versions.last.tags_json.map { |item| item.fetch('id') })
expect(versions.last.tags_json.map { |item| item.fetch('tag_id') })
.not_to include(tag.id)
end
@@ -1551,7 +1551,7 @@ RSpec.describe 'Posts API', type: :request do
expect(PostTag.find_by!(post: post_record, tag:).created_user).to eq(member)
expect(tag.reload.post_count).to eq(1)
snapshots = post_record.post_versions.order(:version_no).map do |version|
version.tags_json.map { |item| item.fetch('id') }
version.tags_json.map { |item| item.fetch('tag_id') }
end
expect(snapshots.map { |ids| ids.include?(tag.id) }).to eq([true, false, true])
end
@@ -1576,9 +1576,9 @@ RSpec.describe 'Posts API', type: :request do
)
end
context 'when nico tag already exists in tags' do
context 'when the external nico tag already exists' do
before do
Tag.find_or_create_by_tag_name!('nico:nico_tag', category: :nico)
create(:external_tag, name: 'nico_tag')
end
it 'returns 422 with tag field errors' do
@@ -1895,7 +1895,7 @@ RSpec.describe 'Posts API', type: :request do
base_version = create_post_version_for!(post_record.reload)
nico_tag = create_nico_tag!('nico:optimistic_lock_nico')
PostTag.create!(post: post_record, tag: nico_tag, created_user: member)
PostExternalTag.create!(post: post_record, external_tag: nico_tag)
PostVersionRecorder.record!(
post: post_record.reload,
@@ -1915,14 +1915,14 @@ RSpec.describe 'Posts API', type: :request do
expect(names).to include('spec_tag')
expect(names).to include(Tag.no_deerjikist.name)
expect(names).to include(nico_tag.name)
expect(post_record.external_tags).to contain_exactly(nico_tag)
end
it 'keeps nico tags even when they are not included in PUT tags' do
sign_in_as(member)
nico_tag = create_nico_tag!('nico:readonly_update_nico')
PostTag.create!(post: post_record, tag: nico_tag, created_user: member)
PostExternalTag.create!(post: post_record, external_tag: nico_tag)
base_version = create_post_version_for!(post_record.reload)
@@ -1937,7 +1937,7 @@ RSpec.describe 'Posts API', type: :request do
expect(names).to include('spec_tag')
expect(names).to include(Tag.no_deerjikist.name)
expect(names).to include(nico_tag.name)
expect(post_record.external_tags).to contain_exactly(nico_tag)
end
it 'allows non-nico tags linked from nico tags to be removed by normal post update' do
@@ -1947,7 +1947,7 @@ RSpec.describe 'Posts API', type: :request do
linked_tag = Tag.find_or_create_by_tag_name!('relation_linked_tag', category: :general)
NicoTagRelation.create!(nico_tag:, tag: linked_tag)
PostTag.create!(post: post_record, tag: nico_tag, created_user: member)
PostExternalTag.create!(post: post_record, external_tag: nico_tag)
PostTag.create!(post: post_record, tag: linked_tag, created_user: member)
base_version = create_post_version_for!(post_record.reload)
@@ -1961,7 +1961,7 @@ RSpec.describe 'Posts API', type: :request do
names = post_record.reload.tags.map(&:name)
expect(names).to include(nico_tag.name)
expect(post_record.external_tags).to contain_exactly(nico_tag)
expect(names).to include('spec_tag')
expect(names).to include(Tag.no_deerjikist.name)
expect(names).not_to include(linked_tag.name)
@@ -2180,6 +2180,34 @@ RSpec.describe 'Posts API', type: :request do
expect(first.fetch('created_at')).to eq(t_v1.iso8601)
end
it 'does not treat an external id as the internal tag filter' do
external_post = create(:post)
external = create(:external_tag, id: tag.id)
PostExternalTag.create!(post: external_post, external_tag: external)
PostVersionRecorder.record!(post: external_post,
event_type: :create, created_by_user: member)
get '/posts/versions', params: { post: external_post.id, tag: tag.id }
expect(response).to have_http_status(:ok)
expect(json.fetch('versions')).to be_empty
expect(json.fetch('count')).to eq(0)
end
it 'can render history containing external identifiers' do
PostExternalTag.create!(post: post_record, external_tag: create(:external_tag))
post_record.update_columns(version_no: 2)
PostVersionRecorder.record!(post: post_record,
event_type: :update, created_by_user: member)
get '/posts/versions', params: { post: post_record.id }
expect(response).to have_http_status(:ok)
expect(json.fetch('count')).to eq(3)
expect(json.fetch('versions').first.fetch('tags')).to include(
'name' => tag2.name, 'type' => 'context')
end
it 'filters versions by tag when the current snapshot includes the tag' do
get '/posts/versions', params: { post: post_record.id, tag: tag2.id }