comatose 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. data/CHANGELOG +176 -0
  2. data/INSTALL +19 -0
  3. data/LICENSE +20 -0
  4. data/MANIFEST +91 -0
  5. data/README.rdoc +148 -0
  6. data/Rakefile +122 -0
  7. data/SPECS +61 -0
  8. data/about.yml +7 -0
  9. data/bin/comatose +109 -0
  10. data/comatose.gemspec +113 -0
  11. data/generators/comatose_migration/USAGE +15 -0
  12. data/generators/comatose_migration/comatose_migration_generator.rb +59 -0
  13. data/generators/comatose_migration/templates/migration.rb +35 -0
  14. data/generators/comatose_migration/templates/v4_upgrade.rb +15 -0
  15. data/generators/comatose_migration/templates/v6_upgrade.rb +23 -0
  16. data/generators/comatose_migration/templates/v7_upgrade.rb +22 -0
  17. data/init.rb +2 -0
  18. data/install.rb +16 -0
  19. data/lib/acts_as_versioned.rb +543 -0
  20. data/lib/comatose/comatose_drop.rb +79 -0
  21. data/lib/comatose/configuration.rb +68 -0
  22. data/lib/comatose/page_wrapper.rb +119 -0
  23. data/lib/comatose/processing_context.rb +69 -0
  24. data/lib/comatose/tasks/admin.rb +60 -0
  25. data/lib/comatose/tasks/data.rb +82 -0
  26. data/lib/comatose/tasks/setup.rb +52 -0
  27. data/lib/comatose/version.rb +4 -0
  28. data/lib/comatose.rb +33 -0
  29. data/lib/comatose_admin_controller.rb +349 -0
  30. data/lib/comatose_admin_helper.rb +37 -0
  31. data/lib/comatose_controller.rb +141 -0
  32. data/lib/comatose_helper.rb +3 -0
  33. data/lib/comatose_page.rb +141 -0
  34. data/lib/liquid/block.rb +96 -0
  35. data/lib/liquid/context.rb +190 -0
  36. data/lib/liquid/document.rb +17 -0
  37. data/lib/liquid/drop.rb +48 -0
  38. data/lib/liquid/errors.rb +7 -0
  39. data/lib/liquid/extensions.rb +53 -0
  40. data/lib/liquid/file_system.rb +62 -0
  41. data/lib/liquid/htmltags.rb +64 -0
  42. data/lib/liquid/standardfilters.rb +111 -0
  43. data/lib/liquid/standardtags.rb +399 -0
  44. data/lib/liquid/strainer.rb +42 -0
  45. data/lib/liquid/tag.rb +25 -0
  46. data/lib/liquid/template.rb +88 -0
  47. data/lib/liquid/variable.rb +39 -0
  48. data/lib/liquid.rb +52 -0
  49. data/lib/redcloth.rb +1129 -0
  50. data/lib/support/class_options.rb +36 -0
  51. data/lib/support/inline_rendering.rb +48 -0
  52. data/lib/support/route_mapper.rb +50 -0
  53. data/lib/text_filters/markdown.rb +14 -0
  54. data/lib/text_filters/markdown_smartypants.rb +15 -0
  55. data/lib/text_filters/none.rb +8 -0
  56. data/lib/text_filters/rdoc.rb +13 -0
  57. data/lib/text_filters/simple.rb +8 -0
  58. data/lib/text_filters/textile.rb +15 -0
  59. data/lib/text_filters.rb +138 -0
  60. data/rails/init.rb +3 -0
  61. data/resources/layouts/comatose_admin_template.html.erb +28 -0
  62. data/resources/public/images/collapsed.gif +0 -0
  63. data/resources/public/images/expanded.gif +0 -0
  64. data/resources/public/images/no-children.gif +0 -0
  65. data/resources/public/images/page.gif +0 -0
  66. data/resources/public/images/spinner.gif +0 -0
  67. data/resources/public/images/title-hover-bg.gif +0 -0
  68. data/resources/public/javascripts/comatose_admin.js +401 -0
  69. data/resources/public/stylesheets/comatose_admin.css +381 -0
  70. data/tasks/comatose.rake +9 -0
  71. data/test/behaviors.rb +106 -0
  72. data/test/fixtures/comatose_pages.yml +96 -0
  73. data/test/functional/comatose_admin_controller_test.rb +112 -0
  74. data/test/functional/comatose_controller_test.rb +44 -0
  75. data/test/javascripts/test.html +26 -0
  76. data/test/javascripts/test_runner.js +307 -0
  77. data/test/test_helper.rb +43 -0
  78. data/test/unit/class_options_test.rb +52 -0
  79. data/test/unit/comatose_page_test.rb +128 -0
  80. data/test/unit/processing_context_test.rb +108 -0
  81. data/test/unit/text_filters_test.rb +52 -0
  82. data/views/comatose_admin/_form.html.erb +96 -0
  83. data/views/comatose_admin/_page_list_item.html.erb +60 -0
  84. data/views/comatose_admin/delete.html.erb +18 -0
  85. data/views/comatose_admin/edit.html.erb +5 -0
  86. data/views/comatose_admin/index.html.erb +18 -0
  87. data/views/comatose_admin/new.html.erb +5 -0
  88. data/views/comatose_admin/reorder.html.erb +30 -0
  89. data/views/comatose_admin/versions.html.erb +40 -0
  90. data/views/layouts/comatose_admin.html.erb +814 -0
  91. data/views/layouts/comatose_admin_customize.html.erb +28 -0
  92. data/views/layouts/comatose_content.html.erb +17 -0
  93. metadata +156 -0
