hobo 1.1.0 → 1.3.0.RC

Sign up to get free protection for your applications and to get access to all the features.
Files changed (278) hide show
  1. data/CHANGES.txt +238 -287
  2. data/Rakefile +14 -31
  3. data/VERSION +1 -0
  4. data/{lib/hobo → app/controllers}/dev_controller.rb +6 -6
  5. data/app/controllers/dryml_support_controller.rb +13 -0
  6. data/{rails_generators/hobo_front_controller/templates → app/views/dev}/summary.dryml +7 -10
  7. data/bin/hobo +12 -144
  8. data/config/initializers/inflections.rb +3 -0
  9. data/config/routes.rb +6 -0
  10. data/{doctest → doctests}/hobo/lifecycles.rdoctest +40 -59
  11. data/{doctest → doctests/hobo}/model.rdoctest +33 -40
  12. data/{doctest → doctests/hobo}/multi_model_forms.rdoctest +15 -19
  13. data/{doctest → doctests/hobo}/scopes.rdoctest +27 -41
  14. data/doctests/prepare_testapp.rb +8 -0
  15. data/hobo.gemspec +26 -199
  16. data/lib/generators/hobo/activation_email.rb +11 -0
  17. data/lib/generators/hobo/admin_subsite/admin_subsite_generator.rb +35 -0
  18. data/lib/generators/hobo/admin_subsite/templates/admin.css +20 -0
  19. data/lib/generators/hobo/admin_subsite/templates/admin_tag_injection.erb +10 -0
  20. data/{rails_generators/hobo_admin_site → lib/generators/hobo/admin_subsite}/templates/application.dryml +0 -0
  21. data/{rails_generators/hobo_admin_site/templates/controller.rb → lib/generators/hobo/admin_subsite/templates/controller.rb.erb} +5 -5
  22. data/lib/generators/hobo/admin_subsite/templates/users_index.dryml +7 -0
  23. data/lib/generators/hobo/assets/assets_generator.rb +18 -0
  24. data/{rails_generators/hobo → lib/generators/hobo/assets}/templates/application.css +0 -0
  25. data/lib/generators/hobo/assets/templates/application.dryml.erb +9 -0
  26. data/{rails_generators/hobo → lib/generators/hobo/assets}/templates/dryml-support.js +2 -2
  27. data/lib/generators/hobo/assets/templates/dryml_taglibs_initializer.rb +1 -0
  28. data/lib/generators/hobo/assets/templates/en_injection.yml +19 -0
  29. data/{rails_generators/hobo → lib/generators/hobo/assets}/templates/guest.rb +1 -1
  30. data/lib/generators/hobo/controller.rb +35 -0
  31. data/lib/generators/hobo/controller/controller_generator.rb +6 -0
  32. data/lib/generators/hobo/controller/templates/controller.rb.erb +7 -0
  33. data/{rails_generators/hobo_front_controller → lib/generators/hobo/front_controller}/USAGE +0 -0
  34. data/lib/generators/hobo/front_controller/front_controller_generator.rb +55 -0
  35. data/{rails_generators/hobo_front_controller/templates/controller.rb → lib/generators/hobo/front_controller/templates/controller.rb.erb} +0 -0
  36. data/{rails_generators/hobo_front_controller → lib/generators/hobo/front_controller}/templates/index.dryml +6 -12
  37. data/lib/generators/hobo/i18n/i18n_generator.rb +35 -0
  38. data/lib/generators/hobo/i18n/templates/app.de.yml +30 -0
  39. data/lib/generators/hobo/i18n/templates/app.en.yml +25 -0
  40. data/lib/generators/hobo/i18n/templates/app.es.yml +31 -0
  41. data/lib/generators/hobo/i18n/templates/app.fr.yml +26 -0
  42. data/lib/generators/hobo/i18n/templates/app.it.yml +28 -0
  43. data/lib/generators/hobo/i18n/templates/app.pt-PT.yml +25 -0
  44. data/lib/generators/hobo/i18n/templates/app.ru.yml +24 -0
  45. data/lib/generators/hobo/i18n/templates/hobo.de.yml +204 -0
  46. data/lib/generators/hobo/i18n/templates/hobo.en.yml +195 -0
  47. data/lib/generators/hobo/i18n/templates/hobo.es.yml +202 -0
  48. data/lib/generators/hobo/i18n/templates/hobo.fr.yml +195 -0
  49. data/lib/generators/hobo/i18n/templates/hobo.it.yml +202 -0
  50. data/lib/generators/hobo/i18n/templates/hobo.pt-PT.yml +196 -0
  51. data/lib/generators/hobo/i18n/templates/hobo.ru.yml +200 -0
  52. data/lib/generators/hobo/invite_only.rb +18 -0
  53. data/lib/generators/hobo/model/USAGE +19 -0
  54. data/lib/generators/hobo/model/model_generator.rb +11 -0
  55. data/{rails_generators/hobo_model/templates/model.rb → lib/generators/hobo/model/templates/model_injection.rb.erb} +0 -2
  56. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/USAGE +0 -0
  57. data/lib/generators/hobo/rapid/rapid_generator.rb +24 -0
  58. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/IE7.js +0 -0
  59. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/blank.gif +0 -0
  60. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/hobo-rapid.css +0 -0
  61. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/hobo-rapid.js +65 -65
  62. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/ie7-recalc.js +21 -21
  63. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/lowpro.js +31 -31
  64. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/reset.css +1 -1
  65. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-ACD3E6-DBE1E5-H.png +0 -0
  66. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-DBE1E5-FCFEF5-H.png +0 -0
  67. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/300-3B5F87-ACD3E6-H.png +0 -0
  68. data/{rails_generators/hobo_rapid/templates/themes/clean → lib/generators/hobo/rapid/templates/themes/clean-sidemenu}/public/images/spinner.gif +0 -0
  69. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/stylesheets/clean-sidemenu.css +81 -0
  70. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/views/clean-sidemenu.dryml +30 -0
  71. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/101-3B5F87-ACD3E6.png +0 -0
  72. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/30-3E547A-242E42.png +0 -0
  73. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/30-DBE1E5-FCFEF5.png +0 -0
  74. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/300-ACD3E6-fff.png +0 -0
  75. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/50-ACD3E6-fff.png +0 -0
  76. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/fieldbg.gif +0 -0
  77. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/pencil.png +0 -0
  78. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/small_close.png +0 -0
  79. data/lib/generators/hobo/rapid/templates/themes/clean/public/images/spinner.gif +0 -0
  80. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/stylesheets/clean.css +16 -16
  81. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/stylesheets/rapid-ui.css +3 -3
  82. data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/views/clean.dryml +1 -1
  83. data/lib/generators/hobo/resource/resource_generator.rb +23 -0
  84. data/lib/generators/hobo/routes/USAGE +9 -0
  85. data/lib/generators/hobo/routes/router.rb +115 -0
  86. data/lib/generators/hobo/routes/routes_generator.rb +40 -0
  87. data/lib/generators/hobo/routes/templates/hobo_routes.rb.erb +33 -0
  88. data/lib/generators/hobo/setup_wizard/USAGE +4 -0
  89. data/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb +274 -0
  90. data/lib/generators/hobo/subsite.rb +48 -0
  91. data/lib/generators/hobo/subsite/subsite_generator.rb +16 -0
  92. data/{rails_generators/hobo_subsite → lib/generators/hobo/subsite}/templates/application.dryml +0 -0
  93. data/{rails_generators/hobo_subsite/templates/controller.rb → lib/generators/hobo/subsite/templates/controller.rb.erb} +1 -1
  94. data/lib/generators/hobo/subsite_taglib/subsite_taglib_generator.rb +16 -0
  95. data/{rails_generators/hobo_admin_site/templates/site_taglib.dryml → lib/generators/hobo/subsite_taglib/templates/taglib.dryml.erb} +9 -10
  96. data/lib/generators/hobo/taglib.rb +12 -0
  97. data/lib/generators/hobo/test_framework/test_framework_generator.rb +72 -0
  98. data/lib/generators/hobo/test_options.rb +19 -0
  99. data/{rails_generators/hobo_user_controller → lib/generators/hobo/user_controller}/templates/accept_invitation.dryml +0 -0
  100. data/lib/generators/hobo/user_controller/templates/controller.rb.erb +31 -0
  101. data/lib/generators/hobo/user_controller/user_controller_generator.rb +25 -0
  102. data/lib/generators/hobo/user_mailer/templates/activation.erb +9 -0
  103. data/{rails_generators/hobo_user_model → lib/generators/hobo/user_mailer}/templates/forgot_password.erb +2 -2
  104. data/{rails_generators/hobo_user_model → lib/generators/hobo/user_mailer}/templates/invite.erb +2 -2
  105. data/lib/generators/hobo/user_mailer/templates/mailer.rb.erb +25 -0
  106. data/lib/generators/hobo/user_mailer/user_mailer_generator.rb +33 -0
  107. data/lib/generators/hobo/user_model/USAGE +12 -0
  108. data/{rails_generators/hobo_user_model/templates/model.rb → lib/generators/hobo/user_model/templates/model_injection.rb.erb} +40 -20
  109. data/lib/generators/hobo/user_model/user_model_generator.rb +23 -0
  110. data/lib/generators/hobo/user_resource/user_resource_generator.rb +27 -0
  111. data/lib/hobo.rb +29 -129
  112. data/lib/hobo/controller.rb +37 -47
  113. data/lib/hobo/controller/authentication_support.rb +109 -0
  114. data/lib/hobo/{model_controller.rb → controller/model.rb} +71 -79
  115. data/lib/hobo/{user_controller.rb → controller/user.rb} +59 -49
  116. data/lib/hobo/engine.rb +80 -0
  117. data/lib/hobo/extensions/action_controller/hobo_methods.rb +44 -0
  118. data/lib/hobo/extensions/action_mailer/helper.rb +38 -0
  119. data/lib/{action_view_extensions/helpers → hobo/extensions/action_view}/tag_helper.rb +5 -2
  120. data/lib/hobo/extensions/action_view/translation_helper.rb +25 -0
  121. data/lib/hobo/extensions/active_model/name.rb +16 -0
  122. data/lib/hobo/extensions/active_model/translation.rb +35 -0
  123. data/lib/{active_record/association_collection.rb → hobo/extensions/active_record/associations/collection.rb} +8 -17
  124. data/lib/{active_record/association_proxy.rb → hobo/extensions/active_record/associations/proxy.rb} +6 -7
  125. data/lib/hobo/extensions/active_record/associations/reflection.rb +23 -0
  126. data/lib/hobo/extensions/active_record/associations/scope.rb +35 -0
  127. data/lib/hobo/extensions/active_record/hobo_methods.rb +11 -0
  128. data/lib/hobo/extensions/active_record/permissions.rb +159 -0
  129. data/lib/hobo/extensions/active_record/relation_with_origin.rb +28 -0
  130. data/lib/hobo/extensions/array.rb +27 -0
  131. data/lib/hobo/extensions/enumerable.rb +12 -0
  132. data/lib/hobo/extensions/i18n.rb +17 -0
  133. data/lib/hobo/{hobo_helper.rb → helper.rb} +58 -31
  134. data/lib/hobo/helper/translations.rb +54 -0
  135. data/lib/hobo/helper/translations/normalizer.rb +39 -0
  136. data/lib/hobo/model.rb +61 -95
  137. data/lib/hobo/model/accessible_associations.rb +178 -0
  138. data/lib/hobo/{find_for.rb → model/find_for.rb} +17 -17
  139. data/lib/hobo/model/guest.rb +25 -0
  140. data/lib/hobo/model/include_in_save.rb +55 -0
  141. data/lib/hobo/model/lifecycles.rb +119 -0
  142. data/lib/hobo/model/lifecycles/actions.rb +146 -0
  143. data/lib/hobo/model/lifecycles/creator.rb +74 -0
  144. data/lib/hobo/model/lifecycles/lifecycle.rb +243 -0
  145. data/lib/hobo/model/lifecycles/state.rb +22 -0
  146. data/lib/hobo/model/lifecycles/transition.rb +70 -0
  147. data/lib/hobo/model/permissions.rb +448 -0
  148. data/lib/hobo/model/scopes.rb +38 -0
  149. data/lib/hobo/model/scopes/apply_scopes.rb +21 -0
  150. data/lib/hobo/model/scopes/automatic_scopes.rb +428 -0
  151. data/lib/hobo/model/user_base.rb +184 -0
  152. data/lib/hobo/model/view_hints.rb +123 -0
  153. data/{rapid_generators → lib/hobo/rapid/generators}/rapid/cards.dryml.erb +2 -2
  154. data/{rapid_generators → lib/hobo/rapid/generators}/rapid/forms.dryml.erb +3 -3
  155. data/{rapid_generators → lib/hobo/rapid/generators}/rapid/pages.dryml.erb +38 -51
  156. data/lib/hobo/rapid/helper.rb +166 -0
  157. data/{taglibs → lib/hobo/rapid/taglibs}/rapid.dryml +6 -5
  158. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_core.dryml +286 -118
  159. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_document_tags.dryml +2 -2
  160. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_editing.dryml +45 -45
  161. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_forms.dryml +190 -158
  162. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_generics.dryml +12 -9
  163. data/lib/hobo/rapid/taglibs/rapid_i18n.dryml +107 -0
  164. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_lifecycles.dryml +7 -7
  165. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_navigation.dryml +15 -15
  166. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_pages.dryml +37 -36
  167. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_plus.dryml +107 -43
  168. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_summary.dryml +28 -57
  169. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_support.dryml +9 -9
  170. data/{taglibs → lib/hobo/rapid/taglibs}/rapid_user_pages.dryml +41 -40
  171. data/lib/hobo/routes.rb +31 -0
  172. data/{doctest → test/doctest}/hobo/hobo_helper.rdoctest +11 -11
  173. data/test/irt/generators/admin_subsite.irt +27 -0
  174. data/test/irt/generators/assets.irt +16 -0
  175. data/test/irt/generators/controller.irt +6 -0
  176. data/test/irt/generators/front_controller.irt +30 -0
  177. data/test/irt/generators/helper.rb +31 -0
  178. data/test/irt/generators/model.irt +28 -0
  179. data/test/irt/generators/partials/_account_user_model_tests.rb +21 -0
  180. data/test/irt/generators/partials/_accounts_users_controller_tests.rb +15 -0
  181. data/test/irt/generators/partials/_default_user_model_tests.rb +21 -0
  182. data/test/irt/generators/partials/_default_users_controller_tests.rb +16 -0
  183. data/test/irt/generators/partials/_house_controller_tests.rb +15 -0
  184. data/test/irt/generators/partials/_house_model_tests.rb +18 -0
  185. data/test/irt/generators/partials/_subsite_taglib_admin.rb +4 -0
  186. data/test/irt/generators/partials/_subsite_taglib_admin_invite_only.rb +3 -0
  187. data/test/irt/generators/partials/_subsite_taglib_noopt.rb +4 -0
  188. data/test/irt/generators/partials/_subsite_taglib_variables.rb +27 -0
  189. data/test/irt/generators/partials/_user_mailer_tests.rb +19 -0
  190. data/test/irt/generators/rapid.irt +29 -0
  191. data/test/irt/generators/resource.irt +8 -0
  192. data/test/irt/generators/subsite.irt +52 -0
  193. data/test/irt/generators/subsite_taglib.irt +23 -0
  194. data/test/irt/generators/test_framework.irt +62 -0
  195. data/test/irt/generators/user_controller.irt +10 -0
  196. data/test/irt/generators/user_mailer.irt +20 -0
  197. data/test/irt/generators/user_model.irt +10 -0
  198. data/test/irt/generators/user_resource.irt +14 -0
  199. data/test/irt/readme.txt +7 -0
  200. data/test/permissions/models/models.rb +27 -24
  201. data/test/permissions/test_permissions.rb +104 -104
  202. metadata +239 -217
  203. data/lib/active_record/association_reflection.rb +0 -20
  204. data/lib/active_record/viewhints_validations_interceptor.rb +0 -9
  205. data/lib/hobo/accessible_associations.rb +0 -183
  206. data/lib/hobo/authentication_support.rb +0 -131
  207. data/lib/hobo/generator.rb +0 -26
  208. data/lib/hobo/guest.rb +0 -25
  209. data/lib/hobo/include_in_save.rb +0 -55
  210. data/lib/hobo/lifecycles.rb +0 -137
  211. data/lib/hobo/lifecycles/actions.rb +0 -142
  212. data/lib/hobo/lifecycles/creator.rb +0 -72
  213. data/lib/hobo/lifecycles/lifecycle.rb +0 -249
  214. data/lib/hobo/lifecycles/state.rb +0 -22
  215. data/lib/hobo/lifecycles/transition.rb +0 -70
  216. data/lib/hobo/model_router.rb +0 -290
  217. data/lib/hobo/permissions.rb +0 -451
  218. data/lib/hobo/permissions/associations.rb +0 -175
  219. data/lib/hobo/rapid_helper.rb +0 -157
  220. data/lib/hobo/scopes.rb +0 -43
  221. data/lib/hobo/scopes/apply_scopes.rb +0 -23
  222. data/lib/hobo/scopes/association_proxy_extensions.rb +0 -62
  223. data/lib/hobo/scopes/automatic_scopes.rb +0 -421
  224. data/lib/hobo/scopes/named_scope_extensions.rb +0 -39
  225. data/lib/hobo/tasks/rails.rb +0 -4
  226. data/lib/hobo/translations.rb +0 -93
  227. data/lib/hobo/undefined_access_error.rb +0 -5
  228. data/lib/hobo/user.rb +0 -182
  229. data/lib/hobo/view_hints.rb +0 -115
  230. data/rails/init.rb +0 -10
  231. data/rails_generators/hobo/USAGE +0 -4
  232. data/rails_generators/hobo/hobo_generator.rb +0 -53
  233. data/rails_generators/hobo/templates/application.dryml +0 -1
  234. data/rails_generators/hobo/templates/initializer.rb +0 -2
  235. data/rails_generators/hobo_admin_site/USAGE +0 -16
  236. data/rails_generators/hobo_admin_site/hobo_admin_site_generator.rb +0 -45
  237. data/rails_generators/hobo_admin_site/templates/admin.css +0 -2
  238. data/rails_generators/hobo_admin_site/templates/users_index.dryml +0 -5
  239. data/rails_generators/hobo_front_controller/hobo_front_controller_generator.rb +0 -95
  240. data/rails_generators/hobo_front_controller/templates/functional_test.rb +0 -8
  241. data/rails_generators/hobo_front_controller/templates/helper.rb +0 -2
  242. data/rails_generators/hobo_model/USAGE +0 -25
  243. data/rails_generators/hobo_model/hobo_model_generator.rb +0 -43
  244. data/rails_generators/hobo_model/templates/fixtures.yml +0 -6
  245. data/rails_generators/hobo_model/templates/hints.rb +0 -7
  246. data/rails_generators/hobo_model/templates/unit_test.rb +0 -8
  247. data/rails_generators/hobo_model_controller/USAGE +0 -30
  248. data/rails_generators/hobo_model_controller/hobo_model_controller_generator.rb +0 -46
  249. data/rails_generators/hobo_model_controller/templates/controller.rb +0 -7
  250. data/rails_generators/hobo_model_controller/templates/functional_test.rb +0 -8
  251. data/rails_generators/hobo_model_controller/templates/helper.rb +0 -2
  252. data/rails_generators/hobo_model_resource/USAGE +0 -38
  253. data/rails_generators/hobo_model_resource/hobo_model_resource_generator.rb +0 -73
  254. data/rails_generators/hobo_model_resource/templates/controller.rb +0 -7
  255. data/rails_generators/hobo_model_resource/templates/functional_test.rb +0 -8
  256. data/rails_generators/hobo_model_resource/templates/helper.rb +0 -2
  257. data/rails_generators/hobo_rapid/hobo_rapid_generator.rb +0 -94
  258. data/rails_generators/hobo_subsite/USAGE +0 -16
  259. data/rails_generators/hobo_subsite/hobo_subsite_generator.rb +0 -73
  260. data/rails_generators/hobo_subsite/templates/site_taglib.dryml +0 -13
  261. data/rails_generators/hobo_user_controller/USAGE +0 -34
  262. data/rails_generators/hobo_user_controller/hobo_user_controller_generator.rb +0 -65
  263. data/rails_generators/hobo_user_controller/templates/controller.rb +0 -29
  264. data/rails_generators/hobo_user_controller/templates/functional_test.rb +0 -8
  265. data/rails_generators/hobo_user_controller/templates/helper.rb +0 -2
  266. data/rails_generators/hobo_user_model/USAGE +0 -16
  267. data/rails_generators/hobo_user_model/hobo_user_model_generator.rb +0 -46
  268. data/rails_generators/hobo_user_model/templates/fixtures.yml +0 -19
  269. data/rails_generators/hobo_user_model/templates/mailer.rb +0 -29
  270. data/rails_generators/hobo_user_model/templates/unit_test.rb +0 -8
  271. data/script/destroy +0 -14
  272. data/script/generate +0 -14
  273. data/taglibs/rapid_translations.dryml +0 -36
  274. data/tasks/environments.rake +0 -19
  275. data/tasks/hobo_tasks.rake +0 -58
  276. data/test/generators/test_generator_helper.rb +0 -29
  277. data/test/generators/test_helper.rb +0 -1
  278. data/test/generators/test_hobo_model_controller_generator.rb +0 -56
