タグ説明移行 (#422) (#423)

Reviewed-on: #423
Co-authored-by: miteruzo <miteruzo@naver.com>
このコミットはプルリクエスト #423 でマージされました。
このコミットが含まれているのは:
2026-10-05 01:22:54 +09:00
committed by みてるぞ
コミット 4a6ace3322
25個のファイルの変更、1746行の追加、180行の削除
+276
ファイルの表示
@@ -0,0 +1,276 @@
require 'rails_helper'
RSpec.describe 'Tag description Wiki compatibility', type: :request do
let!(:user) { create_member_user! }
let!(:tag_name) { create(:tag_name, name: 'description_contract') }
let!(:page) do
Wiki::Commit.create_content!(
tag_name:, body: 'old-revision', created_by_user: user)
end
let!(:revisions) do
first = page.current_revision
second = Wiki::Commit.content!(page:, body: 'old-second', created_user: user)
third = Wiki::Commit.content!(page:, body: 'old-third', created_user: user)
[first, second, third]
end
let!(:tag) { create(:tag, primary_tag_name: tag_name) }
let!(:versions) do
revisions.each_with_index.map do |revision, index|
TagDescriptionVersion.create!(
id: revision.id, tag_id: tag.id, language_code: 'ja',
version_no: index + 1, event_type: index.zero? ? 'create' : 'update',
body: index == 2 ? 'new-version' : 'A',
created_by_user_id: user.id, created_at: revision.created_at)
end
end
let!(:description) do
TagDescription.create!(
id: page.id, tag:, language_code: 'ja', version_no: 3, body: 'new',
created_by_user_id: user.id, updated_by_user_id: user.id)
end
before { page.update_columns(body: 'old') }
# Observe real SELECTs, including cached queries, only during the request.
def without_legacy_reads
queries = []
subscriber = lambda do |*args|
sql = args.last.fetch(:sql)
if sql.match?(/\bSELECT\b/i) && sql.match?(/\bwiki_(pages|revisions|versions)\b/i)
queries << sql
end
end
ActiveSupport::Notifications.subscribed(subscriber, 'sql.active_record') { yield }
expect(queries).to be_empty
end
describe 'show' do
it 'uses current content and revision identity without legacy reads' do
without_legacy_reads { get "/wiki/#{ description.id }" }
expect(response).to have_http_status(:ok)
expect(json).to include('body' => 'new', 'revision_id' => versions.last.id,
'pred' => versions.second.id, 'succ' => nil)
end
[0, 1, 2].each do |index|
it "navigates displayed version #{ index + 1 }, preserving repeated bodies" do
without_legacy_reads do
get "/wiki/#{ description.id }", params: { version: versions[index].id }
end
expect(response).to have_http_status(:ok)
expect(json).to include(
'body' => versions[index].body,
'revision_id' => versions[index].id,
'pred' => index.zero? ? nil : versions[index - 1].id,
'succ' => index == 2 ? nil : versions[index + 1].id)
end
end
it 'does not fall back to a revision absent from new history' do
versions.first.destroy!
without_legacy_reads do
get "/wiki/#{ description.id }", params: { version: revisions.first.id }
end
expect(response).to have_http_status(:not_found)
end
it 'does not fall back when the new current revision is missing' do
versions.last.destroy!
without_legacy_reads { get "/wiki/#{ description.id }" }
expect(response).to have_http_status(:not_found)
end
end
describe 'revision resource scope' do
let!(:other_tag) { create(:tag, primary_name: 'other_description_contract') }
let!(:other_version) do
TagDescriptionVersion.create!(
tag_id: other_tag.id, language_code: 'ja', version_no: 1,
event_type: 'create', body: 'other tag history',
created_by_user_id: user.id, created_at: Time.current)
end
let!(:other_description) do
TagDescription.create!(
tag: other_tag, language_code: 'ja', version_no: 1, body: 'other tag history',
created_by_user_id: user.id, updated_by_user_id: user.id)
end
it 'returns 404 when show specifies another tag description version' do
get "/wiki/#{ description.id }", params: { version: other_version.id }
expect(response).to have_http_status(:not_found)
expect(response.body).not_to include(other_version.body)
end
it 'returns 404 when diff from belongs to another tag description' do
get "/wiki/#{ description.id }/diff",
params: { from: other_version.id, to: versions.last.id }
expect(response).to have_http_status(:not_found)
expect(response.body).not_to include(other_version.body)
end
it 'returns 404 when diff to belongs to another tag description' do
get "/wiki/#{ description.id }/diff",
params: { from: versions.first.id, to: other_version.id }
expect(response).to have_http_status(:not_found)
expect(response.body).not_to include(other_version.body)
end
end
describe 'show_by_title' do
it 'resolves TagName and reads current content from new tables' do
without_legacy_reads { get "/wiki/title/#{ tag_name.name }" }
expect(response).to have_http_status(:ok)
expect(json).to include('id' => description.id, 'body' => 'new',
'revision_id' => versions.last.id)
end
it 'uses historical content and navigation from the new history' do
get "/wiki/title/#{ tag_name.name }", params: { version: versions.second.id }
expect(response).to have_http_status(:ok)
expect(json).to include('body' => 'A', 'revision_id' => versions.second.id,
'pred' => versions.first.id, 'succ' => versions.last.id)
end
it 'ignores changes to same-title legacy content and revision metadata' do
get "/wiki/title/#{ tag_name.name }"
original = json
page.update_columns(body: 'changed legacy body')
revisions.last.update_columns(message: 'legacy message', created_at: 1.day.ago)
revisions.last.wiki_lines.update_all(body: 'changed legacy revision')
get "/wiki/title/#{ tag_name.name }"
expect(json).to eq(original)
expect(json.fetch('body')).to eq('new')
end
end
describe 'exists' do
it 'recognises an ID without reading legacy tables' do
without_legacy_reads { get "/wiki/#{ description.id }/exists" }
expect(response).to have_http_status(:no_content)
end
it 'recognises a title without reading legacy tables' do
without_legacy_reads { get "/wiki/title/#{ tag_name.name }/exists" }
expect(response).to have_http_status(:no_content)
end
context 'without a legacy page' do
before do
WikiVersion.where(wiki_page_id: page.id).delete_all
page.destroy!
end
it 'recognises the description ID alone' do
get "/wiki/#{ description.id }/exists"
expect(response).to have_http_status(:no_content)
end
it 'recognises the TagName alone' do
get "/wiki/title/#{ tag_name.name }/exists"
expect(response).to have_http_status(:no_content)
end
it 'shows the description by title' do
get "/wiki/title/#{ tag_name.name }"
expect(response).to have_http_status(:ok)
expect(json).to include('body' => 'new', 'revision_id' => versions.last.id)
end
end
end
describe 'diff' do
[false, true].each do |current|
it "uses new bodies with #{ current ? 'implicit current' : 'explicit to' }" do
params = { from: versions.first.id }
params[:to] = versions.last.id unless current
get "/wiki/#{ description.id }/diff", params: params
expect(response).to have_http_status(:ok)
expect(json).to include(
'wiki_page_id' => description.id,
'older_revision_id' => versions.first.id,
'newer_revision_id' => versions.last.id,
'diff' => [{ 'type' => 'removed', 'content' => 'A' },
{ 'type' => 'added', 'content' => 'new-version' }])
end
end
it 'does not query legacy tables for diff' do
without_legacy_reads do
get "/wiki/#{ description.id }/diff",
params: { from: versions.first.id, to: versions.last.id }
end
expect(response).to have_http_status(:ok)
end
it 'keeps distinct revision IDs for identical consecutive bodies' do
get "/wiki/#{ description.id }/diff",
params: { from: versions.first.id, to: versions.second.id }
expect(response).to have_http_status(:ok)
expect(json).to include(
'older_revision_id' => versions.first.id,
'newer_revision_id' => versions.second.id,
'diff' => [{ 'type' => 'context', 'content' => 'A' }])
end
end
describe 'changes' do
it 'lists every new version including consecutive identical bodies' do
without_legacy_reads { get '/wiki/changes', params: { id: description.id } }
expect(response).to have_http_status(:ok)
expect(json.map { |row| row.fetch('revision_id') }).to eq(versions.reverse.map(&:id))
expect(json.first.keys).to match_array(
['revision_id', 'pred', 'succ', 'wiki_page', 'user', 'kind', 'message', 'timestamp'])
expect(json.first).to include(
'pred' => versions.second.id, 'succ' => nil, 'kind' => 'content',
'timestamp' => versions.last.created_at.iso8601(3),
'user' => { 'id' => user.id, 'name' => user.name })
expect(json.first.fetch('wiki_page')).to include('id' => description.id,
'title' => tag_name.name)
end
it 'ignores legacy-only revisions and metadata changes' do
get '/wiki/changes', params: { id: description.id }
original = json
revisions.first.update_columns(message: 'legacy changed', created_at: 1.day.ago)
WikiRevision.create!(
wiki_page: page, created_user: user, kind: :content,
tree_sha256: Digest::SHA256.hexdigest('legacy only'), lines_count: 0)
get '/wiki/changes', params: { id: description.id }
expect(json).to eq(original)
expect(json.map { |row| row.fetch('revision_id') }).to eq(versions.reverse.map(&:id))
end
end
describe 'mixed changes' do
it 'includes unmigrated history and ignores migrated legacy-only revisions' do
legacy_page = Wiki::Commit.create_content!(
tag_name: create(:tag_name, name: 'Help_mixed'),
body: 'help', created_by_user: user)
legacy_revision = legacy_page.current_revision
extra = WikiRevision.create!(
wiki_page: page, created_user: user, kind: :content,
tree_sha256: Digest::SHA256.hexdigest('legacy only'), lines_count: 0)
get '/wiki/changes'
expect(response).to have_http_status(:ok)
migrated = json.select { |row| row.fetch('wiki_page').fetch('id') == description.id }
expect(migrated.map { |row| row.fetch('revision_id') }).to eq(versions.reverse.map(&:id))
expect(json.map { |row| row.fetch('revision_id') }).not_to include(extra.id)
expect(json).to include(include(
'revision_id' => legacy_revision.id,
'wiki_page' => include('id' => legacy_page.id, 'title' => 'Help_mixed')))
end
end
describe 'index' do
[nil, 'description_contract'].each do |title|
it "returns new content once in #{ title ? 'filtered' : 'unfiltered' } index" do
get '/wiki', params: { title: }
expect(response).to have_http_status(:ok)
rows = json.select { |row| row.fetch('id') == description.id }
expect(rows.size).to eq(1)
expect(rows.first).to include('body' => 'new', 'title' => tag_name.name)
end
end
end
end
+274
ファイルの表示
@@ -0,0 +1,274 @@
require 'rails_helper'
RSpec.describe 'Tag description Wiki dual writes', type: :request do
let!(:user) { create_member_user! }
let!(:tag_name) { create(:tag_name, name: 'description_write') }
let(:tag) { create(:tag, primary_tag_name: tag_name) }
let(:headers) { { 'X-Transfer-Code' => user.inheritance_code } }
def stored_state
[WikiPage, WikiRevision, WikiVersion, TagDescription, TagDescriptionVersion,
TagName, TagVersion].map do |model|
model.order(:id).map(&:attributes)
end
end
# Fail after a real INSERT/UPDATE, exercising rollback rather than a mock write.
def fail_save model
failure = Class.new(StandardError)
callback = ->(_record) { raise failure, 'injected persistence failure' }
model.set_callback(:save, :after, callback)
expect { yield }.to raise_error(failure)
ensure
model.skip_callback(:save, :after, callback)
end
describe 'POST /wiki' do
before { tag }
def create_description
post '/wiki', params: { title: tag_name.name, body: 'initial', message: 'create' },
headers: headers
end
it 'creates both current records and histories with a shared revision ID' do
expect { create_description }
.to change(WikiPage, :count).by(1)
.and change(WikiRevision, :count).by(1)
.and change(WikiVersion, :count).by(1)
.and change(TagDescription, :count).by(1)
.and change(TagDescriptionVersion, :count).by(1)
expect(response).to have_http_status(:created)
page = WikiPage.find(json.fetch('id'))
description = TagDescription.find_by!(tag_id: tag.id, language_code: 'ja')
version = TagDescriptionVersion.find_by!(tag_id: tag.id, language_code: 'ja')
expect(description).to have_attributes(id: page.id, body: 'initial', version_no: 1)
expect(version).to have_attributes(
id: page.current_revision.id, body: 'initial', version_no: 1,
event_type: 'create', created_by_user_id: user.id)
expect(page.body).to eq(description.body)
expect(page.current_revision.body).to eq(version.body)
expect(page.wiki_versions.last.body).to eq(version.body)
end
['missing_description', 'orphan_description'].each do |title|
it "rejects the bare title #{ title } without writing any resource" do
create(:tag_name, name: title) if title == 'orphan_description'
before_state = stored_state
post '/wiki', params: { title:, body: 'initial' }, headers: headers
expect(response).to have_http_status(:unprocessable_entity)
expect(json).to include('type' => 'validation_error')
expect(stored_state).to eq(before_state)
end
end
it 'creates a namespaced legacy Wiki resource without a Tag' do
expect do
post '/wiki', params: { title: 'Help:description_write', body: 'legacy' },
headers: headers
end.to change(WikiPage, :count).by(1)
.and change(WikiRevision, :count).by(1)
.and change(WikiVersion, :count).by(1)
.and change(TagDescription, :count).by(0)
.and change(TagDescriptionVersion, :count).by(0)
expect(response).to have_http_status(:created)
page = WikiPage.find(json.fetch('id'))
expect(page.tag_name.tag).to be_nil
expect(page.body).to eq('legacy')
expect(page.current_revision.body).to eq('legacy')
end
it 'creates only legacy Wiki for a namespaced title with an existing Tag' do
namespaced_name = create(:tag_name, name: 'help:foo')
namespaced_tag = create(:tag, primary_tag_name: namespaced_name)
expect do
post '/wiki', params: { title: namespaced_name.name, body: 'legacy' },
headers: headers
end.to change(WikiPage, :count).by(1)
.and change(WikiRevision, :count).by(1)
.and change(WikiVersion, :count).by(1)
.and change(TagName, :count).by(0)
.and change(TagDescription, :count).by(0)
.and change(TagDescriptionVersion, :count).by(0)
expect(response).to have_http_status(:created)
page = WikiPage.find(json.fetch('id'))
expect(page).to have_attributes(tag_name_id: namespaced_name.id, body: 'legacy')
expect(page.tag_name.tag).to eq(namespaced_tag)
expect(page.current_revision.body).to eq('legacy')
expect(page.wiki_versions.last.body).to eq('legacy')
end
[WikiPage, WikiRevision, WikiVersion, TagDescription, TagDescriptionVersion].each do |model|
it "rolls back both systems when #{ model.name } persistence fails" do
tag_name
before_state = stored_state
aggregate_failures do
fail_save(model) { create_description }
expect(stored_state).to eq(before_state)
end
end
end
end
describe 'PUT /wiki/:id' do
let!(:page) do
tag
Wiki::Commit.create_content!(
tag_name:, body: 'before', created_by_user: user)
end
let!(:first_revision) { page.current_revision }
let!(:description) do
TagDescription.find_by!(tag_id: tag.id, language_code: 'ja')
end
def update_description body: 'after', title: tag_name.name, base: first_revision.id
put "/wiki/#{ page.id }",
params: { title:, body:, message: 'edit', base_revision_id: base },
headers: headers
end
it 'increments the independent description sequence and shares revision identity' do
expect(page.reload.version_no).to eq(1)
expect(description.version_no).to eq(1)
expect { update_description }
.to change(WikiRevision, :count).by(1)
.and change(WikiVersion, :count).by(1)
.and change(TagDescriptionVersion, :count).by(1)
expect(response).to have_http_status(:ok)
revision = page.reload.current_revision
version = TagDescriptionVersion.find(revision.id)
expect(description.reload).to have_attributes(body: 'after', version_no: 2)
expect(version).to have_attributes(
body: 'after', version_no: 2, event_type: 'update', created_by_user_id: user.id)
expect(page).to have_attributes(body: 'after', version_no: 2)
expect(revision.body).to eq(version.body)
expect(page.wiki_versions.order(:version_no).last.body).to eq(version.body)
end
it 'uses description identity even when its Wiki TagName no longer owns the Tag' do
tag_name.update_columns(tag_id: nil)
expect { update_description }
.to change(WikiRevision, :count).by(1)
.and change(WikiVersion, :count).by(1)
.and change(TagDescriptionVersion, :count).by(1)
expect(response).to have_http_status(:ok)
expect(description.reload).to have_attributes(body: 'after', version_no: 2)
expect(TagDescriptionVersion.find(page.reload.current_revision.id))
.to have_attributes(tag_id: tag.id, body: 'after', version_no: 2)
end
it 'does not add body history for a title-only update' do
revision_count = WikiRevision.count
wiki_version_count = WikiVersion.count
description_version_count = TagDescriptionVersion.count
wiki_version_no = page.reload.version_no
description_version_no = description.version_no
current_revision_id = page.current_revision.id
page_state = page.attributes
description_state = description.attributes
update_description(body: 'before', title: 'Help:description_renamed')
expect(response).to have_http_status(:ok)
expect(tag_name.reload.name).to eq('Help:description_renamed')
expect(WikiRevision.count).to eq(revision_count)
expect(WikiVersion.count).to eq(wiki_version_count)
expect(TagDescriptionVersion.count).to eq(description_version_count)
expect(page.reload).to have_attributes(body: 'before', version_no: wiki_version_no)
expect(page.current_revision.id).to eq(current_revision_id)
expect(page.reload.attributes).to eq(page_state)
expect(description.reload).to have_attributes(
body: 'before', version_no: description_version_no)
expect(description.reload.attributes).to eq(description_state)
end
it 'does not add body history for a TagName rename through tags' do
revision_count = WikiRevision.count
wiki_version_count = WikiVersion.count
description_version_count = TagDescriptionVersion.count
page_version_no = page.reload.version_no
current_revision_id = page.current_revision.id
patch "/tags/#{ tag.id }",
params: { name: 'description_tag_renamed' },
headers: headers
expect(response).to have_http_status(:ok)
expect(tag_name.reload.name).to eq('description_tag_renamed')
expect(WikiRevision.count).to eq(revision_count)
expect(WikiVersion.count).to eq(wiki_version_count)
expect(TagDescriptionVersion.count).to eq(description_version_count)
expect(page.reload.version_no).to eq(page_version_no)
expect(page.current_revision.id).to eq(current_revision_id)
expect(description.reload).to have_attributes(
body: 'before', version_no: 1)
end
it 'keeps both systems and the title unchanged on a stale revision conflict' do
update_description(body: 'current body', base: first_revision.id)
expect(response).to have_http_status(:ok)
stale_revision_id = first_revision.id
before_state = stored_state
update_description(
body: 'conflicting body',
title: 'conflicting_rename',
base: stale_revision_id)
expect(response).to have_http_status(:conflict)
expect(stored_state).to eq(before_state)
expect(tag_name.reload.name).not_to eq('conflicting_rename')
end
[WikiPage, WikiRevision, WikiVersion, TagDescription, TagDescriptionVersion].each do |model|
it "rolls back both systems when #{ model.name } persistence fails" do
before_state = stored_state
aggregate_failures do
fail_save(model) do
update_description(body: 'rollback body', title: 'rollback_rename')
end
expect(stored_state).to eq(before_state)
end
end
end
[['identical body', 'before'],
['normalised-equivalent body', "before\n\n"]].each do |label, body|
it "does not write histories for #{ label }" do
before_state = stored_state
page_state = page.reload.attributes
description_state = description.reload.attributes
current_revision_id = page.current_revision.id
wiki_lines = WikiLine.order(:id).map(&:attributes)
revision_lines = WikiRevisionLine.order(:id).map(&:attributes)
page_version_no = page.version_no
description_version_no = description.version_no
update_description(body:)
expect(response).to have_http_status(:ok)
expect(WikiRevision.count).to eq(before_state[1].length)
expect(WikiVersion.count).to eq(before_state[2].length)
expect(TagDescriptionVersion.count).to eq(before_state[4].length)
expect(page.reload.version_no).to eq(page_version_no)
expect(description.reload.version_no).to eq(description_version_no)
expect(page.current_revision.id).to eq(current_revision_id)
expect(page.reload.attributes).to eq(page_state)
expect(description.reload.attributes).to eq(description_state)
expect(WikiLine.order(:id).map(&:attributes)).to eq(wiki_lines)
expect(WikiRevisionLine.order(:id).map(&:attributes)).to eq(revision_lines)
end
end
end
end
+359
ファイルの表示
@@ -0,0 +1,359 @@
require 'rails_helper'
RSpec.describe 'Tag description native API', type: :request do
let!(:author) { create_member_user! }
let(:editor) { create(:user, :member, name: 'description editor') }
let(:tag_name) { create(:tag_name, name: 'native_description') }
let(:tag) { create(:tag, primary_tag_name: tag_name) }
let(:headers) { { 'X-Transfer-Code' => editor.inheritance_code } }
let(:endpoint) { "/tags/#{ tag.id }/description" }
def stored_state
[WikiPage, WikiRevision, WikiVersion, TagDescription, TagDescriptionVersion,
WikiLine, WikiRevisionLine, TagName, TagVersion].map do |model|
model.order(:id).map(&:attributes)
end
end
def fail_save model
failure = Class.new(StandardError)
callback = ->(_record) { raise failure, 'injected persistence failure' }
model.set_callback(:save, :after, callback)
expect { yield }.to raise_error(failure)
ensure
model.skip_callback(:save, :after, callback)
end
def without_legacy_reads
queries = []
subscriber = lambda do |*args|
sql = args.last.fetch(:sql)
if sql.match?(/\bSELECT\b/i) && sql.match?(/\bwiki_(pages|revisions|versions)\b/i)
queries << sql
end
end
ActiveSupport::Notifications.subscribed(subscriber, 'sql.active_record') { yield }
expect(queries).to be_empty
end
def native_get path, action: 'show'
get path
# A missing route must not make the resource-not-found examples pass.
expect(request.path_parameters).to include(controller: 'tag_descriptions', action:)
end
def native_write body:, request_headers: headers
put endpoint, params: { body: }, headers: request_headers
expect(request.path_parameters).to include(
controller: 'tag_descriptions', action: 'update')
end
def expect_current description
expect(json).to include(
'tag_id' => description.tag_id,
'language_code' => 'ja', 'body' => description.body,
'version_no' => description.version_no,
'created_by_user_id' => description.created_by_user_id,
'updated_by_user_id' => description.updated_by_user_id,
'created_at' => description.created_at.iso8601(3),
'updated_at' => description.updated_at.iso8601(3))
expect(json.keys).not_to include('title', 'name', 'wiki_page', 'tag_name_id')
end
describe 'routing', type: :routing do
it 'routes GET by Tag ID to show' do
expect(get: '/tags/123/description').to route_to(
controller: 'tag_descriptions', action: 'show', id: '123')
end
it 'routes GET by TagName to show_by_title' do
expect(get: '/tags/name/native_description/description').to route_to(
controller: 'tag_descriptions', action: 'show_by_title', name: 'native_description')
end
it 'does not route POST by Tag ID' do
expect(post: '/tags/123/description').not_to be_routable
end
it 'routes PUT by Tag ID to update' do
expect(put: '/tags/123/description').to route_to(
controller: 'tag_descriptions', action: 'update', id: '123')
end
end
describe 'native reads' do
let!(:description) do
TagDescription.create!(
id: tag.id + 1_000_000, tag:, language_code: 'ja', body: 'native current',
version_no: 1, created_by_user_id: author.id, updated_by_user_id: editor.id)
end
let!(:version) do
TagDescriptionVersion.create!(
tag_id: tag.id, language_code: 'ja', body: 'native version', version_no: 1,
event_type: 'create', created_by_user_id: author.id, created_at: Time.current)
end
let(:name_endpoint) { "/tags/name/#{ tag_name.name }/description" }
it 'reads the current resource by Tag ID without a WikiPage' do
expect(description.id).not_to eq(tag.id)
expect(WikiPage.exists?(id: description.id)).to be(false)
without_legacy_reads { native_get(endpoint) }
expect(response).to have_http_status(:ok)
expect_current(description)
end
it 'does not interpret a compatibility handle as a Tag ID' do
other_tag = create(:tag, id: description.id, primary_name: 'handle_collision')
other = TagDescription.create!(
tag: other_tag, language_code: 'ja', body: 'other current', version_no: 1,
created_by_user_id: author.id, updated_by_user_id: author.id)
without_legacy_reads { native_get("/tags/#{ other_tag.id }/description") }
expect(response).to have_http_status(:ok)
expect_current(other)
end
context 'with another language for the same Tag' do
before do
# Seed only the reference row; V1 does not enable an English locale.
Language.connection.execute(<<~SQL)
INSERT IGNORE INTO languages (code, name, created_at)
VALUES ('en', 'English', CURRENT_TIMESTAMP)
SQL
end
it 'selects the Japanese resource' do
TagDescription.create!(
tag:, language_code: 'en', body: 'English current', version_no: 4,
created_by_user_id: author.id, updated_by_user_id: author.id)
without_legacy_reads { native_get(endpoint) }
expect(response).to have_http_status(:ok)
expect_current(description)
end
it 'returns 404 if only the English description exists' do
description.update!(language_code: 'en')
without_legacy_reads { native_get(endpoint) }
expect(response).to have_http_status(:not_found)
end
end
it 'resolves the primary Japanese TagName without a WikiPage' do
without_legacy_reads { native_get(name_endpoint, action: 'show_by_title') }
expect(response).to have_http_status(:ok)
expect_current(description)
end
it 'resolves an alias through the existing TagName canonicalisation semantics' do
alias_name = create(:tag_name, :alias, tag:, name: 'native_alias')
expect(TagName.canonicalise(Locale.nipponese, [alias_name.name])).to eq([tag_name.name])
without_legacy_reads do
native_get("/tags/name/#{ alias_name.name }/description", action: 'show_by_title')
end
expect(response).to have_http_status(:ok)
expect_current(description)
end
[:id, :name].each do |lookup|
it "ignores divergent legacy body and history for #{ lookup } lookup" do
page = WikiPage.create!(
id: description.id, tag_name:, body: 'old current',
created_user: author, updated_user: author)
revision = WikiRevision.create!(
wiki_page: page, created_user: author, kind: :content,
lines_count: 1, tree_sha256: Digest::SHA256.hexdigest('old revision'))
line = WikiLine.create!(body: 'old revision', sha256: revision.tree_sha256)
WikiRevisionLine.create!(wiki_revision: revision, wiki_line: line, position: 0)
WikiVersionRecorder.record!(page:, event_type: :create, created_by_user: author)
path = lookup == :id ? endpoint : name_endpoint
action = lookup == :id ? 'show' : 'show_by_title'
without_legacy_reads { native_get(path, action:) }
expect(response).to have_http_status(:ok)
expect_current(description)
original = json
page.update_columns(body: 'changed old current')
line.update_columns(body: 'changed old revision')
revision.update_columns(message: 'changed old history', created_at: 1.day.ago)
without_legacy_reads { native_get(path, action:) }
expect(response).to have_http_status(:ok)
expect(json).to eq(original)
end
end
end
describe 'missing native resources' do
it 'returns 404 for a Tag without a description' do
without_legacy_reads { native_get(endpoint) }
expect(response).to have_http_status(:not_found)
end
it 'returns 404 for a primary name without a description' do
tag
without_legacy_reads do
native_get("/tags/name/#{ tag_name.name }/description", action: 'show_by_title')
end
expect(response).to have_http_status(:not_found)
end
it 'returns 404 for a missing Tag' do
missing_id = Tag.maximum(:id).to_i + 1
without_legacy_reads { native_get("/tags/#{ missing_id }/description") }
expect(response).to have_http_status(:not_found)
end
end
describe 'PUT /tags/:id/description' do
context 'without an existing description' do
before { tag }
it 'creates both current resources and histories with matching compatibility IDs' do
expect { native_write(body: 'created natively') }
.to change(TagDescription, :count).by(1)
.and change(TagDescriptionVersion, :count).by(1)
.and change(WikiPage, :count).by(1)
.and change(WikiRevision, :count).by(1)
.and change(WikiVersion, :count).by(1)
expect(response).to have_http_status(:created)
description = TagDescription.find_by!(tag_id: tag.id, language_code: 'ja')
page = WikiPage.find(description.id)
revision = page.current_revision
version = TagDescriptionVersion.find(revision.id)
expect(description).to have_attributes(
body: 'created natively', version_no: 1,
created_by_user_id: editor.id, updated_by_user_id: editor.id)
expect(version).to have_attributes(
tag_id: tag.id, language_code: 'ja', body: description.body,
version_no: 1, event_type: 'create', created_by_user_id: editor.id)
expect(page).to have_attributes(tag_name_id: tag_name.id, body: description.body)
expect(revision.body).to eq(version.body)
expect(page.wiki_versions.last.body).to eq(version.body)
expect_current(description)
get "/wiki/#{ description.id }"
expect(response).to have_http_status(:ok)
expect(json).to include('body' => description.body, 'revision_id' => version.id)
end
[WikiPage, WikiRevision, WikiVersion, TagDescription, TagDescriptionVersion].each do |model|
it "rolls back native create when #{ model.name } persistence fails" do
headers
before_state = stored_state
aggregate_failures do
fail_save(model) { native_write(body: 'rollback create') }
expect(stored_state).to eq(before_state)
end
end
end
end
context 'with an existing description' do
let!(:page) do
tag
Wiki::Commit.create_content!(tag_name:, body: 'before', created_by_user: author)
end
let!(:description) do
TagDescription.find_by!(tag_id: tag.id, language_code: 'ja')
end
it 'writes matching histories when the body changes' do
expect(page.reload.version_no).to eq(1)
expect(description.version_no).to eq(1)
expect { native_write(body: 'after') }
.to change(WikiRevision, :count).by(1)
.and change(WikiVersion, :count).by(1)
.and change(TagDescriptionVersion, :count).by(1)
expect(response).to have_http_status(:ok)
expect(description.reload).to have_attributes(
body: 'after', version_no: 2,
created_by_user_id: author.id, updated_by_user_id: editor.id)
expect(page.reload).to have_attributes(body: 'after', version_no: 2)
revision = page.current_revision
version = TagDescriptionVersion.find(revision.id)
expect(version).to have_attributes(
tag_id: tag.id, language_code: 'ja', version_no: 2, event_type: 'update',
body: 'after', created_by_user_id: editor.id)
expect(revision.body).to eq(version.body)
expect(page.wiki_versions.order(:version_no).last.body).to eq(version.body)
get "/wiki/#{ description.id }"
expect(response).to have_http_status(:ok)
expect(json).to include('body' => 'after', 'revision_id' => version.id)
end
['before', "before\n\n"].each do |body|
it 'does not write histories when the normalised body is unchanged' do
before_state = stored_state
page_state = page.reload.attributes
description_state = description.reload.attributes
current_revision_id = page.current_revision.id
native_write(body:)
expect(response).to have_http_status(:ok)
expect(stored_state).to eq(before_state)
expect(page.reload.attributes).to eq(page_state)
expect(description.reload.attributes).to eq(description_state)
expect(page.current_revision.id).to eq(current_revision_id)
end
end
[WikiPage, WikiRevision, WikiVersion, TagDescription, TagDescriptionVersion].each do |model|
it "rolls back native update when #{ model.name } persistence fails" do
headers
before_state = stored_state
aggregate_failures do
fail_save(model) { native_write(body: 'rollback update') }
expect(stored_state).to eq(before_state)
end
end
end
end
end
describe 'write access and validation' do
before { tag }
it 'requires authentication without changing either system' do
before_state = stored_state
native_write(body: 'unauthorised', request_headers: { })
expect(response).to have_http_status(:unauthorized)
expect(stored_state).to eq(before_state)
end
it 'rejects a guest without changing either system' do
guest = create(:user, :guest)
before_state = stored_state
native_write(body: 'forbidden',
request_headers: { 'X-Transfer-Code' => guest.inheritance_code })
expect(response).to have_http_status(:forbidden)
expect(stored_state).to eq(before_state)
end
it 'rejects a banned member without changing either system' do
banned = create(:user, :member, :banned)
before_state = stored_state
native_write(body: 'forbidden',
request_headers: { 'X-Transfer-Code' => banned.inheritance_code })
expect(response).to have_http_status(:forbidden)
expect(stored_state).to eq(before_state)
end
it 'rejects blank body using the existing validation error format' do
headers
before_state = stored_state
native_write(body: '')
expect(response).to have_http_status(:unprocessable_entity)
expect(json).to include('type' => 'validation_error',
'errors' => include('body' => a_kind_of(Array)))
expect(stored_state).to eq(before_state)
end
it 'returns 404 when PUT targets a missing Tag' do
missing_id = Tag.maximum(:id).to_i + 1
put "/tags/#{ missing_id }/description",
params: { body: 'missing' },
headers: headers
expect(response).to have_http_status(:not_found)
end
end
end
+8 -18
ファイルの表示
@@ -25,9 +25,10 @@ RSpec.describe 'Tag and wiki history integrity', type: :request do
end
describe 'PATCH /tags/:id' do
it 'records wiki_version when tag name changes and tag has wiki' do
it 'renames the current Wiki resource without adding body history' do
tag = create_tag!(name: 'patch_tag_wiki_before')
wiki_page = create_wiki_for_tag!(tag:, body: 'wiki body before')
wiki_history = wiki_page.wiki_versions.map(&:attributes)
expect {
patch "/tags/#{ tag.id }", params: {
@@ -35,23 +36,17 @@ RSpec.describe 'Tag and wiki history integrity', type: :request do
}
}
.to change(TagVersion, :count).by(2)
.and change(WikiVersion, :count).by(1)
.and change(WikiVersion, :count).by(0)
expect(response).to have_http_status(:ok)
tag.reload
wiki_page.reload
version = wiki_page.wiki_versions.order(:version_no).last
expect(primary_tag_name_for(tag, 'ja').name).to eq('patch_tag_wiki_after')
expect(wiki_page.title).to eq('patch_tag_wiki_after')
expect(version).to have_attributes(
event_type: 'update',
title: 'patch_tag_wiki_after',
body: 'wiki body before',
created_by_user_id: member_user.id
)
expect(wiki_page.wiki_versions.reload.map(&:attributes)).to eq(wiki_history)
end
it 'does not record wiki_version when only category changes' do
@@ -79,9 +74,10 @@ RSpec.describe 'Tag and wiki history integrity', type: :request do
end
describe 'PUT /tags/:id' do
it 'records wiki_version when tag name changes and tag has wiki' do
it 'renames the current Wiki resource without adding body history' do
tag = create_tag!(name: 'put_tag_wiki_before')
wiki_page = create_wiki_for_tag!(tag:, body: 'wiki body before')
wiki_history = wiki_page.wiki_versions.map(&:attributes)
expect {
put "/tags/#{ tag.id }", params: {
@@ -93,23 +89,17 @@ RSpec.describe 'Tag and wiki history integrity', type: :request do
}
}
.to change(TagVersion, :count).by(2)
.and change(WikiVersion, :count).by(1)
.and change(WikiVersion, :count).by(0)
expect(response).to have_http_status(:ok)
tag.reload
wiki_page.reload
version = wiki_page.wiki_versions.order(:version_no).last
expect(primary_tag_name_for(tag, 'ja').name).to eq('put_tag_wiki_after')
expect(wiki_page.title).to eq('put_tag_wiki_after')
expect(version).to have_attributes(
event_type: 'update',
title: 'put_tag_wiki_after',
body: 'wiki body before',
created_by_user_id: member_user.id
)
expect(wiki_page.wiki_versions.reload.map(&:attributes)).to eq(wiki_history)
end
it 'does not record wiki_version when only category changes' do
+22 -35
ファイルの表示
@@ -727,7 +727,7 @@ RSpec.describe 'Tags API', type: :request do
expect(tag.reload.category).to eq('general')
end
it 'PATCH で tag の name を変更すると対応する wiki version を作成する' do
it 'PATCH の名称変更で Wiki の本文履歴を追加しない' do
wiki_page =
Wiki::Commit.create_content!(
tag_name: primary_tag_name_for(tag, 'ja'),
@@ -735,24 +735,20 @@ RSpec.describe 'Tags API', type: :request do
created_by_user: member_user,
message: 'init')
wiki_history = wiki_page.wiki_versions.map(&:attributes)
expect {
patch "/tags/#{ tag.id }", params: {
name: 'patch_wiki_renamed_tag',
}
}
.to change(TagVersion, :count).by(2)
.and change(WikiVersion, :count).by(1)
.and change(WikiVersion, :count).by(0)
expect(response).to have_http_status(:ok)
version = wiki_page.reload.wiki_versions.order(:version_no).last
expect(version).to have_attributes(
event_type: 'update',
title: 'patch_wiki_renamed_tag',
body: 'wiki body before',
created_by_user_id: member_user.id
)
expect(wiki_page.reload.title).to eq('patch_wiki_renamed_tag')
expect(wiki_page.wiki_versions.reload.map(&:attributes)).to eq(wiki_history)
end
it 'tag の category だけを変更しても wiki version は作成しない' do
@@ -1380,7 +1376,7 @@ RSpec.describe 'Tags API', type: :request do
expect(system_tag.category).to eq(old_category)
end
it 'wiki を持つ tag を更新すると wiki version も作成する' do
it 'Wiki を持つ Tag の名称変更で本文履歴を追加しない' do
wiki_page =
Wiki::Commit.create_content!(
tag_name: primary_tag_name_for(tag, 'ja'),
@@ -1395,6 +1391,8 @@ RSpec.describe 'Tags API', type: :request do
message: 'init'
)
wiki_history = wiki_page.wiki_versions.map(&:attributes)
expect {
put "/tags/#{ tag.id }", params: {
name: 'put_wiki_version_tag',
@@ -1405,18 +1403,12 @@ RSpec.describe 'Tags API', type: :request do
}
}
.to change(TagVersion, :count).by(2)
.and change(WikiVersion, :count).by(1)
.and change(WikiVersion, :count).by(0)
expect(response).to have_http_status(:ok)
version = wiki_page.reload.wiki_versions.order(:version_no).last
expect(version).to have_attributes(
event_type: 'update',
title: 'put_wiki_version_tag',
body: 'wiki body before',
created_by_user_id: member_user.id
)
expect(wiki_page.reload.title).to eq('put_wiki_version_tag')
expect(wiki_page.wiki_versions.reload.map(&:attributes)).to eq(wiki_history)
end
it 'wiki を持つ tag を旧 alias へ戻しても wiki を新しい正本名へ移す' do
@@ -1426,6 +1418,7 @@ RSpec.describe 'Tags API', type: :request do
body: 'wiki body before',
created_by_user: member_user,
message: 'init')
wiki_history = wiki_page.wiki_versions.map(&:attributes)
expect {
put "/tags/#{ tag.id }", params: {
@@ -1445,7 +1438,7 @@ RSpec.describe 'Tags API', type: :request do
}
}
.to change(TagVersion, :count).by(3)
.and change(WikiVersion, :count).by(2)
.and change(WikiVersion, :count).by(0)
expect(response).to have_http_status(:ok)
@@ -1457,10 +1450,8 @@ RSpec.describe 'Tags API', type: :request do
expect(TagName.find_by!(language_code: 'ja', name: 'put_wiki_roundtrip_b'))
.to have_attributes(tag_id: tag.id, primary_flg: false)
versions = wiki_page.wiki_versions.order(:version_no).last(2)
expect(versions.map(&:event_type)).to eq(['update', 'update'])
expect(versions.map(&:title)).to eq(['put_wiki_roundtrip_b', 'spec_tag'])
expect(wiki_page.title).to eq('spec_tag')
expect(wiki_page.wiki_versions.reload.map(&:attributes)).to eq(wiki_history)
end
it '別名を他 tag から奪った場合、奪はれた側の tag version も作成する' do
@@ -1570,7 +1561,7 @@ RSpec.describe 'Tags API', type: :request do
expect(TagImplication.where(tag:, parent_tag: child)).not_to exist
end
it 'tag の name を変更すると対応する wiki version を作成する' do
it 'Tag の名称変更で Wiki の本文履歴を追加しない' do
wiki_page =
Wiki::Commit.create_content!(
tag_name: primary_tag_name_for(tag, 'ja'),
@@ -1578,6 +1569,8 @@ RSpec.describe 'Tags API', type: :request do
created_by_user: member_user,
message: 'init')
wiki_history = wiki_page.wiki_versions.map(&:attributes)
expect {
put "/tags/#{ tag.id }", params: {
name: 'put_wiki_renamed_tag',
@@ -1588,18 +1581,12 @@ RSpec.describe 'Tags API', type: :request do
}
}
.to change(TagVersion, :count).by(2)
.and change(WikiVersion, :count).by(1)
.and change(WikiVersion, :count).by(0)
expect(response).to have_http_status(:ok)
version = wiki_page.reload.wiki_versions.order(:version_no).last
expect(version).to have_attributes(
event_type: 'update',
title: 'put_wiki_renamed_tag',
body: 'wiki body before',
created_by_user_id: member_user.id
)
expect(wiki_page.reload.title).to eq('put_wiki_renamed_tag')
expect(wiki_page.wiki_versions.reload.map(&:attributes)).to eq(wiki_history)
end
end
end
+10 -8
ファイルの表示
@@ -21,7 +21,7 @@ RSpec.describe 'Wiki history integrity', type: :request do
expect {
post '/wiki',
params: {
title: 'wiki_history_create_atomic',
title: 'Help:wiki_history_create_atomic',
body: "a\nb\nc",
message: 'initial commit',
},
@@ -37,7 +37,7 @@ RSpec.describe 'Wiki history integrity', type: :request do
revision = page.current_revision
version = page.wiki_versions.order(:version_no).last
expect(page.title).to eq('wiki_history_create_atomic')
expect(page.title).to eq('Help:wiki_history_create_atomic')
expect(page.body).to eq("a\nb\nc")
expect(revision).to be_content
@@ -47,7 +47,7 @@ RSpec.describe 'Wiki history integrity', type: :request do
expect(version).to have_attributes(
version_no: 1,
event_type: 'create',
title: 'wiki_history_create_atomic',
title: 'Help:wiki_history_create_atomic',
body: "a\nb\nc",
reason: 'initial commit',
created_by_user_id: user.id
@@ -58,7 +58,7 @@ RSpec.describe 'Wiki history integrity', type: :request do
expect {
post '/wiki',
params: {
title: 'wiki_history_blank_body',
title: 'Help:wiki_history_blank_body',
body: "\r\n\r\n",
message: 'blank',
},
@@ -67,16 +67,17 @@ RSpec.describe 'Wiki history integrity', type: :request do
.not_to change(WikiPage, :count)
expect(response).to have_http_status(:unprocessable_entity)
expect(WikiPage.joins(:tag_name).where(tag_names: { name: 'wiki_history_blank_body' })).not_to exist
expect(WikiPage.joins(:tag_name)
.where(tag_names: { name: 'Help:wiki_history_blank_body' })).not_to exist
end
it 'returns 422 and creates no partial page when title already exists' do
create_wiki_page(title: 'wiki_history_duplicate_title', body: 'first')
create_wiki_page(title: 'Help:wiki_history_duplicate_title', body: 'first')
expect {
post '/wiki',
params: {
title: 'wiki_history_duplicate_title',
title: 'Help:wiki_history_duplicate_title',
body: 'second',
message: 'duplicate',
},
@@ -85,7 +86,8 @@ RSpec.describe 'Wiki history integrity', type: :request do
.not_to change(WikiPage, :count)
expect(response).to have_http_status(:unprocessable_entity)
expect(WikiPage.joins(:tag_name).where(tag_names: { name: 'wiki_history_duplicate_title' }).count).to eq(1)
expect(WikiPage.joins(:tag_name)
.where(tag_names: { name: 'Help:wiki_history_duplicate_title' }).count).to eq(1)
end
end
+15 -14
ファイルの表示
@@ -11,6 +11,12 @@ RSpec.describe 'Wiki API', type: :request do
let!(:user) { create_member_user! }
let!(:tn) { create(:tag_name, name: 'spec_wiki_title') }
let!(:tag) do
create(:tag,
primary_tag_name: tn,
category: :general,
deprecated_at: Time.zone.local(2026, 6, 1))
end
let!(:page) do
Wiki::Commit.create_content!(
tag_name: tn,
@@ -18,12 +24,6 @@ RSpec.describe 'Wiki API', type: :request do
created_by_user: user,
message: 'init')
end
let!(:tag) do
create(:tag,
primary_tag_name: tn,
category: :general,
deprecated_at: Time.zone.local(2026, 6, 1))
end
describe 'GET /wiki' do
it 'returns wiki pages with title' do
@@ -111,7 +111,7 @@ RSpec.describe 'Wiki API', type: :request do
context 'when success' do
it 'creates wiki_page and first content revision' do
expect do
post endpoint, params: { title: 'TestPage', body: "a\nb\nc", message: 'init' },
post endpoint, params: { title: 'Help:TestPage', body: "a\nb\nc", message: 'init' },
headers: auth_headers(member)
end
.to change(WikiPage, :count).by(1)
@@ -121,7 +121,7 @@ RSpec.describe 'Wiki API', type: :request do
expect(response).to have_http_status(:created)
page_id = json.fetch('id')
expect(json.fetch('title')).to eq('TestPage')
expect(json.fetch('title')).to eq('Help:TestPage')
created_page = WikiPage.find(page_id)
version = created_page.wiki_versions.order(:version_no).last
@@ -129,7 +129,7 @@ RSpec.describe 'Wiki API', type: :request do
expect(version).to have_attributes(
version_no: 1,
event_type: 'create',
title: 'TestPage',
title: 'Help:TestPage',
body: "a\nb\nc",
created_by_user_id: member.id
)
@@ -151,7 +151,7 @@ RSpec.describe 'Wiki API', type: :request do
WikiLine.create!(sha256: Digest::SHA256.hexdigest('a'), body: 'a', created_at: Time.current, updated_at: Time.current)
post endpoint,
params: { title: 'Reuse', body: "a\na" },
params: { title: 'Help:Reuse', body: "a\na" },
headers: auth_headers(member)
page = WikiPage.find(JSON.parse(response.body).fetch('id'))
@@ -166,7 +166,7 @@ RSpec.describe 'Wiki API', type: :request do
duplicated = 'duplicated_line_for_wiki_line_upsert_spec'
post endpoint,
params: { title: 'DuplicateNewLine', body: "#{ duplicated }\n#{ duplicated }" },
params: { title: 'Help:DuplicateNewLine', body: "#{ duplicated }\n#{ duplicated }" },
headers: auth_headers(member)
expect(response).to have_http_status(:created)
@@ -182,7 +182,8 @@ RSpec.describe 'Wiki API', type: :request do
it 'normalises CRLF and strips trailing newlines' do
post endpoint,
params: { title: 'NormalisedBody', body: "a\r\nb\r\n\r\n", message: 'normalise' },
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)
@@ -413,10 +414,10 @@ RSpec.describe 'Wiki API', type: :request do
top = json.first
expect(top).to include(
'revision_id' => rev2.id,
'pred' => rev2.base_revision_id,
'pred' => rev1.id,
'succ' => nil,
'kind' => 'content',
'message' => 'r2'
'message' => nil
)
expect(top['wiki_page']).to include(
'id' => page.id,
+2 -2
ファイルの表示
@@ -44,12 +44,12 @@ RSpec.describe 'Wiki title collision', type: :request do
end
it 'returns 422 when creating wiki with existing title' do
create_wiki_page(title: 'wiki_collision_create', body: 'already exists')
create_wiki_page(title: 'Help:wiki_collision_create', body: 'already exists')
expect {
post '/wiki',
params: {
title: 'wiki_collision_create',
title: 'Help:wiki_collision_create',
body: 'new body',
message: 'duplicate create',
},
+115
ファイルの表示
@@ -0,0 +1,115 @@
require 'rails_helper'
RSpec.describe 'Unmigrated Wiki compatibility', type: :request do
let!(:user) { create_member_user! }
let!(:tag_name) { create(:tag_name, name: 'Help_contract') }
let!(:page) do
Wiki::Commit.create_content!(tag_name:, body: 'before', created_by_user: user)
end
let!(:first_revision) { page.current_revision }
let!(:last_revision) do
Wiki::Commit.content!(page:, body: 'after', created_user: user,
message: 'legacy edit', base_revision_id: first_revision.id)
end
before { expect(TagDescription.exists?(id: page.id)).to be(false) }
it 'keeps a Tag-linked legacy page in the legacy domain when its title changes' do
create(:tag, primary_tag_name: tag_name)
expect do
put "/wiki/#{ page.id }",
params: { title: 'legacy_tag_renamed', body: 'changed legacy body',
message: 'legacy rename', base_revision_id: last_revision.id },
headers: { 'X-Transfer-Code' => user.inheritance_code }
end.to change(WikiRevision, :count).by(1)
.and change(WikiVersion, :count).by(1)
.and change(TagDescription, :count).by(0)
.and change(TagDescriptionVersion, :count).by(0)
expect(response).to have_http_status(:ok)
expect(page.reload).to have_attributes(body: 'changed legacy body')
expect(page.title).to eq('legacy_tag_renamed')
expect(page.current_revision).to have_attributes(message: 'legacy rename')
end
it 'shows legacy current and historical content by ID' do
get "/wiki/#{ page.id }"
expect(response).to have_http_status(:ok)
expect(json).to include('body' => 'after', 'revision_id' => last_revision.id,
'pred' => first_revision.id, 'succ' => nil)
get "/wiki/#{ page.id }", params: { version: first_revision.id }
expect(response).to have_http_status(:ok)
expect(json).to include('body' => 'before', 'revision_id' => first_revision.id,
'pred' => nil, 'succ' => last_revision.id)
end
it 'shows legacy current and historical content by title' do
get "/wiki/title/#{ tag_name.name }"
expect(response).to have_http_status(:ok)
expect(json).to include('body' => 'after', 'revision_id' => last_revision.id)
get "/wiki/title/#{ tag_name.name }", params: { version: first_revision.id }
expect(response).to have_http_status(:ok)
expect(json).to include('body' => 'before', 'revision_id' => first_revision.id)
end
it 'recognises legacy IDs' do
get "/wiki/#{ page.id }/exists"
expect(response).to have_http_status(:no_content)
end
it 'recognises legacy titles' do
get "/wiki/title/#{ tag_name.name }/exists"
expect(response).to have_http_status(:no_content)
end
it 'diffs legacy revisions with explicit and current target' do
[last_revision.id, nil].each do |to|
get "/wiki/#{ page.id }/diff", params: { from: first_revision.id, to: }
expect(response).to have_http_status(:ok)
expect(json).to include(
'wiki_page_id' => page.id, 'title' => tag_name.name,
'older_revision_id' => first_revision.id, 'newer_revision_id' => last_revision.id,
'diff' => [{ 'type' => 'removed', 'content' => 'before' },
{ 'type' => 'added', 'content' => 'after' }])
end
end
describe 'revision resource scope' do
let!(:other_page) do
Wiki::Commit.create_content!(
tag_name: create(:tag_name, name: 'Help_other_contract'),
body: 'other page history', created_by_user: user)
end
let(:other_revision) { other_page.current_revision }
it 'returns 404 when show specifies another page revision' do
get "/wiki/#{ page.id }", params: { version: other_revision.id }
expect(response).to have_http_status(:not_found)
end
it 'returns 404 when diff from belongs to another page' do
get "/wiki/#{ page.id }/diff",
params: { from: other_revision.id, to: last_revision.id }
expect(response).to have_http_status(:not_found)
end
it 'returns 404 when diff to belongs to another page' do
get "/wiki/#{ page.id }/diff",
params: { from: first_revision.id, to: other_revision.id }
expect(response).to have_http_status(:not_found)
end
end
it 'retains legacy history metadata and ordering' do
get '/wiki/changes', params: { id: page.id }
expect(response).to have_http_status(:ok)
expect(json.map { |row| row.fetch('revision_id') }).to eq(
[last_revision.id, first_revision.id])
expect(json.first).to include(
'pred' => first_revision.id, 'succ' => nil, 'kind' => 'content',
'message' => 'legacy edit', 'timestamp' => last_revision.created_at.iso8601(3),
'wiki_page' => { 'id' => page.id, 'title' => tag_name.name, 'deprecated_at' => nil },
'user' => { 'id' => user.id, 'name' => user.name })
end
end