97 行
4.0 KiB
Ruby
97 行
4.0 KiB
Ruby
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 '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
|