@@ -1,13 +1,13 @@
1
- # Notes:
2
- #
1
+ # Notes:
2
+ #
3
3
  # create/update/delete by guest
4
4
  # create/update/delete by non-permitted user
5
5
  # create/update/delete by permitted user
6
- #
6
+ #
7
7
  # All of the above for has-many related records
8
8
  # All of the above for has-many through related records
9
9
  # All of the above for belongs-to related records
10
- #
10
+ #
11
11
  # a permitted user can't create/update/delete any of the above related records without :accessible
12
12
 
13
13
 
@@ -20,13 +20,13 @@ require 'shoulda'
20
20
  Models.init
21
21
 
22
22
  class PermissionsTest < Test::Unit::TestCase
23
-
23
+
24
24
  def assert_create_prevented(*models)
25
25
  counts = models.*.count
26
26
  assert_raises(Hobo::PermissionDeniedError) { yield }
27
27
  assert_equal(counts, models.*.count)
28
28
  end
29
-
29
+
30
30
  def assert_created(*args)
31
31
  expectations = {}
32
32
  args.in_groups_of(2) {|model, expected| expectations[model] = [model.count, expected]}
@@ -37,58 +37,58 @@ class PermissionsTest < Test::Unit::TestCase
37
37
  assert_equal(nums.last, delta, "Expected #{nums.last} #{model.name.pluralize} to be created, but #{delta} were")
