Skip to content
Snippets Groups Projects
Commit 8f210aeb authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 996f7009
No related branches found
No related tags found
No related merge requests found
Showing
with 609 additions and 809 deletions
Loading
Loading
@@ -6,7 +6,7 @@ module Banzai
class Rewriter
def initialize(link_string, wiki:, slug:)
@uri = Addressable::URI.parse(link_string)
@wiki_base_path = wiki && wiki.wiki_page_path
@wiki_base_path = wiki && wiki.wiki_base_path
@slug = slug
end
 
Loading
Loading
Loading
Loading
@@ -47,7 +47,8 @@ module Gitlab
cookie_domain: Gitlab::CurrentSettings.snowplow_cookie_domain,
app_id: Gitlab::CurrentSettings.snowplow_site_id,
form_tracking: additional_features,
link_click_tracking: additional_features
link_click_tracking: additional_features,
iglu_registry_url: Gitlab::CurrentSettings.snowplow_iglu_registry_url
}.transform_keys! { |key| key.to_s.camelize(:lower).to_sym }
end
 
Loading
Loading
Loading
Loading
@@ -78,6 +78,8 @@ module Gitlab
in_review_folder: count(::Environment.in_review_folder),
groups: count(Group),
issues: count(Issue),
issues_with_associated_zoom_link: count(ZoomMeeting.added_to_issue),
issues_using_zoom_quick_actions: count(ZoomMeeting.select(:issue_id).distinct),
keys: count(Key),
label_lists: count(List.label),
lfs_objects: count(LfsObject),
Loading
Loading
Loading
Loading
@@ -130,15 +130,5 @@ module Gitlab
IPAddr.new(str)
rescue IPAddr::InvalidAddressError
end
# Filter a Hash against a mapping of keys to sets of allowed values.
#
# Keys that do not pass the filter will be removed from the Hash.
# This mutates the input hash.
def allow_hash_values(hash, allowed)
allowed.each do |key, allowed_values|
hash.delete(key) if hash.key?(key) && !allowed_values.include?(hash[key])
end
end
end
end
Loading
Loading
@@ -411,9 +411,6 @@ msgstr ""
msgid "%{verb} %{time_spent_value} spent time."
msgstr ""
 
msgid "·"
msgstr ""
msgid "'%{level}' is not a valid visibility level"
msgstr ""
 
Loading
Loading
@@ -8848,6 +8845,9 @@ msgstr ""
msgid "If your HTTP repository is not publicly accessible, add your credentials."
msgstr ""
 
msgid "Iglu registry URL (optional)"
msgstr ""
msgid "ImageDiffViewer|2-up"
msgstr ""
 
Loading
Loading
@@ -9543,6 +9543,9 @@ msgstr ""
msgid "Kubernetes error: %{error_code}"
msgstr ""
 
msgid "Kubernetes popover"
msgstr ""
msgid "LDAP"
msgstr ""
 
Loading
Loading
@@ -18891,10 +18894,7 @@ msgstr ""
msgid "Wiki pages"
msgstr ""
 
msgid "Wiki was successfully created"
msgstr ""
msgid "Wiki was successfully updated"
msgid "Wiki was successfully updated."
msgstr ""
 
msgid "WikiClone|Clone your wiki"
Loading
Loading
@@ -18912,18 +18912,6 @@ msgstr ""
msgid "WikiClone|Start Gollum and edit locally"
msgstr ""
 
msgid "WikiDirEmpty|A wiki is where you can store all the details about your project. This can include why you've created it, its principles, how to use it, and so on."
msgstr ""
msgid "WikiDirEmpty|Create a page"
msgstr ""
msgid "WikiDirEmpty|Create a page in this directory"
msgstr ""
msgid "WikiDirEmpty|This directory has no wiki pages"
msgstr ""
msgid "WikiEditPageTip|Tip: You can move this page by adding the path to the beginning of the title."
msgstr ""
 
Loading
Loading
@@ -18942,9 +18930,6 @@ msgstr ""
msgid "WikiEmpty|A wiki is where you can store all the details about your project. This can include why you've created it, its principles, how to use it, and so on."
msgstr ""
 
msgid "WikiEmpty|Create this page"
msgstr ""
msgid "WikiEmpty|Create your first page"
msgstr ""
 
Loading
Loading
@@ -18954,9 +18939,6 @@ msgstr ""
msgid "WikiEmpty|The wiki lets you write documentation for your project"
msgstr ""
 
msgid "WikiEmpty|This page does not exist"
msgstr ""
msgid "WikiEmpty|This project has no wiki pages"
msgstr ""
 
Loading
Loading
@@ -19011,9 +18993,6 @@ msgstr ""
msgid "WikiPage|Write your content or drag files here…"
msgstr ""
 
msgid "Wiki|Contents"
msgstr ""
msgid "Wiki|Create New Page"
msgstr ""
 
Loading
Loading
@@ -19026,9 +19005,6 @@ msgstr ""
msgid "Wiki|Edit Page"
msgstr ""
 
msgid "Wiki|Hide folder contents"
msgstr ""
msgid "Wiki|More Pages"
msgstr ""
 
Loading
Loading
@@ -19047,13 +19023,10 @@ msgstr ""
msgid "Wiki|Pages"
msgstr ""
 
msgid "Wiki|Show files separately"
msgstr ""
msgid "Wiki|Show folder contents"
msgid "Wiki|Title"
msgstr ""
 
msgid "Wiki|Title"
msgid "Wiki|Wiki Pages"
msgstr ""
 
msgid "Will deploy to"
Loading
Loading
Loading
Loading
@@ -5,7 +5,7 @@ module QA
module Project
module Wiki
class Edit < Page::Base
view 'app/views/shared/wiki/_main_links.html.haml' do
view 'app/views/projects/wikis/_main_links.html.haml' do
element :new_page_link, 'New page' # rubocop:disable QA/ElementWithPattern
element :page_history_link, 'Page history' # rubocop:disable QA/ElementWithPattern
element :edit_page_link, 'Edit' # rubocop:disable QA/ElementWithPattern
Loading
Loading
Loading
Loading
@@ -7,7 +7,7 @@ module QA
class New < Page::Base
include Component::LazyLoader
 
view 'app/views/projects/wiki_pages/_form.html.haml' do
view 'app/views/projects/wikis/_form.html.haml' do
element :wiki_title_textbox
element :wiki_content_textarea
element :wiki_message_textbox
Loading
Loading
Loading
Loading
@@ -7,11 +7,11 @@ module QA
class Show < Page::Base
include Page::Component::LegacyClonePanel
 
view 'app/views/shared/wiki/_page_listing.html.haml' do
view 'app/views/projects/wikis/pages.html.haml' do
element :clone_repository_link, 'Clone repository' # rubocop:disable QA/ElementWithPattern
end
 
