admin_assistant 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (377) hide show
  1. data/.gitignore +16 -0
  2. data/Rakefile +34 -6
  3. data/VERSION +1 -0
  4. data/admin_assistant.gemspec +440 -0
  5. data/doc/img/blog_posts-index.png +0 -0
  6. data/install.rb +25 -4
  7. data/lib/admin_assistant/active_record_column.rb +133 -45
  8. data/lib/admin_assistant/association_target.rb +16 -3
  9. data/lib/admin_assistant/belongs_to_column.rb +18 -10
  10. data/lib/admin_assistant/builder.rb +67 -30
  11. data/lib/admin_assistant/column.rb +153 -71
  12. data/lib/admin_assistant/date_time_range_end_point_selector.rb +340 -0
  13. data/lib/admin_assistant/default_search_column.rb +3 -7
  14. data/lib/admin_assistant/form_view.rb +114 -10
  15. data/lib/admin_assistant/has_many_column.rb +56 -0
  16. data/lib/admin_assistant/index.rb +220 -83
  17. data/lib/admin_assistant/polymorphic_belongs_to_column.rb +1 -1
  18. data/lib/admin_assistant/request/base.rb +196 -67
  19. data/lib/admin_assistant/request/create.rb +55 -7
  20. data/lib/admin_assistant/request/edit.rb +1 -2
  21. data/lib/admin_assistant/request/index.rb +16 -9
  22. data/lib/admin_assistant/request/new.rb +19 -7
  23. data/lib/admin_assistant/request/update.rb +28 -13
  24. data/lib/admin_assistant/search.rb +17 -2
  25. data/lib/admin_assistant/virtual_column.rb +15 -7
  26. data/lib/admin_assistant.rb +101 -81
  27. data/lib/javascripts/admin_assistant.js +1 -1
  28. data/lib/stylesheets/activescaffold.css +6 -1
  29. data/lib/stylesheets/default.css +17 -0
  30. data/lib/views/form.html.erb +7 -3
  31. data/lib/views/index.html.erb +13 -8
  32. data/lib/views/multi_form.html.erb +71 -0
  33. data/lib/views/show.html.erb +4 -4
  34. data/test_rails_app/README +256 -0
  35. data/test_rails_app/Rakefile +13 -0
  36. data/test_rails_app/app/controllers/admin/appointments2_controller.rb +15 -0
  37. data/test_rails_app/app/controllers/admin/appointments_controller.rb +11 -0
  38. data/test_rails_app/app/controllers/admin/blog_posts2_controller.rb +138 -0
  39. data/test_rails_app/app/controllers/admin/blog_posts3_controller.rb +76 -0
  40. data/test_rails_app/app/controllers/admin/blog_posts4_controller.rb +21 -0
  41. data/test_rails_app/app/controllers/admin/blog_posts5_controller.rb +27 -0
  42. data/test_rails_app/app/controllers/admin/blog_posts6_controller.rb +10 -0
  43. data/test_rails_app/app/controllers/admin/blog_posts_controller.rb +8 -0
  44. data/test_rails_app/app/controllers/admin/blog_posts_custom_new_and_edit_controller.rb +15 -0
  45. data/test_rails_app/app/controllers/admin/blog_posts_read_only_controller.rb +19 -0
  46. data/test_rails_app/app/controllers/admin/bookmarks_controller.rb +11 -0
  47. data/test_rails_app/app/controllers/admin/comments2_controller.rb +14 -0
  48. data/test_rails_app/app/controllers/admin/comments_controller.rb +12 -0
  49. data/test_rails_app/app/controllers/admin/file_column_images2_controller.rb +10 -0
  50. data/test_rails_app/app/controllers/admin/file_column_images_controller.rb +6 -0
  51. data/test_rails_app/app/controllers/admin/images2_controller.rb +11 -0
  52. data/test_rails_app/app/controllers/admin/images_controller.rb +6 -0
  53. data/test_rails_app/app/controllers/admin/misconfigured1_controller.rb +7 -0
  54. data/test_rails_app/app/controllers/admin/not_migrated_yets_controller.rb +9 -0
  55. data/test_rails_app/app/controllers/admin/product_categories2_controller.rb +7 -0
  56. data/test_rails_app/app/controllers/admin/product_categories_controller.rb +5 -0
  57. data/test_rails_app/app/controllers/admin/products2_controller.rb +15 -0
  58. data/test_rails_app/app/controllers/admin/products_controller.rb +31 -0
  59. data/test_rails_app/app/controllers/admin/television_airings_controller.rb +5 -0
  60. data/test_rails_app/app/controllers/admin/television_time_slots_controller.rb +5 -0
  61. data/test_rails_app/app/controllers/admin/users2_controller.rb +10 -0
  62. data/test_rails_app/app/controllers/admin/users_controller.rb +63 -0
  63. data/test_rails_app/app/controllers/application.rb +16 -0
  64. data/test_rails_app/app/controllers/application_controller.rb +16 -0
  65. data/test_rails_app/app/controllers/blog_posts_controller.rb +5 -0
  66. data/test_rails_app/app/helpers/admin/appointments2_helper.rb +2 -0
  67. data/test_rails_app/app/helpers/admin/appointments_helper.rb +2 -0
  68. data/test_rails_app/app/helpers/admin/blog_posts2_helper.rb +27 -0
  69. data/test_rails_app/app/helpers/admin/blog_posts3_helper.rb +2 -0
  70. data/test_rails_app/app/helpers/admin/blog_posts4_helper.rb +2 -0
  71. data/test_rails_app/app/helpers/admin/blog_posts6_helper.rb +16 -0
  72. data/test_rails_app/app/helpers/admin/blog_posts_custom_new_and_edit_helper.rb +29 -0
  73. data/test_rails_app/app/helpers/admin/blog_posts_helper.rb +2 -0
  74. data/test_rails_app/app/helpers/admin/blog_posts_read_only_helper.rb +2 -0
  75. data/test_rails_app/app/helpers/admin/bookmarks_helper.rb +2 -0
  76. data/test_rails_app/app/helpers/admin/comments2_helper.rb +2 -0
  77. data/test_rails_app/app/helpers/admin/comments_helper.rb +2 -0
  78. data/test_rails_app/app/helpers/admin/file_column_images2_helper.rb +2 -0
  79. data/test_rails_app/app/helpers/admin/file_column_images_helper.rb +2 -0
  80. data/test_rails_app/app/helpers/admin/images2_helper.rb +8 -0
  81. data/test_rails_app/app/helpers/admin/images_helper.rb +2 -0
  82. data/test_rails_app/app/helpers/admin/misconfigured1_helper.rb +2 -0
  83. data/test_rails_app/app/helpers/admin/not_migrated_yets_helper.rb +2 -0
  84. data/test_rails_app/app/helpers/admin/product_categories2_helper.rb +2 -0
  85. data/test_rails_app/app/helpers/admin/product_categories_helper.rb +2 -0
  86. data/test_rails_app/app/helpers/admin/products2_helper.rb +3 -0
  87. data/test_rails_app/app/helpers/admin/products_helper.rb +6 -0
  88. data/test_rails_app/app/helpers/admin/television_airings_helper.rb +2 -0
  89. data/test_rails_app/app/helpers/admin/television_time_slots_helper.rb +2 -0
  90. data/test_rails_app/app/helpers/admin/users2_helper.rb +2 -0
  91. data/test_rails_app/app/helpers/admin/users_helper.rb +25 -0
  92. data/test_rails_app/app/helpers/application_helper.rb +3 -0
  93. data/test_rails_app/app/helpers/blog_posts_helper.rb +2 -0
  94. data/test_rails_app/app/models/appointment.rb +5 -0
  95. data/test_rails_app/app/models/blog_post.rb +14 -0
  96. data/test_rails_app/app/models/blog_post_tag.rb +6 -0
  97. data/test_rails_app/app/models/bookmark.rb +6 -0
  98. data/test_rails_app/app/models/comment.rb +4 -0
  99. data/test_rails_app/app/models/file_column_image.rb +3 -0
  100. data/test_rails_app/app/models/image.rb +3 -0
  101. data/test_rails_app/app/models/not_migrated_yet.rb +2 -0
  102. data/test_rails_app/app/models/product.rb +7 -0
  103. data/test_rails_app/app/models/product_category.rb +9 -0
  104. data/test_rails_app/app/models/tag.rb +4 -0
  105. data/test_rails_app/app/models/television_airing.rb +3 -0
  106. data/test_rails_app/app/models/television_time_slot.rb +11 -0
  107. data/test_rails_app/app/models/user.rb +14 -0
  108. data/test_rails_app/app/views/admin/appointments/_subject_input.html.erb +2 -0
  109. data/test_rails_app/app/views/admin/appointments2/_time_input.html.erb +31 -0
  110. data/test_rails_app/app/views/admin/blog_posts2/_after_form.html.erb +5 -0
  111. data/test_rails_app/app/views/admin/blog_posts2/_after_index.html.erb +1 -0
  112. data/test_rails_app/app/views/admin/blog_posts2/_after_tags_input.html.erb +16 -0
  113. data/test_rails_app/app/views/admin/blog_posts2/_before_index.html.erb +2 -0
  114. data/test_rails_app/app/views/admin/blog_posts5/_after_index_header.html.erb +8 -0
  115. data/test_rails_app/app/views/admin/blog_posts_read_only/_body_for_show.html.erb +1 -0
  116. data/test_rails_app/app/views/admin/products/_name_input.html.erb +2 -0
  117. data/test_rails_app/app/views/admin/products/_percent_off_input.html.erb +2 -0
  118. data/test_rails_app/app/views/admin/products/_price_input.html.erb +10 -0
  119. data/test_rails_app/app/views/blog_posts/show.html.erb +13 -0
  120. data/test_rails_app/app/views/layouts/admin.html.erb +31 -0
  121. data/test_rails_app/config/boot.rb +109 -0
  122. data/test_rails_app/config/database.yml +28 -0
  123. data/test_rails_app/config/environment.rb +78 -0
  124. data/test_rails_app/config/environments/development.rb +17 -0
  125. data/test_rails_app/config/environments/production.rb +24 -0
  126. data/test_rails_app/config/environments/test.rb +24 -0
  127. data/test_rails_app/config/initializers/inflections.rb +10 -0
  128. data/test_rails_app/config/initializers/mime_types.rb +5 -0
  129. data/test_rails_app/config/initializers/new_rails_defaults.rb +17 -0
  130. data/test_rails_app/config/locales/en.yml +5 -0
  131. data/test_rails_app/config/routes.rb +43 -0
  132. data/test_rails_app/db/migrate/20090213215514_create_blog_posts.rb +12 -0
  133. data/test_rails_app/db/migrate/20090217225542_add_body_to_blog_posts.rb +9 -0
  134. data/test_rails_app/db/migrate/20090221220917_create_tags.rb +13 -0
  135. data/test_rails_app/db/migrate/20090221220947_create_blog_post_tags.rb +14 -0
  136. data/test_rails_app/db/migrate/20090222162204_add_textile_to_blog_posts.rb +9 -0
  137. data/test_rails_app/db/migrate/20090222163231_add_published_at_to_blog_posts.rb +9 -0
  138. data/test_rails_app/db/migrate/20090301191722_create_images.rb +16 -0
  139. data/test_rails_app/db/migrate/20090305165345_create_accounts.rb +14 -0
  140. data/test_rails_app/db/migrate/20090307225027_rename_accounts_to_users.rb +9 -0
  141. data/test_rails_app/db/migrate/20090307225750_add_user_id_to_blog_posts.rb +9 -0
  142. data/test_rails_app/db/migrate/20090309185114_change_blog_posts_textile.rb +9 -0
  143. data/test_rails_app/db/migrate/20090309193635_create_products.rb +14 -0
  144. data/test_rails_app/db/migrate/20090309203056_create_comments.rb +15 -0
  145. data/test_rails_app/db/migrate/20090323005947_create_file_column_images.rb +12 -0
  146. data/test_rails_app/db/migrate/20090326160049_add_birthday_to_users.rb +9 -0
  147. data/test_rails_app/db/migrate/20090326223606_add_state_to_users.rb +9 -0
  148. data/test_rails_app/db/migrate/20090503134004_add_file_column_image_to_products.rb +9 -0
  149. data/test_rails_app/db/migrate/20090617173651_create_bookmarks.rb +15 -0
  150. data/test_rails_app/db/migrate/20090624165355_add_tags_string_to_blog_post.rb +9 -0
  151. data/test_rails_app/db/migrate/20090625144313_add_avatar_fields_to_user.rb +11 -0
  152. data/test_rails_app/db/migrate/20090629202956_add_merged_into_to_blog_posts.rb +9 -0
  153. data/test_rails_app/db/migrate/20090701171857_add_force_textile_to_users.rb +9 -0
  154. data/test_rails_app/db/migrate/20090704163647_add_deleted_at_to_products.rb +9 -0
  155. data/test_rails_app/db/migrate/20090704173800_add_sale_fields_to_products.rb +13 -0
  156. data/test_rails_app/db/migrate/20090714024501_create_product_categories.rb +15 -0
  157. data/test_rails_app/db/migrate/20090819162835_add_admin_level_to_users.rb +9 -0
  158. data/test_rails_app/db/migrate/20091115134559_add_first_and_last_names_to_users.rb +11 -0
  159. data/test_rails_app/db/migrate/20091221011256_add_position_to_product_categories.rb +9 -0
  160. data/test_rails_app/db/migrate/20091222160814_create_appointments.rb +14 -0
  161. data/test_rails_app/db/migrate/20091227224547_add_user_id_to_appointments.rb +9 -0
  162. data/test_rails_app/db/migrate/20100214213359_create_television_time_slots.rb +13 -0
  163. data/test_rails_app/db/migrate/20100214213451_create_television_airings.rb +15 -0
  164. data/test_rails_app/doc/README_FOR_APP +5 -0
  165. data/test_rails_app/lib/tasks/rspec.rake +163 -0
  166. data/test_rails_app/public/404.html +30 -0
  167. data/test_rails_app/public/422.html +30 -0
  168. data/test_rails_app/public/500.html +33 -0
  169. data/test_rails_app/public/dispatch.cgi +10 -0
  170. data/test_rails_app/public/dispatch.fcgi +24 -0
  171. data/test_rails_app/public/dispatch.rb +10 -0
  172. data/test_rails_app/public/favicon.ico +0 -0
  173. data/test_rails_app/public/images/rails.png +0 -0
  174. data/test_rails_app/public/index.html +274 -0
  175. data/test_rails_app/public/javascripts/application.js +2 -0
  176. data/test_rails_app/public/javascripts/controls.js +963 -0
  177. data/test_rails_app/public/javascripts/dragdrop.js +973 -0
  178. data/test_rails_app/public/javascripts/effects.js +1128 -0
  179. data/test_rails_app/public/javascripts/prototype.js +4320 -0
  180. data/test_rails_app/public/robots.txt +5 -0
  181. data/test_rails_app/public/stylesheets/admin.css +3 -0
  182. data/test_rails_app/public/stylesheets/scaffold.css +54 -0
  183. data/test_rails_app/script/about +4 -0
  184. data/test_rails_app/script/autospec +5 -0
  185. data/test_rails_app/script/console +3 -0
  186. data/test_rails_app/script/dbconsole +3 -0
  187. data/test_rails_app/script/destroy +3 -0
  188. data/test_rails_app/script/generate +3 -0
  189. data/test_rails_app/script/performance/benchmarker +3 -0
  190. data/test_rails_app/script/performance/profiler +3 -0
  191. data/test_rails_app/script/performance/request +3 -0
  192. data/test_rails_app/script/plugin +3 -0
  193. data/test_rails_app/script/populate_tables.rb +49 -0
  194. data/test_rails_app/script/process/inspector +3 -0
  195. data/test_rails_app/script/process/reaper +3 -0
  196. data/test_rails_app/script/process/spawner +3 -0
  197. data/test_rails_app/script/runner +3 -0
  198. data/test_rails_app/script/server +3 -0
  199. data/test_rails_app/script/spec +5 -0
  200. data/test_rails_app/script/spec_server +125 -0
  201. data/test_rails_app/spec/controllers/admin/appointments2_controller_spec.rb +88 -0
  202. data/test_rails_app/spec/controllers/admin/appointments_controller_spec.rb +419 -0
  203. data/test_rails_app/spec/controllers/admin/blog_posts2_controller_spec.rb +1021 -0
  204. data/test_rails_app/spec/controllers/admin/blog_posts3_controller_spec.rb +532 -0
  205. data/test_rails_app/spec/controllers/admin/blog_posts4_controller_spec.rb +231 -0
  206. data/test_rails_app/spec/controllers/admin/blog_posts5_controller_spec.rb +77 -0
  207. data/test_rails_app/spec/controllers/admin/blog_posts6_controller_spec.rb +49 -0
  208. data/test_rails_app/spec/controllers/admin/blog_posts_controller_spec.rb +987 -0
  209. data/test_rails_app/spec/controllers/admin/blog_posts_custom_new_and_edit_controller_spec.rb +99 -0
  210. data/test_rails_app/spec/controllers/admin/blog_posts_read_only_controller_spec.rb +94 -0
  211. data/test_rails_app/spec/controllers/admin/bookmarks_controller_spec.rb +505 -0
  212. data/test_rails_app/spec/controllers/admin/comments2_controller_spec.rb +70 -0
  213. data/test_rails_app/spec/controllers/admin/comments_controller_spec.rb +82 -0
  214. data/test_rails_app/spec/controllers/admin/file_column_images2_controller_spec.rb +25 -0
  215. data/test_rails_app/spec/controllers/admin/file_column_images_controller_spec.rb +82 -0
  216. data/test_rails_app/spec/controllers/admin/images2_controller_spec.rb +44 -0
  217. data/test_rails_app/spec/controllers/admin/images_controller_spec.rb +97 -0
  218. data/test_rails_app/spec/controllers/admin/misconfigured1_controller_spec.rb +21 -0
  219. data/test_rails_app/spec/controllers/admin/not_migrated_yets_controller_spec.rb +10 -0
  220. data/test_rails_app/spec/controllers/admin/product_categories2_controller_spec.rb +215 -0
  221. data/test_rails_app/spec/controllers/admin/product_categories_controller_spec.rb +19 -0
  222. data/test_rails_app/spec/controllers/admin/products2_controller_spec.rb +203 -0
  223. data/test_rails_app/spec/controllers/admin/products_controller_spec.rb +255 -0
  224. data/test_rails_app/spec/controllers/admin/television_airings_controller_spec.rb +32 -0
  225. data/test_rails_app/spec/controllers/admin/television_time_slots_controller_spec.rb +10 -0
  226. data/test_rails_app/spec/controllers/admin/users2_controller_spec.rb +65 -0
  227. data/test_rails_app/spec/controllers/admin/users_controller_spec.rb +344 -0
  228. data/test_rails_app/spec/controllers/blog_posts_controller_spec.rb +13 -0
  229. data/test_rails_app/spec/data/ruby_throated.jpg +0 -0
  230. data/test_rails_app/spec/data/tweenbot.jpg +0 -0
  231. data/test_rails_app/spec/fixtures/appointments.yml +9 -0
  232. data/test_rails_app/spec/fixtures/blog_post_tags.yml +9 -0
  233. data/test_rails_app/spec/fixtures/blog_posts.yml +7 -0
  234. data/test_rails_app/spec/fixtures/bookmarks.yml +11 -0
  235. data/test_rails_app/spec/fixtures/comments.yml +11 -0
  236. data/test_rails_app/spec/fixtures/file_column_images.yml +7 -0
  237. data/test_rails_app/spec/fixtures/images.yml +7 -0
  238. data/test_rails_app/spec/fixtures/not_migrated_yets.yml +7 -0
  239. data/test_rails_app/spec/fixtures/product_categories.yml +7 -0
  240. data/test_rails_app/spec/fixtures/products.yml +9 -0
  241. data/test_rails_app/spec/fixtures/tags.yml +7 -0
  242. data/test_rails_app/spec/fixtures/television_airings.yml +11 -0
  243. data/test_rails_app/spec/fixtures/television_time_slots.yml +7 -0
  244. data/test_rails_app/spec/fixtures/users.yml +9 -0
  245. data/test_rails_app/spec/helpers/admin/appointments2_helper_spec.rb +11 -0
  246. data/test_rails_app/spec/helpers/admin/appointments_helper_spec.rb +11 -0
  247. data/test_rails_app/spec/helpers/admin/blog_posts2_helper_spec.rb +11 -0
  248. data/test_rails_app/spec/helpers/admin/blog_posts3_helper_spec.rb +11 -0
  249. data/test_rails_app/spec/helpers/admin/blog_posts4_helper_spec.rb +11 -0
  250. data/test_rails_app/spec/helpers/admin/blog_posts_custom_new_and_edit_helper_spec.rb +11 -0
  251. data/test_rails_app/spec/helpers/admin/blog_posts_helper_spec.rb +11 -0
  252. data/test_rails_app/spec/helpers/admin/blog_posts_read_only_helper_spec.rb +11 -0
  253. data/test_rails_app/spec/helpers/admin/bookmarks_helper_spec.rb +11 -0
  254. data/test_rails_app/spec/helpers/admin/comments2_helper_spec.rb +11 -0
  255. data/test_rails_app/spec/helpers/admin/comments_helper_spec.rb +11 -0
  256. data/test_rails_app/spec/helpers/admin/file_column_images2_helper_spec.rb +11 -0
  257. data/test_rails_app/spec/helpers/admin/file_column_images_helper_spec.rb +11 -0
  258. data/test_rails_app/spec/helpers/admin/images2_helper_spec.rb +11 -0
  259. data/test_rails_app/spec/helpers/admin/images_helper_spec.rb +11 -0
  260. data/test_rails_app/spec/helpers/admin/misconfigured1_helper_spec.rb +11 -0
  261. data/test_rails_app/spec/helpers/admin/not_migrated_yets_helper_spec.rb +11 -0
  262. data/test_rails_app/spec/helpers/admin/product_categories2_helper_spec.rb +11 -0
  263. data/test_rails_app/spec/helpers/admin/product_categories_helper_spec.rb +11 -0
  264. data/test_rails_app/spec/helpers/admin/products2_helper_spec.rb +11 -0
  265. data/test_rails_app/spec/helpers/admin/products_helper_spec.rb +11 -0
  266. data/test_rails_app/spec/helpers/admin/television_airings_helper_spec.rb +11 -0
  267. data/test_rails_app/spec/helpers/admin/television_time_slots_helper_spec.rb +11 -0
  268. data/test_rails_app/spec/helpers/admin/users2_helper_spec.rb +11 -0
  269. data/test_rails_app/spec/helpers/admin/users_helper_spec.rb +11 -0
  270. data/test_rails_app/spec/helpers/blog_posts_helper_spec.rb +11 -0
  271. data/test_rails_app/spec/models/appointment_spec.rb +16 -0
  272. data/test_rails_app/spec/models/blog_post_spec.rb +13 -0
  273. data/test_rails_app/spec/models/blog_post_tag_spec.rb +14 -0
  274. data/test_rails_app/spec/models/bookmark_spec.rb +15 -0
  275. data/test_rails_app/spec/models/comment_spec.rb +15 -0
  276. data/test_rails_app/spec/models/file_column_image_spec.rb +12 -0
  277. data/test_rails_app/spec/models/image_spec.rb +12 -0
  278. data/test_rails_app/spec/models/not_migrated_yet_spec.rb +15 -0
  279. data/test_rails_app/spec/models/product_category_spec.rb +15 -0
  280. data/test_rails_app/spec/models/product_spec.rb +14 -0
  281. data/test_rails_app/spec/models/tag_spec.rb +13 -0
  282. data/test_rails_app/spec/models/television_airing_spec.rb +15 -0
  283. data/test_rails_app/spec/models/television_time_slot_spec.rb +13 -0
  284. data/test_rails_app/spec/models/user_spec.rb +14 -0
  285. data/test_rails_app/spec/rcov.opts +2 -0
  286. data/test_rails_app/spec/spec.opts +4 -0
  287. data/test_rails_app/spec/spec_helper.rb +88 -0
  288. data/test_rails_app/spec/spec_or_test_helper.rb +49 -0
  289. data/test_rails_app/test/fixtures/file_column_images.yml +7 -0
  290. data/test_rails_app/test/integration/admin_blog_posts2_integration_test.rb +16 -0
  291. data/test_rails_app/test/integration/admin_blog_posts5_integration_test.rb +19 -0
  292. data/test_rails_app/test/integration/admin_blog_posts_integration_test.rb +25 -0
  293. data/test_rails_app/test/test_helper.rb +28 -0
  294. data/test_rails_app/vendor/plugins/file_column/CHANGELOG +69 -0
  295. data/test_rails_app/vendor/plugins/file_column/README +54 -0
  296. data/test_rails_app/vendor/plugins/file_column/Rakefile +36 -0
  297. data/test_rails_app/vendor/plugins/file_column/TODO +6 -0
  298. data/test_rails_app/vendor/plugins/file_column/init.rb +13 -0
  299. data/test_rails_app/vendor/plugins/file_column/lib/file_column.rb +723 -0
  300. data/test_rails_app/vendor/plugins/file_column/lib/file_column_helper.rb +150 -0
  301. data/test_rails_app/vendor/plugins/file_column/lib/file_compat.rb +28 -0
  302. data/test_rails_app/vendor/plugins/file_column/lib/magick_file_column.rb +260 -0
  303. data/test_rails_app/vendor/plugins/file_column/lib/rails_file_column.rb +19 -0
  304. data/test_rails_app/vendor/plugins/file_column/lib/test_case.rb +124 -0
  305. data/test_rails_app/vendor/plugins/file_column/lib/validations.rb +112 -0
  306. data/test_rails_app/vendor/plugins/file_column/test/abstract_unit.rb +63 -0
  307. data/test_rails_app/vendor/plugins/file_column/test/connection.rb +17 -0
  308. data/test_rails_app/vendor/plugins/file_column/test/file_column_helper_test.rb +97 -0
  309. data/test_rails_app/vendor/plugins/file_column/test/file_column_test.rb +650 -0
  310. data/test_rails_app/vendor/plugins/file_column/test/fixtures/entry.rb +32 -0
  311. data/test_rails_app/vendor/plugins/file_column/test/fixtures/invalid-image.jpg +1 -0
  312. data/test_rails_app/vendor/plugins/file_column/test/fixtures/kerb.jpg +0 -0
  313. data/test_rails_app/vendor/plugins/file_column/test/fixtures/mysql.sql +25 -0
  314. data/test_rails_app/vendor/plugins/file_column/test/fixtures/schema.rb +10 -0
  315. data/test_rails_app/vendor/plugins/file_column/test/fixtures/skanthak.png +0 -0
  316. data/test_rails_app/vendor/plugins/file_column/test/magick_test.rb +380 -0
  317. data/test_rails_app/vendor/plugins/file_column/test/magick_view_only_test.rb +21 -0
  318. data/vendor/ar_query/ar_query.gemspec +16 -0
  319. data/website/_layouts/api.html +39 -0
  320. data/website/_layouts/default.html +34 -0
  321. data/website/api/core.markdown +106 -0
  322. data/website/api/destroy.markdown +25 -0
  323. data/website/api/form.markdown +291 -0
  324. data/website/api/idx.markdown +286 -0
  325. data/website/api/index.markdown +147 -0
  326. data/website/api/search.markdown +108 -0
  327. data/website/api/show.markdown +22 -0
  328. data/website/community.markdown +27 -0
  329. data/website/css/lightbox.css +29 -0
  330. data/website/css/main.css +70 -0
  331. data/website/design_principles.markdown +50 -0
  332. data/website/getting_started.markdown +10 -0
  333. data/website/img/blog_posts-index.png +0 -0
  334. data/website/img/blog_posts-search.png +0 -0
  335. data/website/img/lightbox/bullet.gif +0 -0
  336. data/website/img/lightbox/close.gif +0 -0
  337. data/website/img/lightbox/closelabel.gif +0 -0
  338. data/website/img/lightbox/donate-button.gif +0 -0
  339. data/website/img/lightbox/download-icon.gif +0 -0
  340. data/website/img/lightbox/image-1.jpg +0 -0
  341. data/website/img/lightbox/loading.gif +0 -0
  342. data/website/img/lightbox/nextlabel.gif +0 -0
  343. data/website/img/lightbox/prevlabel.gif +0 -0
  344. data/website/img/lightbox/thumb-1.jpg +0 -0
  345. data/website/img/screen1-thumb.png +0 -0
  346. data/website/img/screen1.png +0 -0
  347. data/website/img/screen10-thumb.png +0 -0
  348. data/website/img/screen10.png +0 -0
  349. data/website/img/screen11-thumb.png +0 -0
  350. data/website/img/screen11.png +0 -0
  351. data/website/img/screen2-thumb.png +0 -0
  352. data/website/img/screen2.png +0 -0
  353. data/website/img/screen3-thumb.png +0 -0
  354. data/website/img/screen3.png +0 -0
  355. data/website/img/screen4-thumb.png +0 -0
  356. data/website/img/screen4.png +0 -0
  357. data/website/img/screen5-thumb.png +0 -0
  358. data/website/img/screen5.png +0 -0
  359. data/website/img/screen6-thumb.png +0 -0
  360. data/website/img/screen6.png +0 -0
  361. data/website/img/screen7-thumb.png +0 -0
  362. data/website/img/screen7.png +0 -0
  363. data/website/img/screen8-thumb.png +0 -0
  364. data/website/img/screen8.png +0 -0
  365. data/website/img/screen9-thumb.png +0 -0
  366. data/website/img/screen9.png +0 -0
  367. data/website/img/user-form.png +0 -0
  368. data/website/index.markdown +35 -0
  369. data/website/js/builder.js +136 -0
  370. data/website/js/effects.js +1122 -0
  371. data/website/js/lightbox.js +497 -0
  372. data/website/js/prototype.js +4221 -0
  373. data/website/js/scriptaculous.js +58 -0
  374. data/website/quick_start.markdown +44 -0
  375. data/website/screenshots.markdown +27 -0
  376. data/website/tutorial.markdown +56 -0
  377. metadata +391 -23
@@ -0,0 +1,987 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Admin::BlogPostsController do
4
+ integrate_views
5
+
6
+ before :all do
7
+ User.destroy_all
8
+ @user = User.create! :username => 'soren'
9
+ end
10
+
11
+ describe '#autocomplete_user' do
12
+ before :all do
13
+ @bill1 = User.create! :username => 'Bill 1'
14
+ @bill2 = User.create! :username => 'Bill 2'
15
+ 1.upto(11) do |i|
16
+ User.create! :username => "Bob #{i}"
17
+ end
18
+ User.create! :username => 'Bob'
19
+ end
20
+
21
+ describe 'with no matches' do
22
+ before :each do
23
+ get :autocomplete_user, :user_autocomplete_input => 'Jane'
24
+ end
25
+
26
+ it 'should return empty results' do
27
+ response.should have_tag('ul')
28
+ response.should_not have_tag('ul > li')
29
+ end
30
+
31
+ it 'should not render the admin layout' do
32
+ response.should_not have_tag('head > title')
33
+ end
34
+ end
35
+
36
+ describe 'with two matches' do
37
+ before :each do
38
+ get :autocomplete_user, :user_autocomplete_input => 'Bill'
39
+ end
40
+
41
+ it 'should return those two matches' do
42
+ response.should have_tag('ul') do
43
+ with_tag "li[id=user#{@bill1.id}]", :text => 'Bill 1'
44
+ with_tag "li[id=user#{@bill2.id}]", :text => 'Bill 2'
45
+ end
46
+ end
47
+ end
48
+
49
+ describe 'with 12 matches' do
50
+ before :each do
51
+ get :autocomplete_user, :user_autocomplete_input => 'Bob'
52
+ end
53
+
54
+ it 'should return a max of ten users' do
55
+ response.should have_tag('ul > li', :count => 10)
56
+ end
57
+
58
+ it 'should make sure the shortest matches are included in the results' do
59
+ response.should have_tag('ul > li', :text => 'Bob')
60
+ end
61
+ end
62
+ end
63
+
64
+ describe '#create' do
65
+ describe 'when there are no validation errors' do
66
+ before :each do
67
+ title = random_word
68
+ post(
69
+ :create,
70
+ :blog_post => {
71
+ :title => title, :textile => '1', :user_id => @user.id,
72
+ 'published_at(1i)' => '', 'published_at(2i)' => '',
73
+ 'published_at(3i)' => '', 'published_at(4i)' => '',
74
+ 'published_at(5i)' => ''
75
+ }
76
+ )
77
+ @blog_post = BlogPost.find_by_title(title)
78
+ end
79
+
80
+ it 'should create a new BlogPost' do
81
+ @blog_post.should_not be_nil
82
+ @blog_post.textile?.should be_true
83
+ end
84
+
85
+ it 'should not set published_at' do
86
+ @blog_post.published_at.should be_nil
87
+ end
88
+ end
89
+
90
+ describe 'when there are validation errors' do
91
+ before :each do
92
+ post(
93
+ :create, :blog_post => {:title => ''}, :origin => '/admin/blog_posts'
94
+ )
95
+ end
96
+
97
+ it 'should not create a new BlogPost' do
98
+ BlogPost.find_by_title('').should be_nil
99
+ end
100
+
101
+ it 'should print all the errors' do
102
+ response.should be_success
103
+ response.body.should match(/Title can't be blank/)
104
+ end
105
+
106
+ it 'should show a link back to the index page' do
107
+ response.should have_tag("a[href=/admin/blog_posts]", 'Back to index')
108
+ end
109
+ end
110
+
111
+ describe 'when somebody GETs for some reason' do
112
+ before :each do
113
+ get :create
114
+ end
115
+
116
+ it 'should just redirect to #new' do
117
+ response.should redirect_to(:action => 'new')
118
+ end
119
+ end
120
+ end
121
+
122
+ describe '#destroy' do
123
+ it 'should be an unknown action' do
124
+ lambda { post :destroy, :id => 123 }.should raise_error(
125
+ ActionController::UnknownAction
126
+ )
127
+ end
128
+ end
129
+
130
+ describe '#edit' do
131
+ before :all do
132
+ @blog_post = BlogPost.create! :title => random_word, :user => @user
133
+ end
134
+
135
+ before :each do
136
+ @request.env["HTTP_REFERER"] = '/admin/blog_posts'
137
+ get :edit, :id => @blog_post.id
138
+ end
139
+
140
+ it 'should show a form' do
141
+ response.body.should match(
142
+ %r|<form action="/admin/blog_posts/update/#{@blog_post.id}".*input.*name="blog_post\[title\]"|m
143
+ )
144
+ end
145
+
146
+ it 'should prefill the values' do
147
+ response.body.should match(%r|input.*value="#{@blog_post.title}"|)
148
+ end
149
+
150
+ it 'should show a link back to the index page' do
151
+ response.should have_tag("a[href=/admin/blog_posts]", 'Back to index')
152
+ end
153
+ end
154
+
155
+ describe '#edit when there is a referer value on the request' do
156
+ it 'should have the origin hidden input value' do
157
+ blog_post = BlogPost.create! :title => random_word, :user => @user
158
+ referer_page = 'referer_page'
159
+ @request.env['HTTP_REFERER'] = referer_page
160
+ get :edit, :id => blog_post.id
161
+ response.should have_tag("input#origin[value=#{referer_page}]")
162
+ end
163
+ end
164
+
165
+ describe '#edit when there are more than 15 users' do
166
+ before :all do
167
+ @blog_post = BlogPost.create! :title => random_word, :user => @user
168
+ 1.upto(16) do |i|
169
+ User.create! :username => "--user #{i}--"
170
+ end
171
+ end
172
+
173
+ before :each do
174
+ get :edit, :id => @blog_post.id
175
+ end
176
+
177
+ it 'should use the restricted autocompleter instead of a drop-down' do
178
+ response.should_not have_tag("select[name=?]", "blog_post[user_id]")
179
+ response.should have_tag(
180
+ "input[id=user_autocomplete_input][value=soren]"
181
+ )
182
+ response.should have_tag(
183
+ "input[type=hidden][name=?][id=blog_post_user_id][value=?]",
184
+ "blog_post[user_id]", @user.id.to_s
185
+ )
186
+ response.should have_tag("div[id=user_autocomplete_palette]")
187
+ response.should have_tag('div[id=clear_user_link]')
188
+ response.body.should match(
189
+ %r|
190
+ new\s*AdminAssistant.RestrictedAutocompleter\(
191
+ \s*"user",
192
+ \s*"blog_post_user_id",
193
+ \s*"/admin/blog_posts/autocomplete_user",
194
+ [^)]*"includeBlank":\s*true
195
+ |mx
196
+ )
197
+ end
198
+ end
199
+
200
+ describe '#edit when there are less than 15 users' do
201
+ before :all do
202
+ @blog_post = BlogPost.create! :title => random_word, :user => @user
203
+ User.count.downto(14) do
204
+ user = User.find(
205
+ :first, :conditions => ['username != ?', @user.username]
206
+ )
207
+ user.destroy
208
+ end
209
+ end
210
+
211
+ before :each do
212
+ get :edit, :id => @blog_post.id
213
+ end
214
+
215
+ it 'should use a drop-down with a blank option' do
216
+ response.should have_tag('select[name=?]', 'blog_post[user_id]') do
217
+ with_tag "option[value='']"
218
+ end
219
+ end
220
+ end
221
+
222
+ describe '#index' do
223
+ describe 'when there are no records' do
224
+ before :all do
225
+ BlogPost.destroy_all
226
+ end
227
+
228
+ before :each do
229
+ get :index
230
+ response.should be_success
231
+ end
232
+
233
+ it 'should say "No blog posts found"' do
234
+ response.body.should match(/No blog posts found/)
235
+ end
236
+
237
+ it "should say the name of the model you're editing" do
238
+ response.body.should match(/Blog posts/)
239
+ end
240
+
241
+ it 'should have a new link' do
242
+ response.should have_tag(
243
+ "a[href=/admin/blog_posts/new]", 'New blog post'
244
+ )
245
+ end
246
+
247
+ it 'should have a search form' do
248
+ response.body.should match(
249
+ %r|<a.*onclick="AdminAssistant.show_search_form\(\);.*>Search</a>|
250
+ )
251
+ end
252
+
253
+ it 'should use the admin layout' do
254
+ response.body.should match(/admin_assistant sample Rails app/)
255
+ end
256
+
257
+ it 'should use the default admin_assistant CSS' do
258
+ response.should have_tag(
259
+ 'link[href^=/stylesheets/admin_assistant/default.css]'
260
+ )
261
+ end
262
+ end
263
+
264
+ describe 'when there is one record' do
265
+ before :all do
266
+ BlogPost.destroy_all
267
+ @blog_post = BlogPost.create!(
268
+ :title => "hi there", :user => @user, :textile => false
269
+ )
270
+ end
271
+
272
+ before :each do
273
+ get :index
274
+ response.should be_success
275
+ end
276
+
277
+ it 'should show title by default' do
278
+ response.body.should match(/hi there/)
279
+ end
280
+
281
+ it "should say the name of the model you're editing" do
282
+ response.body.should match(/Blog posts/)
283
+ end
284
+
285
+ it 'should have a new link' do
286
+ response.should have_tag(
287
+ "a[href=/admin/blog_posts/new]", 'New blog post'
288
+ )
289
+ end
290
+
291
+ it 'should have an edit link' do
292
+ response.should have_tag('td.actions') do
293
+ with_tag "a[href=/admin/blog_posts/edit/#{@blog_post.id}]", 'Edit'
294
+ end
295
+ end
296
+
297
+ it 'should have a show link' do
298
+ response.should have_tag(
299
+ "a[href=/admin/blog_posts/show/#{@blog_post.id}]", 'Show'
300
+ )
301
+ end
302
+
303
+ it 'should show sort links' do
304
+ pretty_column_names = {
305
+ 'id' => 'ID', 'title' => 'Title', 'body' => 'Body', 'user' => 'User'
306
+ }
307
+ pretty_column_names.each do |field, pretty_column_name|
308
+ assert_a_tag_with_get_args(
309
+ pretty_column_name, '/admin/blog_posts',
310
+ {:sort => field, :sort_order => 'asc'}, response.body
311
+ )
312
+ end
313
+ end
314
+
315
+ it 'should show pretty column headers' do
316
+ column_headers = ['ID', 'Title', 'Body', 'User']
317
+ column_headers.each do |column_header|
318
+ response.should have_tag('th') do
319
+ with_tag 'a', column_header
320
+ end
321
+ end
322
+ end
323
+
324
+ it 'should say how many records are found' do
325
+ response.should have_tag(
326
+ 'div.aa_footer', :text => '1 blog post found'
327
+ )
328
+ end
329
+
330
+ it "should say username because that's one of our default name fields" do
331
+ response.should have_tag('td', :text => 'soren')
332
+ end
333
+
334
+ it 'should make the textile field an Ajax toggle' do
335
+ toggle_div_id = "blog_post_#{@blog_post.id}_textile"
336
+ post_url =
337
+ "/admin/blog_posts/update/#{@blog_post.id}?" +
338
+ CGI.escape('blog_post[textile]') + "=1&amp;from=#{toggle_div_id}"
339
+ response.should have_tag("div[id=?]", toggle_div_id) do
340
+ ajax_substr = "new Ajax.Updater('#{toggle_div_id}', '#{post_url}'"
341
+ with_tag("a[href=#][onclick*=?]", ajax_substr, :text => 'false')
342
+ end
343
+ end
344
+
345
+ it 'should not show the page selector form' do
346
+ response.should have_tag('.pagination') do
347
+ without_tag('form[method=get][action=/admin/blog_posts]')
348
+ end
349
+ end
350
+
351
+ it 'should have a tbody with the ID blog_posts_index_tbody' do
352
+ response.should have_tag('tbody#blog_posts_index_tbody')
353
+ end
354
+
355
+ it 'should have a tr with the ID based on @blog_post.id' do
356
+ response.should have_tag("tr[id=blog_post_#{@blog_post.id}]")
357
+ end
358
+
359
+ it 'should not show created_at or updated_at by default' do
360
+ response.body.should_not match(/Created at/)
361
+ response.body.should_not match(/Updated at/)
362
+ end
363
+ end
364
+
365
+ describe 'when there is one record that somehow has a nil User' do
366
+ before :all do
367
+ @blog_post = BlogPost.create! :title => "hi there", :user => @user
368
+ BlogPost.update_all "user_id = null"
369
+ end
370
+
371
+ before :each do
372
+ get :index
373
+ end
374
+
375
+ it 'should be fine with a nil User' do
376
+ response.should be_success
377
+ end
378
+ end
379
+
380
+ describe 'when there are more than 10 pages of results' do
381
+ before :all do
382
+ BlogPost.count.upto(251) do
383
+ @blog_post = BlogPost.create!(
384
+ :title => "hi there", :user => @user, :textile => false
385
+ )
386
+ end
387
+ end
388
+
389
+ before :each do
390
+ get :index
391
+ end
392
+
393
+ it 'should show the page selector form at the bottom' do
394
+ response.should have_tag('.pagination') do
395
+ with_tag('form[method=get][action=/admin/blog_posts]') do
396
+ with_tag 'input[name=page]'
397
+ end
398
+ end
399
+ end
400
+ end
401
+ end
402
+
403
+ describe '#index sorting' do
404
+ describe 'when there are two records' do
405
+ before :all do
406
+ BlogPost.destroy_all
407
+ @blog_post1 = BlogPost.create!(
408
+ :title => "title 1", :body => "body 2", :user => @user
409
+ )
410
+ @blog_post2 = BlogPost.create!(
411
+ :title => "title 2", :body => "body 1", :user => @user
412
+ )
413
+ end
414
+
415
+ describe 'sorted by title asc' do
416
+ before :each do
417
+ get :index, :sort => 'title', :sort_order => 'asc'
418
+ response.should be_success
419
+ end
420
+
421
+ it 'should sort by title asc' do
422
+ response.body.should match(%r|title 1.*title 2|m)
423
+ end
424
+
425
+ it 'should show a desc sort link for title' do
426
+ assert_a_tag_with_get_args(
427
+ 'Title', '/admin/blog_posts',
428
+ {:sort => 'title', :sort_order => 'desc'}, response.body
429
+ )
430
+ end
431
+
432
+ it 'should show asc sort links for other fields' do
433
+ pretty_column_names = {'id' => 'ID', 'body' => 'Body'}
434
+ pretty_column_names.each do |field, pretty_column_name|
435
+ assert_a_tag_with_get_args(
436
+ pretty_column_name, '/admin/blog_posts',
437
+ {:sort => field, :sort_order => 'asc'}, response.body
438
+ )
439
+ end
440
+ end
441
+
442
+ it 'should use the right CSS classes in the title header' do
443
+ response.should have_tag('th[class="sort asc"]') do
444
+ with_tag 'a', :text => 'Title'
445
+ end
446
+ end
447
+
448
+ it 'should have no CSS sorting classes in the header for ID' do
449
+ response.should have_tag('th:not([class])') do
450
+ with_tag 'a', :text => 'ID'
451
+ end
452
+ end
453
+
454
+ it 'should mark the title cells with CSS sorting classes' do
455
+ response.should have_tag('td[class="sort"]', :text => 'title 1')
456
+ end
457
+ end
458
+
459
+ describe 'sorted by title desc' do
460
+ before :each do
461
+ get :index, :sort => 'title', :sort_order => 'desc'
462
+ response.should be_success
463
+ end
464
+
465
+ it 'should sort by title desc' do
466
+ response.body.should match(%r|title 2.*title 1|m)
467
+ end
468
+
469
+ it 'should show a no-sort link for title' do
470
+ response.should have_tag("a[href=/admin/blog_posts]", 'Title')
471
+ end
472
+
473
+ it 'should show asc sort links for other fields' do
474
+ pretty_column_names = {'id' => 'ID', 'body' => 'Body'}
475
+ pretty_column_names.each do |field, pretty_column_name|
476
+ assert_a_tag_with_get_args(
477
+ pretty_column_name, '/admin/blog_posts',
478
+ {:sort => field, :sort_order => 'asc'}, response.body
479
+ )
480
+ end
481
+ end
482
+
483
+ it 'should use the right CSS classes in the title header' do
484
+ response.should have_tag('th[class="sort desc"]') do
485
+ with_tag 'a', :text => 'Title'
486
+ end
487
+ end
488
+
489
+ it 'should have no CSS sorting classes in the header for ID' do
490
+ response.should have_tag('th:not([class])') do
491
+ with_tag 'a', :text => 'ID'
492
+ end
493
+ end
494
+
495
+ it 'should mark the title cells with CSS sorting classes' do
496
+ response.should have_tag('td[class="sort"]', :text => 'title 1')
497
+ end
498
+ end
499
+ end
500
+
501
+ describe 'by #user, a belongs_to association' do
502
+ before :all do
503
+ BlogPost.destroy_all
504
+ jean_paul = User.create! :username => 'jean-paul'
505
+ BlogPost.create!(
506
+ :title => 'title 1', :body => 'body 1', :user => @user
507
+ )
508
+ BlogPost.create!(
509
+ :title => 'title 2', :body => 'body 2', :user => jean_paul
510
+ )
511
+ end
512
+
513
+ describe 'asc' do
514
+ before :each do
515
+ get :index, :sort => 'user', :sort_order => 'asc'
516
+ response.should be_success
517
+ end
518
+
519
+ it "should show jean-paul's blog post before soren's" do
520
+ response.body.should match(%r|jean-paul.*soren|m)
521
+ end
522
+
523
+ it 'should use the right CSS classes in the user header' do
524
+ response.should have_tag('th[class="sort asc"]') do
525
+ with_tag 'a', :text => 'User'
526
+ end
527
+ end
528
+
529
+ it 'should mark the title cells with CSS sorting classes' do
530
+ response.should have_tag('td[class="sort"]', :text => 'jean-paul')
531
+ end
532
+
533
+ it 'should show a desc sort link for user' do
534
+ assert_a_tag_with_get_args(
535
+ 'User', '/admin/blog_posts',
536
+ {:sort => 'user', :sort_order => 'desc'}, response.body
537
+ )
538
+ end
539
+ end
540
+
541
+ describe 'desc' do
542
+ before :each do
543
+ get :index, :sort => 'user', :sort_order => 'desc'
544
+ response.should be_success
545
+ end
546
+
547
+ it "should show soren's blog post before jean-paul's" do
548
+ response.body.should match(%r|soren.*jean-paul|m)
549
+ end
550
+ end
551
+ end
552
+ end
553
+
554
+ describe '#index search' do
555
+ before :all do
556
+ BlogPost.destroy_all
557
+ end
558
+
559
+ before :each do
560
+ get :index, :search => 'foo'
561
+ response.should be_success
562
+ end
563
+
564
+ describe 'when there are no records' do
565
+ it "should say 'No blog posts found'" do
566
+ response.body.should match(/No blog posts found/)
567
+ end
568
+
569
+ it "should display the search with the terms" do
570
+ response.body.should match(
571
+ %r|<form[^>]*id="search_form".*show_search_form\(\)|m
572
+ )
573
+ response.body.should match(%r|input.*value="foo"|)
574
+ end
575
+
576
+ it 'should show a link back to the index page' do
577
+ response.should have_tag("a[href=/admin/blog_posts]", 'Back to index')
578
+ end
579
+ end
580
+
581
+ describe 'when there are no records that match' do
582
+ before :all do
583
+ BlogPost.create!(
584
+ :title => 'no match', :body => 'no match', :user => @user
585
+ )
586
+ end
587
+
588
+ it "should say 'No blog posts found'" do
589
+ response.body.should match(/No blog posts found/)
590
+ end
591
+ end
592
+
593
+ describe 'when there is a blog post with a matching title' do
594
+ before :all do
595
+ BlogPost.create!(
596
+ :title => 'foozy', :body => 'blog post body', :user => @user
597
+ )
598
+ end
599
+
600
+ it "should show that blog post" do
601
+ response.body.should match(/blog post body/)
602
+ end
603
+ end
604
+
605
+ describe 'when there is a blog post with a matching body' do
606
+ before :all do
607
+ BlogPost.create!(
608
+ :title => 'blog post title', :body => 'barfoo', :user => @user
609
+ )
610
+ end
611
+
612
+ it "should show that blog post" do
613
+ response.body.should match(/blog post title/)
614
+ end
615
+
616
+ it 'should say how many records are found' do
617
+ response.body.should match(/1 blog post found/)
618
+ end
619
+ end
620
+ end
621
+
622
+ describe '#index pagination with 51 records' do
623
+ before :all do
624
+ BlogPost.destroy_all
625
+ 1.upto(51) do |i|
626
+ BlogPost.create!(
627
+ :title => "title -#{i}-", :body => "body -#{i}-", :user => @user
628
+ )
629
+ end
630
+ end
631
+
632
+ describe 'when looking at the first page' do
633
+ before :each do
634
+ get :index
635
+ response.should be_success
636
+ end
637
+
638
+ it 'should have a link to the next page' do
639
+ response.should have_tag(
640
+ "a[href=/admin/blog_posts?page=2]", 'Next &raquo;'
641
+ )
642
+ response.should have_tag("a[href=/admin/blog_posts?page=2]", '2')
643
+ end
644
+
645
+ it 'should not have a link to the previous page' do
646
+ response.should_not have_tag(
647
+ "a[href=/admin/blog_posts?page=0]", '&laquo; Previous'
648
+ )
649
+ response.should_not have_tag("a[href=/admin/blog_posts?page=0]", '0')
650
+ end
651
+
652
+ it 'should the full number of posts found' do
653
+ response.body.should match(/51 blog posts found/)
654
+ end
655
+ end
656
+
657
+ describe 'when looking at the second page' do
658
+ before :each do
659
+ get :index, :page => '2'
660
+ response.should be_success
661
+ end
662
+
663
+ it 'should have a link to the next page' do
664
+ response.should have_tag(
665
+ "a[href=/admin/blog_posts?page=3]", 'Next &raquo;'
666
+ )
667
+ response.should have_tag("a[href=/admin/blog_posts?page=3]", '3')
668
+ end
669
+
670
+ it 'should have a link to the previous page' do
671
+ response.should have_tag(
672
+ "a[href=/admin/blog_posts?page=1]", '&laquo; Previous'
673
+ )
674
+ response.should have_tag("a[href=/admin/blog_posts?page=1]", '1')
675
+ end
676
+
677
+ it 'should the full number of posts found' do
678
+ response.body.should match(/51 blog posts found/)
679
+ end
680
+ end
681
+
682
+ describe 'when looking at the third page' do
683
+ before :each do
684
+ get :index, :page => '3'
685
+ response.should be_success
686
+ end
687
+
688
+ it 'should not have a link to the next page' do
689
+ response.should_not have_tag(
690
+ "a[href=/admin/blog_posts?page=4]", 'Next &raquo;'
691
+ )
692
+ response.should_not have_tag("a[href=/admin/blog_posts?page=3]", '3')
693
+ end
694
+
695
+ it 'should have a link to the previous page' do
696
+ response.should have_tag(
697
+ "a[href=/admin/blog_posts?page=2]", '&laquo; Previous'
698
+ )
699
+ response.should have_tag("a[href=/admin/blog_posts?page=2]", '2')
700
+ end
701
+
702
+ it 'should the full number of posts found' do
703
+ response.body.should match(/51 blog posts found/)
704
+ end
705
+ end
706
+ end
707
+
708
+ describe '#index with 100_000 records' do
709
+ before :all do
710
+ BlogPost.count.upto(25) do |i|
711
+ BlogPost.create!(
712
+ :title => "title -#{i}-", :body => "body -#{i}-", :user => @user
713
+ )
714
+ end
715
+ records = BlogPost.paginate(:per_page => 25, :page => 1)
716
+ records.total_entries = 100_000
717
+ BlogPost.should_receive(:paginate).and_return(records)
718
+ end
719
+
720
+ before :each do
721
+ get :index
722
+ end
723
+
724
+ it 'should not offer a link to sort by user' do
725
+ assert_no_a_tag_with_get_args(
726
+ 'User', '/admin/blog_posts', {:sort => 'user', :sort_order => 'asc'},
727
+ response.body
728
+ )
729
+ end
730
+ end
731
+
732
+ describe '#new' do
733
+ before :each do
734
+ @alfie = User.find_or_create_by_username 'alfie'
735
+ @request.env["HTTP_REFERER"] = '/admin/blog_posts'
736
+ get :new
737
+ end
738
+
739
+ it 'should show a form' do
740
+ response.body.should match(
741
+ %r|<form action="/admin/blog_posts/create".*input.*name="blog_post\[title\]"|m
742
+ )
743
+ end
744
+
745
+ it 'should use a textarea for the body field' do
746
+ response.body.should match(
747
+ %r|<textarea.*name="blog_post\[body\]".*>.*</textarea>|
748
+ )
749
+ end
750
+
751
+ it 'should show a link back to the index page' do
752
+ response.should have_tag("a[href=/admin/blog_posts]", 'Back to index')
753
+ end
754
+
755
+ it 'should show pretty field names' do
756
+ field_names = ['Title', 'Body']
757
+ field_names.each do |field_name|
758
+ response.should have_tag('label', field_name)
759
+ end
760
+ end
761
+
762
+ it 'should set the for attribute of the labels' do
763
+ field_names = ['Title', 'Body']
764
+ field_names.each do |field_name|
765
+ response.should have_tag("label[for=blog_post_#{field_name.downcase}]")
766
+ end
767
+ end
768
+
769
+ it "should use a checkbox for the boolean field 'textile'" do
770
+ response.body.should match(
771
+ %r!
772
+ <input[^>]*
773
+ (name="blog_post\[textile\][^>]*type="checkbox"|
774
+ type="checkbox"[^>]*name="blog_post\[textile\])
775
+ !x
776
+ )
777
+ end
778
+
779
+ it 'should use a drop-down for the user field' do
780
+ response.should have_tag("select[name=?]", "blog_post[user_id]") do
781
+ with_tag "option:nth-child(1)[value='']"
782
+ with_tag "option:nth-child(2)[value=?]", @alfie.id, :text => 'alfie'
783
+ with_tag "option:nth-child(3)[value=?]", @user.id, :text => 'soren'
784
+ end
785
+ end
786
+
787
+ it 'should set the controller path as a CSS class' do
788
+ response.should have_tag("div[class~=admin_blog_posts]")
789
+ end
790
+
791
+ it 'should use dropdowns with nil defaults for published_at' do
792
+ nums_and_dt_fields = {
793
+ 1 => :year, 2 => :month, 3 => :day, 4 => :hour, 5 => :min
794
+ }
795
+ nums_and_dt_fields.each do |num, dt_field|
796
+ name = "blog_post[published_at(#{num}i)]"
797
+ value_for_now_option = Time.now.send(dt_field).to_s
798
+ if [:hour, :min].include?(dt_field) && value_for_now_option.size == 1
799
+ value_for_now_option = "0#{value_for_now_option}"
800
+ end
801
+ response.should have_tag('select[name=?]', name) do
802
+ with_tag "option[value='']"
803
+ with_tag "option:not([selected])[value=?]", value_for_now_option
804
+ end
805
+ end
806
+ end
807
+
808
+ it 'should show a clear link for published_at' do
809
+ response.body.should have_tag('a', :text => "Clear")
810
+ end
811
+ end
812
+
813
+ describe '#new with a preset value in the GET arguments' do
814
+ before :each do
815
+ get :new, :blog_post => {:user_id => @user.id.to_s}
816
+ end
817
+
818
+ it 'should set that preselected value' do
819
+ response.should have_tag("select[name=?]", "blog_post[user_id]") do
820
+ with_tag "option[value=?][selected=selected]",
821
+ @user.id, :text => 'soren'
822
+ with_tag "option[value='']"
823
+ end
824
+ end
825
+ end
826
+
827
+ describe '#new when there are more than 15 users' do
828
+ before :all do
829
+ User.destroy_all
830
+ 1.upto(16) do |i|
831
+ User.create! :username => "--user #{i}--"
832
+ end
833
+ end
834
+
835
+ before :each do
836
+ get :new
837
+ end
838
+
839
+ it 'should use the restricted autocompleter instead of a drop-down' do
840
+ response.should_not have_tag("select[name=?]", "blog_post[user_id]")
841
+ response.should have_tag("input[id=user_autocomplete_input]")
842
+ response.should have_tag(
843
+ "input[type=hidden][name=?][id=blog_post_user_id]",
844
+ "blog_post[user_id]"
845
+ )
846
+ response.should have_tag("div[id=user_autocomplete_palette]")
847
+ response.should have_tag('div[id=clear_user_link]')
848
+ response.body.should match(
849
+ %r|
850
+ new\s*AdminAssistant.RestrictedAutocompleter\(
851
+ \s*"user",
852
+ \s*"blog_post_user_id",
853
+ \s*"/admin/blog_posts/autocomplete_user",
854
+ [^)]*"includeBlank":\s*true
855
+ |mx
856
+ )
857
+ end
858
+ end
859
+
860
+ describe '#show' do
861
+ before :all do
862
+ BlogPost.destroy_all
863
+ @blog_post = BlogPost.create!(
864
+ :title => "foo > bar & baz", :user => @user, :textile => false
865
+ )
866
+ end
867
+
868
+ before :each do
869
+ get :show, :id => @blog_post.id
870
+ end
871
+
872
+ it 'should show the HTML-escaped title' do
873
+ response.body.should match(/foo &gt; bar &amp; baz/)
874
+ end
875
+
876
+ it 'should have a link to edit' do
877
+ response.should have_tag(
878
+ "a[href=/admin/blog_posts/edit/#{@blog_post.id}]", 'Edit'
879
+ )
880
+ end
881
+
882
+ it 'should show soren' do
883
+ response.body.should match(/soren/)
884
+ end
885
+ end
886
+
887
+ describe '#update' do
888
+ before :all do
889
+ @blog_post = BlogPost.create! :title => random_word, :user => @user
890
+ end
891
+
892
+ describe 'when there are no validation errors' do
893
+ before :each do
894
+ title2 = random_word
895
+ post(
896
+ :update,
897
+ :id => @blog_post.id,
898
+ :blog_post => {
899
+ :title => title2, 'published_at(1i)' => '2009',
900
+ 'published_at(2i)' => '1', 'published_at(3i)' => '2',
901
+ 'published_at(4i)' => '3', 'published_at(5i)' => '4'
902
+ }
903
+ )
904
+ response.should redirect_to(:action => 'index')
905
+ @blog_post_prime = BlogPost.find_by_title(title2)
906
+ end
907
+
908
+ it 'should update a pre-existing BlogPost' do
909
+ @blog_post_prime.should_not be_nil
910
+ end
911
+
912
+ it 'should set published_at' do
913
+ @blog_post_prime.published_at.should == Time.utc(2009, 1, 2, 3, 4)
914
+ end
915
+ end
916
+
917
+ describe 'when there are validation errors' do
918
+ before :each do
919
+ post(
920
+ :update,
921
+ :id => @blog_post.id, :blog_post => {:title => ''},
922
+ :origin => '/admin/blog_posts'
923
+ )
924
+ end
925
+
926
+ it 'should not create a new BlogPost' do
927
+ BlogPost.find_by_title('').should be_nil
928
+ end
929
+
930
+ it 'should print all the errors' do
931
+ response.should be_success
932
+ response.body.should match(/Title can't be blank/)
933
+ end
934
+
935
+ it 'should show a link back to the index page' do
936
+ response.should have_tag("a[href=/admin/blog_posts]", 'Back to index')
937
+ end
938
+ end
939
+
940
+ describe 'on handling the origin param' do
941
+ it 'should redirect to the origin when there is a origin on the form submit' do
942
+ origin = 'http://foo.com'
943
+ post :update, :id => @blog_post.id, :blog_post => {:title => 'foo'}, :origin => origin
944
+ response.should redirect_to(origin)
945
+ end
946
+ end
947
+
948
+ end
949
+
950
+ describe '#update as Ajax toggle' do
951
+ before :all do
952
+ @blog_post = BlogPost.create!(
953
+ :title => random_word, :user => @user, :textile => false
954
+ )
955
+ end
956
+
957
+ before :each do
958
+ post(
959
+ :update,
960
+ :id => @blog_post.id, :from => "blog_post_#{@blog_post.id}_textile",
961
+ :blog_post => {:textile => '1'}
962
+ )
963
+ end
964
+
965
+ it 'should return success' do
966
+ response.should be_success
967
+ end
968
+
969
+ it 'should update the textile field' do
970
+ @blog_post.reload.textile.should be_true
971
+ end
972
+
973
+ it 'should only render a small snippet of HTML with Ajax in it' do
974
+ toggle_div_id = "blog_post_#{@blog_post.id}_textile"
975
+ post_url =
976
+ "/admin/blog_posts/update/#{@blog_post.id}?" +
977
+ CGI.escape('blog_post[textile]') + "=0&amp;from=#{toggle_div_id}"
978
+ response.should_not have_tag('div[id=?]', toggle_div_id)
979
+ ajax_substr = "new Ajax.Updater('#{toggle_div_id}', '#{post_url}'"
980
+ response.should have_tag(
981
+ "a[href=#][onclick*=?]", ajax_substr, :text => 'true'
982
+ )
983
+ response.should_not have_tag('title', :text => 'Admin')
984
+ end
985
+ end
986
+
987
+ end