38
38
  end
39
39
  end
40
-
40
+
41
41
  def assert_change_prevented(record, field)
42
42
  was = record.send(field)
43
43
  assert_raises(Hobo::PermissionDeniedError) { yield }
44
44
  record.reload
45
45
  assert_equal was, record.send(field)
46
46
  end
47
-
47
+
48
48
  def assert_deleted(record)
49
49
  assert_raises(ActiveRecord::RecordNotFound) { record.class.find(record.id) }
50
50
  end
51
-
52
- def assert_destroy_prevented(*records)
51
+
52
+ def assert_destroy_prevented(*records)
53
53
  assert_raises(Hobo::PermissionDeniedError) { yield }
54
54
  records.each { |record| assert record.class.find(record.id) }
55
55
  end
56
-
57
-
56
+
57
+
58
58
  def existing_recipe(user=nil)
59
59
  user ||= User.new :name => "existing recipe owner"
60
60
  Recipe.create :name => "existing recipe", :user => user
61
61
  end
62
-
62
+
63
63
 
64
64
  context "The permission system" do
65
-
65
+
66
66
  context "with a guest user acting" do
67
- setup { @guest = Hobo::Guest.new }
68
-
67
+ setup { @guest = Hobo::Model::Guest.new }
68
+
69
69
  should "prevent creation of a recipe" do
