2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-03-03 22:43:52 -05:00
|
|
|
require "spec_helper"
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe ProjectWiki do
|
2018-09-17 09:36:22 -04:00
|
|
|
let(:user) { create(:user, :commit_email) }
|
|
|
|
let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
|
2013-03-03 22:43:52 -05:00
|
|
|
let(:repository) { project.repository }
|
|
|
|
let(:gitlab_shell) { Gitlab::Shell.new }
|
2017-07-25 13:09:00 -04:00
|
|
|
let(:project_wiki) { described_class.new(project, user) }
|
2018-12-23 02:34:35 -05:00
|
|
|
let(:raw_repository) { Gitlab::Git::Repository.new(project.repository_storage, subject.disk_path + '.git', 'foo', 'group/project.wiki') }
|
2018-09-17 09:36:22 -04:00
|
|
|
let(:commit) { project_wiki.repository.head_commit }
|
2013-03-03 22:43:52 -05:00
|
|
|
|
2014-07-31 12:24:53 -04:00
|
|
|
subject { project_wiki }
|
2017-06-14 14:18:56 -04:00
|
|
|
|
2018-04-13 06:57:19 -04:00
|
|
|
it { is_expected.to delegate_method(:repository_storage).to :project }
|
2017-11-15 09:20:36 -05:00
|
|
|
it { is_expected.to delegate_method(:hashed_storage?).to :project }
|
|
|
|
|
2018-03-05 08:41:54 -05:00
|
|
|
describe "#full_path" do
|
2013-03-03 22:43:52 -05:00
|
|
|
it "returns the project path with namespace with the .wiki extension" do
|
2018-03-05 08:41:54 -05:00
|
|
|
expect(subject.full_path).to eq(project.full_path + '.wiki')
|
2017-07-21 20:37:22 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the same value as #full_path' do
|
2018-03-05 08:41:54 -05:00
|
|
|
expect(subject.full_path).to eq(subject.full_path)
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-13 03:21:01 -04:00
|
|
|
describe '#web_url' do
|
|
|
|
it 'returns the full web URL to the wiki' do
|
2017-07-21 20:37:22 -04:00
|
|
|
expect(subject.web_url).to eq("#{Gitlab.config.gitlab.url}/#{project.full_path}/wikis/home")
|
2016-05-13 03:21:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-03 22:43:52 -05:00
|
|
|
describe "#url_to_repo" do
|
|
|
|
it "returns the correct ssh url to the repo" do
|
2017-07-21 20:37:22 -04:00
|
|
|
expect(subject.url_to_repo).to eq(gitlab_shell.url_to_repo(subject.full_path))
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#ssh_url_to_repo" do
|
|
|
|
it "equals #url_to_repo" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(subject.ssh_url_to_repo).to eq(subject.url_to_repo)
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#http_url_to_repo" do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create :project }
|
2017-03-20 05:56:43 -04:00
|
|
|
|
2017-05-30 08:18:58 -04:00
|
|
|
it 'returns the full http url to the repo' do
|
2017-07-21 20:37:22 -04:00
|
|
|
expected_url = "#{Gitlab.config.gitlab.url}/#{subject.full_path}.git"
|
2017-03-20 05:56:43 -04:00
|
|
|
|
2017-05-30 08:18:58 -04:00
|
|
|
expect(project_wiki.http_url_to_repo).to eq(expected_url)
|
|
|
|
expect(project_wiki.http_url_to_repo).not_to include('@')
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-11 23:05:18 -05:00
|
|
|
describe "#wiki_base_path" do
|
|
|
|
it "returns the wiki base path" do
|
2017-07-21 20:37:22 -04:00
|
|
|
wiki_base_path = "#{Gitlab.config.gitlab.relative_url_root}/#{project.full_path}/wikis"
|
2016-05-03 11:33:43 -04:00
|
|
|
|
2016-01-11 23:05:18 -05:00
|
|
|
expect(subject.wiki_base_path).to eq(wiki_base_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-03 22:43:52 -05:00
|
|
|
describe "#wiki" do
|
2017-10-03 12:58:33 -04:00
|
|
|
it "contains a Gitlab::Git::Wiki instance" do
|
|
|
|
expect(subject.wiki).to be_a Gitlab::Git::Wiki
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "creates a new wiki repo if one does not yet exist" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(project_wiki.create_page("index", "test content")).to be_truthy
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
2019-03-17 00:30:30 -04:00
|
|
|
it "creates a new wiki repo with a default commit message" do
|
|
|
|
expect(project_wiki.create_page("index", "test content", :markdown, "")).to be_truthy
|
|
|
|
|
|
|
|
page = project_wiki.find_page('index')
|
|
|
|
|
|
|
|
expect(page.last_version.message).to eq("#{user.username} created page: index")
|
|
|
|
end
|
|
|
|
|
2013-03-03 22:43:52 -05:00
|
|
|
it "raises CouldNotCreateWikiError if it can't create the wiki repository" do
|
2017-10-03 12:58:33 -04:00
|
|
|
# Create a fresh project which will not have a wiki
|
|
|
|
project_wiki = described_class.new(create(:project), user)
|
|
|
|
gitlab_shell = double(:gitlab_shell)
|
2019-01-17 16:50:18 -05:00
|
|
|
allow(gitlab_shell).to receive(:create_wiki_repository)
|
2017-10-03 12:58:33 -04:00
|
|
|
allow(project_wiki).to receive(:gitlab_shell).and_return(gitlab_shell)
|
|
|
|
|
|
|
|
expect { project_wiki.send(:wiki) }.to raise_exception(ProjectWiki::CouldNotCreateWikiError)
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-09 11:14:55 -04:00
|
|
|
describe "#empty?" do
|
|
|
|
context "when the wiki repository is empty" do
|
2015-02-12 13:17:35 -05:00
|
|
|
describe '#empty?' do
|
|
|
|
subject { super().empty? }
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
2013-10-09 11:14:55 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when the wiki has pages" do
|
|
|
|
before do
|
2015-02-12 13:17:35 -05:00
|
|
|
project_wiki.create_page("index", "This is an awesome new Gollum Wiki")
|
2018-07-12 02:19:20 -04:00
|
|
|
project_wiki.create_page("another-page", "This is another page")
|
2013-10-09 11:14:55 -04:00
|
|
|
end
|
|
|
|
|
2015-02-12 13:17:35 -05:00
|
|
|
describe '#empty?' do
|
|
|
|
subject { super().empty? }
|
|
|
|
it { is_expected.to be_falsey }
|
2018-07-12 02:19:20 -04:00
|
|
|
|
|
|
|
# Re-enable this when https://gitlab.com/gitlab-org/gitaly/issues/1204 is fixed
|
|
|
|
xit 'only instantiates a Wiki page once' do
|
|
|
|
expect(WikiPage).to receive(:new).once.and_call_original
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
2015-02-12 13:17:35 -05:00
|
|
|
end
|
2013-10-09 11:14:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-03 22:43:52 -05:00
|
|
|
describe "#pages" do
|
|
|
|
before do
|
|
|
|
create_page("index", "This is an awesome new Gollum Wiki")
|
|
|
|
@pages = subject.pages
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
destroy_page(@pages.first.page)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an array of WikiPage instances" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@pages.first).to be_a WikiPage
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns the correct number of pages" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@pages.count).to eq(1)
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#find_page" do
|
2018-11-20 07:29:56 -05:00
|
|
|
before do
|
|
|
|
create_page("index page", "This is an awesome Gollum Wiki")
|
|
|
|
end
|
2017-10-19 10:18:26 -04:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
after do
|
|
|
|
subject.pages.each { |page| destroy_page(page.page) }
|
|
|
|
end
|
2013-03-03 22:43:52 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it "returns the latest version of the page if it exists" do
|
|
|
|
page = subject.find_page("index page")
|
|
|
|
expect(page.title).to eq("index page")
|
|
|
|
end
|
2017-10-19 10:18:26 -04:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it "returns nil if the page does not exist" do
|
|
|
|
expect(subject.find_page("non-existent")).to eq(nil)
|
|
|
|
end
|
2018-02-05 06:26:25 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it "can find a page by slug" do
|
|
|
|
page = subject.find_page("index-page")
|
|
|
|
expect(page.title).to eq("index page")
|
|
|
|
end
|
2018-02-05 06:26:25 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it "returns a WikiPage instance" do
|
|
|
|
page = subject.find_page("index page")
|
|
|
|
expect(page).to be_a WikiPage
|
|
|
|
end
|
2018-11-20 05:36:52 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
context 'pages with multibyte-character title' do
|
|
|
|
before do
|
|
|
|
create_page("autre pagé", "C'est un génial Gollum Wiki")
|
2018-02-05 06:26:25 -05:00
|
|
|
end
|
2018-05-09 11:27:26 -04:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it "can find a page by slug" do
|
|
|
|
page = subject.find_page("autre pagé")
|
|
|
|
expect(page.title).to eq("autre pagé")
|
2018-05-09 11:27:26 -04:00
|
|
|
end
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
context 'pages with invalidly-encoded content' do
|
|
|
|
before do
|
|
|
|
create_page("encoding is fun", "f\xFCr".b)
|
|
|
|
end
|
2013-03-03 22:43:52 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it "can find the page" do
|
|
|
|
page = subject.find_page("encoding is fun")
|
|
|
|
expect(page.content).to eq("fr")
|
|
|
|
end
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-26 05:16:01 -04:00
|
|
|
describe '#find_sidebar' do
|
|
|
|
before do
|
|
|
|
create_page(described_class::SIDEBAR, 'This is an awesome Sidebar')
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
subject.pages.each { |page| destroy_page(page.page) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'finds the page defined as _sidebar' do
|
|
|
|
page = subject.find_page('_sidebar')
|
|
|
|
|
|
|
|
expect(page.content).to eq('This is an awesome Sidebar')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-03-28 16:15:25 -04:00
|
|
|
describe '#find_file' do
|
2018-11-20 07:29:56 -05:00
|
|
|
let(:image) { File.open(Rails.root.join('spec', 'fixtures', 'big-image.png')) }
|
2017-10-23 16:12:11 -04:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
before do
|
|
|
|
subject.wiki # Make sure the wiki repo exists
|
2018-04-11 10:08:23 -04:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
repo_path = Gitlab::GitalyClient::StorageSettings.allow_disk_access do
|
|
|
|
subject.repository.path_to_repo
|
2018-11-20 05:36:52 -05:00
|
|
|
end
|
2018-04-11 10:08:23 -04:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
BareRepoOperations.new(repo_path).commit_file(image, 'image.png')
|
|
|
|
end
|
2018-11-20 05:36:52 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it 'returns the latest version of the file if it exists' do
|
|
|
|
file = subject.find_file('image.png')
|
|
|
|
expect(file.mime_type).to eq('image/png')
|
|
|
|
end
|
2014-03-28 16:15:25 -04:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it 'returns nil if the page does not exist' do
|
|
|
|
expect(subject.find_file('non-existent')).to eq(nil)
|
2014-03-28 16:15:25 -04:00
|
|
|
end
|
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it 'returns a Gitlab::Git::WikiFile instance' do
|
|
|
|
file = subject.find_file('image.png')
|
|
|
|
expect(file).to be_a Gitlab::Git::WikiFile
|
2018-11-20 05:36:52 -05:00
|
|
|
end
|
2018-11-16 09:02:33 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it 'returns the whole file' do
|
|
|
|
file = subject.find_file('image.png')
|
|
|
|
image.rewind
|
|
|
|
|
|
|
|
expect(file.raw_data.b).to eq(image.read.b)
|
2014-03-28 16:15:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-03 22:43:52 -05:00
|
|
|
describe "#create_page" do
|
2018-11-20 07:29:56 -05:00
|
|
|
after do
|
|
|
|
destroy_page(subject.pages.first.page)
|
|
|
|
end
|
2018-09-17 09:36:22 -04:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it "creates a new wiki page" do
|
|
|
|
expect(subject.create_page("test page", "this is content")).not_to eq(false)
|
|
|
|
expect(subject.pages.count).to eq(1)
|
|
|
|
end
|
2015-11-15 14:32:28 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it "returns false when a duplicate page exists" do
|
|
|
|
subject.create_page("test page", "content")
|
|
|
|
expect(subject.create_page("test page", "content")).to eq(false)
|
|
|
|
end
|
2017-05-03 21:47:10 -04:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it "stores an error message when a duplicate page exists" do
|
|
|
|
2.times { subject.create_page("test page", "content") }
|
|
|
|
expect(subject.error_message).to match(/Duplicate page:/)
|
|
|
|
end
|
2017-10-13 09:11:53 -04:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it "sets the correct commit message" do
|
|
|
|
subject.create_page("test page", "some content", :markdown, "commit message")
|
|
|
|
expect(subject.pages.first.page.version.message).to eq("commit message")
|
|
|
|
end
|
2017-05-03 21:47:10 -04:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it 'sets the correct commit email' do
|
|
|
|
subject.create_page('test page', 'content')
|
2018-11-16 09:02:33 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
expect(user.commit_email).not_to eq(user.email)
|
|
|
|
expect(commit.author_email).to eq(user.commit_email)
|
|
|
|
expect(commit.committer_email).to eq(user.commit_email)
|
2018-11-20 05:36:52 -05:00
|
|
|
end
|
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it 'updates project activity' do
|
|
|
|
subject.create_page('Test Page', 'This is content')
|
2018-11-20 05:36:52 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
project.reload
|
|
|
|
|
|
|
|
expect(project.last_activity_at).to be_within(1.minute).of(Time.now)
|
|
|
|
expect(project.last_repository_updated_at).to be_within(1.minute).of(Time.now)
|
2015-11-15 14:32:28 -05:00
|
|
|
end
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#update_page" do
|
|
|
|
before do
|
|
|
|
create_page("update-page", "some content")
|
2017-10-03 12:58:33 -04:00
|
|
|
@gitlab_git_wiki_page = subject.wiki.page(title: "update-page")
|
2017-07-23 04:19:10 -04:00
|
|
|
subject.update_page(
|
2017-10-03 12:58:33 -04:00
|
|
|
@gitlab_git_wiki_page,
|
2017-07-23 04:19:10 -04:00
|
|
|
content: "some other content",
|
|
|
|
format: :markdown,
|
|
|
|
message: "updated page"
|
|
|
|
)
|
2013-03-03 22:43:52 -05:00
|
|
|
@page = subject.pages.first.page
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
destroy_page(@page)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "updates the content of the page" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@page.raw_data).to eq("some other content")
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the correct commit message" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@page.version.message).to eq("updated page")
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
2015-11-15 14:32:28 -05:00
|
|
|
|
2018-09-17 09:36:22 -04:00
|
|
|
it 'sets the correct commit email' do
|
2018-09-18 05:04:15 -04:00
|
|
|
expect(user.commit_email).not_to eq(user.email)
|
2018-09-17 09:36:22 -04:00
|
|
|
expect(commit.author_email).to eq(user.commit_email)
|
|
|
|
expect(commit.committer_email).to eq(user.commit_email)
|
|
|
|
end
|
|
|
|
|
2015-11-15 14:32:28 -05:00
|
|
|
it 'updates project activity' do
|
2017-07-23 04:19:10 -04:00
|
|
|
subject.update_page(
|
2017-10-03 12:58:33 -04:00
|
|
|
@gitlab_git_wiki_page,
|
2017-07-23 04:19:10 -04:00
|
|
|
content: 'Yet more content',
|
|
|
|
format: :markdown,
|
|
|
|
message: 'Updated page again'
|
|
|
|
)
|
2017-05-03 21:47:10 -04:00
|
|
|
|
|
|
|
project.reload
|
|
|
|
|
|
|
|
expect(project.last_activity_at).to be_within(1.minute).of(Time.now)
|
|
|
|
expect(project.last_repository_updated_at).to be_within(1.minute).of(Time.now)
|
2015-11-15 14:32:28 -05:00
|
|
|
end
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#delete_page" do
|
2018-11-20 07:29:56 -05:00
|
|
|
before do
|
|
|
|
create_page("index", "some content")
|
|
|
|
@page = subject.wiki.page(title: "index")
|
|
|
|
end
|
2017-10-31 06:38:15 -04:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it "deletes the page" do
|
|
|
|
subject.delete_page(@page)
|
|
|
|
expect(subject.pages.count).to eq(0)
|
|
|
|
end
|
2018-11-16 09:02:33 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it 'sets the correct commit email' do
|
|
|
|
subject.delete_page(@page)
|
2017-10-31 06:38:15 -04:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
expect(user.commit_email).not_to eq(user.email)
|
|
|
|
expect(commit.author_email).to eq(user.commit_email)
|
|
|
|
expect(commit.committer_email).to eq(user.commit_email)
|
2018-11-20 05:36:52 -05:00
|
|
|
end
|
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
it 'updates project activity' do
|
|
|
|
subject.delete_page(@page)
|
|
|
|
|
|
|
|
project.reload
|
2018-11-20 05:36:52 -05:00
|
|
|
|
2018-11-20 07:29:56 -05:00
|
|
|
expect(project.last_activity_at).to be_within(1.minute).of(Time.now)
|
|
|
|
expect(project.last_repository_updated_at).to be_within(1.minute).of(Time.now)
|
2015-11-15 14:32:28 -05:00
|
|
|
end
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
2016-03-18 10:31:19 -04:00
|
|
|
describe '#create_repo!' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
2016-03-18 10:31:19 -04:00
|
|
|
it 'creates a repository' do
|
2017-10-03 12:58:33 -04:00
|
|
|
expect(raw_repository.exists?).to eq(false)
|
2016-03-18 10:31:19 -04:00
|
|
|
expect(subject.repository).to receive(:after_create)
|
|
|
|
|
2017-10-03 12:58:33 -04:00
|
|
|
subject.send(:create_repo!, raw_repository)
|
|
|
|
|
|
|
|
expect(raw_repository.exists?).to eq(true)
|
2016-03-18 10:31:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-28 09:42:59 -04:00
|
|
|
describe '#ensure_repository' do
|
2018-05-04 05:45:16 -04:00
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
2017-06-28 09:42:59 -04:00
|
|
|
it 'creates the repository if it not exist' do
|
2017-10-03 12:58:33 -04:00
|
|
|
expect(raw_repository.exists?).to eq(false)
|
2017-06-28 09:42:59 -04:00
|
|
|
|
2017-10-03 12:58:33 -04:00
|
|
|
expect(subject).to receive(:create_repo!).and_call_original
|
2017-06-28 09:42:59 -04:00
|
|
|
subject.ensure_repository
|
2017-10-03 12:58:33 -04:00
|
|
|
|
|
|
|
expect(raw_repository.exists?).to eq(true)
|
2017-06-28 09:42:59 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create the repository if it exists' do
|
2017-10-03 12:58:33 -04:00
|
|
|
subject.wiki
|
|
|
|
expect(raw_repository.exists?).to eq(true)
|
2017-06-28 09:42:59 -04:00
|
|
|
|
|
|
|
expect(subject).not_to receive(:create_repo!)
|
|
|
|
|
|
|
|
subject.ensure_repository
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-05-13 03:21:01 -04:00
|
|
|
describe '#hook_attrs' do
|
|
|
|
it 'returns a hash with values' do
|
|
|
|
expect(subject.hook_attrs).to be_a Hash
|
|
|
|
expect(subject.hook_attrs.keys).to contain_exactly(:web_url, :git_ssh_url, :git_http_url, :path_with_namespace, :default_branch)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-31 12:24:53 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def create_temp_repo(path)
|
|
|
|
FileUtils.mkdir_p path
|
2015-11-03 17:10:38 -05:00
|
|
|
system(*%W(#{Gitlab.config.git.bin_path} init --quiet --bare -- #{path}))
|
2014-07-31 12:24:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def remove_temp_repo(path)
|
|
|
|
FileUtils.rm_rf path
|
|
|
|
end
|
|
|
|
|
|
|
|
def commit_details
|
2018-09-17 09:36:22 -04:00
|
|
|
Gitlab::Git::Wiki::CommitDetails.new(user.id, user.username, user.name, user.commit_email, "test commit")
|
2014-07-31 12:24:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_page(name, content)
|
|
|
|
subject.wiki.write_page(name, :markdown, content, commit_details)
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_page(page)
|
2017-10-31 06:38:15 -04:00
|
|
|
subject.delete_page(page, "test commit")
|
2014-07-31 12:24:53 -04:00
|
|
|
end
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|