このコミットが含まれているのは:
@@ -4,6 +4,7 @@ require 'securerandom'
|
||||
|
||||
|
||||
RSpec.describe 'Wiki API', type: :request do
|
||||
include WikiRecords
|
||||
def auth_headers(user)
|
||||
{ 'X-Transfer-Code' => user.inheritance_code }
|
||||
end
|
||||
@@ -18,7 +19,7 @@ RSpec.describe 'Wiki API', type: :request do
|
||||
deprecated_at: Time.zone.local(2026, 6, 1))
|
||||
end
|
||||
let!(:page) do
|
||||
Wiki::Commit.create_content!(
|
||||
seed_wiki_page(
|
||||
tag_name: tn,
|
||||
body: 'init',
|
||||
created_by_user: user,
|
||||
@@ -108,94 +109,14 @@ RSpec.describe 'Wiki API', type: :request do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when success' do
|
||||
it 'creates wiki_page and first content revision' do
|
||||
['Help:TestPage', 'ヘルプ:ホーム'].each do |title|
|
||||
it "rejects frozen creation of #{ title } without history writes" do
|
||||
expect do
|
||||
post endpoint, params: { title: 'Help:TestPage', body: "a\nb\nc", message: 'init' },
|
||||
headers: auth_headers(member)
|
||||
end
|
||||
.to change(WikiPage, :count).by(1)
|
||||
.and change(WikiRevision, :count).by(1)
|
||||
.and change(WikiVersion, :count).by(1)
|
||||
|
||||
expect(response).to have_http_status(:created)
|
||||
|
||||
page_id = json.fetch('id')
|
||||
expect(json.fetch('title')).to eq('Help:TestPage')
|
||||
|
||||
created_page = WikiPage.find(page_id)
|
||||
version = created_page.wiki_versions.order(:version_no).last
|
||||
|
||||
expect(version).to have_attributes(
|
||||
version_no: 1,
|
||||
event_type: 'create',
|
||||
title: 'Help:TestPage',
|
||||
body: "a\nb\nc",
|
||||
created_by_user_id: member.id
|
||||
)
|
||||
|
||||
rev = created_page.current_revision
|
||||
expect(rev).to be_present
|
||||
expect(rev).to be_content
|
||||
expect(rev.message).to eq('init')
|
||||
|
||||
expect(created_page.body).to eq("a\nb\nc")
|
||||
|
||||
expect(rev.lines_count).to eq(3)
|
||||
expect(rev.wiki_revision_lines.order(:position).pluck(:position)).to eq([0, 1, 2])
|
||||
expect(rev.wiki_lines.pluck(:body)).to match_array(['a', 'b', 'c'])
|
||||
end
|
||||
|
||||
it 'reuses existing WikiLine rows by sha256' do
|
||||
# 先に同じ行を作っておく
|
||||
WikiLine.create!(sha256: Digest::SHA256.hexdigest('a'), body: 'a', created_at: Time.current, updated_at: Time.current)
|
||||
|
||||
post endpoint,
|
||||
params: { title: 'Help:Reuse', body: "a\na" },
|
||||
headers: auth_headers(member)
|
||||
|
||||
page = WikiPage.find(JSON.parse(response.body).fetch('id'))
|
||||
rev = page.current_revision
|
||||
expect(rev.lines_count).to eq(2)
|
||||
|
||||
# "a" の WikiLine が増殖しない(1行のはず)
|
||||
expect(WikiLine.where(body: 'a').count).to eq(1)
|
||||
end
|
||||
|
||||
it 'deduplicates duplicated new lines before upsert' do
|
||||
duplicated = 'duplicated_line_for_wiki_line_upsert_spec'
|
||||
|
||||
post endpoint,
|
||||
params: { title: 'Help:DuplicateNewLine', body: "#{ duplicated }\n#{ duplicated }" },
|
||||
headers: auth_headers(member)
|
||||
|
||||
expect(response).to have_http_status(:created)
|
||||
|
||||
page = WikiPage.find(json.fetch('id'))
|
||||
rev = page.current_revision
|
||||
|
||||
expect(rev.lines_count).to eq(2)
|
||||
expect(WikiLine.where(body: duplicated).count).to eq(1)
|
||||
expect(rev.wiki_revision_lines.count).to eq(2)
|
||||
expect(rev.wiki_revision_lines.pluck(:wiki_line_id).uniq.size).to eq(1)
|
||||
end
|
||||
|
||||
it 'normalises CRLF and strips trailing newlines' do
|
||||
post endpoint,
|
||||
params: { title: 'Help:NormalisedBody',
|
||||
body: "a\r\nb\r\n\r\n", message: 'normalise' },
|
||||
headers: auth_headers(member)
|
||||
|
||||
expect(response).to have_http_status(:created)
|
||||
|
||||
page = WikiPage.find(json.fetch('id'))
|
||||
rev = page.current_revision
|
||||
version = page.wiki_versions.order(:version_no).last
|
||||
|
||||
expect(page.body).to eq("a\nb")
|
||||
expect(version.body).to eq("a\nb")
|
||||
expect(rev.lines_count).to eq(2)
|
||||
expect(rev.wiki_lines.order('wiki_revision_lines.position').map(&:body)).to eq(['a', 'b'])
|
||||
post endpoint, params: { title:, body: 'initial' }, headers: auth_headers(member)
|
||||
end.to change(WikiPage, :count).by(0)
|
||||
.and change(WikiRevision, :count).by(0)
|
||||
.and change(WikiVersion, :count).by(0)
|
||||
expect(response.status).to be_between(400, 499)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -211,7 +132,7 @@ RSpec.describe 'Wiki API', type: :request do
|
||||
let!(:test_tag_name) { create(:tag_name, name: 'TestPage') }
|
||||
|
||||
let!(:page) do
|
||||
Wiki::Commit.create_content!(
|
||||
seed_wiki_page(
|
||||
tag_name: test_tag_name,
|
||||
body: "a\nb",
|
||||
created_by_user: member,
|
||||
@@ -249,7 +170,8 @@ RSpec.describe 'Wiki API', type: :request do
|
||||
|
||||
expect do
|
||||
put "/wiki/#{page.id}",
|
||||
params: { title: 'TestPage', body: "x\ny", message: 'edit', base_revision_id: current_id },
|
||||
params: { title: 'TestPage', body: "x\ny", message: 'edit',
|
||||
base_revision_id: current_id },
|
||||
headers: auth_headers(member)
|
||||
end
|
||||
.to change(WikiRevision, :count).by(1)
|
||||
@@ -284,7 +206,7 @@ RSpec.describe 'Wiki API', type: :request do
|
||||
created_by_user: member)
|
||||
|
||||
linked_page =
|
||||
Wiki::Commit.create_content!(
|
||||
seed_wiki_page(
|
||||
tag_name: linked_tag_name,
|
||||
body: 'before',
|
||||
created_by_user: member,
|
||||
@@ -358,13 +280,14 @@ RSpec.describe 'Wiki API', type: :request do
|
||||
|
||||
describe 'GET /wiki/search' do
|
||||
before do
|
||||
Wiki::Commit.create_content!(
|
||||
tag_name: create(:tag_name, name: 'spec_wiki_title_2'),
|
||||
search_tag = create(:tag, primary_name: 'spec_wiki_title_2')
|
||||
seed_wiki_page(
|
||||
tag_name: search_tag.tag_name('ja'),
|
||||
body: 'search body 2',
|
||||
created_by_user: user,
|
||||
message: 'init')
|
||||
|
||||
Wiki::Commit.create_content!(
|
||||
seed_wiki_page(
|
||||
tag_name: create(:tag_name, name: 'unrelated_title'),
|
||||
body: 'unrelated body',
|
||||
created_by_user: user,
|
||||
@@ -516,7 +439,7 @@ RSpec.describe 'Wiki API', type: :request do
|
||||
it 'raises because redirect revisions are deprecated' do
|
||||
target_tag_name = create(:tag_name, name: 'redirect_deprecated_target')
|
||||
target =
|
||||
Wiki::Commit.create_content!(
|
||||
seed_wiki_page(
|
||||
tag_name: target_tag_name,
|
||||
body: 'target',
|
||||
created_by_user: user,
|
||||
@@ -539,7 +462,7 @@ RSpec.describe 'Wiki API', type: :request do
|
||||
linked_tag = create(:tag, primary_tag_name: linked_tag_name, category: :general)
|
||||
|
||||
linked_page =
|
||||
Wiki::Commit.create_content!(
|
||||
seed_wiki_page(
|
||||
tag_name: linked_tag_name,
|
||||
body: 'before',
|
||||
created_by_user: user,
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする