middleman-core 3.0.0.beta.2 → 3.0.0.beta.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. data/features/cli_extension.feature +13 -0
  2. data/features/{cli.feature → cli_init.feature} +1 -10
  3. data/features/directory_index.feature +29 -1
  4. data/features/dynamic_pages.feature +1 -0
  5. data/features/extensionless_text_files.feature +0 -2
  6. data/features/front-matter.feature +17 -1
  7. data/features/frontmatter_page_settings.feature +16 -1
  8. data/features/helpers_relative_link_to.feature +68 -0
  9. data/features/unicode_filenames.feature +14 -0
  10. data/fixtures/csspie/config.rb +0 -0
  11. data/fixtures/csspie/source/stylesheets/PIE.htc +96 -0
  12. data/fixtures/dynamic-pages-app/config.rb +3 -0
  13. data/fixtures/frontmatter-app/source/front-matter-auto.erb +6 -0
  14. data/fixtures/frontmatter-app/source/front-matter.html.erb +2 -0
  15. data/fixtures/frontmatter-app/source/json-front-matter-2.php.erb +7 -0
  16. data/fixtures/frontmatter-app/source/json-front-matter-auto.erb +6 -0
  17. data/fixtures/frontmatter-app/source/json-front-matter.html.erb +6 -0
  18. data/fixtures/unicode-filenames-app/config.rb +1 -0
  19. data/fixtures/unicode-filenames-app/source/snowmen-rule-/342/230/203.html +4 -0
  20. data/lib/middleman-core/application.rb +43 -335
  21. data/lib/middleman-core/cli/build.rb +11 -4
  22. data/lib/middleman-core/cli/bundler.rb +40 -0
  23. data/lib/middleman-core/cli/extension.rb +36 -0
  24. data/lib/middleman-core/cli/server.rb +2 -2
  25. data/lib/middleman-core/cli.rb +2 -6
  26. data/lib/middleman-core/core_extensions/assets.rb +35 -31
  27. data/lib/middleman-core/core_extensions/builder.rb +14 -9
  28. data/lib/middleman-core/core_extensions/data.rb +150 -145
  29. data/lib/middleman-core/core_extensions/default_helpers.rb +159 -97
  30. data/lib/middleman-core/core_extensions/extensions.rb +103 -97
  31. data/lib/middleman-core/core_extensions/external_helpers.rb +27 -23
  32. data/lib/middleman-core/core_extensions/file_watcher.rb +140 -110
  33. data/lib/middleman-core/core_extensions/front_matter.rb +155 -175
  34. data/lib/middleman-core/core_extensions/i18n.rb +111 -102
  35. data/lib/middleman-core/core_extensions/rendering.rb +293 -295
  36. data/lib/middleman-core/core_extensions/request.rb +338 -0
  37. data/lib/middleman-core/core_extensions/routing.rb +72 -68
  38. data/lib/middleman-core/core_extensions/show_exceptions.rb +23 -18
  39. data/lib/middleman-core/core_extensions.rb +39 -0
  40. data/lib/middleman-core/extensions/directory_indexes.rb +1 -4
  41. data/lib/middleman-core/extensions/lorem.rb +10 -3
  42. data/lib/middleman-core/extensions.rb +2 -64
  43. data/lib/middleman-core/preview_server.rb +157 -0
  44. data/lib/middleman-core/sitemap/extensions/ignores.rb +73 -68
  45. data/lib/middleman-core/sitemap/extensions/on_disk.rb +65 -58
  46. data/lib/middleman-core/sitemap/extensions/proxies.rb +86 -75
  47. data/lib/middleman-core/sitemap/extensions/traversal.rb +68 -61
  48. data/lib/middleman-core/sitemap/resource.rb +123 -102
  49. data/lib/middleman-core/sitemap/store.rb +170 -149
  50. data/lib/middleman-core/sitemap.rb +57 -57
  51. data/lib/middleman-core/step_definitions/server_steps.rb +13 -3
  52. data/lib/middleman-core/templates/extension/Gemfile +4 -0
  53. data/lib/middleman-core/templates/extension/Rakefile +12 -0
  54. data/lib/middleman-core/templates/extension/features/support/env.rb +4 -0
  55. data/lib/middleman-core/templates/extension/gemspec +24 -0
  56. data/lib/middleman-core/templates/extension/lib/lib.rb +49 -0
  57. data/lib/middleman-core/templates/extension/lib/middleman_extension.rb +1 -0
  58. data/lib/middleman-core/templates/shared/gitignore +14 -0
  59. data/lib/middleman-core/templates.rb +14 -8
  60. data/lib/middleman-core/util.rb +31 -9
  61. data/lib/middleman-core/version.rb +1 -1
  62. data/lib/middleman-core.rb +6 -4
  63. data/middleman-core.gemspec +4 -6
  64. metadata +62 -203
  65. data/lib/middleman-core/vendor/padrino-core-0.10.6/.document +0 -5
  66. data/lib/middleman-core/vendor/padrino-core-0.10.6/.gitignore +0 -22
  67. data/lib/middleman-core/vendor/padrino-core-0.10.6/.yardopts +0 -1
  68. data/lib/middleman-core/vendor/padrino-core-0.10.6/LICENSE.txt +0 -20
  69. data/lib/middleman-core/vendor/padrino-core-0.10.6/README.rdoc +0 -294
  70. data/lib/middleman-core/vendor/padrino-core-0.10.6/Rakefile +0 -5
  71. data/lib/middleman-core/vendor/padrino-core-0.10.6/bin/padrino +0 -9
  72. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/application/rendering.rb +0 -292
  73. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/application/routing.rb +0 -943
  74. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/application/showexceptions.rb +0 -20
  75. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/application.rb +0 -269
  76. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/caller.rb +0 -53
  77. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/cli/adapter.rb +0 -24
  78. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/cli/base.rb +0 -150
  79. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/cli/console.rb +0 -20
  80. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/cli/rake.rb +0 -24
  81. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/cli/rake_tasks.rb +0 -59
  82. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/command.rb +0 -38
  83. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/images/404.png +0 -0
  84. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/images/500.png +0 -0
  85. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/loader.rb +0 -211
  86. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/cs.yml +0 -34
  87. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/da.yml +0 -34
  88. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/de.yml +0 -34
  89. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/en.yml +0 -34
  90. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/es.yml +0 -34
  91. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/fr.yml +0 -34
  92. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/hu.yml +0 -34
  93. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/it.yml +0 -40
  94. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/ja.yml +0 -34
  95. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/lv.yml +0 -34
  96. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/nl.yml +0 -34
  97. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/no.yml +0 -35
  98. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/pl.yml +0 -34
  99. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/pt_br.yml +0 -40
  100. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/ru.yml +0 -35
  101. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/tr.yml +0 -34
  102. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/uk.yml +0 -34
  103. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/zh_cn.yml +0 -34
  104. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/zh_tw.yml +0 -34
  105. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/logger.rb +0 -428
  106. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/mounter.rb +0 -224
  107. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/reloader.rb +0 -254
  108. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/router.rb +0 -98
  109. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/server.rb +0 -79
  110. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/support_lite.rb +0 -199
  111. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/tasks.rb +0 -21
  112. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/version.rb +0 -20
  113. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core.rb +0 -152
  114. data/lib/middleman-core/vendor/padrino-core-0.10.6/padrino-core.gemspec +0 -38
  115. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/apps/.components +0 -6
  116. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/apps/.gitignore +0 -7
  117. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/apps/complex.rb +0 -32
  118. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/apps/simple.rb +0 -33
  119. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/a.rb +0 -9
  120. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/b.rb +0 -4
  121. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/c.rb +0 -1
  122. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/circular/e.rb +0 -13
  123. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/circular/f.rb +0 -2
  124. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/circular/g.rb +0 -2
  125. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/d.rb +0 -4
  126. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/helper.rb +0 -83
  127. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/mini_shoulda.rb +0 -45
  128. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_application.rb +0 -108
  129. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_core.rb +0 -77
  130. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_dependencies.rb +0 -44
  131. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_filters.rb +0 -278
  132. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_locale.rb +0 -21
  133. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_logger.rb +0 -154
  134. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_mounter.rb +0 -177
  135. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_reloader_complex.rb +0 -75
  136. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_reloader_simple.rb +0 -98
  137. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_rendering.rb +0 -461
  138. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_restful_routing.rb +0 -33
  139. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_router.rb +0 -146
  140. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_routing.rb +0 -1680
  141. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/.document +0 -5
  142. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/.gitignore +0 -21
  143. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/.yardopts +0 -1
  144. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/LICENSE.txt +0 -20
  145. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/README.rdoc +0 -239
  146. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/Rakefile +0 -5
  147. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/asset_tag_helpers.rb +0 -417
  148. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/form_builder/abstract_form_builder.rb +0 -251
  149. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/form_builder/standard_form_builder.rb +0 -43
  150. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/form_helpers.rb +0 -787
  151. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/format_helpers.rb +0 -381
  152. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/cs.yml +0 -103
  153. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/da.yml +0 -91
  154. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/de.yml +0 -81
  155. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/en.yml +0 -103
  156. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/es.yml +0 -103
  157. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/fr.yml +0 -80
  158. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/hu.yml +0 -103
  159. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/it.yml +0 -89
  160. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/ja.yml +0 -103
  161. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/lv.yml +0 -103
  162. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/nl.yml +0 -82
  163. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/no.yml +0 -91
  164. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/pl.yml +0 -95
  165. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/pt_br.yml +0 -103
  166. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/ru.yml +0 -103
  167. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/tr.yml +0 -103
  168. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/uk.yml +0 -103
  169. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/zh_cn.yml +0 -104
  170. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/zh_tw.yml +0 -103
  171. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/number_helpers.rb +0 -288
  172. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/output_helpers/abstract_handler.rb +0 -98
  173. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/output_helpers/erb_handler.rb +0 -79
  174. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/output_helpers/haml_handler.rb +0 -63
  175. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/output_helpers/slim_handler.rb +0 -81
  176. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/output_helpers.rb +0 -175
  177. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/render_helpers.rb +0 -60
  178. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/tag_helpers.rb +0 -260
  179. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/translation_helpers.rb +0 -38
  180. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers.rb +0 -59
  181. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/padrino-helpers.gemspec +0 -27
  182. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/app.rb +0 -73
  183. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/capture_concat.erb +0 -14
  184. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/capture_concat.haml +0 -12
  185. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/capture_concat.slim +0 -13
  186. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_for.erb +0 -14
  187. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_for.haml +0 -12
  188. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_for.slim +0 -12
  189. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_tag.erb +0 -11
  190. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_tag.haml +0 -9
  191. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_tag.slim +0 -9
  192. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/current_engine.erb +0 -5
  193. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/current_engine.haml +0 -5
  194. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/current_engine.slim +0 -5
  195. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/fields_for.erb +0 -20
  196. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/fields_for.haml +0 -15
  197. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/fields_for.slim +0 -15
  198. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_for.erb +0 -72
  199. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_for.haml +0 -59
  200. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_for.slim +0 -59
  201. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_tag.erb +0 -86
  202. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_tag.haml +0 -70
  203. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_tag.slim +0 -70
  204. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/link_to.erb +0 -5
  205. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/link_to.haml +0 -4
  206. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/link_to.slim +0 -4
  207. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/mail_to.erb +0 -3
  208. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/mail_to.haml +0 -3
  209. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/mail_to.slim +0 -3
  210. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/meta_tag.erb +0 -3
  211. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/meta_tag.haml +0 -3
  212. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/meta_tag.slim +0 -3
  213. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/partials/_erb.erb +0 -1
  214. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/partials/_haml.haml +0 -1
  215. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/partials/_slim.slim +0 -1
  216. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/simple_partial.erb +0 -1
  217. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/simple_partial.haml +0 -1
  218. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/simple_partial.slim +0 -1
  219. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/app.rb +0 -50
  220. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/current_engine.haml +0 -5
  221. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/current_engines/_erb.erb +0 -1
  222. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/current_engines/_haml.haml +0 -1
  223. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/current_engines/_slim.slim +0 -1
  224. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/erb/test.erb +0 -1
  225. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/explicit_engine.haml +0 -5
  226. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/haml/test.haml +0 -1
  227. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/template/_user.haml +0 -7
  228. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/template/haml_template.haml +0 -1
  229. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/template/some_template.haml +0 -2
  230. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/helper.rb +0 -66
  231. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_asset_tag_helpers.rb +0 -328
  232. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_form_builder.rb +0 -1106
  233. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_form_helpers.rb +0 -770
  234. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_format_helpers.rb +0 -227
  235. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_locale.rb +0 -20
  236. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_number_helpers.rb +0 -139
  237. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_output_helpers.rb +0 -153
  238. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_render_helpers.rb +0 -76
  239. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_tag_helpers.rb +0 -106
  240. data/lib/middleman-core/watcher.rb +0 -196
