2018-02-05 12:17:21 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::Git::Wiki do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
let(:user) { project.owner }
|
2018-02-07 11:33:12 -05:00
|
|
|
let(:project_wiki) { ProjectWiki.new(project, user) }
|
|
|
|
subject { project_wiki.wiki }
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2018-06-18 04:19:11 -04:00
|
|
|
describe '#page' do
|
2018-02-07 11:33:12 -05:00
|
|
|
before do
|
2018-02-05 12:17:21 -05:00
|
|
|
create_page('page1', 'content')
|
2018-02-07 11:33:12 -05:00
|
|
|
create_page('foo/page1', 'content foo/page1')
|
|
|
|
end
|
2018-02-05 12:17:21 -05:00
|
|
|
|
2018-02-07 11:33:12 -05:00
|
|
|
after do
|
2018-02-05 12:17:21 -05:00
|
|
|
destroy_page('page1')
|
|
|
|
destroy_page('page1', 'foo')
|
|
|
|
end
|
2018-02-07 11:33:12 -05:00
|
|
|
|
|
|
|
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
|
2018-02-05 12:17:21 -05:00
|
|
|
end
|
|
|
|
|
2018-06-18 04:19:11 -04:00
|
|
|
describe '#delete_page' do
|
2018-06-12 08:31:10 -04:00
|
|
|
after do
|
|
|
|
destroy_page('page1')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'only removes the page with the same path' do
|
|
|
|
create_page('page1', 'content')
|
|
|
|
create_page('*', 'content')
|
|
|
|
|
|
|
|
subject.delete_page('*', commit_details('whatever'))
|
|
|
|
|
|
|
|
expect(subject.pages.count).to eq 1
|
|
|
|
expect(subject.pages.first.title).to eq 'page1'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-05 12:17:21 -05:00
|
|
|
def create_page(name, content)
|
2018-02-07 11:33:12 -05:00
|
|
|
subject.write_page(name, :markdown, content, commit_details(name))
|
2018-02-05 12:17:21 -05:00
|
|
|
end
|
|
|
|
|
2018-02-07 11:33:12 -05:00
|
|
|
def commit_details(name)
|
2018-04-18 13:50:56 -04:00
|
|
|
Gitlab::Git::Wiki::CommitDetails.new(user.id, user.username, user.name, user.email, "created page #{name}")
|
2018-02-05 12:17:21 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_page(title, dir = '')
|
2018-02-07 11:33:12 -05:00
|
|
|
page = subject.page(title: title, dir: dir)
|
|
|
|
project_wiki.delete_page(page, "test commit")
|
2018-02-05 12:17:21 -05:00
|
|
|
end
|
|
|
|
end
|