view 'app/views/projects/wiki_pages/show.html.haml' do
view 'app/views/projects/wikis/show.html.haml' do
element :wiki_page_content
end
 
Loading
Loading
Loading
Loading
@@ -13,7 +13,7 @@ module QA
resource.message = 'Update home'
end
 
validate_created('My First Wiki Content')
validate_content('My First Wiki Content')
 
Page::Project::Wiki::Edit.perform(&:click_edit)
Page::Project::Wiki::New.perform do |page| # rubocop:disable QA/AmbiguousPageObjectName
Loading
Loading
@@ -21,7 +21,7 @@ module QA
page.save_changes
end
 
validate_edited('My Second Wiki Content')
validate_content('My Second Wiki Content')
 
Resource::Repository::WikiPush.fabricate! do |push|
push.wiki = wiki
Loading
Loading
@@ -34,12 +34,7 @@ module QA
expect(page).to have_content('My Third Wiki Content')
end
 
def validate_created(content)
expect(page).to have_content('Wiki was successfully created')
expect(page).to have_content(/#{content}/)
end
def validate_edited(content)
def validate_content(content)
expect(page).to have_content('Wiki was successfully updated')
expect(page).to have_content(/#{content}/)
end
Loading
Loading
Loading
Loading
@@ -26,17 +26,35 @@ def emit_errors(static_analysis)
end
end
 
tasks = [
%w[bin/rake lint:all],
%w[bundle exec license_finder],
%w[yarn run eslint],
%w[yarn run stylelint],
%w[yarn run prettier-all],
%w[bundle exec rubocop --parallel],
%w[scripts/lint-conflicts.sh],
%w[scripts/lint-rugged]
]
def jobs_to_run(node_index, node_total)
all_tasks = [
%w[bin/rake lint:all],
%w[bundle exec license_finder],
%w[yarn run eslint],
%w[yarn run stylelint],
%w[yarn run prettier-all],
%w[bundle exec rubocop --parallel],
%w[scripts/lint-conflicts.sh],
%w[scripts/lint-rugged]
]
 
case node_total
when 1
all_tasks
when 2
rake_lint_all, *rest_jobs = all_tasks
case node_index
when 1
[rake_lint_all]
else
rest_jobs
end
else
raise "Parallelization > 2 (currently set to #{node_total}) isn't supported yet!"
end
end
tasks = jobs_to_run((ENV['CI_NODE_INDEX'] || 1).to_i, (ENV['CI_NODE_TOTAL'] || 1).to_i)
static_analysis = Gitlab::Popen::Runner.new
 
static_analysis.run(tasks) do |cmd, &run|
Loading
Loading
# frozen_string_literal: true
require 'spec_helper'
describe Projects::WikiDirectoriesController do
set(:project) { create(:project, :public, :repository) }
let(:user) { project.owner }
let(:project_wiki) { ProjectWiki.new(project, user) }
let(:wiki) { project_wiki.wiki }
let(:dir_slug) { 'the-directory' }
let(:dir_contents) { [create(:wiki_page)] }
let(:the_dir) { WikiDirectory.new(dir_slug, dir_contents) }
before do
allow(controller).to receive(:find_dir).and_return(the_dir)
sign_in(user)
end
describe 'GET #show' do
let(:show_params) do
{
namespace_id: project.namespace,
project_id: project,
id: dir_slug
}
end
before do
get :show, params: show_params
end
context 'the directory is empty' do
let(:the_dir) { nil }
it { is_expected.to render_template('empty') }
end
context 'the directory does exist' do
it { is_expected.to render_template('show') }
it 'sets the wiki_dir attribute' do
expect(assigns(:wiki_dir)).to eq(the_dir)
end
it 'assigns the wiki pages' do
expect(assigns(:wiki_pages)).to eq(dir_contents)
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Projects::WikiPagesController do
set(:project) { create(:project, :public, :repository) }
let(:user) { project.owner }
let(:project_wiki) { ProjectWiki.new(project, user) }
let(:wiki) { project_wiki.wiki }
let(:wiki_title) { 'page-title-test' }
let(:parent_ids) { { namespace_id: project.namespace.path, project_id: project.name } }
let(:redirect_destination) { Rails.application.routes.recognize_path(response.redirect_url) }
before do
create_page(wiki_title, 'hello world')
sign_in(user)
end
after do
destroy_page(wiki_title)
end
def helper
Helper.instance
end
class Helper
include Singleton
include ActionView::Helpers::UrlHelper
end
describe 'GET #new' do
subject { get :new, params: parent_ids }
it 'redirects to #show and appends a `random_title` param' do
subject
expect(response).to have_http_status(302)
expect(redirect_destination)
.to include(parent_ids.merge(controller: 'projects/wiki_pages', action: 'show'))
expect(response.redirect_url).to match(/\?random_title=true\Z/)
end
end
describe 'GET #show' do
render_views
let(:requested_wiki_page) { wiki_title }
let(:random_title) { nil }
subject do
get :show, params: {
namespace_id: project.namespace,
project_id: project,
id: requested_wiki_page,
random_title: random_title
}
end
context 'when the wiki repo cannot be created' do
before do
allow(controller).to receive(:load_wiki) { raise ProjectWiki::CouldNotCreateWikiError }
end
it 'redirects to the project path' do
headers = { 'Location' => a_string_ending_with(Gitlab::Routing.url_helpers.project_path(project)) }
subject
expect(response).to be_redirect
expect(response.header.to_hash).to include(headers)
end
end
context 'when the page exists' do
it 'limits the retrieved pages for the sidebar' do
expect(controller).to receive(:load_wiki).and_return(project_wiki)
# Sidebar entries
expect(project_wiki).to receive(:list_pages).with(limit: 15).and_call_original
subject
expect(response).to have_http_status(:ok)
expect(response.body).to include(wiki_title)
end
context 'when page content encoding is invalid' do
it 'sets flash error' do
allow(controller).to receive(:valid_encoding?).and_return(false)
subject
expect(response).to have_http_status(:ok)
expect(flash[:notice]).to eq 'The content of this page is not encoded in UTF-8. Edits can only be made via the Git repository.'
end
end
end
context 'when the page does not exist' do
let(:requested_wiki_page) { 'this-page-does-not-yet-exist' }
context 'the current user can create wiki pages' do
it { is_expected.to render_template('edit') }
it 'makes a call to see if the wiki is empty' do
expect(controller).to receive(:load_wiki).and_return(project_wiki)
expect(project_wiki).to receive(:list_pages).once.with(limit: anything).and_call_original
expect(project_wiki).to receive(:list_pages).with(limit: 1).and_call_original
subject
end
describe 'assigned title' do
shared_examples :wiki_page_with_correct_title do
it 'assigns the correct title' do
subject
expect(assigns(:page)).to have_attributes(title: assigned_title)
end
end
context 'random_title is absent' do
let(:random_title) { nil }
it_behaves_like :wiki_page_with_correct_title do
let(:assigned_title) { WikiPage.unhyphenize(requested_wiki_page) }
end
end
context 'random_title is present' do
let(:random_title) { true }
it_behaves_like :wiki_page_with_correct_title do
let(:assigned_title) { be_empty }
end
end
end
end
context 'the current user cannot create wiki pages' do
before do
forbid_controller_ability! :create_wiki
end
it { is_expected.to render_template('missing_page') }
end
end
context 'when page is a file' do
include WikiHelpers
let(:path) { upload_file_to_wiki(project, user, file_name) }
before do
get :show, params: { namespace_id: project.namespace, project_id: project, id: path }
end
context 'when file is an image' do
let(:file_name) { 'dk.png' }
it 'delivers the image' do
expect(response.headers['Content-Disposition']).to match(/^inline/)
expect(response.headers[Gitlab::Workhorse::DETECT_HEADER]).to eq "true"
end
context 'when file is a svg' do
let(:file_name) { 'unsanitized.svg' }
it 'delivers the image' do
expect(response.headers['Content-Disposition']).to match(/^inline/)
expect(response.headers[Gitlab::Workhorse::DETECT_HEADER]).to eq "true"
end
end
end
context 'when file is a pdf' do
let(:file_name) { 'git-cheat-sheet.pdf' }
it 'sets the content type to sets the content response headers' do
expect(response.headers['Content-Disposition']).to match(/^inline/)
expect(response.headers[Gitlab::Workhorse::DETECT_HEADER]).to eq "true"
end
end
end
end
describe 'POST #preview_markdown' do
let(:page_id) { 'page/path' }
let(:markdown_text) { '*Markdown* text' }
let(:wiki_page) { create(:wiki_page, wiki: project_wiki, attrs: { title: wiki_title }) }
let(:processed_md) { json_response.fetch('body') }
let(:preview_params) do
{ namespace_id: project.namespace, project_id: project, id: wiki_page.slug, text: markdown_text }
end
before do
post :preview_markdown, params: preview_params
end
it 'renders json in a correct format' do
expect(response).to have_http_status(:ok)
expect(json_response).to include('body' => String, 'references' => Hash)
end
describe 'double brackets within backticks' do
let(:markdown_text) do
<<-HEREDOC
`[[do_not_linkify]]`
```
[[also_do_not_linkify]]
```
HEREDOC
end
it "does not linkify double brackets inside code blocks as expected" do
expect(processed_md).to include('[[do_not_linkify]]', '[[also_do_not_linkify]]')
end
end
describe 'link re-writing' do
let(:links) do
[
{ text: 'regular link', path: 'regular' },
{ text: 'relative link 1', path: '../relative' },
{ text: 'relative link 2', path: './relative' },
{ text: 'relative link 3', path: './e/f/relative' },
{ text: 'spaced link', path: 'title with spaces' }
]
end
shared_examples :wiki_link_rewriter do
let(:markdown_text) { links.map { |text:, path:| "[#{text}](#{path})" }.join("\n") }
let(:expected_links) do
links.zip(paths).map do |(link, path)|
helper.link_to(link[:text], "#{project_wiki.wiki_page_path}/#{path}")
end
end
it 'processes the links correctly' do
expect(processed_md).to include(*expected_links)
end
end
context 'the current page has spaces in its title' do
let(:wiki_title) { 'page a/page b/page c/page d' }
it_behaves_like :wiki_link_rewriter do
let(:paths) do
['regular',
'page-a/page-b/relative',
'page-a/page-b/page-c/relative',
'page-a/page-b/page-c/e/f/relative',
'title%20with%20spaces']
end
end
end
context 'the current page has an unproblematic title' do
let(:wiki_title) { 'a/b/c/d' }
it_behaves_like :wiki_link_rewriter do
let(:paths) do
['regular', 'a/b/relative', 'a/b/c/relative', 'a/b/c/e/f/relative', 'title%20with%20spaces']
end
end
end
context "when there are hyphens in the page name" do
let(:wiki_title) { 'page-a/page-b/page-c/page-d' }
it_behaves_like :wiki_link_rewriter do
let(:paths) do
['regular',
'page-a/page-b/relative',
'page-a/page-b/page-c/relative',
'page-a/page-b/page-c/e/f/relative',
'title%20with%20spaces']
end
end
end
end
end
describe 'GET #edit' do
subject { get(:edit, params: { namespace_id: project.namespace, project_id: project, id: wiki_title }) }
context 'when page content encoding is invalid' do
it 'redirects to show' do
allow(controller).to receive(:valid_encoding?).and_return(false)
subject
expect(response).to redirect_to(project_wiki_path(project, project_wiki.list_pages.first))
end
end
context 'when page content encoding is valid' do
render_views
it 'shows the edit page' do
subject
expect(response).to have_http_status(:ok)
expect(response.body).to include('Edit Page')
end
end
end
describe 'PATCH #update' do
let(:new_title) { 'New title' }
let(:new_content) { 'New content' }
subject do
patch(:update,
params: {
namespace_id: project.namespace,
project_id: project,
id: wiki_title,
wiki_page: { title: new_title, content: new_content }
})
end
context 'when page content encoding is invalid' do
it 'redirects to show' do
allow(controller).to receive(:valid_encoding?).and_return(false)
subject
expect(response).to redirect_to(project_wiki_path(project, project_wiki.list_pages.first))
end
end
context 'when page content encoding is valid' do
render_views
it 'updates the page' do
subject
wiki_page = project_wiki.list_pages(load_content: true).first
expect(wiki_page.title).to eq new_title
expect(wiki_page.content).to eq new_content
end
end
end
describe 'GET #history' do
before do
allow(controller)
.to receive(:can?)
.with(any_args)
.and_call_original
# The :create_wiki permission is irrelevant to reading history.
expect(controller)
.not_to receive(:can?)
.with(anything, :create_wiki, any_args)
allow(controller)
.to receive(:can?)
.with(anything, :read_wiki, any_args)
.and_return(allow_read_wiki)
end
shared_examples 'fetching history' do |expected_status|
before do
get :history, params: { namespace_id: project.namespace, project_id: project, id: wiki_title }
end
it "returns status #{expected_status}" do
expect(response).to have_http_status(expected_status)
end
end
it_behaves_like 'fetching history', :ok do
let(:allow_read_wiki) { true }
it 'assigns @page_versions' do
expect(assigns(:page_versions)).to be_present
end
end
it_behaves_like 'fetching history', :not_found do
let(:allow_read_wiki) { false }
end
end
private
def create_page(name, content)
wiki.write_page(name, :markdown, content, commit_details(name))
end
def commit_details(name)
Gitlab::Git::Wiki::CommitDetails.new(user.id, user.username, user.name, user.email, "created page #{name}")
end
def destroy_page(title, dir = '')
page = wiki.page(title: title, dir: dir)
project_wiki.delete_page(page, "test commit")
end
end
Loading
Loading
@@ -4,10 +4,10 @@ require 'spec_helper'
 
describe Projects::WikisController do
let_it_be(:project) { create(:project, :public, :repository) }
let_it_be(:user) { project.owner }
let_it_be(:project_wiki) { ProjectWiki.new(project, user) }
let_it_be(:wiki) { project_wiki.wiki }
let_it_be(:wiki_title) { 'page title test' }
let(:user) { project.owner }
let(:project_wiki) { ProjectWiki.new(project, user) }
let(:wiki) { project_wiki.wiki }
let(:wiki_title) { 'page title test' }
 
before do
create_page(wiki_title, 'hello world')
Loading
Loading
@@ -19,86 +19,231 @@ describe Projects::WikisController do
destroy_page(wiki_title)
end
 
describe 'GET #pages' do
subject do
get :pages, params: { namespace_id: project.namespace, project_id: project, id: wiki_title }.merge(extra_params)
describe 'GET #new' do
subject { get :new, params: { namespace_id: project.namespace, project_id: project } }
it 'redirects to #show and appends a `random_title` param' do
subject
expect(response).to have_http_status(302)
expect(Rails.application.routes.recognize_path(response.redirect_url)).to include(
controller: 'projects/wikis',
action: 'show'
)
expect(response.redirect_url).to match(/\?random_title=true\Z/)
end
end
 
let(:extra_params) { {} }
describe 'GET #pages' do
subject { get :pages, params: { namespace_id: project.namespace, project_id: project, id: wiki_title } }
 
it 'does not load the pages content' do
expect(controller).to receive(:load_wiki).and_return(project_wiki)
expect(project_wiki).to receive(:list_pages).twice.and_call_original
 
subject
end
end
 
describe 'illegal params' do
shared_examples :a_bad_request do
it do
expect { subject }.to raise_error(ActionController::BadRequest)
end
end
describe 'GET #history' do
before do
allow(controller)
.to receive(:can?)
.with(any_args)
.and_call_original
 
describe ':sort' do
let(:extra_params) { { sort: 'wibble' } }
# The :create_wiki permission is irrelevant to reading history.
expect(controller)
.not_to receive(:can?)
.with(anything, :create_wiki, any_args)
 
it_behaves_like :a_bad_request
end
allow(controller)
.to receive(:can?)
.with(anything, :read_wiki, any_args)
.and_return(allow_read_wiki)
end
 
describe ':direction' do
let(:extra_params) { { direction: 'wibble' } }
shared_examples 'fetching history' do |expected_status|
before do
get :history, params: { namespace_id: project.namespace, project_id: project, id: wiki_title }
end
 
it_behaves_like :a_bad_request
it "returns status #{expected_status}" do
expect(response).to have_http_status(expected_status)
end
end
 
describe ':show_children' do
let(:extra_params) { { show_children: 'wibble' } }
it_behaves_like 'fetching history', :ok do
let(:allow_read_wiki) { true }
 
it_behaves_like :a_bad_request
it 'assigns @page_versions' do
expect(assigns(:page_versions)).to be_present
end
end
 
shared_examples 'sorting-and-nesting' do |sort_key, default_nesting|
context "the user is sorting by #{sort_key}" do
let(:extra_params) { sort_params.merge(nesting_params) }
let(:sort_params) { { sort: sort_key } }
let(:nesting_params) { {} }
it_behaves_like 'fetching history', :not_found do
let(:allow_read_wiki) { false }
end
end
describe 'GET #show' do
render_views
let(:random_title) { nil }
subject { get :show, params: { namespace_id: project.namespace, project_id: project, id: id, random_title: random_title } }
context 'when page exists' do
let(:id) { wiki_title }
it 'limits the retrieved pages for the sidebar' do
expect(controller).to receive(:load_wiki).and_return(project_wiki)
expect(project_wiki).to receive(:list_pages).with(limit: 15).and_call_original
subject
expect(response).to have_http_status(:ok)
expect(assigns(:page).title).to eq(wiki_title)
end
context 'when page content encoding is invalid' do
it 'sets flash error' do
allow(controller).to receive(:valid_encoding?).and_return(false)
 
before do
subject
expect(response).to have_http_status(:ok)
expect(flash[:notice]).to eq('The content of this page is not encoded in UTF-8. Edits can only be made via the Git repository.')
end
end
end
context 'when the page does not exist' do
let(:id) { 'does not exist' }
 
it "sets nesting to #{default_nesting} by default" do
expect(assigns :nesting).to eq default_nesting
before do
subject
end
it 'builds a new wiki page with the id as the title' do
expect(assigns(:page).title).to eq(id)
end
context 'when a random_title param is present' do
let(:random_title) { true }
it 'builds a new wiki page with no title' do
expect(assigns(:page).title).to be_empty
end
end
end
 
it 'hides children if the default requires it' do
expect(assigns :show_children).to be(default_nesting != ProjectWiki::NESTING_CLOSED)
context 'when page is a file' do
include WikiHelpers
let(:id) { upload_file_to_wiki(project, user, file_name) }
before do
subject
end
context 'when file is an image' do
let(:file_name) { 'dk.png' }
it 'delivers the image' do
expect(response.headers['Content-Disposition']).to match(/^inline/)
expect(response.headers[Gitlab::Workhorse::DETECT_HEADER]).to eq "true"
end
 
ProjectWiki::NESTINGS.each do |nesting|
context "the user explicitly passes show_children = #{nesting}" do
let(:nesting_params) { { show_children: nesting } }
context 'when file is a svg' do
let(:file_name) { 'unsanitized.svg' }
 
it 'sets nesting to the provided value' do
expect(assigns :nesting).to eq nesting
end
it 'delivers the image' do
expect(response.headers['Content-Disposition']).to match(/^inline/)
expect(response.headers[Gitlab::Workhorse::DETECT_HEADER]).to eq "true"
end
end
end
 
context 'the user wants children hidden' do
let(:nesting_params) { { show_children: 'hidden' } }
context 'when file is a pdf' do
let(:file_name) { 'git-cheat-sheet.pdf' }
 
it 'hides children' do
expect(assigns :show_children).to be false
end
it 'sets the content type to sets the content response headers' do
expect(response.headers['Content-Disposition']).to match(/^inline/)
expect(response.headers[Gitlab::Workhorse::DETECT_HEADER]).to eq "true"
end
end
end
end
describe 'POST #preview_markdown' do
it 'renders json in a correct format' do
post :preview_markdown, params: { namespace_id: project.namespace, project_id: project, id: 'page/path', text: '*Markdown* text' }
expect(json_response.keys).to match_array(%w(body references))
end
end
describe 'GET #edit' do
subject { get(:edit, params: { namespace_id: project.namespace, project_id: project, id: wiki_title }) }
context 'when page content encoding is invalid' do
it 'redirects to show' do
allow(controller).to receive(:valid_encoding?).and_return(false)
subject
expect(response).to redirect_to(project_wiki_path(project, project_wiki.list_pages.first))
end
end
 
include_examples 'sorting-and-nesting', ProjectWiki::CREATED_AT_ORDER, ProjectWiki::NESTING_FLAT
include_examples 'sorting-and-nesting', ProjectWiki::TITLE_ORDER, ProjectWiki::NESTING_CLOSED
context 'when page content encoding is valid' do
render_views
it 'shows the edit page' do
subject
expect(response).to have_http_status(:ok)
expect(response.body).to include('Edit Page')
end
end
end
describe 'PATCH #update' do
let(:new_title) { 'New title' }
let(:new_content) { 'New content' }
subject do
patch(:update,
params: {
namespace_id: project.namespace,
project_id: project,
id: wiki_title,
wiki: { title: new_title, content: new_content }
})
end
context 'when page content encoding is invalid' do
it 'redirects to show' do
allow(controller).to receive(:valid_encoding?).and_return(false)
subject
expect(response).to redirect_to(project_wiki_path(project, project_wiki.list_pages.first))
end
end
context 'when page content encoding is valid' do
render_views
it 'updates the page' do
subject
wiki_page = project_wiki.list_pages(load_content: true).first
expect(wiki_page.title).to eq new_title
expect(wiki_page.content).to eq new_content
end
end
end
 
def create_page(name, content)
Loading
Loading
Loading
Loading
@@ -18,12 +18,12 @@ FactoryBot.define do
association :wiki, factory: :project_wiki, strategy: :build
initialize_with { new(wiki, page, true) }
 
before(:create) do |wiki_page, evaluator|
wiki_page.attributes = evaluator.attrs.with_indifferent_access
before(:create) do |page, evaluator|
page.attributes = evaluator.attrs
end
 
to_create do |wiki_page|
wiki_page.create
to_create do |page|
page.create
end
end
end
Loading
Loading
@@ -3,9 +3,8 @@
require 'spec_helper'
 
describe 'Edit Project Settings' do
set(:project) { create(:project, :public, :repository) }
let(:member) { create(:user) }
let!(:project) { create(:project, :public, :repository) }
let!(:issue) { create(:issue, project: project) }
let(:non_member) { create(:user) }
 
Loading
Loading
@@ -82,88 +81,85 @@ describe 'Edit Project Settings' do
end
 
describe 'project features visibility pages' do
set(:pipeline) { create(:ci_empty_pipeline, project: project) }
set(:job) { create(:ci_build, pipeline: pipeline) }
where(:method_name, :build_url) do
[
[:builds, -> { project_job_path(project, job) }],
[:issues, -> { project_issues_path(project) }],
[:wiki, -> { project_wiki_path(project, :home) }],
[:snippets, -> { project_snippets_path(project) }],
[:merge_requests, -> { project_merge_requests_path(project) }]
]
let(:pipeline) { create(:ci_empty_pipeline, project: project) }
let(:job) { create(:ci_build, pipeline: pipeline) }
let(:tools) do
{
builds: project_job_path(project, job),
issues: project_issues_path(project),
wiki: project_wiki_path(project, :home),
snippets: project_snippets_path(project),
merge_requests: project_merge_requests_path(project)
}
end
 
with_them do
let(:url) { build_url.call }
let(:attr_name) { "#{method_name}_access_level" }
context 'normal user' do
before do
project.team.truncate
sign_in(member)
end
it 'renders 200 if tool is enabled' do
project.project_feature.update_attribute(attr_name, ProjectFeature::ENABLED)
context 'normal user' do
before do
sign_in(member)
end
 
it 'renders 200 if tool is enabled' do
tools.each do |method_name, url|
project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::ENABLED)
visit url
expect(page.status_code).to eq(200)
end
end
 
it 'renders 404 if feature is disabled' do
project.project_feature.update_attribute(attr_name, ProjectFeature::DISABLED)
it 'renders 404 if feature is disabled' do
tools.each do |method_name, url|
project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::DISABLED)
visit url
expect(page.status_code).to eq(404)
end
end
 
