このコミットが含まれているのは:
@@ -517,6 +517,24 @@ RSpec.describe 'Posts API', type: :request do
|
||||
expect([true, false]).to include(json['viewed'])
|
||||
end
|
||||
|
||||
it 'omits deprecated tags' do
|
||||
deprecated_tag = Tag.create!(
|
||||
name: 'deprecated_post_tag',
|
||||
category: :general,
|
||||
deprecated_at: Time.current
|
||||
)
|
||||
PostTag.create!(post: post_record, tag: deprecated_tag)
|
||||
|
||||
request
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
tag_names = json.fetch('tags').flat_map { |node|
|
||||
[node.fetch('name')] + node.fetch('children').map { |child| child.fetch('name') }
|
||||
}
|
||||
expect(tag_names).to include('spec_tag')
|
||||
expect(tag_names).not_to include('deprecated_post_tag')
|
||||
end
|
||||
|
||||
context 'when post has parent, child, and sibling posts' do
|
||||
let!(:parent_post) do
|
||||
create_parent_post!(
|
||||
@@ -697,6 +715,52 @@ RSpec.describe 'Posts API', type: :request do
|
||||
expect(names).not_to include('manko')
|
||||
end
|
||||
|
||||
it 'rejects a deprecated tag specified directly' do
|
||||
Tag.create!(
|
||||
name: 'deprecated_direct_tag',
|
||||
category: :general,
|
||||
deprecated_at: Time.current
|
||||
)
|
||||
sign_in_as(member)
|
||||
|
||||
post '/posts', params: post_write_params(
|
||||
title: 'new post',
|
||||
url: 'https://example.com/deprecated-direct-tag',
|
||||
tags: 'deprecated_direct_tag',
|
||||
thumbnail: dummy_upload
|
||||
)
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(json.fetch('errors')).to include(
|
||||
'tags' => ['廃止済みタグは付与できません.']
|
||||
)
|
||||
end
|
||||
|
||||
it 'expands through deprecated parent tags and saves active ancestors' do
|
||||
child = Tag.create!(name: 'active_child', category: :general)
|
||||
deprecated_parent = Tag.create!(
|
||||
name: 'deprecated_parent',
|
||||
category: :general,
|
||||
deprecated_at: Time.current
|
||||
)
|
||||
active_grandparent = Tag.create!(name: 'active_grandparent', category: :general)
|
||||
TagImplication.create!(tag: child, parent_tag: deprecated_parent)
|
||||
TagImplication.create!(tag: deprecated_parent, parent_tag: active_grandparent)
|
||||
sign_in_as(member)
|
||||
|
||||
post '/posts', params: post_write_params(
|
||||
title: 'expanded post',
|
||||
url: 'https://example.com/expanded-deprecated-parent',
|
||||
tags: 'active_child',
|
||||
thumbnail: dummy_upload
|
||||
)
|
||||
|
||||
expect(response).to have_http_status(:created)
|
||||
saved_names = Post.find(json.fetch('id')).tags.map(&:name)
|
||||
expect(saved_names).to include('active_child', 'active_grandparent')
|
||||
expect(saved_names).not_to include('deprecated_parent')
|
||||
end
|
||||
|
||||
context "when nico tag already exists in tags" do
|
||||
before do
|
||||
Tag.find_undiscard_or_create_by!(
|
||||
@@ -930,6 +994,26 @@ RSpec.describe 'Posts API', type: :request do
|
||||
expect(names).to include('spec_tag_2')
|
||||
end
|
||||
|
||||
it 'rejects a deprecated tag specified directly' do
|
||||
Tag.create!(
|
||||
name: 'deprecated_update_tag',
|
||||
category: :general,
|
||||
deprecated_at: Time.current
|
||||
)
|
||||
sign_in_as(member)
|
||||
|
||||
put "/posts/#{ post_record.id }", params: post_update_params(
|
||||
post_record,
|
||||
title: 'updated title',
|
||||
tags: 'deprecated_update_tag'
|
||||
)
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(json.fetch('errors')).to include(
|
||||
'tags' => ['廃止済みタグは付与できません.']
|
||||
)
|
||||
end
|
||||
|
||||
context "when nico tag already exists in tags" do
|
||||
before do
|
||||
Tag.find_undiscard_or_create_by!(
|
||||
|
||||
新しい課題から参照
ユーザをブロックする