merb-core 0.9.7 → 0.9.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (274) hide show
  1. data/CHANGELOG +136 -2
  2. data/CONTRIBUTORS +6 -0
  3. data/PUBLIC_CHANGELOG +38 -0
  4. data/Rakefile +38 -30
  5. data/lib/merb-core.rb +88 -23
  6. data/lib/merb-core/bootloader.rb +235 -51
  7. data/lib/merb-core/config.rb +121 -36
  8. data/lib/merb-core/controller/abstract_controller.rb +59 -36
  9. data/lib/merb-core/controller/exceptions.rb +2 -15
  10. data/lib/merb-core/controller/merb_controller.rb +44 -1
  11. data/lib/merb-core/controller/mime.rb +4 -0
  12. data/lib/merb-core/controller/mixins/controller.rb +38 -21
  13. data/lib/merb-core/controller/mixins/render.rb +44 -29
  14. data/lib/merb-core/controller/mixins/responder.rb +3 -31
  15. data/lib/merb-core/controller/template.rb +45 -21
  16. data/lib/merb-core/core_ext/kernel.rb +60 -32
  17. data/lib/merb-core/dispatch/default_exception/default_exception.rb +2 -2
  18. data/lib/merb-core/dispatch/default_exception/views/_css.html.erb +3 -1
  19. data/lib/merb-core/dispatch/default_exception/views/_javascript.html.erb +71 -67
  20. data/lib/merb-core/dispatch/default_exception/views/index.html.erb +7 -3
  21. data/lib/merb-core/dispatch/dispatcher.rb +3 -3
  22. data/lib/merb-core/dispatch/request.rb +56 -9
  23. data/lib/merb-core/dispatch/router.rb +159 -133
  24. data/lib/merb-core/dispatch/router/behavior.rb +462 -703
  25. data/lib/merb-core/dispatch/router/cached_proc.rb +3 -3
  26. data/lib/merb-core/dispatch/router/resources.rb +289 -0
  27. data/lib/merb-core/dispatch/router/route.rb +514 -294
  28. data/lib/merb-core/dispatch/session.rb +4 -2
  29. data/lib/merb-core/logger.rb +213 -202
  30. data/lib/merb-core/plugins.rb +9 -1
  31. data/lib/merb-core/rack.rb +3 -1
  32. data/lib/merb-core/rack/adapter.rb +7 -4
  33. data/lib/merb-core/rack/adapter/abstract.rb +188 -0
  34. data/lib/merb-core/rack/adapter/ebb.rb +12 -13
  35. data/lib/merb-core/rack/adapter/evented_mongrel.rb +2 -15
  36. data/lib/merb-core/rack/adapter/irb.rb +3 -2
  37. data/lib/merb-core/rack/adapter/mongrel.rb +22 -15
  38. data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +4 -16
  39. data/lib/merb-core/rack/adapter/thin.rb +21 -22
  40. data/lib/merb-core/rack/adapter/thin_turbo.rb +4 -11
  41. data/lib/merb-core/rack/adapter/webrick.rb +54 -18
  42. data/lib/merb-core/rack/application.rb +4 -4
  43. data/lib/merb-core/rack/handler/mongrel.rb +12 -13
  44. data/lib/merb-core/rack/middleware/csrf.rb +1 -1
  45. data/lib/merb-core/rack/stream_wrapper.rb +41 -0
  46. data/lib/merb-core/server.rb +157 -90
  47. data/lib/merb-core/tasks/gem_management.rb +267 -0
  48. data/lib/merb-core/tasks/merb.rb +1 -0
  49. data/lib/merb-core/tasks/merb_rake_helper.rb +48 -34
  50. data/lib/merb-core/tasks/stats.rake +1 -1
  51. data/lib/merb-core/test.rb +9 -3
  52. data/lib/merb-core/test/helpers.rb +1 -0
  53. data/lib/merb-core/test/helpers/mock_request_helper.rb +393 -0
  54. data/lib/merb-core/test/helpers/multipart_request_helper.rb +3 -2
  55. data/lib/merb-core/test/helpers/request_helper.rb +40 -372
  56. data/lib/merb-core/test/helpers/route_helper.rb +16 -2
  57. data/lib/merb-core/test/matchers.rb +1 -0
  58. data/lib/merb-core/test/matchers/controller_matchers.rb +4 -247
  59. data/lib/merb-core/test/matchers/request_matchers.rb +140 -0
  60. data/lib/merb-core/test/matchers/view_matchers.rb +22 -4
  61. data/lib/merb-core/test/run_specs.rb +118 -26
  62. data/lib/merb-core/test/test_ext/rspec.rb +181 -0
  63. data/lib/merb-core/version.rb +1 -9
  64. metadata +10 -342
  65. data/docs/bootloading.dox +0 -58
  66. data/docs/documentation_standards +0 -40
  67. data/docs/merb-core-call-stack-diagram.mmap +0 -0
  68. data/docs/merb-core-call-stack-diagram.pdf +0 -0
  69. data/docs/merb-core-call-stack-diagram.png +0 -0
  70. data/docs/new_render_api +0 -51
  71. data/lib/merb-core/vendor/facets.rb +0 -2
  72. data/lib/merb-core/vendor/facets/dictionary.rb +0 -433
  73. data/lib/merb-core/vendor/facets/inflect.rb +0 -342
  74. data/spec/private/config/adapter_spec.rb +0 -32
  75. data/spec/private/config/config_spec.rb +0 -202
  76. data/spec/private/config/environment_spec.rb +0 -13
  77. data/spec/private/config/merb_spec.rb +0 -34
  78. data/spec/private/config/spec_helper.rb +0 -1
  79. data/spec/private/core_ext/kernel_spec.rb +0 -159
  80. data/spec/private/dispatch/bootloader_spec.rb +0 -24
  81. data/spec/private/dispatch/fixture/app/controllers/application.rb +0 -4
  82. data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +0 -25
  83. data/spec/private/dispatch/fixture/app/controllers/foo.rb +0 -19
  84. data/spec/private/dispatch/fixture/app/helpers/global_helpers.rb +0 -8
  85. data/spec/private/dispatch/fixture/app/views/exeptions/client_error.html.erb +0 -37
  86. data/spec/private/dispatch/fixture/app/views/exeptions/internal_server_error.html.erb +0 -216
  87. data/spec/private/dispatch/fixture/app/views/exeptions/not_acceptable.html.erb +0 -38
  88. data/spec/private/dispatch/fixture/app/views/exeptions/not_found.html.erb +0 -40
  89. data/spec/private/dispatch/fixture/app/views/foo/bar.html.erb +0 -0
  90. data/spec/private/dispatch/fixture/app/views/layout/application.html.erb +0 -11
  91. data/spec/private/dispatch/fixture/config/black_hole.rb +0 -12
  92. data/spec/private/dispatch/fixture/config/environments/development.rb +0 -6
  93. data/spec/private/dispatch/fixture/config/environments/production.rb +0 -5
  94. data/spec/private/dispatch/fixture/config/environments/test.rb +0 -6
  95. data/spec/private/dispatch/fixture/config/init.rb +0 -45
  96. data/spec/private/dispatch/fixture/config/rack.rb +0 -11
  97. data/spec/private/dispatch/fixture/config/router.rb +0 -35
  98. data/spec/private/dispatch/fixture/log/merb_test.log +0 -8839
  99. data/spec/private/dispatch/fixture/public/images/merb.jpg +0 -0
  100. data/spec/private/dispatch/fixture/public/merb.fcgi +0 -4
  101. data/spec/private/dispatch/fixture/public/stylesheets/master.css +0 -119
  102. data/spec/private/dispatch/route_params_spec.rb +0 -23
  103. data/spec/private/dispatch/spec_helper.rb +0 -1
  104. data/spec/private/router/behavior_spec.rb +0 -60
  105. data/spec/private/router/fixture/log/merb_test.log +0 -35
  106. data/spec/private/router/route_spec.rb +0 -418
  107. data/spec/private/router/router_spec.rb +0 -183
  108. data/spec/private/vendor/facets/plural_spec.rb +0 -564
  109. data/spec/private/vendor/facets/singular_spec.rb +0 -489
  110. data/spec/public/DEFINITIONS +0 -11
  111. data/spec/public/abstract_controller/controllers/alt_views/layout/application.erb +0 -1
  112. data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_string_controller_layout.erb +0 -1
  113. data/spec/public/abstract_controller/controllers/alt_views/layout/merb/test/fixtures/abstract/render_template_controller_layout.erb +0 -1
  114. data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/index.erb +0 -1
  115. data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/display_object_with_multiple_roots/show.erb +0 -1
  116. data/spec/public/abstract_controller/controllers/alt_views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +0 -1
  117. data/spec/public/abstract_controller/controllers/alt_views/partial/basic_partial_with_multiple_roots/_partial.erb +0 -1
  118. data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_and_custom_location/index.erb +0 -1
  119. data/spec/public/abstract_controller/controllers/alt_views/render_template_multiple_roots_inherited/index.erb +0 -1
  120. data/spec/public/abstract_controller/controllers/cousins.rb +0 -41
  121. data/spec/public/abstract_controller/controllers/display.rb +0 -60
  122. data/spec/public/abstract_controller/controllers/filters.rb +0 -260
  123. data/spec/public/abstract_controller/controllers/helpers.rb +0 -41
  124. data/spec/public/abstract_controller/controllers/partial.rb +0 -121
  125. data/spec/public/abstract_controller/controllers/render.rb +0 -113
  126. data/spec/public/abstract_controller/controllers/views/helpers/capture/index.erb +0 -1
  127. data/spec/public/abstract_controller/controllers/views/helpers/capture_eq/index.erb +0 -1
  128. data/spec/public/abstract_controller/controllers/views/helpers/capture_with_args/index.erb +0 -1
  129. data/spec/public/abstract_controller/controllers/views/helpers/concat/index.erb +0 -1
  130. data/spec/public/abstract_controller/controllers/views/layout/alt.erb +0 -1
  131. data/spec/public/abstract_controller/controllers/views/layout/custom.erb +0 -1
  132. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object/index.erb +0 -1
  133. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/display_object_with_action/new.erb +0 -1
  134. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template/index.erb +0 -1
  135. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_app_layout/index.erb +0 -0
  136. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_custom_layout/index.erb +0 -1
  137. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/index.erb +0 -1
  138. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_template_multiple_roots/show.erb +0 -1
  139. data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_two_throw_contents/index.erb +0 -1
  140. data/spec/public/abstract_controller/controllers/views/partial/another_directory/_partial.erb +0 -1
  141. data/spec/public/abstract_controller/controllers/views/partial/basic_partial/_partial.erb +0 -1
  142. data/spec/public/abstract_controller/controllers/views/partial/basic_partial/index.erb +0 -1
  143. data/spec/public/abstract_controller/controllers/views/partial/basic_partial_with_multiple_roots/index.erb +0 -1
  144. data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_first.erb +0 -1
  145. data/spec/public/abstract_controller/controllers/views/partial/nested_partial/_second.erb +0 -1
  146. data/spec/public/abstract_controller/controllers/views/partial/nested_partial/index.erb +0 -1
  147. data/spec/public/abstract_controller/controllers/views/partial/partial_in_another_directory/index.erb +0 -1
  148. data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/_collection.erb +0 -1
  149. data/spec/public/abstract_controller/controllers/views/partial/partial_with_both/index.erb +0 -1
  150. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/_collection.erb +0 -1
  151. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections/index.erb +0 -1
  152. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/_collection.erb +0 -1
  153. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_as/index.erb +0 -1
  154. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/_collection.erb +0 -1
  155. data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/index.erb +0 -1
  156. data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/_variables.erb +0 -1
  157. data/spec/public/abstract_controller/controllers/views/partial/partial_with_locals/index.erb +0 -1
  158. data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/_both.erb +0 -1
  159. data/spec/public/abstract_controller/controllers/views/partial/partial_with_with_and_locals/index.erb +0 -1
  160. data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/_partial.erb +0 -1
  161. data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/index.erb +0 -1
  162. data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/_with_partial.erb +0 -1
  163. data/spec/public/abstract_controller/controllers/views/partial/with_as_partial/index.erb +0 -1
  164. data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/_with_partial.erb +0 -1
  165. data/spec/public/abstract_controller/controllers/views/partial/with_nil_partial/index.erb +0 -1
  166. data/spec/public/abstract_controller/controllers/views/partial/with_partial/_with_partial.erb +0 -1
  167. data/spec/public/abstract_controller/controllers/views/partial/with_partial/index.erb +0 -1
  168. data/spec/public/abstract_controller/controllers/views/test_display/foo.html.erb +0 -1
  169. data/spec/public/abstract_controller/controllers/views/test_render/foo.html.erb +0 -0
  170. data/spec/public/abstract_controller/controllers/views/wonderful/index.erb +0 -1
  171. data/spec/public/abstract_controller/display_spec.rb +0 -37
  172. data/spec/public/abstract_controller/filter_spec.rb +0 -136
  173. data/spec/public/abstract_controller/helper_spec.rb +0 -21
  174. data/spec/public/abstract_controller/partial_spec.rb +0 -61
  175. data/spec/public/abstract_controller/render_spec.rb +0 -90
  176. data/spec/public/abstract_controller/spec_helper.rb +0 -31
  177. data/spec/public/boot_loader/boot_loader_spec.rb +0 -33
  178. data/spec/public/boot_loader/spec_helper.rb +0 -1
  179. data/spec/public/controller/authentication_spec.rb +0 -174
  180. data/spec/public/controller/base_spec.rb +0 -88
  181. data/spec/public/controller/conditional_get_spec.rb +0 -100
  182. data/spec/public/controller/config/init.rb +0 -6
  183. data/spec/public/controller/controllers/authentication.rb +0 -74
  184. data/spec/public/controller/controllers/base.rb +0 -65
  185. data/spec/public/controller/controllers/conditional_get.rb +0 -35
  186. data/spec/public/controller/controllers/cookies.rb +0 -36
  187. data/spec/public/controller/controllers/dispatcher.rb +0 -35
  188. data/spec/public/controller/controllers/display.rb +0 -118
  189. data/spec/public/controller/controllers/redirect.rb +0 -36
  190. data/spec/public/controller/controllers/responder.rb +0 -93
  191. data/spec/public/controller/controllers/url.rb +0 -7
  192. data/spec/public/controller/controllers/views/layout/custom.html.erb +0 -1
  193. data/spec/public/controller/controllers/views/layout/custom_arg.html.erb +0 -1
  194. data/spec/public/controller/controllers/views/layout/custom_arg.json.erb +0 -1
  195. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.html.erb +0 -1
  196. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.xml.erb +0 -1
  197. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.html.erb +0 -1
  198. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_provides/index.xml.erb +0 -1
  199. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/index.html.erb +0 -1
  200. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/no_layout.html.erb +0 -1
  201. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template_argument/index.html.erb +0 -1
  202. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/html_default/index.html.erb +0 -1
  203. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/layout/custom.html.erb +0 -1
  204. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.html.erb +0 -1
  205. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/local_provides/index.xml.erb +0 -1
  206. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.html.erb +0 -1
  207. data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/multi_provides/index.js.erb +0 -1
  208. data/spec/public/controller/cookies_spec.rb +0 -95
  209. data/spec/public/controller/dispatcher_spec.rb +0 -410
  210. data/spec/public/controller/display_spec.rb +0 -84
  211. data/spec/public/controller/redirect_spec.rb +0 -33
  212. data/spec/public/controller/responder_spec.rb +0 -169
  213. data/spec/public/controller/spec_helper.rb +0 -13
  214. data/spec/public/controller/url_spec.rb +0 -255
  215. data/spec/public/core/merb_core_spec.rb +0 -45
  216. data/spec/public/core_ext/fixtures/core_ext_dependency.rb +0 -2
  217. data/spec/public/core_ext/kernel_spec.rb +0 -88
  218. data/spec/public/core_ext/spec_helper.rb +0 -1
  219. data/spec/public/directory_structure/directory/app/controllers/application.rb +0 -3
  220. data/spec/public/directory_structure/directory/app/controllers/base.rb +0 -13
  221. data/spec/public/directory_structure/directory/app/controllers/custom.rb +0 -19
  222. data/spec/public/directory_structure/directory/app/views/base/template.html.erb +0 -1
  223. data/spec/public/directory_structure/directory/app/views/wonderful/template.erb +0 -1
  224. data/spec/public/directory_structure/directory/config/router.rb +0 -3
  225. data/spec/public/directory_structure/directory/log/merb_test.log +0 -4588
  226. data/spec/public/directory_structure/directory_spec.rb +0 -43
  227. data/spec/public/logger/logger_spec.rb +0 -181
  228. data/spec/public/logger/spec_helper.rb +0 -1
  229. data/spec/public/rack/conditinal_get_middleware_spec.rb +0 -127
  230. data/spec/public/rack/csrf_middleware_spec.rb +0 -70
  231. data/spec/public/rack/rack_middleware_spec.rb +0 -99
  232. data/spec/public/rack/shared_example_groups.rb +0 -35
  233. data/spec/public/reloading/directory/app/controllers/application.rb +0 -3
  234. data/spec/public/reloading/directory/app/controllers/reload.rb +0 -6
  235. data/spec/public/reloading/directory/config/init.rb +0 -2
  236. data/spec/public/reloading/directory/log/merb_test.log +0 -288231
  237. data/spec/public/reloading/reload_spec.rb +0 -103
  238. data/spec/public/request/multipart_spec.rb +0 -41
  239. data/spec/public/request/request_spec.rb +0 -250
  240. data/spec/public/router/default_spec.rb +0 -21
  241. data/spec/public/router/deferred_spec.rb +0 -22
  242. data/spec/public/router/fixation_spec.rb +0 -49
  243. data/spec/public/router/fixture/log/merb_test.log +0 -524
  244. data/spec/public/router/namespace_spec.rb +0 -113
  245. data/spec/public/router/nested_matches_spec.rb +0 -97
  246. data/spec/public/router/nested_resources_spec.rb +0 -41
  247. data/spec/public/router/resource_spec.rb +0 -37
  248. data/spec/public/router/resources_spec.rb +0 -82
  249. data/spec/public/router/spec_helper.rb +0 -90
  250. data/spec/public/router/special_spec.rb +0 -61
  251. data/spec/public/router/string_spec.rb +0 -61
  252. data/spec/public/session/controllers/sessions.rb +0 -56
  253. data/spec/public/session/cookie_session_spec.rb +0 -73
  254. data/spec/public/session/memcached_session_spec.rb +0 -31
  255. data/spec/public/session/memory_session_spec.rb +0 -28
  256. data/spec/public/session/multiple_sessions_spec.rb +0 -74
  257. data/spec/public/session/no_session_spec.rb +0 -12
  258. data/spec/public/session/session_spec.rb +0 -106
  259. data/spec/public/template/template_spec.rb +0 -104
  260. data/spec/public/template/templates/error.html.erb +0 -2
  261. data/spec/public/template/templates/template.html.erb +0 -1
  262. data/spec/public/template/templates/template.html.myt +0 -1
  263. data/spec/public/test/controller_matchers_spec.rb +0 -412
  264. data/spec/public/test/controllers/controller_assertion_mock.rb +0 -7
  265. data/spec/public/test/controllers/dispatch_controller.rb +0 -11
  266. data/spec/public/test/controllers/spec_helper_controller.rb +0 -39
  267. data/spec/public/test/multipart_request_helper_spec.rb +0 -159
  268. data/spec/public/test/multipart_upload_text_file.txt +0 -1
  269. data/spec/public/test/request_helper_spec.rb +0 -269
  270. data/spec/public/test/route_helper_spec.rb +0 -78
  271. data/spec/public/test/route_matchers_spec.rb +0 -166
  272. data/spec/public/test/view_helper_spec.rb +0 -96
  273. data/spec/public/test/view_matchers_spec.rb +0 -183
  274. data/spec/spec_helper.rb +0 -121
@@ -1,7 +0,0 @@
1
- class Merb::Test::ControllerAssertionMock
2
-
3
- def self.called(action)
4
- return action
5
- end
6
-
7
- end
@@ -1,11 +0,0 @@
1
- class Merb::Test::DispatchController < Merb::Controller
2
-
3
- def index
4
- Merb::Test::ControllerAssertionMock.called(:index)
5
- end
6
-
7
- def show
8
- Merb::Test::ControllerAssertionMock.called(:show)
9
- end
10
-
11
- end
@@ -1,39 +0,0 @@
1
- class SpecHelperController < Merb::Controller
2
-
3
- def index
4
- Merb::Test::ControllerAssertionMock.called(:index)
5
- end
6
-
7
- def show
8
- Merb::Test::ControllerAssertionMock.called(:show)
9
- end
10
-
11
- def edit
12
- Merb::Test::ControllerAssertionMock.called(:edit)
13
- end
14
-
15
- def new
16
- Merb::Test::ControllerAssertionMock.called(:new)
17
- end
18
-
19
- def create
20
- Merb::Test::ControllerAssertionMock.called(:create)
21
- end
22
-
23
- def update
24
- Merb::Test::ControllerAssertionMock.called(:update)
25
- end
26
-
27
- def destroy
28
- Merb::Test::ControllerAssertionMock.called(:destroy)
29
- end
30
- end
31
-
32
- module Namespaced
33
- class SpecHelperController < Merb::Controller
34
- def index
35
- Merb::Test::ControllerAssertionMock.called(:index)
36
- end
37
- end
38
- end
39
-
@@ -1,159 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
-
3
- Merb.start :environment => 'test', :log_level => :fatal
4
-
5
- Dir[File.join(File.dirname(__FILE__), "controllers/**/*.rb")].each do |f|
6
- require f
7
- end
8
-
9
- describe Merb::Test::MultipartRequestHelper do
10
-
11
- describe "#dispatch_multipart_to" do
12
-
13
- before(:all) do
14
- @controller_klass = Merb::Test::DispatchController
15
- end
16
-
17
- it "should dispatch to the given controller and action" do
18
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:index)
19
-
20
- dispatch_multipart_to(@controller_klass, :index)
21
- end
22
-
23
- it "should dispatch to the given controller and action with params" do
24
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:show)
25
-
26
- controller = dispatch_multipart_to(@controller_klass, :show, :name => "Fred")
27
- controller.params[:name].should == "Fred"
28
- end
29
-
30
- it "should handle a file object when used as a param" do
31
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:show)
32
- file_name = File.join(File.dirname(__FILE__), "multipart_upload_text_file.txt")
33
- File.open( file_name ) do |file|
34
- controller = dispatch_multipart_to(@controller_klass, :show, :my_file => file)
35
- file_params = controller.params[:my_file]
36
- file_params[:content_type].should == "text/plain"
37
- file_params[:size].should == File.size(file_name)
38
- file_params[:tempfile].should be_a_kind_of(File)
39
- file_params[:filename].should == "multipart_upload_text_file.txt"
40
- end
41
- end
42
- end
43
-
44
- describe "#multipart_post" do
45
- before(:each) do
46
- Merb::Router.prepare do |r|
47
- r.resources :spec_helper_controller
48
- end
49
- end
50
-
51
- it "should post to the create action" do
52
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:create)
53
- multipart_post("/spec_helper_controller")
54
- end
55
-
56
- it "should post to the create action with params" do
57
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:create)
58
- controller = multipart_post("/spec_helper_controller", :name => "Harry")
59
- controller.params[:name].should == "Harry"
60
- end
61
-
62
- it "should upload a file to the action using multipart" do
63
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:create)
64
- file_name = File.join(File.dirname(__FILE__), "multipart_upload_text_file.txt")
65
- File.open( file_name ) do |file|
66
- controller = multipart_post("/spec_helper_controller", :my_file => file)
67
- file_params = controller.params[:my_file]
68
- file_params[:content_type].should == "text/plain"
69
- file_params[:size].should == File.size(file_name)
70
- file_params[:tempfile].should be_a_kind_of(File)
71
- file_params[:filename].should == "multipart_upload_text_file.txt"
72
- end
73
- end
74
-
75
- end
76
-
77
- describe "#multipart_put" do
78
- before(:each) do
79
- Merb::Router.prepare do |r|
80
- r.resources :spec_helper_controller
81
- end
82
- end
83
- it "should put to the update action multipart" do
84
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:update)
85
- multipart_put("/spec_helper_controller/1")
86
- end
87
-
88
- it "should put to the update action with multipart params" do
89
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:update)
90
- controller = multipart_put("/spec_helper_controller/my_id", :name => "Harry")
91
- controller.params[:name].should == "Harry"
92
- controller.params[:id].should == "my_id"
93
- end
94
-
95
- it "should upload a file to the action using multipart" do
96
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:update)
97
- file_name = File.join(File.dirname(__FILE__), "multipart_upload_text_file.txt")
98
- File.open( file_name ) do |file|
99
- controller = multipart_put("/spec_helper_controller/my_id", :my_file => file)
100
- controller.params[:id].should == "my_id"
101
- file_params = controller.params[:my_file]
102
- file_params[:content_type].should == "text/plain"
103
- file_params[:size].should == File.size(file_name)
104
- file_params[:tempfile].should be_a_kind_of(File)
105
- file_params[:filename].should == "multipart_upload_text_file.txt"
106
- end
107
- end
108
- end
109
- end
110
-
111
- module Merb::Test::MultipartRequestHelper
112
- describe Param, '#to_multipart' do
113
- it "should represent the key and value correctly" do
114
- param = Param.new('foo', 'bar')
115
- param.to_multipart.should == %(Content-Disposition: form-data; name="foo"\r\n\r\nbar\r\n)
116
- end
117
- end
118
-
119
- describe FileParam, '#to_multipart' do
120
- it "should represent the key, filename and content correctly" do
121
- param = FileParam.new('foo', '/bar.txt', 'baz')
122
- param.to_multipart.should == %(Content-Disposition: form-data; name="foo"; filename="/bar.txt"\r\nContent-Type: text/plain\r\n\r\nbaz\r\n)
123
- end
124
- end
125
-
126
- describe Post, '#push_params(params) param parsing' do
127
- before(:each) do
128
- @fake_return_param = mock('fake return_param')
129
- end
130
-
131
- it "should create Param from params when param doesn't respond to read" do
132
- params = { 'normal' => 'normal_param' }
133
- Param.should_receive(:new).with('normal', 'normal_param').and_return(@fake_return_param)
134
- Post.new.push_params(params)
135
- end
136
-
137
- it "should create FileParam from params when param does response to read" do
138
- file_param = mock('file param')
139
- file_param.should_receive(:read).and_return('file contents')
140
- file_param.should_receive(:path).and_return('file.txt')
141
- params = { 'file' => file_param }
142
- FileParam.should_receive(:new).with('file', 'file.txt', 'file contents').and_return(@fake_return_param)
143
- Post.new.push_params(params)
144
- end
145
- end
146
-
147
- describe Post, '#to_multipart' do
148
- it "should create a multipart request from the params" do
149
- file_param = mock('file param')
150
- file_param.should_receive(:read).and_return('file contents')
151
- file_param.should_receive(:path).and_return('file.txt')
152
- params = { 'file' => file_param, 'normal' => 'normal_param' }
153
- multipart = Post.new(params)
154
- query, content_type = multipart.to_multipart
155
- content_type.should == "multipart/form-data, boundary=----------0xKhTmLbOuNdArY"
156
- query.should == "------------0xKhTmLbOuNdArY\r\nContent-Disposition: form-data; name=\"file\"; filename=\"file.txt\"\r\nContent-Type: text/plain\r\n\r\nfile contents\r\n------------0xKhTmLbOuNdArY\r\nContent-Disposition: form-data; name=\"normal\"\r\n\r\nnormal_param\r\n------------0xKhTmLbOuNdArY--"
157
- end
158
- end
159
- end
@@ -1 +0,0 @@
1
- File With Some Text In It For Testing Multipart Uploads
@@ -1,269 +0,0 @@
1
- require File.join(File.dirname(__FILE__), "..", "..", "spec_helper")
2
-
3
- Merb.start :environment => 'test', :log_level => :fatal
4
-
5
- Dir[File.join(File.dirname(__FILE__), "controllers/**/*.rb")].each do |f|
6
- require f
7
- end
8
-
9
- describe Merb::Test::RequestHelper do
10
-
11
- describe Merb::Test::RequestHelper::CookieJar do
12
-
13
- it "should update its values from a request object" do
14
- cookie_jar = Merb::Test::RequestHelper::CookieJar.new
15
- cookie_jar.should be_empty
16
- request = fake_request
17
- request.cookies[:foo] = "bar+baz" # escaped by default
18
- cookie_jar.update_from_request request
19
- cookie_jar[:foo].should == 'bar baz'
20
- end
21
-
22
- end
23
-
24
- describe "#dispatch_to" do
25
-
26
- before(:all) do
27
- @controller_klass = Merb::Test::DispatchController
28
- end
29
-
30
- it "should dispatch to the given controller and action" do
31
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:index)
32
-
33
- dispatch_to(@controller_klass, :index)
34
- end
35
-
36
- it "should dispatch to the given controller and action with params" do
37
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:show)
38
-
39
- controller = dispatch_to(@controller_klass, :show, :name => "Fred")
40
- controller.params[:name].should == "Fred"
41
- end
42
-
43
- it "should dispatch to the given controller and action with the query string merged into the params" do
44
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:show)
45
- controller = dispatch_to(@controller_klass, :show, {:name => "Fred"}, {'QUERY_STRING' => "last_name=Jones&age=42"} )
46
-
47
- controller.params[:name].should == "Fred"
48
- controller.params[:last_name].should == "Jones"
49
- controller.params[:age].should == "42"
50
- end
51
-
52
- it "should not hit the router to match its route" do
53
- Merb::Router.should_not_receive(:match)
54
- dispatch_to(@controller_klass, :index)
55
- end
56
-
57
- it "merges :controller into params" do
58
- controller = dispatch_to(@controller_klass, :show, :name => "Fred")
59
-
60
- controller.params[:controller].should == @controller_klass.name.to_const_path
61
- end
62
-
63
- it "merges :action into params" do
64
- controller = dispatch_to(@controller_klass, :show, :name => "Fred")
65
-
66
- controller.params[:action].should == "show"
67
- end
68
-
69
- it "should support setting request.raw_post" do
70
- controller = dispatch_to(@controller_klass, :show, {}, {:post_body => 'some XML'})
71
- controller.request.raw_post.should == 'some XML'
72
- end
73
- end
74
-
75
- describe "#dispatch_with_basic_authentication_to" do
76
-
77
- before(:all) do
78
- @controller_klass = Merb::Test::DispatchController
79
- end
80
-
81
- it "should dispatch to the given controller and action" do
82
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:index)
83
-
84
- dispatch_with_basic_authentication_to(@controller_klass, :index, "Fred", "secret")
85
- end
86
-
87
- it "should dispatch to the given controller and action with authentication token" do
88
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:show)
89
-
90
- controller = dispatch_with_basic_authentication_to(@controller_klass, :show, "Fred", "secret")
91
-
92
- controller.request.env["X_HTTP_AUTHORIZATION"].should == "Basic #{Base64.encode64("Fred:secret")}"
93
- end
94
-
95
- it "should dispatch to the given controller and action with authentication token and params" do
96
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:show)
97
-
98
- controller = dispatch_with_basic_authentication_to(@controller_klass, :show, "Fred", "secret", :name => "Fred")
99
-
100
- controller.request.env["X_HTTP_AUTHORIZATION"].should == "Basic #{Base64.encode64("Fred:secret")}"
101
- controller.params[:name].should == "Fred"
102
- end
103
-
104
- it "should not hit the router to match its route" do
105
- Merb::Router.should_not_receive(:match)
106
- dispatch_with_basic_authentication_to(@controller_klass, :index, "Fred", "secret")
107
- end
108
- end
109
-
110
- describe "#get" do
111
- before(:each) do
112
- Merb::Router.prepare do |r|
113
- r.resources :spec_helper_controller
114
- r.match("/:controller/:action/:custom").to(:controller => ":controller")
115
- end
116
- end
117
-
118
- it "should perform the index action when used with a get" do
119
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:index)
120
- get("/spec_helper_controller")
121
- end
122
-
123
- it "should perform the index action and have params available" do
124
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:index)
125
- controller = get("/spec_helper_controller", :name => "Harry")
126
- controller.params[:name].should == "Harry"
127
- end
128
-
129
- it "should perform the index action and have params available from the query string" do
130
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:index)
131
- controller = get("/spec_helper_controller?last_name=Oswald&age=25", :name => "Harry")
132
- controller.params[:name].should == "Harry"
133
- controller.params[:last_name].should == "Oswald"
134
- controller.params[:age].should == "25"
135
- end
136
-
137
- it "should evaluate in the context of the controller in the block" do
138
- get("/spec_helper_controller") do |controller|
139
- controller.class.should == SpecHelperController
140
- end
141
- end
142
-
143
- it "should allow for custom router params" do
144
- controller = get("/spec_helper_controller/index/my_custom_stuff")
145
- controller.params[:custom].should == "my_custom_stuff"
146
- end
147
-
148
- it "should get the show action" do
149
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:show)
150
- controller = get("/spec_helper_controller/my_id")
151
- controller.params[:id].should == "my_id"
152
- end
153
- end
154
-
155
- describe "#post" do
156
- before(:each) do
157
- Merb::Router.prepare do |r|
158
- r.resources :spec_helper_controller
159
- end
160
- end
161
-
162
- it "should post to the create action" do
163
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:create)
164
- post("/spec_helper_controller")
165
- end
166
-
167
- it "should post to the create action with params" do
168
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:create)
169
- controller = post("/spec_helper_controller", :name => "Harry")
170
- controller.params[:name].should == "Harry"
171
- end
172
- end
173
-
174
- describe "#put" do
175
- before(:each) do
176
- Merb::Router.prepare do |r|
177
- r.resources :spec_helper_controller
178
- end
179
- end
180
- it "should put to the update action" do
181
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:update)
182
- put("/spec_helper_controller/1")
183
- end
184
-
185
- it "should put to the update action with params" do
186
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:update)
187
- controller = put("/spec_helper_controller/my_id", :name => "Harry")
188
- controller.params[:name].should == "Harry"
189
- controller.params[:id].should == "my_id"
190
- end
191
- end
192
-
193
- describe "#delete" do
194
- before(:each) do
195
- Merb::Router.prepare do |r|
196
- r.resources :spec_helper_controller
197
- end
198
- end
199
- it "should put to the update action" do
200
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:destroy)
201
- delete("/spec_helper_controller/1")
202
- end
203
-
204
- it "should put to the update action with params" do
205
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:destroy)
206
- controller = delete("/spec_helper_controller/my_id", :name => "Harry")
207
- controller.params[:name].should == "Harry"
208
- controller.params[:id].should == "my_id"
209
- end
210
- end
211
-
212
- describe "#request" do
213
- before(:each) do
214
- Merb::Router.prepare do |r|
215
- r.namespace :namespaced do |namespaced|
216
- namespaced.resources :spec_helper_controller
217
- end
218
- end
219
- end
220
-
221
- it "should support setting request.raw_post" do
222
- controller = request("/namespaced/spec_helper_controller", {}, {:post_body => 'some XML'})
223
- controller.request.raw_post.should == 'some XML'
224
- end
225
-
226
- it "should get namespaced index action" do
227
- Merb::Test::ControllerAssertionMock.should_receive(:called).with(:index)
228
- controller = request("/namespaced/spec_helper_controller")
229
- controller.class.should == Namespaced::SpecHelperController
230
- end
231
-
232
- it "should make the post body available in the request on deferred routing" do
233
- Merb::Router.prepare do |r|
234
- r.match('/xmlrpc').defer_to do |request, params|
235
- request.raw_post.should == 'XMLRPC request body'
236
- {:controller => 'spec_helper_controller', :action => :index}
237
- end
238
- end
239
-
240
- request('/xmlrpc', {}, {:post_body => 'XMLRPC request body'})
241
- end
242
- end
243
-
244
- end
245
-
246
- module Merb::Test::RequestHelper
247
- describe FakeRequest, ".new(env = {}, req = StringIO.new)" do
248
- it "should create request with default enviroment, minus rack.input" do
249
- @mock = FakeRequest.new
250
- @mock.env.except('rack.input').should == FakeRequest::DEFAULT_ENV
251
- end
252
-
253
- it "should override default env values passed in HTTP format" do
254
- @mock = FakeRequest.new('HTTP_ACCEPT' => 'nothing')
255
- @mock.env['HTTP_ACCEPT'].should == 'nothing'
256
- end
257
-
258
- it "should override default env values passed in symbol format" do
259
- @mock = FakeRequest.new(:http_accept => 'nothing')
260
- @mock.env['HTTP_ACCEPT'].should == 'nothing'
261
- end
262
-
263
- it "should set rack input to an empty StringIO" do
264
- @mock = FakeRequest.new
265
- @mock.env['rack.input'].should be_kind_of(StringIO)
266
- @mock.env['rack.input'].read.should == ''
267
- end
268
- end
269
- end