it 'renders 404 if feature is enabled only for team members' do
project.project_feature.update_attribute(attr_name, ProjectFeature::PRIVATE)
it 'renders 404 if feature is enabled only for team members' do
project.team.truncate
 
tools.each do |method_name, url|
project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::PRIVATE)
visit url
expect(page.status_code).to eq(404)
end
end
 
it 'renders 200 if user is member of group' do
group = create(:group)
project.group = group
project.save
group.add_owner(member)
it 'renders 200 if user is member of group' do
group = create(:group)
project.group = group
project.save
 
project.project_feature.update_attribute(attr_name, ProjectFeature::PRIVATE)
group.add_owner(member)
 
tools.each do |method_name, url|
project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::PRIVATE)
visit url
expect(page.status_code).to eq(200)
end
end
end
 
context 'admin user' do
before do
non_member.update_attribute(:admin, true)
project.team.truncate
sign_in(non_member)
end
context 'admin user' do
before do
non_member.update_attribute(:admin, true)
sign_in(non_member)
end
 
it 'renders 404 if feature is disabled' do
it 'renders 404 if feature is disabled' do
tools.each do |method_name, url|
project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::DISABLED)
visit url
expect(page.status_code).to eq(404)
end
end
 
it 'renders 200 if feature is enabled only for team members' do
project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::PRIVATE)
it 'renders 200 if feature is enabled only for team members' do
project.team.truncate
 
tools.each do |method_name, url|
project.project_feature.update_attribute("#{method_name}_access_level", ProjectFeature::PRIVATE)
visit url
expect(page.status_code).to eq(200)
end
end
Loading
Loading
Loading
Loading
@@ -4,54 +4,164 @@ require 'spec_helper'
 
describe 'Projects > Wiki > User previews markdown changes', :js do
set(:user) { create(:user) }
set(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
let(:project_wiki) { ProjectWiki.new(project, user) }
let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
let(:wiki_page) { create(:wiki_page, wiki: project.wiki, attrs: { title: 'home', content: '[some link](other-page)' }) }
let(:wiki_content) do
<<-HEREDOC
[regular link](regular)
[relative link 1](../relative)
[relative link 2](./relative)
[relative link 3](./e/f/relative)
[spaced link](title with spaces)
HEREDOC
end
 
before do
project.add_maintainer(user)
sign_in(user)
init_home!
end
 
def init_home!
create(:wiki_page, wiki: project.wiki, attrs: { title: 'home', content: '[some link](other-page)' })
end
context "while creating a new wiki page" do
context "when there are no spaces or hyphens in the page name" do
it "rewrites relative links as expected" do
create_wiki_page('a/b/c/d', content: wiki_content)
 
def fill_in_content!
page.within '.wiki-form' do
fill_in :wiki_page_content, with: wiki_content
expect(page).to have_content("regular link")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/relative\">relative link 1</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/relative\">relative link 2</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/e/f/relative\">relative link 3</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
end
end
end
 
def show_preview!
page.within '.wiki-form' do
click_on 'Preview'
context "when there are spaces in the page name" do
it "rewrites relative links as expected" do
create_wiki_page('a page/b page/c page/d page', content: wiki_content)
expect(page).to have_content("regular link")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
end
end
end
 
context 'when writing a new page' do
let(:new_wiki_path) { 'a/b/c/d' }
let(:wiki_content) { 'Some [awesome wiki](content)' }
context "when there are hyphens in the page name" do
it "rewrites relative links as expected" do
create_wiki_page('a-page/b-page/c-page/d-page', content: wiki_content)
 
it 'can show a preview of markdown content' do
visit project_wiki_pages_new_path(project, id: new_wiki_path)
fill_in_content!
show_preview!
expect(page).to have_content("regular link")
 
expect(page).to have_link('awesome wiki')
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
end
end
end
 
context 'when editing an existing page' do
let(:wiki_content) { 'Some [bemusing](content)' }
let(:wiki_page) { create(:wiki_page, wiki: project_wiki) }
context "while editing a wiki page" do
context "when there are no spaces or hyphens in the page name" do
it "rewrites relative links as expected" do
create_wiki_page('a/b/c/d')
click_link 'Edit'
fill_in :wiki_content, with: wiki_content
click_on "Preview"
expect(page).to have_content("regular link")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/relative\">relative link 1</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/relative\">relative link 2</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/e/f/relative\">relative link 3</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
end
end
context "when there are spaces in the page name" do
it "rewrites relative links as expected" do
create_wiki_page('a page/b page/c page/d page')
click_link 'Edit'
fill_in :wiki_content, with: wiki_content
click_on "Preview"
expect(page).to have_content("regular link")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
end
end
context "when there are hyphens in the page name" do
it "rewrites relative links as expected" do
create_wiki_page('a-page/b-page/c-page/d-page')
click_link 'Edit'
fill_in :wiki_content, with: wiki_content
click_on "Preview"
 
it 'can show a preview of markdown content, when writing' do
visit project_wiki_edit_path(project, wiki_page)
fill_in_content!
show_preview!
expect(page).to have_content("regular link")
 
expect(page).to have_link('bemusing')
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>")
expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>")
end
end
context 'when rendering the preview' do
it 'renders content with CommonMark' do
create_wiki_page('a-page/b-page/c-page/common-mark')
click_link 'Edit'
fill_in :wiki_content, with: "1. one\n - sublist\n"
click_on "Preview"
# the above generates two separate lists (not embedded) in CommonMark
expect(page).to have_content("sublist")
expect(page).not_to have_xpath("//ol//li//ul")
end
end
end
it "does not linkify double brackets inside code blocks as expected" do
wiki_content = <<-HEREDOC
`[[do_not_linkify]]`
```
[[also_do_not_linkify]]
```
HEREDOC
create_wiki_page('linkify_test', wiki_content)
expect(page).to have_content("do_not_linkify")
expect(page.html).to include('[[do_not_linkify]]')
expect(page.html).to include('[[also_do_not_linkify]]')
end
private
def create_wiki_page(path, content = 'content')
visit project_wiki_path(project, wiki_page)
click_link 'New page'
fill_in :wiki_title, with: path
fill_in :wiki_content, with: content
click_button 'Create page'
end
end
Loading
Loading
@@ -3,15 +3,9 @@
require "spec_helper"
 
describe "User creates wiki page" do
include CapybaraHelpers
include WikiHelpers
set(:user) { create(:user) }
let(:project) { create(:project) }
let(:user) { create(:user) }
let(:wiki) { ProjectWiki.new(project, user) }
let(:new_page) { WikiPage.new(wiki) }
let(:message_field) { form_field_name(new_page, :message) }
let(:project) { create(:project) }
 
before do
project.add_maintainer(user)
Loading
Loading
@@ -19,76 +13,36 @@ describe "User creates wiki page" do
sign_in(user)
end
 
def start_writing(page_path)
click_link("New page")
fill_in(:wiki_page_title, with: page_path)
end
def create_page(attrs = {})
page.within(".wiki-form") do
attrs.each do |k, v|
fill_in("wiki_page_#{k}".to_sym, with: v)
end
end
click_on("Create page")
end
shared_examples 'updates commit message' do
describe 'commit message', :js do
it "has `Create home` as a commit message" do
wait_for_requests
expect(page).to have_field(message_field, with: "Create home")
end
end
end
context "when wiki is empty" do
before do
visit(project_wikis_path(project))
 
click_link "Create your first page"
find('.wiki-form')
end
 
context "in a user namespace" do
let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
let(:wiki_page_content) { '' }
 
it "shows validation error message" do
create_page
expect(page)
.to have_content("The form contains the following error:")
.and have_content("Content can't be blank")
.and have_css('.wiki-form')
.and have_css('.qa-create-page-button')
end
it 'offers to create pages that do not yet exist' do
create_page(content: "[link test](test)")
page.within(".wiki-form") do
fill_in(:wiki_content, with: "")
 
expect(page)
.to have_content("Home")
.and have_content("link test")
click_on("Create page")
end
 
click_link("link test")
expect(page).to have_content("The form contains the following error:").and have_content("Content can't be blank")
 
expect(page).to have_content("Create New Page")
end
page.within(".wiki-form") do
fill_in(:wiki_content, with: "[link test](test)")
 
it "has a link to the parent directory in the pages sidebar" do
wiki_full_path = "one/two/three-test"
create_page(title: wiki_full_path, content: 'wiki content')
click_on("Create page")
end
 
wiki_page = wiki.find_page(wiki_full_path)
expect(wiki_page).to be_present
dir = wiki.find_dir(wiki_page.directory)
expect(dir).to be_present
expect(page).to have_content("Home").and have_content("link test")
 
expect(current_path).to include(wiki_full_path)
click_link("link test")
 
expect(page).to have_link(dir.slug, href: project_wiki_dir_path(project, dir))
expect(page).to have_content("Create New Page")
end
 
it "shows non-escaped link in the pages list", :quarantine do
Loading
Loading
@@ -104,17 +58,19 @@ describe "User creates wiki page" do
expect(page).to have_xpath("//a[@href='/#{project.full_path}/wikis/one/two/three-test']")
end
 
it_behaves_like 'updates commit message'
it "has `Create home` as a commit message", :js do
wait_for_requests
expect(page).to have_field("wiki[message]", with: "Create home")
end
 
it "creates a page from the home page" do
page_content = <<~WIKI_CONTENT
[test](test)
[GitLab API doc](api)
[Rake tasks](raketasks)
# Wiki header
WIKI_CONTENT
fill_in(:wiki_content, with: "[test](test)\n[GitLab API doc](api)\n[Rake tasks](raketasks)\n# Wiki header\n")
fill_in(:wiki_message, with: "Adding links to wiki")
 
create_page(content: page_content, message: "Adding links to wiki")
page.within(".wiki-form") do
click_button("Create page")
end
 
expect(current_path).to eq(project_wiki_path(project, "home"))
expect(page).to have_content("test GitLab API doc Rake tasks Wiki header")
Loading
Loading
@@ -155,7 +111,7 @@ describe "User creates wiki page" do
end
end
 
it "creates ASCIIdoc wiki with LaTeX blocks", :js do
it "creates ASCII wiki with LaTeX blocks", :js do
stub_application_setting(plantuml_url: "http://localhost", plantuml_enabled: true)
 
ascii_content = <<~MD
Loading
Loading
@@ -176,25 +132,37 @@ describe "User creates wiki page" do
stem:[2+2] is 4
MD
 
find("#wiki_page_format option[value=asciidoc]").select_option
find("#wiki_format option[value=asciidoc]").select_option
fill_in(:wiki_content, with: ascii_content)
 
create_page(content: ascii_content)
page.within(".wiki-form") do
click_button("Create page")
end
 
page.within ".md" do
expect(page).to have_selector(".katex", count: 3).and have_content("2+2 is 4")
end
end
 
it_behaves_like 'wiki file attachments'
it_behaves_like 'wiki file attachments', :quarantine
end
 
context "in a group namespace" do
context "in a group namespace", :js do
let(:project) { create(:project, :wiki_repo, namespace: create(:group, :public)) }
 
it_behaves_like 'updates commit message'
it "has `Create home` as a commit message" do
wait_for_requests
 
it "creates a page from the home page" do
create_page(content: "My awesome wiki!")
expect(page).to have_field("wiki[message]", with: "Create home")
end
it "creates a page from the home page", :quarantine do
page.within(".wiki-form") do
fill_in(:wiki_content, with: "My awesome wiki!")
click_button("Create page")
end
 
expect(page).to have_content("Home")
.and have_content("Last edited by #{user.name}")
Loading
Loading
@@ -210,37 +178,76 @@ describe "User creates wiki page" do
visit(project_wikis_path(project))
end
 
shared_examples 'creates page by slug' do |slug, unslug|
it "creates #{slug}" do
start_writing(slug)
context "in a user namespace" do
let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
 
# Commit message field should have correct value.
expect(page).to have_field(message_field, with: "Create #{unslug}")
context "via the `new wiki page` page" do
it "creates a page with a single word" do
click_link("New page")
 
create_page(content: "My awesome wiki!")
page.within(".wiki-form") do
fill_in(:wiki_title, with: "foo")
fill_in(:wiki_content, with: "My awesome wiki!")
end
 
expect(page).to have_content(unslug)
.and have_content("Last edited by #{user.name}")
.and have_content("My awesome wiki!")
end
end
# Commit message field should have correct value.
expect(page).to have_field("wiki[message]", with: "Create foo")
 
context "in a user namespace" do
let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
click_button("Create page")
 
context "via the `new wiki page` page" do
include_examples 'creates page by slug', 'foo', 'foo'
include_examples 'creates page by slug', 'Spaces in the name', 'Spaces in the name'
include_examples 'creates page by slug', 'Hyphens-in-the-name', 'Hyphens in the name'
expect(page).to have_content("foo")
.and have_content("Last edited by #{user.name}")
.and have_content("My awesome wiki!")
end
it "creates a page with spaces in the name" do
click_link("New page")
page.within(".wiki-form") do
fill_in(:wiki_title, with: "Spaces in the name")
fill_in(:wiki_content, with: "My awesome wiki!")
end
# Commit message field should have correct value.
expect(page).to have_field("wiki[message]", with: "Create Spaces in the name")
click_button("Create page")
expect(page).to have_content("Spaces in the name")
.and have_content("Last edited by #{user.name}")
.and have_content("My awesome wiki!")
end
it "creates a page with hyphens in the name" do
click_link("New page")
page.within(".wiki-form") do
fill_in(:wiki_title, with: "hyphens-in-the-name")
fill_in(:wiki_content, with: "My awesome wiki!")
end
# Commit message field should have correct value.
expect(page).to have_field("wiki[message]", with: "Create hyphens in the name")
page.within(".wiki-form") do
fill_in(:wiki_content, with: "My awesome wiki!")
click_button("Create page")
end
expect(page).to have_content("hyphens in the name")
.and have_content("Last edited by #{user.name}")
.and have_content("My awesome wiki!")
end
end
 
it "shows the emoji autocompletion dropdown" do
start_writing('text-autocomplete')
click_link("New page")
 
page.within(".wiki-form") do
find("#wiki_page_content").native.send_keys("")
find("#wiki_content").native.send_keys("")
 
fill_in(:wiki_page_content, with: ":")
fill_in(:wiki_content, with: ":")
end
 
expect(page).to have_selector(".atwho-view")
Loading
Loading
@@ -251,9 +258,23 @@ describe "User creates wiki page" do
let(:project) { create(:project, :wiki_repo, namespace: create(:group, :public)) }
 
context "via the `new wiki page` page" do
include_examples 'creates page by slug', 'foo', 'foo'
include_examples 'creates page by slug', 'Spaces in the name', 'Spaces in the name'
include_examples 'creates page by slug', 'Hyphens-in-the-name', 'Hyphens in the name'
it "creates a page" do
click_link("New page")
page.within(".wiki-form") do
fill_in(:wiki_title, with: "foo")
fill_in(:wiki_content, with: "My awesome wiki!")
end
# Commit message field should have correct value.
expect(page).to have_field("wiki[message]", with: "Create foo")
click_button("Create page")
expect(page).to have_content("foo")
.and have_content("Last edited by #{user.name}")
.and have_content("My awesome wiki!")
end
end
end
end
Loading
Loading
Loading
Loading
@@ -6,7 +6,6 @@ describe 'User deletes wiki page', :js do
let(:user) { create(:user) }
let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
let(:wiki_page) { create(:wiki_page, wiki: project.wiki) }
let(:project_wiki) { ProjectWiki.new(project, user) }
 
before do
sign_in(user)
Loading
Loading
@@ -19,6 +18,5 @@ describe 'User deletes wiki page', :js do
find('.modal-footer .btn-danger').click
 
expect(page).to have_content('Page was successfully deleted')
expect(project_wiki.find_page(wiki_page.slug)).to be nil
end
end
Loading
Loading
@@ -10,13 +10,6 @@ describe 'User updates wiki page' do
sign_in(user)
end
 
def create_page(attrs = {})
page.within('.wiki-form') do
attrs.each { |k, v| fill_in("wiki_page_#{k}".to_sym, with: v) }
click_on('Create page')
end
end
context 'when wiki is empty' do
before do
visit(project_wikis_path(project))
Loading
Loading
@@ -35,7 +28,12 @@ describe 'User updates wiki page' do
end
 
it 'updates a page that has a path', :js do
create_page(title: 'one/two/three-test', content: 'wiki content')
fill_in(:wiki_title, with: 'one/two/three-test')
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')
Loading
Loading
@@ -74,9 +72,9 @@ describe 'User updates wiki page' do
 
it 'updates a page', :js do
# Commit message field should have correct value.
expect(page).to have_field('wiki_page[message]', with: 'Update home')
expect(page).to have_field('wiki[message]', with: 'Update home')
 
fill_in(:wiki_page_content, with: 'My awesome wiki!')
fill_in(:wiki_content, with: 'My awesome wiki!')
click_button('Save changes')
 
expect(page).to have_content('Home')
Loading
Loading
@@ -85,31 +83,31 @@ describe 'User updates wiki page' do
end
 
it 'updates the commit message as the title is changed', :js do
fill_in(:wiki_page_title, with: 'Wiki title')
fill_in(:wiki_title, with: 'Wiki title')
 
expect(page).to have_field('wiki_page[message]', with: 'Update Wiki title')
expect(page).to have_field('wiki[message]', with: 'Update Wiki title')
end
 
it 'does not allow XSS', :js do
fill_in(:wiki_page_title, with: '<script>')
fill_in(:wiki_title, with: '<script>')
 
expect(page).to have_field('wiki_page[message]', with: 'Update &lt;script&gt;')
expect(page).to have_field('wiki[message]', with: 'Update &lt;script&gt;')
end
 
it 'shows a validation error message' do
fill_in(:wiki_page_content, with: '')
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_page_content').value).to eq('')
expect(find('textarea#wiki_content').value).to eq('')
end
 
it 'shows the emoji autocompletion dropdown', :js do
find('#wiki_page_content').native.send_keys('')
fill_in(:wiki_page_content, with: ':')
find('#wiki_content').native.send_keys('')
fill_in(:wiki_content, with: ':')
 
expect(page).to have_selector('.atwho-view')
end
Loading
Loading
@@ -145,9 +143,9 @@ describe 'User updates wiki page' do
 
it 'updates a page', :js do
# Commit message field should have correct value.
expect(page).to have_field('wiki_page[message]', with: 'Update home')
expect(page).to have_field('wiki[message]', with: 'Update home')
 
fill_in(:wiki_page_content, with: 'My awesome wiki!')
fill_in(:wiki_content, with: 'My awesome wiki!')
 
click_button('Save changes')
 
Loading
Loading
@@ -171,43 +169,50 @@ describe 'User updates wiki page' do
visit(project_wiki_edit_path(project, wiki_page))
end
 
def edit_title!(title)
fill_in(:wiki_page_title, with: title)
it 'moves the page to the root folder' do
fill_in(:wiki_title, with: "/#{page_name}")
 
click_button('Save changes')
end
it 'moves the page to the root folder' do
edit_title!("/#{page_name}")
 
expect(current_path).to eq(project_wiki_path(project, page_name))
end
 
it 'moves the page to other dir' do
new_page_path = "baz/quux/#{page_name}"
edit_title!(new_page_path)
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_path))
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)
edit_title!(page_name)
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_path = "quux/baz/new_page_name"
edit_title!(new_page_path)
new_page_dir = "foo1/bar1/new_page_name"
fill_in(:wiki_title, with: new_page_dir)
 