70
70
  assert_create_prevented(Recipe) { Recipe.user_create! @guest, :name => "test recipe" }
71
71
  end
72
-
72
+
73
73
  should "prevent update of an exiting recipe" do
74
74
  r = existing_recipe
75
75
  assert_change_prevented(r, :name) { r.user_update_attributes!(@guest, :name => "pwned!") }
76
76
  end
77
-
77
+
78
78
  should "prevent deletion of an existing recipe" do
79
79
  r = existing_recipe
80
80
  assert_destroy_prevented(r) { r.user_destroy(@guest) }
81
81
  end
82
-
82
+
83
83
  end
84
-
84
+
85
85
  context "with a regular user acting" do
86
-
87
- setup { @user = User.create! :name => "regular" }
88
-
89
-
86
+
87
+ setup { @user = User.create! :name => "regular" }
88
+
89
+
90
90
  # --- Permitted basic actions --- #
91
-
91
+
92
92
  should "allow creation of a recipe" do
93
93
  assert_created Recipe, 1 do
94
94
  @recipe = Recipe.user_create! @user, :name => "test recipe"
@@ -102,7 +102,7 @@ class PermissionsTest < Test::Unit::TestCase
102
102
  r.reload
103
103
  assert_equal("new name", r.name)
104
104
  end
105
-
105
+
106
106
  should "allow deletion of a recipe (owned by the acting user)" do
107
107
  r = existing_recipe(@user)
108
108
  r.user_destroy(@user)
@@ -115,28 +115,28 @@ class PermissionsTest < Test::Unit::TestCase
115
115
  should "prevent creation of a recipe owned by another user" do
116
116
  assert_create_prevented(Recipe) { Recipe.user_create! @user, :name => "test recipe", :user => User.new }
117
117
  end
118
-
118
+
119
119
  context "on a recipe owned by another user" do
120
120
  setup { @r = existing_recipe(User.create!(:name => "a n other")) }
121
-
121
+
122
122
  should "prevent update" do
123
123
  assert_change_prevented(@r, :name) { @r.user_update_attributes!(@user, :name => "pwned!") }
124
124
  end
125
-
125
+
126
126
  should "prevent deletion" do
127
127
  assert_destroy_prevented(@r) { @r.user_destroy(@user) }
128
128
  end
129
-
129
+
130
130
  end
131
-
132
-
131
+
132
+
133
133
  # --- Prevented actions on has_many related records --- #
134
-
134
+
135
135
  # (sanity check)
136
136
  should "prevent creation of images without a recipe" do
137
137
  assert_create_prevented(Image) { Image.user_create! @user, :name => "test image" }
138
138
  end
139
-
139
+
140
140
  should "prevent creation of images along with a recipe" do # Only paid up users can
141
141
  assert_create_prevented(Recipe, Image) do
142
142
  Recipe.user_create! @user, :name => "test recipe",
@@ -144,7 +144,7 @@ class PermissionsTest < Test::Unit::TestCase
144
144
  '1' => { :name => "image 2" } }
145
145
  end
146
146
  end
147
-
147
+
148
148
  context "on an another's recipe with images" do
149
149
  setup do
150
150
  user = User.create :name => "a n other"
@@ -152,71 +152,71 @@ class PermissionsTest < Test::Unit::TestCase
152
152
  @i1 = @r.images.create(:name => "image 1")
153
153
  @i2 = @r.images.create(:name => "image 2")
154
154
  end
155
-
155
+
156
156
  should "prevent update of those images" do
157
157
  assert_change_prevented(@i1, :name) do
158
158
  @r.user_update_attributes!(@user, :images => { '0' => { :id => @i1.id, :name => "pwned!" } })
159
159
  end
160
160
  end
161
-
161
+
162
162
  should "prevent deletion of those images" do
163
163
  assert_destroy_prevented(@i1, @i2) { @r.user_update_attributes!(@user, :images => { }) }
164
164
  end
165
165
  end
166
-
166
+
167
167
  # Note: permitted actions on has-many associated records are in the paid-up user section
168
168
  # Tis the tyranny of the dominant hiearchy : )
169
-
169
+
170
170
 
171
171
  # --- Permitted actions on has_many :through relationships --- #
172
-
172
+
173
173
  context "" do
174
174
  setup do
175
175
  @c1 = User.create :name => "Collaborator 1"
176
176
  @c2 = User.create :name => "Collaborator 2"
177
177
  end
178
-
178
+
179
179
  should "allow adding collaborators when creating a recipe" do
180
- @r = Recipe.user_create! @user, :name => "my recipe",
180
+ @r = Recipe.user_create! @user, :name => "my recipe",
181
181
  :collaborators => { '0' => "@#{@c1.id}", '1' => "@#{@c2.id}" }
182
182
  assert_equal(@r.collaborators, [@c1, @c2])
183
183
  end
184
-
184
+
185
185
  should "allow adding collaborators to a recipe" do
186
186
  @r = existing_recipe(@user)
187
-
187
+
188
188
  @r.user_update_attributes! @user, :collaborators => { '0' => "@#{@c1.id}", '1' => "@#{@c2.id}" }
189
189
  assert_equal(@r.collaborators, [@c1, @c2])
190
190
  end
191
-
191
+
192
192
  should "allow removing collaborators from a recipe" do
193
193
  @r = existing_recipe(@user)
194
194
  @r.collaborators << @c1
195
- @r.collaborators << @c2
195
+ @r.collaborators << @c2
196
196
  join1, join2 = @r.collaboratorships
197
-
197
+
198
198
  # sanity check
199
199
  @r.reload
200
200
  assert_equal(@r.collaborators.length, 2)
