rango 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (382) hide show
  1. data/CHANGELOG +6 -0
  2. data/CONTRIBUTORS +1 -0
  3. data/README.textile +4 -1
  4. data/bin/rango +1 -1
  5. data/lib/rango.rb +78 -12
  6. data/lib/rango/contrib/pagination.rb +2 -0
  7. data/lib/rango/controller.rb +58 -12
  8. data/lib/rango/environments.rb +26 -0
  9. data/lib/rango/exceptions.rb +2 -14
  10. data/lib/rango/gv.rb +7 -90
  11. data/lib/rango/gv/static.rb +22 -0
  12. data/lib/rango/helpers.rb +0 -1
  13. data/lib/rango/helpers/assets.rb +2 -0
  14. data/lib/rango/helpers/general.rb +1 -0
  15. data/lib/rango/helpers/syntax.rb +2 -0
  16. data/lib/rango/mini.rb +30 -0
  17. data/lib/rango/mixins/application.rb +5 -3
  18. data/lib/rango/mixins/configurable.rb +1 -0
  19. data/lib/rango/mixins/render.rb +13 -84
  20. data/lib/rango/orm/tasks/datamapper.rake +2 -2
  21. data/lib/rango/project.rb +2 -2
  22. data/lib/rango/rack/middlewares/basic.rb +15 -11
  23. data/lib/rango/rack/request.rb +5 -3
  24. data/lib/rango/router.rb +20 -2
  25. data/lib/rango/router/adapters/rack_mount.rb +0 -1
  26. data/lib/rango/router/adapters/rack_router.rb +0 -1
  27. data/lib/rango/router/adapters/urlmap.rb +0 -1
  28. data/lib/rango/router/adapters/usher.rb +0 -1
  29. data/lib/rango/settings/framework.rb +2 -43
  30. data/lib/rango/templates/{erubis.rb → exts/erubis.rb} +0 -19
  31. data/lib/rango/templates/exts/tilt.rb +16 -0
  32. data/lib/rango/templates/helpers.rb +107 -0
  33. data/lib/rango/templates/template.rb +44 -115
  34. data/lib/rango/utils.rb +9 -4
  35. data/spec/rango/controller_spec.rb +3 -1
  36. data/spec/rango/environments_spec.rb +68 -0
  37. data/spec/rango/gv_spec.rb +10 -0
  38. data/spec/rango/mini_spec.rb +58 -0
  39. data/spec/rango/project_spec.rb +1 -1
  40. data/spec/rango/templates/template_spec.rb +81 -0
  41. data/spec/rango/utils_spec.rb +33 -0
  42. data/spec/rango_spec.rb +3 -17
  43. data/spec/spec_helper.rb +5 -3
  44. data/spec/stubs/config.ru +5 -0
  45. data/spec/stubs/templates/capture.html.erb +1 -1
  46. data/spec/stubs/templates/erubis.html.erubis +2 -0
  47. data/spec/stubs/templates/inheritance/basic/base.html.haml +2 -0
  48. data/spec/stubs/templates/inheritance/basic/index.html.haml +2 -0
  49. data/spec/stubs/templates/inheritance/capture/erb/base.html.erb +3 -0
  50. data/spec/stubs/templates/inheritance/capture/erb/index.html.erb +4 -0
  51. data/spec/stubs/templates/inheritance/capture/erubis/base.html.erubis +3 -0
  52. data/spec/stubs/templates/inheritance/capture/erubis/index.html.erubis +4 -0
  53. data/spec/stubs/templates/inheritance/capture/haml/base.html.haml +2 -0
  54. data/spec/stubs/templates/inheritance/capture/haml/index.html.haml +3 -0
  55. data/spec/stubs/templates/test.html.haml +1 -0
  56. data/spec/stubs/templates/variables.html.haml +1 -0
  57. data/stubs/app/content/init.rb.rbt +2 -1
  58. data/stubs/app/content/views.rb.rbt +2 -0
  59. data/stubs/bigapp/content/views/%controller%.rb.rbt +2 -0
  60. data/stubs/project/content/config.ru.rbt +3 -0
  61. data/stubs/project/content/init.rb.rbt +11 -5
  62. data/stubs/project/content/settings.rb +0 -2
  63. data/stubs/project/content/settings_local.rb.rbt +1 -1
  64. data/stubs/project/content/templates/base.html.haml.rbt +1 -0
  65. metadata +42 -329
  66. data/examples/README.textile +0 -12
  67. data/examples/blog/Gemfile +0 -80
  68. data/examples/blog/Rakefile +0 -12
  69. data/examples/blog/TODO.txt +0 -0
  70. data/examples/blog/bin/autospec +0 -3
  71. data/examples/blog/bin/css2sass +0 -3
  72. data/examples/blog/bin/cucumber +0 -3
  73. data/examples/blog/bin/haml +0 -3
  74. data/examples/blog/bin/html2haml +0 -3
  75. data/examples/blog/bin/htmldiff +0 -3
  76. data/examples/blog/bin/launchy +0 -3
  77. data/examples/blog/bin/ldiff +0 -3
  78. data/examples/blog/bin/nokogiri +0 -3
  79. data/examples/blog/bin/racksh +0 -3
  80. data/examples/blog/bin/rackup +0 -3
  81. data/examples/blog/bin/rake +0 -3
  82. data/examples/blog/bin/rango +0 -3
  83. data/examples/blog/bin/sass +0 -3
  84. data/examples/blog/bin/shotgun +0 -3
  85. data/examples/blog/bin/simple-templater +0 -3
  86. data/examples/blog/bin/spec +0 -3
  87. data/examples/blog/bin/tt +0 -3
  88. data/examples/blog/blog/init.rb +0 -9
  89. data/examples/blog/blog/models.rb +0 -21
  90. data/examples/blog/blog/views.rb +0 -16
  91. data/examples/blog/config.ru +0 -19
  92. data/examples/blog/gems/cache/addressable-2.1.1.gem +0 -0
  93. data/examples/blog/gems/cache/builder-2.1.2.gem +0 -0
  94. data/examples/blog/gems/cache/bundler-0.7.0.gem +0 -0
  95. data/examples/blog/gems/cache/cli-0.0.1.gem +0 -0
  96. data/examples/blog/gems/cache/configuration-1.1.0.gem +0 -0
  97. data/examples/blog/gems/cache/cucumber-0.4.4.gem +0 -0
  98. data/examples/blog/gems/cache/data_objects-0.10.0.gem +0 -0
  99. data/examples/blog/gems/cache/diff-lcs-1.1.2.gem +0 -0
  100. data/examples/blog/gems/cache/dm-core-0.10.1.gem +0 -0
  101. data/examples/blog/gems/cache/dm-timestamps-0.10.1.gem +0 -0
  102. data/examples/blog/gems/cache/do_mysql-0.10.0.gem +0 -0
  103. data/examples/blog/gems/cache/do_sqlite3-0.10.0.gem +0 -0
  104. data/examples/blog/gems/cache/extlib-0.9.13.gem +0 -0
  105. data/examples/blog/gems/cache/fuzzyhash-0.0.9.gem +0 -0
  106. data/examples/blog/gems/cache/haml-2.2.14.gem +0 -0
  107. data/examples/blog/gems/cache/launchy-0.3.3.gem +0 -0
  108. data/examples/blog/gems/cache/media-path-0.1.gem +0 -0
  109. data/examples/blog/gems/cache/nokogiri-1.4.0.gem +0 -0
  110. data/examples/blog/gems/cache/polyglot-0.2.9.gem +0 -0
  111. data/examples/blog/gems/cache/rack-1.0.1.gem +0 -0
  112. data/examples/blog/gems/cache/rack-test-0.5.2.gem +0 -0
  113. data/examples/blog/gems/cache/racksh-0.9.4.2.gem +0 -0
  114. data/examples/blog/gems/cache/rake-0.8.7.gem +0 -0
  115. data/examples/blog/gems/cache/rango-0.1.0.gem +0 -0
  116. data/examples/blog/gems/cache/rspec-1.2.9.gem +0 -0
  117. data/examples/blog/gems/cache/rubyexts-0.0.1.gem +0 -0
  118. data/examples/blog/gems/cache/shotgun-0.4.gem +0 -0
  119. data/examples/blog/gems/cache/simple-templater-0.0.1.gem +0 -0
  120. data/examples/blog/gems/cache/term-ansicolor-1.0.4.gem +0 -0
  121. data/examples/blog/gems/cache/treetop-1.4.2.gem +0 -0
  122. data/examples/blog/gems/cache/usher-0.5.11.gem +0 -0
  123. data/examples/blog/gems/cache/webrat-0.5.3.gem +0 -0
  124. data/examples/blog/init.rb +0 -49
  125. data/examples/blog/settings.rb +0 -15
  126. data/examples/blog/settings_local.rb +0 -6
  127. data/examples/blog/spec/blog/init_spec.rb +0 -7
  128. data/examples/blog/spec/blog/models_spec.rb +0 -28
  129. data/examples/blog/spec/blog/views_spec.rb +0 -22
  130. data/examples/blog/spec/spec.opts +0 -5
  131. data/examples/blog/spec/spec_helper.rb +0 -27
  132. data/examples/blog/templates/base.html.haml +0 -16
  133. data/examples/blog/templates/index.html.haml +0 -12
  134. data/lib/rango/boot.rb +0 -55
  135. data/lib/rango/helpers/README +0 -179
  136. data/lib/rango/helpers/merb-helpers.rb +0 -3
  137. data/lib/rango/helpers/merb-helpers/core_ext.rb +0 -58
  138. data/lib/rango/helpers/merb-helpers/core_ext/numeric.rb +0 -389
  139. data/lib/rango/helpers/merb-helpers/date_time_formatting.rb +0 -146
  140. data/lib/rango/helpers/merb-helpers/date_time_helpers.rb +0 -191
  141. data/lib/rango/helpers/merb-helpers/form/builder.rb +0 -450
  142. data/lib/rango/helpers/merb-helpers/form/helpers.rb +0 -453
  143. data/lib/rango/helpers/merb-helpers/form_helpers.rb +0 -21
  144. data/lib/rango/helpers/merb-helpers/tag_helpers.rb +0 -63
  145. data/lib/rango/helpers/merb-helpers/text_helpers.rb +0 -73
  146. data/lib/rango/loggers/logger.rb +0 -100
  147. data/lib/rango/mixins/chainable.rb +0 -68
  148. data/lib/rango/mixins/hookable.rb +0 -32
  149. data/lib/rango/mixins/import.rb +0 -89
  150. data/lib/rango/mixins/mini.rb +0 -29
  151. data/lib/rango/mixins/strategy.rb +0 -28
  152. data/lib/rango/rango.rb +0 -93
  153. data/lib/rango/router/specification.txt +0 -11
  154. data/lib/rango/templates/adapter.rb +0 -19
  155. data/lib/rango/templates/adapters/erb.rb +0 -63
  156. data/lib/rango/templates/adapters/erubis.rb +0 -65
  157. data/lib/rango/templates/adapters/haml.rb +0 -26
  158. data/lib/rango/templates/templates.txt +0 -39
  159. data/spec/factories.rb +0 -22
  160. data/spec/rango/boot_spec.rb +0 -15
  161. data/spec/rango/helpers/merb-helpers/core_ext/numeric_spec.rb +0 -0
  162. data/spec/rango/helpers/merb-helpers/core_ext_spec.rb +0 -21
  163. data/spec/rango/helpers/merb-helpers/date_time_formatting_spec.rb +0 -0
  164. data/spec/rango/helpers/merb-helpers/date_time_helpers_spec.rb +0 -0
  165. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/application.rb +0 -4
  166. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_check_box.rb +0 -4
  167. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_file_field.rb +0 -4
  168. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_hidden_field.rb +0 -4
  169. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_option_tag.rb +0 -4
  170. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_password_field.rb +0 -4
  171. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_radio_button.rb +0 -4
  172. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_radio_group.rb +0 -4
  173. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_select.rb +0 -4
  174. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_text_area.rb +0 -4
  175. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_text_field.rb +0 -4
  176. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/button.rb +0 -4
  177. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/check_box.rb +0 -4
  178. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/custom_builder.rb +0 -4
  179. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/delete_button.rb +0 -4
  180. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/exceptions.rb +0 -25
  181. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/field_set.rb +0 -4
  182. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/fields_for.rb +0 -3
  183. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/file_field.rb +0 -4
  184. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/foo.rb +0 -23
  185. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/form.rb +0 -4
  186. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/form_for.rb +0 -4
  187. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/hacker.rb +0 -4
  188. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/hidden_field.rb +0 -4
  189. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/label.rb +0 -4
  190. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/numeric_ext.rb +0 -4
  191. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/option_tag.rb +0 -4
  192. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/password_field.rb +0 -4
  193. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/radio_button.rb +0 -4
  194. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/radio_group.rb +0 -4
  195. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/relative_date.rb +0 -4
  196. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/relative_date_span.rb +0 -4
  197. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/select.rb +0 -4
  198. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/specs_controller.rb +0 -13
  199. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/submit.rb +0 -4
  200. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/tag_helper.rb +0 -23
  201. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/text_area.rb +0 -4
  202. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/text_field.rb +0 -4
  203. data/spec/rango/helpers/merb-helpers/fixture/app/helpers/global_helpers.rb +0 -7
  204. data/spec/rango/helpers/merb-helpers/fixture/app/models/fake_dm_model.rb +0 -27
  205. data/spec/rango/helpers/merb-helpers/fixture/app/models/first_generic_fake_model.rb +0 -59
  206. data/spec/rango/helpers/merb-helpers/fixture/app/models/hacker_generic_model.rb +0 -7
  207. data/spec/rango/helpers/merb-helpers/fixture/app/models/second_generic_fake_model.rb +0 -20
  208. data/spec/rango/helpers/merb-helpers/fixture/app/models/third_generic_fake_model.rb +0 -5
  209. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/basic.html.erb +0 -4
  210. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/basic_unchecked.html.erb +0 -3
  211. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/checked.html.erb +0 -4
  212. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/errors.html.erb +0 -4
  213. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/label.html.erb +0 -3
  214. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/on_and_off.html.erb +0 -3
  215. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/raise_value_error.html.erb +0 -3
  216. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_file_field_specs/additional_attributes.html.erb +0 -3
  217. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_file_field_specs/takes_string.html.erb +0 -3
  218. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_file_field_specs/with_label.html.erb +0 -3
  219. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_hidden_field_specs/basic.html.erb +0 -3
  220. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_hidden_field_specs/errors.html.erb +0 -3
  221. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_hidden_field_specs/hidden_error.html.erb +0 -3
  222. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_hidden_field_specs/label.html.erb +0 -3
  223. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_option_tag_specs/grouped.html.erb +0 -3
  224. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_option_tag_specs/nested.html.erb +0 -3
  225. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_option_tag_specs/text_and_value.html.erb +0 -4
  226. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_password_field_specs/attributes.html.erb +0 -3
  227. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_password_field_specs/basic.html.erb +0 -3
  228. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_password_field_specs/label.html.erb +0 -3
  229. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_radio_button_specs/basic.html.erb +0 -3
  230. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_radio_group_specs/basic.html.erb +0 -3
  231. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_radio_group_specs/hashes.html.erb +0 -3
  232. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_radio_group_specs/mixed.html.erb +0 -4
  233. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_radio_group_specs/override_id.html.erb +0 -3
  234. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/basic.html.erb +0 -3
  235. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/blank.html.erb +0 -3
  236. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/label.html.erb +0 -3
  237. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/multiple.html.erb +0 -3
  238. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/prompt.html.erb +0 -3
  239. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/with_options.html.erb +0 -3
  240. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/with_options_with_blank.html.erb +0 -3
  241. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_text_area_specs/basic.html.erb +0 -3
  242. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_text_area_specs/label.html.erb +0 -3
  243. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_text_field_specs/basic.html.erb +0 -3
  244. data/spec/rango/helpers/merb-helpers/fixture/app/views/button_specs/button_with_label.html.erb +0 -1
  245. data/spec/rango/helpers/merb-helpers/fixture/app/views/button_specs/button_with_values.html.erb +0 -1
  246. data/spec/rango/helpers/merb-helpers/fixture/app/views/button_specs/disabled_button.html.erb +0 -1
  247. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/basic.html.erb +0 -1
  248. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/boolean.html.erb +0 -1
  249. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/disabled.html.erb +0 -1
  250. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/label.html.erb +0 -1
  251. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/on_off_is_boolean.html.erb +0 -1
  252. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/raise_unless_both_on_and_off.html.erb +0 -2
  253. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/raises_error_if_not_boolean.html.erb +0 -1
  254. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/raises_error_if_on_off_and_boolean_false.html.erb +0 -1
  255. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/simple.html.erb +0 -1
  256. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/to_string.html.erb +0 -8
  257. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/unchecked.html.erb +0 -2
  258. data/spec/rango/helpers/merb-helpers/fixture/app/views/custom_builder_specs/everything.html.erb +0 -10
  259. data/spec/rango/helpers/merb-helpers/fixture/app/views/delete_button_specs/delete_with_explicit_url.html.erb +0 -1
  260. data/spec/rango/helpers/merb-helpers/fixture/app/views/delete_button_specs/delete_with_extra_params.html.erb +0 -1
  261. data/spec/rango/helpers/merb-helpers/fixture/app/views/delete_button_specs/delete_with_label.html.erb +0 -1
  262. data/spec/rango/helpers/merb-helpers/fixture/app/views/delete_button_specs/simple_delete.html.erb +0 -1
  263. data/spec/rango/helpers/merb-helpers/fixture/app/views/exeptions/client_error.html.erb +0 -37
  264. data/spec/rango/helpers/merb-helpers/fixture/app/views/exeptions/internal_server_error.html.erb +0 -216
  265. data/spec/rango/helpers/merb-helpers/fixture/app/views/exeptions/not_acceptable.html.erb +0 -38
  266. data/spec/rango/helpers/merb-helpers/fixture/app/views/exeptions/not_found.html.erb +0 -40
  267. data/spec/rango/helpers/merb-helpers/fixture/app/views/fields_for_specs/basic.html.erb +0 -3
  268. data/spec/rango/helpers/merb-helpers/fixture/app/views/fields_for_specs/midstream.html.erb +0 -7
  269. data/spec/rango/helpers/merb-helpers/fixture/app/views/fields_for_specs/nil.html.erb +0 -3
  270. data/spec/rango/helpers/merb-helpers/fixture/app/views/fieldset_specs/legend.html.erb +0 -3
  271. data/spec/rango/helpers/merb-helpers/fixture/app/views/file_field_specs/disabled.html.erb +0 -1
  272. data/spec/rango/helpers/merb-helpers/fixture/app/views/file_field_specs/makes_multipart.html.erb +0 -3
  273. data/spec/rango/helpers/merb-helpers/fixture/app/views/file_field_specs/with_label.html.erb +0 -1
  274. data/spec/rango/helpers/merb-helpers/fixture/app/views/file_field_specs/with_values.html.erb +0 -1
  275. data/spec/rango/helpers/merb-helpers/fixture/app/views/foo/bar.html.erb +0 -0
  276. data/spec/rango/helpers/merb-helpers/fixture/app/views/form_for_specs/basic.html.erb +0 -3
  277. data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/create_a_form.html.erb +0 -3
  278. data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/create_a_multipart_form.html.erb +0 -3
  279. data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/fake_delete_if_set.html.erb +0 -3
  280. data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/fake_put_if_set.html.erb +0 -3
  281. data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/get_if_set.html.erb +0 -3
  282. data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/post_by_default.html.erb +0 -3
  283. data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/resourceful_form.html.erb +0 -3
  284. data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/file_field.html.erb +0 -3
  285. data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/hidden_field.html.erb +0 -3
  286. data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/option_tag.html.erb +0 -4
  287. data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/password_field.html.erb +0 -3
  288. data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/radio_button.html.erb +0 -3
  289. data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/radio_group.html.erb +0 -3
  290. data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/text_area.html.erb +0 -3
  291. data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/text_field.html.erb +0 -3
  292. data/spec/rango/helpers/merb-helpers/fixture/app/views/hidden_field_specs/basic.html.erb +0 -1
  293. data/spec/rango/helpers/merb-helpers/fixture/app/views/hidden_field_specs/disabled.html.erb +0 -1
  294. data/spec/rango/helpers/merb-helpers/fixture/app/views/hidden_field_specs/label.html.erb +0 -1
  295. data/spec/rango/helpers/merb-helpers/fixture/app/views/label_specs/basic.html.erb +0 -1
  296. data/spec/rango/helpers/merb-helpers/fixture/app/views/label_specs/basic_with_attributes.html.erb +0 -1
  297. data/spec/rango/helpers/merb-helpers/fixture/app/views/label_specs/basic_with_class.html.erb +0 -1
  298. data/spec/rango/helpers/merb-helpers/fixture/app/views/layout/application.html.erb +0 -11
  299. data/spec/rango/helpers/merb-helpers/fixture/app/views/numeric_ext_specs/minutes_to_hours.html.erb +0 -1
  300. data/spec/rango/helpers/merb-helpers/fixture/app/views/numeric_ext_specs/to_concurrency_default.html.erb +0 -1
  301. data/spec/rango/helpers/merb-helpers/fixture/app/views/numeric_ext_specs/two_digits.html.erb +0 -1
  302. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/array.html.erb +0 -1
  303. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/clean.html.erb +0 -1
  304. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/collection.html.erb +0 -1
  305. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/multiple_selects.html.erb +0 -1
  306. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/no_extra_attributes.html.erb +0 -1
  307. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/optgroups.html.erb +0 -1
  308. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/selected.html.erb +0 -1
  309. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/with_blank.html.erb +0 -1
  310. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/with_prompt.html.erb +0 -1
  311. data/spec/rango/helpers/merb-helpers/fixture/app/views/password_field_specs/basic.html.erb +0 -1
  312. data/spec/rango/helpers/merb-helpers/fixture/app/views/password_field_specs/disabled.html.erb +0 -1
  313. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_button_specs/basic.html.erb +0 -1
  314. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_button_specs/checked.html.erb +0 -1
  315. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_button_specs/disabled.html.erb +0 -1
  316. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_button_specs/label.html.erb +0 -1
  317. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_button_specs/unchecked.html.erb +0 -1
  318. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_group_specs/attributes.html.erb +0 -1
  319. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_group_specs/basic.html.erb +0 -1
  320. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_group_specs/checked.html.erb +0 -1
  321. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_group_specs/hash.html.erb +0 -1
  322. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_group_specs/specific_attributes.html.erb +0 -1
  323. data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_span_specs/date_span_on_same_day.html.erb +0 -1
  324. data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_span_specs/date_span_on_same_day_on_different_year.html.erb +0 -1
  325. data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_specs/relative_date_with_year.html.erb +0 -1
  326. data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_specs/relative_date_without_year.html.erb +0 -1
  327. data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_specs/relative_today.html.erb +0 -1
  328. data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_specs/relative_tomorrow.html.erb +0 -1
  329. data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_specs/relative_yesterday.html.erb +0 -1
  330. data/spec/rango/helpers/merb-helpers/fixture/app/views/select_specs/basic.html.erb +0 -1
  331. data/spec/rango/helpers/merb-helpers/fixture/app/views/select_specs/blank.html.erb +0 -1
  332. data/spec/rango/helpers/merb-helpers/fixture/app/views/select_specs/multiple.html.erb +0 -1
  333. data/spec/rango/helpers/merb-helpers/fixture/app/views/select_specs/selected.html.erb +0 -1
  334. data/spec/rango/helpers/merb-helpers/fixture/app/views/submit_specs/disabled_submit.html.erb +0 -1
  335. data/spec/rango/helpers/merb-helpers/fixture/app/views/submit_specs/submit_with_label.html.erb +0 -1
  336. data/spec/rango/helpers/merb-helpers/fixture/app/views/submit_specs/submit_with_values.html.erb +0 -1
  337. data/spec/rango/helpers/merb-helpers/fixture/app/views/tag_helper/nested_tags.html.erb +0 -5
  338. data/spec/rango/helpers/merb-helpers/fixture/app/views/tag_helper/tag_with_attributes.html.erb +0 -1
  339. data/spec/rango/helpers/merb-helpers/fixture/app/views/tag_helper/tag_with_content.html.erb +0 -1
  340. data/spec/rango/helpers/merb-helpers/fixture/app/views/tag_helper/tag_with_content_in_the_block.html.erb +0 -3
  341. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_area_specs/basic.html.erb +0 -1
  342. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_area_specs/disabled.html.erb +0 -1
  343. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_area_specs/label.html.erb +0 -1
  344. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_area_specs/nil.html.erb +0 -1
  345. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_field_specs/basic.html.erb +0 -1
  346. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_field_specs/class.html.erb +0 -1
  347. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_field_specs/disabled.html.erb +0 -1
  348. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_field_specs/label.html.erb +0 -1
  349. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_field_specs/symbolized_name.html.erb +0 -1
  350. data/spec/rango/helpers/merb-helpers/fixture/config/environments/development.rb +0 -8
  351. data/spec/rango/helpers/merb-helpers/fixture/config/environments/production.rb +0 -7
  352. data/spec/rango/helpers/merb-helpers/fixture/config/environments/test.rb +0 -8
  353. data/spec/rango/helpers/merb-helpers/fixture/config/init.rb +0 -48
  354. data/spec/rango/helpers/merb-helpers/fixture/config/rack.rb +0 -13
  355. data/spec/rango/helpers/merb-helpers/fixture/config/router.rb +0 -40
  356. data/spec/rango/helpers/merb-helpers/fixture/public/images/merb.jpg +0 -0
  357. data/spec/rango/helpers/merb-helpers/fixture/public/merb.fcgi +0 -4
  358. data/spec/rango/helpers/merb-helpers/fixture/public/stylesheets/master.css +0 -119
  359. data/spec/rango/helpers/merb-helpers/form/builder_spec.rb +0 -0
  360. data/spec/rango/helpers/merb-helpers/form/helpers_spec.rb +0 -0
  361. data/spec/rango/helpers/merb-helpers/form_helpers_spec.rb +0 -0
  362. data/spec/rango/helpers/merb-helpers/merb_helpers_config_spec.rb +0 -85
  363. data/spec/rango/helpers/merb-helpers/merb_helpers_date_time_spec.rb +0 -270
  364. data/spec/rango/helpers/merb-helpers/merb_helpers_form_spec.rb +0 -1372
  365. data/spec/rango/helpers/merb-helpers/merb_helpers_tag_helper_spec.rb +0 -46
  366. data/spec/rango/helpers/merb-helpers/merb_helpers_text_spec.rb +0 -71
  367. data/spec/rango/helpers/merb-helpers/numeric_extlib_spec.rb +0 -138
  368. data/spec/rango/helpers/merb-helpers/ordinalize_spec.rb +0 -55
  369. data/spec/rango/helpers/merb-helpers/tag_helpers_spec.rb +0 -0
  370. data/spec/rango/helpers/merb-helpers/text_helpers_spec.rb +0 -0
  371. data/spec/rango/helpers/merb-helpers_spec.rb +0 -0
  372. data/spec/rango/mixins/chainable_spec.rb +0 -0
  373. data/spec/rango/mixins/hookable_spec.rb +0 -0
  374. data/spec/rango/mixins/import_spec.rb +0 -0
  375. data/spec/rango/mixins/mini_spec.rb +0 -0
  376. data/spec/rango/mixins/strategy_spec.rb +0 -0
  377. data/spec/rango/rango_spec.rb +0 -0
  378. data/spec/rango/templates/adapter_spec.rb +0 -0
  379. data/spec/rango/templates/adapters/erb_spec.rb +0 -0
  380. data/spec/rango/templates/adapters/erubis_spec.rb +0 -117
  381. data/spec/rango/templates/adapters/haml_spec.rb +0 -0
  382. data/spec/rango/templates/adapters/template_helpers.rb +0 -38
@@ -1,1372 +0,0 @@
1
- # encoding: utf-8
2
-
3
- __END__
4
- require_relative "../../../spec_helper"
5
- require "rango/helpers/merb-helpers/form_helpers"
6
-
7
- # Quick rundown of how these specs work
8
- # please read before hacking on this plugin
9
- #
10
- # helpers must be tested through then entire stack
11
- # what that means is that each spec must
12
- # send a request to a controller and render a template
13
- #
14
- # Start by creating a spec controller subclassing SpecController
15
- # which itself is a subclass of Rango::Controller
16
- # specs_controller.rb (available at spec/fixture/app/controllers/specs_controller.rb)
17
- # defines SpecController.
18
- # Create a new controller in the spec/fixture/app/controllers/ if you are adding a new helper
19
- #
20
- # To test your helper, start by initializing a controller
21
- #
22
- # @controller = CustomHelperSpecs.new(Rango::Request.new({}))
23
- #
24
- # Note that we are sending a real request to the controller, feel free to use the request as needed
25
- #
26
- # You might need to access real objects in your views
27
- # you can do that by setting them up in the controller
28
- #
29
- # @obj = FakeModel.new # FaKeModel is defined in spec/fixture/models/first_generic_fake_model.rb check it out!
30
- # @controller.instance_variable_set(:@obj, @obj)
31
- #
32
- # To test a helper, you need to render a view:
33
- #
34
- # result = @controller.render :view_name
35
- #
36
- # Of course, you need to create a view:
37
- # spec/fixture/app/views/custom_helper_specs/view_name.html.erb
38
- # in the view, call the helper you want to test
39
- #
40
- # You can now test the helper in the view:
41
- # result.should match_tag(:form, :method => "post")
42
- #
43
-
44
-
45
- # Rango::Plugins.config[:helpers] = {
46
- # :default_builder => Rango::Helpers::Form::Builder::FormWithErrors
47
- # }
48
-
49
- describe "error_messages_for" do
50
- before :each do
51
- @c = Application.new({})
52
- @dm_obj = Object.new
53
- @sq_obj = Object.new
54
- @dm_errors = [["foo", "bar"],["baz","bat"]]
55
- @sq_errors = Object.new
56
- @sq_errors.stub!(:full_messages).and_return(["foo", "baz"])
57
- @dm_obj.stub!(:errors).and_return(@dm_errors)
58
- @dm_obj.stub!(:new_record?).and_return(false)
59
- @sq_obj.stub!(:errors).and_return(@sq_errors)
60
- @sq_obj.stub!(:new_record?).and_return(false)
61
- end
62
-
63
- it "should build default error messages for AR-like models" do
64
- errs = @c.error_messages_for(@dm_obj)
65
- errs.should include("<h2>Form submission failed because of 2 problems</h2>")
66
- errs.should include("<li>foo bar</li>")
67
- errs.should include("<li>baz bat</li>")
68
- end
69
-
70
- it "should build default error messages for Sequel-like models" do
71
- errs = @c.error_messages_for(@sq_obj)
72
- errs.should include("<h2>Form submission failed because of 2 problems</h2>")
73
- errs.should include("<li>foo</li>")
74
- errs.should include("<li>baz</li>")
75
- end
76
-
77
- # it "should build default error messages for symbol" do
78
- # errs = error_messages_for(:obj)
79
- # errs.should include("<h2>Form submittal failed because of 2 problems</h2>")
80
- # errs.should include("<li>foo bar</li>")
81
- # errs.should include("<li>baz bat</li>")
82
- # end
83
-
84
- it "should accept a custom HTML class" do
85
- errs = @c.error_messages_for(@dm_obj, :error_class => "foo")
86
- errs.should include("<div class='foo'>")
87
- end
88
-
89
- it "should accept a custom header block" do
90
- errs = @c.error_messages_for(@dm_obj, :header => "<h3>Failure: %s issue%s</h3>")
91
- errs.should include("<h3>Failure: 2 issues</h3>")
92
- end
93
-
94
- # it "should put the error messages inside a form if :before is false" do
95
- # ret = @c.form_for @dm_obj do
96
- # _buffer << error_messages
97
- # end
98
- # ret.should =~ /\A\s*<form.*<div class='error'>/
99
- # end
100
-
101
- end
102
-
103
- describe "form" do
104
-
105
- before :each do
106
- @c = FormSpecs.new(Rango::Request.new({}))
107
- end
108
-
109
- describe "when _default_builder is Rango::Helpers::Form::Builder::ResourcefulFormWithErrors" do
110
-
111
- before(:each) do
112
- @obj = FakeModel2.new
113
- @c.instance_variable_set(:@obj, @obj)
114
- end
115
-
116
- it "should not explode when #form is called" do
117
- r = @c.render :resourceful_form
118
- pending
119
- #r.should =~ /action="fake_model2\/#{@obj.id}"/
120
- end
121
- end
122
-
123
-
124
- it "should use the post method by default" do
125
- ret = @c.render(:post_by_default)
126
- ret.should have_selector("form[method=post]")
127
- ret.should include("CONTENT")
128
- end
129
-
130
- it "should use the get method if set" do
131
- ret = @c.render(:get_if_set)
132
- ret.should have_selector("form[method=get]")
133
- end
134
-
135
- it "should fake out the put method if set" do
136
- ret = @c.render(:fake_put_if_set)
137
- ret.should have_selector("form[method=post]")
138
- ret.should have_selector("input[type=hidden][name=_method][value=put]")
139
- end
140
-
141
- it "should fake out the delete method if set" do
142
- ret = @c.render(:fake_delete_if_set)
143
- ret.should have_selector("form[method=post]")
144
- ret.should have_selector("input[type=hidden][name=_method][value=delete]")
145
- end
146
-
147
- # TODO: Why is this required?
148
- # ---------------------------
149
- #
150
- # it "should silently set method to post if an unsupported method is used" do
151
- # form_tag :method => :dodgy do
152
- # _buffer << "CONTENT"
153
- # end
154
- # _buffer.should match_tag(:form, :method => "post")
155
- # _buffer.should_not match_tag(:input, :type => "hidden", :name => "_method", :value => "dodgy")
156
- # end
157
-
158
- it "should take create a form" do
159
- ret = @c.render(:create_a_form)
160
- ret.should have_selector("form[action=foo][method=post]")
161
- ret.should include("Hello")
162
- end
163
-
164
- it "should set a form to be multipart" do
165
- ret = @c.render(:create_a_multipart_form)
166
- ret.should have_selector("form[action=foo][method=post][enctype='multipart/form-data']")
167
- ret.should include("CONTENT")
168
- end
169
- end
170
-
171
-
172
- describe "form_for" do
173
-
174
- before :each do
175
- @c = FormForSpecs.new(Rango::Request.new({}))
176
- @c.instance_variable_set(:@obj, FakeModel.new)
177
- end
178
-
179
- it "should wrap the contents in a form tag" do
180
- form = @c.render :basic
181
- form.should have_selector("form[method=post]")
182
- form.should have_selector("input[type=hidden][value=put][name=_method]")
183
- end
184
-
185
- it "should set the method to post be default" do
186
- new_fake_model = FakeModel2.new
187
- @c.instance_variable_set(:@obj, new_fake_model)
188
- form = @c.render :basic
189
- form.should have_selector("form[method=post]")
190
- form.should_not have_selector("input[type=hidden][name=_method]")
191
- end
192
-
193
- it "should support PUT if the object passed in is not a new_record? via a hidden field" do
194
- form = @c.render :basic
195
- form.should have_selector("form[method=post]")
196
- form.should have_selector("input[type=hidden][value=put][name=_method]")
197
- end
198
-
199
- end
200
-
201
-
202
- describe "fields_for" do
203
-
204
- before :each do
205
- @c = FieldsForSpecs.new(Rango::Request.new({}))
206
- @c.instance_variable_set(:@obj, FakeModel.new)
207
- end
208
-
209
-
210
- it "should dump the contents in the context of the object" do
211
- r = @c.render :basic
212
- r.should have_selector("input[type=text][value=foowee]")
213
- end
214
-
215
- it "should be able to modify the context midstream" do
216
- @c.instance_variable_set(:@obj2, FakeModel2.new)
217
- r = @c.render :midstream
218
- r.should have_selector("input[type=text][value=foowee]")
219
- r.should have_selector("input[name='fake_model2[foo]'][type=text][value=foowee2]")
220
- end
221
-
222
- it "should handle an explicit nil attribute" do
223
- r = @c.render :nil
224
- r.should have_selector("input[name='fake_model[foo]'][value=foowee][type=text]")
225
- end
226
-
227
- it "should pass context back to the old object after exiting block" do
228
- @c.instance_variable_set(:@obj2, FakeModel2.new)
229
- r = @c.render :midstream
230
- r.should have_selector("input[id=fake_model_foo][name='fake_model[foo]'][type=text][extra=true]")
231
- end
232
- end
233
-
234
- describe "text_field" do
235
-
236
- before :each do
237
- @c = TextFieldSpecs.new(Rango::Request.new({}))
238
- end
239
-
240
- it "should return a basic text field based on the values passed in" do
241
- r = @c.render :basic
242
- r.should have_selector("input[type=text][id=foo][name=foo][value=bar]")
243
- end
244
-
245
- it "should update an existing :class with a new class" do
246
- r = @c.render :class
247
- r.should == "<input type=\"text\" class=\"awesome foobar text\"/>"
248
- end
249
-
250
- it "should be disabled if :disabled => true is passed in" do
251
- r = @c.render :disabled
252
- r.should have_selector("input[type=text][disabled=disabled]")
253
- end
254
-
255
- it "should provide an additional label tag if the :label option is passed in as a hash" do
256
- r = @c.render :label
257
- r.should have_selector("label[class=cool][for=foo]:contains('LABEL')")
258
- end
259
-
260
- it "should allow a symbolized name" do
261
- r = @c.render :symbolized_name
262
- r.should have_selector("input[type=text][name=foo][value=bar]")
263
- r.should have_selector("label[for=foo]:contains('LABEL')")
264
- end
265
- end
266
-
267
- describe "bound_text_field" do
268
-
269
- before :each do
270
- @c = BoundTextFieldSpecs.new(Rango::Request.new({}))
271
- @c.instance_variable_set(:@obj, FakeModel.new)
272
- end
273
-
274
- it "should take a string object and return a useful text control" do
275
- r = @c.render :basic
276
- r.should have_selector("input[type=text][id=fake_model_foo][name='fake_model[foo]'][value=foowee]")
277
- end
278
-
279
- it "should take additional attributes and use them" do
280
- r = @c.render :basic
281
- r.should have_selector("input[type=text][name='fake_model[foo]'][value=foowee][bar='7']")
282
- end
283
-
284
- it "should provide an additional label tag if the :label option is passed in" do
285
- form = @c.render :basic
286
- form.should match(/<label.*>LABEL<\/label><input/)
287
- form.should_not have_selector("input[label=LABEL]")
288
- end
289
-
290
- it "should render the label tag with the proper for= atttribute" do
291
- form = @c.render :basic
292
- form.should have_selector("label[for=fake_model_foo]:contains('LABEL')")
293
- end
294
-
295
- it "should not errorify the field for a new object" do
296
- r = @c.render :basic
297
- r.should_not have_selector("input[type=text][name='fake_model[foo]'][class=error]")
298
- end
299
-
300
- it "should errorify a field for a model with errors" do
301
- model = mock("model")
302
- model.stub!(:new_record?).and_return(true)
303
- model.stub!(:class).and_return("MyClass")
304
- model.stub!(:foo).and_return("FOO")
305
- errors = mock("errors")
306
- errors.should_receive(:on).with(:foo).and_return(true)
307
-
308
- model.stub!(:errors).and_return(errors)
309
- @c.instance_variable_set(:@obj, model)
310
- r = @c.render :basic
311
- r.should have_selector("input[class='error text']")
312
- end
313
- end
314
-
315
- describe "bound_radio_button" do
316
-
317
- before :each do
318
- @c = BoundRadioButtonSpecs.new(Rango::Request.new({}))
319
- @c.instance_variable_set(:@obj, FakeModel.new)
320
- end
321
-
322
- it "should take a string object and return a useful text control" do
323
- r = @c.render :basic
324
- r.should have_selector("input[type=radio][id=fake_model_foo][name='fake_model[foo]'][value=foowee]")
325
- end
326
-
327
- it "should take additional attributes and use them" do
328
- r = @c.render :basic
329
- r.should have_selector("input[type=radio][name='fake_model[foo]'][value=foowee][bar='7']")
330
- end
331
-
332
- it "should provide an additional label tag if the :label option is passed in" do
333
- form = @c.render :basic
334
- form.should have_selector("input + label:contains('LABEL')")
335
- form.should_not have_selector("input[label]")
336
- end
337
-
338
- it "should render the label tag with the proper for= atttribute" do
339
- form = @c.render :basic
340
- form.should have_selector("label[for=fake_model_foo]:contains('LABEL')")
341
- end
342
-
343
- it "should not errorify the field for a new object" do
344
- r = @c.render :basic
345
- r.should_not have_selector("input[type=radio][name='fake_model[foo]'][class=error]")
346
- end
347
-
348
- it "should errorify a field for a model with errors" do
349
- model = mock("model")
350
- model.stub!(:new_record?).and_return(true)
351
- model.stub!(:class).and_return("MyClass")
352
- model.stub!(:foo).and_return("FOO")
353
- errors = mock("errors")
354
- errors.should_receive(:on).with(:foo).and_return(true)
355
-
356
- model.stub!(:errors).and_return(errors)
357
- @c.instance_variable_set(:@obj, model)
358
- r = @c.render :basic
359
- r.should have_selector("input[class='error radio']")
360
- end
361
- end
362
-
363
- describe "password_field" do
364
-
365
- before :each do
366
- @c = PasswordFieldSpecs.new(Rango::Request.new({}))
367
- end
368
-
369
- it "should return a basic password field, but omit the value" do
370
- r = @c.render :basic
371
- r.should have_selector("input[type=password][id=foo][name=foo]")
372
- end
373
-
374
- it "should provide an additional label tag if the :label option is passed in" do
375
- r = @c.render :basic
376
- r.should have_selector("label[for=foo]:contains('LABEL')")
377
- end
378
-
379
- it "should be disabled if :disabled => true is passed in" do
380
- r = @c.render :disabled
381
- r.should match_tag(:input, :type => "password", :disabled => "disabled")
382
- end
383
- end
384
-
385
- describe "bound_password_field" do
386
-
387
- before :each do
388
- @c = BoundPasswordFieldSpecs.new(Rango::Request.new({}))
389
- @obj = FakeModel.new
390
- @c.instance_variable_set(:@obj, @obj)
391
- end
392
-
393
- it "should take a string object and return a useful password control, but omit the value" do
394
- r = @c.render :basic
395
- r.should match_tag(:input, :type => "password", :id => "fake_model_foo", :name => "fake_model[foo]")
396
- end
397
-
398
- it "should take additional attributes and use them" do
399
- r = @c.render :basic
400
- r.should match_tag(:input, :type => "password", :name => "fake_model[foo]", :bar => "7", :value => @obj.foo)
401
- end
402
-
403
- it "should provide an additional label tag if the :label option is passed in" do
404
- r = @c.render :basic
405
- r.should match(/<label.*>LABEL<\/label><input/)
406
- r.should_not match_tag(:input, :label => "LABEL")
407
- end
408
-
409
- it "should render the label tag with the proper for= atttribute" do
410
- form = @c.render :basic
411
- form.should have_selector("label[for=fake_model_foo]:contains('LABEL')")
412
- end
413
-
414
- it "should not errorify the field for a new object" do
415
- r = @c.render :basic
416
- r.should_not match_tag(:input, :class => "error")
417
- end
418
-
419
- it "should errorify a field for a model with errors" do
420
- model = mock("model")
421
- model.stub!(:new_record?).and_return(true)
422
- model.stub!(:class).and_return("MyClass")
423
- model.stub!(:foo).and_return("FOO")
424
- errors = mock("errors")
425
- errors.should_receive(:on).with(:foo).and_return(true)
426
-
427
- model.stub!(:errors).and_return(errors)
428
-
429
- @c.instance_variable_set(:@obj, model)
430
- r = @c.render :basic
431
- r.should match_tag(:input, :class => "error password")
432
- end
433
-
434
- end
435
-
436
- describe "check_box" do
437
-
438
- before :each do
439
- @c = CheckBoxSpecs.new(Rango::Request.new({}))
440
- end
441
-
442
- it "should return a basic checkbox based on the values passed in" do
443
- r = @c.render :basic
444
- r.should match_tag(:input, :class => "checkbox", :id => "foo", :name => "foo", :checked => "checked")
445
- end
446
-
447
- it "should provide an additional label tag if the :label option is passed in" do
448
- result = @c.render :label
449
- result.should have_selector("label[for=foo]:contains('LABEL')")
450
-
451
- result.should match(/<input.*><label/)
452
- res = result.scan(/<[^>]*>/)
453
- res[0].should_not match_tag(:input, :label => "LABEL")
454
- end
455
-
456
- it 'should remove the checked="checked" attribute if :checked is false or nil' do
457
- r = @c.render :unchecked
458
- r.should_not include('checked="')
459
- end
460
-
461
- it 'should have the checked="checked" attribute if :checked => true is passed in' do
462
- r = @c.render :basic
463
- r.should include('checked="checked"')
464
- end
465
-
466
- it "should not be boolean by default" do
467
- r = @c.render :basic
468
- r.should match_tag(:input, :type => "checkbox", :name => "foo")
469
- end
470
-
471
- it "should add a hidden input if boolean" do
472
- r = @c.render :boolean
473
- r.should have_tag(:input, :type => "checkbox", :value => "1")
474
- r.should have_tag(:input, :type => "hidden", :value => "0")
475
- r.should match(/<input.*?type="hidden"[^>]*>[^<]*<input.*?type="checkbox"[^>]*>/)
476
-
477
- end
478
-
479
- it "should not allow a :value param if boolean" do
480
- lambda { @c.render :raises_error_if_not_boolean }.
481
- should raise_error(ArgumentError, /can't be used with a boolean checkbox/)
482
- end
483
-
484
- it "should not allow :boolean => false if :on and :off are specified" do
485
- lambda { @c.render :raises_error_if_on_off_and_boolean_false }.
486
- should raise_error(ArgumentError, /cannot be used/)
487
- end
488
-
489
- it "should be boolean if :on and :off are specified" do
490
- html = @c.render :on_off_is_boolean
491
- html.should have_tag(:input, :type => "checkbox", :value => "YES", :name => "foo")
492
- html.should have_tag(:input, :type => "hidden", :value => "NO", :name => "foo")
493
- end
494
-
495
- it "should have both :on and :off specified or neither" do
496
- lambda { @c.render :raise_unless_both_on_and_off }.should raise_error(ArgumentError, /must be specified/)
497
- lambda { @c.render :raise_unless_both_on_and_off }.should raise_error(ArgumentError, /must be specified/)
498
- end
499
-
500
- it "should convert :value to a string on a non-boolean checkbox" do
501
- r = @c.render :to_string
502
- r.should match_tag(:input, :value => "")
503
- r.should match_tag(:input, :value => "false")
504
- r.should match_tag(:input, :value => "0")
505
- r.should match_tag(:input, :value => "0")
506
- r.should match_tag(:input, :value => "1")
507
- r.should match_tag(:input, :value => "1")
508
- r.should match_tag(:input, :value => "true")
509
- end
510
-
511
- it "should be disabled if :disabled => true is passed in" do
512
- r = @c.render :disabled
513
- r.should match_tag(:input, :type => "checkbox", :disabled => "disabled")
514
- end
515
-
516
- it "should be possible to call with just check_box" do
517
- r = @c.render :simple
518
- r.should match_tag(:input, :type => "checkbox", :class => "checkbox")
519
- end
520
- end
521
-
522
- describe "bound_check_box" do
523
-
524
- before :each do
525
- @c = BoundCheckBoxSpecs.new(Rango::Request.new({}))
526
- @c.instance_variable_set(:@obj, FakeModel.new)
527
- end
528
-
529
- it "should take a string and return a useful checkbox control" do
530
- r = @c.render :basic
531
- r.should match_tag(:input, :type =>"checkbox", :id => "fake_model_baz", :name => "fake_model[baz]", :class => "checkbox", :value => "1", :checked => "checked", :id => "fake_model_baz")
532
- r.should match_tag(:input, :type =>"hidden", :name => "fake_model[baz]", :value => "0")
533
- end
534
-
535
- it "should raise an error if you try to use :value" do
536
- lambda { @c.render(:raise_value_error) }.should raise_error(ArgumentError, /:value can't be used with a bound_check_box/)
537
- end
538
-
539
- it "should support models from datamapper" do
540
- @c.instance_variable_set(:@obj, FakeDMModel.new)
541
- r = @c.render :basic
542
- r.should match_tag(:input,
543
- :type =>"checkbox",
544
- :name => "fake_dm_model[baz]",
545
- :class => "checkbox",
546
- :value => "1",
547
- :checked => "checked",
548
- :id => "fake_dm_model_baz")
549
-
550
- r.should match_tag(:input, :type =>"hidden", :name => "fake_dm_model[bat]", :value => "0")
551
- r.should match_tag(:input, :type =>"checkbox", :name => "fake_dm_model[bat]", :class => "checkbox", :value => "1")
552
- end
553
-
554
- it "should allow a user to set the :off value" do
555
- r = @c.render :on_and_off
556
- r.should match_tag(:input, :type =>"hidden", :name => "fake_model[bat]", :value => "off")
557
- r.should match_tag(:input, :type =>"checkbox", :name => "fake_model[bat]", :class => "checkbox", :value => "on")
558
- end
559
-
560
- it "should render controls with errors if their attribute contains an error" do
561
- r = @c.render :errors
562
- r.should match_tag(:input, :type =>"checkbox", :name => "fake_model[bazbad]", :class => "error checkbox", :value => "1", :checked => "checked")
563
- r.should match_tag(:input, :type =>"hidden", :name => "fake_model[batbad]", :value => "0")
564
- end
565
-
566
- it "should provide an additional label tag if the :label option is passed in" do
567
- form = @c.render :label
568
- form.should match( /<input.*><label.*>LABEL<\/label>/ )
569
- form.should_not match_tag(:input, :label => "LABEL")
570
- end
571
-
572
- it "should render the label tag with the proper for= atttribute" do
573
- form = @c.render :label
574
- form.should have_selector("label[for=fake_model_foo]:contains('LABEL')")
575
- end
576
-
577
- it "should not errorify the field for a new object" do
578
- r = @c.render :basic
579
- r.should_not match_tag(:input, :type => "checkbox", :class => "error checkbox")
580
- end
581
-
582
- it "should errorify a field for a model with errors" do
583
- model = mock("model")
584
- model.stub!(:new_record?).and_return(true)
585
- model.stub!(:class).and_return("MyClass")
586
- model.stub!(:baz).and_return("BAZ")
587
- model.stub!(:bat).and_return("BAT")
588
- errors = mock("errors")
589
- errors.should_receive(:on).with(:baz).and_return(true)
590
- errors.should_receive(:on).with(:bat).and_return(true)
591
-
592
- model.stub!(:errors).and_return(errors)
593
-
594
- @c.instance_variable_set(:@obj, model)
595
- r = @c.render :basic
596
- r.should match_tag(:input, :type => "checkbox", :class => "error checkbox")
597
- end
598
-
599
- it "should be boolean" do
600
- r = @c.render :basic
601
- r.should have_tag(:input, :type => "checkbox", :value => "1")
602
- r.should have_tag(:input, :type => "hidden", :value => "0")
603
- end
604
-
605
- it "should be checked if the value of the model's attribute is equal to the value of :on" do
606
- r = @c.render :checked
607
- r.should match_tag(:input, :type =>"checkbox", :value => "foowee", :checked => "checked")
608
- r.should match_tag(:input, :type =>"checkbox", :value => "YES")
609
- end
610
-
611
- it "should render false attributes as not checked" do
612
- @c.instance_variable_set(:@obj, FakeDMModel.new)
613
- r = @c.render :basic_unchecked
614
- r.should match_tag(:input, :type =>"checkbox", :name => "fake_dm_model[bat]")
615
- r.should_not include("checked=")
616
- end
617
- end
618
-
619
- describe "hidden_field" do
620
-
621
- before :each do
622
- @c = HiddenFieldSpecs.new(Rango::Request.new({}))
623
- end
624
-
625
- it "should return a basic checkbox based on the values passed in" do
626
- r = @c.render :basic
627
- r.should match_tag(:input, :type => "hidden", :id => "foo", :name => "foo", :value => "bar")
628
- end
629
-
630
- it "should not render a label if the :label option is passed in" do
631
- res = @c.render :label
632
- res.should_not match(/<label>LABEL/)
633
- res.should_not match_tag(:input, :label=> "LABEL")
634
- end
635
-
636
- it "should be disabled if :disabled => true is passed in" do
637
- r = @c.render :disabled
638
- r.should match_tag(:input, :type => "hidden", :disabled => "disabled")
639
- end
640
- end
641
-
642
- describe "bound_hidden_field" do
643
-
644
- before :each do
645
- @c = BoundHiddenFieldSpecs.new(Rango::Request.new({}))
646
- @c.instance_variable_set(:@obj, FakeModel.new)
647
- end
648
-
649
- it "should take a string and return a hidden field control" do
650
- r = @c.render :basic
651
- r.should match_tag(:input, :type =>"hidden", :id => "fake_model_foo", :name => "fake_model[foo]", :value => "foowee")
652
- end
653
-
654
- it "should render controls with errors if their attribute contains an error" do
655
- r = @c.render :errors
656
- r.should match_tag(:input, :type =>"hidden", :name => "fake_model[foobad]", :value => "foowee", :class => "error hidden")
657
- end
658
-
659
- it "should not render a label if the :label option is passed in" do
660
- r = @c.render :label
661
- r.should_not match(/<label>LABEL/)
662
- r.should_not match_tag(:input, :label=> "LABEL")
663
- end
664
-
665
- it "should not errorify the field for a new object" do
666
- r = @c.render :basic
667
- r.should_not match_tag(:input, :type => "hidden", :class => "error")
668
- end
669
-
670
- it "should not errorify a field for a model with errors" do
671
- model = mock("model")
672
- model.stub!(:new_record?).and_return(true)
673
- model.stub!(:class).and_return("MyClass")
674
- model.stub!(:foo).and_return("FOO")
675
- errors = mock("errors")
676
- errors.should_receive(:on).with(:foo).and_return(true)
677
-
678
- model.stub!(:errors).and_return(errors)
679
-
680
- @c.instance_variable_set(:@model, model)
681
- r = @c.render :hidden_error
682
- r.should match_tag(:input, :type => "hidden", :name => "my_class[foo]", :class => "error hidden")
683
- end
684
-
685
- end
686
-
687
- describe "radio_button" do
688
-
689
- before :each do
690
- @c = RadioButtonSpecs.new(Rango::Request.new({}))
691
- end
692
-
693
- it "should should return a basic radio button based on the values passed in" do
694
- r = @c.render :basic
695
- r.should match_tag(:input, :type => "radio", :name => "foo", :value => "bar", :id => "baz")
696
- end
697
-
698
- it "should provide an additional label tag if the :label option is passed in" do
699
- result = @c.render :label
700
- result.should match(/<input.*><label.*>LABEL<\/label>/)
701
- res = result.scan(/<[^>]*>/)
702
- res[0].should_not match_tag(:input, :label => "LABEL")
703
- end
704
-
705
- it "should render the label tag with the proper for= atttribute" do
706
- form = @c.render :label
707
- form.should have_selector("label[for='foo']:contains('LABEL')")
708
- end
709
-
710
- it "should be disabled if :disabled => true is passed in" do
711
- r = @c.render :disabled
712
- r.should match_tag(:input, :type => "radio", :disabled => "disabled")
713
- end
714
-
715
- it "should be checked if :checked => true is passed in" do
716
- r = @c.render :checked
717
- r.should match_tag(:input, :type => "radio", :checked => "checked")
718
- end
719
-
720
- it "should be unchecked if :checked => false is passed in" do
721
- r = @c.render :unchecked
722
- r.should_not include("checked=")
723
- end
724
- end
725
-
726
- describe "radio_group" do
727
-
728
- before :each do
729
- @c = RadioGroupSpecs.new(Rango::Request.new({}))
730
- end
731
-
732
- it "should return a group of radio buttons" do
733
- radio = @c.render :basic
734
- radio_tags = radio.scan(/<[^>]*>/)
735
- radio_tags[0].should match_tag(:input, :type => "radio", :value => "foowee")
736
- radio_tags[3].should match_tag(:input, :type => "radio", :value => "baree")
737
- end
738
-
739
- it "should provide an additional label tag for each option in array-based options" do
740
- radio = @c.render :basic
741
- radio.scan( /<input.*?><label.*?>(foowee|baree)<\/label>/ ).size.should == 2
742
- radio = radio.scan(/<[^>]*>/)
743
- radio[0].should_not match_tag(:input, :label => "LABEL")
744
- radio[3].should_not match_tag(:input, :label => "LABEL")
745
- end
746
-
747
- it "should accept array of hashes as options" do
748
- radio = @c.render :hash
749
- radio.scan( /<input.*?><label.*?>(Five|Bar)<\/label>/ ).size.should == 2
750
- radio.scan(/<[^>]*>/).size.should == 6
751
- radio.should match_tag(:input, :value => 5)
752
- radio.should match_tag(:label)
753
- radio.should match_tag(:input, :value => 'bar', :id => 'bar_id')
754
- radio.should match_tag(:label, :for => 'bar_id')
755
- end
756
-
757
- it "should render the label tags on each radio button with the proper for= atttribute" do
758
- form = @c.render :hash
759
- form.should have_selector("label[for='bar_id']:contains('Bar')")
760
- end
761
-
762
- it "should apply attributes to each element" do
763
- radio = @c.render :attributes
764
- radio = radio.scan(/<[^>]*>/)
765
- radio[0].should match_tag(:input, :type => "radio", :value => "foowee", :class => "CLASS radio")
766
- radio[3].should match_tag(:input, :type => "radio", :value => "baree", :class => "CLASS radio")
767
- end
768
-
769
- it "should override universal attributes with specific ones" do
770
- radio = @c.render :specific_attributes
771
- radio = radio.scan(/<[^>]*>/)
772
- radio[0].should match_tag(:input, :type => "radio", :value => "foowee", :class => "CLASS radio")
773
- radio[3].should match_tag(:input, :type => "radio", :value => "baree", :class => "BAREE radio")
774
- end
775
-
776
- it "should allow specifying a checked radio button" do
777
- r = @c.render :checked
778
- r.should match_tag(:input, :value => "bar", :checked => "checked")
779
- end
780
- end
781
-
782
-
783
- describe "bound_radio_group" do
784
-
785
- before do
786
- @c = BoundRadioGroupSpecs.new(Rango::Request.new({}))
787
- @c.instance_variable_set(:@obj, FakeModel.new)
788
- end
789
-
790
- it "should return a group of radio buttons" do
791
- r = @c.render :basic
792
- r.should match_tag(:input, :type => "radio", :id => "fake_model_foo_foowee", :name => "fake_model[foo]", :value => "foowee", :checked => "checked")
793
- r.should match_tag(:input, :type => "radio", :id => "fake_model_foo_baree", :name => "fake_model[foo]", :value => "baree")
794
- r.should_not match_tag(:checked => "checked")
795
- end
796
-
797
- it "should provide an additional label tag for each option in array-based options" do
798
- r = @c.render :basic
799
- r.scan( /<input.*?><label.*?>(foowee|baree)<\/label>/ ).size.should == 2
800
- radio = r.scan(/<[^>]*>/)[2..-2]
801
- radio[0].should_not match_tag(:input, :label => "LABEL")
802
- radio[3].should_not match_tag(:input, :label => "LABEL")
803
- end
804
-
805
- it "should render the label tags on each radio option with the proper for= atttribute" do
806
- form = @c.render :basic
807
- form.should have_selector("label[for=fake_model_foo_foowee]:contains('foowee')")
808
- form.should have_selector("label[for=fake_model_foo_baree]:contains('baree')")
809
- end
810
-
811
- it "should accept array of hashes as options" do
812
- r = @c.render :hashes
813
- r.scan( /<input.*?><label.*?>(Five|Bar)<\/label>/ ).size.should == 2
814
- r.scan(/<[^>]*>/)[2..-2].size.should == 6
815
- r.should match_tag(:input, :value => 5)
816
- r.should match_tag(:label)
817
- r.should match_tag(:input, :value => 'bar', :id => 'bar_id')
818
- r.should match_tag(:label, :for => 'bar_id')
819
- end
820
-
821
- it "should provide autogenerated id for inputs" do
822
- r = @c.render :mixed
823
- r.should match_tag(:input, :id => 'fake_model_foo_bar')
824
- r.should match_tag(:label, :for => 'fake_model_foo_bar')
825
- r.should match_tag(:input, :id => 'fake_model_foo_bar')
826
- r.should match_tag(:label, :for => 'fake_model_foo_bar')
827
- end
828
-
829
- it "should override autogenerated id for inputs with hash-given id" do
830
- r = @c.render :override_id
831
- r.should match_tag(:input, :id => 'bar_id')
832
- r.should match_tag(:label, :for => 'bar_id')
833
- end
834
-
835
- it "should only have one element with the checked property" do
836
- r = @c.render :basic
837
- r.should match_tag(:input, :checked => "checked")
838
- r.should_not match_tag(:input, :checked => "false")
839
- end
840
- end
841
-
842
-
843
- describe "text_area" do
844
-
845
- before do
846
- @c = TextAreaSpecs.new(Rango::Request.new({}))
847
- end
848
-
849
- it "should should return a basic text area based on the values passed in" do
850
- r = @c.render :basic
851
- r.should match_tag(:textarea, :name => "foo", :id => "foo")
852
- end
853
-
854
- it "should handle a nil content" do
855
- r = @c.render :nil
856
- r.should == "<textarea name=\"foo\" id=\"foo\"></textarea>"
857
- end
858
-
859
-
860
- # TODO: Why is this required?
861
- # ---------------------------
862
- #
863
- # it "should handle a nil attributes hash" do
864
- # text_area("CONTENT", nil).should == "<textarea>CONTENT</textarea>"
865
- # end
866
-
867
- it "should render a label when the :label option is passed in" do
868
- result = @c.render :label
869
- result.should match(/<label.*>LABEL<\/label><textarea/)
870
- result.should_not match_tag(:textarea, :label => "LABEL")
871
-
872
- result.should have_selector("label[for=foo]:contains('LABEL')")
873
- end
874
-
875
- it "should be disabled if :disabled => true is passed in" do
876
- r = @c.render :disabled
877
- r.should match_tag(:textarea, :disabled => "disabled")
878
- end
879
- end
880
-
881
- describe "bound_text_area" do
882
-
883
- before do
884
- @c = BoundTextAreaSpecs.new(Rango::Request.new({}))
885
- @obj = FakeModel.new
886
- @c.instance_variable_set(:@obj, @obj)
887
- end
888
-
889
- it "should provide :id attribute" do
890
- r = @c.render :basic
891
- r.should match_tag(:textarea, :id => 'fake_model_foo', :name => "fake_model[foo]")
892
- r.should =~ />\s*#{@obj.foo}\s*</
893
- end
894
-
895
- it "should render the label tag with the proper for= atttribute" do
896
- form = @c.render :label
897
- form.should have_selector("label[for='fake_model_foo']:contains('LABEL')")
898
- end
899
- end
900
-
901
- describe "select" do
902
-
903
- before do
904
- @c = SelectSpecs.new(Rango::Request.new({}))
905
- end
906
-
907
- it "should provide a blank option if you :include_blank" do
908
- r = @c.render :blank
909
- r.should =~ /<option.*>\s*<\/option>/
910
- end
911
-
912
- it "should render the select tag proper attributes" do
913
- r = @c.render :basic
914
- r.should match_tag( :select, :name => "foo", :id => "foo")
915
- r.should have_selector("select[name=foo] option:contains('one')")
916
- r.should have_selector("select[name=foo] option:contains('two')")
917
- r.should have_selector("select[name=foo] option:contains('three')")
918
- end
919
-
920
- it "should allow selecting an option by passing in :selected => 'three'" do
921
- r = @c.render :selected
922
- r.should_not have_selector("select[name=foo] option[selected]:contains('one')")
923
- r.should_not have_selector("select[name=foo] option[selected]:contains('two')")
924
- r.should have_selector("select[name=foo] option[selected]:contains('three')")
925
- end
926
-
927
- it "should render the select tag with suffix '[]' to name when :multiple => true" do
928
- r = @c.render :multiple
929
- r.should match_tag( :select, :name => "foo[]")
930
- end
931
-
932
- it "should render a label when the :label option is passed in" do
933
- result = @c.render :label
934
- result.should have_selector("label[for=foo]:contains('LABEL')")
935
- end
936
- end
937
-
938
- describe "bound_select" do
939
-
940
- before do
941
- @c = BoundSelectSpecs.new(Rango::Request.new({}))
942
- @c.instance_variable_set(:@obj, FakeModel.new)
943
- end
944
-
945
- it "should render the select tag with the correct id and name" do
946
- r = @c.render :basic
947
- r.should match_tag( :select, :id => "fake_model_foo", :name => "fake_model[foo]" )
948
- end
949
-
950
- it "should render the select tag with suffix '[]' to name when :multiple => true" do
951
- r = @c.render :multiple
952
- r.should match_tag( :select, :id => "fake_model_foo", :name => "fake_model[foo][]" )
953
- end
954
-
955
- it "should include a blank option" do
956
- r = @c.render :blank
957
- r.should match_tag(:option, :value => '')
958
- r.should =~ /<option.*>\s*<\/option>/
959
- end
960
-
961
- it "should render a prompt option without a value" do
962
- r = @c.render :prompt
963
- r.should match_tag(:option, :value => '')
964
- r.should =~ /<option.*>Choose<\/option>/
965
- end
966
-
967
- it "should render a select tag with options" do
968
- r = @c.render :with_options
969
- r.should match_tag( :select, :class => "class1 class2", :title=> "This is the title" )
970
- r.should =~ /<select.*>\s*<\/select>/
971
- end
972
-
973
- it "should render a select tag with options and a blank option" do
974
- r = @c.render :with_options_with_blank
975
- r.should match_tag( :select, :title => "TITLE" )
976
- r.should match_tag( :option, :value => '' )
977
- r.should =~ /<option.*>\s*<\/option>/
978
- end
979
-
980
- it "should render the label tag with the proper for= atttribute" do
981
- form = @c.render :label
982
- form.should have_selector("label[for=fake_model_foo]:contains('LABEL')")
983
- end
984
-
985
- # Not sure how this makes any sense
986
- # ---------------------------------
987
- #
988
- # it "should render the text as the value if no text_method is specified" do
989
- # form_for @obj do
990
- # content = select( :foo, :collection => [FakeModel] )
991
- # content.should match_tag( :option, :value => "FakeModel" )
992
- # end
993
- # end
994
-
995
- end
996
-
997
- describe "bound option tags" do
998
-
999
- before do
1000
- @c = BoundOptionTagSpecs.new(Rango::Request.new({}))
1001
- @c.instance_variable_set(:@obj, FakeModel.new)
1002
- end
1003
-
1004
-
1005
- it "should use text_method and value_method for tag generation" do
1006
- r = @c.render :text_and_value
1007
- r.should match_tag( :option, :content => "foowee", :value => "7" )
1008
- r.should match_tag( :option, :content => "foowee2", :value => "barbar" )
1009
-
1010
- # content = options_from_collection_for_select( [FakeModel.new, FakeModel2.new], :text_method => 'foo', :value_method => 'bar' )
1011
- # content.should match_tag( :option, :content => "foowee", :value => "7" )
1012
- # content.should match_tag( :option, :content => "foowee2", :value => "barbar" )
1013
- end
1014
-
1015
- it "should render a hash of arrays as a grouped select box" do
1016
- model1 = FakeModel.new ; model1.make = "Ford" ; model1.model = "Mustang" ; model1.vin = '1'
1017
- model2 = FakeModel.new ; model2.make = "Ford" ; model2.model = "Falcon" ; model2.vin = '2'
1018
- model3 = FakeModel.new ; model3.make = "Holden" ; model3.model = "Commodore" ; model3.vin = '3'
1019
- @c.instance_variable_set(:@model1, model1)
1020
- @c.instance_variable_set(:@model2, model2)
1021
- @c.instance_variable_set(:@model3, model3)
1022
- @c.instance_variable_set(:@collection, [model1, model2, model3].inject({}) {|s,e| (s[e.make] ||= []) << e; s })
1023
- r = @c.render :grouped
1024
- # Blank actually defaults to ""
1025
- r.should =~ /<optgroup label=\"Ford\"><option/
1026
- r.should match_tag( :optgroup, :label => "Ford" )
1027
- r.should match_tag( :option, :selected => "selected", :value => "1", :content => "Mustang" )
1028
- r.should match_tag( :option, :value => "2", :content => "Falcon" )
1029
- r.should match_tag( :optgroup, :label => "Holden" )
1030
- r.should match_tag( :option, :value => "3", :content => "Commodore" )
1031
-
1032
- # collection = [@model1, @model2, @model3].inject({}) {|s,e| (s[e.make] ||= []) << e; s }
1033
- # content = options_from_collection_for_select(collection, :text_method => 'model', :value_method => 'vin', :selected => '1')
1034
- end
1035
-
1036
- it "should render a collection of nested value/content arrays" do
1037
- r = @c.render :nested
1038
- r.should match_tag(:select, :id => "fake_model_foo", :name => "fake_model[foo]")
1039
- r.should match_tag(:option, :value => "small", :content => "Small")
1040
- r.should match_tag(:option, :value => "medium", :content => "Medium")
1041
- r.should match_tag(:option, :value => "large", :content => "Large")
1042
- end
1043
-
1044
- # Is this really worth the extra speed hit? I'm thinking not
1045
- # ----------------------------------------------------------
1046
- #
1047
- # it "should humanize and titlize keys in the label for the option group" do
1048
- # collection = { :some_snake_case_key => [FakeModel.new] }
1049
- # form_for @obj do
1050
- # content = select( :foo, :collection => collection )
1051
- # content.should match_tag( :optgroup, :label => "Some Snake Case Key" )
1052
- # end
1053
- # end
1054
-
1055
- end
1056
-
1057
- #require "hpricot"
1058
-
1059
- describe "option tags" do
1060
-
1061
- before do
1062
- @c = OptionTagSpecs.new(Rango::Request.new({}))
1063
- @c.instance_variable_set(:@collection, [['rabbit','Rabbit'],['horse','Horse'],['bird','Bird']])
1064
- end
1065
-
1066
- it "should provide an option tag for each item in the collection" do
1067
- r = @c.render :collection
1068
- #doc = Hpricot( r )
1069
- #(doc/"option").size.should == 3
1070
- end
1071
-
1072
- it "should provide a blank option" do
1073
- r = @c.render :with_blank
1074
- r.should match_tag( :option, :value => '' )
1075
- end
1076
-
1077
- it "should render the prompt option at the top" do
1078
- r = @c.render :with_prompt
1079
- #ontent = select( :collection => [["foo", "Foo"]], :prompt => 'Choose' )
1080
- r.should match(/<option[^>]*>Choose<\/option>[^<]*<option[^>]*>Foo<\/option>/)
1081
- end
1082
-
1083
- it "should provide selected options by value" do
1084
- r = @c.render :selected
1085
- r.should match_tag( :option, :value => 'rabbit', :selected => 'selected', :content => 'Rabbit' )
1086
- r.should_not match_tag( :option, :value => 'chicken', :selected => nil, :content => 'Chicken' )
1087
- end
1088
-
1089
- it "should handle arrays for selected when :multiple is true" do
1090
- r = @c.render :multiple_selects
1091
- r.should match_tag( :option, :value => 'minutes', :selected => 'selected', :content => 'Time' )
1092
- r.should match_tag( :option, :value => 'dollars', :selected => 'selected', :content => 'Money' )
1093
- end
1094
-
1095
- it "should render a hash of options as optgroup" do
1096
- r = @c.render :optgroups
1097
- r.should match_tag( :optgroup, :label => 'Fruit' )
1098
- r.should match_tag( :optgroup, :label => 'Vegetables' )
1099
- r.should match_tag( :option, :value => 'banana', :selected => 'selected', :content => 'Banana' )
1100
- end
1101
-
1102
- it "should accept an array of strings in :collection as the content/value of each option" do
1103
- r = @c.render :array
1104
- r.should match_tag(:option, :content => "one", :value => "one")
1105
- r.should match_tag(:option, :content => "two", :value => "two")
1106
- end
1107
-
1108
- it "should only pass :selected and :value attrs to <option> tags" do
1109
- r = @c.render :no_extra_attributes
1110
- r = r.slice(/<option[^>]*>[^<]*<\/option>/)
1111
- r.should match_tag(:option, :value => "rabbit", :content => "Rabbit")
1112
- r.should_not match_tag(:option, :id => "my_id", :name => "my_name", :class => "classy")
1113
- end
1114
-
1115
- it "should not pollute the <select> attributes with <option> attributes" do
1116
- r = @c.render :clean
1117
- r.should_not match_tag(:select, :value => "banana", :selected => "selected")
1118
- end
1119
- end
1120
-
1121
- describe "fieldset" do
1122
-
1123
- before :each do
1124
- @c = FieldsetSpecs.new(Rango::Request.new({}))
1125
- end
1126
-
1127
- it "should provide legend option" do
1128
- r = @c.render :legend
1129
- r.should have_selector("fieldset legend:contains('TEST')")
1130
- end
1131
-
1132
- end
1133
-
1134
- describe "label" do
1135
-
1136
- before :each do
1137
- @c = LabelSpecs.new(Rango::Request.new({}))
1138
- end
1139
-
1140
- it "should render a label tag" do
1141
- r = @c.render :basic
1142
- r.should have_selector("label[for=user_first_name]:contains('First Name')")
1143
- end
1144
-
1145
- it "should render a label tag with a :class attribute set" do
1146
- r = @c.render :basic_with_class
1147
- r.should have_selector("label[class=name_class]")
1148
- end
1149
-
1150
- it "should render a label tag with both rel and style attributes set" do
1151
- r = @c.render :basic_with_attributes
1152
- r.should have_selector("label[rel=tooltip][style='display:none']")
1153
- end
1154
-
1155
- end
1156
-
1157
- describe "file_field" do
1158
-
1159
- before :each do
1160
- @c = FileFieldSpecs.new(Rango::Request.new({}))
1161
- end
1162
-
1163
- it "should return a basic file field based on the values passed in" do
1164
- r = @c.render :with_values
1165
- r.should have_selector("input[type=file][id=foo][name=foo][value=bar]")
1166
- end
1167
-
1168
- it "should wrap the field in a label if the :label option is passed to the file" do
1169
- r = @c.render :with_label
1170
- r.should have_selector("label[for=foo]:contains('LABEL') + input.file[type=file]")
1171
- end
1172
-
1173
- it "should be disabled if :disabled => true is passed in" do
1174
- r = @c.render :disabled
1175
- r.should have_selector("input[type=file][disabled=disabled]")
1176
- end
1177
-
1178
- it "should make the surrounding form multipart" do
1179
- r = @c.render :makes_multipart
1180
- r.should have_selector("form[enctype='multipart/form-data']")
1181
- end
1182
- end
1183
-
1184
- describe "bound_file_field" do
1185
-
1186
- before :each do
1187
- @c = BoundFileFieldSpecs.new(Rango::Request.new({}))
1188
- @c.instance_variable_set(:@obj, FakeModel.new)
1189
- end
1190
-
1191
- it "should take a string object and return a useful file control" do
1192
- r = @c.render :takes_string
1193
- r.should have_selector("input[type=file][id=fake_model_foo][name='fake_model[foo]'][value=foowee]")
1194
- end
1195
-
1196
- it "should take additional attributes and use them" do
1197
- r = @c.render :additional_attributes
1198
- r.should have_selector("input[type=file][name='fake_model[foo]'][value=foowee][bar='7']")
1199
- end
1200
-
1201
- it "should wrap the file_field in a label if the :label option is passed in" do
1202
- r = @c.render :with_label
1203
- r.should have_selector("label[for=fake_model_foo]:contains('LABEL')")
1204
- r.should_not have_selector("input[label=LABEL]")
1205
- end
1206
- end
1207
-
1208
- describe "submit" do
1209
-
1210
- before :each do
1211
- @c = SubmitSpecs.new(Rango::Request.new({}))
1212
- end
1213
-
1214
- it "should return a basic submit input based on the values passed in" do
1215
- r = @c.render :submit_with_values
1216
- r.should have_selector("input[type=submit][name=foo][value=Done]")
1217
- end
1218
-
1219
- it "should provide an additional label tag if the :label option is passed in" do
1220
- r = @c.render :submit_with_label
1221
- r.should have_selector("input[type=submit][name=submit][value=Done]")
1222
- r.should have_selector("label:contains('LABEL')")
1223
- end
1224
-
1225
- it "should be disabled if :disabled => true is passed in" do
1226
- r = @c.render :disabled_submit
1227
- r.should have_selector("input[type=submit][value=Done][disabled=disabled]")
1228
- end
1229
- end
1230
-
1231
- describe "button" do
1232
-
1233
- before :each do
1234
- @c = ButtonSpecs.new(Rango::Request.new({}))
1235
- end
1236
-
1237
- it "should return a button based on the values passed in" do
1238
- r = @c.render :button_with_values
1239
- r.should have_selector("button[type=button][name=foo][value=bar]:contains('Click Me')")
1240
- end
1241
-
1242
- it "should provide an additional label tag if the :label option is passed in" do
1243
- r = @c.render :button_with_label
1244
- r.should have_selector("button[value=foo]")
1245
- r.should have_selector("label:contains('LABEL')")
1246
- end
1247
-
1248
- it "should be disabled if :disabled => true is passed in" do
1249
- r = @c.render :disabled_button
1250
- r.should have_selector("button[disabled=true]")
1251
- end
1252
- end
1253
-
1254
-
1255
- class MyBuilder < Rango::Helpers::Form::Builder::Base
1256
-
1257
- def update_bound_controls(method, attrs, type)
1258
- super
1259
- attrs[:bound] = type
1260
- end
1261
-
1262
- def update_unbound_controls(attrs, type)
1263
- super
1264
- attrs[:unbound] = type
1265
- end
1266
-
1267
- end
1268
-
1269
- describe "custom builder" do
1270
-
1271
- before :each do
1272
- @c = CustomBuilderSpecs.new(Rango::Request.new({}))
1273
- @c.instance_variable_set(:@obj, FakeModel.new)
1274
- end
1275
-
1276
- it "should let you override update_bound_controls" do
1277
- r = @c.render :everything
1278
- r.should =~ / bound="file"/
1279
- r.should =~ / bound="text"/
1280
- r.should =~ / bound="hidden"/
1281
- r.should =~ / bound="password"/
1282
- r.should =~ / bound="radio"/
1283
- r.should =~ / bound="text_area"/
1284
- end
1285
-
1286
- it "should let you override update_unbound_controls" do
1287
- r = @c.render :everything
1288
- r.should have_selector("button[unbound=button]")
1289
- r.should have_selector("input[unbound=submit]")
1290
- r.should have_selector("textarea[unbound=text_area]")
1291
- end
1292
- end
1293
-
1294
-
1295
- describe 'delete_button' do
1296
-
1297
- before :each do
1298
- @controller = DeleteButtonSpecs.new(Rango::Request.new({}))
1299
- @controller.instance_variable_set(:@obj, FakeModel.new)
1300
- end
1301
-
1302
- it "should have a default submit button text" do
1303
- result = @controller.render :simple_delete # <%= delete_button @obj %>
1304
- result.should have_selector("input[type=submit][value=Delete]")
1305
- end
1306
-
1307
- it 'should return a button inside of a form for the object' do
1308
- result = @controller.render :simple_delete # <%= delete_button @obj %>
1309
- result.should have_selector("form[action='/fake_models/fake_model'][method=post]")
1310
- result.should have_selector("input[type=hidden][value=DELETE][name=_method]")
1311
- end
1312
-
1313
- it 'should allow you to modify the label' do
1314
- result = @controller.render :delete_with_label # <%= delete_button(@obj, "Delete moi!") %>
1315
- result.should have_selector("input[type=submit][value='Delete moi!']")
1316
- end
1317
-
1318
- it "should allow you to pass some extra params like a class" do
1319
- result = @controller.render :delete_with_extra_params
1320
- result.should have_selector("input.custom-class[type=submit][value=Delete]")
1321
- end
1322
-
1323
- it "should allow to pass an explicit url as a string" do
1324
- result = @controller.render :delete_with_explicit_url # <%= delete_button('/test/custom_url') %>
1325
- result.should have_selector("form[action='/test/custom_url'][method=post]")
1326
- end
1327
-
1328
- end
1329
-
1330
- describe "escaping values" do
1331
-
1332
- before :each do
1333
- @c = Hacker.new(Rango::Request.new({}))
1334
- @c.instance_variable_set(:@obj, HackerModel.new)
1335
- end
1336
-
1337
- it "should escape bound text field values" do
1338
- r = @c.render :text_field
1339
- r.should =~ /&amp;&quot;&lt;&gt;/
1340
- end
1341
-
1342
- it "should escape bound hidden field values" do
1343
- r = @c.render :hidden_field
1344
- r.should =~ /&amp;&quot;&lt;&gt;/
1345
- end
1346
-
1347
- it "should escape bound password field values" do
1348
- r = @c.render :password_field
1349
- r.should =~ /&amp;&quot;&lt;&gt;/
1350
- end
1351
-
1352
- it "should escape bound text area values" do
1353
- r = @c.render :text_area
1354
- r.should =~ /&amp;&quot;&lt;&gt;/
1355
- end
1356
-
1357
- it "should escape bound file field values" do
1358
- r = @c.render :file_field
1359
- r.should =~ /&amp;&quot;&lt;&gt;/
1360
- end
1361
-
1362
- it "should escape bound option tag values" do
1363
- r = @c.render :option_tag
1364
- r.should =~ /&amp;&quot;&lt;&gt;/
1365
- end
1366
-
1367
- it "should escape bound radio button values" do
1368
- r = @c.render :radio_button
1369
- r.should =~ /&amp;&quot;&lt;&gt;/
1370
- end
1371
-
1372
- end