merb 0.5.3 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (294) hide show
  1. data/LICENSE +0 -20
  2. data/README +0 -277
  3. data/Rakefile +80 -199
  4. data/TODO +0 -3
  5. metadata +19 -438
  6. data/SVN_REVISION +0 -1
  7. data/app_generators/merb/USAGE +0 -5
  8. data/app_generators/merb/merb_generator.rb +0 -108
  9. data/app_generators/merb/templates/Rakefile +0 -124
  10. data/app_generators/merb/templates/app/controllers/application.rb +0 -3
  11. data/app_generators/merb/templates/app/controllers/exceptions.rb +0 -13
  12. data/app_generators/merb/templates/app/helpers/global_helper.rb +0 -5
  13. data/app_generators/merb/templates/app/mailers/views/layout/application.html.erb +0 -1
  14. data/app_generators/merb/templates/app/mailers/views/layout/application.text.erb +0 -1
  15. data/app_generators/merb/templates/app/parts/views/layout/application.html.erb +0 -1
  16. data/app_generators/merb/templates/app/views/exceptions/internal_server_error.html.erb +0 -216
  17. data/app_generators/merb/templates/app/views/exceptions/not_acceptable.html.erb +0 -38
  18. data/app_generators/merb/templates/app/views/exceptions/not_found.html.erb +0 -40
  19. data/app_generators/merb/templates/app/views/layout/application.html.erb +0 -11
  20. data/app_generators/merb/templates/config/boot.rb +0 -11
  21. data/app_generators/merb/templates/config/dependencies.rb +0 -41
  22. data/app_generators/merb/templates/config/environments/development.rb +0 -1
  23. data/app_generators/merb/templates/config/environments/production.rb +0 -1
  24. data/app_generators/merb/templates/config/environments/test.rb +0 -1
  25. data/app_generators/merb/templates/config/merb.yml +0 -82
  26. data/app_generators/merb/templates/config/merb_init.rb +0 -17
  27. data/app_generators/merb/templates/config/plugins.yml +0 -1
  28. data/app_generators/merb/templates/config/router.rb +0 -35
  29. data/app_generators/merb/templates/config/upload.conf +0 -0
  30. data/app_generators/merb/templates/public/images/merb.jpg +0 -0
  31. data/app_generators/merb/templates/public/merb.fcgi +0 -6
  32. data/app_generators/merb/templates/public/stylesheets/master.css +0 -119
  33. data/app_generators/merb/templates/script/destroy +0 -32
  34. data/app_generators/merb/templates/script/generate +0 -32
  35. data/app_generators/merb/templates/script/stop_merb +0 -13
  36. data/app_generators/merb/templates/script/win_script.cmd +0 -1
  37. data/app_generators/merb/templates/spec/spec.opts +0 -6
  38. data/app_generators/merb/templates/spec/spec_helper.rb +0 -15
  39. data/app_generators/merb/templates/test/test_helper.rb +0 -14
  40. data/app_generators/merb_plugin/USAGE +0 -5
  41. data/app_generators/merb_plugin/merb_plugin_generator.rb +0 -68
  42. data/app_generators/merb_plugin/templates/LICENSE +0 -20
  43. data/app_generators/merb_plugin/templates/README +0 -4
  44. data/app_generators/merb_plugin/templates/Rakefile +0 -35
  45. data/app_generators/merb_plugin/templates/TODO +0 -5
  46. data/app_generators/merb_plugin/templates/merbtasks.rb +0 -6
  47. data/app_generators/merb_plugin/templates/sampleplugin.rb +0 -10
  48. data/app_generators/merb_plugin/templates/sampleplugin_spec.rb +0 -7
  49. data/app_generators/merb_plugin/templates/spec_helper.rb +0 -2
  50. data/bin/merb +0 -4
  51. data/lib/autotest/discover.rb +0 -3
  52. data/lib/autotest/merb_rspec.rb +0 -80
  53. data/lib/merb.rb +0 -188
  54. data/lib/merb/abstract_controller.rb +0 -399
  55. data/lib/merb/assets.rb +0 -160
  56. data/lib/merb/assets.rb.orig +0 -119
  57. data/lib/merb/boot_loader.rb +0 -286
  58. data/lib/merb/boot_loader.rb.orig +0 -235
  59. data/lib/merb/caching.rb +0 -5
  60. data/lib/merb/caching/action_cache.rb +0 -92
  61. data/lib/merb/caching/fragment_cache.rb +0 -39
  62. data/lib/merb/caching/store/file_cache.rb +0 -90
  63. data/lib/merb/caching/store/memory_cache.rb +0 -85
  64. data/lib/merb/config.rb +0 -290
  65. data/lib/merb/constants.rb +0 -50
  66. data/lib/merb/controller.rb +0 -220
  67. data/lib/merb/cookies.rb +0 -95
  68. data/lib/merb/core_ext.rb +0 -15
  69. data/lib/merb/core_ext/array.rb +0 -0
  70. data/lib/merb/core_ext/class.rb +0 -180
  71. data/lib/merb/core_ext/enumerable.rb +0 -49
  72. data/lib/merb/core_ext/get_args.rb +0 -76
  73. data/lib/merb/core_ext/hash.rb +0 -306
  74. data/lib/merb/core_ext/inflections.rb +0 -112
  75. data/lib/merb/core_ext/inflector.rb +0 -275
  76. data/lib/merb/core_ext/kernel.rb +0 -242
  77. data/lib/merb/core_ext/mash.rb +0 -88
  78. data/lib/merb/core_ext/module.rb +0 -67
  79. data/lib/merb/core_ext/numeric.rb +0 -72
  80. data/lib/merb/core_ext/object.rb +0 -183
  81. data/lib/merb/core_ext/string.rb +0 -53
  82. data/lib/merb/core_ext/symbol.rb +0 -6
  83. data/lib/merb/dispatcher.rb +0 -109
  84. data/lib/merb/drb_server.rb +0 -19
  85. data/lib/merb/erubis_ext.rb +0 -10
  86. data/lib/merb/exceptions.rb +0 -192
  87. data/lib/merb/generators/merb_app/merb_app.rb +0 -22
  88. data/lib/merb/generators/merb_generator_helpers.rb +0 -318
  89. data/lib/merb/generators/merb_plugin.rb +0 -22
  90. data/lib/merb/logger.rb +0 -78
  91. data/lib/merb/mail_controller.rb +0 -268
  92. data/lib/merb/mailer.rb +0 -87
  93. data/lib/merb/mixins/basic_authentication.rb +0 -35
  94. data/lib/merb/mixins/controller.rb +0 -160
  95. data/lib/merb/mixins/erubis_capture.rb +0 -68
  96. data/lib/merb/mixins/general_controller.rb +0 -253
  97. data/lib/merb/mixins/inline_partial.rb +0 -32
  98. data/lib/merb/mixins/render.rb +0 -465
  99. data/lib/merb/mixins/responder.rb +0 -449
  100. data/lib/merb/mixins/view_context.rb +0 -558
  101. data/lib/merb/mixins/web_controller.rb +0 -36
  102. data/lib/merb/mongrel_handler.rb +0 -168
  103. data/lib/merb/part_controller.rb +0 -29
  104. data/lib/merb/plugins.rb +0 -16
  105. data/lib/merb/rack_adapter.rb +0 -37
  106. data/lib/merb/request.rb +0 -465
  107. data/lib/merb/router.rb +0 -646
  108. data/lib/merb/server.rb +0 -169
  109. data/lib/merb/session.rb +0 -23
  110. data/lib/merb/session/cookie_store.rb +0 -118
  111. data/lib/merb/session/mem_cache_session.rb +0 -131
  112. data/lib/merb/session/memory_session.rb +0 -176
  113. data/lib/merb/template.rb +0 -37
  114. data/lib/merb/template/erubis.rb +0 -68
  115. data/lib/merb/template/haml.rb +0 -87
  116. data/lib/merb/template/markaby.rb +0 -59
  117. data/lib/merb/template/xml_builder.rb +0 -50
  118. data/lib/merb/test/fake_request.rb +0 -74
  119. data/lib/merb/test/helper.rb +0 -260
  120. data/lib/merb/test/hpricot.rb +0 -136
  121. data/lib/merb/test/multipart.rb +0 -66
  122. data/lib/merb/test/rspec.rb +0 -18
  123. data/lib/merb/test/rspec_matchers/controller_matchers.rb +0 -117
  124. data/lib/merb/test/rspec_matchers/markup_matchers.rb +0 -98
  125. data/lib/merb/upload_handler.rb +0 -80
  126. data/lib/merb/upload_progress.rb +0 -48
  127. data/lib/merb/version.rb +0 -49
  128. data/lib/merb/view_context.rb +0 -79
  129. data/lib/tasks.rb +0 -7
  130. data/lib/tasks/merb.rake +0 -54
  131. data/merb_default_generators/model/USAGE +0 -0
  132. data/merb_default_generators/model/model_generator.rb +0 -16
  133. data/merb_default_generators/model/templates/new_model_template.erb +0 -5
  134. data/merb_default_generators/resource_controller/USAGE +0 -0
  135. data/merb_default_generators/resource_controller/resource_controller_generator.rb +0 -26
  136. data/merb_default_generators/resource_controller/templates/controller.rb +0 -30
  137. data/merb_default_generators/resource_controller/templates/edit.html.erb +0 -1
  138. data/merb_default_generators/resource_controller/templates/helper.rb +0 -5
  139. data/merb_default_generators/resource_controller/templates/index.html.erb +0 -1
  140. data/merb_default_generators/resource_controller/templates/new.html.erb +0 -1
  141. data/merb_default_generators/resource_controller/templates/show.html.erb +0 -1
  142. data/merb_generators/controller/USAGE +0 -5
  143. data/merb_generators/controller/controller_generator.rb +0 -16
  144. data/merb_generators/controller/templates/controller.rb +0 -8
  145. data/merb_generators/controller/templates/helper.rb +0 -5
  146. data/merb_generators/controller/templates/index.html.erb +0 -3
  147. data/merb_generators/part_controller/USAGE +0 -5
  148. data/merb_generators/part_controller/part_controller_generator.rb +0 -27
  149. data/merb_generators/part_controller/templates/controller.rb +0 -8
  150. data/merb_generators/part_controller/templates/helper.rb +0 -5
  151. data/merb_generators/part_controller/templates/index.html.erb +0 -3
  152. data/merb_generators/resource/USAGE +0 -0
  153. data/merb_generators/resource/resource_generator.rb +0 -67
  154. data/rspec_generators/merb_controller_test/merb_controller_test_generator.rb +0 -67
  155. data/rspec_generators/merb_controller_test/templates/controller_spec.rb +0 -8
  156. data/rspec_generators/merb_controller_test/templates/edit_spec.rb +0 -12
  157. data/rspec_generators/merb_controller_test/templates/helper_spec.rb +0 -5
  158. data/rspec_generators/merb_controller_test/templates/index_spec.rb +0 -12
  159. data/rspec_generators/merb_controller_test/templates/new_spec.rb +0 -12
  160. data/rspec_generators/merb_controller_test/templates/show_spec.rb +0 -5
  161. data/rspec_generators/merb_model_test/merb_model_test_generator.rb +0 -26
  162. data/rspec_generators/merb_model_test/templates/model_spec_template.erb +0 -7
  163. data/script/destroy +0 -14
  164. data/script/generate +0 -14
  165. data/spec/fixtures/config/environments/environment_config_test.yml +0 -1
  166. data/spec/fixtures/config/merb.yml +0 -18
  167. data/spec/fixtures/controllers/dispatch_spec_controllers.rb +0 -235
  168. data/spec/fixtures/controllers/render_spec_controllers.rb +0 -184
  169. data/spec/fixtures/foo.rb +0 -3
  170. data/spec/fixtures/mailers/views/layout/application.html.erb +0 -3
  171. data/spec/fixtures/mailers/views/layout/application.text.erb +0 -3
  172. data/spec/fixtures/mailers/views/test_mail_controller/eighth.html.erb +0 -1
  173. data/spec/fixtures/mailers/views/test_mail_controller/eighth.text.erb +0 -1
  174. data/spec/fixtures/mailers/views/test_mail_controller/first.html.erb +0 -1
  175. data/spec/fixtures/mailers/views/test_mail_controller/first.text.erb +0 -1
  176. data/spec/fixtures/mailers/views/test_mail_controller/ninth.html.erb +0 -1
  177. data/spec/fixtures/mailers/views/test_mail_controller/ninth.text.erb +0 -1
  178. data/spec/fixtures/mailers/views/test_mail_controller/second.text.erb +0 -1
  179. data/spec/fixtures/mailers/views/test_mail_controller/third.html.erb +0 -1
  180. data/spec/fixtures/models/router_spec_models.rb +0 -30
  181. data/spec/fixtures/parts/views/layout/todo_part.html.erb +0 -3
  182. data/spec/fixtures/parts/views/layout/todo_part.xml.erb +0 -3
  183. data/spec/fixtures/parts/views/todo_part/formatted_output.html.erb +0 -1
  184. data/spec/fixtures/parts/views/todo_part/formatted_output.js.erb +0 -1
  185. data/spec/fixtures/parts/views/todo_part/formatted_output.xml.erb +0 -1
  186. data/spec/fixtures/parts/views/todo_part/list.html.erb +0 -3
  187. data/spec/fixtures/sample.txt +0 -1
  188. data/spec/fixtures/views/erubis.html.erb +0 -1
  189. data/spec/fixtures/views/examples/_erubis.html.erb +0 -1
  190. data/spec/fixtures/views/examples/_haml.html.haml +0 -1
  191. data/spec/fixtures/views/examples/_markaby.html.mab +0 -1
  192. data/spec/fixtures/views/examples/_throw_content.html.erb +0 -6
  193. data/spec/fixtures/views/examples/hello.xml.builder +0 -1
  194. data/spec/fixtures/views/examples/js.js.erb +0 -1
  195. data/spec/fixtures/views/examples/template_catch_content.html.erb +0 -15
  196. data/spec/fixtures/views/examples/template_catch_content_from_partial.html.erb +0 -6
  197. data/spec/fixtures/views/examples/template_throw_content.html.erb +0 -10
  198. data/spec/fixtures/views/examples/template_throw_content_without_block.html.erb +0 -3
  199. data/spec/fixtures/views/exceptions/admin_access_required.html.erb +0 -1
  200. data/spec/fixtures/views/extension_template_controller/_nested_js.js.erb +0 -1
  201. data/spec/fixtures/views/extension_template_controller/_nested_xml.xml.erb +0 -1
  202. data/spec/fixtures/views/extension_template_controller/_render_partial_multiple_times.html.erb +0 -1
  203. data/spec/fixtures/views/extension_template_controller/erubis_templates.html.erb +0 -1
  204. data/spec/fixtures/views/extension_template_controller/erubis_templates.js.erb +0 -1
  205. data/spec/fixtures/views/extension_template_controller/erubis_templates.rhtml +0 -1
  206. data/spec/fixtures/views/extension_template_controller/erubis_templates.xml.erb +0 -1
  207. data/spec/fixtures/views/extension_template_controller/haml_index.html.haml +0 -0
  208. data/spec/fixtures/views/extension_template_controller/haml_templates.html.haml +0 -1
  209. data/spec/fixtures/views/extension_template_controller/haml_templates.js.haml +0 -1
  210. data/spec/fixtures/views/extension_template_controller/haml_templates.xml.haml +0 -1
  211. data/spec/fixtures/views/extension_template_controller/index.html.erb +0 -0
  212. data/spec/fixtures/views/extension_template_controller/markaby_index.html.mab +0 -0
  213. data/spec/fixtures/views/extension_template_controller/markaby_templates.html.mab +0 -1
  214. data/spec/fixtures/views/extension_template_controller/markaby_templates.js.mab +0 -1
  215. data/spec/fixtures/views/extension_template_controller/markaby_templates.xml.mab +0 -1
  216. data/spec/fixtures/views/extension_template_controller/render_multiple_partials.html.erb +0 -4
  217. data/spec/fixtures/views/extension_template_controller/render_nested_js.js.erb +0 -1
  218. data/spec/fixtures/views/extension_template_controller/render_nested_xml.xml.erb +0 -1
  219. data/spec/fixtures/views/haml.html.haml +0 -1
  220. data/spec/fixtures/views/haml.xml.haml +0 -2
  221. data/spec/fixtures/views/layout/application.html.erb +0 -1
  222. data/spec/fixtures/views/layout/application.xml.erb +0 -1
  223. data/spec/fixtures/views/layout/nested/example.html.erb +0 -1
  224. data/spec/fixtures/views/markaby.html.mab +0 -1
  225. data/spec/fixtures/views/nested/example/test.html.erb +0 -1
  226. data/spec/fixtures/views/partials/_erubis.html.erb +0 -1
  227. data/spec/fixtures/views/partials/_erubis_collection.html.erb +0 -1
  228. data/spec/fixtures/views/partials/_erubis_collection_with_locals.html.erb +0 -1
  229. data/spec/fixtures/views/partials/_erubis_new.html.erb +0 -1
  230. data/spec/fixtures/views/partials/_haml.html.haml +0 -1
  231. data/spec/fixtures/views/partials/_haml_collection.html.haml +0 -1
  232. data/spec/fixtures/views/partials/_haml_collection_with_locals.html.haml +0 -1
  233. data/spec/fixtures/views/partials/_haml_new.html.haml +0 -1
  234. data/spec/fixtures/views/partials/_markaby.html.mab +0 -1
  235. data/spec/fixtures/views/partials/_markaby_collection.html.mab +0 -1
  236. data/spec/fixtures/views/partials/_markaby_collection_with_locals.html.mab +0 -1
  237. data/spec/fixtures/views/partials/_markaby_new.html.mab +0 -1
  238. data/spec/fixtures/views/render_object_controller/render_object_with_template.html.erb +0 -1
  239. data/spec/fixtures/views/render_object_controller/render_object_with_template.js.erb +0 -1
  240. data/spec/fixtures/views/render_object_controller/render_object_with_template.xml.erb +0 -1
  241. data/spec/fixtures/views/template_views/interface__buffer_erubis.html.erb +0 -4
  242. data/spec/fixtures/views/template_views/interface__buffer_haml.html.haml +0 -7
  243. data/spec/fixtures/views/template_views/interface__buffer_markaby.html.mab +0 -7
  244. data/spec/fixtures/views/template_views/interface_capture_erubis.html.erb +0 -15
  245. data/spec/fixtures/views/template_views/interface_capture_haml.html.haml +0 -15
  246. data/spec/fixtures/views/template_views/interface_capture_markaby.html.mab +0 -4
  247. data/spec/fixtures/views/template_views/interface_concat_erubis.html.erb +0 -12
  248. data/spec/fixtures/views/template_views/interface_concat_haml.html.haml +0 -11
  249. data/spec/fixtures/views/template_views/interface_concat_markaby.html.mab +0 -14
  250. data/spec/fixtures/views/test.dir/the_template.html.erb +0 -1
  251. data/spec/merb/abstract_controller_spec.rb +0 -38
  252. data/spec/merb/assets_spec.rb +0 -207
  253. data/spec/merb/caching_spec.rb +0 -102
  254. data/spec/merb/config_spec.rb +0 -29
  255. data/spec/merb/controller_filters_spec.rb +0 -253
  256. data/spec/merb/controller_spec.rb +0 -126
  257. data/spec/merb/cookie_store_spec.rb +0 -72
  258. data/spec/merb/cookies_spec.rb +0 -96
  259. data/spec/merb/core_ext/class_spec.rb +0 -97
  260. data/spec/merb/core_ext/enumerable_spec.rb +0 -27
  261. data/spec/merb/core_ext/hash_spec.rb +0 -251
  262. data/spec/merb/core_ext/inflector_spec.rb +0 -34
  263. data/spec/merb/core_ext/kernel_spec.rb +0 -25
  264. data/spec/merb/core_ext/numeric_spec.rb +0 -26
  265. data/spec/merb/core_ext/object_spec.rb +0 -47
  266. data/spec/merb/core_ext/string_spec.rb +0 -22
  267. data/spec/merb/core_ext/symbol_spec.rb +0 -7
  268. data/spec/merb/dependency_spec.rb +0 -22
  269. data/spec/merb/dispatch_spec.rb +0 -528
  270. data/spec/merb/fake_request_spec.rb +0 -80
  271. data/spec/merb/generator_spec.rb +0 -248
  272. data/spec/merb/handler_spec.rb +0 -169
  273. data/spec/merb/mail_controller_spec.rb +0 -177
  274. data/spec/merb/mailer_spec.rb +0 -87
  275. data/spec/merb/multipart_spec.rb +0 -50
  276. data/spec/merb/part_controller_spec.rb +0 -124
  277. data/spec/merb/plugins_spec.rb +0 -80
  278. data/spec/merb/render_spec.rb +0 -469
  279. data/spec/merb/request_spec.rb +0 -287
  280. data/spec/merb/responder_spec.rb +0 -562
  281. data/spec/merb/router_spec.rb +0 -900
  282. data/spec/merb/server_spec.rb +0 -19
  283. data/spec/merb/template_spec.rb +0 -41
  284. data/spec/merb/upload_handler_spec.rb +0 -108
  285. data/spec/merb/version_spec.rb +0 -33
  286. data/spec/merb/view_context_spec.rb +0 -366
  287. data/spec/spec_generator_helper.rb +0 -34
  288. data/spec/spec_helper.rb +0 -101
  289. data/spec/spec_helpers/url_shared_behaviour.rb +0 -112
  290. data/test_unit_generators/merb_controller_test/merb_controller_test_generator.rb +0 -53
  291. data/test_unit_generators/merb_controller_test/templates/functional_test.rb +0 -17
  292. data/test_unit_generators/merb_controller_test/templates/helper_test.rb +0 -9
  293. data/test_unit_generators/merb_model_test/merb_model_test_generator.rb +0 -29
  294. data/test_unit_generators/merb_model_test/templates/model_test_unit_template.erb +0 -9
@@ -1,287 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- describe Merb::Request do
4
- include Mocha::SetupAndTeardown
5
-
6
- class GoodPosts < Merb::Controller
7
- def show() end
8
- end
9
-
10
- before(:each) do
11
- setup_stubs
12
- @in = Merb::Test::FakeRequest.new
13
- Merb::Request.any_instance.stubs(:route_params).returns({})
14
- end
15
-
16
- after(:each) do
17
- teardown_stubs
18
- end
19
-
20
- it "should parse POST body into params" do
21
- @in.post_body = "title=hello%20there&body=some%20text&user[roles][]=admin&user[roles][]=superuser&commit=Submit"
22
- @in['REQUEST_METHOD'] = 'POST'
23
- @in['CONTENT_TYPE'] = "application/x-www-form-urlencoded"
24
- request = Merb::Request.new(@in)
25
- request.params[:title].should == "hello there"
26
- request.params[:body].should == "some text"
27
- request.params[:commit].should == "Submit"
28
- request.params[:user][:roles].class.should == Array
29
- request.params[:user][:roles][0].should == "admin"
30
- request.params[:user][:roles][1].should == "superuser"
31
- end
32
-
33
- it "should parse POST body into params unless Content-Type header is set explicitly" do
34
- input = "title=hello%20there&body=some%20text&commit=Submit"
35
- @in.post_body = input
36
- @in['REQUEST_METHOD'] = 'POST'
37
- @in['CONTENT_TYPE'] = 'text/plain'
38
- request = Merb::Request.new(@in)
39
- request.params[:title].should be_nil
40
- request.params[:body].should be_nil
41
- request.params[:commit].should be_nil
42
- request.raw_post.should == input
43
- end
44
-
45
- it "should parse PUT body into params" do
46
- @in.post_body = "title=hello%20there&body=some%20text&commit=Submit"
47
- @in['REQUEST_METHOD'] = 'PUT'
48
- @in['CONTENT_TYPE'] = "application/x-www-form-urlencoded"
49
- request = Merb::Request.new(@in)
50
- request.params[:title].should == "hello there"
51
- request.params[:body].should == "some text"
52
- request.params[:commit].should == "Submit"
53
- end
54
-
55
- it "should parse PUT body into params unless Content-Type header is set explicitly" do
56
- input = "title=hello%20there&body=some%20text&commit=Submit"
57
- @in.post_body = input
58
- @in['REQUEST_METHOD'] = 'PUT'
59
- @in['CONTENT_TYPE'] = 'text/plain'
60
- request = Merb::Request.new(@in)
61
- request.params[:title].should be_nil
62
- request.params[:body].should be_nil
63
- request.params[:commit].should be_nil
64
- request.raw_post.should == input
65
- end
66
-
67
- it "should parse Query String into params" do
68
- @in['QUERY_STRING'] = "title=hello%20there&body=some%20text&commit=Submit"
69
- request = Merb::Request.new(@in)
70
- request.params[:title].should == "hello there"
71
- request.params[:body].should == "some text"
72
- request.params[:commit].should == "Submit"
73
- end
74
-
75
- it "shouldn't explode on key only query" do
76
- @in['QUERY_STRING'] = "pop"
77
- request = Merb::Request.new(@in)
78
- request.params.has_key?(:pop).should be_true
79
- end
80
-
81
- it "shouldn't explode on value only query" do
82
- @in['QUERY_STRING'] = "=bang"
83
- request = Merb::Request.new(@in)
84
- request.params.has_value?('bang').should be_true
85
- end
86
-
87
- it "should handle file upload for multipart/form-data posts" do
88
- m = Merb::Test::Multipart::Post.new :file => File.open(FIXTURES / 'sample.txt')
89
- body, head = m.to_multipart
90
- @in['REQUEST_METHOD'] = 'POST'
91
- @in['CONTENT_TYPE'] = head
92
- @in['CONTENT_LENGTH'] = body.length
93
- @in.post_body = body
94
- request = Merb::Request.new(@in)
95
- request.params[:file].should_not be_nil
96
- request.params[:file][:tempfile].class.should == Tempfile
97
- request.params[:file][:content_type].should == 'text/plain'
98
- end
99
-
100
- # it "multipart/form-data handles multiple form fields" do
101
- # m = Merb::Test::Multipart::Post.new :foo => 'bario', 'files[]' => File.open(FIXTURES / 'sample.txt')
102
- # m.push_params 'files[]' => File.open(FIXTURES / 'foo.rb')
103
- # body, head = m.to_multipart
104
- # @in['REQUEST_METHOD'] = 'POST'
105
- # @in['CONTENT_TYPE'] = head
106
- # @in['CONTENT_LENGTH'] = body.length
107
- # @in.post_body = body
108
- # request = Merb::Request.new(@in)
109
- # params[:foo].should == 'bario'
110
- # params[:files].should_not be_nil
111
- # params[:files].should be_kind_of(Array)
112
- # params[:files].first[:tempfile].class.should == Tempfile
113
- # end
114
-
115
- it "Json Post Body is parsed into params" do
116
- @in.post_body = "{\"title\":\"hello there\",\"body\":\"some text\"}"
117
- @in['REQUEST_METHOD'] = 'POST'
118
- @in['CONTENT_TYPE'] = "text/x-json"
119
- request = Merb::Request.new(@in)
120
- request.params[:title].should == "hello there"
121
- request.params[:body].should == "some text"
122
- end
123
-
124
- it "Json Post Body is not parsed into params if Merb::Request::parse_json_params = false" do
125
- Merb::Request::parse_json_params = false
126
- @in.post_body = "{\"title\":\"hello there\",\"body\":\"some text\"}"
127
- @in['REQUEST_METHOD'] = 'POST'
128
- @in['CONTENT_TYPE'] = "text/x-json"
129
- request = Merb::Request.new(@in)
130
- request.params[:title].should be_nil
131
- request.params[:body].should be_nil
132
- Merb::Request::parse_json_params = true
133
- end
134
-
135
- it "should parse a JSON body into params when charset provided" do
136
- @in.post_body = "{\"title\":\"hello there\",\"body\":\"some text\"}"
137
- @in['REQUEST_METHOD'] = 'POST'
138
- @in['CONTENT_TYPE'] = "text/x-json; charset=utf-8"
139
- request = Merb::Request.new(@in)
140
- request.params[:title].should == "hello there"
141
- request.params[:body].should == "some text"
142
- end
143
-
144
- it "should parse an XML body into params when charset provided" do
145
- @in.post_body = "<root><title>hello there</title><body>some text</body></root>"
146
- @in['REQUEST_METHOD'] = 'POST'
147
- @in['CONTENT_TYPE'] = "text/xml; charset=utf-8"
148
- request = Merb::Request.new(@in)
149
- request.params[:root][:title].should == "hello there"
150
- request.params[:root][:body].should == "some text"
151
- end
152
-
153
- it "should handle hash-style form fields in multipart/form-data" do
154
- m = Merb::Test::Multipart::Post.new :foo => 'bario',
155
- 'files[foo][file]' => File.open(FIXTURES / 'foo.rb'),
156
- 'files[foo][name]' => "Foo",
157
- 'files[bar][file]' => File.open(FIXTURES / 'foo.rb'),
158
- 'files[bar][name]' => "Bar",
159
- 'deep[files][foobar][]' => File.open(FIXTURES / 'foo.rb'),
160
- 'regular_fields[user][name]' => "John Doe",
161
- 'regular_fields[user][email]' => "jdoe@example.com"
162
- body, head = m.to_multipart
163
- @in['REQUEST_METHOD'] = 'POST'
164
- @in['CONTENT_TYPE'] = head
165
- @in['CONTENT_LENGTH'] = body.length
166
- @in.post_body = body
167
- request = Merb::Request.new(@in)
168
-
169
- request.params.should_not include(:"files[foo]")
170
- request.params.should_not include(:"files[bar]")
171
- request.params.should_not include(:"regular_fields[user]")
172
- request.params.should_not include(:"deep[files]")
173
-
174
- request.params[:files][:foo][:name].should == "Foo"
175
- request.params[:files][:foo][:file].should include(:filename)
176
- request.params[:files][:foo][:file][:tempfile].class.should == Tempfile
177
- request.params[:files][:bar][:name].should == "Bar"
178
- request.params[:files][:bar][:file].should include(:filename)
179
- request.params[:files][:bar][:file][:tempfile].class.should == Tempfile
180
-
181
- request.params[:deep][:files][:foobar].class.should == Array
182
- request.params[:deep][:files][:foobar].size.should == 1
183
-
184
- request.params[:regular_fields][:user][:name].should == "John Doe"
185
- end
186
-
187
- it "should understand PUT if passed as _method in query string for RESTful form dispatch" do
188
- @in.post_body = "title=hello"
189
- @in['QUERY_STRING'] = '_method=put'
190
- @in['REQUEST_METHOD'] = 'POST'
191
- @in['CONTENT_TYPE'] = "application/x-www-form-urlencoded"
192
- request = Merb::Request.new(@in)
193
- request.method.should == :put
194
- request.params[:title].should == "hello"
195
- end
196
-
197
- it "should understand DELETE if passed as _method in query string for RESTful form dispatch" do
198
- @in.post_body = "title=hello"
199
- @in['QUERY_STRING'] = '_method=delete'
200
- @in['REQUEST_METHOD'] = 'POST'
201
- @in['CONTENT_TYPE'] = "application/x-www-form-urlencoded"
202
- request = Merb::Request.new(@in)
203
- request.method.should == :delete
204
- request.params[:title].should == "hello"
205
- end
206
-
207
- it "should understand PUT if passed as _method in request body for RESTful form dispatch" do
208
- @in.post_body = "_method=put&title=hello"
209
- @in['REQUEST_METHOD'] = 'POST'
210
- @in['CONTENT_TYPE'] = "application/x-www-form-urlencoded"
211
- request = Merb::Request.new(@in)
212
- request.method.should == :put
213
- request.params[:title].should == "hello"
214
- end
215
-
216
- it "should understand DELETE if passed as _method in request body for RESTful form dispatch" do
217
- @in.post_body = "_method=delete&title=hello"
218
- @in['REQUEST_METHOD'] = 'POST'
219
- @in['CONTENT_TYPE'] = "application/x-www-form-urlencoded"
220
- request = Merb::Request.new(@in)
221
- request.env['REQUEST_METHOD'].should == 'POST'
222
- request.method.should == :delete
223
- request.params[:title].should == "hello"
224
- end
225
-
226
- it "should not raise a NotFound exception when the controller class exists" do
227
- @in['REQUEST_URI'] = "/good_posts/show/1"
228
- @in['REQUEST_METHOD'] = 'GET'
229
- @in['CONTENT_TYPE'] = "application/x-www-form-urlencoded"
230
- request = Merb::Request.new(@in)
231
- request.stubs(:controller_name).returns("good_posts")
232
- lambda { request.controller_class }.should_not raise_error(Merb::ControllerExceptions::NotFound)
233
- end
234
-
235
- it "should raise a NotFound exception when the controller does not exist" do
236
- @in['REQUEST_URI'] = "/bad_posts/show/1"
237
- @in['REQUEST_METHOD'] = 'GET'
238
- @in['CONTENT_TYPE'] = "application/x-www-form-urlencoded"
239
- request = Merb::Request.new(@in)
240
- request.stubs(:controller_name).returns("bad_posts")
241
- lambda { request.controller_class }.should raise_error(Merb::ControllerExceptions::NotFound)
242
- end
243
-
244
- it "should set accept to '*/*' when HTTP_ACCEPT is blank" do
245
- @in['HTTP_ACCEPT'] = ""
246
- request = Merb::Request.new(@in)
247
- request.accept.should == "*/*"
248
- end
249
-
250
- it "should set accept to '*/*' when HTTP_ACCEPT is empty" do
251
- @in['HTTP_ACCEPT'] = nil
252
- request = Merb::Request.new(@in)
253
- request.accept.should == "*/*"
254
- end
255
-
256
- it "should set accept to '*/*' when HTTP_ACCEPT is not set" do
257
- @in.env.delete('HTTP_ACCEPT')
258
- request = Merb::Request.new(@in)
259
- request.accept.should == "*/*"
260
- end
261
-
262
- it "should be able to tell you the HTTP method for POST requests without an error" do
263
- @in['REQUEST_METHOD'] = 'POST'
264
- request = Merb::Request.new(@in)
265
- lambda {request.method}.should_not raise_error
266
- request.method.should == :post
267
- end
268
-
269
- it "should be able to tell you the HTTP method for GET requests without an error" do
270
- @in['REQUEST_METHOD'] = 'GET'
271
- request = Merb::Request.new(@in)
272
- lambda {request.method}.should_not raise_error
273
- request.method.should == :get
274
- end
275
-
276
-
277
- it "multipart_params should return an empty hash if the request is not multipart" do
278
- request = Merb::Request.new(@in)
279
- request.send(:multipart_params).should == {}
280
- end
281
-
282
- it "should add namespace to controller name" do
283
- request = Merb::Request.new(@in)
284
- request.stubs(:route_params).returns({:controller => 'bar', :namespace => 'foo'})
285
- request.controller_name.should == "foo/bar"
286
- end
287
- end
@@ -1,562 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
-
3
- module ResponderSpecModule
4
- def new_mime(entry,index)
5
- Merb::ResponderMixin::Rest::AcceptType.new(entry,index)
6
- end
7
- end
8
-
9
- describe "The Merb Module" do
10
-
11
- after do
12
- Merb.reset_default_mime_types!
13
- end
14
-
15
- it "should respond to add_mime_type" do
16
- Merb.should respond_to(:add_mime_type)
17
- end
18
- it "should respond to remove_mime_type" do
19
- Merb.should respond_to(:remove_mime_type)
20
- end
21
- it "should respond to available_mime_types" do
22
- Merb.should respond_to(:available_mime_types)
23
- end
24
- it "should respond to outgoing_headers" do
25
- Merb.should respond_to(:response_headers)
26
- end
27
- it "should respond to add_outgoing_headers!" do
28
- Merb.should respond_to(:add_response_headers!)
29
- end
30
- it "should respond to remove_outgoing_headers!" do
31
- Merb.should respond_to(:remove_response_headers!)
32
- end
33
-
34
- it "should give access to the available_mime_types" do
35
- Merb.available_mime_types.should equal(Merb::ResponderMixin::Rest::TYPES)
36
- end
37
-
38
- it "should add a mime type to the TYPES array" do
39
- Merb::ResponderMixin::Rest::TYPES.has_key?(:png).should be_false
40
- Merb.add_mime_type(:png, :to_png, %w[image/png])
41
- Merb::ResponderMixin::Rest::TYPES.has_key?(:png).should be_true
42
- end
43
- it "should only accept Symbols for add_mime_type's key argument" do
44
- lambda{
45
- Merb.add_mime_type('silly string', %w[string/silly])
46
- }.should raise_error(ArgumentError)
47
- end
48
- it "should only accept an Array for add_mime_type's values argument" do
49
- lambda{Merb.add_mime_type(:key, :to_key, 'Congos')}.should raise_error(ArgumentError)
50
- end
51
- it "should remove a mime type from the TYPES array" do
52
- Merb.add_mime_type(:png, :to_png, %w[image/png])
53
- Merb::ResponderMixin::Rest::TYPES.has_key?(:png).should be_true
54
- Merb.remove_mime_type(:png)
55
- Merb::ResponderMixin::Rest::TYPES.has_key?(:png).should be_false
56
- end
57
- it "should not allow removal of the special :all mime-type" do
58
- Merb.remove_mime_type(:all).should be_false
59
- Merb::ResponderMixin::Rest::TYPES.has_key?(:all).should be_true
60
- end
61
-
62
- it "should add a mime type with outgoing headers defined" do
63
- Merb.available_mime_types.should_not have_key(:pdf)
64
- Merb.response_headers.should_not have_key?(:pdf)
65
- Merb.mime_transform_method(:pdf).should be_nil
66
- Merb.add_mime_type(:pdf, :to_pdf, %w[application/pdf],{"Content-Encoding" => "gzip"})
67
- Merb.available_mime_types.should have_key(:pdf)
68
- Merb.available_mime_types[:pdf].should == %w[application/pdf]
69
- Merb.response_headers.should have_key(:pdf)
70
- Merb.response_headers[:pdf].should == { "Content-Encoding" => "gzip" }
71
- Merb.mime_transform_method(:pdf).should == :to_pdf
72
- end
73
-
74
- it "should add an outgoing header for an existing mime type" do
75
- Merb.response_headers[:html].should be_empty
76
- Merb.add_response_headers!(:html,{:header => "content"})
77
- Merb.response_headers[:html].should == {:header => "content"}
78
- end
79
-
80
- it "should set the transform for the default html to nil" do
81
- Merb.available_mime_types.should have_key(:html)
82
- Merb.mime_transform_method(:html).should be_nil
83
-
84
- end
85
-
86
- it "should set xml to default to :Encoding => 'UTF-8'" do
87
- Merb.response_headers[:xml].should == {:Encoding => "UTF-8"}
88
- end
89
-
90
- it "should set the xml transform method to :to_xml" do
91
- Merb.mime_transform_method(:xml).should == :to_xml
92
- end
93
-
94
- it "should set the :js transform method to :to_json" do
95
- Merb.mime_transform_method(:js).should == :to_json
96
- end
97
-
98
- it "should replace any and all existing headers on an existing mime type" do
99
- header = {:header => "content"}
100
- Merb.response_headers[:xml].should_not be_empty
101
- Merb.response_headers[:xml].should_not == header
102
- Merb.add_response_headers!(:xml, header)
103
- Merb.response_headers[:xml].should == header
104
- end
105
-
106
- it "the specs should not alter the outgoing headers between specs" do
107
- Merb.response_headers[:xml].should == {:Encoding => "UTF-8"}
108
- end
109
-
110
- it "should remove all existing headers for a given mime type" do
111
- Merb.response_headers[:xml].should_not be_empty
112
- Merb.remove_response_headers!(:xml)
113
- Merb.response_headers[:xml].should be_empty
114
- end
115
- end
116
-
117
- describe "A Merb Responder's AcceptType" do
118
- include ResponderSpecModule
119
-
120
- before :each do
121
- @app_xhtml = new_mime('application/xhtml+xml',1)
122
- @text_html = new_mime('text/html',5)
123
- @app_html = new_mime('application/html;q=0.9',9)
124
- end
125
-
126
- it "should initialize properly from mime description and index" do
127
- acc_entry = new_mime(' application/html ; q=0.9 ',1)
128
- acc_entry.media_range.should == 'application/html'
129
- acc_entry.quality.should == 90
130
- acc_entry.index.should == 1
131
- acc_entry.synonyms.should ==
132
- %w[text/html application/xhtml+xml application/html]
133
- acc_entry.super_range.should == 'text/html'
134
- acc_entry.to_s.should == acc_entry.media_range
135
- end
136
-
137
- it "should assign lowest quality to */* unless otherwise specified" do
138
- new_mime('*/*',1).quality.should == 0
139
- new_mime('*/*;q=1.0',1).quality.should == 100
140
- new_mime('*/*;q=0.2',1).quality.should == 20
141
- end
142
-
143
- it "should be equal to another AcceptType in the same synonym group" do
144
- @text_html.should == @app_html
145
- @text_html.should eql(@app_html)
146
- @text_html.hash.should == @app_html.hash
147
- end
148
-
149
- it "should share a super range with an AcceptType in the same synonym group" do
150
- @text_html.synonyms.should == @app_html.synonyms
151
- @text_html.super_range.should == @app_html.super_range
152
- end
153
-
154
- it "should parse type and subtype" do
155
- @app_xhtml.type.should == 'application'
156
- @app_xhtml.sub_type.should == 'xhtml+xml'
157
- @text_html.type.should == 'text'
158
- @text_html.sub_type.should == 'html'
159
- @app_html.type.should == 'application'
160
- @app_html.sub_type.should == 'html'
161
- end
162
-
163
- end
164
-
165
- describe "A Merb Responder's parsing of an Accept header" do
166
-
167
- setup do
168
- @acc_hdr = "text/xml,application/xml,application/xhtml+xml," \
169
- "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"
170
- end
171
-
172
- it "should parse accept header string to Array of AcceptType instances" do
173
- acc_hdr = Merb::ResponderMixin::Rest::Responder.parse(@acc_hdr)
174
- acc_hdr.should be_kind_of(Array)
175
- acc_hdr.all?{|e| e.kind_of?(Merb::ResponderMixin::Rest::AcceptType) }.should be_true
176
- end
177
-
178
- it "should parse single entry accept headers" do
179
- acc_hdr = Merb::ResponderMixin::Rest::Responder.parse('application/xml')
180
- acc_hdr.should be_kind_of(Array)
181
- acc_hdr.all?{|e| e.kind_of?(Merb::ResponderMixin::Rest::AcceptType) }.should be_true
182
- end
183
-
184
- it "should parse accept header into proper number of AcceptType instances" do
185
- acc_hdr = 'foo/bar,baz/quuz,chimi/changa,cobra/khai'
186
- acc_hdr = Merb::ResponderMixin::Rest::Responder.parse(acc_hdr)
187
- acc_hdr.size.should == 4
188
- end
189
-
190
- it "should only return unique AcceptType instances" do
191
- acc_hdr = 'text/html,application/xhtml+xml,application/html,text/xml,' \
192
- 'application/xml,application/x-xml'
193
- acc_hdr = Merb::ResponderMixin::Rest::Responder.parse(acc_hdr)
194
- acc_hdr.size.should == 2
195
- end
196
-
197
- it "should sort AcceptType instances by quality" do
198
- acc_hdr = 'foo/bar;q=0.1,donny/darko;q=0.9,tango/cash,water/melon;q=0.5'
199
- acc_hdr = Merb::ResponderMixin::Rest::Responder.parse(acc_hdr)
200
- acc_hdr.map!{|hdr| hdr.super_range }.should ==
201
- %w[tango/cash donny/darko water/melon foo/bar]
202
- end
203
-
204
- it "should sort AcceptType instances by order" do
205
- acc_hdr = 'foo/bar,baz/quuz,chimi/changa,cobra/khai'
206
- acc_hdr = Merb::ResponderMixin::Rest::Responder.parse(acc_hdr)
207
- acc_hdr.map!{|hdr| hdr.super_range }.should ==
208
- %w[foo/bar baz/quuz chimi/changa cobra/khai]
209
- end
210
-
211
- it "should prefer alternate xml forms (foo+xml) over application/xml" do
212
- acc_hdr = Merb::ResponderMixin::Rest::Responder.parse(@acc_hdr)
213
- acc_hdr.first.super_range.should == 'text/html'
214
- end
215
-
216
- it "should sort AcceptType instances by quality and order" do
217
- acc_hdr = Merb::ResponderMixin::Rest::Responder.parse(@acc_hdr)
218
- acc_hdr.map!{|hdr| hdr.super_range }.should ==
219
- %w[text/html application/xml image/png text/plain */*]
220
- end
221
-
222
- end
223
-
224
-
225
- class ResponderSpecController < Merb::Controller
226
- def index
227
- only_provides :html, :xml, :yaml
228
- content_type.to_s
229
- end
230
-
231
- def create
232
- only_provides :xml
233
- render :nothing => 201
234
- end
235
- end
236
-
237
- class CrazyResponderSpecController < Merb::Controller
238
- def index
239
- only_provides :donkey
240
- content_type
241
- "donkey"
242
- end
243
- end
244
-
245
- Merb::BootLoader.load_action_arguments
246
- Merb::BootLoader.load_controller_template_path_cache
247
- Merb::BootLoader.load_inline_helpers
248
-
249
- describe "A Merb Responder's Content Negotiation" do
250
-
251
- it "should set Content-Type by :format for supported type: xml" do
252
- c = new_responder_spec_controller(:format => 'xml')
253
- c.dispatch(:index)
254
- c.status.should == 200
255
- c.headers['Content-Type'].should == 'application/xml'
256
- end
257
-
258
- it "should set Content-Type by :format for supported type: yaml" do
259
- c = new_responder_spec_controller(:format => 'yaml')
260
- c.dispatch(:index)
261
- c.status.should == 200
262
- c.headers['Content-Type'].should == 'application/x-yaml'
263
- end
264
-
265
- it "should set Content-Type by :format for supported type: html" do
266
- c = new_responder_spec_controller(:format => 'html')
267
- c.dispatch(:index)
268
- c.status.should == 200
269
- c.headers['Content-Type'].should == 'text/html'
270
- end
271
-
272
- it "should set Content-Type by accept header for supported type: xml" do
273
- c = new_responder_spec_controller(:http_accept => 'text/xml')
274
- c.dispatch(:index)
275
- c.status.should == 200
276
- c.headers['Content-Type'].should == 'application/xml'
277
- end
278
-
279
- it "should set Content-Type by accept header for supported type: yaml" do
280
- c = new_responder_spec_controller(:http_accept => 'text/yaml')
281
- c.dispatch(:index)
282
- c.status.should == 200
283
- c.headers['Content-Type'].should == 'application/x-yaml'
284
- end
285
-
286
- it "should set Content-Type by accept header for supported type: html" do
287
- c = new_responder_spec_controller(:http_accept => 'text/html')
288
- c.dispatch(:index)
289
- c.status.should == 200
290
- c.headers['Content-Type'].should == 'text/html'
291
- end
292
-
293
- it "should set Content-Type by :format in preference to accept headers when both are of a supported response type" do
294
- c = new_responder_spec_controller(:http_accept => 'text/plain', :format => 'yaml')
295
- c.dispatch(:index)
296
- c.status.should == 200
297
- c.headers['Content-Type'].should == 'application/x-yaml'
298
- end
299
-
300
- it "should set status 406 when format is of an unsupported response type" do
301
- c = new_responder_spec_controller(:format => 'fromage')
302
- lambda{c.dispatch(:index)}.should raise_error(Merb::ControllerExceptions::NotAcceptable)
303
- end
304
-
305
- it "should set status 406 when no accept header is of a unsupported response type" do
306
- c = new_responder_spec_controller(:http_accept => 'stale/crackers;q=0.7,camel/milk;q=1.0')
307
- lambda{c.dispatch(:index)}.should raise_error(Merb::ControllerExceptions::NotAcceptable)
308
- end
309
-
310
- it "should raise 406 when negotiated type is not in TYPES" do
311
- r = Merb::Test::FakeRequest.new
312
- c = CrazyResponderSpecController.build(r, r.body)
313
- lambda{c.dispatch(:index)}.should raise_error(Merb::ControllerExceptions::NotAcceptable)
314
- end
315
-
316
- it "should call the block for the supported response type yaml" do
317
- c = new_responder_spec_controller(:http_accept => 'text/yaml')
318
- c.dispatch(:index)
319
- c.body.should == "yaml"
320
- end
321
-
322
- it "should call the block for the supported response type xml" do
323
- c = new_responder_spec_controller(:http_accept => 'text/xml')
324
- c.dispatch(:index)
325
- c.body.should == "xml"
326
- end
327
-
328
- it "should call the block for the supported response type html" do
329
- c = new_responder_spec_controller(:http_accept => 'text/html')
330
- c.dispatch(:index)
331
- c.body.should == "html"
332
- end
333
-
334
- it "should utilise format in preference to accept header" do
335
- c = new_responder_spec_controller(:http_accept => 'text/html', :format => 'xml')
336
- c.dispatch(:index)
337
- c.status.should == 200
338
- c.headers['Content-Type'].should == 'application/xml'
339
- end
340
-
341
- it "should respond to the */* catchall accept header" do
342
- c = new_responder_spec_controller(:http_accept => '*/*')
343
- c.dispatch(:index)
344
- c.status.should == 200
345
- c.headers['Content-Type'].should == 'text/html'
346
- end
347
-
348
- it "should honor a return :nothing => status specified in the respond_to block" do
349
- c = new_responder_spec_controller(:http_accept => 'application/xml')
350
- c.dispatch(:create)
351
- c.status.should == 201
352
- end
353
-
354
- def new_responder_spec_controller(options={})
355
- params = {:controller => 'ResponderSpecController', :action => 'index'}
356
- params.update(:format => options.delete(:format)) if options[:format]
357
-
358
- @request = Merb::Test::FakeRequest.new(options)
359
- @request.params.merge!(params)
360
- ResponderSpecController.build(@request, @request.body)
361
- end
362
- end
363
-
364
- class SimpleResponder
365
- include Merb::ResponderMixin
366
- end
367
-
368
- describe "Merb::ResponderMixin", "negotiating content_type" do
369
- before(:each) do
370
- @responder = SimpleResponder.new
371
- @responder.stub!(:provided_formats).and_return([:html, :xml])
372
- @responder.stub!(:params).and_return({:format => "html"})
373
- @request = mock("request")
374
- @request.stub!(:accept).and_return("text/html")
375
- @responder.stub!(:request).and_return(@request)
376
- end
377
-
378
- it "should have a perform_content_negotiation" do
379
- @responder.should respond_to(:perform_content_negotiation)
380
- end
381
-
382
- it "should use provided_formats when params[:format] is nil" do
383
- @responder.stub!(:params).and_return({})
384
- @responder.should_receive(:provided_formats).
385
- at_least(:once).and_return([:html])
386
- @responder.perform_content_negotiation
387
- end
388
-
389
- it "should use provided_formats when params[:format] is not nil" do
390
- @responder.should_receive(:provided_formats).
391
- at_least(:once).and_return([:html])
392
- @responder.perform_content_negotiation
393
- end
394
-
395
- it "should use params[:format] when determining content_type" do
396
- @responder.should_receive(:params).at_least(:once).
397
- and_return({:format => "html"})
398
- @responder.perform_content_negotiation
399
- end
400
-
401
- it "should use request.accept when params[:format] is nil" do
402
- @responder.stub!(:params).and_return({})
403
- @responder.should_receive(:request).once.and_return(@request)
404
- @request.should_receive(:accept).once.and_return("text/html")
405
- @responder.perform_content_negotiation
406
- end
407
-
408
- it "should not use request.accept when params[:format] is not nil" do
409
- @responder.should_receive(:request).exactly(0).times
410
- @responder.perform_content_negotiation
411
- end
412
-
413
- it "should return :html when params[:format] = :html" do
414
- @responder.perform_content_negotiation.should == :html
415
- end
416
-
417
- it "should raise NotAcceptable when params[:format] = :html but :html is not provided" do
418
- @responder.should_receive(:provided_formats).at_least(:once).
419
- and_return([:xml])
420
- lambda {@responder.perform_content_negotiation}.should raise_error(Merb::ControllerExceptions::NotAcceptable)
421
- end
422
-
423
- it "should return :xml when it is the first provided and accepts is */*" do
424
- @responder.stub!(:provided_formats).and_return([:xml, :html])
425
- @responder.stub!(:params).and_return({})
426
- @request.should_receive(:accept).once.and_return("*/*")
427
- @responder.perform_content_negotiation.should == :xml
428
- end
429
-
430
- it "should return :xml when it is the first requested" do
431
- @responder.stub!(:provided_formats).and_return([:html, :xml, :text])
432
- @responder.stub!(:params).and_return({})
433
- @request.should_receive(:accept).once.and_return("text/xml, text/html")
434
- @responder.perform_content_negotiation.should == :xml
435
- end
436
-
437
- it "should raise NotAcceptable when accepts and provides do not intersect" do
438
- @responder.stub!(:provided_formats).and_return([:html, :text])
439
- @responder.stub!(:params).and_return({})
440
- @request.should_receive(:accept).once.and_return("text/xml, text/json")
441
- lambda {@responder.perform_content_negotiation}.should raise_error(Merb::ControllerExceptions::NotAcceptable)
442
- end
443
-
444
- it "should short circuit and raise NotAcceptable when provided_formats is empty" do
445
- @responder.stub!(:provided_formats).and_return([])
446
- @responder.should_receive(:params).exactly(0).times
447
- @responder.should_receive(:request).exactly(0).times
448
- lambda {@responder.perform_content_negotiation}.should raise_error(Merb::ControllerExceptions::NotAcceptable)
449
- end
450
- end
451
-
452
- class DoubleProvides < Merb::Controller
453
- def double_provides ; provides :xml; @_content_type = :html ; provides :txt ; end
454
- end
455
-
456
- describe "Merb::ResponderMixin", "dealing with content_type variable" do
457
- it "should raise an error if provides is called after content_type has been determined" do
458
- c = new_controller("double_provides",DoubleProvides)
459
- lambda { c.double_provides }.should raise_error
460
- end
461
-
462
- it "should return false for content_type_set? when @_content_type is nil" do
463
- c = new_controller("double_provides",DoubleProvides)
464
- c.should_not be_content_type_set
465
- end
466
-
467
- it "should return true for content_type_set? when @_content_type is not nil" do
468
- c = new_controller("double_provides",DoubleProvides)
469
- c.instance_variable_set("@_content_type",:html)
470
- c.should be_content_type_set
471
- end
472
-
473
- it "should return @_content_type when content_type is called" do
474
- c = new_controller("double_provides",DoubleProvides)
475
- c.instance_variable_set("@_content_type",:html)
476
- c.content_type.should == :html
477
- end
478
-
479
- it "should allow content_type to be set directly" do
480
- c = new_controller()
481
- c.content_type=:txt
482
- c.content_type.should == :txt
483
- end
484
- end
485
-
486
- class FormattedBasic < Merb::Controller ; end
487
- class WithXml < Merb::Controller ; provides :xml ; end
488
- class XmlOnly < Merb::Controller ; only_provides :xml ; end
489
- class ProvidesNothing < Merb::Controller ; does_not_provide :html ; end
490
- class HtmlAgain < Merb::Controller ; provides :html ; end
491
-
492
- class ManyProvides < Merb::Controller
493
- provides :html, :xml, :txt
494
- def noextra ; end
495
- def extra ; provides :json, :yaml ; end
496
- end
497
-
498
- describe "Responder", "managing provided formats (class)" do
499
- it "should have the default class_provided_formats of [:html]" do
500
- c = new_controller("index",FormattedBasic)
501
- c.class_provided_formats.should == [:html]
502
- end
503
-
504
- it "should add :xml to class_provided_formats when called with provides :xml" do
505
- c = new_controller("index",WithXml)
506
- c.class_provided_formats.should == [:html, :xml]
507
- end
508
-
509
- it "should only have :xml in class_provided_formats when called with only_provides :xml" do
510
- c = new_controller("index",XmlOnly)
511
- c.class_provided_formats.should == [:xml]
512
- end
513
-
514
- it "should have an empty class_provided_formats when called with does_not_provide :html" do
515
- c = new_controller("index",ProvidesNothing)
516
- c.class_provided_formats.should == []
517
- end
518
-
519
- it "should only have :html in class_provided_formats when called with provides :html (after other controllers have set it)" do
520
- c = new_controller("index",HtmlAgain)
521
- c.class_provided_formats.should == [:html]
522
- end
523
-
524
- it "should handle multiple provides added via class method" do
525
- c = new_controller("noextra",ManyProvides)
526
- c.provided_formats.should == [:html, :xml, :txt]
527
- end
528
- end
529
-
530
- class ActionProvides < Merb::Controller
531
- def basic ; end
532
- def with_xml ; provides :xml ; end
533
- def xml_only ; only_provides :xml ; end
534
- def nothing ; does_not_provide :html ; end
535
- end
536
-
537
- describe "Responder", "managing provided formats (action)" do
538
- it "should have the default provided_formats" do
539
- c = new_controller("basic",ActionProvides)
540
- c.basic
541
- c.provided_formats.should == [:html]
542
- end
543
-
544
- it "should add :xml to provided_formats when called with provides :xml" do
545
- c = new_controller("with_xml",ActionProvides)
546
- c.with_xml
547
- c.provided_formats.should == [:html, :xml]
548
- end
549
-
550
- it "should only have :xml in provided_formats when called with only_provides :xml" do
551
- c = new_controller("xml_only",ActionProvides)
552
- c.xml_only
553
- c.provided_formats.should == [:xml]
554
- end
555
-
556
- it "should have an empty provided_formats when called with does_not_provide :html" do
557
- c = new_controller("nothing",ActionProvides)
558
- c.nothing
559
- c.provided_formats.should be_empty
560
- end
561
- end
562
-