2013-03-03 22:43:52 -05:00
|
|
|
require "spec_helper"
|
|
|
|
|
|
|
|
describe WikiPage do
|
2014-07-31 12:24:53 -04:00
|
|
|
let(:project) { create(:empty_project) }
|
2013-03-03 22:43:52 -05:00
|
|
|
let(:user) { project.owner }
|
2014-04-09 07:35:58 -04:00
|
|
|
let(:wiki) { ProjectWiki.new(project, user) }
|
2013-03-03 22:43:52 -05:00
|
|
|
|
|
|
|
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-02-12 13:17:35 -05:00
|
|
|
expect(@wiki_page.slug).to eq("test-page")
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the title attribute" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@wiki_page.title).to eq("test page")
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the formatted content attribute" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@wiki_page.content).to eq("test content")
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the format attribute" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@wiki_page.format).to eq(:markdown)
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the message attribute" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@wiki_page.message).to eq("test commit")
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "sets the version attribute" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@wiki_page.version).to be_a Gollum::Git::Commit
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "validations" do
|
|
|
|
before do
|
2015-06-22 14:41:00 -04:00
|
|
|
subject.attributes = { title: 'title', content: 'content' }
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "validates presence of title" do
|
|
|
|
subject.attributes.delete(:title)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(subject.valid?).to be_falsey
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "validates presence of content" do
|
|
|
|
subject.attributes.delete(:content)
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(subject.valid?).to be_falsey
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2015-06-22 14:41:00 -04:00
|
|
|
@wiki_attr = { title: "Index", content: "Home Page", format: "markdown" }
|
2013-03-03 22:43:52 -05:00
|
|
|
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-02-12 13:17:35 -05:00
|
|
|
expect(wiki.find_page("Index")).not_to be_nil
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(subject.create(@wiki_attr)).to eq(true)
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-03-21 21:04:29 -04:00
|
|
|
describe "dot in the title" do
|
|
|
|
let(:title) { 'Index v1.2.3' }
|
|
|
|
|
|
|
|
before do
|
2015-06-22 14:41:00 -04:00
|
|
|
@wiki_attr = { title: title, content: "Home Page", format: "markdown" }
|
2015-03-21 21:04:29 -04:00
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-03 22:43:52 -05:00
|
|
|
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-02-12 13:17:35 -05:00
|
|
|
expect(@page.update("more content")).to be_truthy
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#destroy" do
|
|
|
|
before do
|
|
|
|
create_page("Delete Page", "content")
|
|
|
|
@page = wiki.find_page("Delete Page")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should delete the page" do
|
|
|
|
@page.delete
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(wiki.pages).to be_empty
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return true" do
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@page.delete).to eq(true)
|
2013-03-03 22:43:52 -05:00
|
|
|
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-02-12 13:17:35 -05:00
|
|
|
expect(@page.versions.count).to eq(4)
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-09 01:14:16 -04:00
|
|
|
describe "#title" do
|
|
|
|
before do
|
|
|
|
create_page("Title", "content")
|
|
|
|
@page = wiki.find_page("Title")
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
destroy_page("Title")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "should be replace a hyphen to a space" do
|
|
|
|
@page.title = "Import-existing-repositories-into-GitLab"
|
2015-02-12 13:17:35 -05:00
|
|
|
expect(@page.title).to eq("Import existing repositories into GitLab")
|
2014-04-09 01:14:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-31 12:24:53 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def remove_temp_repo(path)
|
|
|
|
FileUtils.rm_rf path
|
|
|
|
end
|
|
|
|
|
|
|
|
def commit_details
|
2015-10-03 02:48:54 -04:00
|
|
|
{ name: user.name, email: user.email, message: "test commit" }
|
2014-07-31 12:24:53 -04:00
|
|
|
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
|
2013-03-03 22:43:52 -05:00
|
|
|
end
|