201
201
 
202
202
  @r.user_update_attributes! @user, :collaborators => {}
203
203
  assert_equal(@r.collaborators.length, 0)
204
-
204
+
205
205
  assert_deleted(join1)
206
206
  assert_deleted(join2)
207
207
  end
208
-
209
-
208
+
209
+
210
210
  # --- Prevented actions on has_many :through relationships --- #
211
-
211
+
212
212
  context "on another's recipe" do
213
213
  setup do
214
214
  other_user = User.create :name => "a n other"
215
215
  @r = existing_recipe(other_user)
216
216
  end
217
-
217
+
218
218
  should "prevent adding collaborators" do
219
- assert_create_prevented(Collaboratorship) do
219
+ assert_create_prevented(Collaboratorship) do
220
220
  @r.user_update_attributes! @user, :collaborators => { '0' => "@#{@c1.id}", '1' => "@#{@c2.id}" }
221
221
  end
222
222
  end
@@ -233,45 +233,45 @@ class PermissionsTest < Test::Unit::TestCase
233
233
  end
234
234
  end
235
235
  end
236
-
236
+
237
237
  end
238
-
238
+
239
239
  # --- Permitted actions on a belongs_to related record --- #
240
-
240
+
241
241
  should "allow creation of a code-example along with a recipe" do
242
242
  assert_created(Recipe, 1, CodeExample, 1) do
243
- @r = Recipe.user_create! @user, :name => "recipe with code example",
243
+ @r = Recipe.user_create! @user, :name => "recipe with code example",
244
244
  :code_example => { :filename => "code.zip" }
245
245
  end
246
246
  assert_equal("code.zip", @r.code_example.filename)
247
247
  end
248
-
248
+
249
249
  should "allow creation of a code-example for an existing recipe" do
250
250
  @r = existing_recipe(@user)
251
251
  assert_created(CodeExample, 1) do
252
252
  @r.user_update_attributes! @user, :code_example => { :filename => "code.zip" }
253
253
  end
254
- assert_equal("code.zip", @r.code_example.filename)
254
+ assert_equal("code.zip", @r.code_example.filename)
255
255
  end
256
-
256
+
257
257
  should "allow the code example related to a recipe to be changed" do
258
258
  r = existing_recipe @user
259
259
  c1 = CodeExample.create! :filename => "exmaple1.zip"
260
260
  c2 = CodeExample.create! :filename => "exmaple2.zip"
261
261
  r.code_example = c1
262
262
  r.save
263
-
263
+
264
264
  r.user_update_attributes! @user, :code_example => "@#{c2.id}"
265
-
265
+
266
266
  assert_equal(c2, r.code_example)
267
267
  end
268
-
269
- context "on an existing recipe with a code example" do
268
+
269
+ context "on an existing recipe with a code example" do
270
270
  setup do
271
271
  @ce = CodeExample.create! :filename => "exmaple.zip"
272
272
  @r = Recipe.create :name => "existing recipe", :user => @user, :code_example => @ce
273
273
  end
274
-
274
+
275
275
  should "allow update of the code-example" do
276
276
  # To update the exsting target of a belongs_to association, the id must be included in the hash
277
277
  # It is an error to provide any id other than that of the existing target
@@ -286,12 +286,12 @@ class PermissionsTest < Test::Unit::TestCase
286
286
  assert_nil @r.code_example
287
287
  # Note - the code-example is not deleted from the database
288
288
  end
289
-
289
+
290
290
  end
291
-
292
-
291
+
292
+
293
293
  # --- Prevented actions on a belongs_to related record --- #
294
-
294
+
295
295
  context "on another's recipe" do
296
296
  setup { @r = existing_recipe }
297
297
 
@@ -300,13 +300,13 @@ class PermissionsTest < Test::Unit::TestCase
300
300
  @r.user_update_attributes! @user, :code_example => { :filename => "code.zip" }
301
301
  end
302
302
  end
303
-
303
+
304
304
  context "with a code example" do
305
305
  setup do
306
306
  @ce = @r.code_example = CodeExample.create!(:filename => "exmaple.zip")
307
307
  @r.save
308
308
  end
309
-
309
+
310
310
  should "prevent update of the code-example" do
311
311
  assert_change_prevented(@ce, :filename) do
312
312
  @r.user_update_attributes! @user, :code_example => { :filename => "changed.zip" }
@@ -317,23 +317,23 @@ class PermissionsTest < Test::Unit::TestCase
317
317
  assert_change_prevented(@r, :code_example_id) do
318
318
  @r.user_update_attributes! @user, :code_example => {}
319
319
  end
320
-
320
+
321
321
  end
322
322
  end
323
- end
324
-
323
+ end
324
+
325
325
  # --- Actions on non-accesible has_many associations --- #
326
-
327
- # When associations are not declared :accesssible => true, attemting to update them
326
+
327
+ # When associations are not declared :accesssible => true, attemting to update them
328
328
  # causes a type-mismatch
329
-
329
+
330
330
  should "prevent creation of comments via a recipe" do
331
331
  r = existing_recipe
332
332
  assert_raises(ActiveRecord::AssociationTypeMismatch) do
333
333
  r.user_update_attributes! @user, :comments => { '0' => { :body => "dodgy comment"} }
334
334
  end
335
335
  end
336
-
336
+
337
337
  should "prevent update of comments via their recipe" do
338
338
  r = existing_recipe
339
339
  c = r.comments.create :body => "My nice comment"
@@ -341,26 +341,26 @@ class PermissionsTest < Test::Unit::TestCase
341
341
  r.user_update_attributes! @user, :comments => { '0' => { :id => c.id, :body => "dodgy comment"} }
342
342
  end
343
343
  end
344
-
344
+
345
345
  should "prevent deletion of comments via their recipe" do
346
346
  r = existing_recipe
347
347
  c = r.comments.create :body => "My nice comment"
348
348
  assert_destroy_prevented(c) do
349
349
  r.user_update_attributes! @user, :comments => { }
350
- end
350
+ end
351
351
  end
352
-
353
-
352
+
353
+
354
354
  # --- Actions on non-accessible belongs_to associations --- #
355
-
355
+
356
356
  should "prevent creation of a recipe when creating a comment" do
357
357
  count = Recipe.count
358
- assert_raises(ActiveRecord::AssociationTypeMismatch) do
358
+ assert_raises(ActiveRecord::AssociationTypeMismatch) do
359
359
  Comment.user_create! @user, :body => "my comment", :recipe => { :name => "I created a recipe!" }
360
360
  end
361
361
  assert_equal(count, Recipe.count)
362
362
  end
363
-
363
+
364
364
  should "prevent update of a recipe via one of its comments" do
365
365
  r = existing_recipe
366
366
  c = r.comments.create :body => "My comment"
@@ -369,7 +369,7 @@ class PermissionsTest < Test::Unit::TestCase
369
369
  end
370
370
  assert_equal("existing recipe", r.name)
371
371
  end
372
-
372
+
373
373
  should "prevent deletion of a recipe via one of its comments" do
374
374
  r = existing_recipe
375
375
  c = r.comments.create :body => "My comment"
@@ -378,20 +378,20 @@ class PermissionsTest < Test::Unit::TestCase
378
378
  end
379
379
  assert Recipe.find(r.id)
380
380
  end
381
-
381
+
382
382
  end
383
-
383
+
384
384
  context "with a paid up user acting" do
385
385
  setup { @user = User.create! :name => "paid up user", :paid_up => true }
386
-
386
+
387
387
  should "prevent direct creation of images" do # images must belong to a recipe
388
388
  assert_create_prevented(Image) { Image.user_create! @user, :name => "test image" }
389
389
  end
390
-
390
+
391
391
  # --- Permitted actions on has_many related records --- #
392
-
392
+
393
393
  should "allow creation of images along with a recipe" do
394
-
394
+
395
395
  assert_created Recipe, 1, Image, 2 do
396
396
  @recipe = Recipe.user_create! @user, :images => { '0' => { :name => "image 1" },
397
397
  '1' => { :name => "image 2" } }
@@ -406,14 +406,14 @@ class PermissionsTest < Test::Unit::TestCase
406
406
  end
407
407
 
408
408
  end
409
-
409
+
410
410
  context "on an existing recipe with images" do
411
411
  setup do
412
412
  @recipe = Recipe.create! :name => "recipe with images", :user => @user
413
413
  @i1 = @recipe.images.create! :name => "image 1"
414
414
  @i2 = @recipe.images.create! :name => "image 2"
415
- end
416
-
415
+ end
416
+
417
417
  should "allow creation of images when updating a recipe" do
418
418
  @recipe.user_update_attributes! @user, :images => { '0' => { :id => @i1.id },
419
419
  '1' => { :id => @i2.id },
@@ -424,7 +424,7 @@ class PermissionsTest < Test::Unit::TestCase
424
424
  assert_equal("image 2", Image.find(@i2.id).name)
425
425
  assert_equal("new image", @recipe.images[2].name)
426
426
  end
427
-
427
+
428
428
  should "allow updates to images when updating a recipe" do
429
429
  @recipe.user_update_attributes! @user, :images => { '0' => { :id => @i1.id, :name => "new name" },
430
430
  '1' => { :id => @i2.id } }
@@ -433,19 +433,19 @@ class PermissionsTest < Test::Unit::TestCase
433
433
  assert_equal("new name", Image.find(@i1.id).name)
434
434
  assert_equal("new name", @recipe.images[0].name)
435
435
  end
436
-
436
+
437
437
  should "allow deletion of images when updating a recipe" do
438
438
  @recipe.user_update_attributes! @user, :images => { '0' => { :id => @i1.id } }
439
439
  @recipe.reload
440
440
  assert_equal(1, @recipe.images.length)
441
441
  assert_deleted(@i2)
442
442
  end
443
-
443
+
444
444
  end
445
-
446
-
445
+
446
+
447
447
  end
448
-
449
- end
450
-
451
- end
448
+
449
+ end
450
+
451
+ end