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,900 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require 'benchmark'
3
- include Benchmark
4
-
5
- require FIXTURES / 'models/router_spec_models'
6
-
7
- # OpenStruct fails to return :method correctly,
8
- # which we require for our Request object.
9
- class SimpleRequest < OpenStruct
10
- def method
11
- @table[:method]
12
- end
13
- end
14
-
15
- def generate(*args)
16
- Merb::Router.generate *args
17
- end
18
-
19
- describe 'generate helper' do
20
- it 'should reference Merb::Router method of the same name' do
21
- Merb::Router.should_receive(:generate).with(:test)
22
- generate :test
23
- end
24
- end
25
-
26
- describe Merb::Router::CachedProc do
27
- it "should register a regular expression" do
28
- regexp = /t.*e.*s.*t/
29
- cc = Merb::Router::CachedProc.new(regexp)
30
- Merb::Router::CachedProc[cc.index].cache.should == regexp
31
- end
32
-
33
- it "should register a proc" do
34
- testproc = proc { puts 'test' }
35
- cc = Merb::Router::CachedProc.new(testproc)
36
- Merb::Router::CachedProc[cc.index].cache.should == testproc
37
- end
38
-
39
- it "should return ruby code as an evaluatable string" do
40
- testproc = proc { 'test proc' }
41
- cc = Merb::Router::CachedProc.new(testproc)
42
- "#{cc}".should == "CachedProc[#{cc.index}].cache"
43
- eval("Merb::Router::#{cc}.call").should == "test proc"
44
- end
45
- end
46
-
47
- describe Merb::Router do
48
- it "should compile to an if / elsif statement" do
49
- lambda {
50
- Merb::Router.prepare do |r|
51
- r.match('/:controller/:action').to_resources(:controller => '/admin/:controller')
52
- end
53
- Merb::Router.compiled_statement.should match(/^\s*if/m)
54
- }.should_not raise_error
55
- end
56
-
57
- it "should match against requests" do
58
- Merb::Router.prepare do |r|
59
- r.match('/:controller/:action').to_resources(:controller => '/admin/:controller')
60
- end
61
- request = Merb::Test::FakeRequest.new(:request_uri => "/test/request")
62
- result = Merb::Router.match(request, {})
63
- end
64
-
65
- it "should be able to prepend routes to the @@routes list" do
66
- r1, r2 = nil, nil
67
- Merb::Router.prepare do |r|
68
- r1 = r.match('/:controller/:action').to(:controller => '/admin/:controller')
69
- end
70
- Merb::Router.prepend do |r|
71
- r2 = r.match('/:controller/:action').to(:controller => '/admin/:controller')
72
- end
73
- Merb::Router.routes[0].should == r2
74
- Merb::Router.routes[1].should == r1
75
- end
76
-
77
- it "should be able to append routes to the @@routes list" do
78
- r1, r2 = nil, nil
79
- Merb::Router.prepare do |r|
80
- r1 = r.match('/:controller/:action').to(:controller => '/admin/:controller')
81
- end
82
- Merb::Router.append do |r|
83
- r2 = r.match('/:controller/:action').to(:controller => '/admin/:controller')
84
- end
85
- Merb::Router.routes[0].should == r1
86
- Merb::Router.routes[1].should == r2
87
- end
88
-
89
- it "should have a spec helper to match routes" do
90
- Merb::Router.prepare { |r| r.default_routes }
91
- with_route('/pages/show/1', 'GET') do |params|
92
- params[:controller].should == 'pages'
93
- params[:action].should == 'show'
94
- params[:id].should == '1'
95
- end
96
- end
97
-
98
- # it "should be fast" do
99
- # Merb::Router.prepare do |r|
100
- # r.resource :icon
101
- # r.resources :posts, :member => {:stats => [:get, :put]},
102
- # :collection => {:filter => [:get]} do |post|
103
- # post.resources :comments, :member => {:stats => [:get, :put]}
104
- # post.resource :profile
105
- # end
106
- # r.resources :as do |a|
107
- # a.resources :bs do |b|
108
- # b.resources :cs
109
- # end
110
- # end
111
- # r.match("/admin") do |admin|
112
- # admin.resources :tags
113
- # end
114
- # r.default_routes
115
- # end
116
- # request = Merb::Test::FakeRequest.new(:request_uri => "/test/request")
117
- #
118
- # bm(12) do |test|
119
- # # user system total real
120
- # # with CachedCode 4.510000 0.050000 4.560000 ( 5.244656)
121
- # # with in-place regexps 2.130000 0.030000 2.160000 ( 2.272443)
122
- # test.report("with in-place regexps") do
123
- # 20_000.times do
124
- # Merb::Router.match(request)
125
- # end
126
- # end
127
- # end
128
- # end
129
- end
130
-
131
- describe Merb::Router, "when doing route matching with a big set of example routes" do
132
- require 'set'
133
- def should_only_have_keys(hash, *keys)
134
- Set.new(hash.keys).should == Set.new(keys)
135
- end
136
-
137
- before :all do
138
- Merb::Router.prepare do |r|
139
- # A simple route match, sends "/contact" to Info#contact,
140
- # i.e. the 'contact' method inside the 'Info' controller
141
- r.match("/contact").
142
- to(:controller => "info", :action => "contact")
143
-
144
- # Use placeholders (e.g. :book_id) in the match, and they will be passed along to params
145
- r.match("/books/:book_id/:action").
146
- to(:controller => "books")
147
-
148
- # Use placeholders in the "to" results for more complicated routing, e.g. for modules
149
- r.match("/admin/:module/:controller/:action").
150
- to(:controller => ":module/:controller")
151
- r.match("/admin/:module/:controller/:action/:id").
152
- to(:controller => ":module/:controller")
153
-
154
- # Use a 'match' block to factor out repetitive 'match' parts
155
- r.match("/accounts") do |a|
156
- # The following will match "/accounts/overview" and route to Accounts#overview
157
- a.match("/overview").
158
- to(:controller => "accounts", :action => "overview")
159
- a.match("/:id/:action").
160
- to(:controller => "accounts")
161
- a.match("/:id/:action.:format").
162
- to(:controller => "accounts")
163
- end
164
-
165
- # Use a 'to' block to factor out repetitive 'to' parts
166
- r.to(:controller => "accounts") do |a|
167
- $r = a.match("/reports").
168
- to(:action => "reports") # maps to Accounts#reports
169
-
170
- a.match("/slideshow/:id").
171
- to(:action => "slideshow") # maps to Accounts#slideshow
172
- end
173
-
174
- # Use a regular expression as the path matcher. Note that you must specify the
175
- # ^ (beginning of line) and $ (end of line) boundaries if you desire them.
176
- r.match(%r{^/movies/:id/movie-[a-z][a-zA-Z\-]+$}).
177
- to(:controller => "movies", :action => "search_engine_optimizer")
178
-
179
- # Use square-bracket notation to replace param results with captures from the path
180
- r.match(%r[^/movies/(\d+)-(\d+)-(\d+)$]).
181
- to(:controller => "movies", :movie_id => "[1][2][3]", :action => "show")
182
-
183
- # Use the second optional argument of 'match' to be more specific about the request;
184
- # in this case, only accept the POST method for the /movies/create action
185
- r.match("/movies/create", :method => "post").
186
- to(:controller => "movies", :action => "create")
187
-
188
- # Use variables from the 'match' as results sent to the controller in the params hash,
189
- # e.g. :user_agent[1] will be replaced with either 'MSIE' or 'Gecko' in the following case:
190
- r.match(%r[^/movies/(.+)], :user_agent => /(MSIE|Gecko)/).
191
- to(:controller => "movies", :title => "[1]", :action => "show", :agent => ":user_agent[1]")
192
-
193
- # The 'match' method can also be called without the path string or regexp.
194
- # In this example, direct all insecure traffic to a Insecure#index
195
- r.match(:protocol => "http://").
196
- to(:controller => "insecure", :action => "index")
197
-
198
- # Use anonymous placeholders in place of the ugly-looking pattern, /([^\/.,;?]+)/
199
- r.match("/::/users/::").
200
- to(:controller => "users", :action => "[2]", :id => "[1]")
201
-
202
- # Namespace can be used to specify the module
203
- r.match('/bar').to(:controller => 'bar', :namespace => 'foo')
204
-
205
- # Namespace can be used to provide path prefix
206
- r.match('/admin').to(:namespace => 'admin') do |foo|
207
- foo.match('/foo').to(:controller => 'foo')
208
- end
209
-
210
- r.match('/foo').to(:controller => 'foo')
211
-
212
- # Putting it all together, and adding the requirement that we use an "admin" prefix on the
213
- # host (e.g. admin.mysite.com), do some interesting stuff:
214
- r.match(:host => /^admin\b/).to(:namespace => 'admin') do |admin|
215
- admin.match(%r[/([A-Z]\w+)\+([A-Z]\w+)/::]).
216
- to(:controller => "users", :action => ":path[3]",
217
- :first_name => ":path[1]", :last_name => ":path[2]")
218
- end.to(:controller => "users", :action => "default")
219
- # Note that the last line above sends all traffic in the "admin" subdomain to the
220
- # Admin::Users#default action if no other route is matched.
221
-
222
- # Create a deferred route. In this case, the decision of whether or not the route
223
- # is a match is made via the .xhr? call. Note that it's ok to put the hash in a
224
- # conditional because if the "if" statement is false, ruby returns nil (i.e. no match).
225
- r.match(%r[^/deferred]).defer_to do |request, params|
226
- { :controller => "ajax", :action => "index" } if request.xhr?
227
- end
228
-
229
- # Use the placeholders in a the deferred route
230
- r.match("/deferred/:action").defer_to do |request, params|
231
- params.merge(:controller => "deferred")
232
- end
233
- end
234
- end
235
-
236
- it "should connect '/contact' to Info#contact" do
237
- index, route = Merb::Router.match(SimpleRequest.new(:protocol => "http://", :path => '/contact'), {})
238
- route[:controller].should == "info"
239
- route[:action].should == "contact"
240
- should_only_have_keys(route, :controller, :action)
241
- end
242
-
243
- it "should use placeholders in the match and pass them along to the params" do
244
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/books/12/show'), {})
245
- route[:controller].should == "books"
246
- route[:action].should == "show"
247
- route[:book_id].should == "12"
248
- should_only_have_keys(route, :controller, :action, :book_id)
249
- end
250
-
251
- it "should allow placeholders to be used in the params to construct results from matches" do
252
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/admin/accounts/users/index'), {})
253
- route[:controller].should == "accounts/users"
254
- route[:action].should == "index"
255
- should_only_have_keys(route, :module, :controller, :action)
256
-
257
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/admin/payment/processors/edit/4'), {})
258
- route[:controller].should == "payment/processors"
259
- route[:action].should == "edit"
260
- route[:id].should == "4"
261
- should_only_have_keys(route, :module, :controller, :action, :id)
262
- end
263
-
264
- it "should allow 'match' to use a block to factor out repetitive parts, merging the path as it goes" do
265
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/accounts/overview'), {})
266
- route[:controller].should == "accounts"
267
- route[:action].should == "overview"
268
- should_only_have_keys(route, :controller, :action)
269
-
270
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/accounts/12/show.xml'), {})
271
- route[:controller].should == "accounts"
272
- route[:action].should == "show"
273
- route[:id].should == "12"
274
- route[:format].should == "xml"
275
- should_only_have_keys(route, :controller, :action, :id, :format)
276
- end
277
-
278
- it "should allow 'to' to use a block to factor out repetitive params" do
279
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/reports'), {})
280
- route[:controller].should == "accounts"
281
- route[:action].should == "reports"
282
- should_only_have_keys(route, :controller, :action)
283
-
284
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/slideshow/2'), {})
285
- route[:controller].should == "accounts"
286
- route[:action].should == "slideshow"
287
- route[:id].should == "2"
288
- should_only_have_keys(route, :controller, :action, :id)
289
- end
290
-
291
- it "should be able to use a regular expression instead of a string as the path-matcher" do
292
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/movies/5/movie-an-adventure-in-wonderland'), {})
293
- route[:controller].should == "movies"
294
- route[:action].should == "search_engine_optimizer"
295
- route[:id].should == "5"
296
- should_only_have_keys(route, :controller, :action, :id)
297
- end
298
-
299
- it "should be able to use square bracket notation to replace param results with captures from the path" do
300
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/movies/123-1-9999'), {})
301
- route[:controller].should == "movies"
302
- route[:action].should == "show"
303
- route[:movie_id].should == "12319999"
304
- should_only_have_keys(route, :controller, :action, :movie_id)
305
- end
306
-
307
- it "should only allow the POST method to '/movies/create'" do
308
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/movies/create', :method => "get"), {})
309
- route[:controller].should be_nil
310
- route[:action].should be_nil
311
- should_only_have_keys(route)
312
-
313
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/movies/create', :method => "post"), {})
314
- route[:controller].should == "movies"
315
- route[:action].should == "create"
316
- should_only_have_keys(route, :controller, :action)
317
- end
318
-
319
- it "should use variables from the 'match' as a result sent to the controller in the params hash" do
320
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/movies/harry-potter-3', :user_agent => "Internet Explorer (MSIE)"), {})
321
- route[:controller].should == "movies"
322
- route[:action].should == "show"
323
- route[:title].should == "harry-potter-3"
324
- route[:agent].should == "MSIE"
325
- should_only_have_keys(route, :controller, :action, :title, :agent)
326
- end
327
-
328
- it "should be able to match without the use of a path, sending all HTTP traffic to 'insecure' controller" do
329
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/visit', :protocol => "http://"), {})
330
- route[:controller].should == "insecure"
331
- route[:action].should == "index"
332
- should_only_have_keys(route, :controller, :action)
333
-
334
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/3/users/show', :protocol => "http://"), {})
335
- route[:controller].should == "insecure"
336
- route[:action].should == "index"
337
- should_only_have_keys(route, :controller, :action)
338
- end
339
-
340
- it "should use anonymous placeholders" do
341
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/5/users/show', :protocol => "https://"), {})
342
- route[:controller].should == "users"
343
- route[:action].should == "show"
344
- route[:id].should == "5"
345
- should_only_have_keys(route, :controller, :action, :id)
346
- end
347
-
348
- it "should use namespace" do
349
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/bar', :method => :get), {})
350
- route[:namespace].should == 'foo'
351
- route[:controller].should == 'bar'
352
- route[:action].should == 'index'
353
- should_only_have_keys(route, :namespace, :controller, :action)
354
- end
355
-
356
- it "should have namespace 'admin' if path is '/admin/foo'" do
357
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/admin/foo', :method => :get), {})
358
- route[:namespace].should == 'admin'
359
- route[:controller].should == 'foo'
360
- route[:action].should == 'index'
361
- should_only_have_keys(route, :namespace, :controller, :action)
362
- end
363
-
364
- it "should not have namespace if path is just '/foo'" do
365
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/foo', :method => :get), {})
366
- route[:controller].should == 'foo'
367
- route[:action].should == 'index'
368
- should_only_have_keys(route, :controller, :action)
369
- end
370
-
371
- it "should send all admin.* domains to the 'admin/users' controller, and 'default' action" do
372
- index, route = Merb::Router.match(SimpleRequest.new(:host => "admin.mysite.com", :path => '/welcome', :protocol => "https://"), {})
373
- route[:namespace].should == "admin"
374
- route[:controller].should == "users"
375
- route[:action].should == "default"
376
- should_only_have_keys(route, :namespace, :controller, :action)
377
-
378
- index, route = Merb::Router.match(SimpleRequest.new(:host => "admin.another-site.com", :path => '/go/somewhere/else', :protocol => "https://"), {})
379
- route[:namespace].should == "admin"
380
- route[:controller].should == "users"
381
- route[:action].should == "default"
382
- should_only_have_keys(route, :namespace, :controller, :action)
383
- end
384
-
385
- it "should decipher the first-name / last-name pairs on an admin.* domain" do
386
- index, route = Merb::Router.match(SimpleRequest.new(:host => "admin.mysite.com", :path => '/Duane+Johnson/edit', :protocol => "https://"), {})
387
- route[:namespace].should == "admin"
388
- route[:controller].should == "users"
389
- route[:action].should == "edit"
390
- route[:first_name].should == "Duane"
391
- route[:last_name].should == "Johnson"
392
- should_only_have_keys(route, :namespace, :controller, :action, :first_name, :last_name)
393
- end
394
-
395
- it "should defer to the Ajax controller for xhr requests" do
396
- index, route = Merb::Router.match(SimpleRequest.new(:xhr? => true, :path => '/deferred/to/somewhere', :protocol => "https://"), {})
397
- route[:controller].should == "ajax"
398
- route[:action].should == "index"
399
- should_only_have_keys(route, :controller, :action)
400
- end
401
-
402
- it "should let a deferred block use the path's MatchData" do
403
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/deferred/elsewhere', :protocol => "https://"), {})
404
- route[:controller].should == "deferred"
405
- route[:action].should == "elsewhere"
406
- should_only_have_keys(route, :controller, :action)
407
- end
408
- end
409
-
410
- describe Merb::Router, "with a single resource, 'blogposts' with 'comments'" do
411
- before :each do
412
- Merb::Router.prepare do |r|
413
- r.resources :blogposts do |b|
414
- b.resources :comments
415
- end
416
- end
417
- end
418
-
419
- it "should match /blogposts" do
420
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts', :method => :get), {})
421
- route[:controller].should == 'blogposts'
422
- route[:action].should == 'index'
423
-
424
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts', :method => :post), {})
425
- route[:controller].should == 'blogposts'
426
- route[:action].should == 'create'
427
- end
428
-
429
- it "should match /blogposts/new" do
430
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts/new', :method => :get), {})
431
- route[:controller].should == 'blogposts'
432
- route[:action].should == 'new'
433
- end
434
-
435
- it "should match /blogposts/1" do
436
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts/1', :method => :get), {})
437
- route[:controller].should == 'blogposts'
438
- route[:action].should == 'show'
439
- route[:id].should == '1'
440
-
441
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts/1', :method => :put), {})
442
- route[:controller].should == 'blogposts'
443
- route[:action].should == 'update'
444
- route[:id].should == '1'
445
-
446
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts/1', :method => :delete), {})
447
- route[:controller].should == 'blogposts'
448
- route[:action].should == 'destroy'
449
- route[:id].should == '1'
450
- end
451
-
452
- it "should match /blogposts/1;edit" do
453
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts/1;edit', :method => :get), {})
454
- route[:controller].should == 'blogposts'
455
- route[:action].should == 'edit'
456
- route[:id].should == '1'
457
-
458
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts/1;edit', :method => :put), {})
459
- route[:controller].should be_nil
460
- route[:action].should be_nil
461
- end
462
-
463
- it "should match /blogposts/1/edit" do
464
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts/1/edit', :method => :get), {})
465
- route[:controller].should == 'blogposts'
466
- route[:action].should == 'edit'
467
- route[:id].should == '1'
468
-
469
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/blogposts/1/edit', :method => :put), {})
470
- route[:controller].should be_nil
471
- route[:action].should be_nil
472
- end
473
-
474
- it "should generate blogposts path" do
475
- generate(:blogposts).should == '/blogposts'
476
- end
477
-
478
- it "should generate blogpost path" do
479
- generate(:blogpost, :id => 1).should == '/blogposts/1'
480
- b = Blogposts.new
481
- generate(:blogpost, b).should == '/blogposts/42'
482
- generate(:blogpost, :id => b).should == '/blogposts/42'
483
- end
484
-
485
- it "should generate new_blogpost path" do
486
- generate(:new_blogpost).should == '/blogposts/new'
487
- end
488
-
489
- it "should generate edit_blogpost path" do
490
- generate(:edit_blogpost, {:id => 1}).should == '/blogposts/1/edit'
491
- end
492
-
493
- it "should generate comments path" do
494
- c = Comment.new
495
- generate(:comments, c).should == '/blogposts/42/comments'
496
- end
497
-
498
- it "should generate comment path" do
499
- c = Comment.new
500
- generate(:comment, c).should == '/blogposts/42/comments/24'
501
- end
502
- end
503
-
504
-
505
- describe Merb::Router, "with resources using name_prefix, 'oranges' and 'ape'" do
506
- before :each do
507
- Merb::Router.prepare do |r|
508
- r.resources :oranges, :name_prefix => "florida_"
509
- r.resource :ape, :name_prefix => "grape_"
510
- end
511
- end
512
-
513
- it "should match /oranges" do
514
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/oranges', :method => :get), {})
515
- route[:controller].should == 'oranges'
516
- route[:action].should == 'index'
517
- end
518
-
519
- it "should generate florida_oranges path" do
520
- generate(:florida_oranges).should == '/oranges'
521
- end
522
-
523
- it "should generate florida_orange path" do
524
- generate(:florida_orange, :id => 1).should == '/oranges/1'
525
- b = Blogposts.new
526
- generate(:florida_orange, b).should == '/oranges/42'
527
- generate(:florida_orange, :id => b).should == '/oranges/42'
528
- end
529
-
530
- it "should generate new_florida_orange path" do
531
- generate(:new_florida_orange).should == '/oranges/new'
532
- end
533
-
534
- it "should generate edit_florida_orange path" do
535
- generate(:edit_florida_orange, {:id => 1}).should == '/oranges/1/edit'
536
- end
537
-
538
- it "should match /ape" do
539
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/ape', :method => :get), {})
540
- route[:controller].should == 'ape'
541
- route[:action].should == 'show'
542
- end
543
-
544
- it "should generate grape_ape path" do
545
- generate(:grape_ape).should == '/ape'
546
- end
547
-
548
- it "should generate new_grape_ape path" do
549
- generate(:new_grape_ape).should == '/ape/new'
550
- end
551
-
552
- it "should generate edit_grape_ape path" do
553
- generate(:edit_grape_ape).should == '/ape/edit'
554
- end
555
- end
556
-
557
- describe Merb::Router, "with resources using a collection action" do
558
- before :each do
559
- Merb::Router.prepare do |r|
560
- r.resources :flowers, :collection => { :random => [:get] }
561
- end
562
- end
563
-
564
- it "should generate random_flowers path" do
565
- generate(:random_flowers).should == '/flowers/random'
566
- end
567
-
568
- it "should match GET to /flowers/random" do
569
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/flowers/random', :method => :get), {})
570
- route[:controller].should == 'flowers'
571
- route[:action].should == 'random'
572
- end
573
-
574
- it "should match GET to /flowers/random.xml" do
575
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/flowers/random.xml', :method => :get), {})
576
- route[:controller].should == 'flowers'
577
- route[:action].should == 'random'
578
- route[:format].should == 'xml'
579
- end
580
-
581
- end
582
-
583
- describe Merb::Router, "with resources using a member action { :pick => [:get] }" do
584
- before :each do
585
- Merb::Router.prepare do |r|
586
- r.resources :flowers, :member => { :pick => [:get] }
587
- end
588
- end
589
-
590
- it 'should generate pick_flower path' do
591
- generate(:pick_flower, :id => 1).should == '/flowers/1/pick'
592
- end
593
-
594
- it "should match GET to /flowers/2/pick" do
595
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/flowers/2/pick', :method => :get), {})
596
- route[:controller].should == 'flowers'
597
- route[:action].should == 'pick'
598
- route[:id].should == '2'
599
- end
600
-
601
- it "should not match POST to /flowers/2/pick" do
602
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/flowers/2/pick', :method => :post), {})
603
- route[:controller].should_not == 'flowers'
604
- route[:action].should_not == 'pick'
605
- route[:id].should_not == '2'
606
- end
607
-
608
- it "should not match PUT to /flowers/2/pick" do
609
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/flowers/2/pick', :method => :put), {})
610
- route[:controller].should_not == 'flowers'
611
- route[:action].should_not == 'pick'
612
- route[:id].should_not == '2'
613
- end
614
-
615
- it "should not match DELETE to /flowers/2/pick" do
616
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/flowers/2/pick', :method => :delete), {})
617
- route[:controller].should_not == 'flowers'
618
- route[:action].should_not == 'pick'
619
- route[:id].should_not == '2'
620
- end
621
-
622
- it "should match GET to /flowers/2/pick.xml" do
623
- index, route = Merb::Router.match(SimpleRequest.new(:path => '/flowers/2/pick.xml', :method => :get), {})
624
- route[:controller].should == 'flowers'
625
- route[:action].should == 'pick'
626
- route[:id].should == '2'
627
- route[:format].should == 'xml'
628
- end
629
-
630
- end
631
-
632
- describe Merb::Router::Behavior do
633
- before :all do
634
- @behavior = Merb::Router::Behavior
635
- end
636
-
637
- it "should leave strings as strings and add ^...$ in the @conditions hash" do
638
- @behavior.new(:path => '/one/two').conditions[:path].should == '^/one/two$'
639
- end
640
-
641
- it "should replace special characters in strings with their escaped equivalents" do
642
- @behavior.new(:path => 'test.xml').conditions[:path].should == '^test\\.xml$'
643
- end
644
-
645
- it "should convert symbols to strings and add ^...$ in the @conditions hash" do
646
- @behavior.new(:method => :get).conditions[:method].should == '^get$'
647
- end
648
-
649
- it "should convert regular expressions to strings in the @conditions hash" do
650
- @behavior.new(:protocol => /https?/).conditions[:protocol].should == 'https?'
651
- end
652
-
653
- it "should deduce placeholders from the @conditions hash" do
654
- ph = @behavior.new(:path => '/:controller/:action').placeholders
655
- ph[:controller].should == [:path, 1]
656
- ph[:action].should == [:path, 2]
657
- end
658
-
659
- it "should deduce placeholders from the @conditions hash, even when they contain numbers" do
660
- ph = @behavior.new({:path => "/:part1/:part2"}).placeholders
661
- ph[:part1].should == [:path, 1]
662
- ph[:part2].should == [:path, 2]
663
- end
664
-
665
- it "should deduce placeholders within regular expressions that contain prefixed captures" do
666
- ph = @behavior.new(:path => %r[/(\d+)/:controller/:action]).placeholders
667
- ph[:controller].should == [:path, 2]
668
- ph[:action].should == [:path, 3]
669
-
670
- ph = @behavior.new(:path => %r[/:controller/:action/(\d+)]).placeholders
671
- ph[:controller].should == [:path, 1]
672
- ph[:action].should == [:path, 2]
673
- end
674
-
675
- it "should deduce placeholder positions in nested captures" do
676
- ph = @behavior.new(:path => %r[(/(\d+)/:controller)/:action]).placeholders
677
- ph[:controller].should == [:path, 3]
678
- ph[:action].should == [:path, 4]
679
-
680
- ph = @behavior.new(:path => %r[/(\d+)/(:controller)/:action]).placeholders
681
- ph[:controller].should == [:path, 3]
682
- ph[:action].should == [:path, 4]
683
-
684
- ph = @behavior.new(:path => %r[/(\d+)/:controller/(:action)]).placeholders
685
- ph[:controller].should == [:path, 2]
686
- ph[:action].should == [:path, 4]
687
-
688
- ph = @behavior.new(:path => %r[(/(\d+)/(:controller/((:action))))]).placeholders
689
- ph[:controller].should == [:path, 4]
690
- ph[:action].should == [:path, 7]
691
- end
692
-
693
- it "should replace any placeholders found within @conditions strings with segment regular expressions" do
694
- m = @behavior.new(:path => "/:my/:place:holders/:here").conditions
695
- m[:path].should == "^/([^/.,;?]+)/([^/.,;?]+)([^/.,;?]+)/([^/.,;?]+)$"
696
- end
697
-
698
- it "should set default values for params that came from placeholders" do
699
- p = @behavior.new(:path => "/:my/:place:holders/:here").params
700
- p[:my].should == ":my"
701
- p[:place].should == ":place"
702
- p[:holders].should == ":holders"
703
- p[:here].should == ":here"
704
- end
705
-
706
- it "should merge params with its ancestors" do
707
- b = @behavior.new({}, { :controller => "my_controller", :action => "index" })
708
- c = @behavior.new({}, { :action => "show" }, b)
709
- c.merged_params.should == { :controller => "my_controller", :action => "show" }
710
- end
711
-
712
- # it "should have a default action and controller for merged params" do
713
- # a = @behavior.new
714
- # a.merged_params.should == {:controller => "application", :action => "index"}
715
- #
716
- # b = @behavior.new({}, {:controller => "admin"})
717
- # b.merged_params.should == {:controller => "admin", :action => "index"}
718
- #
719
- # c = @behavior.new({}, {:action => "show"})
720
- # c.merged_params.should == {:controller => "application", :action => "show"}
721
- # end
722
-
723
- it "should merge conditions with its ancestors" do
724
- b = @behavior.new({ :method => "get", :protocol => "http" })
725
- c = @behavior.new({ :method => "put" }, {}, b)
726
- c.merged_conditions.should == { :method => "^put$", :protocol => "^http$" }
727
- end
728
-
729
- it "should merge placeholders with its ancestors" do
730
- b = @behavior.new({ :method => "get", :protocol => ":ssl" }, { :action => ":method" })
731
- c = @behavior.new({ :method => "put" }, { :action => ":ssl" }, b)
732
- c.merged_placeholders.should == { :ssl => [:protocol, 1] }
733
- end
734
-
735
- it "should add the number of path captures in the ancestors' paths to placeholders that hold a place for :path captures" do
736
- b = @behavior.new(:path => "/:controller/:action")
737
- b.placeholders.should == { :controller => [:path, 1], :action => [:path, 2] }
738
- c = @behavior.new({ :path => "/:id" }, {}, b)
739
- c.placeholders.should == { :id => [:path, 1] }
740
-
741
- c.merged_placeholders.should == { :controller => [:path, 1], :action => [:path, 2], :id => [:path, 3] }
742
- end
743
-
744
- it "should merge the :path differently than other @conditions keys -- it should concatenate" do
745
- b = @behavior.new({:method => "get", :protocol => "http"})
746
- c = @behavior.new({:path => "/test", :method => "put"}, {}, b)
747
- c.merged_conditions.should == {:method => "^put$", :protocol => "^http$", :path => "^/test$"}
748
-
749
- b = @behavior.new({:path => "/test", :method => "get", :protocol => "http"})
750
- c = @behavior.new({:method => "put"}, {}, b)
751
- c.merged_conditions.should == {:method => "^put$", :protocol => "^http$", :path => "^/test$"}
752
-
753
- b = @behavior.new({:path => "/admin", :method => "get", :protocol => "http"})
754
- c = @behavior.new({:path => "/test", :method => "put"}, {}, b)
755
- c.merged_conditions.should == {:method => "^put$", :protocol => "^http$", :path => "^/admin/test$"}
756
- end
757
-
758
- it "should be able to compile the @params to strings and request matches" do
759
- b = @behavior.new({:path => "/admin/:controller/:action", :method => "get"})
760
- cp = b.send(:compiled_params)
761
- cp[:controller].should == "path1"
762
- cp[:action].should == "path2"
763
-
764
- b = @behavior.new(
765
- {:path => "/admin/:controller/:action/:postfix", :method => "get"},
766
- {:controller => "/admin/:controller", :action => "neat_o_:action:postfix"})
767
- cp = b.send(:compiled_params)
768
- cp[:controller].should == "\"/admin/\" + path1"
769
- cp[:action].should == "\"neat_o_\" + path2 + path3"
770
- end
771
-
772
- it "should allow a bracketed number such as [3] to compile to path3" do
773
- b = @behavior.new(
774
- {:path => "/admin/:controller/:action/(.+)", :method => "get"},
775
- {:catchall => "[3]"})
776
- cp = b.send(:compiled_params)
777
- cp[:catchall].should == "path3"
778
- end
779
-
780
- it "should allow a backslash to escape an underscore in the compiled params" do
781
- b = @behavior.new(
782
- {:path => "/admin/:controller/:action", :method => "get"},
783
- {:action => "some_prefix_:action\\_other"})
784
- cp = b.send(:compiled_params)
785
- cp[:action].should == "\"some_prefix_\" + path2 + \"_other\""
786
- end
787
-
788
- it "should return a Route object containing compiled conditions and params when .to is called" do
789
- a = @behavior.new({:path => "/admin"})
790
- b = a.match("/:controller/:action", :method => "get")
791
- route = b.to(:controller => "/admin/:controller")
792
- route.conditions[:path].to_s.should == /^\/admin\/([^\/.,;?]+)\/([^\/.,;?]+)$/.to_s
793
- route.conditions[:method].should == /^get$/
794
- route.params.should == {:controller => "\"/admin/\" + path1", :action => "path2"}
795
- end
796
-
797
- it "should allow for conditional blocks using the 'defer_to' method" do
798
- b = @behavior.new(:path => '/admin')
799
- route = b.defer_to { |request| { :controller => 'late_bound', :action => 'place' } }
800
- route.conditional_block.should be_an_instance_of(Proc)
801
- route.compile.should match(/block_result/m)
802
- end
803
- end
804
-
805
- describe Merb::Router::Behavior, "class methods" do
806
- before :all do
807
- @b = Merb::Router::Behavior
808
- end
809
-
810
- it 'should count opening parentheses' do
811
- [[' ( )', 1, 1],
812
- [' ( )', 50, 1],
813
- [' (() )', 1, 1],
814
- [' (() )', 2, 2]].each do |parens,limit,expected|
815
- @b.count_parens_up_to(parens, limit).should == expected
816
- end
817
-
818
- # TODO: skip escaped open parens
819
- end
820
-
821
- it 'should concatenate strings without endcaps' do
822
- [[nil, nil, nil],
823
- [nil, '^test', '^test'],
824
- ['my$', nil, 'my$'],
825
- ['my', 'test', 'mytest'],
826
- ['my$', 'test', 'mytest'],
827
- ['my^', 'test', 'my^test'],
828
- ['my$', '^test', 'mytest'],
829
- ['^my$', '^test$', '^mytest$']].each do |str1, str2, expected|
830
- @b.concat_without_endcaps(str1, str2).should == expected
831
- end
832
- end
833
-
834
- it 'should compile arrays with strings and symbols into code' do
835
- [[[:var, 'this string'], %{var + "this string"}],
836
- [['one string'], %{"one string"}],
837
- [["string", :var, :var2, "other"], %{"string" + var + var2 + "other"}]].each do |array, expected|
838
- @b.array_to_code(array).should == expected
839
- end
840
- end
841
- end
842
-
843
- describe Merb::Router::Route, 'rendered as a string' do
844
- before :all do
845
- Merb::Router.prepare { |r| r.default_routes }
846
- @routes = Merb::Router.routes
847
- end
848
-
849
- it 'should show the default route' do
850
- @routes.last.to_s.should == "/:controller(/:action(/:id)?)?(\\.:format)?"
851
- end
852
- end
853
-
854
- describe Merb::Router, 'using namespaces' do
855
- before :each do
856
- Merb::Router.prepare do |r|
857
- r.namespace :admin do |a|
858
- a.resources :namespace_block_resources
859
- a.resource :namespace_block_resource
860
- end
861
-
862
- r.match :namespace => 'admin' do |a|
863
- a.resources :match_block_resources
864
- a.resource :match_block_resource
865
- end
866
-
867
- r.resources :namespace_option_resources, :namespace => 'admin'
868
- r.resource :namespace_option_resource, :namespace => 'admin'
869
-
870
- r.resources :resources, :namespace => 'admin'
871
- r.resource :resource, :namespace => 'admin'
872
- r.resources :resources
873
- r.resource :resource
874
-
875
- r.resources :path_namespace_resources, :namespace => 'admin/supersecret'
876
- r.resources :path_namespace_resource, :namespace => 'admin/supersecret'
877
- end
878
- end
879
-
880
- # Several ways to define a namespace. Perhaps too many?
881
- %w( namespace_block match_block namespace_option ).each do |context|
882
- %w( resources resource ).each do |r|
883
- it "defines :#{r} in a :#{context} context" do
884
- generate("admin_#{context}_#{r}").should == "/admin/#{context}_#{r}"
885
- end
886
- end
887
- end
888
-
889
- it 'defines namespaces with path fragments' do
890
- generate(:admin_supersecret_path_namespace_resources).should ==
891
- '/admin/supersecret/path_namespace_resources'
892
- end
893
-
894
- it 'allows resources of the same name in different namespaces' do
895
- %w( resources resource ).each do |r|
896
- generate("admin_#{r}").should == "/admin/#{r}"
897
- generate(r).should == "/#{r}"
898
- end
899
- end
900
- end