@@ -1,1680 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/helper')
2
-
3
- class FooError < RuntimeError; end
4
-
5
-
6
- describe "Routing" do
7
- setup do
8
- Padrino::Application.send(:register, Padrino::Rendering)
9
- Padrino::Rendering::DEFAULT_RENDERING_OPTIONS[:strict_format] = false
10
- end
11
-
12
- should "serve static files with simple cache control" do
13
- mock_app do
14
- set :static_cache_control, :public
15
- set :public_folder, File.dirname(__FILE__)
16
- end
17
- get "/#{File.basename(__FILE__)}"
18
- assert headers.has_key?('Cache-Control')
19
- assert_equal headers['Cache-Control'], 'public'
20
- end # static simple
21
-
22
- should "serve static files with cache control and max_age" do
23
- mock_app do
24
- set :static_cache_control, [:public, :must_revalidate, {:max_age => 300}]
25
- set :public_folder, File.dirname(__FILE__)
26
- end
27
- get "/#{File.basename(__FILE__)}"
28
- assert headers.has_key?('Cache-Control')
29
- assert_equal headers['Cache-Control'], 'public, must-revalidate, max-age=300'
30
- end # static max_age
31
-
32
- should 'ignore trailing delimiters for basic route' do
33
- mock_app do
34
- get("/foo"){ "okey" }
35
- get(:test) { "tester" }
36
- end
37
- get "/foo"
38
- assert_equal "okey", body
39
- get "/foo/"
40
- assert_equal "okey", body
41
- get "/test"
42
- assert_equal "tester", body
43
- get "/test/"
44
- assert_equal "tester", body
45
- end
46
-
47
- should 'fail with unrecognized route exception when not found' do
48
- mock_app do
49
- get(:index){ "okey" }
50
- end
51
- get @app.url_for(:index)
52
- assert_equal "okey", body
53
- assert_raises(Padrino::Routing::UnrecognizedException) {
54
- get @app.url_for(:fake)
55
- }
56
- end
57
-
58
- should 'accept regexp routes' do
59
- mock_app do
60
- get(%r{/fob|/baz}) { "regexp" }
61
- get("/foo") { "str" }
62
- get %r{/([0-9]+)/} do |num|
63
- "Your lucky number: #{num} #{params[:captures].first}"
64
- end
65
- get /\/page\/([0-9]+)|\// do |num|
66
- "My lucky number: #{num} #{params[:captures].first}"
67
- end
68
- end
69
- get "/foo"
70
- assert_equal "str", body
71
- get "/fob"
72
- assert_equal "regexp", body
73
- get "/baz"
74
- assert_equal "regexp", body
75
- get "/1234/"
76
- assert_equal "Your lucky number: 1234 1234", body
77
- get "/page/99"
78
- assert_equal "My lucky number: 99 99", body
79
- end
80
-
81
- should 'accept regexp routes with generate with :generate_with' do
82
- mock_app do
83
- get(%r{/fob|/baz}, :name => :foo, :generate_with => '/fob') { "regexp" }
84
- end
85
- assert_equal "/fob", @app.url(:foo)
86
- end
87
-
88
- should "parse routes with question marks" do
89
- mock_app do
90
- get("/foo/?"){ "okey" }
91
- post('/unauthenticated/?') { "no access" }
92
- end
93
- get "/foo"
94
- assert_equal "okey", body
95
- get "/foo/"
96
- assert_equal "okey", body
97
- post "/unauthenticated"
98
- assert_equal "no access", body
99
- post "/unauthenticated/"
100
- assert_equal "no access", body
101
- end
102
-
103
- should 'match correctly similar paths' do
104
- mock_app do
105
- get("/my/:foo_id"){ params[:foo_id] }
106
- get("/my/:bar_id/bar"){ params[:bar_id] }
107
- end
108
- get "/my/1"
109
- assert_equal "1", body
110
- get "/my/2/bar"
111
- assert_equal "2", body
112
- end
113
-
114
- should "match user agents" do
115
- app = mock_app do
116
- get("/main", :agent => /IE/){ "hello IE" }
117
- get("/main"){ "hello" }
118
- end
119
- get "/main"
120
- assert_equal "hello", body
121
- get "/main", {}, {'HTTP_USER_AGENT' => 'This is IE'}
122
- assert_equal "hello IE", body
123
- end
124
-
125
- should "use regex for parts of a route" do
126
- app = mock_app do
127
- get("/main/:id", :id => /\d+/){ "hello #{params[:id]}" }
128
- end
129
- get "/main/123"
130
- assert_equal "hello 123", body
131
- get "/main/asd"
132
- assert_equal 404, status
133
- end
134
-
135
- should "not generate overlapping head urls" do
136
- app = mock_app do
137
- get("/main"){ "hello" }
138
- post("/main"){ "hello" }
139
- end
140
- assert_equal 3, app.routes.size, "should generate GET, HEAD and PUT"
141
- assert_equal ["GET"], app.routes[0].conditions[:request_method]
142
- assert_equal ["HEAD"], app.routes[1].conditions[:request_method]
143
- assert_equal ["POST"], app.routes[2].conditions[:request_method]
144
- end
145
-
146
- should 'generate basic urls' do
147
- mock_app do
148
- get(:foo){ "/foo" }
149
- get(:foo, :with => :id){ |id| "/foo/#{id}" }
150
- get([:foo, :id]){ |id| "/foo/#{id}" }
151
- get(:hash, :with => :id){ url(:hash, :id => 1) }
152
- get([:hash, :id]){ url(:hash, :id => 1) }
153
- get(:array, :with => :id){ url(:array, 23) }
154
- get([:array, :id]){ url(:array, 23) }
155
- get(:hash_with_extra, :with => :id){ url(:hash_with_extra, :id => 1, :query => 'string') }
156
- get([:hash_with_extra, :id]){ url(:hash_with_extra, :id => 1, :query => 'string') }
157
- get(:array_with_extra, :with => :id){ url(:array_with_extra, 23, :query => 'string') }
158
- get([:array_with_extra, :id]){ url(:array_with_extra, 23, :query => 'string') }
159
- get("/old-bar/:id"){ params[:id] }
160
- post(:mix, :map => "/mix-bar/:id"){ params[:id] }
161
- get(:mix, :map => "/mix-bar/:id"){ params[:id] }
162
- end
163
- get "/foo"
164
- assert_equal "/foo", body
165
- get "/foo/123"
166
- assert_equal "/foo/123", body
167
- get "/hash/2"
168
- assert_equal "/hash/1", body
169
- get "/array/23"
170
- assert_equal "/array/23", body
171
- get "/hash_with_extra/1"
172
- assert_equal "/hash_with_extra/1?query=string", body
173
- get "/array_with_extra/23"
174
- assert_equal "/array_with_extra/23?query=string", body
175
- get "/old-bar/3"
176
- assert_equal "3", body
177
- post "/mix-bar/4"
178
- assert_equal "4", body
179
- get "/mix-bar/4"
180
- assert_equal "4", body
181
- end
182
-
183
- should 'generate url with format' do
184
- mock_app do
185
- get(:a, :provides => :any){ url(:a, :format => :json) }
186
- get(:b, :provides => :js){ url(:b, :format => :js) }
187
- get(:c, :provides => [:js, :json]){ url(:c, :format => :json) }
188
- get(:d, :provides => [:html, :js]){ url(:d, :format => :js, :foo => :bar) }
189
- end
190
- get "/a.js"
191
- assert_equal "/a.json", body
192
- get "/b.js"
193
- assert_equal "/b.js", body
194
- get "/b.ru"
195
- assert_equal 405, status
196
- get "/c.js"
197
- assert_equal "/c.json", body
198
- get "/c.json"
199
- assert_equal "/c.json", body
200
- get "/c.ru"
201
- assert_equal 405, status
202
- get "/d"
203
- assert_equal "/d.js?foo=bar", body
204
- get "/d.js"
205
- assert_equal "/d.js?foo=bar", body
206
- get "/e.xml"
207
- assert_equal 404, status
208
- end
209
-
210
- should 'use padrino url method' do
211
- mock_app do
212
- end
213
-
214
- assert_equal @app.method(:url).owner, Padrino::Routing::ClassMethods
215
- end
216
-
217
- should 'work correctly with sinatra redirects' do
218
- mock_app do
219
- get(:index) { redirect url(:index) }
220
- get(:google) { redirect "http://google.com" }
221
- get("/foo") { redirect "/bar" }
222
- get("/bar") { "Bar" }
223
- end
224
-
225
- get "/"
226
- assert_equal "http://example.org/", headers['Location']
227
- get "/google"
228
- assert_equal "http://google.com", headers['Location']
229
- get "/foo"
230
- assert_equal "http://example.org/bar", headers['Location']
231
- end
232
-
233
- should "return 406 on Accept-Headers it does not provide" do
234
- mock_app do
235
- get(:a, :provides => [:html, :js]){ content_type }
236
- end
237
-
238
- get "/a", {}, {"HTTP_ACCEPT" => "application/yaml"}
239
- assert_equal 406, status
240
- end
241
-
242
- should "return 406 on file extensions it does not provide and flag is set" do
243
- mock_app do
244
- enable :treat_format_as_accept
245
- get(:a, :provides => [:html, :js]){ content_type }
246
- end
247
-
248
- get "/a.xml", {}, {}
249
- assert_equal 406, status
250
- end
251
-
252
- should "return 404 on file extensions it does not provide and flag is not set" do
253
- mock_app do
254
- get(:a, :provides => [:html, :js]){ content_type }
255
- end
256
-
257
- get "/a.xml", {}, {}
258
- assert_equal 405, status
259
- end
260
-
261
- should "not set content_type to :html if Accept */* and html not in provides" do
262
- mock_app do
263
- get("/foo", :provides => [:json, :xml]) { content_type.to_s }
264
- end
265
-
266
- get '/foo', {}, { 'HTTP_ACCEPT' => '*/*;q=0.5' }
267
- assert_equal 'json', body
268
- end
269
-
270
- should "set content_type to :json if Accept contains */*" do
271
- mock_app do
272
- get("/foo", :provides => [:json]) { content_type.to_s }
273
- end
274
-
275
- get '/foo', {}, { 'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' }
276
- assert_equal 'json', body
277
- end
278
-
279
- should "set content_type to :json if render => :json" do
280
- mock_app do
281
- get("/foo"){ render :foo => :bar }
282
- end
283
-
284
- get '/foo'
285
- assert_equal 'application/json;charset=utf-8', content_type
286
- end
287
-
288
- should 'set and get content_type' do
289
- mock_app do
290
- get("/foo"){ content_type(:json); content_type.to_s }
291
- end
292
- get "/foo"
293
- assert_equal 'application/json;charset=utf-8', content_type
294
- assert_equal 'json', body
295
- end
296
-
297
- should "send the appropriate number of params" do
298
- mock_app do
299
- get('/id/:user_id', :provides => [:json]) { |user_id, format| user_id}
300
- end
301
- get '/id/5.json'
302
- assert_equal '5', body
303
- end
304
-
305
- should "allow .'s in param values" do
306
- mock_app do
307
- get('/id/:email', :provides => [:json]) { |email, format| [email, format] * '/' }
308
- end
309
- get '/id/foo@bar.com.json'
310
- assert_equal 'foo@bar.com/json', body
311
- end
312
-
313
- should "set correct content_type for Accept not equal to */* even if */* also provided" do
314
- mock_app do
315
- get("/foo", :provides => [:html, :js, :xml]) { content_type.to_s }
316
- end
317
-
318
- get '/foo', {}, { 'HTTP_ACCEPT' => 'application/javascript, */*;q=0.5' }
319
- assert_equal 'js', body
320
- end
321
-
322
- should "return the first content type in provides if accept header is empty" do
323
- mock_app do
324
- get(:a, :provides => [:js]){ content_type.to_s }
325
- end
326
-
327
- get "/a", {}, {}
328
- assert_equal "js", body
329
- end
330
-
331
- should "not default to HTML if HTML is not provided and no type is given" do
332
- mock_app do
333
- get(:a, :provides => [:js]){ content_type }
334
- end
335
-
336
- get "/a", {}, {}
337
- assert_equal "application/javascript;charset=utf-8", content_type
338
- end
339
-
340
- should "not match routes if url_format and http_accept is provided but not included" do
341
- mock_app do
342
- get(:a, :provides => [:js, :html]){ content_type }
343
- end
344
-
345
- get "/a.xml", {}, {"HTTP_ACCEPT" => "text/html"}
346
- assert_equal 405, status
347
- end
348
-
349
- should "generate routes for format simple" do
350
- mock_app do
351
- get(:foo, :provides => [:html, :rss]) { render :haml, "Test" }
352
- end
353
- get "/foo"
354
- assert_equal "Test\n", body
355
- get "/foo.rss"
356
- assert_equal "Test\n", body
357
- end
358
-
359
- should "should inject the controller name into the request" do
360
- mock_app do
361
- controller :posts do
362
- get(:index) { request.controller }
363
- controller :mini do
364
- get(:index) { request.controller }
365
- end
366
- end
367
- end
368
- get "/posts"
369
- assert_equal "posts", body
370
- get "/mini"
371
- assert_equal "mini", body
372
- end
373
-
374
- should "support not_found" do
375
- mock_app do
376
- not_found do
377
- response.status = 404
378
- 'whatever'
379
- end
380
-
381
- get :index, :map => "/" do
382
- 'index'
383
- end
384
- end
385
- get '/something'
386
- assert_equal 'whatever', body
387
- assert_equal 404, status
388
- get '/'
389
- assert_equal 'index', body
390
- assert_equal 200, status
391
- end
392
-
393
- should "should inject the route into the request" do
394
- mock_app do
395
- controller :posts do
396
- get(:index) { request.route_obj.named.to_s }
397
- end
398
- end
399
- get "/posts"
400
- assert_equal "posts_index", body
401
- end
402
-
403
- should "preserve the format if you set it manually" do
404
- mock_app do
405
- before do
406
- params[:format] = "json"
407
- end
408
-
409
- get "test", :provides => [:html, :json] do
410
- content_type.inspect
411
- end
412
- end
413
- get "/test"
414
- assert_equal ":json", body
415
- get "/test.html"
416
- assert_equal ":json", body
417
- get "/test.php"
418
- assert_equal ":json", body
419
- end
420
-
421
- should "correctly accept '.' in the route" do
422
- mock_app do
423
- get "test.php", :provides => [:html, :json] do
424
- content_type.inspect
425
- end
426
- end
427
- get "/test.php"
428
- assert_equal ":html", body
429
- get "/test.php.json"
430
- assert_equal ":json", body
431
- end
432
-
433
- should "correctly accept priority of format" do
434
- mock_app do
435
- get "test.php", :provides => [:html, :json, :xml] do
436
- content_type.inspect
437
- end
438
- end
439
-
440
- get "/test.php"
441
- assert_equal ":html", body
442
- get "/test.php", {}, { 'HTTP_ACCEPT' => 'application/xml' }
443
- assert_equal ":xml", body
444
- get "/test.php?format=json", { 'HTTP_ACCEPT' => 'application/xml' }
445
- assert_equal ":json", body
446
- get "/test.php.json?format=html", { 'HTTP_ACCEPT' => 'application/xml' }
447
- assert_equal ":json", body
448
- end
449
-
450
- should "generate routes for format with controller" do
451
- mock_app do
452
- controller :posts do
453
- get(:index, :provides => [:html, :rss, :atom, :js]) { render :haml, "Index.#{content_type}" }
454
- get(:show, :with => :id, :provides => [:html, :rss, :atom]) { render :haml, "Show.#{content_type}" }
455
- end
456
- end
457
- get "/posts"
458
- assert_equal "Index.html\n", body
459
- get "/posts.rss"
460
- assert_equal "Index.rss\n", body
461
- get "/posts.atom"
462
- assert_equal "Index.atom\n", body
463
- get "/posts.js"
464
- assert_equal "Index.js\n", body
465
- get "/posts/show/5"
466
- assert_equal "Show.html\n", body
467
- get "/posts/show/5.rss"
468
- assert_equal "Show.rss\n", body
469
- get "/posts/show/10.atom"
470
- assert_equal "Show.atom\n", body
471
- end
472
-
473
- should 'map routes' do
474
- mock_app do
475
- get(:bar){ "bar" }
476
- end
477
- get "/bar"
478
- assert_equal "bar", body
479
- assert_equal "/bar", @app.url(:bar)
480
- end
481
-
482
- should 'remove index from path' do
483
- mock_app do
484
- get(:index){ "index" }
485
- get("/accounts/index"){ "accounts" }
486
- end
487
- get "/"
488
- assert_equal "index", body
489
- assert_equal "/", @app.url(:index)
490
- get "/accounts/index"
491
- assert_equal "accounts", body
492
- end
493
-
494
- should 'remove index from path with params' do
495
- mock_app do
496
- get(:index, :with => :name){ "index with #{params[:name]}" }
497
- end
498
- get "/bobby"
499
- assert_equal "index with bobby", body
500
- assert_equal "/john", @app.url(:index, :name => "john")
501
- end
502
-
503
- should 'parse named params' do
504
- mock_app do
505
- get(:print, :with => :id){ "Im #{params[:id]}" }
506
- end
507
- get "/print/9"
508
- assert_equal "Im 9", body
509
- assert_equal "/print/9", @app.url(:print, :id => 9)
510
- end
511
-
512
- should '405 on wrong request_method' do
513
- mock_app do
514
- post('/bar'){ "bar" }
515
- end
516
- get "/bar"
517
- assert_equal 405, status
518
- end
519
-
520
- should 'respond to' do
521
- mock_app do
522
- get(:a, :provides => :js){ "js" }
523
- get(:b, :provides => :any){ "any" }
524
- get(:c, :provides => [:js, :json]){ "js,json" }
525
- get(:d, :provides => [:html, :js]){ "html,js"}
526
- end
527
- get "/a"
528
- assert_equal 200, status
529
- assert_equal "js", body
530
- get "/a.js"
531
- assert_equal "js", body
532
- get "/b"
533
- assert_equal "any", body
534
- # TODO randomly fails in minitest :(
535
- # assert_raises(RuntimeError) { get "/b.foo" }
536
- get "/c"
537
- assert_equal 200, status
538
- assert_equal "js,json", body
539
- get "/c.js"
540
- assert_equal "js,json", body
541
- get "/c.json"
542
- assert_equal "js,json", body
543
- get "/d"
544
- assert_equal "html,js", body
545
- get "/d.js"
546
- assert_equal "html,js", body
547
- end
548
-
549
- should 'respond_to and set content_type' do
550
- Rack::Mime::MIME_TYPES['.foo'] = 'application/foo'
551
- mock_app do
552
- get :a, :provides => :any do
553
- case content_type
554
- when :js then "js"
555
- when :json then "json"
556
- when :foo then "foo"
557
- when :html then "html"
558
- end
559
- end
560
- end
561
- get "/a.js"
562
- assert_equal "js", body
563
- assert_equal 'application/javascript;charset=utf-8', response["Content-Type"]
564
- get "/a.json"
565
- assert_equal "json", body
566
- assert_equal 'application/json;charset=utf-8', response["Content-Type"]
567
- get "/a.foo"
568
- assert_equal "foo", body
569
- assert_equal 'application/foo;charset=utf-8', response["Content-Type"]
570
- get "/a"
571
- assert_equal "html", body
572
- assert_equal 'text/html;charset=utf-8', response["Content-Type"]
573
- end
574
-
575
- should 'use controllers' do
576
- mock_app do
577
- controller "/admin" do
578
- get("/"){ "index" }
579
- get("/show/:id"){ "show #{params[:id]}" }
580
- end
581
- end
582
- get "/admin"
583
- assert_equal "index", body
584
- get "/admin/show/1"
585
- assert_equal "show 1", body
586
- end
587
-
588
- should 'use named controllers' do
589
- mock_app do
590
- controller :admin do
591
- get(:index, :with => :id){ params[:id] }
592
- get(:show, :with => :id){ "show #{params[:id]}" }
593
- end
594
- controllers :foo, :bar do
595
- get(:index){ "foo_bar_index" }
596
- end
597
- end
598
- get "/admin/1"
599
- assert_equal "1", body
600
- get "/admin/show/1"
601
- assert_equal "show 1", body
602
- assert_equal "/admin/1", @app.url(:admin_index, :id => 1)
603
- assert_equal "/admin/show/1", @app.url(:admin_show, :id => 1)
604
- get "/foo/bar"
605
- assert_equal "foo_bar_index", body
606
- end
607
-
608
- should 'use map and with' do
609
- mock_app do
610
- get :index, :map => '/bugs', :with => :id do
611
- params[:id]
612
- end
613
- end
614
- get '/bugs/4'
615
- assert_equal '4', body
616
- assert_equal "/bugs/4", @app.url(:index, :id => 4)
617
- end
618
-
619
- should "ignore trailing delimiters within a named controller" do
620
- mock_app do
621
- controller :posts do
622
- get(:index, :provides => [:html, :js]){ "index" }
623
- get(:new) { "new" }
624
- get(:show, :with => :id){ "show #{params[:id]}" }
625
- end
626
- end
627
- get "/posts"
628
- assert_equal "index", body
629
- get "/posts/"
630
- assert_equal "index", body
631
- get "/posts.js"
632
- assert_equal "index", body
633
- get "/posts.js/"
634
- assert_equal "index", body
635
- get "/posts/new"
636
- assert_equal "new", body
637
- get "/posts/new/"
638
- assert_equal "new", body
639
- end
640
-
641
- should "ignore trailing delimiters within a named controller for unnamed actions" do
642
- mock_app do
643
- controller :accounts do
644
- get("/") { "account_index" }
645
- get("/new") { "new" }
646
- end
647
- controller :votes do
648
- get("/") { "vote_index" }
649
- end
650
- end
651
- get "/accounts"
652
- assert_equal "account_index", body
653
- get "/accounts/"
654
- assert_equal "account_index", body
655
- get "/accounts/new"
656
- assert_equal "new", body
657
- get "/accounts/new/"
658
- assert_equal "new", body
659
- get "/votes"
660
- assert_equal "vote_index", body
661
- get "/votes/"
662
- assert_equal "vote_index", body
663
- end
664
-
665
- should 'use named controllers with array routes' do
666
- mock_app do
667
- controller :admin do
668
- get(:index){ "index" }
669
- get(:show, :with => :id){ "show #{params[:id]}" }
670
- end
671
- controllers :foo, :bar do
672
- get(:index){ "foo_bar_index" }
673
- end
674
- end
675
- get "/admin"
676
- assert_equal "index", body
677
- get "/admin/show/1"
678
- assert_equal "show 1", body
679
- assert_equal "/admin", @app.url(:admin, :index)
680
- assert_equal "/admin/show/1", @app.url(:admin, :show, :id => 1)
681
- get "/foo/bar"
682
- assert_equal "foo_bar_index", body
683
- end
684
-
685
- should "support a reindex action and remove index inside controller" do
686
- mock_app do
687
- controller :posts do
688
- get(:index){ "index" }
689
- get(:reindex){ "reindex" }
690
- end
691
- end
692
- get "/posts"
693
- assert_equal "index", body
694
- get "/posts/reindex"
695
- assert_equal "/posts/reindex", @app.url(:posts, :reindex)
696
- assert_equal "reindex", body
697
- end
698
-
699
- should 'use uri_root' do
700
- mock_app do
701
- get(:foo){ "foo" }
702
- end
703
- @app.uri_root = '/'
704
- assert_equal "/foo", @app.url(:foo)
705
- @app.uri_root = '/testing'
706
- assert_equal "/testing/foo", @app.url(:foo)
707
- @app.uri_root = '/testing/'
708
- assert_equal "/testing/foo", @app.url(:foo)
709
- @app.uri_root = 'testing/bar///'
710
- assert_equal "/testing/bar/foo", @app.url(:foo)
711
- end
712
-
713
- should 'use uri_root with controllers' do
714
- mock_app do
715
- controller :foo do
716
- get(:bar){ "bar" }
717
- end
718
- end
719
- @app.uri_root = '/testing'
720
- assert_equal "/testing/foo/bar", @app.url(:foo, :bar)
721
- end
722
-
723
- should 'use RACK_BASE_URI' do
724
- mock_app do
725
- get(:foo){ "foo" }
726
- end
727
- # Wish there was a side-effect free way to test this...
728
- ENV['RACK_BASE_URI'] = '/'
729
- assert_equal "/foo", @app.url(:foo)
730
- ENV['RACK_BASE_URI'] = '/testing'
731
- assert_equal "/testing/foo", @app.url(:foo)
732
- ENV['RACK_BASE_URI'] = nil
733
- end
734
-
735
- should 'reset routes' do
736
- mock_app do
737
- get("/"){ "foo" }
738
- reset_router!
739
- end
740
- get "/"
741
- assert_equal 404, status
742
- end
743
-
744
- should 'respect priorities' do
745
- route_order = []
746
- mock_app do
747
- get(:index, :priority => :normal) { route_order << :normal; pass }
748
- get(:index, :priority => :low) { route_order << :low; "hello" }
749
- get(:index, :priority => :high) { route_order << :high; pass }
750
- end
751
- get '/'
752
- assert_equal [:high, :normal, :low], route_order
753
- assert_equal "hello", body
754
- end
755
-
756
- should 'allow optionals' do
757
- mock_app do
758
- get(:show, :map => "/stories/:type(/:category)") do
759
- "#{params[:type]}/#{params[:category]}"
760
- end
761
- end
762
- get "/stories/foo"
763
- assert_equal "foo/", body
764
- get "/stories/foo/bar"
765
- assert_equal "foo/bar", body
766
- end
767
-
768
- should 'apply maps' do
769
- mock_app do
770
- controllers :admin do
771
- get(:index, :map => "/"){ "index" }
772
- get(:show, :with => :id, :map => "/show"){ "show #{params[:id]}" }
773
- get(:edit, :map => "/edit/:id/product"){ "edit #{params[:id]}" }
774
- get(:wacky, :map => "/wacky-:id-:product_id"){ "wacky #{params[:id]}-#{params[:product_id]}" }
775
- end
776
- end
777
- get "/"
778
- assert_equal "index", body
779
- get @app.url(:admin, :index)
780
- assert_equal "index", body
781
- get "/show/1"
782
- assert_equal "show 1", body
783
- get "/edit/1/product"
784
- assert_equal "edit 1", body
785
- get "/wacky-1-2"
786
- assert_equal "wacky 1-2", body
787
- end
788
-
789
- should 'apply maps when given path is kind of hash' do
790
- mock_app do
791
- controllers :admin do
792
- get(:foobar, "/foo/bar"){ "foobar" }
793
- end
794
- end
795
- get "/foo/bar"
796
- assert_equal "foobar", body
797
- end
798
-
799
- should "apply parent to route" do
800
- mock_app do
801
- controllers :project do
802
- get(:index, :parent => :user) { "index #{params[:user_id]}" }
803
- get(:index, :parent => [:user, :section]) { "index #{params[:user_id]} #{params[:section_id]}" }
804
- get(:edit, :with => :id, :parent => :user) { "edit #{params[:id]} #{params[:user_id]}"}
805
- get(:show, :with => :id, :parent => [:user, :product]) { "show #{params[:id]} #{params[:user_id]} #{params[:product_id]}"}
806
- end
807
- end
808
- get "/user/1/project"
809
- assert_equal "index 1", body
810
- get "/user/1/section/3/project"
811
- assert_equal "index 1 3", body
812
- get "/user/1/project/edit/2"
813
- assert_equal "edit 2 1", body
814
- get "/user/1/product/2/project/show/3"
815
- assert_equal "show 3 1 2", body
816
- end
817
-
818
- should "apply parent to controller" do
819
- mock_app do
820
- controller :project, :parent => :user do
821
- get(:index) { "index #{params[:user_id]}"}
822
- get(:edit, :with => :id, :parent => :user) { "edit #{params[:id]} #{params[:user_id]}"}
823
- get(:show, :with => :id, :parent => :product) { "show #{params[:id]} #{params[:user_id]} #{params[:product_id]}"}
824
- end
825
- end
826
-
827
- user_project_url = "/user/1/project"
828
- get user_project_url
829
- assert_equal "index 1", body
830
- assert_equal user_project_url, @app.url(:project, :index, :user_id => 1)
831
-
832
- user_project_edit_url = "/user/1/project/edit/2"
833
- get user_project_edit_url
834
- assert_equal "edit 2 1", body
835
- assert_equal user_project_edit_url, @app.url(:project, :edit, :user_id => 1, :id => 2)
836
-
837
- user_product_project_url = "/user/1/product/2/project/show/3"
838
- get user_product_project_url
839
- assert_equal "show 3 1 2", body
840
- assert_equal user_product_project_url, @app.url(:project, :show, :user_id => 1, :product_id => 2, :id => 3)
841
- end
842
-
843
- should "apply parent with shallowing to controller" do
844
- mock_app do
845
- controller :project do
846
- parent :user
847
- parent :shop, :optional => true
848
- get(:index) { "index #{params[:user_id]} #{params[:shop_id]}" }
849
- get(:edit, :with => :id) { "edit #{params[:id]} #{params[:user_id]} #{params[:shop_id]}" }
850
- get(:show, :with => :id, :parent => :product) { "show #{params[:id]} #{params[:user_id]} #{params[:product_id]} #{params[:shop_id]}" }
851
- end
852
- end
853
-
854
- assert_equal "/user/1/project", @app.url(:project, :index, :user_id => 1, :shop_id => nil)
855
- assert_equal "/user/1/shop/23/project", @app.url(:project, :index, :user_id => 1, :shop_id => 23)
856
-
857
- user_project_url = "/user/1/project"
858
- get user_project_url
859
- assert_equal "index 1 ", body
860
- assert_equal user_project_url, @app.url(:project, :index, :user_id => 1)
861
-
862
- user_project_edit_url = "/user/1/project/edit/2"
863
- get user_project_edit_url
864
- assert_equal "edit 2 1 ", body
865
- assert_equal user_project_edit_url, @app.url(:project, :edit, :user_id => 1, :id => 2)
866
-
867
- user_product_project_url = "/user/1/product/2/project/show/3"
868
- get user_product_project_url
869
- assert_equal "show 3 1 2 ", body
870
- assert_equal user_product_project_url, @app.url(:project, :show, :user_id => 1, :product_id => 2, :id => 3)
871
-
872
- user_project_url = "/user/1/shop/1/project"
873
- get user_project_url
874
- assert_equal "index 1 1", body
875
- assert_equal user_project_url, @app.url(:project, :index, :user_id => 1, :shop_id => 1)
876
-
877
- user_project_edit_url = "/user/1/shop/1/project/edit/2"
878
- get user_project_edit_url
879
- assert_equal "edit 2 1 1", body
880
- assert_equal user_project_edit_url, @app.url(:project, :edit, :user_id => 1, :id => 2, :shop_id => 1)
881
-
882
- user_product_project_url = "/user/1/shop/1/product/2/project/show/3"
883
- get user_product_project_url
884
- assert_equal "show 3 1 2 1", body
885
- assert_equal user_product_project_url, @app.url(:project, :show, :user_id => 1, :product_id => 2, :id => 3, :shop_id => 1)
886
- end
887
-
888
- should "respect map in parents with shallowing" do
889
- mock_app do
890
- controller :project do
891
- parent :shop, :map => "/foo/bar"
892
- get(:index) { "index #{params[:shop_id]}" }
893
- end
894
- end
895
-
896
- shop_project_url = "/foo/bar/1/project"
897
- get shop_project_url
898
- assert_equal "index 1", body
899
- assert_equal shop_project_url, @app.url(:project, :index, :shop_id => 1)
900
- end
901
-
902
- should "use default values" do
903
- mock_app do
904
- controller :lang => :it do
905
- get(:index, :map => "/:lang") { "lang is #{params[:lang]}" }
906
- end
907
- # This is only for be sure that default values
908
- # work only for the given controller
909
- get(:foo, :map => "/foo") {}
910
- end
911
- assert_equal "/it", @app.url(:index)
912
- assert_equal "/foo", @app.url(:foo)
913
- get "/en"
914
- assert_equal "lang is en", body
915
- end
916
-
917
- should "transitions to the next matching route on pass" do
918
- mock_app do
919
- get '/:foo' do
920
- pass
921
- 'Hello Foo'
922
- end
923
- get '/:bar' do
924
- 'Hello World'
925
- end
926
- end
927
-
928
- get '/za'
929
- assert_equal 'Hello World', body
930
- end
931
-
932
- should "filters by accept header" do
933
- mock_app do
934
- get '/foo', :provides => [:xml, :js] do
935
- request.env['HTTP_ACCEPT']
936
- end
937
- end
938
-
939
- get '/foo', {}, { 'HTTP_ACCEPT' => 'application/xml' }
940
- assert ok?
941
- assert_equal 'application/xml', body
942
- assert_equal 'application/xml;charset=utf-8', response.headers['Content-Type']
943
-
944
- get '/foo.xml'
945
- assert ok?
946
- assert_equal 'application/xml;charset=utf-8', response.headers['Content-Type']
947
-
948
- get '/foo', {}, { 'HTTP_ACCEPT' => 'application/javascript' }
949
- assert ok?
950
- assert_equal 'application/javascript', body
951
- assert_equal 'application/javascript;charset=utf-8', response.headers['Content-Type']
952
-
953
- get '/foo.js'
954
- assert ok?
955
- assert_equal 'application/javascript;charset=utf-8', response.headers['Content-Type']
956
-
957
- get '/foo', {}, { "HTTP_ACCEPT" => 'text/html' }
958
- assert_equal 406, status
959
- end
960
-
961
- should "does not allow global provides" do
962
- mock_app do
963
- provides :xml
964
-
965
- get("/foo"){ "Foo in #{content_type}" }
966
- get("/bar"){ "Bar in #{content_type}" }
967
- end
968
-
969
- get '/foo', {}, { 'HTTP_ACCEPT' => 'application/xml' }
970
- assert_equal 'Foo in xml', body
971
- get '/foo'
972
- assert_equal 'Foo in xml', body
973
-
974
- get '/bar', {}, { 'HTTP_ACCEPT' => 'application/xml' }
975
- assert_equal 'Bar in html', body
976
- end
977
-
978
- should "does not allow global provides in controller" do
979
- mock_app do
980
- controller :base do
981
- provides :xml
982
-
983
- get(:foo, "/foo"){ "Foo in #{content_type}" }
984
- get(:bar, "/bar"){ "Bar in #{content_type}" }
985
- end
986
- end
987
-
988
- get '/foo', {}, { 'HTTP_ACCEPT' => 'application/xml' }
989
- assert_equal 'Foo in xml', body
990
- get '/foo'
991
- assert_equal 'Foo in xml', body
992
-
993
- get '/bar', {}, { 'HTTP_ACCEPT' => 'application/xml' }
994
- assert_equal 'Bar in html', body
995
- end
996
-
997
- should "map non named routes in controllers" do
998
- mock_app do
999
- controller :base do
1000
- get("/foo") { "ok" }
1001
- get("/bar") { "ok" }
1002
- end
1003
- end
1004
-
1005
- get "/base/foo"
1006
- assert ok?
1007
- get "/base/bar"
1008
- assert ok?
1009
- end
1010
-
1011
- should "set content_type to :html for both empty Accept as well as Accept text/html" do
1012
- mock_app do
1013
- provides :html
1014
-
1015
- get("/foo"){ content_type.to_s }
1016
- end
1017
-
1018
- get '/foo', {}, {}
1019
- assert_equal 'html', body
1020
-
1021
- get '/foo', {}, { 'HTTP_ACCEPT' => 'text/html' }
1022
- assert_equal 'html', body
1023
- end
1024
-
1025
- should "set content_type to :html if Accept */*" do
1026
- mock_app do
1027
- get("/foo", :provides => [:html, :js]) { content_type.to_s }
1028
- end
1029
- get '/foo', {}, {}
1030
- assert_equal 'html', body
1031
-
1032
- get '/foo', {}, { 'HTTP_ACCEPT' => '*/*;q=0.5' }
1033
- assert_equal 'html', body
1034
- end
1035
-
1036
- should "set content_type to :js if Accept includes both application/javascript and */*;q=0.5" do
1037
- mock_app do
1038
- get("/foo", :provides => [:html, :js]) { content_type.to_s }
1039
- end
1040
- get '/foo', {}, { 'HTTP_ACCEPT' => 'application/javascript, */*;q=0.5' }
1041
- assert_equal 'js', body
1042
- end
1043
-
1044
- should 'allows custom route-conditions to be set via route options and halt' do
1045
- protector = Module.new do
1046
- def protect(*args)
1047
- condition {
1048
- unless authorize(params["user"], params["password"])
1049
- halt 403, "go away"
1050
- end
1051
- }
1052
- end
1053
- end
1054
-
1055
- mock_app do
1056
- register protector
1057
-
1058
- helpers do
1059
- def authorize(username, password)
1060
- username == "foo" && password == "bar"
1061
- end
1062
- end
1063
-
1064
- get "/", :protect => true do
1065
- "hey"
1066
- end
1067
- end
1068
-
1069
- get "/"
1070
- assert forbidden?
1071
- assert_equal "go away", body
1072
-
1073
- get "/", :user => "foo", :password => "bar"
1074
- assert ok?
1075
- assert_equal "hey", body
1076
- end
1077
-
1078
- should 'allows custom route-conditions to be set via route options using two routes' do
1079
- protector = Module.new do
1080
- def protect(*args)
1081
- condition { authorize(params["user"], params["password"]) }
1082
- end
1083
- end
1084
-
1085
- mock_app do
1086
- register protector
1087
-
1088
- helpers do
1089
- def authorize(username, password)
1090
- username == "foo" && password == "bar"
1091
- end
1092
- end
1093
-
1094
- get "/", :protect => true do
1095
- "hey"
1096
- end
1097
-
1098
- get "/" do
1099
- "go away"
1100
- end
1101
- end
1102
-
1103
- get "/"
1104
- assert_equal "go away", body
1105
-
1106
- get "/", :user => "foo", :password => "bar"
1107
- assert ok?
1108
- assert_equal "hey", body
1109
- end
1110
-
1111
- should "allow concise routing" do
1112
- mock_app do
1113
- get :index, ":id" do
1114
- params[:id]
1115
- end
1116
-
1117
- get :map, "route/:id" do
1118
- params[:id]
1119
- end
1120
- end
1121
-
1122
- get "/123"
1123
- assert_equal "123", body
1124
-
1125
- get "/route/123"
1126
- assert_equal "123", body
1127
- end
1128
-
1129
- should "support halting with 404 and message" do
1130
- mock_app do
1131
- controller do
1132
- get :index do
1133
- halt 404, "not found"
1134
- end
1135
- end
1136
- end
1137
-
1138
- get "/"
1139
- assert_equal 404, status
1140
- assert_equal "not found", body
1141
- end
1142
-
1143
- should "allow passing & halting in before filters" do
1144
- mock_app do
1145
- controller do
1146
- before { env['QUERY_STRING'] == 'secret' or pass }
1147
- get :index do
1148
- "secret index"
1149
- end
1150
- end
1151
-
1152
- controller do
1153
- before { env['QUERY_STRING'] == 'halt' and halt 401, 'go away!' }
1154
- get :index do
1155
- "index"
1156
- end
1157
- end
1158
- end
1159
-
1160
- get "/?secret"
1161
- assert_equal "secret index", body
1162
-
1163
- get "/?halt"
1164
- assert_equal "go away!", body
1165
- assert_equal 401, status
1166
-
1167
- get "/"
1168
- assert_equal "index", body
1169
- end
1170
-
1171
- should 'scope filters in the given controller' do
1172
- mock_app do
1173
- before { @global = 'global' }
1174
- after { @global = nil }
1175
-
1176
- controller :foo do
1177
- before { @foo = :foo }
1178
- after { @foo = nil }
1179
- get("/") { [@foo, @bar, @global].compact.join(" ") }
1180
- end
1181
-
1182
- get("/") { [@foo, @bar, @global].compact.join(" ") }
1183
-
1184
- controller :bar do
1185
- before { @bar = :bar }
1186
- after { @bar = nil }
1187
- get("/") { [@foo, @bar, @global].compact.join(" ") }
1188
- end
1189
- end
1190
-
1191
- get "/bar"
1192
- assert_equal "bar global", body
1193
-
1194
- get "/foo"
1195
- assert_equal "foo global", body
1196
-
1197
- get "/"
1198
- assert_equal "global", body
1199
- end
1200
-
1201
- should 'works with optionals params' do
1202
- mock_app do
1203
- get("/foo(/:bar)") { params[:bar] }
1204
- end
1205
-
1206
- get "/foo/bar"
1207
- assert_equal "bar", body
1208
-
1209
- get "/foo"
1210
- assert_equal "", body
1211
- end
1212
-
1213
- should 'work with multiple dashed params' do
1214
- mock_app do
1215
- get "/route/:foo/:bar/:baz", :provides => :html do
1216
- "#{params[:foo]};#{params[:bar]};#{params[:baz]}"
1217
- end
1218
- end
1219
-
1220
- get "/route/foo/bar/baz"
1221
- assert_equal 'foo;bar;baz', body
1222
-
1223
- get "/route/foo/bar-whatever/baz"
1224
- assert_equal 'foo;bar-whatever;baz', body
1225
- end
1226
-
1227
- should 'work with arbitrary params' do
1228
- mock_app do
1229
- get(:testing) { params[:foo] }
1230
- end
1231
-
1232
- url = @app.url(:testing, :foo => 'bar')
1233
- assert_equal "/testing?foo=bar", url
1234
- get url
1235
- assert_equal "bar", body
1236
- end
1237
-
1238
- should 'ignore nil params' do
1239
- mock_app do
1240
- get(:testing, :provides => [:html, :json]) do
1241
- end
1242
- end
1243
- assert_equal '/testing.html', @app.url(:testing, :format => :html)
1244
- assert_equal '/testing', @app.url(:testing, :format => nil)
1245
- end
1246
-
1247
- should 'be able to access params in a before filter' do
1248
- username_from_before_filter = nil
1249
-
1250
- mock_app do
1251
- before do
1252
- username_from_before_filter = params[:username]
1253
- end
1254
-
1255
- get :users, :with => :username do
1256
- end
1257
- end
1258
- get '/users/josh'
1259
- assert_equal 'josh', username_from_before_filter
1260
- end
1261
-
1262
- should "be able to access params normally when a before filter is specified" do
1263
- mock_app do
1264
- before { }
1265
- get :index do
1266
- params.inspect
1267
- end
1268
- end
1269
- get '/?test=what'
1270
- assert_equal '{"test"=>"what"}', body
1271
- end
1272
-
1273
- should 'work with controller and arbitrary params' do
1274
- mock_app do
1275
- get(:testing) { params[:foo] }
1276
- controller :test1 do
1277
- get(:url1) { params[:foo] }
1278
- get(:url2, :provides => [:html, :json]) { params[:foo] }
1279
- end
1280
- end
1281
-
1282
- url = @app.url(:test1, :url1, :foo => 'bar1')
1283
- assert_equal "/test1/url1?foo=bar1", url
1284
- get url
1285
- assert_equal "bar1", body
1286
-
1287
- url = @app.url(:test1, :url2, :foo => 'bar2')
1288
- assert_equal "/test1/url2?foo=bar2", url
1289
- get url
1290
- assert_equal "bar2", body
1291
- end
1292
-
1293
- should "parse two routes with the same path but different http verbs" do
1294
- mock_app do
1295
- get(:index) { "This is the get index" }
1296
- post(:index) { "This is the post index" }
1297
- end
1298
- get "/"
1299
- assert_equal "This is the get index", body
1300
- post "/"
1301
- assert_equal "This is the post index", body
1302
- end
1303
-
1304
- should "use optionals params" do
1305
- mock_app do
1306
- get(:index, :map => "/(:foo(/:bar))") { "#{params[:foo]}-#{params[:bar]}" }
1307
- end
1308
- get "/foo"
1309
- assert_equal "foo-", body
1310
- get "/foo/bar"
1311
- assert_equal "foo-bar", body
1312
- end
1313
-
1314
- should "parse two routes with the same path but different http verbs and provides" do
1315
- mock_app do
1316
- get(:index, :provides => [:html, :json]) { "This is the get index.#{content_type}" }
1317
- post(:index, :provides => [:html, :json]) { "This is the post index.#{content_type}" }
1318
- end
1319
- get "/"
1320
- assert_equal "This is the get index.html", body
1321
- post "/"
1322
- assert_equal "This is the post index.html", body
1323
- get "/.json"
1324
- assert_equal "This is the get index.json", body
1325
- get "/.js"
1326
- assert_equal 405, status
1327
- post "/.json"
1328
- assert_equal "This is the post index.json", body
1329
- post "/.js"
1330
- assert_equal 405, status
1331
- end
1332
-
1333
- should "allow controller level mapping" do
1334
- mock_app do
1335
- controller :map => "controller-:id" do
1336
- get(:url3) { "#{params[:id]}" }
1337
- get(:url4, :map => 'test-:id2') { "#{params[:id]}, #{params[:id2]}" }
1338
- end
1339
- end
1340
-
1341
- url = @app.url(:url3, :id => 1)
1342
- assert_equal "/controller-1/url3", url
1343
- get url
1344
- assert_equal "1", body
1345
-
1346
- url = @app.url(:url4, 1, 2)
1347
- assert_equal "/controller-1/test-2", url
1348
- get url
1349
- assert_equal "1, 2", body
1350
- end
1351
-
1352
- should 'use absolute and relative maps' do
1353
- mock_app do
1354
- controller :one do
1355
- parent :three
1356
- get :index, :map => 'one' do; end
1357
- get :index2, :map => '/one' do; end
1358
- end
1359
-
1360
- controller :two, :map => 'two' do
1361
- parent :three
1362
- get :index, :map => 'two' do; end
1363
- get :index2, :map => '/two', :with => :id do; end
1364
- end
1365
- end
1366
- assert_equal "/three/three_id/one", @app.url(:one, :index, 'three_id')
1367
- assert_equal "/one", @app.url(:one, :index2)
1368
- assert_equal "/two/three/three_id/two", @app.url(:two, :index, 'three_id')
1369
- assert_equal "/two/four_id", @app.url(:two, :index2, 'four_id')
1370
- end
1371
-
1372
- should "work with params and parent options" do
1373
- mock_app do
1374
- controller :test2, :parent => :parent1, :parent1_id => 1 do
1375
- get(:url3) { params[:foo] }
1376
- get(:url4, :with => :with1) { params[:foo] }
1377
- get(:url5, :with => :with2, :provides => [:html]) { params[:foo] }
1378
- end
1379
- end
1380
-
1381
- url = @app.url(:test2, :url3, :foo => 'bar3')
1382
- assert_equal "/parent1/1/test2/url3?foo=bar3", url
1383
- get url
1384
- assert_equal "bar3", body
1385
-
1386
- url = @app.url(:test2, :url4, :with1 => 'awith1', :foo => 'bar4')
1387
- assert_equal "/parent1/1/test2/url4/awith1?foo=bar4", url
1388
- get url
1389
- assert_equal "bar4", body
1390
-
1391
- url = @app.url(:test2, :url5, :with2 => 'awith1', :foo => 'bar5')
1392
- assert_equal "/parent1/1/test2/url5/awith1?foo=bar5", url
1393
- get url
1394
- assert_equal "bar5", body
1395
- end
1396
-
1397
- should "parse params without explicit provides for every matching route" do
1398
- mock_app do
1399
- get(:index, :map => "/foos/:bar") { "get bar = #{params[:bar]}" }
1400
- post :create, :map => "/foos/:bar", :provides => [:html, :js] do
1401
- "post bar = #{params[:bar]}"
1402
- end
1403
- end
1404
-
1405
- get "/foos/hello"
1406
- assert_equal "get bar = hello", body
1407
- post "/foos/hello"
1408
- assert_equal "post bar = hello", body
1409
- post "/foos/hello.js"
1410
- assert_equal "post bar = hello", body
1411
- end
1412
-
1413
- should "properly route to first foo with two similar routes" do
1414
- mock_app do
1415
- controllers do
1416
- get('/foo/') { "this is foo" }
1417
- get(:show, :map => "/foo/:bar/:id") { "/foo/#{params[:bar]}/#{params[:id]}" }
1418
- end
1419
- end
1420
- get "/foo"
1421
- assert_equal "this is foo", body
1422
- get "/foo/"
1423
- assert_equal "this is foo", body
1424
- get '/foo/5/10'
1425
- assert_equal "/foo/5/10", body
1426
- end
1427
-
1428
- should "index routes should be optional when nested" do
1429
- mock_app do
1430
- controller '/users', :provides => [:json] do
1431
- get '/' do
1432
- "foo"
1433
- end
1434
- end
1435
- end
1436
- get "/users.json"
1437
- assert_equal "foo", body
1438
- end
1439
-
1440
- should "use provides as conditional" do
1441
- mock_app do
1442
- provides :json
1443
- get "/" do
1444
- "foo"
1445
- end
1446
- end
1447
- get "/.json"
1448
- assert_equal "foo", body
1449
- end
1450
-
1451
- should "pass controller conditions to each route" do
1452
- counter = 0
1453
-
1454
- mock_app do
1455
- self.class.send(:define_method, :increment!) do |*args|
1456
- condition { counter += 1 }
1457
- end
1458
-
1459
- controller :posts, :conditions => {:increment! => true} do
1460
- get("/foo") { "foo" }
1461
- get("/bar") { "bar" }
1462
- end
1463
-
1464
- end
1465
-
1466
- get "/posts/foo"
1467
- get "/posts/bar"
1468
- assert_equal 2, counter
1469
- end
1470
-
1471
- should "allow controller conditions to be overridden" do
1472
- counter = 0
1473
-
1474
- mock_app do
1475
- self.class.send(:define_method, :increment!) do |increment|
1476
- condition { counter += 1 } if increment
1477
- end
1478
-
1479
- controller :posts, :conditions => {:increment! => true} do
1480
- get("/foo") { "foo" }
1481
- get("/bar", :increment! => false) { "bar" }
1482
- end
1483
-
1484
- end
1485
-
1486
- get "/posts/foo"
1487
- get "/posts/bar"
1488
- assert_equal 1, counter
1489
- end
1490
-
1491
- should "parse params with class level provides" do
1492
- mock_app do
1493
- controllers :posts, :provides => [:html, :js] do
1494
- post(:create, :map => "/foo/:bar/:baz/:id") {
1495
- "POST CREATE #{params[:bar]} - #{params[:baz]} - #{params[:id]}"
1496
- }
1497
- end
1498
- controllers :topics, :provides => [:js, :html] do
1499
- get(:show, :map => "/foo/:bar/:baz/:id") { render "topics/show" }
1500
- post(:create, :map => "/foo/:bar/:baz") { "TOPICS CREATE #{params[:bar]} - #{params[:baz]}" }
1501
- end
1502
- end
1503
- post "/foo/bar/baz.js"
1504
- assert_equal "TOPICS CREATE bar - baz", body, "should parse params with explicit .js"
1505
- post @app.url(:topics, :create, :format => :js, :bar => 'bar', :baz => 'baz')
1506
- assert_equal "TOPICS CREATE bar - baz", body, "should parse params from generated url"
1507
- post "/foo/bar/baz/5.js"
1508
- assert_equal "POST CREATE bar - baz - 5", body
1509
- post @app.url(:posts, :create, :format => :js, :bar => 'bar', :baz => 'baz', :id => 5)
1510
- assert_equal "POST CREATE bar - baz - 5", body
1511
- end
1512
-
1513
- should "parse params properly with inline provides" do
1514
- mock_app do
1515
- controllers :posts do
1516
- post(:create, :map => "/foo/:bar/:baz/:id", :provides => [:html, :js]) {
1517
- "POST CREATE #{params[:bar]} - #{params[:baz]} - #{params[:id]}"
1518
- }
1519
- end
1520
- controllers :topics do
1521
- get(:show, :map => "/foo/:bar/:baz/:id", :provides => [:html, :js]) { render "topics/show" }
1522
- post(:create, :map => "/foo/:bar/:baz", :provides => [:html, :js]) { "TOPICS CREATE #{params[:bar]} - #{params[:baz]}" }
1523
- end
1524
- end
1525
- post @app.url(:topics, :create, :format => :js, :bar => 'bar', :baz => 'baz')
1526
- assert_equal "TOPICS CREATE bar - baz", body, "should properly post to topics create action"
1527
- post @app.url(:posts, :create, :format => :js, :bar => 'bar', :baz => 'baz', :id => 5)
1528
- assert_equal "POST CREATE bar - baz - 5", body, "should properly post to create action"
1529
- end
1530
-
1531
- should "have overideable format" do
1532
- mock_app do
1533
- ::Rack::Mime::MIME_TYPES[".other"] = "text/html"
1534
- before do
1535
- params[:format] ||= :other
1536
- end
1537
- get("/format_test", :provides => [:html, :other]){ content_type.to_s }
1538
- end
1539
- get "/format_test"
1540
- assert_equal "other", body
1541
- end
1542
-
1543
- should 'invokes handlers registered with ::error when raised' do
1544
- mock_app do
1545
- set :raise_errors, false
1546
- error(FooError) { 'Foo!' }
1547
- get '/' do
1548
- raise FooError
1549
- end
1550
- end
1551
- get '/'
1552
- assert_equal 500, status
1553
- assert_equal 'Foo!', body
1554
- end
1555
-
1556
- should 'have MethodOverride middleware' do
1557
- mock_app do
1558
- put('/') { 'okay' }
1559
- end
1560
- assert @app.method_override?
1561
- post '/', {'_method'=>'PUT'}, {}
1562
- assert_equal 200, status
1563
- assert_equal 'okay', body
1564
- end
1565
-
1566
- should 'return value from params' do
1567
- mock_app do
1568
- get("/foo/:bar"){ raise "'bar' should be a string" unless params[:bar].kind_of? String}
1569
- end
1570
- get "/foo/50"
1571
- assert ok?
1572
- end
1573
-
1574
- should 'have MethodOverride middleware with more options' do
1575
- mock_app do
1576
- put('/hi', :provides => [:json]) { 'hi' }
1577
- end
1578
- post '/hi', {'_method'=>'PUT'}
1579
- assert_equal 200, status
1580
- assert_equal 'hi', body
1581
- post '/hi.json', {'_method'=>'PUT'}
1582
- assert_equal 200, status
1583
- assert_equal 'hi', body
1584
- post '/hi.json'
1585
- assert_equal 405, status
1586
- end
1587
-
1588
- should 'parse nested params' do
1589
- mock_app do
1590
- get(:index) { "%s %s" % [params[:account][:name], params[:account][:surname]] }
1591
- end
1592
- get "/?account[name]=foo&account[surname]=bar"
1593
- assert_equal 'foo bar', body
1594
- get @app.url(:index, "account[name]" => "foo", "account[surname]" => "bar")
1595
- assert_equal 'foo bar', body
1596
- end
1597
-
1598
- should 'render sinatra NotFound page' do
1599
- mock_app { set :environment, :development }
1600
- get "/"
1601
- assert_equal 404, status
1602
- assert_match %r{(Sinatra doesn&rsquo;t know this ditty.|<h1>Not Found</h1>)}, body
1603
- end
1604
-
1605
- should 'render a custom NotFound page' do
1606
- mock_app do
1607
- error(Sinatra::NotFound) { "not found" }
1608
- end
1609
- get "/"
1610
- assert_equal 404, status
1611
- assert_match /not found/, body
1612
- end
1613
-
1614
- should 'render a custom 404 page' do
1615
- mock_app do
1616
- error(404) { "not found" }
1617
- end
1618
- get "/"
1619
- assert_equal 404, status
1620
- assert_match /not found/, body
1621
- end
1622
-
1623
- should 'recognize paths' do
1624
- mock_app do
1625
- controller :foo do
1626
- get(:bar, :map => "/my/:id/custom-route") { }
1627
- end
1628
- get(:simple, :map => "/simple/:id") { }
1629
- get(:with_format, :with => :id, :provides => :js) { }
1630
- end
1631
- assert_equal [:foo_bar, { :id => "fantastic" }], @app.recognize_path(@app.url(:foo, :bar, :id => :fantastic))
1632
- assert_equal [:foo_bar, { :id => "18" }], @app.recognize_path(@app.url(:foo, :bar, :id => 18))
1633
- assert_equal [:simple, { :id => "bar" }], @app.recognize_path(@app.url(:simple, :id => "bar"))
1634
- assert_equal [:simple, { :id => "true" }], @app.recognize_path(@app.url(:simple, :id => true))
1635
- assert_equal [:simple, { :id => "9" }], @app.recognize_path(@app.url(:simple, :id => 9))
1636
- assert_equal [:with_format, { :id => "bar", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => "bar", :format => :js))
1637
- assert_equal [:with_format, { :id => "true", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => true, :format => "js"))
1638
- assert_equal [:with_format, { :id => "9", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => 9, :format => :js))
1639
- end
1640
-
1641
- should 'have current_path' do
1642
- mock_app do
1643
- controller :foo do
1644
- get(:index) { current_path }
1645
- get :bar, :map => "/paginate/:page" do
1646
- current_path
1647
- end
1648
- get(:after) { current_path }
1649
- end
1650
- end
1651
- get "/paginate/10"
1652
- assert_equal "/paginate/10", body
1653
- get "/foo/after"
1654
- assert_equal "/foo/after", body
1655
- get "/foo"
1656
- assert_equal "/foo", body
1657
- end
1658
-
1659
- should 'accept :map and :parent' do
1660
- mock_app do
1661
- controller :posts do
1662
- get :show, :parent => :users, :map => "posts/:id" do
1663
- "#{params[:user_id]}-#{params[:id]}"
1664
- end
1665
- end
1666
- end
1667
- get '/users/123/posts/321'
1668
- assert_equal "123-321", body
1669
- end
1670
-
1671
- should 'change params in current_path' do
1672
- mock_app do
1673
- get :index, :map => "/paginate/:page" do
1674
- current_path(:page => 66)
1675
- end
1676
- end
1677
- get @app.url(:index, :page => 10)
1678
- assert_equal "/paginate/66", body
1679
- end
1680
- end