octodmin 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +7 -0
  2. data/.bowerrc +3 -0
  3. data/.gitignore +24 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +9 -0
  6. data/CHANGELOG.md +4 -0
  7. data/Gemfile +17 -0
  8. data/LICENSE.md +22 -0
  9. data/README.md +117 -0
  10. data/Rakefile +38 -0
  11. data/_config.yml +27 -0
  12. data/_deploy.yml +13 -0
  13. data/app/.DS_Store +0 -0
  14. data/app/assets/.DS_Store +0 -0
  15. data/app/assets/javascripts/.DS_Store +0 -0
  16. data/app/assets/javascripts/app.js.coffee +13 -0
  17. data/app/assets/javascripts/components/header.js.cjsx +69 -0
  18. data/app/assets/javascripts/components/posts.js.cjsx +309 -0
  19. data/app/assets/javascripts/components/router.js.cjsx +56 -0
  20. data/app/assets/stylesheets/.DS_Store +0 -0
  21. data/app/assets/stylesheets/app.scss +75 -0
  22. data/app/config/environment.rb +7 -0
  23. data/app/config/routes.rb +19 -0
  24. data/app/config/sprockets.rb +36 -0
  25. data/app/controllers/deploys/create.rb +20 -0
  26. data/app/controllers/frontend/index.rb +8 -0
  27. data/app/controllers/posts/create.rb +18 -0
  28. data/app/controllers/posts/destroy.rb +14 -0
  29. data/app/controllers/posts/index.rb +13 -0
  30. data/app/controllers/posts/restore.rb +14 -0
  31. data/app/controllers/posts/revert.rb +14 -0
  32. data/app/controllers/posts/show.rb +13 -0
  33. data/app/controllers/posts/update.rb +23 -0
  34. data/app/controllers/site/show.rb +12 -0
  35. data/app/controllers/syncs/create.rb +62 -0
  36. data/app/controllers/version/show.rb +12 -0
  37. data/app/octodmin.rb +56 -0
  38. data/app/public/.DS_Store +0 -0
  39. data/app/public/assets/app.css +7960 -0
  40. data/app/public/assets/app.css.gz +7960 -0
  41. data/app/public/assets/app.js +39181 -0
  42. data/app/public/assets/app.js.gz +39181 -0
  43. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.eot +0 -0
  44. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.eot.gz +0 -0
  45. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.svg +288 -0
  46. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.svg.gz +288 -0
  47. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf +0 -0
  48. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf.gz +0 -0
  49. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.woff +0 -0
  50. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.woff.gz +0 -0
  51. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 +0 -0
  52. data/app/public/assets/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2.gz +0 -0
  53. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.eot +0 -0
  54. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.eot.gz +0 -0
  55. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.svg +288 -0
  56. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.svg.gz +288 -0
  57. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.ttf +0 -0
  58. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.ttf.gz +0 -0
  59. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.woff +0 -0
  60. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.woff.gz +0 -0
  61. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.woff2 +0 -0
  62. data/app/public/assets/bootstrap/fonts/glyphicons-halflings-regular.woff2.gz +0 -0
  63. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.eot +0 -0
  64. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.eot.gz +0 -0
  65. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.svg +288 -0
  66. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.svg.gz +288 -0
  67. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.ttf +0 -0
  68. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.ttf.gz +0 -0
  69. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.woff +0 -0
  70. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.woff.gz +0 -0
  71. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.woff2 +0 -0
  72. data/app/public/assets/bootstrap-sass/assets/fonts/bootstrap/glyphicons-halflings-regular.woff2.gz +0 -0
  73. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.eot +0 -0
  74. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.eot.gz +0 -0
  75. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.svg +288 -0
  76. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.svg.gz +288 -0
  77. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.ttf +0 -0
  78. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.ttf.gz +0 -0
  79. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.woff +0 -0
  80. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.woff.gz +0 -0
  81. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.woff2 +0 -0
  82. data/app/public/assets/bootswatch/fonts/glyphicons-halflings-regular.woff2.gz +0 -0
  83. data/app/public/assets/bootswatch-dist/fonts/glyphicons-halflings-regular.eot +0 -0
  84. data/app/public/assets/bootswatch-dist/fonts/glyphicons-halflings-regular.eot.gz +0 -0
  85. data/app/public/assets/bootswatch-dist/fonts/glyphicons-halflings-regular.svg +229 -0
  86. data/app/public/assets/bootswatch-dist/fonts/glyphicons-halflings-regular.svg.gz +229 -0
  87. data/app/public/assets/bootswatch-dist/fonts/glyphicons-halflings-regular.ttf +0 -0
  88. data/app/public/assets/bootswatch-dist/fonts/glyphicons-halflings-regular.ttf.gz +0 -0
  89. data/app/public/assets/bootswatch-dist/fonts/glyphicons-halflings-regular.woff +0 -0
  90. data/app/public/assets/bootswatch-dist/fonts/glyphicons-halflings-regular.woff.gz +0 -0
  91. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.eot +0 -0
  92. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.eot.gz +0 -0
  93. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.svg +565 -0
  94. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.svg.gz +565 -0
  95. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.ttf +0 -0
  96. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.ttf.gz +0 -0
  97. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.woff +0 -0
  98. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.woff.gz +0 -0
  99. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.woff2 +0 -0
  100. data/app/public/assets/fontawesome/fonts/fontawesome-webfont.woff2.gz +0 -0
  101. data/app/public/assets/manifest.json +1 -0
  102. data/app/templates/application.html.erb +13 -0
  103. data/app/templates/frontend/index.html.erb +1 -0
  104. data/app/views/application_layout.rb +5 -0
  105. data/app/views/deploys/create.rb +10 -0
  106. data/app/views/frontend/index.rb +5 -0
  107. data/app/views/posts/create.rb +10 -0
  108. data/app/views/posts/destroy.rb +10 -0
  109. data/app/views/posts/index.rb +10 -0
  110. data/app/views/posts/restore.rb +10 -0
  111. data/app/views/posts/revert.rb +10 -0
  112. data/app/views/posts/show.rb +10 -0
  113. data/app/views/posts/update.rb +10 -0
  114. data/app/views/site/show.rb +10 -0
  115. data/app/views/syncs/create.rb +10 -0
  116. data/app/views/version/show.rb +10 -0
  117. data/bower.json +16 -0
  118. data/config.ru +5 -0
  119. data/lib/octodmin/app.rb +2 -0
  120. data/lib/octodmin/post.rb +161 -0
  121. data/lib/octodmin/site.rb +61 -0
  122. data/lib/octodmin/version.rb +3 -0
  123. data/lib/octodmin.rb +7 -0
  124. data/octodmin.gemspec +24 -0
  125. data/sample/.gitignore +2 -0
  126. data/sample/_includes/footer.html +55 -0
  127. data/sample/_includes/head.html +12 -0
  128. data/sample/_includes/header.html +27 -0
  129. data/sample/_layouts/default.html +20 -0
  130. data/sample/_layouts/page.html +14 -0
  131. data/sample/_layouts/post.html +15 -0
  132. data/sample/_posts/2015-01-29-welcome-to-jekyll.markdown +25 -0
  133. data/sample/_posts/2015-01-30-test.markdown +10 -0
  134. data/sample/_sass/_base.scss +204 -0
  135. data/sample/_sass/_layout.scss +236 -0
  136. data/sample/_sass/_syntax-highlighting.scss +67 -0
  137. data/sample/_templates/draft +4 -0
  138. data/sample/_templates/page +4 -0
  139. data/sample/_templates/post +8 -0
  140. data/sample/about.md +11 -0
  141. data/sample/css/main.scss +52 -0
  142. data/sample/feed.xml +30 -0
  143. data/sample/index.html +23 -0
  144. data/spec/api/deploys_spec.rb +36 -0
  145. data/spec/api/posts_spec.rb +411 -0
  146. data/spec/api/site_spec.rb +18 -0
  147. data/spec/api/syncs_spec.rb +81 -0
  148. data/spec/api/version_spec.rb +14 -0
  149. data/spec/frontend/assets_spec.rb +23 -0
  150. data/spec/frontend/home_spec.rb +16 -0
  151. data/spec/spec_helper.rb +31 -0
  152. data/tmp/.keep +0 -0
  153. metadata +259 -0