@@ -0,0 +1,381 @@
1
+ BODY {
2
+ background: #DDD;
3
+ margin: 0px 100px;
4
+ padding: 0px;
5
+ font-family: "Lucida Grande", Tahoma, Verdana, Arial, Sans-Serif;
6
+ font-size: 12px;
7
+ min-width: 450px;
8
+ }
9
+ /* General Layout and Header Area */
10
+ #page-container {
11
+ margin: 0px;
12
+ padding: 0px;
13
+ }
14
+ #header {
15
+ background: #0053C2;
16
+ padding: 5px;
17
+ border-bottom: 4px solid #00398B;
18
+ }
19
+ #header A {
20
+ text-decoration: none;
21
+ color: white;
22
+ }
23
+ #header A:hover {
24
+ color: white;
25
+ }
26
+ #header h1 {
27
+ margin: 0px;
28
+ padding: 0px;
29
+ padding-left: 10px;
30
+ }
31
+ #header h5 {
32
+ margin: 0px;
33
+ padding: 0px;
34
+ padding-left: 15px;
35
+ color: silver;
36
+ }
37
+ #header #flash {
38
+ float: right;
39
+ color: #4BA8FF;
40
+ font-weight: bold;
41
+ margin-right: 5px;
42
+ }
43
+ /* Content Area */
44
+ #content {
45
+ padding: 15px;
46
+ background: white;
47
+ border-left: 1px solid silver;
48
+ border-right: 1px solid silver;
49
+ }
50
+ #content h1 {
51
+ margin: 0px;
52
+ padding: 0px;
53
+ font-size: 135%;
54
+ color: gray;
55
+ }
56
+ #content .action {
57
+ float: right;
58
+ color: gray;
59
+ }
60
+ #content .action A {
61
+ font-weight: bold;
62
+ text-decoration: none;
63
+ color: darkgreen;
64
+ border-bottom: 1px solid black;
65
+ }
66
+ #content .action A:hover {
67
+ color: red;
68
+ border-bottom: 1px solid red;
69
+ }
70
+ #content .page-header {
71
+ color: gray;
72
+ }
73
+
74
+ /* Page Listing */
75
+ #content .tree-controller {
76
+ border: 0px;
77
+ cursor: pointer;
78
+ }
79
+ #content .page-list.root {
80
+ clear: both;
81
+ list-style: none;
82
+ margin: 0px;
83
+ padding: 0px;
84
+ margin-top: 10px;
85
+ }
86
+ #content .page-list.collapsed {
87
+ display: none;
88
+ }
89
+ #content .page-list {
90
+ background: white;
91
+ clear: both;
92
+ list-style: none;
93
+ border-left: 0px dotted silver;
94
+ margin: 0px;
95
+ padding: 0px;
96
+ padding-left: 15px;
97
+ margin-top: 2px;
98
+ }
99
+ #content .page-list LI {
100
+ clear: both;
101
+ padding: 0px;
102
+ margin: 5px 0px;
103
+ padding-top: 2px;
104
+ padding-right: 0px;
105
+ padding-left: 2px;
106
+ }
107
+ #content .page-list .commands {
108
+ font-size: 90%;
109
+ padding-left: 5px;
110
+ color: silver;
111
+ }
112
+ #content .page-list .commands A {
113
+ color: gray;
114
+ }
115
+ #content .page-list .commands A.add-page:hover {
116
+ color: blue;
117
+ }
118
+ #content .page-list .commands A.reorder-children:hover {
119
+ color: black;
120
+ }
121
+ #content .page-list .commands A.delete-page:hover {
122
+ color: white;
123
+ }
124
+ #content .page-list .commands A.reordering {
125
+ background: navy;
126
+ color: white;
127
+ }
128
+ #content .page-list .commands A.reordering:hover {
129
+ color: white;
130
+ }
131
+ #content .page-list A.page {
132
+ text-decoration: none;
133
+ color: black;
134
+ margin-left: 3px;
135
+ font-size: 150%;
136
+ display: block;
137
+ }
138
+ #content .page-list A.page:hover {
139
+ /*color: blue;*/
140
+ background: white url(../images/comatose/title-hover-bg.gif) top left repeat-y;
141
+ }
142
+ #content .handle, #content .do-reorder UL LI .handle {
143
+ display: none;
144
+ }
145
+
146
+ #content .page-list .hover {
147
+ background: #F1F0DB;
148
+ }
149
+ #content .page-list .hover-delete {
150
+ background: red;
151
+ color: #FF8E90;
152
+ }
153
+ #content .page-list .hover-delete A,
154
+ #content .page-list .hover-delete .commands A {
155
+ color: #FF8E90;
156
+ }
157
+ #content .page-list .hover-delete A.page {
158
+ color: white;
159
+ border-bottom: 0px;
160
+ }
161
+ #content .page-list .hover-delete UL LI A.page {
162
+ color: red;
163
+ border-bottom: 0px;
164
+ }
165
+
166
+ #content .do-reorder LI .handle {
167
+ display: inline;
168
+ background: gray;
169
+ color: white;
170
+ padding: 1px 3px;
171
+ cursor: move;
172
+ }
173
+
174
+ #content .page-list .do-reorder .commands A {
175
+ display: none;
176
+ }
177
+
178
+ /* Page Form */
179
+ #content .page-form {
180
+ margin-top: 10px;
181
+ }
182
+ #content .page-form LABEL {
183
+ font-weight: bold;
184
+ color: #555;
185
+ }
186
+ #content .page-form .meta-info LABEL {
187
+ color: #999 !important;
188
+ }
189
+ #content .page-form .label {
190
+ padding-top: 5px;
191
+ width: 75px;
192
+ text-align: right;
193
+ padding-right: 10px;
194
+ }
195
+ #content .page-form .label.body {
196
+ vertical-align: top;
197
+ padding-top: 10px;
198
+ }
199
+ #content .page-form .field {
200
+ padding-top: 5px;
201
+ }
202
+ #content .page-form .field-help {
203
+ color: gray;
204
+ }
205
+ #content .page-form #page_title {
206
+ font-size: 125%;
207
+ font-weight: bold;
208
+ }
209
+ #content .page-form #page_slug {
210
+ color: gray;
211
+ }
212
+ #content .page-form #page_body {
213
+ font-family: monospace;
214
+ font-size: 110%;
215
+ }
216
+ #content #button-group {
217
+ padding: 10px;
218
+ text-align: right;
219
+ background-color: #EAEAEA;
220
+ margin-top: 10px;
221
+ }
222
+ #content #button-group .last-update {
223
+ float: left;
224
+ color: gray;
225
+ padding-top: 4px;
226
+ font-weight: bold;
227
+ }
228
+ #content #button-group .last-update LABEL {
229
+ font-weight: normal;
230
+ }
231
+ #content #button-group .last-update A {
232
+ color: gray;
233
+ }
234
+ #content #button-group A {
235
+ color: maroon;
236
+ }
237
+ #content #button-group A:hover {
238
+ color: red;
239
+ }
240
+ #content #preview-area {
241
+ margin-top: 10px;
242
+ }
243
+ #content #preview-area FIELDSET {
244
+ border: 1px solid silver;
245
+ }
246
+ #content #preview-area LEGEND {
247
+ font-size: 125%;
248
+ }
249
+ #content #preview-area .preview-body {
250
+ padding: 10px;
251
+ }
252
+ #content #preview-area .preview-note {
253
+ background: #FFFFD9;
254
+ padding: 15px;
255
+ }
256
+ #content #preview-area .commands {
257
+ text-align: right;
258
+ color: gray;
259
+ }
260
+ #content #preview-area .commands A{
261
+ color: gray;
262
+ }
263
+ #content #preview-area .commands A:hover{
264
+ color: black;
265
+ }
266
+ #content .revisions {
267
+ padding: 10px;
268
+ width: 49%;
269
+ }
270
+ #content .current-content {
271
+ }
272
+ #content .older-content {
273
+ background: #E9E9E9;
274
+ float: right;
275
+ }
276
+
277
+ #content .revisions label {
278
+ display: block;
279
+ color: #000;
280
+ }
281
+ #content .revisions label span {
282
+ color: #999;
283
+ font-weight: normal !important;
284
+ }
285
+ #content .revisions .title {
286
+ font-weight: bold;
287
+ margin-top: 5px;
288
+ }
289
+ #content .revisions .header {
290
+ font-size: 110%;
291
+ vertical-align: middle;
292
+ font-weight: bold;
293
+ }
294
+ #content .revisions .header-actions {
295
+ float: right;
296
+ font-size: 90%;
297
+ font-weight: normal;
298
+ color: #999;
299
+ }
300
+ #content .revisions .meta {
301
+ margin-bottom: 15px;
302
+ }
303
+ #content .revisions .footer {
304
+ margin-top: 25px !important;
305
+ text-align: center !important;
306
+ }
307
+ #content #go-btn {
308
+ display: none;
309
+ }
310
+ /* Errors */
311
+ #errorExplanation {
312
+ border: 1px solid red;
313
+ background: #FFEAEB;
314
+ padding: 10px;
315
+ margin-top: 10px;
316
+ }
317
+ #errorExplanation h2 {
318
+ margin: 0px;
319
+ padding: 0px;
320
+ color: maroon;
321
+ }
322
+ #errorExplanation p {
323
+ margin: 0px;
324
+ padding: 0px;
325
+ padding-top: 5px;
326
+ padding-left: 15px;
327
+ }
328
+ #errorExplanation ul {
329
+ margin: 0px;
330
+ padding: 0px;
331
+ padding-left: 35px;
332
+ }
333
+ #errorExplanation li {
334
+ margin: 0px;
335
+ padding: 0px;
336
+ padding-top: 5px;
337
+ }
338
+ /* Footer Area*/
339
+ #footer {
340
+ border-top: 4px solid #AAA;
341
+ text-align: center;
342
+ font-size: 90%;
343
+ color: #AAA;
344
+ padding-top: 5px;
345
+ padding-bottom: 5px;
346
+ }
347
+ #footer A {
348
+ color: #AAA;
349
+ text-decoration: none;
350
+ font-weight: bold;
351
+ }
352
+ #footer A:hover {
353
+ color: #333;
354
+ text-decoration: underline;
355
+ }
356
+
357
+ /* Modifiers */
358
+
359
+ /* When JavaScript is Turned Off... We need to adjust some things... */
360
+ .noscript #more-options,
361
+ .noscript #preview-area,
362
+ .noscript #preview-btn,
363
+ .noscript .tree-controller {
364
+ display: none;
365
+ }
366
+ .noscript .page-list.collapsed {
367
+ display: block !important;
368
+ }
369
+ .noscript .delete-page:hover {
370
+ color: red !important;
371
+ }
372
+ .noscript #content .page-form #page_title,
373
+ .noscript #content .page-form #page_slug,
374
+ .noscript #content .page-form #page_parent,
375
+ .noscript #content .page-form #page_keywords,
376
+ .noscript #content .page-form #page_body {
377
+ width: 100% !important;
378
+ }
379
+ .noscript #content .revisions #go-btn {
380
+ display: inline;
381
+ }
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'comatose'
3
+ rescue LoadError
4
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
5
+ end
6
+
7
+ require 'comatose/tasks/admin'
8
+ require 'comatose/tasks/setup'
9
+ require 'comatose/tasks/data'
data/test/behaviors.rb ADDED
@@ -0,0 +1,106 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+
4
+ module Behaviors
5
+ include Rake
6
+
7
+ class ReportTask < TaskLib
8
+ attr_accessor :pattern
9
+ attr_accessor :html_dir
10
+
11
+ def initialize(name=:behaviors)
12
+ @name = name
13
+ @html_dir = 'doc'
14
+ yield self if block_given?
15
+ define
16
+ end
17
+
18
+ def define
19
+ desc "List behavioral definitions for the classes specified (use for=<regexp> to further limit files included in report)"
20
+ task @name do
21
+ specifications.each do |spec|
22
+ puts "#{spec.name} should:\n"
23
+ spec.requirements.each do |req|
24
+ puts " - #{req}"
25
+ end
26
+ end
27
+ end
28
+
29
+ desc "Generate html report of behavioral definitions for the classes specified (use for=<regexp> to further limit files included in report)"
30
+ task "#{@name}_html" do
31
+ require 'erb'
32
+ txt =<<-EOS
33
+ <html><head>
34
+ <style>
35
+ div.title { width: 600px; font: bold 14pt trebuchet ms; }
36
+ div.specification { font: bold 12pt trebuchet ms; border: solid 1px black; width: 600px; padding: 5px; margin: 5px; }
37
+ ul.requirements { font: normal 11pt verdana; padding-left: 0; margin-left: 0; border-bottom: 1px solid gray; width: 600px; }
38
+ ul.requirements li { list-style: none; margin: 0; padding: 0.25em; border-top: 1px solid gray; }
39
+ </style>
40
+ </head>
41
+ <body>
42
+ <div class="title">Specifications</div>
43
+ <% specifications.each do |spec| %>
44
+ <div class="specification">
45
+ <%= spec.name %> should:
46
+ <ul class="requirements">
47
+ <% spec.requirements.each do |req| %>
48
+ <li><%= req %></li>
49
+ <% end %>
50
+ </ul>
51
+ </div>
52
+ <% end %>
53
+ </body>
54
+ </html>
55
+ EOS
56
+ output_dir = File.expand_path(@html_dir)
57
+ mkdir_p output_dir
58
+ output_filename = output_dir + "/behaviors.html"
59
+ File.open(output_filename,"w") do |f|
60
+ f.write ERB.new(txt).result(binding)
61
+ end
62
+ puts "(Wrote #{output_filename})"
63
+ end
64
+ end
65
+
66
+
67
+ protected
68
+
69
+ def test_files
70
+ test_list = FileList[@pattern]
71
+ if ENV['for']
72
+ test_list = test_list.grep(/#{ENV['for']}/i)
73
+ end
74
+ test_list
75
+ end
76
+
77
+ def specifications
78
+ test_files.map do |file|
79
+ spec = OpenStruct.new
80
+ m = %r".*/([^/].*)_test.rb".match(file)
81
+ class_name = titleize(m[1]) if m[1]
82
+ spec.name = class_name
83
+ spec.requirements = []
84
+ File::readlines(file).each do |line|
85
+ if line =~ /^\s*should\s+\(?\s*["'](.*)["']/
86
+ spec.requirements << $1
87
+ end
88
+ end
89
+ spec
90
+ end
91
+ end
92
+
93
+ def titleize(word)
94
+ humanize(underscore(word)).gsub(/\b([a-z])/) { $1.capitalize }
95
+ end
96
+
97
+ def underscore(camel_cased_word) camel_cased_word.to_s.gsub(/::/, '/').
98
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase
99
+ end
100
+
101
+ def humanize(lower_case_and_underscored_word)
102
+ lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize
103
+ end
104
+
105
+ end
106
+ end
@@ -0,0 +1,96 @@
1
+ # ComatosePage attributes
2
+ # - parent_id
3
+ # - title
4
+ # - full_path
5
+ # - slug
6
+ # - keywords
7
+ # - body
8
+ # - author
9
+ # - filter_type
10
+ # - position
11
+ # - version
12
+ # - updated_on
13
+ # - created_on
14
+
15
+ root:
16
+ id: 1
17
+ parent_id:
18
+ full_path: ""
19
+ slug: home-page
20
+ title: Home Page
21
+ body: |-
22
+ h1. {{ page.title }}
23
+
24
+ This is your *home page*.
25
+ author: Comatose
26
+ keywords: "test, cms"
27
+ filter_type: Textile
28
+ position: 0
29
+ created_on: <%= 10.days.ago.to_s :db %>
30
+ updated_on: <%= 10.days.ago.to_s :db %>
31
+
32
+ faq:
33
+ id: 2
34
+ parent_id: 1
35
+ full_path: "faq"
36
+ slug: faq
37
+ title: Frequently Asked Questions
38
+ body: |-
39
+ h1. {{ page.title }}
40
+ {% for c in page.children %}
41
+ h2. {{ c.link }}
42
+
43
+ {{ c.to_html }}
44
+
45
+ {% endfor %}
46
+ created_on: <%= 10.days.ago.to_s :db %>
47
+ updated_on: <%= 10.days.ago.to_s :db %>
48
+ author: Comatose
49
+ keywords: faq
50
+ filter_type: Textile
51
+ position: 0
52
+
53
+ question_one:
54
+ id: 3
55
+ parent_id: 2
56
+ full_path: "faq/question-one"
57
+ slug: question-one
58
+ title: Question One?
59
+ body: |-
60
+ Content for *question one*.
61
+ created_on: <%= 10.days.ago.to_s :db %>
62
+ updated_on: <%= 10.days.ago.to_s :db %>
63
+ author: Comatose
64
+ keywords: faq
65
+ filter_type: Textile
66
+ position: 0
67
+
68
+ question_two:
69
+ id: 4
70
+ parent_id: 2
71
+ full_path: "faq/question-two"
72
+ slug: question-two
73
+ title: Question Two?
74
+ body: |-
75
+ Content for *question two*.
76
+ created_on: <%= 10.days.ago.to_s :db %>
77
+ updated_on: <%= 10.days.ago.to_s :db %>
78
+ author: Comatose
79
+ keywords: faq
80
+ filter_type: Textile
81
+ position: 1
82
+
83
+ param_driven:
84
+ id: 5
85
+ parent_id: 1
86
+ full_path: "params"
87
+ slug: params
88
+ title: Params
89
+ body: |-
90
+ I'm {{ extra }}
91
+ created_on: <%= 10.days.ago.to_s :db %>
92
+ updated_on: <%= 10.days.ago.to_s :db %>
93
+ author: Comatose
94
+ keywords:
95
+ filter_type: Textile
96
+ position: 0
@@ -0,0 +1,112 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require 'comatose_admin_controller'
3
+ require 'comatose_admin_helper'
4
+ require 'text_filters'
5
+
6
+ # Re-raise errors caught by the controller.
7
+ class ComatoseAdminController
8
+ def rescue_action(e) raise e end
9
+ end
10
+
11
+ class ComatoseAdminControllerTest < Test::Unit::TestCase
12
+
13
+ fixtures :comatose_pages
14
+
15
+ def setup
16
+ @controller = ComatoseAdminController.new
17
+ @request = ActionController::TestRequest.new
18
+ @response = ActionController::TestResponse.new
19
+ end
20
+
21
+ should "show the index action" do
22
+ get :index
23
+ assert_response :success
24
+ assert assigns(:root_pages)
25
+ end
26
+
27
+ should "show the new action" do
28
+ get :new
29
+ assert_response :success
30
+ assert assigns(:page)
31
+ end
32
+
33
+ should "successfully create pages" do
34
+ post :new, :page=>{:title=>"Test page", :body=>'This is a *test*', :parent_id=>1, :filter_type=>'Textile'}
35
+ assert_response :redirect
36
+ assert_redirected_to :controller=>'comatose_admin', :action=>'index'
37
+ end
38
+
39
+ should "create a page with an empty body" do
40
+ post :new, :page=>{:title=>"Test page", :body=>nil, :parent_id=>1, :filter_type=>'Textile'}
41
+ assert_response :redirect
42
+ assert_redirected_to :controller=>'comatose_admin', :action=>'index'
43
+ end
44
+
45
+ should "not create a page with a missing title" do
46
+ post :new, :page=>{:title=>nil, :body=>'This is a *test*', :parent_id=>1, :filter_type=>'Textile'}
47
+ assert_response :success
48
+ assert assigns.has_key?('page'), "Page assignment"
49
+ assert (assigns['page'].errors.length > 0), "Page errors"
50
+ assert_equal 'must be present', assigns['page'].errors.on('title')
51
+ end
52
+
53
+ should "not create a page associated to an invalid parent" do
54
+ post :new, :page=>{:title=>'Test page', :body=>'This is a *test*', :parent_id=>nil, :filter_type=>'Textile'}
55
+ assert_response :success
56
+ assert assigns.has_key?('page'), "Page assignment"
57
+ assert (assigns['page'].errors.length > 0), "Page errors"
58
+ assert_equal 'must be present', assigns['page'].errors.on('parent_id')
59
+ end
60
+
61
+ should "contain all the correct options for filter_type" do
62
+ get :new
63
+ assert_response :success
64
+ assert_select 'SELECT[id=page_filter_type]>*', :count=>TextFilters.all_titles.length
65
+ end
66
+
67
+ should "show the edit action" do
68
+ get :edit, :id=>1
69
+ assert_response :success
70
+ end
71
+
72
+ should "update pages with valid data" do
73
+ post :edit, :id=>1, :page=>{ :title=>'A new title' }
74
+ assert_response :redirect
75
+ assert_redirected_to :action=>"index"
76
+ end
77
+
78
+ should "not update pages with invalid data" do
79
+ post :edit, :id=>1, :page=>{ :title=>nil }
80
+ assert_response :success
81
+ assert_equal 'must be present', assigns['page'].errors.on('title')
82
+ end
83
+
84
+ should "delete a page" do
85
+ post :delete, :id=>1
86
+ assert_response :redirect
87
+ assert_redirected_to :action=>"index"
88
+ end
89
+
90
+ should "reorder pages" do
91
+ q1 = comatose_page :question_one
92
+ assert_not_nil q1
93
+ assert_difference q1, :position do
94
+ post :reorder, :id=>q1.parent.id, :page=>q1.id, :cmd=>'down'
95
+ assert_response :redirect
96
+ assert_redirected_to :action=>"reorder"
97
+ q1.reload
98
+ end
99
+ end
100
+
101
+ should "set runtime mode" do
102
+ assert_equal :plugin, ComatoseAdminController.runtime_mode
103
+ comatose_admin_view_path = File.expand_path(File.join( File.dirname(__FILE__), '..', '..', 'views'))
104
+
105
+ if ComatoseAdminController.respond_to?(:template_root)
106
+ assert_equal comatose_admin_view_path, ComatoseAdminController.template_root
107
+ else
108
+ assert ComatoseAdminController.view_paths.include?(comatose_admin_view_path)
109
+ end
110
+ end
111
+
112
+ end