2017-09-06 18:21:52 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
# For every API endpoint we test 3 states of wikis:
|
|
|
|
# - disabled
|
|
|
|
# - enabled only for team members
|
|
|
|
# - enabled for everyone who has access
|
|
|
|
# Every state is tested for 3 user roles:
|
|
|
|
# - guest
|
|
|
|
# - developer
|
2018-07-11 10:36:08 -04:00
|
|
|
# - maintainer
|
2017-09-06 18:21:52 -04:00
|
|
|
# because they are 3 edge cases of using wiki pages.
|
|
|
|
|
|
|
|
describe API::Wikis do
|
|
|
|
let(:user) { create(:user) }
|
2018-01-03 00:22:01 -05:00
|
|
|
let(:group) { create(:group).tap { |g| g.add_owner(user) } }
|
|
|
|
let(:project_wiki) { create(:project_wiki, project: project, user: user) }
|
2017-09-06 18:21:52 -04:00
|
|
|
let(:payload) { { content: 'content', format: 'rdoc', title: 'title' } }
|
|
|
|
let(:expected_keys_with_content) { %w(content format slug title) }
|
|
|
|
let(:expected_keys_without_content) { %w(format slug title) }
|
|
|
|
|
|
|
|
shared_examples_for 'returns list of wiki pages' do
|
|
|
|
context 'when wiki has pages' do
|
|
|
|
let!(:pages) do
|
2018-01-03 00:22:01 -05:00
|
|
|
[create(:wiki_page, wiki: project_wiki, attrs: { title: 'page1', content: 'content of page1' }),
|
|
|
|
create(:wiki_page, wiki: project_wiki, attrs: { title: 'page2', content: 'content of page2' })]
|
2017-09-06 18:21:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the list of wiki pages without content' do
|
|
|
|
get api(url, user)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-09-06 18:21:52 -04:00
|
|
|
expect(json_response.size).to eq(2)
|
|
|
|
|
|
|
|
json_response.each_with_index do |page, index|
|
|
|
|
expect(page.keys).to match_array(expected_keys_without_content)
|
|
|
|
expect(page['slug']).to eq(pages[index].slug)
|
|
|
|
expect(page['title']).to eq(pages[index].title)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the list of wiki pages with content' do
|
|
|
|
get api(url, user), with_content: 1
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-09-06 18:21:52 -04:00
|
|
|
expect(json_response.size).to eq(2)
|
|
|
|
|
|
|
|
json_response.each_with_index do |page, index|
|
|
|
|
expect(page.keys).to match_array(expected_keys_with_content)
|
|
|
|
expect(page['content']).to eq(pages[index].content)
|
|
|
|
expect(page['slug']).to eq(pages[index].slug)
|
|
|
|
expect(page['title']).to eq(pages[index].title)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'return the empty list of wiki pages' do
|
|
|
|
get api(url, user)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-09-06 18:21:52 -04:00
|
|
|
expect(json_response.size).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'returns wiki page' do
|
|
|
|
it 'returns the wiki page' do
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-09-06 18:21:52 -04:00
|
|
|
expect(json_response.size).to eq(4)
|
|
|
|
expect(json_response.keys).to match_array(expected_keys_with_content)
|
|
|
|
expect(json_response['content']).to eq(page.content)
|
|
|
|
expect(json_response['slug']).to eq(page.slug)
|
|
|
|
expect(json_response['title']).to eq(page.title)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'creates wiki page' do
|
|
|
|
it 'creates the wiki page' do
|
|
|
|
post(api(url, user), payload)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(201)
|
2017-09-06 18:21:52 -04:00
|
|
|
expect(json_response.size).to eq(4)
|
|
|
|
expect(json_response.keys).to match_array(expected_keys_with_content)
|
|
|
|
expect(json_response['content']).to eq(payload[:content])
|
|
|
|
expect(json_response['slug']).to eq(payload[:title].tr(' ', '-'))
|
|
|
|
expect(json_response['title']).to eq(payload[:title])
|
|
|
|
expect(json_response['rdoc']).to eq(payload[:rdoc])
|
|
|
|
end
|
|
|
|
|
|
|
|
[:title, :content].each do |part|
|
|
|
|
it "responds with validation error on empty #{part}" do
|
|
|
|
payload.delete(part)
|
|
|
|
|
|
|
|
post(api(url, user), payload)
|
|
|
|
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(400)
|
2017-09-06 18:21:52 -04:00
|
|
|
expect(json_response.size).to eq(1)
|
|
|
|
expect(json_response['error']).to eq("#{part} is missing")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for 'updates wiki page' do
|
|
|
|
it 'updates the wiki page' do
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(200)
|
2017-09-06 18:21:52 -04:00
|
|
|
expect(json_response.size).to eq(4)
|
|
|
|
expect(json_response.keys).to match_array(expected_keys_with_content)
|
|
|
|
expect(json_response['content']).to eq(payload[:content])
|
|
|
|
expect(json_response['slug']).to eq(payload[:title].tr(' ', '-'))
|
|
|
|
expect(json_response['title']).to eq(payload[:title])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for '403 Forbidden' do
|
|
|
|
it 'returns 403 Forbidden' do
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(403)
|
2017-09-06 18:21:52 -04:00
|
|
|
expect(json_response.size).to eq(1)
|
|
|
|
expect(json_response['message']).to eq('403 Forbidden')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for '404 Wiki Page Not Found' do
|
|
|
|
it 'returns 404 Wiki Page Not Found' do
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-09-06 18:21:52 -04:00
|
|
|
expect(json_response.size).to eq(1)
|
|
|
|
expect(json_response['message']).to eq('404 Wiki Page Not Found')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for '404 Project Not Found' do
|
|
|
|
it 'returns 404 Project Not Found' do
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(404)
|
2017-09-06 18:21:52 -04:00
|
|
|
expect(json_response.size).to eq(1)
|
|
|
|
expect(json_response['message']).to eq('404 Project Not Found')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples_for '204 No Content' do
|
|
|
|
it 'returns 204 No Content' do
|
2017-10-19 14:28:19 -04:00
|
|
|
expect(response).to have_gitlab_http_status(204)
|
2017-09-06 18:21:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /projects/:id/wikis' do
|
|
|
|
let(:url) { "/projects/#{project.id}/wikis" }
|
|
|
|
|
|
|
|
context 'when wiki is disabled' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_repo, :wiki_disabled) }
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
context 'when user is guest' do
|
|
|
|
before do
|
|
|
|
get api(url)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '404 Project Not Found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
|
|
|
|
get api(url, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '403 Forbidden'
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer' do
|
2017-09-06 18:21:52 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
get api(url, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '403 Forbidden'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when wiki is available only for team members' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_repo, :wiki_private) }
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
context 'when user is guest' do
|
|
|
|
before do
|
|
|
|
get api(url)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '404 Project Not Found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'returns list of wiki pages'
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer' do
|
2017-09-06 18:21:52 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-06 18:21:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'returns list of wiki pages'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when wiki is available for everyone with access' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_repo) }
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
context 'when user is guest' do
|
|
|
|
before do
|
|
|
|
get api(url)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '404 Project Not Found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'returns list of wiki pages'
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer' do
|
2017-09-06 18:21:52 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-06 18:21:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'returns list of wiki pages'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET /projects/:id/wikis/:slug' do
|
|
|
|
let(:page) { create(:wiki_page, wiki: project.wiki) }
|
|
|
|
let(:url) { "/projects/#{project.id}/wikis/#{page.slug}" }
|
|
|
|
|
|
|
|
context 'when wiki is disabled' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_repo, :wiki_disabled) }
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
context 'when user is guest' do
|
|
|
|
before do
|
|
|
|
get api(url)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '404 Project Not Found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
|
|
|
|
get api(url, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '403 Forbidden'
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer' do
|
2017-09-06 18:21:52 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
get api(url, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '403 Forbidden'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when wiki is available only for team members' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_repo, :wiki_private) }
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
context 'when user is guest' do
|
|
|
|
before do
|
|
|
|
get api(url)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '404 Project Not Found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
get api(url, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'returns wiki page'
|
|
|
|
|
|
|
|
context 'when page is not existing' do
|
|
|
|
let(:url) { "/projects/#{project.id}/wikis/unknown" }
|
|
|
|
|
|
|
|
include_examples '404 Wiki Page Not Found'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer' do
|
2017-09-06 18:21:52 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
get api(url, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'returns wiki page'
|
|
|
|
|
|
|
|
context 'when page is not existing' do
|
|
|
|
let(:url) { "/projects/#{project.id}/wikis/unknown" }
|
|
|
|
|
|
|
|
include_examples '404 Wiki Page Not Found'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when wiki is available for everyone with access' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_repo) }
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
context 'when user is guest' do
|
|
|
|
before do
|
|
|
|
get api(url)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '404 Project Not Found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
|
|
|
|
get api(url, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'returns wiki page'
|
|
|
|
|
|
|
|
context 'when page is not existing' do
|
|
|
|
let(:url) { "/projects/#{project.id}/wikis/unknown" }
|
|
|
|
|
|
|
|
include_examples '404 Wiki Page Not Found'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer' do
|
2017-09-06 18:21:52 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
get api(url, user)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'returns wiki page'
|
|
|
|
|
|
|
|
context 'when page is not existing' do
|
|
|
|
let(:url) { "/projects/#{project.id}/wikis/unknown" }
|
|
|
|
|
|
|
|
include_examples '404 Wiki Page Not Found'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'POST /projects/:id/wikis' do
|
|
|
|
let(:payload) { { title: 'title', content: 'content' } }
|
|
|
|
let(:url) { "/projects/#{project.id}/wikis" }
|
|
|
|
|
|
|
|
context 'when wiki is disabled' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_disabled, :wiki_repo) }
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
context 'when user is guest' do
|
|
|
|
before do
|
|
|
|
post(api(url), payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '404 Project Not Found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
post(api(url, user), payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '403 Forbidden'
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer' do
|
2017-09-06 18:21:52 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-06 18:21:52 -04:00
|
|
|
post(api(url, user), payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '403 Forbidden'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when wiki is available only for team members' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_private, :wiki_repo) }
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
context 'when user is guest' do
|
|
|
|
before do
|
|
|
|
post(api(url), payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '404 Project Not Found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'creates wiki page'
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer' do
|
2017-09-06 18:21:52 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-06 18:21:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'creates wiki page'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when wiki is available for everyone with access' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_repo) }
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
context 'when user is guest' do
|
|
|
|
before do
|
|
|
|
post(api(url), payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '404 Project Not Found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'creates wiki page'
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer' do
|
2017-09-06 18:21:52 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-06 18:21:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'creates wiki page'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'PUT /projects/:id/wikis/:slug' do
|
2018-01-03 00:22:01 -05:00
|
|
|
let(:page) { create(:wiki_page, wiki: project_wiki) }
|
2017-09-06 18:21:52 -04:00
|
|
|
let(:payload) { { title: 'new title', content: 'new content' } }
|
|
|
|
let(:url) { "/projects/#{project.id}/wikis/#{page.slug}" }
|
|
|
|
|
|
|
|
context 'when wiki is disabled' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_disabled, :wiki_repo) }
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
context 'when user is guest' do
|
|
|
|
before do
|
|
|
|
put(api(url), payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '404 Project Not Found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
|
|
|
|
put(api(url, user), payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '403 Forbidden'
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer' do
|
2017-09-06 18:21:52 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
put(api(url, user), payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '403 Forbidden'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when wiki is available only for team members' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_private, :wiki_repo) }
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
context 'when user is guest' do
|
|
|
|
before do
|
|
|
|
put(api(url), payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '404 Project Not Found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
|
|
|
|
put(api(url, user), payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'updates wiki page'
|
|
|
|
|
|
|
|
context 'when page is not existing' do
|
|
|
|
let(:url) { "/projects/#{project.id}/wikis/unknown" }
|
|
|
|
|
|
|
|
include_examples '404 Wiki Page Not Found'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer' do
|
2017-09-06 18:21:52 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
put(api(url, user), payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'updates wiki page'
|
|
|
|
|
|
|
|
context 'when page is not existing' do
|
|
|
|
let(:url) { "/projects/#{project.id}/wikis/unknown" }
|
|
|
|
|
|
|
|
include_examples '404 Wiki Page Not Found'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when wiki is available for everyone with access' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_repo) }
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
context 'when user is guest' do
|
|
|
|
before do
|
|
|
|
put(api(url), payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '404 Project Not Found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
|
|
|
|
put(api(url, user), payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'updates wiki page'
|
|
|
|
|
|
|
|
context 'when page is not existing' do
|
|
|
|
let(:url) { "/projects/#{project.id}/wikis/unknown" }
|
|
|
|
|
|
|
|
include_examples '404 Wiki Page Not Found'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer' do
|
2017-09-06 18:21:52 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
put(api(url, user), payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'updates wiki page'
|
|
|
|
|
|
|
|
context 'when page is not existing' do
|
|
|
|
let(:url) { "/projects/#{project.id}/wikis/unknown" }
|
|
|
|
|
|
|
|
include_examples '404 Wiki Page Not Found'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-01-03 00:22:01 -05:00
|
|
|
|
|
|
|
context 'when wiki belongs to a group project' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_repo, namespace: group) }
|
2018-01-03 00:22:01 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
put(api(url, user), payload)
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'updates wiki page'
|
|
|
|
end
|
2017-09-06 18:21:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'DELETE /projects/:id/wikis/:slug' do
|
2018-01-03 00:22:01 -05:00
|
|
|
let(:page) { create(:wiki_page, wiki: project_wiki) }
|
2017-09-06 18:21:52 -04:00
|
|
|
let(:url) { "/projects/#{project.id}/wikis/#{page.slug}" }
|
|
|
|
|
|
|
|
context 'when wiki is disabled' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_disabled, :wiki_repo) }
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
context 'when user is guest' do
|
|
|
|
before do
|
|
|
|
delete(api(url))
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '404 Project Not Found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
|
|
|
|
delete(api(url, user))
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '403 Forbidden'
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer' do
|
2017-09-06 18:21:52 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
delete(api(url, user))
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '403 Forbidden'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when wiki is available only for team members' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_private, :wiki_repo) }
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
context 'when user is guest' do
|
|
|
|
before do
|
|
|
|
delete(api(url))
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '404 Project Not Found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
|
|
|
|
delete(api(url, user))
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '403 Forbidden'
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer' do
|
2017-09-06 18:21:52 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
delete(api(url, user))
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '204 No Content'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when wiki is available for everyone with access' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_repo) }
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
context 'when user is guest' do
|
|
|
|
before do
|
|
|
|
delete(api(url))
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '404 Project Not Found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is developer' do
|
|
|
|
before do
|
|
|
|
project.add_developer(user)
|
|
|
|
|
|
|
|
delete(api(url, user))
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '403 Forbidden'
|
|
|
|
end
|
|
|
|
|
2018-07-11 10:36:08 -04:00
|
|
|
context 'when user is maintainer' do
|
2017-09-06 18:21:52 -04:00
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
project.add_maintainer(user)
|
2017-09-06 18:21:52 -04:00
|
|
|
|
|
|
|
delete(api(url, user))
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '204 No Content'
|
|
|
|
|
|
|
|
context 'when page is not existing' do
|
|
|
|
let(:url) { "/projects/#{project.id}/wikis/unknown" }
|
|
|
|
|
|
|
|
include_examples '404 Wiki Page Not Found'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-01-03 00:22:01 -05:00
|
|
|
|
|
|
|
context 'when wiki belongs to a group project' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project, :wiki_repo, namespace: group) }
|
2018-01-03 00:22:01 -05:00
|
|
|
|
|
|
|
before do
|
|
|
|
delete(api(url, user))
|
|
|
|
end
|
|
|
|
|
|
|
|
include_examples '204 No Content'
|
|
|
|
end
|
2017-09-06 18:21:52 -04:00
|
|
|
end
|
|
|
|
end
|