typus 3.0.12 → 3.1.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (339) hide show
  1. data/Gemfile +10 -16
  2. data/README.md +7 -10
  3. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/blank.gif +0 -0
  4. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancy_close.png +0 -0
  5. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancy_loading.png +0 -0
  6. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancy_nav_left.png +0 -0
  7. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancy_nav_right.png +0 -0
  8. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancy_shadow_e.png +0 -0
  9. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancy_shadow_n.png +0 -0
  10. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancy_shadow_ne.png +0 -0
  11. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancy_shadow_nw.png +0 -0
  12. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancy_shadow_s.png +0 -0
  13. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancy_shadow_se.png +0 -0
  14. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancy_shadow_sw.png +0 -0
  15. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancy_shadow_w.png +0 -0
  16. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancy_title_left.png +0 -0
  17. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancy_title_main.png +0 -0
  18. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancy_title_over.png +0 -0
  19. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancy_title_right.png +0 -0
  20. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancybox-x.png +0 -0
  21. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancybox-y.png +0 -0
  22. data/app/assets/{vendor/typus/vendor/jquery.fancybox-1.3.4/fancybox → images/typus}/fancybox.png +0 -0
  23. data/app/assets/javascripts/typus/application.js +7 -0
  24. data/app/assets/{vendor/typus/javascripts/application.js → javascripts/typus/custom.js} +0 -0
  25. data/app/assets/{vendor/typus/javascripts → javascripts/typus}/jquery.application.js +6 -8
  26. data/app/assets/{vendor/typus/javascripts → javascripts/typus}/jquery.rails.autocomplete.js +0 -0
  27. data/app/assets/{vendor/typus/javascripts → javascripts/typus}/jquery.searchField.js +0 -0
  28. data/app/assets/stylesheets/typus/application.css +7 -0
  29. data/app/assets/{vendor/typus/stylesheets/application.css → stylesheets/typus/custom.css} +0 -0
  30. data/app/assets/stylesheets/typus/pagination.css +17 -0
  31. data/app/assets/{vendor/typus/stylesheets → stylesheets/typus}/reset.css +0 -0
  32. data/app/assets/{vendor/typus/stylesheets → stylesheets/typus}/screen.css +2 -27
  33. data/app/assets/vendor/{typus/vendor/jquery-tokeninput → jquery-tokeninput}/css/token-input-facebook.css +0 -0
  34. data/app/assets/vendor/{typus/vendor/jquery-tokeninput → jquery-tokeninput}/css/token-input-mac.css +0 -0
  35. data/app/assets/vendor/{typus/vendor/jquery-tokeninput → jquery-tokeninput}/css/token-input.css +0 -0
  36. data/app/assets/vendor/{typus/vendor/jquery-tokeninput → jquery-tokeninput}/js/jquery.tokeninput.js +0 -0
  37. data/app/assets/vendor/{typus/vendor/jquery-ui-1.8.12.custom → jquery-ui-1.8.12.custom}/css/ui-lightness/images/ui-bg_diagonals-thick_18_b81900_40x40.png +0 -0
  38. data/app/assets/vendor/{typus/vendor/jquery-ui-1.8.12.custom → jquery-ui-1.8.12.custom}/css/ui-lightness/images/ui-bg_diagonals-thick_20_666666_40x40.png +0 -0
  39. data/app/assets/vendor/{typus/vendor/jquery-ui-1.8.12.custom → jquery-ui-1.8.12.custom}/css/ui-lightness/images/ui-bg_flat_10_000000_40x100.png +0 -0
  40. data/app/assets/vendor/{typus/vendor/jquery-ui-1.8.12.custom → jquery-ui-1.8.12.custom}/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png +0 -0
  41. data/app/assets/vendor/{typus/vendor/jquery-ui-1.8.12.custom → jquery-ui-1.8.12.custom}/css/ui-lightness/images/ui-bg_glass_100_fdf5ce_1x400.png +0 -0
  42. data/app/assets/vendor/{typus/vendor/jquery-ui-1.8.12.custom → jquery-ui-1.8.12.custom}/css/ui-lightness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  43. data/app/assets/vendor/{typus/vendor/jquery-ui-1.8.12.custom → jquery-ui-1.8.12.custom}/css/ui-lightness/images/ui-bg_gloss-wave_35_f6a828_500x100.png +0 -0
  44. data/app/assets/vendor/{typus/vendor/jquery-ui-1.8.12.custom → jquery-ui-1.8.12.custom}/css/ui-lightness/images/ui-bg_highlight-soft_100_eeeeee_1x100.png +0 -0
  45. data/app/assets/vendor/{typus/vendor/jquery-ui-1.8.12.custom → jquery-ui-1.8.12.custom}/css/ui-lightness/images/ui-bg_highlight-soft_75_ffe45c_1x100.png +0 -0
  46. data/app/assets/vendor/{typus/vendor/jquery-ui-1.8.12.custom → jquery-ui-1.8.12.custom}/css/ui-lightness/images/ui-icons_222222_256x240.png +0 -0
  47. data/app/assets/vendor/{typus/vendor/jquery-ui-1.8.12.custom → jquery-ui-1.8.12.custom}/css/ui-lightness/images/ui-icons_228ef1_256x240.png +0 -0
  48. data/app/assets/vendor/{typus/vendor/jquery-ui-1.8.12.custom → jquery-ui-1.8.12.custom}/css/ui-lightness/images/ui-icons_ef8c08_256x240.png +0 -0
  49. data/app/assets/vendor/{typus/vendor/jquery-ui-1.8.12.custom → jquery-ui-1.8.12.custom}/css/ui-lightness/images/ui-icons_ffd27a_256x240.png +0 -0
  50. data/app/assets/vendor/{typus/vendor/jquery-ui-1.8.12.custom → jquery-ui-1.8.12.custom}/css/ui-lightness/images/ui-icons_ffffff_256x240.png +0 -0
  51. data/app/assets/vendor/{typus/vendor/jquery-ui-1.8.12.custom → jquery-ui-1.8.12.custom}/css/ui-lightness/jquery-ui-1.8.12.custom.css +0 -0
  52. data/app/assets/vendor/{typus/vendor/jquery-ui-1.8.12.custom → jquery-ui-1.8.12.custom}/index.html +0 -0
  53. data/app/assets/vendor/{typus/vendor/jquery-ui-1.8.12.custom → jquery-ui-1.8.12.custom}/js/jquery-ui-1.8.12.custom.min.js +0 -0
  54. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/blank.gif +0 -0
  55. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancy_close.png +0 -0
  56. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancy_loading.png +0 -0
  57. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancy_nav_left.png +0 -0
  58. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancy_nav_right.png +0 -0
  59. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_e.png +0 -0
  60. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_n.png +0 -0
  61. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_ne.png +0 -0
  62. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_nw.png +0 -0
  63. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_s.png +0 -0
  64. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_se.png +0 -0
  65. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_sw.png +0 -0
  66. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancy_shadow_w.png +0 -0
  67. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancy_title_left.png +0 -0
  68. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancy_title_main.png +0 -0
  69. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancy_title_over.png +0 -0
  70. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancy_title_right.png +0 -0
  71. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancybox-x.png +0 -0
  72. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancybox-y.png +0 -0
  73. data/app/assets/vendor/jquery.fancybox-1.3.4/fancybox/fancybox.png +0 -0
  74. data/app/assets/vendor/{typus/vendor/jquery.fancybox-1.3.4 → jquery.fancybox-1.3.4}/fancybox/jquery.easing-1.3.pack.js +0 -0
  75. data/app/assets/vendor/{typus/vendor/jquery.fancybox-1.3.4 → jquery.fancybox-1.3.4}/fancybox/jquery.fancybox-1.3.4.css +0 -0
  76. data/app/assets/vendor/{typus/vendor/jquery.fancybox-1.3.4 → jquery.fancybox-1.3.4}/fancybox/jquery.fancybox-1.3.4.js +0 -0
  77. data/app/assets/vendor/{typus/vendor/jquery.fancybox-1.3.4 → jquery.fancybox-1.3.4}/fancybox/jquery.fancybox-1.3.4.pack.js +0 -0
  78. data/app/assets/vendor/{typus/vendor/jquery.fancybox-1.3.4 → jquery.fancybox-1.3.4}/fancybox/jquery.mousewheel-3.0.4.pack.js +0 -0
  79. data/app/controllers/admin/base_controller.rb +5 -3
  80. data/app/controllers/admin/resources_controller.rb +3 -7
  81. data/app/controllers/admin/session_controller.rb +2 -5
  82. data/app/helpers/admin/base_helper.rb +1 -1
  83. data/app/helpers/admin/display_helper.rb +0 -2
  84. data/app/helpers/admin/file_preview_helper.rb +10 -10
  85. data/app/helpers/admin/filters_helper.rb +1 -1
  86. data/app/helpers/admin/relationships_helper.rb +20 -21
  87. data/app/helpers/admin/sidebar_helper.rb +1 -8
  88. data/app/helpers/admin/table_helper.rb +8 -8
  89. data/app/views/admin/dashboard/_applications.html.erb +1 -1
  90. data/app/views/admin/helpers/base/_apps.html.erb +2 -7
  91. data/app/views/admin/helpers/base/_header.html.erb +1 -1
  92. data/app/views/admin/helpers/resources/_errors.html.erb +1 -1
  93. data/app/views/admin/helpers/sidebar/_sidebar.html.erb +1 -1
  94. data/app/views/admin/resources/index.html.erb +4 -4
  95. data/app/views/admin/shared/_head.html.erb +2 -17
  96. data/app/views/admin/templates/_belongs_to_with_autocomplete.html.erb +1 -1
  97. data/app/views/admin/templates/_has_n.html.erb +3 -3
  98. data/app/views/admin/templates/_has_one.html.erb +2 -2
  99. data/app/views/admin/templates/_selector.html.erb +7 -2
  100. data/config/locales/typus.ca.yml +1 -1
  101. data/config/locales/typus.de.models.yml +5 -6
  102. data/config/locales/typus.de.yml +36 -39
  103. data/config/locales/typus.el.yml +1 -1
  104. data/config/locales/typus.es.yml +1 -1
  105. data/config/locales/typus.fr.yml +1 -2
  106. data/config/locales/typus.hu.yml +1 -1
  107. data/config/locales/typus.locale.yml.template +1 -1
  108. data/config/locales/typus.pt-BR.yml +1 -1
  109. data/config/locales/typus.ru.yml +1 -1
  110. data/config/locales/typus.zh-CN.yml +1 -1
  111. data/config/routes.rb +2 -2
  112. data/lib/generators/templates/config/initializers/typus.rb +1 -3
  113. data/lib/generators/templates/config/typus/README +0 -1
  114. data/lib/generators/typus/migration_generator.rb +0 -3
  115. data/lib/support/active_record.rb +7 -9
  116. data/lib/typus.rb +7 -8
  117. data/lib/typus/authentication/session.rb +3 -2
  118. data/lib/typus/controller/associations.rb +2 -2
  119. data/lib/typus/controller/format.rb +3 -3
  120. data/lib/typus/engine.rb +2 -6
  121. data/lib/typus/i18n.rb +4 -0
  122. data/lib/typus/orm/active_record/admin_user_v1.rb +13 -12
  123. data/lib/typus/orm/active_record/admin_user_v2.rb +31 -1
  124. data/lib/typus/orm/active_record/class_methods.rb +1 -0
  125. data/lib/typus/orm/base.rb +0 -4
  126. data/lib/typus/regex.rb +2 -0
  127. data/lib/typus/version.rb +1 -1
  128. data/test/app/controllers/admin/account_controller_test.rb +94 -0
  129. data/test/app/controllers/admin/assets_controller_test.rb +156 -0
  130. data/test/app/controllers/admin/base_controller_test.rb +25 -0
  131. data/test/app/controllers/admin/birds_controller_test.rb +33 -0
  132. data/test/app/controllers/admin/cases_controller_test.rb +20 -0
  133. data/test/app/controllers/admin/categories_controller_test.rb +134 -0
  134. data/test/app/controllers/admin/comments_controller_test.rb +71 -0
  135. data/test/app/controllers/admin/dashboard_controller_test.rb +150 -0
  136. data/test/app/controllers/admin/image_holders_controller_test.rb +74 -0
  137. data/test/app/controllers/admin/invoices_controller_test.rb +77 -0
  138. data/test/app/controllers/admin/orders_controller_test.rb +17 -0
  139. data/test/app/controllers/admin/pages_controller_test.rb +33 -0
  140. data/test/app/controllers/admin/posts_controller_test.rb +764 -0
  141. data/test/app/controllers/admin/projects_controller_test.rb +48 -0
  142. data/test/app/controllers/admin/session_controller_test.rb +91 -0
  143. data/test/app/controllers/admin/status_controller_test.rb +33 -0
  144. data/test/app/controllers/admin/typus_users_controller_test.rb +154 -0
  145. data/test/app/controllers/admin/users_controller_test.rb +101 -0
  146. data/test/app/controllers/admin/views_controller_test.rb +36 -0
  147. data/test/app/helpers/admin/base_helper_test.rb +75 -0
  148. data/test/app/helpers/admin/dashboard_helper_test.rb +28 -0
  149. data/test/app/helpers/admin/file_preview_helper_test.rb +90 -0
  150. data/test/app/helpers/admin/filters_helper_test.rb +166 -0
  151. data/test/app/helpers/admin/form_helper_test.rb +126 -0
  152. data/test/app/helpers/admin/list_helper_test.rb +76 -0
  153. data/test/app/helpers/admin/relationships_helper_test.rb +19 -0
  154. data/test/app/helpers/admin/resources_helper_test.rb +46 -0
  155. data/test/app/helpers/admin/search_helper_test.rb +56 -0
  156. data/test/app/helpers/admin/sidebar_helper_test.rb +20 -0
  157. data/test/app/helpers/admin/table_helper_test.rb +245 -0
  158. data/test/app/mailers/admin/mailer_test.rb +20 -0
  159. data/test/app/models/admin_user_test.rb +22 -0
  160. data/test/app/models/typus_user_roles_test.rb +125 -0
  161. data/test/app/models/typus_user_test.rb +145 -0
  162. data/test/app/models/user_test.rb +38 -0
  163. data/test/config/routes_test.rb +30 -0
  164. data/test/factories.rb +134 -0
  165. data/test/fixtures/config/broken/application.yml +68 -0
  166. data/test/fixtures/config/broken/application_roles.yml +20 -0
  167. data/test/fixtures/config/broken/empty.yml +0 -0
  168. data/test/fixtures/config/broken/empty_roles.yml +0 -0
  169. data/test/fixtures/config/broken/undefined.yml +3 -0
  170. data/test/fixtures/config/broken/undefined_roles.yml +6 -0
  171. data/test/fixtures/config/default/typus.yml +13 -0
  172. data/test/fixtures/config/default/typus_roles.yml +2 -0
  173. data/test/fixtures/config/empty/empty_01.yml +0 -0
  174. data/test/fixtures/config/empty/empty_01_roles.yml +0 -0
  175. data/test/fixtures/config/empty/empty_02.yml +0 -0
  176. data/test/fixtures/config/empty/empty_02_roles.yml +0 -0
  177. data/test/fixtures/config/locales/es.yml +10 -0
  178. data/test/fixtures/config/namespaced/application.yml +5 -0
  179. data/test/fixtures/config/namespaced/application_roles.yml +2 -0
  180. data/test/fixtures/config/ordered/001_roles.yml +2 -0
  181. data/test/fixtures/config/ordered/002_roles.yml +2 -0
  182. data/test/fixtures/config/unordered/app_one_roles.yml +2 -0
  183. data/test/fixtures/config/unordered/app_two_roles.yml +2 -0
  184. data/test/fixtures/rails_app/.gitignore +4 -0
  185. data/test/fixtures/rails_app/Capfile +7 -0
  186. data/test/fixtures/rails_app/README +256 -0
  187. data/test/fixtures/rails_app/Rakefile +7 -0
  188. data/test/fixtures/rails_app/app/controllers/admin/admin_users_controller.rb +2 -0
  189. data/test/fixtures/rails_app/app/controllers/admin/animals_controller.rb +2 -0
  190. data/test/fixtures/rails_app/app/controllers/admin/article/entries_controller.rb +2 -0
  191. data/test/fixtures/rails_app/app/controllers/admin/assets_controller.rb +51 -0
  192. data/test/fixtures/rails_app/app/controllers/admin/birds_controller.rb +2 -0
  193. data/test/fixtures/rails_app/app/controllers/admin/cases_controller.rb +2 -0
  194. data/test/fixtures/rails_app/app/controllers/admin/categories_controller.rb +2 -0
  195. data/test/fixtures/rails_app/app/controllers/admin/comments_controller.rb +2 -0
  196. data/test/fixtures/rails_app/app/controllers/admin/dogs_controller.rb +2 -0
  197. data/test/fixtures/rails_app/app/controllers/admin/entries_controller.rb +2 -0
  198. data/test/fixtures/rails_app/app/controllers/admin/hits_controller.rb +37 -0
  199. data/test/fixtures/rails_app/app/controllers/admin/image_holders_controller.rb +2 -0
  200. data/test/fixtures/rails_app/app/controllers/admin/invoices_controller.rb +2 -0
  201. data/test/fixtures/rails_app/app/controllers/admin/orders_controller.rb +2 -0
  202. data/test/fixtures/rails_app/app/controllers/admin/pages_controller.rb +7 -0
  203. data/test/fixtures/rails_app/app/controllers/admin/posts_controller.rb +2 -0
  204. data/test/fixtures/rails_app/app/controllers/admin/project_collaborators_controller.rb +2 -0
  205. data/test/fixtures/rails_app/app/controllers/admin/projects_controller.rb +2 -0
  206. data/test/fixtures/rails_app/app/controllers/admin/status_controller.rb +2 -0
  207. data/test/fixtures/rails_app/app/controllers/admin/typus_users_controller.rb +2 -0
  208. data/test/fixtures/rails_app/app/controllers/admin/users_controller.rb +2 -0
  209. data/test/fixtures/rails_app/app/controllers/admin/views_controller.rb +8 -0
  210. data/test/fixtures/rails_app/app/controllers/admin/watch_dog_controller.rb +2 -0
  211. data/test/fixtures/rails_app/app/controllers/application_controller.rb +3 -0
  212. data/test/fixtures/rails_app/app/helpers/application_helper.rb +2 -0
  213. data/test/fixtures/rails_app/app/helpers/form_helper.rb +3 -0
  214. data/test/fixtures/rails_app/app/models/admin_user.rb +7 -0
  215. data/test/fixtures/rails_app/app/models/animal.rb +21 -0
  216. data/test/fixtures/rails_app/app/models/article.rb +10 -0
  217. data/test/fixtures/rails_app/app/models/article/entry.rb +2 -0
  218. data/test/fixtures/rails_app/app/models/asset.rb +45 -0
  219. data/test/fixtures/rails_app/app/models/bird.rb +2 -0
  220. data/test/fixtures/rails_app/app/models/case.rb +2 -0
  221. data/test/fixtures/rails_app/app/models/category.rb +31 -0
  222. data/test/fixtures/rails_app/app/models/comment.rb +17 -0
  223. data/test/fixtures/rails_app/app/models/delayed/task.rb +5 -0
  224. data/test/fixtures/rails_app/app/models/dog.rb +2 -0
  225. data/test/fixtures/rails_app/app/models/entry.rb +23 -0
  226. data/test/fixtures/rails_app/app/models/hit.rb +27 -0
  227. data/test/fixtures/rails_app/app/models/image_holder.rb +21 -0
  228. data/test/fixtures/rails_app/app/models/invoice.rb +10 -0
  229. data/test/fixtures/rails_app/app/models/order.rb +9 -0
  230. data/test/fixtures/rails_app/app/models/page.rb +24 -0
  231. data/test/fixtures/rails_app/app/models/post.rb +32 -0
  232. data/test/fixtures/rails_app/app/models/project.rb +17 -0
  233. data/test/fixtures/rails_app/app/models/project_collaborator.rb +16 -0
  234. data/test/fixtures/rails_app/app/models/site.rb +16 -0
  235. data/test/fixtures/rails_app/app/models/typus_user.rb +15 -0
  236. data/test/fixtures/rails_app/app/models/user.rb +16 -0
  237. data/test/fixtures/rails_app/app/models/view.rb +19 -0
  238. data/test/fixtures/rails_app/app/views/admin/assets/_index.html.erb +3 -0
  239. data/test/fixtures/rails_app/app/views/admin/cases/_index.html.erb +3 -0
  240. data/test/fixtures/rails_app/app/views/admin/categories/_index.html.erb +3 -0
  241. data/test/fixtures/rails_app/app/views/admin/dashboard/_sidebar.html.erb +11 -0
  242. data/test/fixtures/rails_app/app/views/admin/entries/_index.html.erb +3 -0
  243. data/test/fixtures/rails_app/app/views/admin/hits/_edit.html.erb +7 -0
  244. data/test/fixtures/rails_app/app/views/admin/hits/_index.html.erb +3 -0
  245. data/test/fixtures/rails_app/app/views/admin/hits/index.html.erb +28 -0
  246. data/test/fixtures/rails_app/app/views/admin/pages/_index.html.erb +3 -0
  247. data/test/fixtures/rails_app/app/views/admin/posts/_edit.html.erb +1 -0
  248. data/test/fixtures/rails_app/app/views/admin/posts/_index.html.erb +5 -0
  249. data/test/fixtures/rails_app/app/views/admin/posts/_new.html.erb +1 -0
  250. data/test/fixtures/rails_app/app/views/admin/posts/_show.html.erb +1 -0
  251. data/test/fixtures/rails_app/app/views/admin/resources/_sidebar.html.erb +1 -0
  252. data/test/fixtures/rails_app/app/views/admin/status/index.html.erb +9 -0
  253. data/test/fixtures/rails_app/app/views/admin/templates/_datepicker.html.erb +1 -0
  254. data/test/fixtures/rails_app/app/views/admin/watch_dog/index.html.erb +9 -0
  255. data/test/fixtures/rails_app/config.ru +4 -0
  256. data/test/fixtures/rails_app/config/application.rb +55 -0
  257. data/test/fixtures/rails_app/config/boot.rb +6 -0
  258. data/test/fixtures/rails_app/config/database.yml +42 -0
  259. data/test/fixtures/rails_app/config/deploy.rb +36 -0
  260. data/test/fixtures/rails_app/config/environment.rb +5 -0
  261. data/test/fixtures/rails_app/config/environments/development.rb +38 -0
  262. data/test/fixtures/rails_app/config/environments/production.rb +57 -0
  263. data/test/fixtures/rails_app/config/environments/test.rb +44 -0
  264. data/test/fixtures/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  265. data/test/fixtures/rails_app/config/initializers/dragonfly.rb +1 -0
  266. data/test/fixtures/rails_app/config/initializers/inflections.rb +11 -0
  267. data/test/fixtures/rails_app/config/initializers/mime_types.rb +5 -0
  268. data/test/fixtures/rails_app/config/initializers/secret_token.rb +7 -0
  269. data/test/fixtures/rails_app/config/initializers/session_store.rb +8 -0
  270. data/test/fixtures/rails_app/config/initializers/wrap_parameters.rb +12 -0
  271. data/test/fixtures/rails_app/config/locales/en.yml +5 -0
  272. data/test/fixtures/rails_app/config/mongoid.yml +20 -0
  273. data/test/fixtures/rails_app/config/routes.rb +61 -0
  274. data/test/fixtures/rails_app/config/typus/README +68 -0
  275. data/test/fixtures/rails_app/config/typus/admin.yml +16 -0
  276. data/test/fixtures/rails_app/config/typus/admin_roles.yml +3 -0
  277. data/test/fixtures/rails_app/config/typus/crud_basic.yml +10 -0
  278. data/test/fixtures/rails_app/config/typus/crud_basic_roles.yml +2 -0
  279. data/test/fixtures/rails_app/config/typus/crud_extended.yml +66 -0
  280. data/test/fixtures/rails_app/config/typus/crud_extended_roles.yml +18 -0
  281. data/test/fixtures/rails_app/config/typus/crud_namespaced.yml +10 -0
  282. data/test/fixtures/rails_app/config/typus/crud_namespaced_roles.yml +2 -0
  283. data/test/fixtures/rails_app/config/typus/has_many.yml +0 -0
  284. data/test/fixtures/rails_app/config/typus/has_many_roles.yml +0 -0
  285. data/test/fixtures/rails_app/config/typus/has_many_through.yml +23 -0
  286. data/test/fixtures/rails_app/config/typus/has_many_through_roles.yml +4 -0
  287. data/test/fixtures/rails_app/config/typus/has_one.yml +12 -0
  288. data/test/fixtures/rails_app/config/typus/has_one_roles.yml +3 -0
  289. data/test/fixtures/rails_app/config/typus/mongo_db.yml +4 -0
  290. data/test/fixtures/rails_app/config/typus/mongo_db_roles.yml +2 -0
  291. data/test/fixtures/rails_app/config/typus/polymorphic.yml +17 -0
  292. data/test/fixtures/rails_app/config/typus/polymorphic_roles.yml +5 -0
  293. data/test/fixtures/rails_app/config/typus/resource_roles.yml +7 -0
  294. data/test/fixtures/rails_app/config/typus/sti.yml +5 -0
  295. data/test/fixtures/rails_app/config/typus/sti_roles.yml +2 -0
  296. data/test/fixtures/rails_app/config/typus/unknown.yml +3 -0
  297. data/test/fixtures/rails_app/config/typus/unknown_roles.yml +5 -0
  298. data/test/fixtures/rails_app/db/.gitkeep +0 -0
  299. data/test/fixtures/rails_app/db/schema.rb +209 -0
  300. data/test/fixtures/rails_app/db/seeds.rb +58 -0
  301. data/test/fixtures/rails_app/db/seeds/assets/000.jpg +0 -0
  302. data/test/fixtures/rails_app/db/seeds/assets/001.jpg +0 -0
  303. data/test/fixtures/rails_app/db/seeds/assets/002.jpg +0 -0
  304. data/test/fixtures/rails_app/db/seeds/assets/003.jpg +0 -0
  305. data/test/fixtures/rails_app/db/seeds/assets/004.jpg +0 -0
  306. data/test/fixtures/rails_app/public/404.html +26 -0
  307. data/test/fixtures/rails_app/public/422.html +26 -0
  308. data/test/fixtures/rails_app/public/500.html +26 -0
  309. data/test/fixtures/rails_app/public/favicon.ico +0 -0
  310. data/test/fixtures/rails_app/public/images/rails.png +0 -0
  311. data/test/fixtures/rails_app/public/robots.txt +5 -0
  312. data/test/fixtures/rails_app/public/stylesheets/.gitkeep +0 -0
  313. data/test/fixtures/rails_app/script/rails +6 -0
  314. data/test/lib/support/active_record_test.rb +139 -0
  315. data/test/lib/support/fake_user_test.rb +63 -0
  316. data/test/lib/support/hash_test.rb +25 -0
  317. data/test/lib/support/object_test.rb +10 -0
  318. data/test/lib/support/string_test.rb +80 -0
  319. data/test/lib/typus/configuration_test.rb +48 -0
  320. data/test/lib/typus/controller/actions_test.rb +141 -0
  321. data/test/lib/typus/controller/associations_test.rb +7 -0
  322. data/test/lib/typus/controller/autocomplete_test.rb +7 -0
  323. data/test/lib/typus/controller/filters_test.rb +73 -0
  324. data/test/lib/typus/controller/format_test.rb +7 -0
  325. data/test/lib/typus/i18n_test.rb +13 -0
  326. data/test/lib/typus/orm/active_record/class_methods_test.rb +381 -0
  327. data/test/lib/typus/orm/active_record/search_test.rb +328 -0
  328. data/test/lib/typus/regex_test.rb +62 -0
  329. data/test/lib/typus/resources_test.rb +41 -0
  330. data/test/lib/typus_test.rb +132 -0
  331. data/test/test_helper.rb +41 -0
  332. data/typus.gemspec +3 -10
  333. metadata +525 -137
  334. data/.gitmodules +0 -3
  335. data/app/assets/vendor/typus/javascripts/jquery.rails.js +0 -158
  336. data/app/assets/vendor/typus/vendor/jquery-ui-1.8.12.custom/js/jquery-1.5.1.min.js +0 -16
  337. data/app/views/admin/templates/_text_with_ckeditor.html.erb +0 -13
  338. data/config/locales/typus.pt-PT.models.yml +0 -17
  339. data/config/locales/typus.pt-PT.yml +0 -83
@@ -0,0 +1,74 @@
1
+ require "test_helper"
2
+
3
+ =begin
4
+
5
+ What's being tested here?
6
+
7
+ - Polymorphic associations.
8
+
9
+ =end
10
+
11
+ class Admin::ImageHoldersControllerTest < ActionController::TestCase
12
+
13
+ setup do
14
+ admin_sign_in
15
+ end
16
+
17
+ context "create polymorphic association" do
18
+
19
+ setup do
20
+ @bird = Factory(:bird)
21
+ end
22
+
23
+ should "contain a message" do
24
+ get :new, { :resource => @bird.class.name, :resource_id => @bird.id }
25
+ assert_select 'body div#flash', "Cancel adding a new image holder?"
26
+ end
27
+
28
+ should "work" do
29
+ assert_difference('@bird.image_holders.count') do
30
+ post :create, { :image_holder => { :name => "ImageHolder" },
31
+ :resource => "Bird", :resource_id => @bird.id }
32
+ end
33
+
34
+ assert_response :redirect
35
+ assert_redirected_to "http://test.host/admin/birds/edit/#{@bird.id}"
36
+ assert_equal "Bird successfully updated.", flash[:notice]
37
+ end
38
+
39
+ end
40
+
41
+ ##
42
+ # TODO: Eventually this code should be run in the Original model, so ideally
43
+ # a Bird unrelates ImageHolder and not ImageHolder unrelates Bird.
44
+ #
45
+ context "unrelate" do
46
+
47
+ ##
48
+ # We are in:
49
+ #
50
+ # /admin/birds/edit/1
51
+ #
52
+ # And we see a list of comments under it:
53
+ #
54
+ # /admin/image_holders/unrelate/1?resource=Bird&resource_id=1
55
+ # /admin/image_holders/unrelate/2?resource=Bird&resource_id=1
56
+ # ...
57
+ ##
58
+
59
+ setup do
60
+ @image_holder = Factory(:image_holder)
61
+ @bird = Factory(:bird)
62
+ @bird.image_holders << @image_holder
63
+ @request.env['HTTP_REFERER'] = "/admin/birds/edit/#{@bird.id}"
64
+ end
65
+
66
+ should "work" do
67
+ assert_difference('@bird.image_holders.count', -1) do
68
+ post :unrelate, :id => @image_holder.id, :resource => "Bird", :resource_id => @bird.id
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,77 @@
1
+ require "test_helper"
2
+
3
+ =begin
4
+
5
+ What's being tested here?
6
+
7
+ - Invoice belongs_to Order
8
+
9
+ =end
10
+
11
+ class Admin::InvoicesControllerTest < ActionController::TestCase
12
+
13
+ setup do
14
+ admin_sign_in
15
+ end
16
+
17
+ ##
18
+ # Here we are using the create_with_back_to method.
19
+ #
20
+ # /admin/invoices/new?back_to=&order_id=4&resource=Order&resource_id=4
21
+ #
22
+ context "Create an invoice from an Order" do
23
+
24
+ setup do
25
+ @order = Factory(:order)
26
+ @invoice = { :number => "Invoice#0000001" }
27
+ end
28
+
29
+ should "initialize the object with the params passed on the url" do
30
+ get :new, :resource => "Order", :resource => "Order", :order_id => @order.id
31
+ assert assigns(:item).order.eql?(@order)
32
+ end
33
+
34
+ # TODO: Take a look at this to refactor the create method.
35
+ should "create new invoice assign it to order and redirect to order" do
36
+ @invoice = { :number => "Invoice#0000001", :order_id => @order.id }
37
+
38
+ assert_difference('Invoice.count') do
39
+ post :create, { :invoice => @invoice, :resource => "Order", :order_id => @order.id }
40
+ end
41
+
42
+ assert_response :redirect
43
+ assert_redirected_to "/admin/orders/edit/#{@order.id}"
44
+ end
45
+
46
+ should_eventually "raise an error if we try to add an invoice to an order which already has an invoice" do
47
+ @invoice = Factory(:invoice)
48
+ get :new, { :resource => "Order", :resource_id => @invoice.order.id, :order_id => @invoice.order.id }
49
+ assert_response :unprocessable_entity
50
+ end
51
+
52
+ should_eventually "raise an error if we try to create an invoice to an order which already has an invoice" do
53
+ @invoice = Factory(:invoice)
54
+ post :create, :invoice => { :number => "Invoice#0000001" },
55
+ :resource => "Order", :resource_id => @invoice.order.id, :order_id => @invoice.order.id
56
+ assert_response :unprocessable_entity
57
+ end
58
+
59
+ end
60
+
61
+ context "Unrelate" do
62
+
63
+ setup do
64
+ @invoice = Factory(:invoice)
65
+ @order = @invoice.order
66
+ @request.env['HTTP_REFERER'] = "/admin/orders/edit/#{@order.id}"
67
+ end
68
+
69
+ should "work for unrelate Invoice from Order" do
70
+ post :unrelate, :id => @invoice.id, :resource => 'Order', :resource_id => @order.id
71
+ assert @order.reload.invoice.nil?
72
+ assert_equal "Order successfully updated.", flash[:notice]
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,17 @@
1
+ require "test_helper"
2
+
3
+ =begin
4
+
5
+ What's being tested here?
6
+
7
+ - Order has_one Invoice
8
+
9
+ =end
10
+
11
+ class Admin::OrdersControllerTest < ActionController::TestCase
12
+
13
+ setup do
14
+ admin_sign_in
15
+ end
16
+
17
+ end
@@ -0,0 +1,33 @@
1
+ require "test_helper"
2
+
3
+ =begin
4
+
5
+ What's being tested here?
6
+
7
+ - Scopes
8
+
9
+ Hey! I do not recommend setting a default_scope because you'll probably get
10
+ unexpected results. This is here for testing purposes, but please, avoid
11
+ using this kind of stuff.
12
+
13
+ =end
14
+
15
+ class Admin::PagesControllerTest < ActionController::TestCase
16
+
17
+ setup do
18
+ admin_sign_in
19
+ Factory(:page)
20
+ Factory(:page, :status => false)
21
+ end
22
+
23
+ teardown do
24
+ Page.delete_all
25
+ TypusUser.delete_all
26
+ end
27
+
28
+ test "get :index returns scoped results" do
29
+ get :index
30
+ assert_equal Page.all, assigns(:items)
31
+ end
32
+
33
+ end
@@ -0,0 +1,764 @@
1
+ require "test_helper"
2
+
3
+ =begin
4
+
5
+ What's being tested here?
6
+
7
+ - CRUD: Create, read, update, destroy
8
+ - CRUD Extras: toggle
9
+ - Filters
10
+ - Forms
11
+ - Overrides
12
+ - Permissions
13
+ - Roles
14
+ - Views
15
+
16
+ =end
17
+
18
+ class Admin::PostsControllerTest < ActionController::TestCase
19
+
20
+ setup do
21
+ admin_sign_in
22
+ @post = Factory(:post)
23
+ end
24
+
25
+ teardown do
26
+ Post.delete_all
27
+ TypusUser.delete_all
28
+ end
29
+
30
+ ##############################################################################
31
+ #
32
+ ##############################################################################
33
+
34
+ context "CRUD" do
35
+
36
+ should "render index" do
37
+ get :index
38
+ assert_response :success
39
+ assert_template 'index'
40
+ end
41
+
42
+ context "new" do
43
+
44
+ should "render" do
45
+ get :new
46
+ assert_response :success
47
+ assert_template 'new'
48
+ end
49
+
50
+ should "reject params which are not included in @resource.columns.map(&:name)" do
51
+ %w(chunky_bacon).each do |param|
52
+ get :new, {param => param}
53
+ assert_response :success
54
+ assert_template 'new'
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ should "create" do
61
+ assert_difference('Post.count') do
62
+ post :create, :post => @post.attributes
63
+ assert_response :redirect
64
+ assert_redirected_to "/admin/posts/edit/#{Post.last.id}"
65
+ end
66
+ end
67
+
68
+ should "render show" do
69
+ get :show, :id => @post.id
70
+ assert_response :success
71
+ assert_template 'show'
72
+ end
73
+
74
+ should "render edit" do
75
+ get :edit, :id => @post.id
76
+ assert_response :success
77
+ assert_template 'edit'
78
+ end
79
+
80
+ should "update" do
81
+ post :update, :id => @post.id, :post => { :title => 'Updated' }
82
+ assert_response :redirect
83
+ assert_redirected_to "/admin/posts/edit/#{@post.id}"
84
+ end
85
+
86
+ end
87
+
88
+ context "CRUD extras" do
89
+
90
+ setup do
91
+ @request.env['HTTP_REFERER'] = "/admin/posts"
92
+ end
93
+
94
+ context "toggle" do
95
+
96
+ should "work" do
97
+ assert !@post.published
98
+ get :toggle, :id => @post.id, :field => "published"
99
+
100
+ assert_response :redirect
101
+ assert_redirected_to @request.env["HTTP_REFERER"]
102
+ assert_equal "Post successfully updated.", flash[:notice]
103
+ assert @post.reload.published
104
+ end
105
+
106
+ should "render edit post when validation fails" do
107
+ @post.body = nil
108
+ @post.save(:validate => false)
109
+ get :toggle, :id => @post.id, :field => "published"
110
+ assert_response :success
111
+ assert_template "admin/resources/edit"
112
+ end
113
+
114
+ end
115
+
116
+ end
117
+
118
+ context "Filters" do
119
+
120
+ should "render index with accepted params" do
121
+ @post.update_attributes(:published => true)
122
+ get :index, :published => 'true'
123
+ assert_response :success
124
+ assert_template 'index'
125
+ assert assigns(:items).size.eql?(1)
126
+
127
+ get :index, :published => 'false'
128
+ assert assigns(:items).size.eql?(0)
129
+ end
130
+
131
+ should "render index with accepted params - search" do
132
+ @post.update_attributes(:title => "neinonon")
133
+ get :index, :search => 'neinonon'
134
+ assert_response :success
135
+ assert_template 'index'
136
+ assert assigns(:items).size.eql?(1)
137
+
138
+ get :index, :search => 'unexisting'
139
+ assert assigns(:items).size.eql?(0)
140
+ end
141
+
142
+ should "render index with non-accepted params" do
143
+ get :index, :non_accepted_param => 'non_accepted_param'
144
+ assert_response :success
145
+ assert_template 'index'
146
+ end
147
+
148
+ end
149
+
150
+ context "Filters" do
151
+
152
+ should "be included in index" do
153
+ get :index
154
+ assert assigns(:predefined_filters).nil?
155
+ end
156
+
157
+ end
158
+
159
+ context "Actions" do
160
+
161
+ should "be edit and trash on index" do
162
+ get :index
163
+
164
+ expected = [["Edit", {"action"=>"edit"}, {}],
165
+ ["Trash", {"action"=>"destroy"}, {"method"=>"delete", "confirm"=>"Trash?"}]]
166
+
167
+ assert_equal expected, assigns(:resource_actions)
168
+ end
169
+
170
+ context "with overriden default action on item" do
171
+
172
+ setup do
173
+ Typus::Resources.expects(:default_action_on_item).at_least_once.returns('show')
174
+ end
175
+
176
+ should "be show and trash on index" do
177
+ get :index
178
+
179
+ expected = [["Show", {"action"=>"show"}, {}],
180
+ ["Trash", {"action"=>"destroy"}, {"method"=>"delete", "confirm"=>"Trash?"}]]
181
+
182
+ assert_equal expected, assigns(:resource_actions)
183
+ end
184
+
185
+ end
186
+
187
+ end
188
+
189
+ context "Forms" do
190
+
191
+ setup do
192
+ get :new
193
+ end
194
+
195
+ should "verify forms" do
196
+ assert_select "form"
197
+ end
198
+
199
+ # We have 3 inputs: 1 hidden which is the UTF8 stuff, one which is the
200
+ # Post#title and finally the submit button.
201
+ should "have 3 inputs" do
202
+ assert_select "form input", 3
203
+
204
+ # Post#title: Input
205
+ assert_select 'label[for="post_title"]'
206
+ assert_select 'input#post_title[type="text"]'
207
+ end
208
+
209
+ should "have 1 textarea" do
210
+ assert_select "form textarea", 1
211
+
212
+ # Post#body: Text Area
213
+ assert_select 'label[for="post_body"]'
214
+ assert_select 'textarea#post_body'
215
+ end
216
+
217
+ should "have 6 selectors" do
218
+ assert_select "form select", 6
219
+
220
+ # Post#created_at: Datetime
221
+ assert_select 'label[for="post_created_at"]'
222
+ assert_select 'select#post_created_at_1i'
223
+ assert_select 'select#post_created_at_2i'
224
+ assert_select 'select#post_created_at_3i'
225
+ assert_select 'select#post_created_at_4i'
226
+ assert_select 'select#post_created_at_5i'
227
+
228
+ # Post#status: Selector
229
+ assert_select 'label[for="post_status"]'
230
+ assert_select 'select#post_status'
231
+ end
232
+
233
+ should "have 1 template" do
234
+ assert_match "templates#datepicker_template_published_at", @response.body
235
+ end
236
+
237
+ end
238
+
239
+ context "Overwrite action_after_save" do
240
+
241
+ setup do
242
+ Typus::Resources.expects(:action_after_save).returns("index")
243
+ @post = Factory(:post)
244
+ end
245
+
246
+ should "create an item and redirect to index" do
247
+ assert_difference('Post.count') do
248
+ post :create, :post => @post.attributes
249
+ assert_response :redirect
250
+ assert_redirected_to :action => 'index'
251
+ end
252
+ end
253
+
254
+ should "update an item and redirect to index" do
255
+ post :update, :id => @post.id, :post => { :title => 'Updated' }
256
+ assert_response :redirect
257
+ assert_redirected_to :action => 'index'
258
+ end
259
+
260
+ end
261
+
262
+ context "Formats" do
263
+
264
+ should "render index and return xml" do
265
+ get :index, :format => "xml"
266
+
267
+ assert_response :success
268
+
269
+ assert_match %Q[<?xml version="1.0" encoding="UTF-8"?>], @response.body
270
+ assert_match %Q[<posts type="array">], @response.body
271
+ assert_match "<status>#{@post.status}</status>", @response.body
272
+ assert_match "<title>#{@post.title}</title>", @response.body
273
+ end
274
+
275
+ should "render index and return csv" do
276
+ expected = <<-RAW
277
+ title;status
278
+ #{@post.title};#{@post.status}
279
+ RAW
280
+
281
+ get :index, :format => "csv"
282
+
283
+ assert_response :success
284
+ assert_equal expected, @response.body
285
+ end
286
+
287
+ should "not instantiate resource_actions" do
288
+ get :index, :format => "xml"
289
+ assert assigns(:resource_actions).nil?
290
+ end
291
+
292
+ should "not instantiate predefined_filters" do
293
+ get :index, :format => "xml"
294
+ assert assigns(:predefined_filters).nil?
295
+ end
296
+
297
+ end
298
+
299
+ context "Permissions" do
300
+
301
+ context "Root" do
302
+
303
+ setup do
304
+ @editor = Factory(:typus_user, :email => "editor@example.com", :role => "editor")
305
+ @post = Factory(:post, :typus_user => @editor)
306
+ end
307
+
308
+ should "should list all posts no matter who is the owner" do
309
+ Post.delete_all
310
+ admin = TypusUser.where(:role => 'admin').first
311
+ 2.times { Factory(:post, :typus_user => @editor) }
312
+ 2.times { Factory(:post, :typus_user => @typus_user) }
313
+ Typus::Resources.expects(:only_user_items).returns(true)
314
+
315
+ get :index
316
+
317
+ assert Post.count.eql?(4)
318
+ assert assigns(:items).size.eql?(4)
319
+ assert_equal [@editor.id, @editor.id, @typus_user.id, @typus_user.id], assigns(:items).map(&:typus_user_id)
320
+ end
321
+
322
+ should "be able to edit any record" do
323
+ Post.all.each do |post|
324
+ get :edit, :id => post.id
325
+ assert_response :success
326
+ assert_template 'edit'
327
+ end
328
+ end
329
+
330
+ should "verify_admin_updating_an_item_does_not_change_typus_user_id_if_not_defined" do
331
+ _post = @post
332
+ post :update, :id => @post.id, :post => { :title => 'Updated by admin' }
333
+ assert_equal _post.typus_user_id, @post.reload.typus_user_id
334
+ end
335
+
336
+ should "verify_admin_updating_an_item_does_change_typus_user_id_to_whatever_admin_wants" do
337
+ post :update, :id => @post.id, :post => { :title => 'Updated', :typus_user_id => 108 }
338
+ assert @post.reload.typus_user_id.eql?(108)
339
+ end
340
+
341
+ end
342
+
343
+ context "No root" do
344
+
345
+ setup do
346
+ editor_sign_in
347
+ @request.env['HTTP_REFERER'] = '/admin/posts'
348
+ end
349
+
350
+ should "not be root" do
351
+ assert @typus_user.is_not_root?
352
+ end
353
+
354
+ should "verify_editor_can_show_any_record" do
355
+ Post.all.each do |post|
356
+ get :show, :id => post.id
357
+ assert_response :success
358
+ assert_template 'show'
359
+ end
360
+ end
361
+
362
+ should "verify_editor_tried_to_edit_a_post_owned_by_himself" do
363
+ get :edit, :id => Factory(:post, :typus_user => @typus_user).id
364
+ assert_response :success
365
+ end
366
+
367
+ should "verify_editor_tries_to_edit_a_post_owned_by_the_admin" do
368
+ get :edit, :id => Factory(:post).id
369
+ assert_response :unprocessable_entity
370
+ end
371
+
372
+ should "verify_editor_tries_to_show_a_post_owned_by_the_admin" do
373
+ get :show, :id => Factory(:post).id
374
+ assert_response :success
375
+ end
376
+
377
+ should "only list editor posts" do
378
+ Post.delete_all
379
+ admin = TypusUser.where(:role => 'admin').first
380
+ 2.times { Factory(:post, :typus_user => admin) }
381
+ 2.times { Factory(:post, :typus_user => @typus_user) }
382
+ Typus::Resources.expects(:only_user_items).returns(true)
383
+
384
+ get :index
385
+
386
+ assert Post.count.eql?(4)
387
+ assert assigns(:items).size.eql?(2)
388
+ assert_equal [@typus_user.id, @typus_user.id], assigns(:items).map(&:typus_user_id)
389
+ end
390
+
391
+ should "verify_editor_tries_to_show_a_post_owned_by_the_admin when only user items" do
392
+ Typus::Resources.expects(:only_user_items).returns(true)
393
+ post = Factory(:post)
394
+ get :show, :id => post.id
395
+ assert_response :unprocessable_entity
396
+ end
397
+
398
+ should "verify_typus_user_id_of_item_when_creating_record" do
399
+ assert_difference('Post.count') do
400
+ post :create, :post => { :title => "Chunky Bacon", :body => "Lorem ipsum ..." }
401
+ end
402
+
403
+ assert_equal @request.session[:typus_user_id], assigns(:item).typus_user_id
404
+ end
405
+
406
+ should "verify_editor_updating_an_item_does_not_change_typus_user_id" do
407
+ [ 108, nil ].each do |typus_user_id|
408
+ post_ = Factory(:post, :typus_user => @typus_user)
409
+ post :update, :id => post_.id, :post => { :title => 'Updated', :typus_user_id => @typus_user.id }
410
+ post_updated = Post.find(post_.id)
411
+ assert_equal @request.session[:typus_user_id], post_updated.typus_user_id
412
+ end
413
+ end
414
+
415
+ end
416
+
417
+ end
418
+
419
+ context "Roles" do
420
+
421
+ setup do
422
+ @request.env['HTTP_REFERER'] = '/admin/posts'
423
+ end
424
+
425
+ context "Admin" do
426
+
427
+ should "be able to add posts" do
428
+ assert @typus_user.can?("create", "Post")
429
+ end
430
+
431
+ should "be able to destroy posts" do
432
+ get :destroy, :id => Factory(:post).id, :method => :delete
433
+
434
+ assert_response :redirect
435
+ assert_equal "Post successfully removed.", flash[:notice]
436
+ assert_redirected_to :action => :index
437
+ end
438
+
439
+ end
440
+
441
+ context "Designer" do
442
+
443
+ setup do
444
+ Typus.user_class.delete_all
445
+ @designer = Factory(:typus_user, :role => "designer")
446
+ @request.session[:typus_user_id] = @designer.id
447
+ @post = Factory(:post)
448
+ end
449
+
450
+ should "not be able to add posts" do
451
+ get :new
452
+
453
+ assert_response :unprocessable_entity
454
+ end
455
+
456
+ should "not be able to destroy posts" do
457
+ assert_no_difference('Post.count') do
458
+ get :destroy, :id => @post.id, :method => :delete
459
+ end
460
+ assert_response :unprocessable_entity
461
+ end
462
+
463
+ end
464
+
465
+ end
466
+
467
+ context "Relationships (relate)" do
468
+
469
+ setup do
470
+ @post = Factory(:post)
471
+ end
472
+
473
+ should "relate comment to post (has_many)" do
474
+ comment = Factory(:comment, :post => nil)
475
+ @request.env['HTTP_REFERER'] = "/admin/posts/edit/#{@post.id}#comments"
476
+
477
+ assert_difference('@post.comments.count') do
478
+ post :relate, :id => @post.id, :related => { :model => 'Comment', :id => comment.id, :association_name => 'comments' }
479
+ end
480
+
481
+ assert_response :redirect
482
+ assert_redirected_to @request.env['HTTP_REFERER']
483
+ assert_equal "Post successfully updated.", flash[:notice]
484
+ end
485
+
486
+ should "return a message instead a 404 error if related_id is empty" do
487
+ comment = Factory(:comment, :post => nil)
488
+ @request.env['HTTP_REFERER'] = "/admin/posts/edit/#{@post.id}#comments"
489
+
490
+ assert_no_difference('@post.comments.count') do
491
+ post :relate, :id => @post.id, :related => { :model => 'Comment', :id => "", :association_name => 'comments' }
492
+ end
493
+
494
+ assert_response :redirect
495
+ assert_redirected_to @request.env['HTTP_REFERER']
496
+ assert_equal "Please, select an option.", flash[:notice]
497
+ end
498
+
499
+ should "return a message instead a 404 error if related_id is nil" do
500
+ comment = Factory(:comment, :post => nil)
501
+ @request.env['HTTP_REFERER'] = "/admin/posts/edit/#{@post.id}#comments"
502
+
503
+ assert_no_difference('@post.comments.count') do
504
+ post :relate, :id => @post.id, :related => { :model => 'Comment', :id => nil, :association_name => 'comments' }
505
+ end
506
+
507
+ assert_response :redirect
508
+ assert_redirected_to @request.env['HTTP_REFERER']
509
+ assert_equal "Please, select an option.", flash[:notice]
510
+ end
511
+
512
+ should "relate category to post (has_and_belongs_to_many)" do
513
+ category = Factory(:category)
514
+ @request.env['HTTP_REFERER'] = "/admin/posts/edit/#{@post.id}#categories"
515
+
516
+ assert_difference('category.posts.count') do
517
+ post :relate, :id => @post.id, :related => { :model => 'Category', :id => category.id, :association_name => 'categories' }
518
+ end
519
+
520
+ assert_response :redirect
521
+ assert_redirected_to @request.env['HTTP_REFERER']
522
+ assert_equal "Post successfully updated.", flash[:notice]
523
+ end
524
+
525
+ end
526
+
527
+ context "Views" do
528
+
529
+ context "Index" do
530
+
531
+ setup do
532
+ get :index
533
+ end
534
+
535
+ should "render index and validates_presence_of_custom_partials" do
536
+ assert_match "posts#_index.html.erb", @response.body
537
+ end
538
+
539
+ should "render_index_and_verify_page_title" do
540
+ assert_select "title", "Typus &mdash; Posts"
541
+ end
542
+
543
+ should "render index_and_show_add_entry_link" do
544
+ assert_select "#sidebar ul" do
545
+ assert_select "li", "Add new"
546
+ end
547
+ end
548
+
549
+ end
550
+
551
+ context "New" do
552
+
553
+ setup do
554
+ get :new
555
+ end
556
+
557
+ should "render new and partials_on_new" do
558
+ assert_match "posts#_new.html.erb", @response.body
559
+ end
560
+
561
+ should "render new and verify page title" do
562
+ assert_select "title", "Typus &mdash; New Post"
563
+ end
564
+
565
+ end
566
+
567
+ context "Edit" do
568
+
569
+ setup do
570
+ get :edit, :id => Factory(:post).id
571
+ end
572
+
573
+ should "render_edit_and_verify_presence_of_custom_partials" do
574
+ assert_match "posts#_edit.html.erb", @response.body
575
+ end
576
+
577
+ should "render_edit_and_verify_page_title" do
578
+ assert_select "title", "Typus &mdash; Edit Post"
579
+ end
580
+
581
+ end
582
+
583
+ context "Show" do
584
+
585
+ setup do
586
+ get :show, :id => Factory(:post).id
587
+ end
588
+
589
+ should "render_show_and_verify_presence_of_custom_partials" do
590
+ assert_match "posts#_show.html.erb", @response.body
591
+ end
592
+
593
+ should "render show and verify page title" do
594
+ assert_select "title", "Typus &mdash; Show Post"
595
+ end
596
+
597
+ end
598
+
599
+ should "get_index_and_render_edit_or_show_links" do
600
+ %w(edit show).each do |action|
601
+ Typus::Resources.expects(:default_action_on_item).at_least_once.returns(action)
602
+ get :index
603
+ Post.all.each do |post|
604
+ assert_match "/posts/#{action}/#{post.id}", @response.body
605
+ end
606
+ end
607
+ end
608
+
609
+ context "Designer" do
610
+
611
+ setup do
612
+ designer_sign_in
613
+ end
614
+
615
+ should "render_index_and_not_show_add_entry_link" do
616
+ get :index
617
+ assert_response :success
618
+ assert_no_match /Add Post/, @response.body
619
+ end
620
+
621
+ end
622
+
623
+ context "Editor" do
624
+
625
+ setup do
626
+ editor_sign_in
627
+ end
628
+
629
+ =begin
630
+
631
+ ##
632
+ # This feature is no longer available. I've to decide if I want to take
633
+ # it back.
634
+ #
635
+ should "get_index_and_render_edit_or_show_links_on_owned_records" do
636
+ get :index
637
+ Post.all.each do |post|
638
+ action = post.owned_by?(@typus_user) ? "edit" : "show"
639
+ assert_match "/posts/#{action}/#{post.id}", @response.body
640
+ end
641
+ end
642
+
643
+ =end
644
+
645
+ should "get_index_and_render_edit_or_show_on_only_user_items" do
646
+ %w(edit show).each do |action|
647
+ Typus::Resources.stubs(:only_user_items).returns(true)
648
+ Typus::Resources.stubs(:default_action_on_item).returns(action)
649
+ get :index
650
+ Post.all.each do |post|
651
+ if @typus_user.owns?(post)
652
+ assert_match "/posts/#{action}/#{post.id}", @response.body
653
+ else
654
+ assert_no_match /\/posts\/#{action}\/#{post.id}/, @response.body
655
+ end
656
+ end
657
+ end
658
+ end
659
+
660
+ end
661
+
662
+ end
663
+
664
+ ##
665
+ # We are in a View and we want to create a new Post from there to be able
666
+ # to assign it. There are two cases:
667
+ #
668
+ # - We are creating the view.
669
+ # - We are editing the view.
670
+ #
671
+ context "create_with_back_to" do
672
+
673
+ setup do
674
+ @post = { :title => 'This is another title', :body => 'Body' }
675
+ end
676
+
677
+ context "when creating an item" do
678
+
679
+ ##
680
+ # We click on the "Add new" link and we are redirected to:
681
+ #
682
+ # /admin/posts/new
683
+ #
684
+ # With a collection of params which will be used to create the
685
+ # association if everything works as expected.
686
+ #
687
+ # Once the association is created we are redirected back to where we
688
+ # started with a param which selects the Post on the View form.
689
+ #
690
+ # /admin/views/new?post_id=1
691
+ #
692
+ # So we end up having a new Post and if we save the form will be
693
+ # assigned to the view.
694
+ #
695
+
696
+ should "create new post and redirect to view" do
697
+ assert_difference('Post.count') do
698
+ post :create, :post => @post, :resource => "View"
699
+ end
700
+
701
+ assert_response :redirect
702
+ assert_redirected_to "/admin/views/new?post_id=#{Post.last.id}"
703
+ end
704
+
705
+ end
706
+
707
+ context "when editing an item" do
708
+
709
+ ##
710
+ # We click on the "Add new" link and we are redirected to:
711
+ #
712
+ # /admin/posts/new
713
+ #
714
+ # The important thing here is that we are passing the `resource_id`
715
+ # because we will assign the newly created Post to the View.
716
+ #
717
+ # So we will end up having a new Post assigned to the View.
718
+ #
719
+
720
+ setup do
721
+ @view = Factory(:view, :post => nil)
722
+ end
723
+
724
+ should "create new post and redirect to view" do
725
+ assert_difference('Post.count') do
726
+ post :create, :post => @post, :resource => "View", :resource_id => @view.id
727
+ end
728
+ assert_response :redirect
729
+ assert_redirected_to "/admin/views/edit/#{@view.id}"
730
+
731
+ # Make sure the association is created!
732
+ assert @view.reload.post
733
+ end
734
+
735
+ end
736
+
737
+ end
738
+
739
+ context "autocomplete" do
740
+
741
+ setup do
742
+ 25.times { Factory(:post) }
743
+ end
744
+
745
+ should "work and return a json hash with ten items" do
746
+ get :autocomplete, { :term => "Post" }
747
+ assert_response :success
748
+ assert assigns(:items).size.eql?(20)
749
+ end
750
+
751
+ should "work and return json hash with one item" do
752
+ post = Post.first
753
+ post.update_attributes(:title => "fesplugas")
754
+
755
+ get :autocomplete, :term => "jmeiss"
756
+ assert assigns(:items).size.eql?(0)
757
+
758
+ get :autocomplete, :term => "fesplugas"
759
+ assert assigns(:items).size.eql?(1)
760
+ end
761
+
762
+ end
763
+
764
+ end