このコミットが含まれているのは:
@@ -2,6 +2,7 @@ require 'cgi'
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Wiki history integrity', type: :request do
|
||||
include WikiRecords
|
||||
let!(:user) { create_member_user! }
|
||||
|
||||
def auth_headers user
|
||||
@@ -9,7 +10,7 @@ RSpec.describe 'Wiki history integrity', type: :request do
|
||||
end
|
||||
|
||||
def create_wiki_page title:, body: 'body', message: 'init', user: self.user
|
||||
Wiki::Commit.create_content!(
|
||||
seed_wiki_page(
|
||||
tag_name: create(:tag_name, name: title),
|
||||
body:,
|
||||
created_by_user: user,
|
||||
@@ -17,41 +18,14 @@ RSpec.describe 'Wiki history integrity', type: :request do
|
||||
end
|
||||
|
||||
describe 'POST /wiki' do
|
||||
it 'creates wiki_page, wiki_revision, and wiki_version atomically' do
|
||||
expect {
|
||||
post '/wiki',
|
||||
params: {
|
||||
title: 'Help:wiki_history_create_atomic',
|
||||
body: "a\nb\nc",
|
||||
message: 'initial commit',
|
||||
},
|
||||
it 'rejects frozen creation without partial page or history' do
|
||||
expect do
|
||||
post '/wiki', params: { title: 'Help:wiki_history_create_atomic', body: 'initial' },
|
||||
headers: auth_headers(user)
|
||||
}
|
||||
.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 = WikiPage.find(json.fetch('id'))
|
||||
revision = page.current_revision
|
||||
version = page.wiki_versions.order(:version_no).last
|
||||
|
||||
expect(page.title).to eq('Help:wiki_history_create_atomic')
|
||||
expect(page.body).to eq("a\nb\nc")
|
||||
|
||||
expect(revision).to be_content
|
||||
expect(revision.message).to eq('initial commit')
|
||||
expect(revision.lines_count).to eq(3)
|
||||
|
||||
expect(version).to have_attributes(
|
||||
version_no: 1,
|
||||
event_type: 'create',
|
||||
title: 'Help:wiki_history_create_atomic',
|
||||
body: "a\nb\nc",
|
||||
reason: 'initial commit',
|
||||
created_by_user_id: user.id
|
||||
)
|
||||
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
|
||||
|
||||
it 'returns 422 and creates nothing when normalised body is blank' do
|
||||
@@ -71,21 +45,19 @@ RSpec.describe 'Wiki history integrity', type: :request do
|
||||
.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
|
||||
it 'rejects frozen creation without modifying an existing page or history' do
|
||||
create_wiki_page(title: 'Help:wiki_history_duplicate_title', body: 'first')
|
||||
|
||||
expect {
|
||||
expect do
|
||||
post '/wiki',
|
||||
params: {
|
||||
title: 'Help:wiki_history_duplicate_title',
|
||||
body: 'second',
|
||||
message: 'duplicate',
|
||||
},
|
||||
params: { title: 'Help:wiki_history_duplicate_title',
|
||||
body: 'second', message: 'duplicate' },
|
||||
headers: auth_headers(user)
|
||||
}
|
||||
.not_to change(WikiPage, :count)
|
||||
end.to change(WikiPage, :count).by(0)
|
||||
.and change(WikiRevision, :count).by(0)
|
||||
.and change(WikiVersion, :count).by(0)
|
||||
|
||||
expect(response).to have_http_status(:unprocessable_entity)
|
||||
expect(response.status).to be_between(400, 499)
|
||||
expect(WikiPage.joins(:tag_name)
|
||||
.where(tag_names: { name: 'Help:wiki_history_duplicate_title' }).count).to eq(1)
|
||||
end
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする