1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
require "spec_helper"
describe WikiPage do
def remove_temp_repo(path)
FileUtils.rm_rf path
end
def commit_details
commit = {name: user.name, email: user.email, message: "test commit"}
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
let(:project) { create(:project) }
let(:repository) { project.repository }
let(:user) { project.owner }
let(:wiki) { ProjectWiki.new(project, user) }
subject { WikiPage.new(wiki) }
before do
create_temp_repo(wiki.send(:path_to_repo))
end
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
@wiki_page.slug.should == "test-page"
end
it "sets the title attribute" do
@wiki_page.title.should == "test page"
end
it "sets the formatted content attribute" do
@wiki_page.content.should == "test content"
end
it "sets the format attribute" do
@wiki_page.format.should == :markdown
end
it "sets the message attribute" do
@wiki_page.message.should == "test commit"
end
it "sets the version attribute" do
@wiki_page.version.should be_a Commit
end
end
end
describe "validations" do
before do
subject.attributes = {title: 'title', content: 'content'}
end
it "validates presence of title" do
subject.attributes.delete(:title)
subject.valid?.should be_false
end
it "validates presence of content" do
subject.attributes.delete(:content)
subject.valid?.should be_false
end
end
before do
@wiki_attr = {title: "Index", content: "Home Page", format: "markdown"}
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)
wiki.find_page("Index").should_not be_nil
end
it "returns true" do
subject.create(@wiki_attr).should == true
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
@page.update("more content").should be_true
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
wiki.pages.should be_empty
end
it "should return true" do
@page.delete.should == true
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}") }
@page.versions.count.should == 4
end
end
end
|