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,46 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+
4
+ describe "Kernel#require" do
5
+
6
+ before do
7
+ @logger = StringIO.new
8
+ Merb.logger = Merb::Logger.new(@logger)
9
+ end
10
+
11
+ it "should be able to require and throw a useful error message" do
12
+ Kernel.stub!(:require).with("redcloth").and_raise(LoadError)
13
+ Merb.logger.should_receive(:error!).with("foo")
14
+ Kernel.rescue_require("redcloth", "foo")
15
+ end
16
+
17
+
18
+ end
19
+
20
+ describe "Kernel#caller" do
21
+
22
+ it "should be able to determine caller info" do
23
+ __caller_info__.should be_kind_of(Array)
24
+ end
25
+
26
+ it "should be able to get caller lines" do
27
+ __caller_lines__(__caller_info__[0], __caller_info__[1], 4).length.should == 9
28
+ __caller_lines__(__caller_info__[0], __caller_info__[1], 4).should be_kind_of(Array)
29
+ end
30
+
31
+ end
32
+
33
+ describe "Kernel misc." do
34
+ it "should extract options from args" do
35
+ args = ["foo", "bar", {:baz => :bar}]
36
+ Kernel.extract_options_from_args!(args).should == {:baz => :bar}
37
+ args.should == ["foo", "bar"]
38
+ end
39
+
40
+ it "should throw a useful error if there's no debugger" do
41
+ Merb.logger.should_receive(:info!).with "\n***** Debugger requested, but was not " +
42
+ "available: Start server with --debugger " +
43
+ "to enable *****\n"
44
+ Kernel.debugger
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+ class Foo
3
+
4
+ end
5
+
6
+ describe Object do
7
+
8
+
9
+ it "should treat an empty string as blank" do
10
+ "".should be_blank
11
+ end
12
+
13
+ it "should treat a string with just spaces as blank" do
14
+ " ".should be_blank
15
+ end
16
+
17
+ it "should treat an empty array as blank" do
18
+ [].should be_blank
19
+ end
20
+
21
+ it "should treat boolean false as blank" do
22
+ false.should be_blank
23
+ end
24
+
25
+ end
26
+
27
+ describe Object, "#quacks_like" do
28
+ it "use respond_to? to determine quacks_like :symbol" do
29
+ "Foo".should be_quacks_like(:strip)
30
+ end
31
+
32
+ it "should return true if any of the elements in the Array are true" do
33
+ "Foo".should be_quacks_like([String, Array])
34
+ end
35
+
36
+ it "should return false if an invalid value is passed in" do
37
+ "Foo".should_not be_quacks_like({})
38
+ end
39
+ end
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe Merb::SimpleSet do
4
+
5
+ before do
6
+ @s = Merb::SimpleSet.new("Foo")
7
+ end
8
+
9
+ it "should support <<" do
10
+ @s << "Hello"
11
+ @s.should be_include("Hello")
12
+ end
13
+
14
+ it "should support merge" do
15
+ @s.should include("Foo")
16
+ @t = @s.merge(["Bar"])
17
+ @t.should be_kind_of(Merb::SimpleSet)
18
+ @t.should include("Foo")
19
+ @t.should include("Bar")
20
+ end
21
+
22
+ it "should support inspect" do
23
+ @s.inspect.should == "#<SimpleSet: {\"Foo\"}>"
24
+ end
25
+
26
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ describe String, "to_const_string" do
4
+
5
+ it "should convert a path into a constant string" do
6
+ "foo/bar/baz_bat".to_const_string.should == "Foo::Bar::BazBat"
7
+ end
8
+
9
+ end
@@ -0,0 +1,107 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+ Merb.start :environment => 'test'
3
+ module CookiesSpecModule
4
+
5
+ def cookie_time(time)
6
+ time.gmtime.strftime(Merb::Const::COOKIE_EXPIRATION_FORMAT)
7
+ end
8
+ end
9
+
10
+ describe Merb::Cookies do
11
+ include CookiesSpecModule
12
+
13
+ before do
14
+ @_cookies = Mash.new
15
+ @_headers = {}
16
+ @cookies = Merb::Cookies.new(@_cookies, @_headers)
17
+ end
18
+
19
+ it "should respond to []" do
20
+ @cookies.should respond_to(:[])
21
+ end
22
+
23
+ it "should respond to []=" do
24
+ @cookies.should respond_to(:[]=)
25
+ end
26
+
27
+ it "should respond to delete" do
28
+ @cookies.should respond_to(:delete)
29
+ end
30
+
31
+ it "should accept simple cookies that expire at end of session" do
32
+ @cookies[:foo] = 'bar'
33
+
34
+ @_headers['Set-Cookie'].should == ['foo=bar; path=/;']
35
+
36
+ @cookies[:foo].should == 'bar'
37
+ @cookies['foo'].should == 'bar'
38
+ end
39
+
40
+ it "should accept cookies with expiry dates" do
41
+ expires = Time.now + 2 * (60*60*24*7)
42
+ @cookies[:dozen] = {
43
+ :value => 'twelve',
44
+ :expires => expires
45
+ }
46
+
47
+ @_headers['Set-Cookie'].should ==
48
+ ["dozen=twelve; expires=%s; path=/;" % cookie_time(expires)]
49
+
50
+ @cookies[:dozen].should == 'twelve'
51
+ @cookies['dozen'].should == 'twelve'
52
+ end
53
+
54
+ it "should accept multiple cookies" do
55
+ expires = Time.now + 2 * (60*60*24*7)
56
+ @cookies[:foo] = 'bar'
57
+ @cookies[:dozen] = {
58
+ :value => 'twelve',
59
+ :expires => expires
60
+ }
61
+
62
+ @_headers['Set-Cookie'].should == [
63
+ 'foo=bar; path=/;',
64
+ "dozen=twelve; expires=%s; path=/;" % cookie_time(expires)
65
+ ]
66
+
67
+ @cookies[:dozen].should == 'twelve'
68
+ @cookies['dozen'].should == 'twelve'
69
+ @cookies[:foo].should == 'bar'
70
+ @cookies['foo'].should == 'bar'
71
+ end
72
+
73
+ it "should leave the value unescaped in the current request" do
74
+ @cookies[:foo] = "100%"
75
+ @_headers['Set-Cookie'].should == [
76
+ 'foo=100%25; path=/;'
77
+ ]
78
+
79
+ @cookies[:foo].should == '100%'
80
+ @cookies['foo'].should == '100%'
81
+ end
82
+
83
+ it "should give access to currently saved cookies" do
84
+ @_cookies[:original] = 'accessible'
85
+ @cookies[:original].should == 'accessible'
86
+
87
+ @cookies[:foo] = 'bar'
88
+ @cookies[:foo].should == 'bar'
89
+ @cookies[:original].should == 'accessible'
90
+ end
91
+
92
+ it "should overwrite old cookies with new cookies" do
93
+ @_cookies[:foo] = 'bar'
94
+ @cookies[:foo].should == 'bar'
95
+
96
+ @cookies[:foo] = 'new'
97
+ @cookies[:foo].should == 'new'
98
+ end
99
+
100
+ it "should allow deleting of cookies" do
101
+ @_cookies[:foo] = 'bar'
102
+ @cookies[:foo].should == 'bar'
103
+
104
+ @cookies.delete(:foo)
105
+ @cookies[:foo].should == nil
106
+ end
107
+ end
@@ -0,0 +1,26 @@
1
+ require File.join(File.dirname(__FILE__), "spec_helper")
2
+ require 'rack/mock'
3
+ require 'stringio'
4
+ Merb.start :environment => 'test',
5
+ :merb_root => File.dirname(__FILE__) / 'fixture'
6
+
7
+ describe Merb::Dispatcher do
8
+
9
+ it "should handle return an Exceptions controller for a bad route request" do
10
+ env = Rack::MockRequest.env_for("/notreal")
11
+ Merb::Dispatcher.handle(env).should be_kind_of(Exceptions)
12
+ end
13
+
14
+ it "should search for an action matching the specific exception in the Exceptions controller" do
15
+ env = Rack::MockRequest.env_for("/foo/raise_not_acceptable")
16
+ env['REQUEST_URI'] = '/foo/raise_not_acceptable'
17
+ Merb::Dispatcher.handle(env).action_name.should == 'not_acceptable'
18
+ end
19
+
20
+ it "should search for actions matching more general exception types if the specific one cannot be found in the Exception controller" do
21
+ env = Rack::MockRequest.env_for("/foo/raise_conflict")
22
+ env['REQUEST_URI'] = '/foo/raise_conflict'
23
+ Merb::Dispatcher.handle(env).action_name.should == 'client_error'
24
+ end
25
+
26
+ end
@@ -0,0 +1,4 @@
1
+
2
+
3
+ class Application < Merb::Controller
4
+ end
@@ -0,0 +1,27 @@
1
+
2
+
3
+ class Exceptions < Application
4
+
5
+ attr_reader :handler
6
+
7
+ # handle NotFound exceptions (404)
8
+
9
+ def not_found
10
+ @handler = :not_found
11
+ render :format => :html
12
+ end
13
+
14
+ # handle NotAcceptable exceptions (406)
15
+
16
+ def not_acceptable
17
+ @handler = :not_acceptable
18
+ render "Handled by: not_acceptable"
19
+ end
20
+
21
+ # # Any client error (400 series)
22
+ def client_error
23
+ @handler = :client_error
24
+ render "Handled by: client_error"
25
+ end
26
+
27
+ end
@@ -0,0 +1,21 @@
1
+
2
+
3
+ class Foo < Application
4
+
5
+ def index
6
+ "index"
7
+ end
8
+
9
+ def bar
10
+ render
11
+ end
12
+
13
+ def raise_conflict
14
+ raise Conflict
15
+ end
16
+
17
+ def raise_not_acceptable
18
+ raise NotAcceptable
19
+ end
20
+
21
+ end
@@ -0,0 +1,8 @@
1
+
2
+
3
+ module Merb
4
+
5
+ module GlobalHelper
6
+ # helpers defined here available to all views.
7
+ end
8
+ end
@@ -0,0 +1,37 @@
1
+ <div id="container">
2
+ <div id="header-container">
3
+ <img src="/images/merb.jpg">
4
+ <!-- <h1>Mongrel + Erb</h1> -->
5
+ <h2>pocket rocket web framework</h2>
6
+ <hr />
7
+ </div>
8
+
9
+ <div id="left-container">
10
+ <h3>Exception:</h3>
11
+ <p><%= params[:exception] %></p>
12
+ </div>
13
+
14
+ <div id="main-container">
15
+ <h3>Why am I seeing this page?</h3>
16
+ <p>
17
+ An unexpected "client error" has occurred. That means something in your request
18
+ was not allowed, but the server does not have any more specific information.
19
+ </p>
20
+
21
+ <h3>Where can I find help?</h3>
22
+ <p>If you have any questions or if you can't figure something out, please take a
23
+ look at our <a href="http://merb.devjavu.com/"> project development page</a> or,
24
+ feel free to come chat at irc.freenode.net, channel #merb.</p>
25
+
26
+ <h3>How do I edit this page?</h3>
27
+ <p>You can change what people see when this happens byy editing <tt>app/views/exceptions/not_found.html.erb</tt>.</p>
28
+
29
+ </div>
30
+
31
+ <div id="footer-container">
32
+ <hr />
33
+ <div class="left"></div>
34
+ <div class="right">&copy; 2007 the merb dev team</div>
35
+ <p>&nbsp;</p>
36
+ </div>
37
+ </div>
@@ -0,0 +1,216 @@
1
+ <html>
2
+ <head>
3
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
4
+ <title><%= @exception_name %></title>
5
+ <style type="text/css" media="screen">
6
+ body {
7
+ font-family:arial;
8
+ font-size:11px;
9
+ }
10
+ h1 {
11
+ font-size:48px;
12
+ letter-spacing:-4px;
13
+ margin:0;
14
+ line-height:36px;
15
+ color:#333;
16
+ }
17
+ h1 sup {
18
+ font-size: 0.5em;
19
+ }
20
+ h1 sup.error_500, h1 sup.error_400 {
21
+ color:#990E05;
22
+ }
23
+ h1 sup.error_100, h1 sup.error_200 {
24
+ color:#00BF10;
25
+ }
26
+ h1 sup.error_300 {
27
+ /* pretty sure you cant 'see' status 300
28
+ errors but if you could I think they
29
+ would be blue */
30
+ color:#1B2099;
31
+ }
32
+ h2 {
33
+ font-size:36px;
34
+ letter-spacing:-3px;
35
+ margin:0;
36
+ line-height:28px;
37
+ color:#444;
38
+ }
39
+ a, a:visited {
40
+ color:#00BF10;
41
+ }
42
+ .internalError {
43
+ width:800px;
44
+ margin:50px auto;
45
+ }
46
+ .header {
47
+ border-bottom:10px solid #333;
48
+ margin-bottom:1px;
49
+ background-image: url("data:image/gif;base64,R0lGODlhAwADAIAAAP///8zMzCH5BAAAAAAALAAAAAADAAMAAAIEBHIJBQA7");
50
+ padding:20px;
51
+ }
52
+ table.trace {
53
+ width:100%;
54
+ font-family:courier, monospace;
55
+ letter-spacing:-1px;
56
+ border-collapse: collapse;
57
+ border-spacing:0;
58
+ }
59
+ table.trace tr td{
60
+ padding:0;
61
+ height:26px;
62
+ font-size:13px;
63
+ vertical-align:middle;
64
+ }
65
+ table.trace tr.file{
66
+ border-top:2px solid #fff;
67
+ background-color:#F3F3F3;
68
+ }
69
+ table.trace tr.source {
70
+ background-color:#F8F8F8;
71
+ display:none;
72
+ }
73
+ table.trace .open tr.source {
74
+ display:table-row;
75
+ }
76
+ table.trace tr.file td.expand {
77
+ width:23px;
78
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAAXCAIAAABvSEP3AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAdVJREFUeNqMVL+TwUAYxaRIOlEhlZHGDAUzzOQ61+AqXMV1lJSU7q/QRqm8KFUcJTNn5qJkaPyoKKVz7y4mF8na5Kt29tt9+/Z97/u81+vVQ4r9frdarS6Xi7ETDIZisRjxMGPfmk4niNPpZE+xLAugbPaZ53nzvtfMBe/3+/3dbuehBrAKhZdUKkVAWa9Xsiybv0CPZDJZLr/qa5/BwgwRjYqOKIvFYjQa/aNommZh0Ww2K5UqzwfoQOPxaLPZ3FAmk0+7lplMpt1u53J5OpBOR0eZEE9wHJfP5zud93g88QhluwWbjW+5VOmKBgKBer3eaDTDYeGBQF8+x7rqIYoiPgixWJazpA6HA+MSxRArkUgMh0M409g8Ho8+9wYxxCqVSq1W26EDHGM2m4HOHQrEc38f/Yn7cLmlIRhBENzcx8cVRZnPZ/YUep2BWkjTIfA+PKVpZAXR5QxsjiqCKvGEqqp443w+0dvy17swqD0HB3S73V5PpkNg1qBqt8kwGCjmPkinM0QJbIoEa7U6UG6ToVgs4V9G2g0ESoP5Aoi7KYX5oCgf8IKbkvn9/mr1LRQKESamzgJy0g0tSZIuB3nuGqRU9Vv9C4sKkUhEkp4soxvxI8AAhWrrtXa3X8EAAAAASUVORK5CYII=);
79
+ background-position:top left;
80
+ background-repeat:no-repeat;
81
+ }
82
+ table.trace .open tr.file td.expand {
83
+ width:19px;
84
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAB1CAIAAAAqdO2mAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAXZJREFUeNrslK1ywkAUhcMOBomEOiSdqLxEBJX0NaijOsjyHGGmCGyQQYaiiiw4gktkcOmZbpsuuzQ/M5XnqJ2d3S/n3nM3rTzPLUP7/Tt0+pLcGQwG3W53OLyHzPMtjYL7q9UqSRLrD4E1Gj1orCvKYuFHUWTVkOM44/HjDcp8/lL4r6NerzeZPMm1KFw0QkDn83m5fP2lHA4fNQvRtNvtjsfDd0WzmSfb2e/fdTqdOvdh/HLJZLOn0+d2HJ+KRGzbdl23EpFlmed5cp2maRzHQq1lvQ5KMi6EUZBGfup6E1pTfd+vrGW7jbQ2C9hTt9BpqNyIWaAwAy6xg2eBz5iRC/NomiZhGN5sqmnkauo0BUGgVQoBjQ80oCACgNQdZHfTYBkF2mxCtWWAqunWpahxIDUt3QYUxIFQpJHyIWpXjinabKbbwItMHT+NyjchrP8QKaSQQgoppJBCCimkkEIKKaSQQgoppJBCCimkkEIKKaSo+hRgAEFD17X08O2NAAAAAElFTkSuQmCC);
85
+ background-position:top left;
86
+ background-repeat:no-repeat;
87
+ }
88
+ table.trace tr.source td.collapse {
89
+ width:19px;
90
+ background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAB1CAIAAAAqdO2mAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAVxJREFUeNrs0zFygkAUBmBlUkgJHdABlQwVkVJKKUxBYWbkALTxMJwhltyDFkss03IF8pudIcwaDaDl/6pd2P327b7d+eHwMXs4lNkzggoVKlSoUKFChQoVKlSoUKFChQoVKlSoUKFChQqVEYqm6ft9+qiSJEkYho7jTlcw2fd9NOI4nq4gEdFwXXe1Cqco63VkWVbXRTqLhTpOwQRpF7quR1E0TgGhqvLKUFCyoQqG/rks3O6kZKW/eRFpevOCoGTXVTcMQ5EyxyDEkML1c5RzuZOICIyXqn7JBVez6282MWrx731HOv2qB8Hri2lamNk0DfpVVdV1Peodappmmua8bdvzuc7zfNprzrLMth1FnGh/X8MjCAIQv/cFz/+65PcDh7rbvYv2ZUfdj+PxsyzLgVl0hKwgTqeqKApx2LeOc7t98zyv/1FWOgvx9RPii23bmL9cetJ8Ed8CDAC6aFW8bCzFhwAAAABJRU5ErkJggg==);
91
+ background-position:bottom left;
92
+ background-repeat:no-repeat;
93
+ background-color:#6F706F;
94
+ }
95
+ table.trace tr td.path {
96
+ padding-left:10px;
97
+ }
98
+ table.trace tr td.code {
99
+ padding-left:35px;
100
+ white-space: pre;
101
+ line-height:9px;
102
+ padding-bottom:10px;
103
+ }
104
+ table.trace tr td.code em {
105
+ font-weight:bold;
106
+ color:#00BF10;
107
+ }
108
+ table.trace tr td.code a {
109
+ width: 20px;
110
+ float: left;
111
+ }
112
+ table.trace tr td.code .more {
113
+ color:#666;
114
+ }
115
+ table.trace tr td.line {
116
+ width:30px;
117
+ text-align:right;
118
+ padding-right:4px;
119
+ }
120
+ .footer {
121
+ margin-top:5px;
122
+ font-size:11px;
123
+ color:#444;
124
+ text-align:right;
125
+ }
126
+ </style>
127
+ </head>
128
+ <body>
129
+ <div class="internalError">
130
+
131
+ <div class="header">
132
+ <h1><%= @exception_name %> <sup class="error_<%= @exception.class::STATUS %>"><%= @exception.class::STATUS %></sup></h1>
133
+ <% if show_details = ::Merb::Config[:exception_details] -%>
134
+ <h2><%= @exception.message %></h2>
135
+ <% else -%>
136
+ <h2>Sorry about that...</h2>
137
+ <% end -%>
138
+ <h3>Parameters</h3>
139
+ <ul>
140
+ <% params[:original_params].each do |param, value| %>
141
+ <li><strong><%= param %>:</strong> <%= value.inspect %></li>
142
+ <% end %>
143
+ <%= "<li>None</li>" if params[:original_params].empty? %>
144
+ </ul>
145
+
146
+ <h3>Session</h3>
147
+ <ul>
148
+ <% params[:original_session].each do |param, value| %>
149
+ <li><strong><%= param %>:</strong> <%= value.inspect %></li>
150
+ <% end %>
151
+ <%= "<li>None</li>" if params[:original_session].empty? %>
152
+ </ul>
153
+
154
+ <h3>Cookies</h3>
155
+ <ul>
156
+ <% params[:original_cookies].each do |param, value| %>
157
+ <li><strong><%= param %>:</strong> <%= value.inspect %></li>
158
+ <% end %>
159
+ <%= "<li>None</li>" if params[:original_cookies].empty? %>
160
+ </ul>
161
+ </div>
162
+
163
+ <% if show_details %>
164
+ <table class="trace">
165
+ <% @exception.backtrace.each_with_index do |line, index| %>
166
+ <tbody class="close">
167
+ <tr class="file">
168
+ <td class="expand">
169
+ </td>
170
+ <td class="path">
171
+ <%= (line.match(/^([^:]+)/)[1] rescue 'unknown').sub(/\/((opt|usr)\/local\/lib\/(ruby\/)?(gems\/)?(1.8\/)?(gems\/)?|.+\/app\/)/, '') %>
172
+ <% unless line.match(/\.erb:/) %>
173
+ in "<strong><%= line.match(/:in `(.+)'$/)[1] rescue '?' %></strong>"
174
+ <% else %>
175
+ (<strong>ERB Template</strong>)
176
+ <% end %>
177
+ </td>
178
+ <td class="line">
179
+ <a href="txmt://open?url=file://<%=file = (line.match(/^([^:]+)/)[1] rescue 'unknown')%>&amp;line=<%= lineno = line.match(/:([0-9]+):/)[1] rescue '?' %>"><%=lineno%></a>&nbsp;
180
+ </td>
181
+ </tr>
182
+ <tr class="source">
183
+ <td class="collapse">
184
+ </td>
185
+ <td class="code" colspan="2"><% (__caller_lines__(file, lineno, 5) rescue []).each do |llineno, lcode, lcurrent| %>
186
+ <a href="txmt://open?url=file://<%=file%>&amp;line=<%=llineno%>"><%= llineno %></a><%='<em>' if llineno==lineno.to_i %><%= lcode.size > 90 ? Erubis::XmlHelper.html_escape(lcode[0..90])+'<span class="more">......</span>' : Erubis::XmlHelper.html_escape(lcode) %><%='</em>' if llineno==lineno.to_i %>
187
+ <% end %>
188
+
189
+ </td>
190
+ </tr>
191
+ </tbody>
192
+ <% end %>
193
+ </table>
194
+ <script type="text/javascript" charset="utf-8">
195
+ // swop the open & closed classes
196
+ els = document.getElementsByTagName('td');
197
+ for(i=0; i<els.length; i++){
198
+ if(els[i].className=='expand' || els[i].className=='collapse'){
199
+ els[i].onclick = function(e){
200
+ tbody = this.parentNode.parentNode;
201
+ if(tbody.className=='open'){
202
+ tbody.className='closed';
203
+ }else{
204
+ tbody.className='open';
205
+ }
206
+ }
207
+ }
208
+ }
209
+ </script>
210
+ <% end %>
211
+ <div class="footer">
212
+ lots of love, from <a href="#">merb</a>
213
+ </div>
214
+ </div>
215
+ </body>
216
+ </html>