このコミットが含まれているのは:
@@ -114,7 +114,7 @@ RSpec.describe 'Posts API', type: :request do
|
||||
end
|
||||
|
||||
let!(:tag_name) { create(:tag_name, name: 'spec_tag') }
|
||||
let!(:tag) { create(:tag, tag_name: tag_name, category: :general) }
|
||||
let!(:tag) { create(:tag, primary_tag_name: tag_name, category: :general) }
|
||||
|
||||
let!(:post_record) do
|
||||
Post.create!(title: 'spec post', url: 'https://example.com/spec').tap do |p|
|
||||
@@ -126,9 +126,9 @@ RSpec.describe 'Posts API', type: :request do
|
||||
let!(:user) { create_member_user! }
|
||||
|
||||
let!(:tag_name) { create(:tag_name, name: 'spec_tag') }
|
||||
let!(:tag) { create(:tag, tag_name:, category: :general) }
|
||||
let!(:tag) { create(:tag, primary_tag_name: tag_name, category: :general) }
|
||||
let!(:tag_name2) { create(:tag_name, name: 'unko') }
|
||||
let!(:tag2) { create(:tag, tag_name: tag_name2, category: :deerjikist) }
|
||||
let!(:tag2) { create(:tag, primary_tag_name: tag_name2, category: :deerjikist) }
|
||||
let!(:alias_tag_name) { create(:tag_name, :alias, name: 'manko', tag:) }
|
||||
|
||||
let!(:hit_post) do
|
||||
@@ -267,7 +267,7 @@ RSpec.describe 'Posts API', type: :request do
|
||||
end
|
||||
|
||||
it 'keeps internal name searches independent of colliding external ids' do
|
||||
get '/posts', params: { tags: tag.name }
|
||||
get '/posts', params: { tags: primary_tag_name_for(tag, 'ja').name }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json.fetch('count')).to eq(3)
|
||||
@@ -286,7 +286,7 @@ RSpec.describe 'Posts API', type: :request do
|
||||
|
||||
[nil, 'all'].each do |match|
|
||||
it "intersects internal and external matches with match=#{ match || 'omitted' }" do
|
||||
params = { tags: "#{ tag.name } nico:search_external" }
|
||||
params = { tags: "#{ primary_tag_name_for(tag, 'ja').name } nico:search_external" }
|
||||
params[:match] = match if match
|
||||
|
||||
get '/posts', params: params
|
||||
@@ -307,7 +307,8 @@ RSpec.describe 'Posts API', type: :request do
|
||||
end
|
||||
|
||||
it 'excludes external matches from an internal tag search' do
|
||||
get '/posts', params: { tags: "#{ tag.name } not:nico:search_external" }
|
||||
get '/posts', params: {
|
||||
tags: "#{ primary_tag_name_for(tag, 'ja').name } not:nico:search_external" }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json.fetch('count')).to eq(2)
|
||||
@@ -316,7 +317,9 @@ RSpec.describe 'Posts API', type: :request do
|
||||
end
|
||||
|
||||
it 'unions an external match with a negated internal match' do
|
||||
get '/posts', params: { tags: "nico:search_external not:#{ tag.name }", match: 'any' }
|
||||
get '/posts', params: {
|
||||
tags: "nico:search_external not:#{ primary_tag_name_for(tag, 'ja').name }",
|
||||
match: 'any' }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json.fetch('count')).to eq(2)
|
||||
@@ -333,7 +336,9 @@ RSpec.describe 'Posts API', type: :request do
|
||||
end
|
||||
|
||||
it 'applies the same mixed name search to the existing random endpoint' do
|
||||
get '/posts/random', params: { tags: "#{ tag.name } nico:search_external", match: 'all' }
|
||||
get '/posts/random', params: {
|
||||
tags: "#{ primary_tag_name_for(tag, 'ja').name } nico:search_external",
|
||||
match: 'all' }
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json.fetch('id')).to eq(both_post.id)
|
||||
@@ -342,13 +347,13 @@ RSpec.describe 'Posts API', type: :request do
|
||||
|
||||
context 'when tags contain not:' do
|
||||
let!(:foo_tag_name) { create(:tag_name, name: 'not_spec_foo') }
|
||||
let!(:foo_tag) { create(:tag, tag_name: foo_tag_name, category: :general) }
|
||||
let!(:foo_tag) { create(:tag, primary_tag_name: foo_tag_name, category: :general) }
|
||||
|
||||
let!(:bar_tag_name) { create(:tag_name, name: 'not_spec_bar') }
|
||||
let!(:bar_tag) { create(:tag, tag_name: bar_tag_name, category: :general) }
|
||||
let!(:bar_tag) { create(:tag, primary_tag_name: bar_tag_name, category: :general) }
|
||||
|
||||
let!(:baz_tag_name) { create(:tag_name, name: 'not_spec_baz') }
|
||||
let!(:baz_tag) { create(:tag, tag_name: baz_tag_name, category: :general) }
|
||||
let!(:baz_tag) { create(:tag, primary_tag_name: baz_tag_name, category: :general) }
|
||||
|
||||
let!(:foo_alias_tag_name) do
|
||||
create(:tag_name, :alias, name: 'not_spec_foo_alias', tag: foo_tag)
|
||||
@@ -739,7 +744,9 @@ RSpec.describe 'Posts API', type: :request do
|
||||
.find { _1['name'] == 'nico:post_index_external' }
|
||||
|
||||
expect(post_json.fetch('tags')).to include(
|
||||
a_hash_including('id' => tag.id, 'name' => tag.name, 'category' => 'general'))
|
||||
a_hash_including('id' => tag.id,
|
||||
'name' => primary_tag_name_for(tag, 'ja').name,
|
||||
'category' => 'general'))
|
||||
expect(external_json).not_to be_nil
|
||||
expect_external_tag_json(external_json, external_tag)
|
||||
end
|
||||
@@ -773,7 +780,7 @@ RSpec.describe 'Posts API', type: :request do
|
||||
|
||||
it 'omits deprecated tags' do
|
||||
deprecated_tag = create(:tag,
|
||||
name: 'deprecated_post_tag',
|
||||
primary_name: 'deprecated_post_tag',
|
||||
category: :general,
|
||||
deprecated_at: Time.current)
|
||||
PostTag.create!(post: post_record, tag: deprecated_tag)
|
||||
@@ -853,7 +860,7 @@ RSpec.describe 'Posts API', type: :request do
|
||||
tags =
|
||||
15.times.map do |i|
|
||||
tag_name = create(:tag_name, name: "show_query_tag_#{ i }")
|
||||
tag = create(:tag, tag_name:, category: :general)
|
||||
tag = create(:tag, primary_tag_name: tag_name, category: :general)
|
||||
create(:tag_name, :alias, name: "show_query_alias_#{ i }", tag:)
|
||||
PostTag.create!(post: post_record, tag:)
|
||||
tag
|
||||
@@ -909,7 +916,9 @@ RSpec.describe 'Posts API', type: :request do
|
||||
expect(response).to have_http_status(:ok)
|
||||
|
||||
expect(json.fetch('tags')).to include(
|
||||
a_hash_including('id' => tag.id, 'name' => tag.name, 'category' => 'general'))
|
||||
a_hash_including('id' => tag.id,
|
||||
'name' => primary_tag_name_for(tag, 'ja').name,
|
||||
'category' => 'general'))
|
||||
external_json =
|
||||
json
|
||||
.fetch('tags')
|
||||
@@ -1157,7 +1166,7 @@ RSpec.describe 'Posts API', type: :request do
|
||||
|
||||
it 'rejects a deprecated tag specified directly' do
|
||||
create(:tag,
|
||||
name: 'deprecated_direct_tag',
|
||||
primary_name: 'deprecated_direct_tag',
|
||||
category: :general,
|
||||
deprecated_at: Time.current)
|
||||
sign_in_as(member)
|
||||
@@ -1176,16 +1185,16 @@ RSpec.describe 'Posts API', type: :request do
|
||||
end
|
||||
|
||||
it 'expands through multiple deprecated parent tags and saves active ancestors' do
|
||||
child = create(:tag, name: 'active_child', category: :general)
|
||||
child = create(:tag, primary_name: 'active_child', category: :general)
|
||||
deprecated_parent = create(:tag,
|
||||
name: 'deprecated_parent',
|
||||
primary_name: 'deprecated_parent',
|
||||
category: :general,
|
||||
deprecated_at: Time.current)
|
||||
deprecated_grandparent = create(:tag,
|
||||
name: 'deprecated_grandparent',
|
||||
primary_name: 'deprecated_grandparent',
|
||||
category: :general,
|
||||
deprecated_at: Time.current)
|
||||
active_grandparent = create(:tag, name: 'active_grandparent', category: :general)
|
||||
active_grandparent = create(:tag, primary_name: 'active_grandparent', category: :general)
|
||||
TagImplication.create!(tag: child, parent_tag: deprecated_parent)
|
||||
TagImplication.create!(tag: deprecated_parent, parent_tag: deprecated_grandparent)
|
||||
TagImplication.create!(tag: deprecated_grandparent, parent_tag: active_grandparent)
|
||||
@@ -1199,7 +1208,8 @@ RSpec.describe 'Posts API', type: :request do
|
||||
)
|
||||
|
||||
expect(response).to have_http_status(:created)
|
||||
saved_names = Post.find(json.fetch('id')).tags.map(&:name)
|
||||
saved_names = TagName.where(tag_id: Post.find(json.fetch('id')).tags.select(:id),
|
||||
language_code: 'ja', primary_flg: true).pluck(:name)
|
||||
expect(saved_names).to include('active_child', 'active_grandparent')
|
||||
expect(saved_names).not_to include('deprecated_parent', 'deprecated_grandparent')
|
||||
end
|
||||
@@ -1302,7 +1312,8 @@ RSpec.describe 'Posts API', type: :request do
|
||||
expect(response).to have_http_status(:created)
|
||||
|
||||
created_post = Post.find(json.fetch('id'))
|
||||
tag = Tag.joins(:tag_name).find_by!(tag_names: { name: '伊地知ニジカ' })
|
||||
tag = TagName.find_by!(name: '伊地知ニジカ',
|
||||
language_code: 'ja', primary_flg: true).tag
|
||||
section = PostTagSection.find_by!(post: created_post, tag:)
|
||||
|
||||
expect(section.begin_ms).to eq(60_000)
|
||||
@@ -1322,7 +1333,8 @@ RSpec.describe 'Posts API', type: :request do
|
||||
expect(response).to have_http_status(:created)
|
||||
|
||||
created_post = Post.find(json.fetch('id'))
|
||||
tag = Tag.joins(:tag_name).find_by!(tag_names: { name: '伊地知ニジカ' })
|
||||
tag = TagName.find_by!(name: '伊地知ニジカ',
|
||||
language_code: 'ja', primary_flg: true).tag
|
||||
expect(PostTagSection.find_by(post: created_post, tag:)).to be_nil
|
||||
end
|
||||
|
||||
@@ -1339,7 +1351,8 @@ RSpec.describe 'Posts API', type: :request do
|
||||
expect(response).to have_http_status(:created)
|
||||
|
||||
created_post = Post.find(json.fetch('id'))
|
||||
tag = Tag.joins(:tag_name).find_by!(tag_names: { name: '伊地知ニジカ' })
|
||||
tag = TagName.find_by!(name: '伊地知ニジカ',
|
||||
language_code: 'ja', primary_flg: true).tag
|
||||
expect(PostTagSection.find_by(post: created_post, tag:)).to be_nil
|
||||
end
|
||||
|
||||
@@ -1656,7 +1669,7 @@ RSpec.describe 'Posts API', type: :request do
|
||||
begin_ms: 1000, end_ms: 2000)
|
||||
|
||||
tn2 = create(:tag_name, name: 'spec_tag_2')
|
||||
replacement_tag = create(:tag, tag_name: tn2, category: :general)
|
||||
replacement_tag = create(:tag, primary_tag_name: tn2, category: :general)
|
||||
|
||||
put "/posts/#{post_record.id}", params: post_update_params(
|
||||
post_record,
|
||||
@@ -1705,7 +1718,7 @@ RSpec.describe 'Posts API', type: :request do
|
||||
|
||||
it 'rejects a deprecated tag specified directly' do
|
||||
create(:tag,
|
||||
name: 'deprecated_update_tag',
|
||||
primary_name: 'deprecated_update_tag',
|
||||
category: :general,
|
||||
deprecated_at: Time.current)
|
||||
sign_in_as(member)
|
||||
@@ -1962,7 +1975,7 @@ RSpec.describe 'Posts API', type: :request do
|
||||
put "/posts/#{post_record.id}", params: post_write_params(
|
||||
base_version_no: base_version.version_no,
|
||||
title: 'updated by me',
|
||||
tags: "spec_tag #{Tag.no_deerjikist.name}")
|
||||
tags: "spec_tag #{primary_tag_name_for(Tag.no_deerjikist, 'ja').name}")
|
||||
|
||||
expect(response).to have_http_status(:conflict)
|
||||
|
||||
@@ -1994,7 +2007,8 @@ RSpec.describe 'Posts API', type: :request do
|
||||
put "/posts/#{post_record.id}", params: post_write_params(
|
||||
base_version_no: base_version.version_no,
|
||||
title: post_record.title,
|
||||
tags: "spec_tag #{Tag.no_deerjikist.name} incoming_added_tag")
|
||||
tags: ['spec_tag', primary_tag_name_for(Tag.no_deerjikist, 'ja').name,
|
||||
'incoming_added_tag'].join(' '))
|
||||
|
||||
expect(response).to have_http_status(:conflict)
|
||||
|
||||
@@ -2024,15 +2038,17 @@ RSpec.describe 'Posts API', type: :request do
|
||||
put "/posts/#{post_record.id}", params: post_write_params(
|
||||
base_version_no: base_version.version_no,
|
||||
title: post_record.title,
|
||||
tags: "spec_tag #{Tag.no_deerjikist.name} incoming_merge_tag",
|
||||
tags: ['spec_tag', primary_tag_name_for(Tag.no_deerjikist, 'ja').name,
|
||||
'incoming_merge_tag'].join(' '),
|
||||
merge: '1')
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
|
||||
names = post_record.reload.tags.map(&:name)
|
||||
names = TagName.where(tag_id: post_record.reload.tags.select(:id),
|
||||
language_code: 'ja', primary_flg: true).pluck(:name)
|
||||
|
||||
expect(names).to include('spec_tag')
|
||||
expect(names).to include(Tag.no_deerjikist.name)
|
||||
expect(names).to include(primary_tag_name_for(Tag.no_deerjikist, 'ja').name)
|
||||
expect(names).to include('current_merge_tag')
|
||||
expect(names).to include('incoming_merge_tag')
|
||||
end
|
||||
@@ -2055,14 +2071,15 @@ RSpec.describe 'Posts API', type: :request do
|
||||
put "/posts/#{post_record.id}", params: post_write_params(
|
||||
base_version_no: base_version.version_no,
|
||||
title: post_record.title,
|
||||
tags: "spec_tag #{ Tag.no_deerjikist.name }")
|
||||
tags: "spec_tag #{ primary_tag_name_for(Tag.no_deerjikist, 'ja').name }")
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
|
||||
names = post_record.reload.tags.map(&:name)
|
||||
names = TagName.where(tag_id: post_record.reload.tags.select(:id),
|
||||
language_code: 'ja', primary_flg: true).pluck(:name)
|
||||
|
||||
expect(names).to include('spec_tag')
|
||||
expect(names).to include(Tag.no_deerjikist.name)
|
||||
expect(names).to include(primary_tag_name_for(Tag.no_deerjikist, 'ja').name)
|
||||
expect(post_record.external_tags).to contain_exactly(nico_tag)
|
||||
end
|
||||
|
||||
@@ -2077,14 +2094,15 @@ RSpec.describe 'Posts API', type: :request do
|
||||
put "/posts/#{post_record.id}", params: post_write_params(
|
||||
base_version_no: base_version.version_no,
|
||||
title: 'updated title',
|
||||
tags: "spec_tag #{ Tag.no_deerjikist.name }")
|
||||
tags: "spec_tag #{ primary_tag_name_for(Tag.no_deerjikist, 'ja').name }")
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
|
||||
names = post_record.reload.tags.map(&:name)
|
||||
names = TagName.where(tag_id: post_record.reload.tags.select(:id),
|
||||
language_code: 'ja', primary_flg: true).pluck(:name)
|
||||
|
||||
expect(names).to include('spec_tag')
|
||||
expect(names).to include(Tag.no_deerjikist.name)
|
||||
expect(names).to include(primary_tag_name_for(Tag.no_deerjikist, 'ja').name)
|
||||
expect(post_record.external_tags).to contain_exactly(nico_tag)
|
||||
|
||||
external_json =
|
||||
@@ -2112,16 +2130,17 @@ RSpec.describe 'Posts API', type: :request do
|
||||
put "/posts/#{post_record.id}", params: post_write_params(
|
||||
base_version_no: base_version.version_no,
|
||||
title: post_record.title,
|
||||
tags: "spec_tag #{ Tag.no_deerjikist.name }")
|
||||
tags: "spec_tag #{ primary_tag_name_for(Tag.no_deerjikist, 'ja').name }")
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
|
||||
names = post_record.reload.tags.map(&:name)
|
||||
names = TagName.where(tag_id: post_record.reload.tags.select(:id),
|
||||
language_code: 'ja', primary_flg: true).pluck(: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)
|
||||
expect(names).to include(primary_tag_name_for(Tag.no_deerjikist, 'ja').name)
|
||||
expect(names).not_to include(primary_tag_name_for(linked_tag, 'ja').name)
|
||||
end
|
||||
|
||||
it 'force-updates stale posts without base_version_no' do
|
||||
@@ -2137,7 +2156,7 @@ RSpec.describe 'Posts API', type: :request do
|
||||
|
||||
put "/posts/#{post_record.id}", params: post_write_params(
|
||||
title: 'forced title',
|
||||
tags: "spec_tag #{Tag.no_deerjikist.name}",
|
||||
tags: "spec_tag #{primary_tag_name_for(Tag.no_deerjikist, 'ja').name}",
|
||||
force: '1')
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
@@ -2191,7 +2210,7 @@ RSpec.describe 'Posts API', type: :request do
|
||||
let(:oc_before) { Time.zone.local(2020, 1, 1, 0, 0, 0) }
|
||||
|
||||
let!(:tag_name2) { create(:tag_name, name: 'spec_tag_2') }
|
||||
let!(:tag2) { create(:tag, tag_name: tag_name2, category: :general) }
|
||||
let!(:tag2) { create(:tag, primary_tag_name: tag_name2, category: :general) }
|
||||
|
||||
def snapshot_tags(post)
|
||||
post.snapshot_tag_names.join(' ')
|
||||
@@ -2416,7 +2435,7 @@ RSpec.describe 'Posts API', type: :request do
|
||||
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')
|
||||
'name' => primary_tag_name_for(tag2, 'ja').name, 'type' => 'context')
|
||||
end
|
||||
|
||||
it 'filters versions by tag when the current snapshot includes the tag' do
|
||||
@@ -2550,7 +2569,7 @@ RSpec.describe 'Posts API', type: :request do
|
||||
base_version = create_post_version_for!(post_record)
|
||||
|
||||
tag_name2 = create(:tag_name, name: 'spec_tag_2')
|
||||
create(:tag, tag_name: tag_name2, category: :general)
|
||||
create(:tag, primary_tag_name: tag_name2, category: :general)
|
||||
|
||||
expect do
|
||||
put "/posts/#{post_record.id}", params: post_write_params(
|
||||
@@ -2715,7 +2734,7 @@ RSpec.describe 'Posts API', type: :request do
|
||||
base_version = create_post_version_for!(post_record.reload)
|
||||
|
||||
tag_name2 = create(:tag_name, name: 'spec_tag_2')
|
||||
tag2 = create(:tag, tag_name: tag_name2, category: :general)
|
||||
tag2 = create(:tag, primary_tag_name: tag_name2, category: :general)
|
||||
|
||||
expect {
|
||||
put "/posts/#{post_record.id}", params: post_write_params(
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする