2014-09-02 18:07:02 +05:30
|
|
|
require "spec_helper"
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
describe WikiPage, models: true do
|
2014-09-02 18:07:02 +05:30
|
|
|
let(:project) { create(:empty_project) }
|
|
|
|
let(:user) { project.owner }
|
|
|
|
let(:wiki) { ProjectWiki.new(project, user) }
|
|
|
|
|
|
|
|
subject { WikiPage.new(wiki) }
|
|
|
|
|
|
|
|
describe "#initialize" do
|
|
|
|
context "when initialized with an existing gollum page" do
|
|
|
|
before do
|
|
|
|
create_page("test page", "test content")
|
|
|
|
@page = wiki.wiki.paged("test page")
|
|
|
|
@wiki_page = WikiPage.new(wiki, @page, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the slug attribute" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@wiki_page.slug).to eq("test-page")
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the title attribute" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@wiki_page.title).to eq("test page")
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the formatted content attribute" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@wiki_page.content).to eq("test content")
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the format attribute" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@wiki_page.format).to eq(:markdown)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the message attribute" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@wiki_page.message).to eq("test commit")
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the version attribute" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@wiki_page.version).to be_a Gollum::Git::Commit
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "validations" do
|
|
|
|
before do
|
2015-09-11 14:41:01 +05:30
|
|
|
subject.attributes = { title: 'title', content: 'content' }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "validates presence of title" do
|
|
|
|
subject.attributes.delete(:title)
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.valid?).to be_falsey
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "validates presence of content" do
|
|
|
|
subject.attributes.delete(:content)
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.valid?).to be_falsey
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2015-09-11 14:41:01 +05:30
|
|
|
@wiki_attr = { title: "Index", content: "Home Page", format: "markdown" }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe "#create" do
|
|
|
|
after do
|
|
|
|
destroy_page("Index")
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with valid attributes" do
|
|
|
|
it "saves the wiki page" do
|
|
|
|
subject.create(@wiki_attr)
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(wiki.find_page("Index")).not_to be_nil
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(subject.create(@wiki_attr)).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "dot in the title" do
|
|
|
|
let(:title) { 'Index v1.2.3' }
|
|
|
|
|
|
|
|
before do
|
2015-09-11 14:41:01 +05:30
|
|
|
@wiki_attr = { title: title, content: "Home Page", format: "markdown" }
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe "#create" do
|
|
|
|
after do
|
|
|
|
destroy_page(title)
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with valid attributes" do
|
|
|
|
it "saves the wiki page" do
|
|
|
|
subject.create(@wiki_attr)
|
|
|
|
expect(wiki.find_page(title)).not_to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
|
|
|
expect(subject.create(@wiki_attr)).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#update" do
|
|
|
|
before do
|
|
|
|
create_page(title, "content")
|
|
|
|
@page = wiki.find_page(title)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "updates the content of the page" do
|
|
|
|
@page.update("new content")
|
|
|
|
@page = wiki.find_page(title)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
|
|
|
expect(@page.update("more content")).to be_truthy
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#update" do
|
|
|
|
before do
|
|
|
|
create_page("Update", "content")
|
|
|
|
@page = wiki.find_page("Update")
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
destroy_page("Update")
|
|
|
|
end
|
|
|
|
|
|
|
|
context "with valid attributes" do
|
|
|
|
it "updates the content of the page" do
|
|
|
|
@page.update("new content")
|
|
|
|
@page = wiki.find_page("Update")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@page.update("more content")).to be_truthy
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#destroy" do
|
|
|
|
before do
|
|
|
|
create_page("Delete Page", "content")
|
|
|
|
@page = wiki.find_page("Delete Page")
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "deletes the page" do
|
2014-09-02 18:07:02 +05:30
|
|
|
@page.delete
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(wiki.pages).to be_empty
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "returns true" do
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@page.delete).to eq(true)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#versions" do
|
|
|
|
before do
|
|
|
|
create_page("Update", "content")
|
|
|
|
@page = wiki.find_page("Update")
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
destroy_page("Update")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns an array of all commits for the page" do
|
|
|
|
3.times { |i| @page.update("content #{i}") }
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@page.versions.count).to eq(4)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#title" do
|
|
|
|
before do
|
|
|
|
create_page("Title", "content")
|
|
|
|
@page = wiki.find_page("Title")
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
destroy_page("Title")
|
|
|
|
end
|
|
|
|
|
2016-09-13 17:45:13 +05:30
|
|
|
it "replaces a hyphen to a space" do
|
2014-09-02 18:07:02 +05:30
|
|
|
@page.title = "Import-existing-repositories-into-GitLab"
|
2015-04-26 12:48:37 +05:30
|
|
|
expect(@page.title).to eq("Import existing repositories into GitLab")
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
describe '#historical?' do
|
|
|
|
before do
|
|
|
|
create_page('Update', 'content')
|
|
|
|
@page = wiki.find_page('Update')
|
|
|
|
3.times { |i| @page.update("content #{i}") }
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
destroy_page('Update')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true when requesting an old version' do
|
|
|
|
old_version = @page.versions.last.to_s
|
|
|
|
old_page = wiki.find_page('Update', old_version)
|
|
|
|
|
|
|
|
expect(old_page.historical?).to eq true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when requesting latest version' do
|
|
|
|
latest_version = @page.versions.first.to_s
|
|
|
|
latest_page = wiki.find_page('Update', latest_version)
|
|
|
|
|
|
|
|
expect(latest_page.historical?).to eq false
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false when version is nil' do
|
|
|
|
latest_page = wiki.find_page('Update', nil)
|
|
|
|
|
|
|
|
expect(latest_page.historical?).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def remove_temp_repo(path)
|
|
|
|
FileUtils.rm_rf path
|
|
|
|
end
|
|
|
|
|
|
|
|
def commit_details
|
2015-10-24 18:46:33 +05:30
|
|
|
{ name: user.name, email: user.email, message: "test commit" }
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def create_page(name, content)
|
|
|
|
wiki.wiki.write_page(name, :markdown, content, commit_details)
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_page(title)
|
|
|
|
page = wiki.wiki.paged(title)
|
|
|
|
wiki.wiki.delete_page(page, commit_details)
|
|
|
|
end
|
|
|
|
end
|