@@ -0,0 +1,36 @@
1
+ require "spec_helper"
2
+
3
+ describe "deploys" do
4
+ let(:app) { Octodmin::App.new(File.expand_path("../..", __dir__)) }
5
+
6
+ before do
7
+ expect(Octopress::Deploy).to receive(:push).once
8
+ end
9
+
10
+ describe "create" do
11
+ context "invalid" do
12
+ before do
13
+ allow(Octopress::Deploy).to receive(:push).and_raise(SystemExit, "Deploy error")
14
+ post "/api/deploys"
15
+ end
16
+ subject { parse_json(last_response.body)["errors"] }
17
+
18
+ it "returns errors" do
19
+ expect(last_response).to_not be_ok
20
+ expect(subject).to eql(["Deploy error"])
21
+ end
22
+ end
23
+
24
+ context "valid" do
25
+ before do
26
+ allow(Octopress::Deploy).to receive(:push).and_return(nil)
27
+ post "/api/deploys"
28
+ end
29
+ subject { parse_json(last_response.body)["deploys"] }
30
+
31
+ it "returns errors" do
32
+ expect(subject).to eql(["Deployed successfully"])
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,411 @@
1
+ require "spec_helper"
2
+
3
+ shared_examples_for "existing post" do
4
+ it "has post" do
5
+ expect(subject["identifier"]).to eql("2015-01-30-test")
6
+ expect(subject["added"]).to eql(false)
7
+ expect(subject["changed"]).to eql(false)
8
+ expect(subject["deleted"]).to eql(false)
9
+ expect(subject["title"]).to eql("Test")
10
+ expect(subject["slug"]).to eql("test")
11
+ expect(subject["path"]).to eql("_posts/2015-01-30-test.markdown")
12
+ expect(subject["date"]).to start_with("2015-01-30")
13
+ expect(subject["excerpt"]).to eql("<h1 id=\"omg\">OMG</h1>\n\n")
14
+ expect(subject["content"]).to eql("# OMG\n\nThis is a *post*!\n")
15
+ expect(subject["custom"]).to eql("data")
16
+ end
17
+ end
18
+
19
+ shared_examples_for "new post" do
20
+ it "has post" do
21
+ expect(File.exists?("sample/_posts/#{date}-new-one.markdown")).to be_truthy
22
+ expect(subject["identifier"]).to eql("#{date}-new-one")
23
+ expect(subject["added"]).to eql(true)
24
+ expect(subject["changed"]).to eql(false)
25
+ expect(subject["deleted"]).to eql(false)
26
+ expect(subject["title"]).to eql("New One")
27
+ expect(subject["slug"]).to eql("new-one")
28
+ expect(subject["path"]).to eql("_posts/#{date}-new-one.markdown")
29
+ expect(subject["date"]).to start_with(date)
30
+ expect(subject["excerpt"]).to eql("<p>New post from <strong>template</strong></p>\n\n")
31
+ expect(subject["content"]).to eql("New post from **template**\n")
32
+ expect(subject["custom"]).to eql("default")
33
+ end
34
+ end
35
+
36
+ shared_examples_for "updated post" do
37
+ it "has post" do
38
+ expect(File.exists?("sample/_posts/2015-01-30-test.markdown")).to be_truthy
39
+ expect(subject["identifier"]).to eql("2015-01-30-test")
40
+ expect(subject["added"]).to eql(false)
41
+ expect(subject["changed"]).to eql(true)
42
+ expect(subject["deleted"]).to eql(false)
43
+ expect(subject["title"]).to eql("Test")
44
+ expect(subject["slug"]).to eql("test")
45
+ expect(subject["path"]).to eql("_posts/2015-01-30-test.markdown")
46
+ expect(subject["date"]).to start_with("2015-01-30")
47
+ expect(subject["excerpt"]).to eql("<h3 id=\"wow\">WOW</h3>\n\n")
48
+ expect(subject["content"]).to eql("### WOW\n")
49
+ expect(subject["custom"]).to eql("new")
50
+ expect(subject.has_key?("junk")).to be_falsy
51
+ end
52
+ end
53
+
54
+ shared_examples_for "new updated post" do
55
+ it "has post" do
56
+ expect(File.exists?("sample/_posts/#{date}-new-one.markdown")).to be_falsy
57
+ expect(File.exists?("sample/_posts/#{date}-updated-one.markdown")).to be_truthy
58
+ expect(subject["identifier"]).to eql("#{date}-updated-one")
59
+ expect(subject["added"]).to eql(true)
60
+ expect(subject["changed"]).to eql(false)
61
+ expect(subject["deleted"]).to eql(false)
62
+ expect(subject["title"]).to eql("Updated One")
63
+ expect(subject["slug"]).to eql("updated-one")
64
+ expect(subject["path"]).to eql("_posts/#{date}-updated-one.markdown")
65
+ expect(subject["date"]).to start_with(date)
66
+ expect(subject["excerpt"]).to eql("<h3 id=\"wow\">WOW</h3>\n\n")
67
+ expect(subject["content"]).to eql("### WOW\n")
68
+ expect(subject["custom"]).to eql("updated")
69
+ expect(subject.has_key?("junk")).to be_falsy
70
+ end
71
+ end
72
+
73
+
74
+ shared_examples_for "deleted post" do
75
+ it "has no post" do
76
+ expect(File.exists?("sample/_posts/2015-01-29-welcome-to-jekyll.markdown")).to be_truthy
77
+ expect(subject["identifier"]).to eql("2015-01-29-welcome-to-jekyll")
78
+ expect(subject["added"]).to eql(false)
79
+ expect(subject["changed"]).to eql(false)
80
+ expect(subject["deleted"]).to eql(true)
81
+ expect(subject["title"]).to eql("Welcome to Jekyll!")
82
+ end
83
+ end
84
+
85
+ describe "posts" do
86
+ let(:app) { Octodmin::App.new(File.expand_path("../..", __dir__)) }
87
+ let(:date) { Date.today.strftime("%Y-%m-%d") }
88
+
89
+ describe "index" do
90
+ before { get "/api/posts" }
91
+ subject { parse_json(last_response.body)["posts"] }
92
+
93
+ context "first post" do
94
+ subject { parse_json(last_response.body)["posts"].first }
95
+ it_behaves_like "existing post"
96
+ end
97
+
98
+ context "last post" do
99
+ specify do
100
+ expect(subject.last["identifier"]).to eql("2015-01-29-welcome-to-jekyll")
101
+ expect(subject.last["title"]).to eql("Welcome to Jekyll!")
102
+ end
103
+ end
104
+ end
105
+
106
+ describe "create" do
107
+ context "invalid" do
108
+ subject { parse_json(last_response.body)["errors"] }
109
+
110
+ context "no title" do
111
+ before { post "/api/posts" }
112
+
113
+ it "is not ok" do
114
+ expect(last_response).to_not be_ok
115
+ expect(subject).to eql(["Required param `title` is not specified"])
116
+ end
117
+ end
118
+
119
+ context "same title" do
120
+ before do
121
+ post "/api/posts", title: "Yo"
122
+ post "/api/posts", title: "Yo"
123
+ end
124
+ after { File.delete("sample/_posts/#{date}-yo.markdown") }
125
+
126
+ it "is not ok" do
127
+ expect(last_response).to_not be_ok
128
+ expect(subject).to eql(["Post with specified `title` already exists"])
129
+ end
130
+ end
131
+ end
132
+
133
+ context "valid" do
134
+ context "regular post" do
135
+ before { post "/api/posts", title: "New One" }
136
+ after { File.delete("sample/_posts/#{date}-new-one.markdown") }
137
+ subject { parse_json(last_response.body)["posts"] }
138
+
139
+ context "response" do
140
+ it_behaves_like "new post"
141
+ end
142
+
143
+ context "request" do
144
+ before { get "/api/posts/#{date}-new-one" }
145
+ it_behaves_like "new post"
146
+ end
147
+ end
148
+
149
+ context "special post" do
150
+ before { post "/api/posts", title: "Тестовий" }
151
+ after { File.delete("sample/_posts/#{date}-testovyi.markdown") }
152
+ subject { parse_json(last_response.body)["posts"] }
153
+
154
+ context "response" do
155
+ it "has post" do
156
+ expect(File.exists?("sample/_posts/#{date}-testovyi.markdown")).to be_truthy
157
+ expect(subject["identifier"]).to eql("#{date}-testovyi")
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
163
+
164
+ describe "show" do
165
+ context "invalid" do
166
+ subject { parse_json(last_response.body)["errors"] }
167
+
168
+ context "no post" do
169
+ before { get "/api/posts/omg" }
170
+
171
+ it "is not ok" do
172
+ expect(last_response).to_not be_ok
173
+ expect(subject).to eql(["Could not find post"])
174
+ end
175
+ end
176
+ end
177
+
178
+ context "valid" do
179
+ before { get "/api/posts/2015-01-30-test" }
180
+ subject { parse_json(last_response.body)["posts"] }
181
+ it_behaves_like "existing post"
182
+ end
183
+ end
184
+
185
+ describe "update" do
186
+ context "invalid" do
187
+ subject { parse_json(last_response.body)["errors"] }
188
+
189
+ context "no post" do
190
+ before { patch "/api/posts/omg" }
191
+
192
+ it "is not ok" do
193
+ expect(last_response).to_not be_ok
194
+ expect(subject).to eql(["Could not find post"])
195
+ end
196
+ end
197
+
198
+ context "no params" do
199
+ before { patch "/api/posts/2015-01-30-test" }
200
+
201
+ it "is not ok" do
202
+ expect(last_response).to_not be_ok
203
+ expect(subject).to eql(["Required params are not specified"])
204
+ end
205
+ end
206
+ end
207
+
208
+ context "valid" do
209
+ context "old post" do
210
+ before do
211
+ patch "/api/posts/2015-01-30-test", {
212
+ layout: "other",
213
+ title: "Test",
214
+ slug: "test",
215
+ date: "2015-01-30 21:10:00",
216
+ content: "### WOW",
217
+ custom: "new",
218
+ junk: "shit",
219
+ }
220
+ end
221
+ after do
222
+ git = Git.open(Octodmin::App.dir)
223
+ git.checkout("sample/_posts/2015-01-30-test.markdown")
224
+ end
225
+ subject { parse_json(last_response.body)["posts"] }
226
+
227
+ context "response" do
228
+ it_behaves_like "updated post"
229
+ end
230
+
231
+ context "request" do
232
+ before { get "/api/posts/2015-01-30-test" }
233
+ it_behaves_like "updated post"
234
+ end
235
+ end
236
+
237
+ context "new post" do
238
+ before do
239
+ post "/api/posts", title: "New One"
240
+ patch "/api/posts/#{date}-new-one", {
241
+ layout: "post",
242
+ title: "Updated One",
243
+ slug: "updated-one",
244
+ date: "#{date} 00:00:00",
245
+ content: "### WOW",
246
+ custom: "updated",
247
+ junk: "shit",
248
+ }
249
+ end
250
+ after do
251
+ File.delete("sample/_posts/#{date}-updated-one.markdown")
252
+ end
253
+ subject { parse_json(last_response.body)["posts"] }
254
+
255
+ context "response" do
256
+ it_behaves_like "new updated post"
257
+ end
258
+
259
+ context "request" do
260
+ before { get "/api/posts/#{date}-updated-one" }
261
+ it_behaves_like "new updated post"
262
+ end
263
+ end
264
+
265
+ context "special post" do
266
+ before do
267
+ post "/api/posts", title: "New One"
268
+ patch "/api/posts/#{date}-new-one", {
269
+ layout: "post",
270
+ title: "Новий",
271
+ slug: "novyi",
272
+ date: "#{date} 00:00:00",
273
+ content: "### WOW",
274
+ custom: "updated",
275
+ junk: "shit",
276
+ }
277
+ end
278
+ after do
279
+ File.delete("sample/_posts/#{date}-novyi.markdown")
280
+ end
281
+ subject { parse_json(last_response.body)["posts"] }
282
+
283
+ context "response" do
284
+ it "has post" do
285
+ expect(File.exists?("sample/_posts/#{date}-novyi.markdown")).to be_truthy
286
+ expect(subject["identifier"]).to eql("#{date}-novyi")
287
+ end
288
+ end
289
+ end
290
+ end
291
+ end
292
+
293
+ describe "delete" do
294
+ context "invalid" do
295
+ subject { parse_json(last_response.body)["errors"] }
296
+
297
+ context "no post" do
298
+ before { delete "/api/posts/omg" }
299
+
300
+ it "is not ok" do
301
+ expect(last_response).to_not be_ok
302
+ expect(subject).to eql(["Could not find post"])
303
+ end
304
+ end
305
+ end
306
+
307
+ context "valid" do
308
+ context "new post" do
309
+ before do
310
+ post "/api/posts", title: "New One"
311
+ delete "/api/posts/#{date}-new-one"
312
+ get "/api/posts/#{date}-new-one"
313
+ end
314
+ subject { parse_json(last_response.body)["errors"] }
315
+
316
+ it "has no post" do
317
+ expect(last_response).to_not be_ok
318
+ expect(subject).to eql(["Could not find post"])
319
+ end
320
+ end
321
+
322
+ context "old post" do
323
+ before do
324
+ delete "/api/posts/2015-01-29-welcome-to-jekyll"
325
+ end
326
+ after do
327
+ git = Git.open(Octodmin::App.dir)
328
+ git.add("sample/_posts/2015-01-29-welcome-to-jekyll.markdown")
329
+ end
330
+ subject { parse_json(last_response.body)["posts"] }
331
+ it_behaves_like "deleted post"
332
+ end
333
+ end
334
+ end
335
+
336
+ describe "restore" do
337
+ context "invalid" do
338
+ subject { parse_json(last_response.body)["errors"] }
339
+
340
+ context "no post" do
341
+ before { patch "/api/posts/omg/restore" }
342
+
343
+ it "is not ok" do
344
+ expect(last_response).to_not be_ok
345
+ expect(subject).to eql(["Could not find post"])
346
+ end
347
+ end
348
+ end
349
+
350
+ context "valid" do
351
+ context "existing post" do
352
+ before do
353
+ patch "/api/posts/2015-01-30-test/restore"
354
+ end
355
+ subject { parse_json(last_response.body)["posts"] }
356
+ it_behaves_like "existing post"
357
+ end
358
+
359
+ context "deleted post" do
360
+ before do
361
+ delete "/api/posts/2015-01-30-test"
362
+ patch "/api/posts/2015-01-30-test/restore"
363
+ end
364
+ subject { parse_json(last_response.body)["posts"] }
365
+ it_behaves_like "existing post"
366
+ end
367
+ end
368
+ end
369
+
370
+ describe "revert" do
371
+ context "invalid" do
372
+ subject { parse_json(last_response.body)["errors"] }
373
+
374
+ context "no post" do
375
+ before { patch "/api/posts/omg/revert" }
376
+
377
+ it "is not ok" do
378
+ expect(last_response).to_not be_ok
379
+ expect(subject).to eql(["Could not find post"])
380
+ end
381
+ end
382
+ end
383
+
384
+ context "valid" do
385
+ context "existing post" do
386
+ before do
387
+ patch "/api/posts/2015-01-30-test/revert"
388
+ end
389
+ subject { parse_json(last_response.body)["posts"] }
390
+ it_behaves_like "existing post"
391
+ end
392
+
393
+ context "changed post" do
394
+ before do
395
+ patch "/api/posts/2015-01-30-test", {
396
+ layout: "other",
397
+ title: "Test",
398
+ slug: "test",
399
+ date: "2015-01-30 21:10:00",
400
+ content: "### WOW",
401
+ custom: "new",
402
+ junk: "shit",
403
+ }
404
+ patch "/api/posts/2015-01-30-test/revert"
405
+ end
406
+ subject { parse_json(last_response.body)["posts"] }
407
+ it_behaves_like "existing post"
408
+ end
409
+ end
410
+ end
411
+ end
@@ -0,0 +1,18 @@
1
+ require "spec_helper"
2
+
3
+ describe "site" do
4
+ let(:app) { Octodmin::App.new(File.expand_path("../..", __dir__)) }
5
+
6
+ describe "show" do
7
+ before { get "/api/site" }
8
+ subject { parse_json(last_response.body)["sites"] }
9
+
10
+ it "returns site" do
11
+ expect(subject["title"]).to eql("Your awesome title")
12
+ end
13
+
14
+ it "returns octodmin config" do
15
+ expect(subject["octodmin"]["front_matter"].keys).to eq(["layout", "title", "slug", "date", "custom"])
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,81 @@
1
+ require "spec_helper"
2
+
3
+ describe "syncs" do
4
+ let(:date) { Date.today.strftime("%Y-%m-%d") }
5
+ let(:app) { Octodmin::App.new(File.expand_path("../..", __dir__)) }
6
+
7
+ before do
8
+ allow_any_instance_of(Git::Base).to receive(:pull).and_return(nil)
9
+ allow_any_instance_of(Git::Base).to receive(:push).and_return(nil)
10
+ end
11
+
12
+ describe "create" do
13
+ context "invalid" do
14
+ before do
15
+ allow_any_instance_of(Git::Base).to receive(:pull).and_raise(Git::GitExecuteError, "Git error")
16
+ expect_any_instance_of(Git::Base).to receive(:pull).once
17
+
18
+ post "/api/posts", title: "Blah"
19
+ post "/api/syncs"
20
+ end
21
+ after { File.delete("sample/_posts/#{date}-blah.markdown") }
22
+ subject { parse_json(last_response.body)["errors"] }
23
+
24
+ it "returns errors" do
25
+ expect(last_response).to_not be_ok
26
+ expect(subject).to eql(["Git error"])
27
+ end
28
+ end
29
+
30
+ context "valid" do
31
+ context "no changes" do
32
+ before do
33
+ expect_any_instance_of(Git::Base).to receive(:pull).once
34
+ post "/api/syncs"
35
+ end
36
+ subject { parse_json(last_response.body)["syncs"] }
37
+
38
+ it "returns errors" do
39
+ expect(subject).to eql(["Everything is up-to-date"])
40
+ end
41
+ end
42
+
43
+ context "with changes" do
44
+ before do
45
+ allow_any_instance_of(Git::Base).to receive(:commit).and_return(nil)
46
+ expect_any_instance_of(Git::Base).to receive(:pull).once
47
+ expect_any_instance_of(Git::Base).to receive(:commit).once
48
+ expect_any_instance_of(Git::Base).to receive(:push).once
49
+
50
+ # Create post
51
+ post "/api/posts", title: "Yo"
52
+
53
+ # Update post
54
+ patch "/api/posts/2015-01-30-test", {
55
+ layout: "other",
56
+ title: "Test",
57
+ slug: "test",
58
+ date: "2015-01-30 18:10:00",
59
+ content: "### WOW",
60
+ }
61
+
62
+ # Delete post
63
+ delete "/api/posts/2015-01-29-welcome-to-jekyll"
64
+
65
+ post "/api/syncs"
66
+ end
67
+ after do
68
+ File.delete("sample/_posts/#{date}-yo.markdown")
69
+ git = Git.open(Octodmin::App.dir)
70
+ git.checkout("sample/_posts/2015-01-30-test.markdown")
71
+ git.checkout("sample/_posts/2015-01-29-welcome-to-jekyll.markdown")
72
+ end
73
+ subject { parse_json(last_response.body)["syncs"] }
74
+
75
+ it "returns syncs" do
76
+ expect(subject).to eql(["Octodmin sync for 3 files\n\n_posts/#{date}-yo.markdown\n_posts/2015-01-30-test.markdown\n_posts/2015-01-29-welcome-to-jekyll.markdown"])
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,14 @@
1
+ require "spec_helper"
2
+
3
+ describe "version" do
4
+ let(:app) { Octodmin::App.new(File.expand_path("../..", __dir__)) }
5
+
6
+ describe "show" do
7
+ before { get "/api/version" }
8
+ subject { parse_json(last_response.body)["versions"] }
9
+
10
+ it "returns version" do
11
+ expect(subject).to eql(Octodmin::VERSION)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ require "spec_helper"
2
+
3
+ describe "assets" do
4
+ let(:app) { Octodmin::App.new(File.expand_path("../..", __dir__)) }
5
+
6
+ describe "css" do
7
+ before { get "/assets/app.css" }
8
+ subject { last_response.body }
9
+
10
+ it "returns css" do
11
+ expect(subject).to include("@charset")
12
+ end
13
+ end
14
+
15
+ describe "js" do
16
+ before { get "/assets/app.js" }
17
+ subject { last_response.body }
18
+
19
+ it "returns js" do
20
+ expect(subject).to include("App = React.createClass")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require "spec_helper"
2
+
3
+ describe "home" do
4
+ let(:app) { Octodmin::App.new(File.expand_path("../..", __dir__)) }
5
+
6
+ describe "home" do
7
+ before { get "/" }
8
+ subject { last_response.body }
9
+
10
+ it "returns home" do
11
+ expect(subject).to include("<!DOCTYPE html>")
12
+ expect(subject).to include("/assets/app.css")
13
+ expect(subject).to include("/assets/app.js")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,31 @@
1
+ ENV["RACK_ENV"] = ENV["LOTUS_ENV"] = "test"
2
+
3
+ require "rubygems"
4
+ require "bundler/setup"
5
+
6
+ Bundler.require(:test)
7
+ require "rack/test"
8
+
9
+ if ENV["COVERAGE"] == "true"
10
+ require "simplecov"
11
+ require "coveralls"
12
+
13
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
14
+ SimpleCov::Formatter::HTMLFormatter,
15
+ Coveralls::SimpleCov::Formatter
16
+ ]
17
+
18
+ SimpleCov.start do
19
+ command_name "spec"
20
+ add_filter "spec"
21
+ end
22
+ end
23
+
24
+ $:.unshift "lib"
25
+ require "octodmin"
26
+ require "octodmin/app"
27
+
28
+ RSpec.configure do |config|
29
+ config.include Rack::Test::Methods
30
+ config.include JsonSpec::Helpers
31
+ end
data/tmp/.keep ADDED
File without changes