spontaneous 0.2.0.beta4 → 0.2.0.beta5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +39 -0
  3. data/Gemfile +11 -6
  4. data/Readme.markdown +136 -69
  5. data/application/css/core.css.scss +27 -7
  6. data/application/css/editing.css.scss +4 -26
  7. data/application/css/schema_error.css.scss +22 -0
  8. data/application/js/content.js +11 -3
  9. data/application/js/edit_panel.js +1 -4
  10. data/application/js/field/file.js +17 -0
  11. data/application/js/field/image.js +30 -21
  12. data/application/js/field/string.js +4 -1
  13. data/application/js/field_preview.js +21 -16
  14. data/application/js/publish.js +6 -6
  15. data/application/js/types.js +5 -13
  16. data/application/js/views.js +2 -2
  17. data/application/js/views/box_view.js +3 -2
  18. data/application/js/views/page_piece_view.js +1 -1
  19. data/application/js/views/piece_view.js +1 -1
  20. data/application/views/schema_modification_error.html.erb +13 -3
  21. data/db/migrations/20131104101935_site_must_publish_all.rb +14 -0
  22. data/lib/spontaneous.rb +0 -1
  23. data/lib/spontaneous/box_style.rb +15 -9
  24. data/lib/spontaneous/capistrano/deploy.rb +13 -1
  25. data/lib/spontaneous/change.rb +11 -13
  26. data/lib/spontaneous/cli.rb +5 -2
  27. data/lib/spontaneous/cli/assets.rb +7 -1
  28. data/lib/spontaneous/cli/console.rb +7 -1
  29. data/lib/spontaneous/cli/content.rb +35 -0
  30. data/lib/spontaneous/cli/fields.rb +3 -2
  31. data/lib/spontaneous/cli/generate.rb +5 -2
  32. data/lib/spontaneous/cli/server.rb +12 -8
  33. data/lib/spontaneous/cli/site.rb +12 -12
  34. data/lib/spontaneous/cli/user.rb +28 -14
  35. data/lib/spontaneous/collections/box_set.rb +4 -4
  36. data/lib/spontaneous/collections/field_set.rb +4 -4
  37. data/lib/spontaneous/collections/prototype_set.rb +12 -4
  38. data/lib/spontaneous/data_mapper.rb +11 -7
  39. data/lib/spontaneous/data_mapper/content_model.rb +8 -0
  40. data/lib/spontaneous/data_mapper/content_model/associations.rb +1 -1
  41. data/lib/spontaneous/data_mapper/dataset.rb +14 -2
  42. data/lib/spontaneous/data_mapper/scope.rb +33 -13
  43. data/lib/spontaneous/facet.rb +4 -0
  44. data/lib/spontaneous/field.rb +12 -12
  45. data/lib/spontaneous/field/base.rb +27 -22
  46. data/lib/spontaneous/field/boolean.rb +4 -4
  47. data/lib/spontaneous/field/date.rb +2 -2
  48. data/lib/spontaneous/field/file.rb +24 -18
  49. data/lib/spontaneous/field/html.rb +1 -1
  50. data/lib/spontaneous/field/image.rb +6 -19
  51. data/lib/spontaneous/field/location.rb +1 -1
  52. data/lib/spontaneous/field/long_string.rb +3 -3
  53. data/lib/spontaneous/field/markdown.rb +3 -3
  54. data/lib/spontaneous/field/select.rb +2 -2
  55. data/lib/spontaneous/field/string.rb +2 -2
  56. data/lib/spontaneous/field/tags.rb +2 -2
  57. data/lib/spontaneous/field/update.rb +21 -20
  58. data/lib/spontaneous/field/webvideo.rb +6 -6
  59. data/lib/spontaneous/field/webvideo/fallback.rb +2 -2
  60. data/lib/spontaneous/field/webvideo/vimeo.rb +7 -7
  61. data/lib/spontaneous/generators/site.rb +2 -2
  62. data/lib/spontaneous/generators/site/Gemfile.tt +5 -1
  63. data/lib/spontaneous/layout.rb +2 -2
  64. data/lib/spontaneous/media.rb +1 -0
  65. data/lib/spontaneous/media/file.rb +6 -5
  66. data/lib/spontaneous/media/image/attributes.rb +4 -0
  67. data/lib/spontaneous/media/image/renderable.rb +4 -4
  68. data/lib/spontaneous/media/store.rb +22 -0
  69. data/lib/spontaneous/{storage → media/store}/backend.rb +1 -1
  70. data/lib/spontaneous/{storage → media/store}/cloud.rb +1 -1
  71. data/lib/spontaneous/{storage → media/store}/local.rb +1 -1
  72. data/lib/spontaneous/media/temp_file.rb +1 -1
  73. data/lib/spontaneous/model.rb +10 -7
  74. data/lib/spontaneous/model/action.rb +7 -0
  75. data/lib/spontaneous/model/action/clean.rb +87 -0
  76. data/lib/spontaneous/model/box/allowed_types.rb +15 -1
  77. data/lib/spontaneous/model/core.rb +10 -0
  78. data/lib/spontaneous/model/core/aliases.rb +1 -1
  79. data/lib/spontaneous/model/core/content_groups.rb +1 -1
  80. data/lib/spontaneous/model/core/fields.rb +1 -1
  81. data/lib/spontaneous/model/core/modifications.rb +2 -2
  82. data/lib/spontaneous/model/core/page_search.rb +4 -0
  83. data/lib/spontaneous/model/core/publishing.rb +4 -17
  84. data/lib/spontaneous/model/core/render.rb +4 -4
  85. data/lib/spontaneous/model/core/styles.rb +2 -2
  86. data/lib/spontaneous/model/core/visibility.rb +6 -2
  87. data/lib/spontaneous/model/page.rb +6 -2
  88. data/lib/spontaneous/model/page/controllers.rb +55 -17
  89. data/lib/spontaneous/model/page/formats.rb +12 -7
  90. data/lib/spontaneous/model/page/layouts.rb +2 -2
  91. data/lib/spontaneous/model/page/locks.rb +4 -1
  92. data/lib/spontaneous/model/page/page_tree.rb +40 -6
  93. data/lib/spontaneous/output.rb +14 -52
  94. data/lib/spontaneous/output/context.rb +11 -39
  95. data/lib/spontaneous/output/context/navigation.rb +31 -0
  96. data/lib/spontaneous/output/format.rb +15 -19
  97. data/lib/spontaneous/output/renderable.rb +99 -0
  98. data/lib/spontaneous/output/store.rb +24 -0
  99. data/lib/spontaneous/output/store/backend.rb +52 -0
  100. data/lib/spontaneous/output/store/file.rb +77 -0
  101. data/lib/spontaneous/output/store/moneta.rb +117 -0
  102. data/lib/spontaneous/output/store/revision.rb +34 -0
  103. data/lib/spontaneous/output/store/store.rb +15 -0
  104. data/lib/spontaneous/output/store/transaction.rb +44 -0
  105. data/lib/spontaneous/output/template/engine.rb +17 -7
  106. data/lib/spontaneous/output/template/renderer.rb +66 -40
  107. data/lib/spontaneous/page_lock.rb +5 -7
  108. data/lib/spontaneous/page_piece.rb +2 -2
  109. data/lib/spontaneous/permissions/user.rb +14 -7
  110. data/lib/spontaneous/plugins/application/features.rb +8 -4
  111. data/lib/spontaneous/plugins/application/state.rb +12 -6
  112. data/lib/spontaneous/prototypes/box_prototype.rb +9 -10
  113. data/lib/spontaneous/prototypes/field_prototype.rb +66 -15
  114. data/lib/spontaneous/publishing/immediate.rb +30 -26
  115. data/lib/spontaneous/rack.rb +12 -7
  116. data/lib/spontaneous/rack/back.rb +43 -37
  117. data/lib/spontaneous/rack/back/base.rb +4 -4
  118. data/lib/spontaneous/rack/back/changes.rb +2 -2
  119. data/lib/spontaneous/rack/back/file.rb +16 -24
  120. data/lib/spontaneous/rack/back/map.rb +5 -5
  121. data/lib/spontaneous/rack/back/preview.rb +3 -4
  122. data/lib/spontaneous/rack/back/schema.rb +1 -1
  123. data/lib/spontaneous/rack/back/site.rb +6 -7
  124. data/lib/spontaneous/rack/front.rb +19 -16
  125. data/lib/spontaneous/rack/middleware/authenticate.rb +3 -3
  126. data/lib/spontaneous/rack/middleware/reloader.rb +3 -2
  127. data/lib/spontaneous/rack/middleware/scope.rb +25 -19
  128. data/lib/spontaneous/rack/page_controller.rb +164 -13
  129. data/lib/spontaneous/rack/public.rb +23 -62
  130. data/lib/spontaneous/rack/static.rb +2 -3
  131. data/lib/spontaneous/schema.rb +27 -8
  132. data/lib/spontaneous/schema/schema_modification.rb +9 -1
  133. data/lib/spontaneous/schema/uid.rb +2 -2
  134. data/lib/spontaneous/schema/uid_map.rb +3 -2
  135. data/lib/spontaneous/search/database.rb +2 -2
  136. data/lib/spontaneous/search/field.rb +5 -3
  137. data/lib/spontaneous/search/index.rb +12 -7
  138. data/lib/spontaneous/search/results.rb +5 -3
  139. data/lib/spontaneous/server.rb +2 -2
  140. data/lib/spontaneous/site.rb +10 -3
  141. data/lib/spontaneous/site/features.rb +26 -6
  142. data/lib/spontaneous/site/helpers.rb +9 -12
  143. data/lib/spontaneous/site/level.rb +7 -9
  144. data/lib/spontaneous/site/map.rb +9 -11
  145. data/lib/spontaneous/site/paths.rb +5 -5
  146. data/lib/spontaneous/site/publishing.rb +83 -80
  147. data/lib/spontaneous/site/schema.rb +1 -7
  148. data/lib/spontaneous/site/search.rb +8 -18
  149. data/lib/spontaneous/site/selectors.rb +60 -54
  150. data/lib/spontaneous/site/state.rb +36 -30
  151. data/lib/spontaneous/site/storage.rb +10 -16
  152. data/lib/spontaneous/state.rb +8 -0
  153. data/lib/spontaneous/style.rb +32 -33
  154. data/lib/spontaneous/version.rb +1 -1
  155. data/spontaneous.gemspec +22 -21
  156. data/test/fixtures/public/templates/layouts/default.html.cut +1 -1
  157. data/test/fixtures/public/templates/layouts/default.pdf.cut +1 -1
  158. data/test/fixtures/public/templates/layouts/default.rss.cut +1 -1
  159. data/test/fixtures/search/config/indexes.rb +1 -1
  160. data/test/fixtures/serialisation/class_hash.yaml.erb +13 -1
  161. data/test/fixtures/serialisation/root_hash.yaml.erb +10 -0
  162. data/test/functional/test_application.rb +20 -24
  163. data/test/functional/test_back.rb +26 -27
  164. data/test/functional/test_cli.rb +146 -0
  165. data/test/functional/test_front.rb +287 -216
  166. data/test/functional/test_user_manager.rb +1 -1
  167. data/test/test_helper.rb +15 -11
  168. data/test/unit/test_alias.rb +32 -25
  169. data/test/unit/test_asset_bundler.rb +1 -1
  170. data/test/unit/test_assets.rb +34 -33
  171. data/test/unit/test_authentication.rb +1 -1
  172. data/test/unit/test_boxes.rb +16 -2
  173. data/test/unit/test_changesets.rb +23 -11
  174. data/test/unit/test_content.rb +15 -0
  175. data/test/unit/test_context.rb +139 -0
  176. data/test/unit/test_controllers.rb +374 -0
  177. data/test/{experimental → unit}/test_crypt.rb +0 -0
  178. data/test/unit/test_datamapper.rb +260 -237
  179. data/test/unit/test_datamapper_content.rb +42 -12
  180. data/test/{experimental → unit}/test_features.rb +85 -3
  181. data/test/unit/test_fields.rb +117 -42
  182. data/test/unit/test_formats.rb +11 -1
  183. data/test/unit/test_generators.rb +2 -2
  184. data/test/unit/test_helpers.rb +7 -8
  185. data/test/unit/test_images.rb +39 -2
  186. data/test/unit/test_layouts.rb +14 -12
  187. data/test/unit/test_media.rb +32 -23
  188. data/test/unit/test_output_store.rb +342 -0
  189. data/test/unit/test_page.rb +8 -1
  190. data/test/unit/test_permissions.rb +11 -7
  191. data/test/unit/test_plugins.rb +3 -3
  192. data/test/unit/test_prototype_set.rb +8 -1
  193. data/test/unit/test_publishing.rb +67 -54
  194. data/test/unit/test_render.rb +91 -38
  195. data/test/unit/test_revisions.rb +4 -4
  196. data/test/unit/test_schema.rb +109 -84
  197. data/test/unit/test_search.rb +42 -42
  198. data/test/unit/test_serialisation.rb +3 -2
  199. data/test/unit/test_site.rb +39 -27
  200. data/test/unit/test_storage.rb +9 -6
  201. data/test/unit/test_styles.rb +25 -32
  202. data/test/unit/test_templates.rb +8 -4
  203. metadata +89 -54
  204. data/lib/spontaneous/model/page/request.rb +0 -105
  205. data/lib/spontaneous/storage.rb +0 -22
@@ -0,0 +1,146 @@
1
+ require 'foreman/engine/cli'
2
+
3
+
4
+
5
+ require File.expand_path('../../test_helper', __FILE__)
6
+
7
+
8
+ describe "CLI" do
9
+ let(:cli) { Spontaneous::Cli }
10
+ let(:root) { cli::Root }
11
+
12
+ describe "Console" do
13
+ let(:cmd) { cli::Console }
14
+ it "maps 'spot console' to Console#open" do
15
+ cmd.any_instance.expects(:open_console)
16
+ root.start(["console"])
17
+ end
18
+ it "maps 'spot c' to Console#open" do
19
+ cmd.any_instance.expects(:open_console)
20
+ root.start(["c"])
21
+ end
22
+ end
23
+
24
+ describe "Server" do
25
+ let(:cmd) { cli::Server }
26
+
27
+ def expect_subcommand_launch
28
+ foreman = mock()
29
+ foreman.expects(:register).with("front", regexp_matches(/spot server front/))
30
+ foreman.expects(:register).with("back", regexp_matches(/spot server back/))
31
+ foreman.expects(:register).with("tasks", regexp_matches(/spot server tasks/))
32
+ foreman.expects(:start)
33
+ ::Foreman::Engine::CLI.expects(:new).returns(foreman)
34
+ end
35
+
36
+ it "maps 'spot server' to Server#start" do
37
+ cmd.any_instance.expects(:start)
38
+ root.start(["server"])
39
+ end
40
+
41
+ it "'spot server' launches front & back" do
42
+ expect_subcommand_launch
43
+ root.start(["server"])
44
+ end
45
+
46
+ it "'spot s' launches front & back" do
47
+ expect_subcommand_launch
48
+ root.start(["s"])
49
+ end
50
+
51
+ it "maps 'spot server back' to Server#back" do
52
+ silence_logger do
53
+ cmd.any_instance.expects(:start_server).with(:back)
54
+ root.start(["server", "back"])
55
+ end
56
+ end
57
+
58
+ it "maps 'spot s back' to Server#back" do
59
+ silence_logger do
60
+ cmd.any_instance.expects(:start_server).with(:back)
61
+ root.start(["s", "back"])
62
+ end
63
+ end
64
+
65
+ it "maps 'spot server front' to Server#front" do
66
+ silence_logger do
67
+ cmd.any_instance.expects(:start_server).with(:front)
68
+ root.start(["server", "front"])
69
+ end
70
+ end
71
+
72
+ it "maps 'spot s front' to Server#front" do
73
+ silence_logger do
74
+ cmd.any_instance.expects(:start_server).with(:front)
75
+ root.start(["s", "front"])
76
+ end
77
+ end
78
+
79
+ it "maps 'spot server tasks' to Server#tasks" do
80
+ silence_logger do
81
+ cmd.any_instance.expects(:start_simultaneous)
82
+ root.start(["server", "tasks"])
83
+ end
84
+ end
85
+
86
+ it "maps 'spot s tasks' to Server#tasks" do
87
+ silence_logger do
88
+ cmd.any_instance.expects(:start_simultaneous)
89
+ root.start(["s", "tasks"])
90
+ end
91
+ end
92
+ end
93
+
94
+ describe "User" do
95
+ let(:cmd) { cli::User }
96
+ it "maps 'spot user' to User#add" do
97
+ cmd.any_instance.expects(:add_user)
98
+ root.start(["user"])
99
+ end
100
+
101
+ it "maps 'spot user add' to User#add" do
102
+ cmd.any_instance.expects(:add_user)
103
+ root.start(["user", "add"])
104
+ end
105
+
106
+ it "maps 'spot user list' to User#list" do
107
+ cmd.any_instance.expects(:list_users)
108
+ root.start(["user", "list"])
109
+ end
110
+
111
+ it "maps 'spot user authenticate' to User#authenticate" do
112
+ cmd.any_instance.expects(:authenticate_user).with("garry", "fishingrod")
113
+ root.start(["user", "authenticate", "garry", "fishingrod"])
114
+ end
115
+ end
116
+ describe "Generate" do
117
+ let(:cmd) { cli::Generate }
118
+ let(:generator) { ::Spontaneous::Generators::Site }
119
+ it "maps 'generate site' to Generate#site" do
120
+ generator.expects(:start).with([])
121
+ root.start(["generate", "site"])
122
+ end
123
+
124
+ it "maps 'generate example.com' to Generate#site" do
125
+ generator.expects(:start).with(['example.com'])
126
+ root.start(["generate", "example.com"])
127
+ end
128
+
129
+ end
130
+
131
+ describe "Assets" do
132
+ let(:cmd) { cli::Assets }
133
+ it "maps 'spot assets compile' to Assets#compile" do
134
+ cmd.any_instance.expects(:compile_assets)
135
+ root.start(["assets", "compile", "--destination=/tmp/destination"])
136
+ end
137
+ end
138
+
139
+ describe "Content" do
140
+ let(:cmd) { cli::Content }
141
+ it "maps 'spot content clean' to Content#clean" do
142
+ cmd.any_instance.expects(:clean_content)
143
+ root.start(["content", "clean"])
144
+ end
145
+ end
146
+ end
@@ -8,6 +8,8 @@ describe "Front" do
8
8
  include RackTestMethods
9
9
 
10
10
  start do
11
+ @warn_level = $VERBOSE
12
+ $VERBOSE = nil
11
13
  site_root = Dir.mktmpdir
12
14
  FileUtils.cp_r(File.expand_path("../../fixtures/public/templates", __FILE__), site_root)
13
15
  Spontaneous::Output.write_compiled_scripts = true
@@ -15,13 +17,21 @@ describe "Front" do
15
17
 
16
18
  site = setup_site(site_root)
17
19
  let(:site) { site }
18
- S::Site.background_mode = :immediate
19
20
  S::State.delete
20
21
 
21
- Site.background_mode = :immediate
22
+ site.background_mode = :immediate
23
+ site.output_store :Memory
22
24
  ::Content.delete
23
25
 
26
+ class ::Page
27
+ controller do
28
+ set :show_exceptions, false
29
+ set :raise_errors, true
30
+ set :dump_errors, true
31
+ end
32
+ end
24
33
  class ::SitePage < ::Page
34
+ add_output :pdf
25
35
  layout :default
26
36
  layout :dynamic
27
37
  box :pages
@@ -32,65 +42,99 @@ describe "Front" do
32
42
  class ::StaticPage < ::Page
33
43
  layout :default
34
44
  end
35
- class ::SubPage < SitePage; end
36
45
 
46
+ class ::DynamicRequestParams < ::Page
47
+ layout(:html) { "{{ params[:horse] }}*{{ equine }}" }
48
+ end
49
+
50
+ class ::DynamicRenderParams < ::Page
51
+ add_output :mobile
52
+ add_output :session
53
+ add_output :params
54
+ layout(:html) { "{{ teeth }}${ path }.${ __format }" }
55
+ layout(:mobile) { "${ path }.${ __format }" }
56
+ layout(:session) { %[{{session['user_id']}}/{{params['wendy']}}/{{request.env["SERVER_NAME"]}}] }
57
+ layout(:params) { "{{ something }}"}
58
+ end
59
+
60
+ class ::CommentablePage < ::Page
61
+ attr_accessor :status
62
+
63
+ add_output :xml
64
+ add_output :post
65
+ layout(:html) { "${path}.${ __format }" }
66
+ layout(:post) { "{{results.join(',')}}" }
67
+ layout(:xml) { "${ path}.${ __format }" }
68
+ box :pages
69
+ end
70
+
71
+ class ::FeedPage < ::Page
72
+ outputs :rss, [:html, {:mimetype => "application/xhtml+xml"}], [:pdf, {:private => true}]
73
+ layout { "${ path }.${ __format }" }
74
+ end
37
75
 
38
76
  root = ::SitePage.create
39
77
  about = ::SitePage.create(:slug => "about", :uid => "about")
40
- subpage = ::SubPage.create(:slug => "now", :uid => "now")
78
+ feed = ::FeedPage.create(:slug => "feed", :uid => "feed")
41
79
  news = ::SitePage.create(:slug => "news", :uid => "news")
42
- dynamic = ::SitePage.create(:slug => "dynamic", :uid => "dynamic")
43
80
  static = ::StaticPage.create(:slug => "static", :uid => "static")
44
- dynamic.layout = :dynamic
81
+ dynamic_request_params = ::DynamicRequestParams.create(slug: "dynamic-request-params", uid: "dynamic_request_params")
82
+ dynamic_render_params = ::DynamicRenderParams.create(slug: "dynamic-render-params", uid: "dynamic_render_params")
83
+ commentable = ::CommentablePage.create(slug:"commentable", uid: "commentable")
45
84
  root.pages << about
85
+ root.pages << feed
46
86
  root.pages << news
47
- root.pages << dynamic
87
+ root.pages << dynamic_request_params
88
+ root.pages << dynamic_render_params
48
89
  root.pages << static
49
- about.pages << subpage
90
+ root.pages << commentable
50
91
  root.save
51
92
 
52
93
  let(:root_id) { root.id }
53
94
  let(:about_id) { about.id }
54
- let(:subpage_id) { subpage.id }
95
+ let(:feed_id) { feed.id }
55
96
  let(:news_id) { news.id }
56
- let(:dynamic_id) { dynamic.id }
97
+ let(:dynamic_request_params_id) { dynamic_request_params.id }
98
+ let(:dynamic_render_params_id) { dynamic_render_params.id }
57
99
  let(:static_id) { static.id }
100
+ let(:commentable_id) { commentable.id }
58
101
 
59
102
  Content.delete_revision(1) rescue nil
60
103
 
61
104
  Spontaneous.logger.silent! {
62
- S::Site.publish_all
105
+ site.publish_all
63
106
  }
64
107
  end
65
108
 
66
109
  finish do
67
- Object.send(:remove_const, :SitePage) rescue nil
68
- Object.send(:remove_const, :SubPage) rescue nil
69
- Content.delete
110
+ [:SitePage, :StaticPage, :DynamicRequestParams, :DynamicRenderParams, :CommentablePage, :FeedPage].each do |const|
111
+ Object.send(:remove_const, const) rescue nil
112
+ end
113
+ if defined?(Content)
114
+ Content.delete
115
+ Content.delete_revision(1)
116
+ end
70
117
  S::State.delete
71
- Content.delete_revision(1)
72
118
  teardown_site(true)
73
119
  Spontaneous::Output.write_compiled_scripts = false
120
+ $VERBOSE = @warn_level
74
121
  end
75
122
 
76
123
  let(:root) { Content[root_id] }
77
124
  let(:about) { Content[about_id] }
78
- let(:subpage) { Content[subpage_id] }
125
+ let(:feed) { Content[feed_id] }
79
126
  let(:news) { Content[news_id] }
80
- let(:dynamic) { Content[dynamic_id] }
127
+ let(:dynamic_request_params) { Content[dynamic_request_params_id] }
128
+ let(:dynamic_render_params) { Content[dynamic_render_params_id] }
81
129
  let(:static) { Content[static_id] }
130
+ let(:commentable) { Content[commentable_id] }
82
131
 
83
132
  def app
84
- Spontaneous::Rack::Front.application
133
+ @app ||= Spontaneous::Rack::Front.application(site)
85
134
  end
86
135
 
87
- after do
88
- SitePage.instance_variable_set(:@layout_procs, nil)
89
- SitePage.instance_variable_set(:@request_blocks, {})
90
- [root, about, subpage, news, static].each do |page|
91
- page.layout = :default
92
- end
93
- dynamic.layout = :dynamic
136
+ def renderer
137
+ @renderer ||= Spontaneous::Output::Template::PublishRenderer.new(site, true)
94
138
  end
95
139
 
96
140
  def session
@@ -103,10 +147,6 @@ describe "Front" do
103
147
 
104
148
  describe "Public pages" do
105
149
 
106
- after do
107
- about.class.outputs :html
108
- end
109
-
110
150
  it "return a 404 if asked for a non-existant page" do
111
151
  get '/not-bloody-likely'
112
152
  assert last_response.status == 404
@@ -133,7 +173,6 @@ describe "Front" do
133
173
  end
134
174
 
135
175
  it "honor the format of the request" do
136
- about.class.outputs :html, :pdf
137
176
  get '/about.pdf'
138
177
  assert last_response.ok?
139
178
  last_response.body.must_equal "/about.pdf\n"
@@ -141,19 +180,17 @@ describe "Front" do
141
180
  end
142
181
 
143
182
  it "provide the default format of the page if none is explicitly given" do
144
- about.class.outputs :rss, :html
145
- get '/about'
183
+ get '/feed'
146
184
  assert last_response.ok?
147
185
  last_response.content_type.must_equal ::Rack::Mime.mime_type('.rss') + ";charset=utf-8"
148
- last_response.body.must_equal "/about.rss\n"
186
+ last_response.body.must_equal "/feed.rss"
149
187
  end
150
188
 
151
189
  it "return a custom content type if one is defined" do
152
- about.class.outputs [:html, {:mimetype => "application/xhtml+xml"}]
153
- get '/about'
190
+ get '/feed.html'
154
191
  assert last_response.ok?
155
192
  last_response.content_type.must_equal "application/xhtml+xml;charset=utf-8"
156
- last_response.body.must_equal "/about.html\n"
193
+ last_response.body.must_equal "/feed.html"
157
194
  end
158
195
 
159
196
 
@@ -163,21 +200,19 @@ describe "Front" do
163
200
  end
164
201
 
165
202
  it "raise a 404 when accessing a private format" do
166
- about.class.outputs [:html, {:mimetype => "application/xhtml+xml"}], [:rss, {:private => true}]
167
- get '/about.rss'
203
+ get '/feed.pdf'
168
204
  assert last_response.status == 404
169
205
  end
170
206
 
171
207
  describe "Dynamic pages" do
172
208
  before do
209
+ Content::Page.stubs(:path).with("/").returns(root)
173
210
  Content::Page.stubs(:path).with("/about").returns(about)
174
211
  Content::Page.stubs(:path).with("/static").returns(static)
175
212
  Content::Page.stubs(:path).with("/news").returns(news)
176
213
  end
177
214
 
178
215
  after do
179
- about.layout = :default
180
- SitePage.instance_variable_set(:@request_blocks, {})
181
216
  end
182
217
 
183
218
  it "default to static behaviour" do
@@ -185,139 +220,176 @@ describe "Front" do
185
220
  page = SitePage.new
186
221
  refute page.dynamic?
187
222
  end
223
+
188
224
  it "correctly show a dynamic behaviour" do
189
- SitePage.request do
190
- show "/static"
225
+ DynamicRenderParams.controller do
226
+ get { show "/static" }
191
227
  end
192
- assert SitePage.dynamic?
193
- page = SitePage.new
228
+ assert DynamicRenderParams.dynamic?
229
+ page = DynamicRenderParams.new
194
230
  assert page.dynamic?
195
231
  end
196
232
 
197
233
  it "render an alternate page if passed a page" do
198
- SitePage.request do
199
- show Site['/static']
234
+ DynamicRenderParams.controller do
235
+ get { render site['/static'] }
200
236
  end
201
- get '/about'
237
+ get '/dynamic-render-params'
202
238
  assert last_response.ok?
203
239
  last_response.body.must_equal "/static.html\n"
204
240
  end
205
241
 
206
242
  it "render an alternate page if passed a path" do
207
- # about.stubs(:request_show).returns("/news")
208
- SitePage.request do
209
- show "/static"
243
+ DynamicRenderParams.controller do
244
+ get { render "/static" }
210
245
  end
211
- get '/about'
246
+ get '/dynamic-render-params'
212
247
  assert last_response.ok?
213
248
  last_response.body.must_equal "/static.html\n"
214
249
  end
215
250
 
216
251
  it "render an alternate page if passed a uid with a #" do
217
- # about.stubs(:request_show).returns("#news")
218
- SitePage.request do
219
- show "static"
252
+ DynamicRenderParams.controller do
253
+ get { render "static" }
220
254
  end
221
- get '/about'
255
+ get '/dynamic-render-params'
222
256
  assert last_response.ok?
223
257
  last_response.body.must_equal "/static.html\n"
224
258
  end
225
259
 
226
260
  it "render an alternate page if passed a uid" do
227
- # about.stubs(:request_show).returns("news")
228
- SitePage.request do
229
- show "static"
261
+ DynamicRenderParams.controller do
262
+ get { render "static" }
230
263
  end
231
- get '/about'
264
+ get '/dynamic-render-params'
232
265
  assert last_response.ok?
233
266
  last_response.body.must_equal "/static.html\n"
234
267
  end
235
268
 
236
269
  it "return not found of #request_show returns an invalid uid or path" do
237
- # about.stubs(:request_show).returns("caterpillars")
238
- SitePage.request do
239
- show "caterpillars"
270
+ DynamicRenderParams.controller do
271
+ get { render "caterpillars" }
240
272
  end
241
- get '/about'
273
+ get '/dynamic-render-params'
242
274
  assert last_response.status == 404
243
275
  end
244
276
 
245
277
  it "return the right status code" do
246
- SitePage.request do
247
- show "static", 404
278
+ DynamicRenderParams.controller do
279
+ get { render "static", 403 }
248
280
  end
249
- get '/about'
250
- assert last_response.status == 404
281
+ get '/dynamic-render-params'
282
+ assert last_response.status == 403
251
283
  last_response.body.must_equal "/static.html\n"
252
284
  end
253
285
 
254
286
  it "allow handing POST requests" do
255
- SitePage.request :post do
256
- show "static"
287
+ DynamicRenderParams.controller do
288
+ post { render "static" }
257
289
  end
258
- post '/about'
290
+ post '/dynamic-render-params'
259
291
  assert last_response.status == 200, "Expected status 200 but recieved #{last_response.status}"
260
292
  last_response.body.must_equal "/static.html\n"
261
293
  end
262
294
 
263
295
  it "allow returning of any status code without altering content" do
264
- SitePage.request do
265
- 404
296
+ DynamicRenderParams.controller do
297
+ get { render 403 }
266
298
  end
267
- get '/about'
268
- assert last_response.status == 404
269
- last_response.body.must_equal "/about.html\n"
299
+ get '/dynamic-render-params'
300
+ assert last_response.status == 403
301
+ last_response.body.must_equal "/dynamic-render-params.html"
270
302
  end
271
303
 
272
304
  it "allow altering of headers" do
273
- SitePage.request do
274
- headers["X-Works"] = "Yes"
305
+ DynamicRenderParams.controller do
306
+ get do
307
+ headers["X-Works"] = "Yes"
308
+ render
309
+ end
275
310
  end
276
- get '/about'
311
+ get '/dynamic-render-params'
277
312
  assert last_response.status == 200
278
- last_response.body.must_equal "/about.html\n"
313
+ last_response.body.must_equal "/dynamic-render-params.html"
279
314
  last_response.headers["X-Works"].must_equal "Yes"
280
315
  end
281
316
 
282
317
  it "allow passing of template params & a page to the render call" do
283
- SitePage.layout do
284
- "{{ teeth }}"
318
+ DynamicRenderParams.controller do
319
+ get { render page, :teeth => "blue" }
320
+ end
321
+ get '/dynamic-render-params'
322
+ assert last_response.status == 200
323
+ last_response.body.must_equal "blue/dynamic-render-params.html"
324
+ end
325
+
326
+ it "allows setting status code and passing parameters to the show call" do
327
+ DynamicRenderParams.controller do
328
+ get { render "$dynamic_render_params", 401, :teeth => "white" }
285
329
  end
286
- SitePage.request do
287
- render page, :teeth => "white"
330
+ get '/dynamic-render-params'
331
+ assert last_response.status == 401
332
+ last_response.body.must_equal "white/dynamic-render-params.html"
333
+ end
334
+
335
+ it "allows passing parameters to the render call" do
336
+ DynamicRenderParams.controller do
337
+ get { render "$dynamic_render_params", :teeth => "white" }
288
338
  end
289
- get '/about'
339
+ get '/dynamic-render-params'
290
340
  assert last_response.status == 200
291
- last_response.body.must_equal "white"
292
- SitePage.instance_variable_set(:@layout_procs, nil)
341
+ last_response.body.must_equal "white/dynamic-render-params.html"
293
342
  end
294
343
 
295
344
  it "give access to the request params within the controller" do
296
- SitePage.layout { "{{ params[:horse] }}*{{ equine }}" }
297
- SitePage.request :post do
298
- value = params[:horse]
299
- render page, :equine => value
345
+ DynamicRequestParams.controller do
346
+ post do
347
+ value = params[:horse]
348
+ render page, :equine => value
349
+ end
300
350
  end
301
- post '/about', :horse => "dancing"
351
+ post '/dynamic-request-params', :horse => "dancing"
302
352
  assert last_response.status == 200
303
353
  last_response.body.must_equal "dancing*dancing"
304
- SitePage.instance_variable_set(:@layout_procs, nil)
305
354
  end
306
355
 
307
356
  it "allows for dynamically setting the output" do
308
- SitePage.add_output :mobile
309
- SitePage.layout do
310
- "${ path }.${ __format }"
311
- end
312
- SitePage.request :get do
313
- if request.user_agent =~ /iPhone/
314
- output :mobile
357
+ DynamicRenderParams.controller do
358
+ get do
359
+ if request.user_agent =~ /iPhone/
360
+ output :mobile
361
+ end
362
+ render teeth: "clean"
315
363
  end
316
364
  end
317
- get "/about", {}, { "HTTP_USER_AGENT" => "Desktop" }
318
- last_response.body.must_equal "/about.html"
319
- get "/about", {}, { "HTTP_USER_AGENT" => "iPhone" }
320
- last_response.body.must_equal "/about.mobile"
365
+ get "/dynamic-render-params", {}, { "HTTP_USER_AGENT" => "Desktop" }
366
+ assert last_response.status == 200, "Expected status 200 but got #{last_response.status}"
367
+ last_response.body.must_equal "clean/dynamic-render-params.html"
368
+ get "/dynamic-render-params", {}, { "HTTP_USER_AGENT" => "iPhone" }
369
+ last_response.body.must_equal "/dynamic-render-params.mobile"
370
+ end
371
+
372
+ it "inherits any request handlers from superclasses" do
373
+ # request block inheritance is done at type creation & is not dynamic
374
+ # so we need to create a new class that will inherit the newly minted
375
+ # :get request handler
376
+ DynamicRenderParams.controller do
377
+ get { render "about" }
378
+ end
379
+
380
+ class ::TempPage < DynamicRenderParams; end
381
+
382
+ temp = ::TempPage.create(:slug => "temp", :uid => "temp")
383
+ root.pages << temp
384
+ root.save
385
+ site.model.stubs(:path).with("/temp").returns(temp)
386
+
387
+ get "/temp"
388
+ last_response.status.must_equal 200
389
+ last_response.body.must_equal "/about.html\n"
390
+
391
+ temp.destroy
392
+ Object.send(:remove_const, "TempPage")
321
393
  end
322
394
 
323
395
  # should "handle anything that responds to #render(format)" do
@@ -336,55 +408,57 @@ describe "Front" do
336
408
  end
337
409
 
338
410
  it "respond appropriatly to redirects to path" do
339
- SitePage.request do
340
- redirect "/news"
411
+ DynamicRenderParams.controller do
412
+ get do
413
+ redirect "/news"
414
+ end
341
415
  end
342
- get '/about'
416
+ get '/dynamic-render-params'
343
417
  assert last_response.status == 302
344
418
  last_response.headers["Location"].must_equal "http://example.org/news"
345
419
  end
346
420
 
347
421
  it "respond appropriately to redirects to a Page instance" do
348
- SitePage.request do
349
- redirect Page.path("/news")
422
+ DynamicRenderParams.controller do
423
+ get { redirect Page.path("/news") }
350
424
  end
351
- get '/about'
425
+ get '/dynamic-render-params'
352
426
  assert last_response.status == 302
353
427
  last_response.headers["Location"].must_equal "http://example.org/news"
354
428
  end
355
429
 
356
430
  it "respond appropriately to redirects to a UID" do
357
- SitePage.request do
358
- redirect "news"
431
+ DynamicRenderParams.controller do
432
+ get { redirect "news" }
359
433
  end
360
- get '/about'
434
+ get '/dynamic-render-params'
361
435
  assert last_response.status == 302
362
436
  last_response.headers["Location"].must_equal "http://example.org/news"
363
437
  end
364
438
 
365
439
  it "recognise a :temporary redirect" do
366
- SitePage.request do
367
- redirect "/news", :temporary
440
+ DynamicRenderParams.controller do
441
+ get { redirect "/news", :temporary }
368
442
  end
369
- get '/about'
443
+ get '/dynamic-render-params'
370
444
  assert last_response.status == 302
371
445
  last_response.headers["Location"].must_equal "http://example.org/news"
372
446
  end
373
447
 
374
448
  it "recognise a :permanent redirect" do
375
- SitePage.request do
376
- redirect "/news", :permanent
449
+ DynamicRenderParams.controller do
450
+ get { redirect "/news", :permanent }
377
451
  end
378
- get '/about'
452
+ get '/dynamic-render-params'
379
453
  assert last_response.status == 301
380
454
  last_response.headers["Location"].must_equal "http://example.org/news"
381
455
  end
382
456
 
383
457
  it "correctly apply numeric status codes" do
384
- SitePage.request do
385
- redirect "/news", 307
458
+ DynamicRenderParams.controller do
459
+ get { redirect "/news", 307 }
386
460
  end
387
- get '/about'
461
+ get '/dynamic-render-params'
388
462
  last_response.headers["Location"].must_equal "http://example.org/news"
389
463
  assert last_response.status == 307
390
464
  end
@@ -404,55 +478,60 @@ describe "Front" do
404
478
  end
405
479
 
406
480
  it "have access to the params, request & session object" do
407
- get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
408
- assert last_response.ok?
409
- last_response.body.must_equal "42/peter/example.org\n"
481
+ DynamicRenderParams.controller do
482
+ get { render }
483
+ end
484
+ get '/dynamic-render-params.session', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
485
+ assert last_response.ok?, "Expected status 200 but got #{last_response.status}"
486
+ last_response.body.must_equal "42/peter/example.org"
410
487
  end
411
488
 
489
+ # Disabled for the moment while I think about the implications of the
490
+ # template store & if there isn't a better way to optimise the render
491
+ # by using a LRU cache of the compiled classes or something like that.
412
492
  describe "caching" do
413
- it "use pre-rendered versions of the templates" do
414
- dummy_content = 'cached-version/#{session[\'user_id\']}'
415
- dummy_template = File.join(site.revision_root, "current/dynamic/dynamic.html.cut")
416
- File.open(dummy_template, 'w') { |f| f.write(dummy_content) }
417
- get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
418
- last_response.body.must_equal "cached-version/42"
419
- end
420
-
421
- it "cache templates as ruby files" do
422
- dummy_content = 'cached-version/#{session[\'user_id\']}'
423
- dummy_template = File.join(site.revision_root, "current/dynamic/index.html.cut")
424
- Spontaneous::Output.renderer.write_compiled_scripts = true
425
- File.open(dummy_template, 'w') { |f| f.write(dummy_content) }
426
- FileUtils.rm(@cache_file) if File.exists?(@cache_file)
427
- refute File.exists?(@cache_file)
428
- get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
429
-
430
- assert File.exists?(@cache_file)
431
- File.open(@cache_file, 'w') { |f| f.write('@__buf << %Q`@cache_filed-version/#{params[\'wendy\']}`;')}
432
- # Force compiled file to have a later timestamp
433
- File.utime(Time.now, Time.now + 1, @cache_file)
434
- get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
435
- last_response.body.must_equal "@cache_filed-version/peter"
436
- end
437
-
438
- it "not cache templates if caching turned off" do
439
- Spontaneous::Output.cache_templates = false
440
- refute File.exists?(@cache_file)
441
- get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
442
- refute File.exists?(@cache_file)
443
- end
493
+ # it "use pre-rendered versions of the templates" do
494
+ # dummy_content = 'cached-version/#{session[\'user_id\']}'
495
+ # dummy_template = File.join(site.revision_root, "current/dynamic/dynamic.html.cut")
496
+ # File.open(dummy_template, 'w') { |f| f.write(dummy_content) }
497
+ # get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
498
+ # last_response.body.must_equal "cached-version/42"
499
+ # end
500
+
501
+ # it "cache templates as ruby files" do
502
+ # dummy_content = 'cached-version/#{session[\'user_id\']}'
503
+ # dummy_template = File.join(site.revision_root, "current/dynamic/index.html.cut")
504
+ # # Spontaneous::Output.renderer.write_compiled_scripts = true
505
+ # File.open(dummy_template, 'w') { |f| f.write(dummy_content) }
506
+ # FileUtils.rm(@cache_file) if File.exists?(@cache_file)
507
+ # refute File.exists?(@cache_file)
508
+ # get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
509
+
510
+ # assert File.exists?(@cache_file)
511
+ # File.open(@cache_file, 'w') { |f| f.write('@__buf << %Q`@cache_filed-version/#{params[\'wendy\']}`;')}
512
+ # # Force compiled file to have a later timestamp
513
+ # File.utime(Time.now, Time.now + 1, @cache_file)
514
+ # get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
515
+ # last_response.body.must_equal "@cache_filed-version/peter"
516
+ # end
517
+
518
+ # it "not cache templates if caching turned off" do
519
+ # Spontaneous::Output.cache_templates = false
520
+ # refute File.exists?(@cache_file)
521
+ # get '/dynamic', {'wendy' => 'peter'}, 'rack.session' => { 'user_id' => 42 }
522
+ # refute File.exists?(@cache_file)
523
+ # end
444
524
  end
445
525
  end
446
526
 
447
527
  describe "Model controllers" do
448
528
  before do
449
- SitePage.instance_variable_set(:@request_blocks, {})
450
529
  class ::TestController < Spontaneous::Rack::PageController
451
530
  get '/' do
452
531
  "Magic"
453
532
  end
454
533
  end
455
- SitePage.controller :comments do
534
+ CommentablePage.controller :comments do
456
535
  get '/' do
457
536
  "Success"
458
537
  end
@@ -465,7 +544,7 @@ describe "Front" do
465
544
  end
466
545
  end
467
546
 
468
- SitePage.controller :status do
547
+ CommentablePage.controller :status do
469
548
  get '/:status' do
470
549
  page.status = params[:status]
471
550
  page
@@ -477,7 +556,7 @@ describe "Front" do
477
556
  end
478
557
  end
479
558
 
480
- SitePage.controller :search do
559
+ CommentablePage.controller :search do
481
560
  get '/render/:query' do
482
561
  render({ results: %w(a b c)})
483
562
  end
@@ -487,149 +566,141 @@ describe "Front" do
487
566
  end
488
567
 
489
568
  get '/renderoutput/:query' do
490
- render page, :xml, { results: %w(a b c)}
569
+ render page, :post, { results: %w(a b c)}
491
570
  end
492
571
  end
493
572
 
494
- SitePage.controller :test, ::TestController
573
+ CommentablePage.controller :test, ::TestController
495
574
 
496
- SitePage.controller :test2, ::TestController do
575
+ CommentablePage.controller :test2, ::TestController do
497
576
  get "/block" do
498
577
  "Block"
499
578
  end
500
579
  end
501
580
 
581
+ class ::SubPage < CommentablePage; end
582
+ @subpage = ::SubPage.create(:slug => "now", :uid => "now")
583
+ commentable.pages << @subpage
584
+
585
+ @subpage.reload
586
+
502
587
  Content.stubs(:path).with("/").returns(root)
503
- Content.stubs(:path).with("/about").returns(about)
504
- Content.stubs(:path).with("/about/now").returns(subpage)
588
+ Content.stubs(:path).with("/commentable").returns(commentable)
589
+ Content.stubs(:path).with("/commentable/now").returns(@subpage)
590
+ @renderer = Spontaneous::Output.published_renderer(site)
505
591
  end
506
592
 
507
593
  after do
508
- SitePage.instance_variable_set(:@request_blocks, {})
509
- SitePage.send(:remove_const, :StatusController) rescue nil
510
- SitePage.send(:remove_const, :TestController) rescue nil
511
- SitePage.send(:remove_const, :Test2Controller) rescue nil
594
+ Object.send(:remove_const, :SubPage) rescue nil
595
+ CommentablePage.instance_variable_set(:@request_blocks, {})
596
+ CommentablePage.send(:remove_const, :StatusController) rescue nil
597
+ CommentablePage.send(:remove_const, :TestController) rescue nil
598
+ CommentablePage.send(:remove_const, :Test2Controller) rescue nil
512
599
  Object.send(:remove_const, :TestController) rescue nil
513
- about.class.outputs :html
514
600
  end
515
601
 
516
602
  it "not be used unless necessary" do
517
- get "/about"
603
+ get "/commentable"
518
604
  assert last_response.ok?
519
- last_response.body.must_equal about.render
605
+ last_response.body.must_equal commentable.render_using(@renderer).read
520
606
  end
521
607
 
522
- it "work on the homepage" do
523
- get "/@comments"
608
+ it "work on sub classes" do
609
+ get "/commentable/now/@comments"
524
610
  assert last_response.ok?
525
611
  last_response.body.must_equal "Success"
526
612
  end
527
613
 
528
614
 
529
615
  it "be recognised" do
530
- get "/about/@comments"
616
+ get "/commentable/@comments"
531
617
  assert last_response.ok?
532
618
  last_response.body.must_equal "Success"
533
619
  end
534
620
 
535
621
  it "render the page correctly if action returns page object" do
536
- get "/about/@comments/page"
622
+ get "/commentable/@comments/page"
537
623
  assert last_response.ok?
538
- last_response.body.must_equal about.render
624
+ last_response.body.must_equal commentable.render_using(@renderer).read
539
625
  end
540
626
 
541
627
  it "return 404 if trying unknown namespace" do
542
- get "/about/@missing/action"
628
+ get "/commentable/@missing/action"
543
629
  assert last_response.status == 404
544
630
  end
545
631
 
546
632
  it "respond to multiple namespaces" do
547
- get "/about/@status/good"
633
+ get "/commentable/@status/good"
548
634
  assert last_response.ok?
549
- last_response.body.must_equal about.render
550
- about.status.must_equal "good"
635
+ last_response.body.must_equal commentable.render_using(@renderer).read
636
+ commentable.status.must_equal "good"
551
637
  end
552
638
 
553
639
  it "accept POST requests" do
554
- post "/about/@status/good"
640
+ post "/commentable/@status/good"
555
641
  assert last_response.ok?
556
- last_response.body.must_equal about.render
557
- about.status.must_equal "good"
642
+ last_response.body.must_equal commentable.render_using(@renderer).read
643
+ commentable.status.must_equal "good"
558
644
  end
559
645
 
560
646
  it "return 404 unless post request has an action" do
561
- Page.expects(:path).with("/about").never
562
- post "/about"
647
+ Page.expects(:path).with("/commentable").never
648
+ post "/commentable"
563
649
  assert last_response.status == 404
564
650
  end
565
651
 
566
652
  it "return 404 for post requests to unknown actions" do
567
- post "/about/@status/missing/action"
653
+ post "/commentable/@status/missing/action"
568
654
  assert last_response.status == 404
569
655
  end
570
656
 
571
657
  # probably the wrong place to test this -- should be in units -- but what the heck
572
658
  it "be able to generate urls for actions" do
573
- about.action_url(:status, "/good").must_equal "/about/@status/good"
659
+ commentable.action_url(:status, "/good").must_equal "/commentable/@status/good"
574
660
  end
575
661
 
576
662
  it "be able to generate urls for actions with no path" do
577
- about.action_url(:status).must_equal "/about/@status"
663
+ commentable.action_url(:status).must_equal "/commentable/@status"
578
664
  end
579
665
 
580
666
  it "pass the output onto the page if the action returns it to the render call" do
581
- about.class.outputs :html, :xml
582
- about.class.layout do
583
- "${path}.${__format}"
584
- end
585
- get "/about/@comments/page.xml"
667
+ get "/commentable/@comments/page.xml"
586
668
  assert last_response.ok?
587
- last_response.body.must_equal "/about.xml"
669
+ last_response.body.must_equal "/commentable.xml"
588
670
  end
589
671
 
590
672
  it "use the format within the action if required" do
591
- about.class.outputs :html, :xml
592
- get "/about/@comments/format.xml"
593
- assert last_response.ok?
673
+ get "/commentable/@comments/format.xml"
674
+ assert last_response.ok?, "Expected status 200 but got #{last_response.status}"
594
675
  last_response.body.must_equal "xml"
595
676
  end
596
677
 
597
678
  it "be inherited by subclasses" do
598
- get "/about/now/@comments"
679
+ get "/commentable/now/@comments"
599
680
  assert last_response.ok?
600
681
  last_response.body.must_equal "Success"
601
682
  end
602
683
 
603
684
  it "allow definition of controller using class" do
604
- get "/about/@test"
685
+ get "/commentable/@test"
605
686
  assert last_response.ok?
606
687
  last_response.body.must_equal "Magic"
607
688
  end
608
689
 
609
690
  it "allow definition of controller using class and extend it using block" do
610
- get "/about/@test2/block"
691
+ get "/commentable/@test2/block"
611
692
  assert last_response.ok?
612
693
  last_response.body.must_equal "Block"
613
694
  end
614
695
 
615
696
  it "allows passing parameters to the page render" do
616
- about.class.outputs :html, :xml
617
- about.class.layout do
618
- "{{results.join(',')}}"
619
- end
620
-
621
- get "/about/@search/render/query.xml"
697
+ get "/commentable/@search/render/query.post"
622
698
  assert last_response.ok?, "Expected 200 OK but got #{last_response.status}"
623
699
  last_response.body.must_equal "a,b,c"
624
700
  end
625
701
 
626
702
  it "allows passing an output to the page render" do
627
- about.class.outputs :html, :xml
628
- about.class.layout do
629
- "{{results.join(',')}}"
630
- end
631
-
632
- get "/about/@search/renderoutput/query"
703
+ get "/commentable/@search/renderoutput/query"
633
704
  assert last_response.ok?, "Expected 200 OK but got #{last_response.status}"
634
705
  last_response.body.must_equal "a,b,c"
635
706
  end
@@ -642,7 +713,7 @@ describe "Front" do
642
713
  end
643
714
  end
644
715
 
645
- SitePage.controller :drummer do
716
+ CommentablePage.controller :drummer do
646
717
  get '/' do
647
718
  "Success"
648
719
  end
@@ -654,8 +725,8 @@ describe "Front" do
654
725
  end
655
726
 
656
727
  it "affect all controller actions" do
657
- get "/about/@drummer/nothing"
658
- assert last_response.ok?
728
+ get "/commentable/@drummer/nothing"
729
+ assert last_response.ok?, "Expected 200 got #{last_response.status}"
659
730
  last_response.body.must_equal "Something"
660
731
  end
661
732
  end
@@ -703,4 +774,4 @@ describe "Front" do
703
774
  end
704
775
  end
705
776
  end
706
- end
777
+ end