Removing gitaly flags
This commit is contained in:
parent
683984f2e3
commit
d40912bb49
5 changed files with 493 additions and 455 deletions
|
@ -25,9 +25,8 @@ module Gitlab
|
|||
@repository.exists?
|
||||
end
|
||||
|
||||
# Disabled because of https://gitlab.com/gitlab-org/gitaly/merge_requests/539
|
||||
def write_page(name, format, content, commit_details)
|
||||
@repository.gitaly_migrate(:wiki_write_page, status: Gitlab::GitalyClient::MigrationStatus::DISABLED) do |is_enabled|
|
||||
@repository.gitaly_migrate(:wiki_write_page) do |is_enabled|
|
||||
if is_enabled
|
||||
gitaly_write_page(name, format, content, commit_details)
|
||||
gollum_wiki.clear_cache
|
||||
|
@ -48,9 +47,8 @@ module Gitlab
|
|||
end
|
||||
end
|
||||
|
||||
# Disable because of https://gitlab.com/gitlab-org/gitlab-ce/issues/42094
|
||||
def update_page(page_path, title, format, content, commit_details)
|
||||
@repository.gitaly_migrate(:wiki_update_page, status: Gitlab::GitalyClient::MigrationStatus::DISABLED) do |is_enabled|
|
||||
@repository.gitaly_migrate(:wiki_update_page) do |is_enabled|
|
||||
if is_enabled
|
||||
gitaly_update_page(page_path, title, format, content, commit_details)
|
||||
gollum_wiki.clear_cache
|
||||
|
|
|
@ -1,226 +1,234 @@
|
|||
require 'spec_helper'
|
||||
|
||||
# Remove skip_gitaly_mock flag when gitaly_update_page implements moving pages
|
||||
describe 'User updates wiki page', :skip_gitaly_mock do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
before do
|
||||
project.add_master(user)
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
context 'when wiki is empty' do
|
||||
describe 'User updates wiki page' do
|
||||
shared_examples 'wiki page user update' do
|
||||
let(:user) { create(:user) }
|
||||
before do
|
||||
visit(project_wikis_path(project))
|
||||
project.add_master(user)
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
context 'in a user namespace' do
|
||||
let(:project) { create(:project, namespace: user.namespace) }
|
||||
|
||||
it 'redirects back to the home edit page' do
|
||||
page.within(:css, '.wiki-form .form-actions') do
|
||||
click_on('Cancel')
|
||||
end
|
||||
|
||||
expect(current_path).to eq project_wiki_path(project, :home)
|
||||
context 'when wiki is empty' do
|
||||
before do
|
||||
visit(project_wikis_path(project))
|
||||
end
|
||||
|
||||
it 'updates a page that has a path', :js do
|
||||
click_on('New page')
|
||||
context 'in a user namespace' do
|
||||
let(:project) { create(:project, namespace: user.namespace) }
|
||||
|
||||
page.within('#modal-new-wiki') do
|
||||
fill_in(:new_wiki_path, with: 'one/two/three-test')
|
||||
click_on('Create page')
|
||||
it 'redirects back to the home edit page' do
|
||||
page.within(:css, '.wiki-form .form-actions') do
|
||||
click_on('Cancel')
|
||||
end
|
||||
|
||||
expect(current_path).to eq project_wiki_path(project, :home)
|
||||
end
|
||||
|
||||
page.within '.wiki-form' do
|
||||
fill_in(:wiki_content, with: 'wiki content')
|
||||
click_on('Create page')
|
||||
it 'updates a page that has a path', :js do
|
||||
click_on('New page')
|
||||
|
||||
page.within('#modal-new-wiki') do
|
||||
fill_in(:new_wiki_path, with: 'one/two/three-test')
|
||||
click_on('Create page')
|
||||
end
|
||||
|
||||
page.within '.wiki-form' do
|
||||
fill_in(:wiki_content, with: 'wiki content')
|
||||
click_on('Create page')
|
||||
end
|
||||
|
||||
expect(current_path).to include('one/two/three-test')
|
||||
expect(find('.wiki-pages')).to have_content('Three')
|
||||
|
||||
first(:link, text: 'Three').click
|
||||
|
||||
expect(find('.nav-text')).to have_content('Three')
|
||||
|
||||
click_on('Edit')
|
||||
|
||||
expect(current_path).to include('one/two/three-test')
|
||||
expect(page).to have_content('Edit Page')
|
||||
|
||||
fill_in('Content', with: 'Updated Wiki Content')
|
||||
click_on('Save changes')
|
||||
|
||||
expect(page).to have_content('Updated Wiki Content')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when wiki is not empty' do
|
||||
let(:project_wiki) { create(:project_wiki, project: project, user: project.creator) }
|
||||
let!(:wiki_page) { create(:wiki_page, wiki: project_wiki, attrs: { title: 'home', content: 'Home page' }) }
|
||||
|
||||
before do
|
||||
visit(project_wikis_path(project))
|
||||
end
|
||||
|
||||
context 'in a user namespace' do
|
||||
let(:project) { create(:project, namespace: user.namespace) }
|
||||
|
||||
it 'updates a page' do
|
||||
click_link('Edit')
|
||||
|
||||
# Commit message field should have correct value.
|
||||
expect(page).to have_field('wiki[message]', with: 'Update home')
|
||||
|
||||
fill_in(:wiki_content, with: 'My awesome wiki!')
|
||||
click_button('Save changes')
|
||||
|
||||
expect(page).to have_content('Home')
|
||||
expect(page).to have_content("Last edited by #{user.name}")
|
||||
expect(page).to have_content('My awesome wiki!')
|
||||
end
|
||||
|
||||
expect(current_path).to include('one/two/three-test')
|
||||
expect(find('.wiki-pages')).to have_content('Three')
|
||||
it 'shows a validation error message' do
|
||||
click_link('Edit')
|
||||
|
||||
first(:link, text: 'Three').click
|
||||
fill_in(:wiki_content, with: '')
|
||||
click_button('Save changes')
|
||||
|
||||
expect(find('.nav-text')).to have_content('Three')
|
||||
expect(page).to have_selector('.wiki-form')
|
||||
expect(page).to have_content('Edit Page')
|
||||
expect(page).to have_content('The form contains the following error:')
|
||||
expect(page).to have_content("Content can't be blank")
|
||||
expect(find('textarea#wiki_content').value).to eq('')
|
||||
end
|
||||
|
||||
click_on('Edit')
|
||||
it 'shows the autocompletion dropdown', :js do
|
||||
click_link('Edit')
|
||||
|
||||
expect(current_path).to include('one/two/three-test')
|
||||
expect(page).to have_content('Edit Page')
|
||||
find('#wiki_content').native.send_keys('')
|
||||
fill_in(:wiki_content, with: '@')
|
||||
|
||||
fill_in('Content', with: 'Updated Wiki Content')
|
||||
click_on('Save changes')
|
||||
expect(page).to have_selector('.atwho-view')
|
||||
end
|
||||
|
||||
expect(page).to have_content('Updated Wiki Content')
|
||||
it 'shows the error message' do
|
||||
click_link('Edit')
|
||||
|
||||
wiki_page.update(content: 'Update')
|
||||
|
||||
click_button('Save changes')
|
||||
|
||||
expect(page).to have_content('Someone edited the page the same time you did.')
|
||||
end
|
||||
|
||||
it 'updates a page' do
|
||||
click_on('Edit')
|
||||
fill_in('Content', with: 'Updated Wiki Content')
|
||||
click_on('Save changes')
|
||||
|
||||
expect(page).to have_content('Updated Wiki Content')
|
||||
end
|
||||
|
||||
it 'cancels edititng of a page' do
|
||||
click_on('Edit')
|
||||
|
||||
page.within(:css, '.wiki-form .form-actions') do
|
||||
click_on('Cancel')
|
||||
end
|
||||
|
||||
expect(current_path).to eq(project_wiki_path(project, wiki_page))
|
||||
end
|
||||
end
|
||||
|
||||
context 'in a group namespace' do
|
||||
let(:project) { create(:project, namespace: create(:group, :public)) }
|
||||
|
||||
it 'updates a page' do
|
||||
click_link('Edit')
|
||||
|
||||
# Commit message field should have correct value.
|
||||
expect(page).to have_field('wiki[message]', with: 'Update home')
|
||||
|
||||
fill_in(:wiki_content, with: 'My awesome wiki!')
|
||||
|
||||
click_button('Save changes')
|
||||
|
||||
expect(page).to have_content('Home')
|
||||
expect(page).to have_content("Last edited by #{user.name}")
|
||||
expect(page).to have_content('My awesome wiki!')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the page is in a subdir' do
|
||||
let!(:project) { create(:project, namespace: user.namespace) }
|
||||
let(:project_wiki) { create(:project_wiki, project: project, user: project.creator) }
|
||||
let(:page_name) { 'page_name' }
|
||||
let(:page_dir) { "foo/bar/#{page_name}" }
|
||||
let!(:wiki_page) { create(:wiki_page, wiki: project_wiki, attrs: { title: page_dir, content: 'Home page' }) }
|
||||
|
||||
before do
|
||||
visit(project_wiki_edit_path(project, wiki_page))
|
||||
end
|
||||
|
||||
it 'moves the page to the root folder', :skip_gitaly_mock do
|
||||
fill_in(:wiki_title, with: "/#{page_name}")
|
||||
|
||||
click_button('Save changes')
|
||||
|
||||
expect(current_path).to eq(project_wiki_path(project, page_name))
|
||||
end
|
||||
|
||||
it 'moves the page to other dir' do
|
||||
new_page_dir = "foo1/bar1/#{page_name}"
|
||||
|
||||
fill_in(:wiki_title, with: new_page_dir)
|
||||
|
||||
click_button('Save changes')
|
||||
|
||||
expect(current_path).to eq(project_wiki_path(project, new_page_dir))
|
||||
end
|
||||
|
||||
it 'remains in the same place if title has not changed' do
|
||||
original_path = project_wiki_path(project, wiki_page)
|
||||
|
||||
fill_in(:wiki_title, with: page_name)
|
||||
|
||||
click_button('Save changes')
|
||||
|
||||
expect(current_path).to eq(original_path)
|
||||
end
|
||||
|
||||
it 'can be moved to a different dir with a different name' do
|
||||
new_page_dir = "foo1/bar1/new_page_name"
|
||||
|
||||
fill_in(:wiki_title, with: new_page_dir)
|
||||
|
||||
click_button('Save changes')
|
||||
|
||||
expect(current_path).to eq(project_wiki_path(project, new_page_dir))
|
||||
end
|
||||
|
||||
it 'can be renamed and moved to the root folder' do
|
||||
new_name = 'new_page_name'
|
||||
|
||||
fill_in(:wiki_title, with: "/#{new_name}")
|
||||
|
||||
click_button('Save changes')
|
||||
|
||||
expect(current_path).to eq(project_wiki_path(project, new_name))
|
||||
end
|
||||
|
||||
it 'squishes the title before creating the page' do
|
||||
new_page_dir = " foo1 / bar1 / #{page_name} "
|
||||
|
||||
fill_in(:wiki_title, with: new_page_dir)
|
||||
|
||||
click_button('Save changes')
|
||||
|
||||
expect(current_path).to eq(project_wiki_path(project, "foo1/bar1/#{page_name}"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when wiki is not empty' do
|
||||
let(:project_wiki) { create(:project_wiki, project: project, user: project.creator) }
|
||||
let!(:wiki_page) { create(:wiki_page, wiki: project_wiki, attrs: { title: 'home', content: 'Home page' }) }
|
||||
|
||||
before do
|
||||
visit(project_wikis_path(project))
|
||||
end
|
||||
|
||||
context 'in a user namespace' do
|
||||
let(:project) { create(:project, namespace: user.namespace) }
|
||||
|
||||
it 'updates a page' do
|
||||
click_link('Edit')
|
||||
|
||||
# Commit message field should have correct value.
|
||||
expect(page).to have_field('wiki[message]', with: 'Update home')
|
||||
|
||||
fill_in(:wiki_content, with: 'My awesome wiki!')
|
||||
click_button('Save changes')
|
||||
|
||||
expect(page).to have_content('Home')
|
||||
expect(page).to have_content("Last edited by #{user.name}")
|
||||
expect(page).to have_content('My awesome wiki!')
|
||||
end
|
||||
|
||||
it 'shows a validation error message' do
|
||||
click_link('Edit')
|
||||
|
||||
fill_in(:wiki_content, with: '')
|
||||
click_button('Save changes')
|
||||
|
||||
expect(page).to have_selector('.wiki-form')
|
||||
expect(page).to have_content('Edit Page')
|
||||
expect(page).to have_content('The form contains the following error:')
|
||||
expect(page).to have_content("Content can't be blank")
|
||||
expect(find('textarea#wiki_content').value).to eq('')
|
||||
end
|
||||
|
||||
it 'shows the autocompletion dropdown', :js do
|
||||
click_link('Edit')
|
||||
|
||||
find('#wiki_content').native.send_keys('')
|
||||
fill_in(:wiki_content, with: '@')
|
||||
|
||||
expect(page).to have_selector('.atwho-view')
|
||||
end
|
||||
|
||||
it 'shows the error message' do
|
||||
click_link('Edit')
|
||||
|
||||
wiki_page.update(content: 'Update')
|
||||
|
||||
click_button('Save changes')
|
||||
|
||||
expect(page).to have_content('Someone edited the page the same time you did.')
|
||||
end
|
||||
|
||||
it 'updates a page' do
|
||||
click_on('Edit')
|
||||
fill_in('Content', with: 'Updated Wiki Content')
|
||||
click_on('Save changes')
|
||||
|
||||
expect(page).to have_content('Updated Wiki Content')
|
||||
end
|
||||
|
||||
it 'cancels edititng of a page' do
|
||||
click_on('Edit')
|
||||
|
||||
page.within(:css, '.wiki-form .form-actions') do
|
||||
click_on('Cancel')
|
||||
end
|
||||
|
||||
expect(current_path).to eq(project_wiki_path(project, wiki_page))
|
||||
end
|
||||
end
|
||||
|
||||
context 'in a group namespace' do
|
||||
let(:project) { create(:project, namespace: create(:group, :public)) }
|
||||
|
||||
it 'updates a page' do
|
||||
click_link('Edit')
|
||||
|
||||
# Commit message field should have correct value.
|
||||
expect(page).to have_field('wiki[message]', with: 'Update home')
|
||||
|
||||
fill_in(:wiki_content, with: 'My awesome wiki!')
|
||||
|
||||
click_button('Save changes')
|
||||
|
||||
expect(page).to have_content('Home')
|
||||
expect(page).to have_content("Last edited by #{user.name}")
|
||||
expect(page).to have_content('My awesome wiki!')
|
||||
end
|
||||
end
|
||||
context 'when Gitaly is enabled' do
|
||||
it_behaves_like 'wiki page user update'
|
||||
end
|
||||
|
||||
context 'when the page is in a subdir' do
|
||||
let!(:project) { create(:project, namespace: user.namespace) }
|
||||
let(:project_wiki) { create(:project_wiki, project: project, user: project.creator) }
|
||||
let(:page_name) { 'page_name' }
|
||||
let(:page_dir) { "foo/bar/#{page_name}" }
|
||||
let!(:wiki_page) { create(:wiki_page, wiki: project_wiki, attrs: { title: page_dir, content: 'Home page' }) }
|
||||
|
||||
before do
|
||||
visit(project_wiki_edit_path(project, wiki_page))
|
||||
end
|
||||
|
||||
it 'moves the page to the root folder' do
|
||||
fill_in(:wiki_title, with: "/#{page_name}")
|
||||
|
||||
click_button('Save changes')
|
||||
|
||||
expect(current_path).to eq(project_wiki_path(project, page_name))
|
||||
end
|
||||
|
||||
it 'moves the page to other dir' do
|
||||
new_page_dir = "foo1/bar1/#{page_name}"
|
||||
|
||||
fill_in(:wiki_title, with: new_page_dir)
|
||||
|
||||
click_button('Save changes')
|
||||
|
||||
expect(current_path).to eq(project_wiki_path(project, new_page_dir))
|
||||
end
|
||||
|
||||
it 'remains in the same place if title has not changed' do
|
||||
original_path = project_wiki_path(project, wiki_page)
|
||||
|
||||
fill_in(:wiki_title, with: page_name)
|
||||
|
||||
click_button('Save changes')
|
||||
|
||||
expect(current_path).to eq(original_path)
|
||||
end
|
||||
|
||||
it 'can be moved to a different dir with a different name' do
|
||||
new_page_dir = "foo1/bar1/new_page_name"
|
||||
|
||||
fill_in(:wiki_title, with: new_page_dir)
|
||||
|
||||
click_button('Save changes')
|
||||
|
||||
expect(current_path).to eq(project_wiki_path(project, new_page_dir))
|
||||
end
|
||||
|
||||
it 'can be renamed and moved to the root folder' do
|
||||
new_name = 'new_page_name'
|
||||
|
||||
fill_in(:wiki_title, with: "/#{new_name}")
|
||||
|
||||
click_button('Save changes')
|
||||
|
||||
expect(current_path).to eq(project_wiki_path(project, new_name))
|
||||
end
|
||||
|
||||
it 'squishes the title before creating the page' do
|
||||
new_page_dir = " foo1 / bar1 / #{page_name} "
|
||||
|
||||
fill_in(:wiki_title, with: new_page_dir)
|
||||
|
||||
click_button('Save changes')
|
||||
|
||||
expect(current_path).to eq(project_wiki_path(project, "foo1/bar1/#{page_name}"))
|
||||
end
|
||||
context 'when Gitaly is disabled', :skip_gitaly_mock do
|
||||
it_behaves_like 'wiki page user update'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,146 +1,155 @@
|
|||
require 'spec_helper'
|
||||
|
||||
# Remove skip_gitaly_mock flag when gitaly_update_page implements moving pages
|
||||
describe 'User views a wiki page', :skip_gitaly_mock do
|
||||
let(:user) { create(:user) }
|
||||
let(:project) { create(:project, namespace: user.namespace) }
|
||||
let(:wiki_page) do
|
||||
create(:wiki_page,
|
||||
wiki: project.wiki,
|
||||
attrs: { title: 'home', content: 'Look at this [image](image.jpg)\n\n ![alt text](image.jpg)' })
|
||||
end
|
||||
describe 'User views a wiki page' do
|
||||
shared_examples 'wiki page user view' do
|
||||
let(:user) { create(:user) }
|
||||
let(:project) { create(:project, namespace: user.namespace) }
|
||||
let(:wiki_page) do
|
||||
create(:wiki_page,
|
||||
wiki: project.wiki,
|
||||
attrs: { title: 'home', content: 'Look at this [image](image.jpg)\n\n ![alt text](image.jpg)' })
|
||||
end
|
||||
|
||||
before do
|
||||
project.add_master(user)
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
context 'when wiki is empty' do
|
||||
before do
|
||||
visit(project_wikis_path(project))
|
||||
project.add_master(user)
|
||||
sign_in(user)
|
||||
end
|
||||
|
||||
click_on('New page')
|
||||
context 'when wiki is empty' do
|
||||
before do
|
||||
visit(project_wikis_path(project))
|
||||
|
||||
page.within('#modal-new-wiki') do
|
||||
fill_in(:new_wiki_path, with: 'one/two/three-test')
|
||||
click_on('Create page')
|
||||
click_on('New page')
|
||||
|
||||
page.within('#modal-new-wiki') do
|
||||
fill_in(:new_wiki_path, with: 'one/two/three-test')
|
||||
click_on('Create page')
|
||||
end
|
||||
|
||||
page.within('.wiki-form') do
|
||||
fill_in(:wiki_content, with: 'wiki content')
|
||||
click_on('Create page')
|
||||
end
|
||||
end
|
||||
|
||||
page.within('.wiki-form') do
|
||||
fill_in(:wiki_content, with: 'wiki content')
|
||||
click_on('Create page')
|
||||
it 'shows the history of a page that has a path', :js do
|
||||
expect(current_path).to include('one/two/three-test')
|
||||
|
||||
first(:link, text: 'Three').click
|
||||
click_on('Page history')
|
||||
|
||||
expect(current_path).to include('one/two/three-test')
|
||||
|
||||
page.within(:css, '.nav-text') do
|
||||
expect(page).to have_content('History')
|
||||
end
|
||||
end
|
||||
|
||||
it 'shows an old version of a page', :js do
|
||||
expect(current_path).to include('one/two/three-test')
|
||||
expect(find('.wiki-pages')).to have_content('Three')
|
||||
|
||||
first(:link, text: 'Three').click
|
||||
|
||||
expect(find('.nav-text')).to have_content('Three')
|
||||
|
||||
click_on('Edit')
|
||||
|
||||
expect(current_path).to include('one/two/three-test')
|
||||
expect(page).to have_content('Edit Page')
|
||||
|
||||
fill_in('Content', with: 'Updated Wiki Content')
|
||||
|
||||
click_on('Save changes')
|
||||
click_on('Page history')
|
||||
|
||||
page.within(:css, '.nav-text') do
|
||||
expect(page).to have_content('History')
|
||||
end
|
||||
|
||||
find('a[href*="?version_id"]')
|
||||
end
|
||||
end
|
||||
|
||||
it 'shows the history of a page that has a path', :js do
|
||||
expect(current_path).to include('one/two/three-test')
|
||||
context 'when a page does not have history' do
|
||||
before do
|
||||
visit(project_wiki_path(project, wiki_page))
|
||||
end
|
||||
|
||||
first(:link, text: 'Three').click
|
||||
click_on('Page history')
|
||||
it 'shows all the pages' do
|
||||
expect(page).to have_content(user.name)
|
||||
expect(find('.wiki-pages')).to have_content(wiki_page.title.capitalize)
|
||||
end
|
||||
|
||||
expect(current_path).to include('one/two/three-test')
|
||||
it 'shows a file stored in a page' do
|
||||
gollum_file_double = double('Gollum::File',
|
||||
mime_type: 'image/jpeg',
|
||||
name: 'images/image.jpg',
|
||||
path: 'images/image.jpg',
|
||||
raw_data: '')
|
||||
wiki_file = Gitlab::Git::WikiFile.new(gollum_file_double)
|
||||
|
||||
page.within(:css, '.nav-text') do
|
||||
expect(page).to have_content('History')
|
||||
allow(wiki_file).to receive(:mime_type).and_return('image/jpeg')
|
||||
allow_any_instance_of(ProjectWiki).to receive(:find_file).with('image.jpg', nil).and_return(wiki_file)
|
||||
|
||||
expect(page).to have_xpath('//img[@data-src="image.jpg"]')
|
||||
expect(page).to have_link('image', href: "#{project.wiki.wiki_base_path}/image.jpg")
|
||||
|
||||
click_on('image')
|
||||
|
||||
expect(current_path).to match('wikis/image.jpg')
|
||||
expect(page).not_to have_xpath('/html') # Page should render the image which means there is no html involved
|
||||
end
|
||||
|
||||
it 'shows the creation page if file does not exist' do
|
||||
expect(page).to have_link('image', href: "#{project.wiki.wiki_base_path}/image.jpg")
|
||||
|
||||
click_on('image')
|
||||
|
||||
expect(current_path).to match('wikis/image.jpg')
|
||||
expect(page).to have_content('New Wiki Page')
|
||||
expect(page).to have_content('Create page')
|
||||
end
|
||||
end
|
||||
|
||||
it 'shows an old version of a page', :js do
|
||||
expect(current_path).to include('one/two/three-test')
|
||||
expect(find('.wiki-pages')).to have_content('Three')
|
||||
|
||||
first(:link, text: 'Three').click
|
||||
|
||||
expect(find('.nav-text')).to have_content('Three')
|
||||
|
||||
click_on('Edit')
|
||||
|
||||
expect(current_path).to include('one/two/three-test')
|
||||
expect(page).to have_content('Edit Page')
|
||||
|
||||
fill_in('Content', with: 'Updated Wiki Content')
|
||||
|
||||
click_on('Save changes')
|
||||
click_on('Page history')
|
||||
|
||||
page.within(:css, '.nav-text') do
|
||||
expect(page).to have_content('History')
|
||||
context 'when a page has history' do
|
||||
before do
|
||||
wiki_page.update(message: 'updated home', content: 'updated [some link](other-page)')
|
||||
end
|
||||
|
||||
find('a[href*="?version_id"]')
|
||||
it 'shows the page history' do
|
||||
visit(project_wiki_path(project, wiki_page))
|
||||
|
||||
expect(page).to have_selector('a.btn', text: 'Edit')
|
||||
|
||||
click_on('Page history')
|
||||
|
||||
expect(page).to have_content(user.name)
|
||||
expect(page).to have_content("#{user.username} created page: home")
|
||||
expect(page).to have_content('updated home')
|
||||
end
|
||||
|
||||
it 'does not show the "Edit" button' do
|
||||
visit(project_wiki_path(project, wiki_page, version_id: wiki_page.versions.last.id))
|
||||
|
||||
expect(page).not_to have_selector('a.btn', text: 'Edit')
|
||||
end
|
||||
end
|
||||
|
||||
it 'opens a default wiki page', :js do
|
||||
visit(project_path(project))
|
||||
|
||||
find('.shortcuts-wiki').click
|
||||
|
||||
expect(page).to have_content('Home · Create Page')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when a page does not have history' do
|
||||
before do
|
||||
visit(project_wiki_path(project, wiki_page))
|
||||
end
|
||||
|
||||
it 'shows all the pages' do
|
||||
expect(page).to have_content(user.name)
|
||||
expect(find('.wiki-pages')).to have_content(wiki_page.title.capitalize)
|
||||
end
|
||||
|
||||
it 'shows a file stored in a page' do
|
||||
gollum_file_double = double('Gollum::File',
|
||||
mime_type: 'image/jpeg',
|
||||
name: 'images/image.jpg',
|
||||
path: 'images/image.jpg',
|
||||
raw_data: '')
|
||||
wiki_file = Gitlab::Git::WikiFile.new(gollum_file_double)
|
||||
|
||||
allow(wiki_file).to receive(:mime_type).and_return('image/jpeg')
|
||||
allow_any_instance_of(ProjectWiki).to receive(:find_file).with('image.jpg', nil).and_return(wiki_file)
|
||||
|
||||
expect(page).to have_xpath('//img[@data-src="image.jpg"]')
|
||||
expect(page).to have_link('image', href: "#{project.wiki.wiki_base_path}/image.jpg")
|
||||
|
||||
click_on('image')
|
||||
|
||||
expect(current_path).to match('wikis/image.jpg')
|
||||
expect(page).not_to have_xpath('/html') # Page should render the image which means there is no html involved
|
||||
end
|
||||
|
||||
it 'shows the creation page if file does not exist' do
|
||||
expect(page).to have_link('image', href: "#{project.wiki.wiki_base_path}/image.jpg")
|
||||
|
||||
click_on('image')
|
||||
|
||||
expect(current_path).to match('wikis/image.jpg')
|
||||
expect(page).to have_content('New Wiki Page')
|
||||
expect(page).to have_content('Create page')
|
||||
end
|
||||
context 'when Gitaly is enabled' do
|
||||
it_behaves_like 'wiki page user view'
|
||||
end
|
||||
|
||||
context 'when a page has history' do
|
||||
before do
|
||||
wiki_page.update(message: 'updated home', content: 'updated [some link](other-page)')
|
||||
end
|
||||
|
||||
it 'shows the page history' do
|
||||
visit(project_wiki_path(project, wiki_page))
|
||||
|
||||
expect(page).to have_selector('a.btn', text: 'Edit')
|
||||
|
||||
click_on('Page history')
|
||||
|
||||
expect(page).to have_content(user.name)
|
||||
expect(page).to have_content("#{user.username} created page: home")
|
||||
expect(page).to have_content('updated home')
|
||||
end
|
||||
|
||||
it 'does not show the "Edit" button' do
|
||||
visit(project_wiki_path(project, wiki_page, version_id: wiki_page.versions.last.id))
|
||||
|
||||
expect(page).not_to have_selector('a.btn', text: 'Edit')
|
||||
end
|
||||
end
|
||||
|
||||
it 'opens a default wiki page', :js do
|
||||
visit(project_path(project))
|
||||
|
||||
find('.shortcuts-wiki').click
|
||||
|
||||
expect(page).to have_content('Home · Create Page')
|
||||
context 'when Gitaly is disabled', :skip_gitaly_mock do
|
||||
it_behaves_like 'wiki page user view'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,34 +3,38 @@ require 'spec_helper'
|
|||
describe Gitlab::Git::Wiki do
|
||||
let(:project) { create(:project) }
|
||||
let(:user) { project.owner }
|
||||
let(:wiki) { ProjectWiki.new(project, user) }
|
||||
let(:gollum_wiki) { wiki.wiki }
|
||||
let(:project_wiki) { ProjectWiki.new(project, user) }
|
||||
subject { project_wiki.wiki }
|
||||
|
||||
# Remove skip_gitaly_mock flag when gitaly_find_page when
|
||||
# https://gitlab.com/gitlab-org/gitaly/merge_requests/539 gets merged
|
||||
# https://gitlab.com/gitlab-org/gitlab-ce/issues/42039 is solved
|
||||
describe '#page', :skip_gitaly_mock do
|
||||
it 'returns the right page' do
|
||||
before do
|
||||
create_page('page1', 'content')
|
||||
create_page('foo/page1', 'content')
|
||||
|
||||
expect(gollum_wiki.page(title: 'page1', dir: '').url_path).to eq 'page1'
|
||||
expect(gollum_wiki.page(title: 'page1', dir: 'foo').url_path).to eq 'foo/page1'
|
||||
create_page('foo/page1', 'content foo/page1')
|
||||
end
|
||||
|
||||
after do
|
||||
destroy_page('page1')
|
||||
destroy_page('page1', 'foo')
|
||||
end
|
||||
|
||||
it 'returns the right page' do
|
||||
expect(subject.page(title: 'page1', dir: '').url_path).to eq 'page1'
|
||||
expect(subject.page(title: 'page1', dir: 'foo').url_path).to eq 'foo/page1'
|
||||
end
|
||||
end
|
||||
|
||||
def create_page(name, content)
|
||||
gollum_wiki.write_page(name, :markdown, content, commit_details)
|
||||
subject.write_page(name, :markdown, content, commit_details(name))
|
||||
end
|
||||
|
||||
def commit_details
|
||||
Gitlab::Git::Wiki::CommitDetails.new(user.name, user.email, "test commit")
|
||||
def commit_details(name)
|
||||
Gitlab::Git::Wiki::CommitDetails.new(user.name, user.email, "created page #{name}")
|
||||
end
|
||||
|
||||
def destroy_page(title, dir = '')
|
||||
page = gollum_wiki.page(title: title, dir: dir)
|
||||
wiki.delete_page(page, "test commit")
|
||||
page = subject.page(title: title, dir: dir)
|
||||
project_wiki.delete_page(page, "test commit")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -188,162 +188,181 @@ describe WikiPage do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#create', :skip_gitaly_mock do
|
||||
context 'with valid attributes' do
|
||||
it 'raises an error if a page with the same path already exists' do
|
||||
create_page('New Page', 'content')
|
||||
create_page('foo/bar', 'content')
|
||||
expect { create_page('New Page', 'other content') }.to raise_error Gitlab::Git::Wiki::DuplicatePageError
|
||||
expect { create_page('foo/bar', 'other content') }.to raise_error Gitlab::Git::Wiki::DuplicatePageError
|
||||
describe '#create' do
|
||||
shared_examples 'create method' do
|
||||
context 'with valid attributes' do
|
||||
it 'raises an error if a page with the same path already exists' do
|
||||
create_page('New Page', 'content')
|
||||
create_page('foo/bar', 'content')
|
||||
expect { create_page('New Page', 'other content') }.to raise_error Gitlab::Git::Wiki::DuplicatePageError
|
||||
expect { create_page('foo/bar', 'other content') }.to raise_error Gitlab::Git::Wiki::DuplicatePageError
|
||||
|
||||
destroy_page('New Page')
|
||||
destroy_page('bar', 'foo')
|
||||
destroy_page('New Page')
|
||||
destroy_page('bar', 'foo')
|
||||
end
|
||||
|
||||
it 'if the title is preceded by a / it is removed' do
|
||||
create_page('/New Page', 'content')
|
||||
|
||||
expect(wiki.find_page('New Page')).not_to be_nil
|
||||
|
||||
destroy_page('New Page')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it 'if the title is preceded by a / it is removed' do
|
||||
create_page('/New Page', 'content')
|
||||
context 'when Gitaly is enabled' do
|
||||
it_behaves_like 'create method'
|
||||
end
|
||||
|
||||
expect(wiki.find_page('New Page')).not_to be_nil
|
||||
|
||||
destroy_page('New Page')
|
||||
end
|
||||
context 'when Gitaly is disabled', :skip_gitaly_mock do
|
||||
it_behaves_like 'create method'
|
||||
end
|
||||
end
|
||||
|
||||
# Remove skip_gitaly_mock flag when gitaly_update_page implements moving pages
|
||||
describe "#update", :skip_gitaly_mock do
|
||||
before do
|
||||
create_page("Update", "content")
|
||||
@page = wiki.find_page("Update")
|
||||
end
|
||||
|
||||
after do
|
||||
destroy_page(@page.title, @page.directory)
|
||||
end
|
||||
|
||||
context "with valid attributes" do
|
||||
it "updates the content of the page" do
|
||||
new_content = "new content"
|
||||
|
||||
@page.update(content: new_content)
|
||||
describe "#update" do
|
||||
shared_examples 'update method' do
|
||||
before do
|
||||
create_page("Update", "content")
|
||||
@page = wiki.find_page("Update")
|
||||
|
||||
expect(@page.content).to eq("new content")
|
||||
end
|
||||
|
||||
it "updates the title of the page" do
|
||||
new_title = "Index v.1.2.4"
|
||||
|
||||
@page.update(title: new_title)
|
||||
@page = wiki.find_page(new_title)
|
||||
|
||||
expect(@page.title).to eq(new_title)
|
||||
after do
|
||||
destroy_page(@page.title, @page.directory)
|
||||
end
|
||||
|
||||
it "returns true" do
|
||||
expect(@page.update(content: "more content")).to be_truthy
|
||||
end
|
||||
end
|
||||
context "with valid attributes" do
|
||||
it "updates the content of the page" do
|
||||
new_content = "new content"
|
||||
|
||||
context 'with same last commit sha' do
|
||||
it 'returns true' do
|
||||
expect(@page.update(content: 'more content', last_commit_sha: @page.last_commit_sha)).to be_truthy
|
||||
end
|
||||
end
|
||||
@page.update(content: new_content)
|
||||
@page = wiki.find_page("Update")
|
||||
|
||||
context 'with different last commit sha' do
|
||||
it 'raises exception' do
|
||||
expect { @page.update(content: 'more content', last_commit_sha: 'xxx') }.to raise_error(WikiPage::PageChangedError)
|
||||
end
|
||||
end
|
||||
expect(@page.content).to eq("new content")
|
||||
end
|
||||
|
||||
context 'when renaming a page' do
|
||||
it 'raises an error if the page already exists' do
|
||||
create_page('Existing Page', 'content')
|
||||
it "updates the title of the page" do
|
||||
new_title = "Index v.1.2.4"
|
||||
|
||||
expect { @page.update(title: 'Existing Page', content: 'new_content') }.to raise_error(WikiPage::PageRenameError)
|
||||
expect(@page.title).to eq 'Update'
|
||||
expect(@page.content).to eq 'new_content'
|
||||
@page.update(title: new_title)
|
||||
@page = wiki.find_page(new_title)
|
||||
|
||||
destroy_page('Existing Page')
|
||||
expect(@page.title).to eq(new_title)
|
||||
end
|
||||
|
||||
it "returns true" do
|
||||
expect(@page.update(content: "more content")).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
it 'updates the content and rename the file' do
|
||||
new_title = 'Renamed Page'
|
||||
new_content = 'updated content'
|
||||
|
||||
expect(@page.update(title: new_title, content: new_content)).to be_truthy
|
||||
|
||||
@page = wiki.find_page(new_title)
|
||||
|
||||
expect(@page).not_to be_nil
|
||||
expect(@page.content).to eq new_content
|
||||
end
|
||||
end
|
||||
|
||||
context 'when moving a page' do
|
||||
it 'raises an error if the page already exists' do
|
||||
create_page('foo/Existing Page', 'content')
|
||||
|
||||
expect { @page.update(title: 'foo/Existing Page', content: 'new_content') }.to raise_error(WikiPage::PageRenameError)
|
||||
expect(@page.title).to eq 'Update'
|
||||
expect(@page.content).to eq 'new_content'
|
||||
|
||||
destroy_page('Existing Page', 'foo')
|
||||
context 'with same last commit sha' do
|
||||
it 'returns true' do
|
||||
expect(@page.update(content: 'more content', last_commit_sha: @page.last_commit_sha)).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
it 'updates the content and moves the file' do
|
||||
new_title = 'foo/Other Page'
|
||||
new_content = 'new_content'
|
||||
|
||||
expect(@page.update(title: new_title, content: new_content)).to be_truthy
|
||||
|
||||
page = wiki.find_page(new_title)
|
||||
|
||||
expect(page).not_to be_nil
|
||||
expect(page.content).to eq new_content
|
||||
context 'with different last commit sha' do
|
||||
it 'raises exception' do
|
||||
expect { @page.update(content: 'more content', last_commit_sha: 'xxx') }.to raise_error(WikiPage::PageChangedError)
|
||||
end
|
||||
end
|
||||
|
||||
context 'in subdir' do
|
||||
before do
|
||||
context 'when renaming a page' do
|
||||
it 'raises an error if the page already exists' do
|
||||
create_page('Existing Page', 'content')
|
||||
|
||||
expect { @page.update(title: 'Existing Page', content: 'new_content') }.to raise_error(WikiPage::PageRenameError)
|
||||
expect(@page.title).to eq 'Update'
|
||||
expect(@page.content).to eq 'new_content'
|
||||
|
||||
destroy_page('Existing Page')
|
||||
end
|
||||
|
||||
it 'updates the content and rename the file' do
|
||||
new_title = 'Renamed Page'
|
||||
new_content = 'updated content'
|
||||
|
||||
expect(@page.update(title: new_title, content: new_content)).to be_truthy
|
||||
|
||||
@page = wiki.find_page(new_title)
|
||||
|
||||
expect(@page).not_to be_nil
|
||||
expect(@page.content).to eq new_content
|
||||
end
|
||||
end
|
||||
|
||||
context 'when moving a page' do
|
||||
it 'raises an error if the page already exists' do
|
||||
create_page('foo/Existing Page', 'content')
|
||||
@page = wiki.find_page('foo/Existing Page')
|
||||
|
||||
expect { @page.update(title: 'foo/Existing Page', content: 'new_content') }.to raise_error(WikiPage::PageRenameError)
|
||||
expect(@page.title).to eq 'Update'
|
||||
expect(@page.content).to eq 'new_content'
|
||||
|
||||
destroy_page('Existing Page', 'foo')
|
||||
end
|
||||
|
||||
it 'moves the page to the root folder if the title is preceded by /' do
|
||||
expect(@page.slug).to eq 'foo/Existing-Page'
|
||||
expect(@page.update(title: '/Existing Page', content: 'new_content')).to be_truthy
|
||||
expect(@page.slug).to eq 'Existing-Page'
|
||||
it 'updates the content and moves the file' do
|
||||
new_title = 'foo/Other Page'
|
||||
new_content = 'new_content'
|
||||
|
||||
expect(@page.update(title: new_title, content: new_content)).to be_truthy
|
||||
|
||||
page = wiki.find_page(new_title)
|
||||
|
||||
expect(page).not_to be_nil
|
||||
expect(page.content).to eq new_content
|
||||
end
|
||||
|
||||
it 'does nothing if it has the same title' do
|
||||
original_path = @page.slug
|
||||
context 'in subdir' do
|
||||
before do
|
||||
create_page('foo/Existing Page', 'content')
|
||||
@page = wiki.find_page('foo/Existing Page')
|
||||
end
|
||||
|
||||
expect(@page.update(title: 'Existing Page', content: 'new_content')).to be_truthy
|
||||
expect(@page.slug).to eq original_path
|
||||
it 'moves the page to the root folder if the title is preceded by /', :skip_gitaly_mock do
|
||||
expect(@page.slug).to eq 'foo/Existing-Page'
|
||||
expect(@page.update(title: '/Existing Page', content: 'new_content')).to be_truthy
|
||||
expect(@page.slug).to eq 'Existing-Page'
|
||||
end
|
||||
|
||||
it 'does nothing if it has the same title' do
|
||||
original_path = @page.slug
|
||||
|
||||
expect(@page.update(title: 'Existing Page', content: 'new_content')).to be_truthy
|
||||
expect(@page.slug).to eq original_path
|
||||
end
|
||||
end
|
||||
|
||||
context 'in root dir' do
|
||||
it 'does nothing if the title is preceded by /' do
|
||||
original_path = @page.slug
|
||||
|
||||
expect(@page.update(title: '/Update', content: 'new_content')).to be_truthy
|
||||
expect(@page.slug).to eq original_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'in root dir' do
|
||||
it 'does nothing if the title is preceded by /' do
|
||||
original_path = @page.slug
|
||||
context "with invalid attributes" do
|
||||
it 'aborts update if title blank' do
|
||||
expect(@page.update(title: '', content: 'new_content')).to be_falsey
|
||||
expect(@page.content).to eq 'new_content'
|
||||
|
||||
expect(@page.update(title: '/Update', content: 'new_content')).to be_truthy
|
||||
expect(@page.slug).to eq original_path
|
||||
page = wiki.find_page('Update')
|
||||
expect(page.content).to eq 'content'
|
||||
|
||||
@page.title = 'Update'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "with invalid attributes" do
|
||||
it 'aborts update if title blank' do
|
||||
expect(@page.update(title: '', content: 'new_content')).to be_falsey
|
||||
expect(@page.content).to eq 'new_content'
|
||||
context 'when Gitaly is enabled' do
|
||||
it_behaves_like 'update method'
|
||||
end
|
||||
|
||||
page = wiki.find_page('Update')
|
||||
expect(page.content).to eq 'content'
|
||||
|
||||
@page.title = 'Update'
|
||||
end
|
||||
context 'when Gitaly is disabled', :skip_gitaly_mock do
|
||||
it_behaves_like 'update method'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue