Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/git/wiki_spec.rb')
-rw-r--r--spec/lib/gitlab/git/wiki_spec.rb63
1 files changed, 38 insertions, 25 deletions
diff --git a/spec/lib/gitlab/git/wiki_spec.rb b/spec/lib/gitlab/git/wiki_spec.rb
index dddcf8c40fc..05c7ac149e4 100644
--- a/spec/lib/gitlab/git/wiki_spec.rb
+++ b/spec/lib/gitlab/git/wiki_spec.rb
@@ -8,9 +8,15 @@ RSpec.describe Gitlab::Git::Wiki do
let(:project) { create(:project) }
let(:user) { project.first_owner }
let(:project_wiki) { ProjectWiki.new(project, user) }
+ let(:repository) { project_wiki.repository }
+ let(:default_branch) { described_class.default_ref(project) }
subject(:wiki) { project_wiki.wiki }
+ before do
+ repository.create_if_not_exists(project_wiki.default_branch)
+ end
+
describe '#pages' do
before do
create_page('page1', 'content')
@@ -44,7 +50,7 @@ RSpec.describe Gitlab::Git::Wiki do
after do
destroy_page('page1')
- destroy_page('page1', 'foo')
+ destroy_page('foo/page1')
end
it 'returns the right page' do
@@ -71,20 +77,20 @@ RSpec.describe Gitlab::Git::Wiki do
end
describe '#preview_slug' do
- where(:title, :format, :expected_slug) do
- 'The Best Thing' | :markdown | 'The-Best-Thing'
- 'The Best Thing' | :md | 'The-Best-Thing'
- 'The Best Thing' | :txt | 'The-Best-Thing'
- 'A Subject/Title Here' | :txt | 'A-Subject/Title-Here'
- 'A subject' | :txt | 'A-subject'
- 'A 1/B 2/C 3' | :txt | 'A-1/B-2/C-3'
- 'subject/title' | :txt | 'subject/title'
- 'subject/title.md' | :txt | 'subject/title.md'
- 'foo<bar>+baz' | :txt | 'foo-bar--baz'
- 'foo%2Fbar' | :txt | 'foo%2Fbar'
- '' | :markdown | '.md'
- '' | :md | '.md'
- '' | :txt | '.txt'
+ where(:title, :file_extension, :format, :expected_slug) do
+ 'The Best Thing' | :md | :markdown | 'The-Best-Thing'
+ 'The Best Thing' | :md | :md | 'The-Best-Thing'
+ 'The Best Thing' | :txt | :txt | 'The-Best-Thing'
+ 'A Subject/Title Here' | :txt | :txt | 'A-Subject/Title-Here'
+ 'A subject' | :txt | :txt | 'A-subject'
+ 'A 1/B 2/C 3' | :txt | :txt | 'A-1/B-2/C-3'
+ 'subject/title' | :txt | :txt | 'subject/title'
+ 'subject/title.md' | :txt | :txt | 'subject/title.md'
+ 'foo<bar>+baz' | :txt | :txt | 'foo-bar--baz'
+ 'foo%2Fbar' | :txt | :txt | 'foo%2Fbar'
+ '' | :md | :markdown | '.md'
+ '' | :md | :md | '.md'
+ '' | :txt | :txt | '.txt'
end
with_them do
@@ -97,7 +103,7 @@ RSpec.describe Gitlab::Git::Wiki do
it 'matches the slug generated by gitaly' do
skip('Gitaly cannot generate a slug for an empty title') unless title.present?
- create_page(title, 'content', format: format)
+ create_page(title, 'content', file_extension)
gitaly_slug = wiki.list_pages.first.url_path
@@ -106,16 +112,23 @@ RSpec.describe Gitlab::Git::Wiki do
end
end
- def create_page(name, content, format: :markdown)
- wiki.write_page(name, format, 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}")
+ def create_page(name, content, extension = :md)
+ repository.create_file(
+ user, ::Wiki.sluggified_full_path(name, extension.to_s), content,
+ branch_name: default_branch,
+ message: "created page #{name}",
+ author_email: user.email,
+ author_name: user.name
+ )
end
- def destroy_page(title, dir = '')
- page = wiki.page(title: title, dir: dir)
- project_wiki.delete_page(page, "test commit")
+ def destroy_page(name, extension = :md)
+ repository.delete_file(
+ user, ::Wiki.sluggified_full_path(name, extension.to_s),
+ branch_name: described_class.default_ref(project),
+ message: "delete page #{name}",
+ author_email: user.email,
+ author_name: user.name
+ )
end
end