expect(current_path).to eq(project_wiki_path(project, new_page_path))
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'
 
edit_title!("/#{new_name}")
fill_in(:wiki_title, with: "/#{new_name}")
click_button('Save changes')
 
expect(current_path).to eq(project_wiki_path(project, new_name))
end
Loading
Loading
@@ -215,7 +220,9 @@ describe 'User updates wiki page' do
it 'squishes the title before creating the page' do
new_page_dir = " foo1 / bar1 / #{page_name} "
 
edit_title!(new_page_dir)
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
Loading
Loading
Loading
Loading
@@ -8,11 +8,10 @@ describe 'User views a wiki page' do
let(:user) { create(:user) }
let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
let(:path) { 'image.png' }
let(:wiki_content) { "Look at this [image](#{path})\n\n ![alt text](#{path})" }
let(:wiki_page) do
create(:wiki_page,
wiki: project.wiki,
attrs: { title: 'home', content: wiki_content })
attrs: { title: 'home', content: "Look at this [image](#{path})\n\n ![alt text](#{path})" })
end
 
before do
Loading
Loading
@@ -20,18 +19,17 @@ describe 'User views a wiki page' do
sign_in(user)
end
 
def create_page(attrs = {})
page.within('.wiki-form') do
attrs.each { |k, v| fill_in("wiki_page_#{k}".to_sym, with: v) }
click_on('Create page')
end
end
context 'when wiki is empty' do
before do
visit(project_wikis_path(project))
click_link "Create your first page"
create_page(title: 'one/two/three-test', content: 'wiki content')
fill_in(:wiki_title, with: 'one/two/three-test')
page.within('.wiki-form') do
fill_in(:wiki_content, with: 'wiki content')
click_on('Create page')
end
end
 
it 'shows the history of a page that has a path', :js do
Loading
Loading
@@ -85,27 +83,24 @@ describe 'User views a wiki page' do
 
context 'shows a file stored in a page' do
let(:path) { upload_file_to_wiki(project, user, 'dk.png') }
let(:image_path) { project_wiki_path(project, path) }
 
it do
expect(page).to have_xpath("//img[@data-src='#{image_path}']")
expect(page).to have_link('image', href: "#{image_path}")
expect(page).to have_xpath("//img[@data-src='#{project.wiki.wiki_base_path}/#{path}']")
expect(page).to have_link('image', href: "#{project.wiki.wiki_base_path}/#{path}")
 
click_on('image')
 
expect(current_path).to match(path)
expect(current_path).to match("wikis/#{path}")
expect(page).not_to have_xpath('/html') # Page should render the image which means there is no html involved
end
end
 
it 'shows the creation page if file does not exist' do
href = project_wiki_path(project, path)
expect(page).to have_link('image', href: href)
expect(page).to have_link('image', href: "#{project.wiki.wiki_base_path}/#{path}")
 
click_on('image')
 
expect(current_path).to match(href)
expect(current_path).to match("wikis/#{path}")
expect(page).to have_content('Create New Page')
end
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment