merb-core 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (246) hide show
  1. data/LICENSE +20 -0
  2. data/README +21 -0
  3. data/Rakefile +285 -0
  4. data/TODO +0 -0
  5. data/bin/merb +8 -0
  6. data/bin/merb-specs +5 -0
  7. data/docs/bootloading.dox +57 -0
  8. data/docs/documentation_standards +40 -0
  9. data/docs/new_render_api +51 -0
  10. data/lib/merb-core.rb +304 -0
  11. data/lib/merb-core/autoload.rb +29 -0
  12. data/lib/merb-core/bootloader.rb +601 -0
  13. data/lib/merb-core/config.rb +284 -0
  14. data/lib/merb-core/constants.rb +43 -0
  15. data/lib/merb-core/controller/abstract_controller.rb +531 -0
  16. data/lib/merb-core/controller/exceptions.rb +257 -0
  17. data/lib/merb-core/controller/merb_controller.rb +214 -0
  18. data/lib/merb-core/controller/mime.rb +88 -0
  19. data/lib/merb-core/controller/mixins/controller.rb +262 -0
  20. data/lib/merb-core/controller/mixins/render.rb +324 -0
  21. data/lib/merb-core/controller/mixins/responder.rb +464 -0
  22. data/lib/merb-core/controller/template.rb +205 -0
  23. data/lib/merb-core/core_ext.rb +12 -0
  24. data/lib/merb-core/core_ext/class.rb +192 -0
  25. data/lib/merb-core/core_ext/hash.rb +422 -0
  26. data/lib/merb-core/core_ext/kernel.rb +304 -0
  27. data/lib/merb-core/core_ext/mash.rb +154 -0
  28. data/lib/merb-core/core_ext/object.rb +136 -0
  29. data/lib/merb-core/core_ext/object_space.rb +14 -0
  30. data/lib/merb-core/core_ext/rubygems.rb +28 -0
  31. data/lib/merb-core/core_ext/set.rb +41 -0
  32. data/lib/merb-core/core_ext/string.rb +69 -0
  33. data/lib/merb-core/dispatch/cookies.rb +92 -0
  34. data/lib/merb-core/dispatch/dispatcher.rb +233 -0
  35. data/lib/merb-core/dispatch/exceptions.html.erb +297 -0
  36. data/lib/merb-core/dispatch/request.rb +560 -0
  37. data/lib/merb-core/dispatch/router.rb +141 -0
  38. data/lib/merb-core/dispatch/router/behavior.rb +777 -0
  39. data/lib/merb-core/dispatch/router/cached_proc.rb +52 -0
  40. data/lib/merb-core/dispatch/router/route.rb +212 -0
  41. data/lib/merb-core/dispatch/session.rb +28 -0
  42. data/lib/merb-core/dispatch/session/cookie.rb +166 -0
  43. data/lib/merb-core/dispatch/session/memcached.rb +161 -0
  44. data/lib/merb-core/dispatch/session/memory.rb +234 -0
  45. data/lib/merb-core/gem_ext/erubis.rb +19 -0
  46. data/lib/merb-core/logger.rb +230 -0
  47. data/lib/merb-core/plugins.rb +25 -0
  48. data/lib/merb-core/rack.rb +15 -0
  49. data/lib/merb-core/rack/adapter.rb +42 -0
  50. data/lib/merb-core/rack/adapter/ebb.rb +22 -0
  51. data/lib/merb-core/rack/adapter/evented_mongrel.rb +24 -0
  52. data/lib/merb-core/rack/adapter/fcgi.rb +16 -0
  53. data/lib/merb-core/rack/adapter/irb.rb +108 -0
  54. data/lib/merb-core/rack/adapter/mongrel.rb +25 -0
  55. data/lib/merb-core/rack/adapter/runner.rb +27 -0
  56. data/lib/merb-core/rack/adapter/thin.rb +27 -0
  57. data/lib/merb-core/rack/adapter/webrick.rb +35 -0
  58. data/lib/merb-core/rack/application.rb +77 -0
  59. data/lib/merb-core/rack/handler/mongrel.rb +97 -0
  60. data/lib/merb-core/server.rb +184 -0
  61. data/lib/merb-core/test.rb +10 -0
  62. data/lib/merb-core/test/helpers.rb +9 -0
  63. data/lib/merb-core/test/helpers/controller_helper.rb +8 -0
  64. data/lib/merb-core/test/helpers/multipart_request_helper.rb +175 -0
  65. data/lib/merb-core/test/helpers/request_helper.rb +257 -0
  66. data/lib/merb-core/test/helpers/route_helper.rb +33 -0
  67. data/lib/merb-core/test/helpers/view_helper.rb +121 -0
  68. data/lib/merb-core/test/matchers.rb +9 -0
  69. data/lib/merb-core/test/matchers/controller_matchers.rb +269 -0
  70. data/lib/merb-core/test/matchers/route_matchers.rb +136 -0
  71. data/lib/merb-core/test/matchers/view_matchers.rb +293 -0
  72. data/lib/merb-core/test/run_specs.rb +38 -0
  73. data/lib/merb-core/test/tasks/spectasks.rb +39 -0
  74. data/lib/merb-core/test/test_ext/hpricot.rb +32 -0
  75. data/lib/merb-core/test/test_ext/object.rb +14 -0
  76. data/lib/merb-core/vendor/facets.rb +2 -0
  77. data/lib/merb-core/vendor/facets/dictionary.rb +433 -0
  78. data/lib/merb-core/vendor/facets/inflect.rb +211 -0
  79. data/lib/merb-core/version.rb +11 -0
  80. data/spec/private/config/adapter_spec.rb +32 -0
  81. data/spec/private/config/config_spec.rb +139 -0
  82. data/spec/private/config/environment_spec.rb +13 -0
  83. data/spec/private/config/spec_helper.rb +1 -0
  84. data/spec/private/core_ext/hash_spec.rb +506 -0
  85. data/spec/private/core_ext/kernel_spec.rb +46 -0
  86. data/spec/private/core_ext/object_spec.rb +39 -0
  87. data/spec/private/core_ext/set_spec.rb +26 -0
  88. data/spec/private/core_ext/string_spec.rb +9 -0
  89. data/spec/private/dispatch/cookies_spec.rb +107 -0
  90. data/spec/private/dispatch/dispatch_spec.rb +26 -0
  91. data/spec/private/dispatch/fixture/app/controllers/application.rb +4 -0
  92. data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +27 -0
  93. data/spec/private/dispatch/fixture/app/controllers/foo.rb +21 -0
  94. data/spec/private/dispatch/fixture/app/helpers/global_helpers.rb +8 -0
  95. data/spec/private/dispatch/fixture/app/views/exeptions/client_error.html.erb +37 -0
  96. data/spec/private/dispatch/fixture/app/views/exeptions/internal_server_error.html.erb +216 -0
  97. data/spec/private/dispatch/fixture/app/views/exeptions/not_acceptable.html.erb +38 -0
  98. data/spec/private/dispatch/fixture/app/views/exeptions/not_found.html.erb +40 -0
  99. data/spec/private/dispatch/fixture/app/views/foo/bar.html.erb +0 -0
  100. data/spec/private/dispatch/fixture/app/views/layout/application.html.erb +11 -0
  101. data/spec/private/dispatch/fixture/config/environments/development.rb +6 -0
  102. data/spec/private/dispatch/fixture/config/environments/production.rb +5 -0
  103. data/spec/private/dispatch/fixture/config/environments/test.rb +6 -0
  104. data/spec/private/dispatch/fixture/config/init.rb +45 -0
  105. data/spec/private/dispatch/fixture/config/rack.rb +1 -0
  106. data/spec/private/dispatch/fixture/config/router.rb +35 -0
  107. data/spec/private/dispatch/fixture/log/development.log +1 -0
  108. data/spec/private/dispatch/fixture/log/merb.4000.pid +1 -0
  109. data/spec/private/dispatch/fixture/log/merb_test.log +2040 -0
  110. data/spec/private/dispatch/fixture/log/production.log +1 -0
  111. data/spec/private/dispatch/fixture/merb.4000.pid +1 -0
  112. data/spec/private/dispatch/fixture/public/images/merb.jpg +0 -0
  113. data/spec/private/dispatch/fixture/public/merb.fcgi +4 -0
  114. data/spec/private/dispatch/fixture/public/stylesheets/master.css +119 -0
  115. data/spec/private/dispatch/route_params_spec.rb +24 -0
  116. data/spec/private/dispatch/spec_helper.rb +1 -0
  117. data/spec/private/plugins/plugin_spec.rb +81 -0
  118. data/spec/private/rack/application_spec.rb +43 -0
  119. data/spec/public/DEFINITIONS +11 -0
  120. data/spec/public/abstract_controller/controllers/alt_views/layout/application.erb +1 -0
  121. data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_string_controller_layout.erb +1 -0
  122. data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_template_controller_layout.erb +1 -0
  123. data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/index.erb +1 -0
  124. data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/show.erb +1 -0
  125. data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +1 -0
  126. data/spec/public/abstract_controller/controllers/alt_views/partial/basic_partial_with_multiple_roots/_partial.erb +1 -0
  127. data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_and_custom_location/index.erb +1 -0
  128. data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_inherited/index.erb +1 -0
  129. data/spec/public/abstract_controller/controllers/display.rb +54 -0
  130. data/spec/public/abstract_controller/controllers/filters.rb +167 -0
  131. data/spec/public/abstract_controller/controllers/helpers.rb +31 -0
  132. data/spec/public/abstract_controller/controllers/partial.rb +106 -0
  133. data/spec/public/abstract_controller/controllers/render.rb +86 -0
  134. data/spec/public/abstract_controller/controllers/views/helpers/capture/index.erb +1 -0
  135. data/spec/public/abstract_controller/controllers/views/helpers/concat/index.erb +1 -0
  136. data/spec/public/abstract_controller/controllers/views/layout/alt.erb +1 -0
  137. data/spec/public/abstract_controller/controllers/views/layout/custom.erb +1 -0
  138. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object/index.erb +1 -0
  139. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object_with_action/new.erb +1 -0
  140. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template/index.erb +1 -0
  141. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_app_layout/index.erb +0 -0
  142. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_custom_layout/index.erb +1 -0
  143. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +1 -0
  144. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/show.erb +1 -0
  145. data/spec/public/abstract_controller/controllers/views/partial/another_directory/_partial.erb +1 -0
  146. data/spec/public/abstract_controller/controllers/views/partial/basic_partial/_partial.erb +1 -0
  147. data/spec/public/abstract_controller/controllers/views/partial/basic_partial/index.erb +1 -0
  148. data/spec/public/abstract_controller/controllers/views/partial/basic_partial_with_multiple_roots/index.erb +1 -0
  149. data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_first.erb +1 -0
  150. data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_second.erb +1 -0
  151. data/spec/public/abstract_controller/controllers/views/partial/nested_partial/index.erb +1 -0
  152. data/spec/public/abstract_controller/controllers/views/partial/partial_in_another_directory/index.erb +1 -0
  153. data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/_collection.erb +1 -0
  154. data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/index.erb +1 -0
  155. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/_collection.erb +1 -0
  156. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/index.erb +1 -0
  157. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/_collection.erb +1 -0
  158. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/index.erb +1 -0
  159. data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/_variables.erb +1 -0
  160. data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/index.erb +1 -0
  161. data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/_both.erb +1 -0
  162. data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/index.erb +1 -0
  163. data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/_with_partial.erb +1 -0
  164. data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/index.erb +1 -0
  165. data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/_with_partial.erb +1 -0
  166. data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/index.erb +1 -0
  167. data/spec/public/abstract_controller/controllers/views/partial/with_partial/_with_partial.erb +1 -0
  168. data/spec/public/abstract_controller/controllers/views/partial/with_partial/index.erb +1 -0
  169. data/spec/public/abstract_controller/controllers/views/test_display/foo.html.erb +1 -0
  170. data/spec/public/abstract_controller/controllers/views/test_render/foo.html.erb +0 -0
  171. data/spec/public/abstract_controller/controllers/views/wonderful/index.erb +1 -0
  172. data/spec/public/abstract_controller/display_spec.rb +33 -0
  173. data/spec/public/abstract_controller/filter_spec.rb +80 -0
  174. data/spec/public/abstract_controller/helper_spec.rb +13 -0
  175. data/spec/public/abstract_controller/partial_spec.rb +53 -0
  176. data/spec/public/abstract_controller/render_spec.rb +70 -0
  177. data/spec/public/abstract_controller/spec_helper.rb +27 -0
  178. data/spec/public/boot_loader/boot_loader_spec.rb +33 -0
  179. data/spec/public/boot_loader/spec_helper.rb +1 -0
  180. data/spec/public/controller/base_spec.rb +31 -0
  181. data/spec/public/controller/controllers/base.rb +41 -0
  182. data/spec/public/controller/controllers/display.rb +40 -0
  183. data/spec/public/controller/controllers/responder.rb +67 -0
  184. data/spec/public/controller/controllers/url.rb +7 -0
  185. data/spec/public/controller/controllers/views/layout/custom.html.erb +1 -0
  186. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.html.erb +1 -0
  187. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.xml.erb +1 -0
  188. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/index.html.erb +1 -0
  189. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/html_default/index.html.erb +1 -0
  190. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/layout/custom.html.erb +1 -0
  191. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.html.erb +1 -0
  192. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.xml.erb +1 -0
  193. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.html.erb +1 -0
  194. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.js.erb +1 -0
  195. data/spec/public/controller/display_spec.rb +34 -0
  196. data/spec/public/controller/log/merb.4000.pid +1 -0
  197. data/spec/public/controller/responder_spec.rb +95 -0
  198. data/spec/public/controller/spec_helper.rb +9 -0
  199. data/spec/public/controller/url_spec.rb +152 -0
  200. data/spec/public/directory_structure/directory/app/controllers/application.rb +3 -0
  201. data/spec/public/directory_structure/directory/app/controllers/base.rb +13 -0
  202. data/spec/public/directory_structure/directory/app/controllers/custom.rb +19 -0
  203. data/spec/public/directory_structure/directory/app/views/base/template.html.erb +1 -0
  204. data/spec/public/directory_structure/directory/app/views/wonderful/template.erb +1 -0
  205. data/spec/public/directory_structure/directory/config/router.rb +3 -0
  206. data/spec/public/directory_structure/directory/log/merb.4000.pid +1 -0
  207. data/spec/public/directory_structure/directory/log/merb_test.log +265 -0
  208. data/spec/public/directory_structure/directory/merb.4000.pid +1 -0
  209. data/spec/public/directory_structure/directory_spec.rb +44 -0
  210. data/spec/public/logger/logger_spec.rb +175 -0
  211. data/spec/public/logger/spec_helper.rb +1 -0
  212. data/spec/public/reloading/directory/app/controllers/application.rb +3 -0
  213. data/spec/public/reloading/directory/app/controllers/reload.rb +6 -0
  214. data/spec/public/reloading/directory/config/init.rb +2 -0
  215. data/spec/public/reloading/directory/log/merb.4000.pid +1 -0
  216. data/spec/public/reloading/directory/log/merb_test.log +59 -0
  217. data/spec/public/reloading/directory/merb.4000.pid +1 -0
  218. data/spec/public/reloading/reload_spec.rb +80 -0
  219. data/spec/public/request/multipart_spec.rb +15 -0
  220. data/spec/public/request/request_spec.rb +207 -0
  221. data/spec/public/router/default_spec.rb +21 -0
  222. data/spec/public/router/deferred_spec.rb +22 -0
  223. data/spec/public/router/namespace_spec.rb +113 -0
  224. data/spec/public/router/nested_resources_spec.rb +34 -0
  225. data/spec/public/router/resource_spec.rb +45 -0
  226. data/spec/public/router/resources_spec.rb +57 -0
  227. data/spec/public/router/spec_helper.rb +72 -0
  228. data/spec/public/router/special_spec.rb +44 -0
  229. data/spec/public/router/string_spec.rb +61 -0
  230. data/spec/public/template/template_spec.rb +92 -0
  231. data/spec/public/template/templates/error.html.erb +2 -0
  232. data/spec/public/template/templates/template.html.erb +1 -0
  233. data/spec/public/template/templates/template.html.myt +1 -0
  234. data/spec/public/test/controller_matchers_spec.rb +378 -0
  235. data/spec/public/test/controllers/controller_assertion_mock.rb +7 -0
  236. data/spec/public/test/controllers/dispatch_controller.rb +11 -0
  237. data/spec/public/test/controllers/spec_helper_controller.rb +30 -0
  238. data/spec/public/test/multipart_request_helper_spec.rb +159 -0
  239. data/spec/public/test/multipart_upload_text_file.txt +1 -0
  240. data/spec/public/test/request_helper_spec.rb +153 -0
  241. data/spec/public/test/route_helper_spec.rb +54 -0
  242. data/spec/public/test/route_matchers_spec.rb +133 -0
  243. data/spec/public/test/view_helper_spec.rb +96 -0
  244. data/spec/public/test/view_matchers_spec.rb +107 -0
  245. data/spec/spec_helper.rb +71 -0
  246. metadata +488 -0
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ describe Merb::AbstractController, " with capture and concat" do
4
+
5
+ it "should support capture" do
6
+ dispatch_should_make_body("Capture", "Capture")
7
+ end
8
+
9
+ it "should support concat" do
10
+ dispatch_should_make_body("Concat", "Concat")
11
+ end
12
+
13
+ end
@@ -0,0 +1,53 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ describe Merb::AbstractController, " Partials" do
4
+
5
+ it "should work with no options" do
6
+ dispatch_should_make_body("BasicPartial", "Index Partial")
7
+ end
8
+
9
+ it "should work with :with" do
10
+ dispatch_should_make_body("WithPartial", "Partial with With")
11
+ end
12
+
13
+ it "should work with nil :with" do
14
+ dispatch_should_make_body("WithNilPartial", "Partial with nil local")
15
+ end
16
+
17
+ it "should work with :with and :as" do
18
+ dispatch_should_make_body("WithAsPartial", "Partial with With and As")
19
+ end
20
+
21
+ it "should work with collections" do
22
+ dispatch_should_make_body("PartialWithCollections", "Partial with collection")
23
+ end
24
+
25
+ it "should work with collections and :as" do
26
+ dispatch_should_make_body("PartialWithCollectionsAndAs", "Partial with collection")
27
+ end
28
+
29
+ it "should work with key/value pairs of locals" do
30
+ dispatch_should_make_body("PartialWithLocals", "Partial with local variables")
31
+ end
32
+
33
+ it "should work with both collections and locals" do
34
+ dispatch_should_make_body("PartialWithBoth", "Partial with c-o-l-l-e-c-t-i-o-n-")
35
+ end
36
+
37
+ it "should work with both :with/:as and regular locals" do
38
+ dispatch_should_make_body("PartialWithWithAndLocals", "Partial with with and locals")
39
+ end
40
+
41
+ it "should work with a partial in another directory" do
42
+ dispatch_should_make_body("PartialInAnotherDirectory", "Index Partial in another directory")
43
+ end
44
+
45
+ it "should work with nested partials with locals" do
46
+ dispatch_should_make_body("NestedPartial", "first second first")
47
+ end
48
+
49
+ it "should work with multiple template roots" do
50
+ dispatch_should_make_body("BasicPartialWithMultipleRoots", "Base Index: Alt Partial")
51
+ end
52
+
53
+ end
@@ -0,0 +1,70 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ describe Merb::AbstractController, " rendering plain strings" do
4
+
5
+ before do
6
+ Merb.push_path(:layout, File.dirname(__FILE__) / "controllers" / "views" / "layouts")
7
+ end
8
+
9
+ it "should support rendering plain strings with no layout" do
10
+ dispatch_should_make_body("RenderString", "the index")
11
+ end
12
+
13
+ it "should support rendering plain strings with custom layouts" do
14
+ dispatch_should_make_body("RenderStringCustomLayout", "Custom: the index")
15
+ end
16
+
17
+ it "should support rendering plain strings with the application layout" do
18
+ dispatch_should_make_body("RenderStringAppLayout", "App: the index")
19
+ end
20
+
21
+ it "should support rendering plain strings with the controller layout" do
22
+ dispatch_should_make_body("RenderStringControllerLayout", "Controller: the index")
23
+ end
24
+
25
+ it "should support rendering plain strings with dynamic layouts" do
26
+ dispatch_should_make_body("RenderStringDynamicLayout", "Custom: the index", :index)
27
+ dispatch_should_make_body("RenderStringDynamicLayout", "Alt: the alt index", :alt_index)
28
+ end
29
+
30
+ end
31
+
32
+ describe Merb::AbstractController, " rendering templates" do
33
+
34
+ it "should support rendering templates with no layout" do
35
+ dispatch_should_make_body("RenderTemplate", "the index")
36
+ end
37
+
38
+ it "should support rendering templates with custom layouts" do
39
+ dispatch_should_make_body("RenderStringCustomLayout", "Custom: the index")
40
+ end
41
+
42
+ it "should support rendering templates with the application layout" do
43
+ dispatch_should_make_body("RenderTemplateAppLayout", "App: the index")
44
+ end
45
+
46
+ it "should support rendering plain strings with the controller layout" do
47
+ dispatch_should_make_body("RenderTemplateControllerLayout", "Controller: the index")
48
+ end
49
+
50
+ it "should support rendering templates with a custom location" do
51
+ dispatch_should_make_body("RenderTemplateCustomLocation", "Wonderful")
52
+ end
53
+
54
+ it "should support rendering templates with multiple roots" do
55
+ dispatch_should_make_body("RenderTemplateMultipleRoots", "App: Multiple")
56
+ end
57
+
58
+ it "should support rendering templates with multiple roots, first root" do
59
+ dispatch_should_make_body("RenderTemplateMultipleRoots", "default show", "show")
60
+ end
61
+
62
+ it "should support rendering templates with multiple roots and custom location" do
63
+ dispatch_should_make_body("RenderTemplateMultipleRootsAndCustomLocation", "Woot.")
64
+ end
65
+
66
+ it "should support rendering templates with multiple roots and custom location from an inherited controller" do
67
+ dispatch_should_make_body("RenderTemplateMultipleRootsInherited", "Good.")
68
+ end
69
+
70
+ end
@@ -0,0 +1,27 @@
1
+ __DIR__ = File.dirname(__FILE__)
2
+ require File.join(__DIR__, "..", "..", "spec_helper")
3
+
4
+ require File.join(__DIR__, "controllers", "filters")
5
+ require File.join(__DIR__, "controllers", "render")
6
+ require File.join(__DIR__, "controllers", "partial")
7
+ require File.join(__DIR__, "controllers", "display")
8
+ require File.join(__DIR__, "controllers", "helpers")
9
+
10
+ Merb.start :environment => 'test'
11
+
12
+ module Merb::Test::Behaviors
13
+ include Merb::Test::RequestHelper
14
+
15
+ def dispatch_should_make_body(klass, body, action = :index, opts = {})
16
+ controller = Merb::Test::Fixtures::Abstract.const_get(klass).new
17
+ if opts.key?(:presets)
18
+ opts[:presets].each { |attr, value| controller.send(attr, value)}
19
+ end
20
+ controller._dispatch(action.to_s)
21
+ controller.body.should == body
22
+ end
23
+ end
24
+
25
+ Spec::Runner.configure do |config|
26
+ config.include Merb::Test::Behaviors
27
+ end
@@ -0,0 +1,33 @@
1
+ # The before/after filters in BootLoaders are considered public API.
2
+ #
3
+ # However, Merb::BootLoader.subclasses is not considered public API and should not be used in plugins.
4
+
5
+ require File.join(File.dirname(__FILE__), "spec_helper")
6
+
7
+ class Merb::BootLoader::AfterTest < Merb::BootLoader
8
+ after Merb::BootLoader::BeforeAppRuns
9
+
10
+ def self.run
11
+ end
12
+ end
13
+
14
+ class Merb::BootLoader::BeforeTest < Merb::BootLoader
15
+ before Merb::BootLoader::Templates
16
+
17
+ def self.run
18
+ end
19
+ end
20
+
21
+ describe "The BootLoader" do
22
+
23
+ it "should support adding a BootLoader after another" do
24
+ idx = Merb::BootLoader.subclasses.index("Merb::BootLoader::BeforeAppRuns")
25
+ Merb::BootLoader.subclasses.index("Merb::BootLoader::AfterTest").should == idx + 1
26
+ end
27
+
28
+ it "should support adding a BootLoader before another" do
29
+ idx = Merb::BootLoader.subclasses.index("Merb::BootLoader::Templates")
30
+ Merb::BootLoader.subclasses.index("Merb::BootLoader::BeforeTest").should == idx - 1
31
+ end
32
+
33
+ end
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
@@ -0,0 +1,31 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ describe Merb::Controller, " callable actions" do
4
+
5
+ before do
6
+ Merb.push_path(:layout, File.dirname(__FILE__) / "controllers" / "views" / "layouts")
7
+ Merb::Router.prepare do |r|
8
+ r.default_routes
9
+ end
10
+ end
11
+
12
+ it "should dispatch to callable actions" do
13
+ dispatch_to(Merb::Test::Fixtures::Controllers::Base, :index).body.should == "index"
14
+ end
15
+
16
+ it "should not dispatch to hidden actions" do
17
+ calling { dispatch_to(Merb::Test::Fixtures::Controllers::Base, :hidden) }.
18
+ should raise_error(Merb::ControllerExceptions::ActionNotFound)
19
+ end
20
+
21
+ it "should dispatch to included methods with show_action called" do
22
+ dispatch_to(Merb::Test::Fixtures::Controllers::Base, :baz).body.should == "baz"
23
+ end
24
+
25
+ it "should not dispatch to included methods with show_action not called" do
26
+ calling { dispatch_to(Merb::Test::Fixtures::Controllers::Base, :bat) }.
27
+ should raise_error(Merb::ControllerExceptions::ActionNotFound)
28
+ end
29
+
30
+
31
+ end
@@ -0,0 +1,41 @@
1
+
2
+
3
+ module Merb::Test::Fixtures
4
+
5
+ module Controllers
6
+
7
+ class Testing < Merb::Controller
8
+ self._template_root = File.dirname(__FILE__) / "views"
9
+ end
10
+
11
+ module Inclusion
12
+
13
+ def self.included(base)
14
+ base.show_action(:baz)
15
+ end
16
+
17
+ def baz
18
+ "baz"
19
+ end
20
+
21
+ def bat
22
+ "bat"
23
+ end
24
+
25
+ end
26
+
27
+ class Base < Testing
28
+ include Inclusion
29
+
30
+ def index
31
+ "index"
32
+ end
33
+
34
+ def hidden
35
+ "Bar"
36
+ end
37
+ hide_action :hidden
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+
2
+
3
+ module Merb::Test::Fixtures::Controllers
4
+
5
+ class SomeModel
6
+ def to_xml; "<XML:Model />" end
7
+ end
8
+
9
+ class Testing < Merb::Controller
10
+ self._template_root = File.dirname(__FILE__) / "views"
11
+ end
12
+
13
+ class Display < Testing
14
+
15
+ def index
16
+ @obj = SomeModel.new
17
+ display @obj
18
+ end
19
+ end
20
+
21
+ class DisplayHtmlDefault < Display; end
22
+
23
+ class DisplayClassProvides < Display
24
+ provides :xml
25
+ end
26
+
27
+ class DisplayLocalProvides < Display
28
+
29
+ def index
30
+ @obj = SomeModel.new
31
+ provides :xml
32
+ display @obj
33
+ end
34
+ end
35
+
36
+ class DisplayWithTemplate < Display
37
+ layout :custom
38
+ end
39
+
40
+ end
@@ -0,0 +1,67 @@
1
+
2
+
3
+ module Merb::Test::Fixtures::Controllers
4
+
5
+ class Testing < Merb::Controller
6
+ self._template_root = File.dirname(__FILE__) / "views"
7
+ end
8
+
9
+ class Responder < Testing
10
+
11
+ def index
12
+ render
13
+ end
14
+ end
15
+
16
+ class HtmlDefault < Responder; end
17
+
18
+ class ClassProvides < Responder
19
+ provides :xml
20
+ end
21
+
22
+ class LocalProvides < Responder
23
+ def index
24
+ provides :xml
25
+ render
26
+ end
27
+ end
28
+
29
+ class MultiProvides < Responder
30
+ def index
31
+ provides :html, :js
32
+ render
33
+ end
34
+ end
35
+
36
+ class ClassOnlyProvides < Responder
37
+ only_provides :text, :xml
38
+
39
+ def index
40
+ "nothing"
41
+ end
42
+ end
43
+
44
+ class OnlyProvides < Responder
45
+ def index
46
+ only_provides :text, :xml
47
+ "nothing"
48
+ end
49
+ end
50
+
51
+ class ClassDoesntProvides < Responder
52
+ provides :xml
53
+ does_not_provide :html
54
+
55
+ def index
56
+ "nothing"
57
+ end
58
+ end
59
+
60
+ class DoesntProvide < Responder
61
+ def index
62
+ provides :xml
63
+ does_not_provide :html
64
+ "nothing"
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,7 @@
1
+ module Merb::Test::Fixtures::Controllers
2
+ class Url < Testing
3
+ def index
4
+ 'index'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ Custom: <%= catch_content(:for_layout) %>
@@ -0,0 +1,34 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+
3
+ describe Merb::Controller, " displaying objects based on mime type" do
4
+
5
+ before do
6
+ Merb::Router.prepare do |r|
7
+ r.default_routes
8
+ end
9
+ end
10
+
11
+ it "should default the mime-type to HTML (and raise since there's no to_html)" do
12
+ running { dispatch_to(Merb::Test::Fixtures::Controllers::DisplayHtmlDefault, :index) }.should raise_error(Merb::ControllerExceptions::NotAcceptable)
13
+ end
14
+
15
+ it "should use a template if specified" do
16
+ dispatch_to(Merb::Test::Fixtures::Controllers::DisplayWithTemplate, :index).body.should == "Custom: Template"
17
+ end
18
+
19
+ it "should use other mime-types if they are provided on the class level" do
20
+ controller = dispatch_to(Merb::Test::Fixtures::Controllers::DisplayClassProvides, :index, {}, :http_accept => "application/xml")
21
+ controller.body.should == "<XML:Model />"
22
+ end
23
+
24
+ it "should fail if none of the acceptable mime-types are available" do
25
+ calling { dispatch_to(Merb::Test::Fixtures::Controllers::DisplayClassProvides, :index, {}, :http_accept => "application/json") }.
26
+ should raise_error(Merb::ControllerExceptions::NotAcceptable)
27
+ end
28
+
29
+ it "should use mime-types that are provided at the local level" do
30
+ controller = dispatch_to(Merb::Test::Fixtures::Controllers::DisplayLocalProvides, :index, {}, :http_accept => "application/xml")
31
+ controller.body.should == "<XML:Model />"
32
+ end
33
+
34
+ end