drewda_rails_admin 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (372) hide show
  1. data/Gemfile +53 -0
  2. data/LICENSE.md +20 -0
  3. data/README.md +160 -0
  4. data/Rakefile +19 -0
  5. data/app/assets/images/rails_admin/aristo/images/bg_fallback.png +0 -0
  6. data/app/assets/images/rails_admin/aristo/images/icon_sprite.png +0 -0
  7. data/app/assets/images/rails_admin/aristo/images/progress_bar.gif +0 -0
  8. data/app/assets/images/rails_admin/aristo/images/slider_handles.png +0 -0
  9. data/app/assets/images/rails_admin/aristo/images/ui-icons_222222_256x240.png +0 -0
  10. data/app/assets/images/rails_admin/aristo/images/ui-icons_454545_256x240.png +0 -0
  11. data/app/assets/images/rails_admin/bullet_black.png +0 -0
  12. data/app/assets/images/rails_admin/bullet_white.png +0 -0
  13. data/app/assets/images/rails_admin/calendar.png +0 -0
  14. data/app/assets/images/rails_admin/clock.png +0 -0
  15. data/app/assets/images/rails_admin/colorpicker/colorpicker_background.png +0 -0
  16. data/app/assets/images/rails_admin/colorpicker/colorpicker_hex.png +0 -0
  17. data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_b.png +0 -0
  18. data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_h.png +0 -0
  19. data/app/assets/images/rails_admin/colorpicker/colorpicker_hsb_s.png +0 -0
  20. data/app/assets/images/rails_admin/colorpicker/colorpicker_indic.gif +0 -0
  21. data/app/assets/images/rails_admin/colorpicker/colorpicker_overlay.png +0 -0
  22. data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_b.png +0 -0
  23. data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_g.png +0 -0
  24. data/app/assets/images/rails_admin/colorpicker/colorpicker_rgb_r.png +0 -0
  25. data/app/assets/images/rails_admin/colorpicker/colorpicker_select.gif +0 -0
  26. data/app/assets/images/rails_admin/colorpicker/colorpicker_submit.png +0 -0
  27. data/app/assets/images/rails_admin/colorpicker/custom_background.png +0 -0
  28. data/app/assets/images/rails_admin/colorpicker/custom_hex.png +0 -0
  29. data/app/assets/images/rails_admin/colorpicker/custom_hsb_b.png +0 -0
  30. data/app/assets/images/rails_admin/colorpicker/custom_hsb_h.png +0 -0
  31. data/app/assets/images/rails_admin/colorpicker/custom_hsb_s.png +0 -0
  32. data/app/assets/images/rails_admin/colorpicker/custom_indic.gif +0 -0
  33. data/app/assets/images/rails_admin/colorpicker/custom_rgb_b.png +0 -0
  34. data/app/assets/images/rails_admin/colorpicker/custom_rgb_g.png +0 -0
  35. data/app/assets/images/rails_admin/colorpicker/custom_rgb_r.png +0 -0
  36. data/app/assets/images/rails_admin/colorpicker/custom_submit.png +0 -0
  37. data/app/assets/images/rails_admin/colorpicker/select.png +0 -0
  38. data/app/assets/images/rails_admin/colorpicker/select2.png +0 -0
  39. data/app/assets/images/rails_admin/colorpicker/slider.png +0 -0
  40. data/app/assets/images/rails_admin/logo.png +0 -0
  41. data/app/assets/images/rails_admin/magnifier.png +0 -0
  42. data/app/assets/images/rails_admin/multiselect/icon_sprite.png +0 -0
  43. data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-n-dark.png +0 -0
  44. data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-n-light.png +0 -0
  45. data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-s-dark.png +0 -0
  46. data/app/assets/images/rails_admin/multiselect/ui-icon-circle-triangle-s-light.png +0 -0
  47. data/app/assets/javascripts/rails_admin/custom/ui.js +12 -0
  48. data/app/assets/javascripts/rails_admin/jquery.colorpicker.js +484 -0
  49. data/app/assets/javascripts/rails_admin/jquery.pjax.js +431 -0
  50. data/app/assets/javascripts/rails_admin/jquery.ui.timepicker.js +1371 -0
  51. data/app/assets/javascripts/rails_admin/ra.datetimepicker.js +67 -0
  52. data/app/assets/javascripts/rails_admin/ra.filter-box.js +129 -0
  53. data/app/assets/javascripts/rails_admin/ra.filtering-multiselect.js +280 -0
  54. data/app/assets/javascripts/rails_admin/ra.filtering-select.js +181 -0
  55. data/app/assets/javascripts/rails_admin/ra.nested-form-hooks.coffee +40 -0
  56. data/app/assets/javascripts/rails_admin/ra.remote-form.js +150 -0
  57. data/app/assets/javascripts/rails_admin/rails_admin.js.erb +25 -0
  58. data/app/assets/javascripts/rails_admin/themes/default/ui.js +12 -0
  59. data/app/assets/javascripts/rails_admin/ui.js.coffee +61 -0
  60. data/app/assets/stylesheets/rails_admin/aristo/images/bg_fallback.png +0 -0
  61. data/app/assets/stylesheets/rails_admin/aristo/images/icon_sprite.png +0 -0
  62. data/app/assets/stylesheets/rails_admin/aristo/images/progress_bar.gif +0 -0
  63. data/app/assets/stylesheets/rails_admin/aristo/images/slider_handles.png +0 -0
  64. data/app/assets/stylesheets/rails_admin/aristo/images/ui-icons_222222_256x240.png +0 -0
  65. data/app/assets/stylesheets/rails_admin/aristo/images/ui-icons_454545_256x240.png +0 -0
  66. data/app/assets/stylesheets/rails_admin/aristo/jquery-ui-1.8.7.custom.css.scss +733 -0
  67. data/app/assets/stylesheets/rails_admin/base/README +2 -0
  68. data/app/assets/stylesheets/rails_admin/base/mixins.css.scss +1 -0
  69. data/app/assets/stylesheets/rails_admin/base/theming.css.scss +263 -0
  70. data/app/assets/stylesheets/rails_admin/base/variables.css.scss +1 -0
  71. data/app/assets/stylesheets/rails_admin/custom/mixins.css.scss +12 -0
  72. data/app/assets/stylesheets/rails_admin/custom/theming.css.scss +13 -0
  73. data/app/assets/stylesheets/rails_admin/custom/variables.css.scss +15 -0
  74. data/app/assets/stylesheets/rails_admin/imports.css.scss.erb +76 -0
  75. data/app/assets/stylesheets/rails_admin/jquery.colorpicker.css.scss +180 -0
  76. data/app/assets/stylesheets/rails_admin/jquery.ui.timepicker.css.scss +69 -0
  77. data/app/assets/stylesheets/rails_admin/ra.calendar-additions.css.scss +25 -0
  78. data/app/assets/stylesheets/rails_admin/ra.filtering-multiselect.css.scss +85 -0
  79. data/app/assets/stylesheets/rails_admin/rails_admin.css +4 -0
  80. data/app/assets/stylesheets/rails_admin/themes/default/mixins.css.scss +8 -0
  81. data/app/assets/stylesheets/rails_admin/themes/default/theming.css.scss +11 -0
  82. data/app/assets/stylesheets/rails_admin/themes/default/variables.css.scss +12 -0
  83. data/app/controllers/rails_admin/application_controller.rb +82 -0
  84. data/app/controllers/rails_admin/main_controller.rb +151 -0
  85. data/app/helpers/rails_admin/application_helper.rb +123 -0
  86. data/app/helpers/rails_admin/form_builder.rb +104 -0
  87. data/app/helpers/rails_admin/main_helper.rb +36 -0
  88. data/app/views/kaminari/twitter-bootstrap/_gap.html.haml +2 -0
  89. data/app/views/kaminari/twitter-bootstrap/_next_page.html.haml +4 -0
  90. data/app/views/kaminari/twitter-bootstrap/_page.html.haml +4 -0
  91. data/app/views/kaminari/twitter-bootstrap/_paginator.html.haml +10 -0
  92. data/app/views/kaminari/twitter-bootstrap/_prev_page.html.haml +4 -0
  93. data/app/views/layouts/rails_admin/_secondary_navigation.html.haml +12 -0
  94. data/app/views/layouts/rails_admin/application.html.haml +39 -0
  95. data/app/views/rails_admin/main/_dashboard_history.html.haml +10 -0
  96. data/app/views/rails_admin/main/_delete_notice.html.haml +18 -0
  97. data/app/views/rails_admin/main/_form_colorpicker.html.haml +24 -0
  98. data/app/views/rails_admin/main/_form_datetime.html.haml +4 -0
  99. data/app/views/rails_admin/main/_form_enumeration.html.haml +4 -0
  100. data/app/views/rails_admin/main/_form_field.html.haml +1 -0
  101. data/app/views/rails_admin/main/_form_file_upload.html.haml +18 -0
  102. data/app/views/rails_admin/main/_form_filtering_multiselect.html.haml +59 -0
  103. data/app/views/rails_admin/main/_form_filtering_select.html.haml +47 -0
  104. data/app/views/rails_admin/main/_form_nested_many.html.haml +41 -0
  105. data/app/views/rails_admin/main/_form_nested_one.html.haml +35 -0
  106. data/app/views/rails_admin/main/_form_polymorphic_association.html.haml +34 -0
  107. data/app/views/rails_admin/main/_form_text.html.haml +9 -0
  108. data/app/views/rails_admin/main/_submit_buttons.html.haml +15 -0
  109. data/app/views/rails_admin/main/bulk_delete.html.haml +11 -0
  110. data/app/views/rails_admin/main/dashboard.html.haml +31 -0
  111. data/app/views/rails_admin/main/delete.html.haml +18 -0
  112. data/app/views/rails_admin/main/edit.html.haml +2 -0
  113. data/app/views/rails_admin/main/export.html.haml +75 -0
  114. data/app/views/rails_admin/main/history.html.haml +42 -0
  115. data/app/views/rails_admin/main/index.html.haml +140 -0
  116. data/app/views/rails_admin/main/new.html.haml +2 -0
  117. data/app/views/rails_admin/main/show.html.haml +14 -0
  118. data/config/initializers/active_record_extensions.rb +19 -0
  119. data/config/initializers/devise_patch.rb +9 -0
  120. data/config/initializers/haml.rb +2 -0
  121. data/config/initializers/mongoid_extensions.rb +4 -0
  122. data/config/locales/fr.yml +24 -0
  123. data/config/locales/rails_admin.en.yml +130 -0
  124. data/config/routes.rb +12 -0
  125. data/lib/generators/rails_admin/install_generator.rb +84 -0
  126. data/lib/generators/rails_admin/templates/drop.rb +18 -0
  127. data/lib/generators/rails_admin/templates/initializer.erb +101 -0
  128. data/lib/generators/rails_admin/templates/migration.rb +18 -0
  129. data/lib/generators/rails_admin/uninstall_generator.rb +22 -0
  130. data/lib/generators/rails_admin/utils.rb +30 -0
  131. data/lib/rails_admin.rb +34 -0
  132. data/lib/rails_admin/abstract_model.rb +110 -0
  133. data/lib/rails_admin/adapters/active_record.rb +247 -0
  134. data/lib/rails_admin/adapters/active_record/abstract_object.rb +32 -0
  135. data/lib/rails_admin/adapters/mongoid.rb +333 -0
  136. data/lib/rails_admin/adapters/mongoid/abstract_object.rb +32 -0
  137. data/lib/rails_admin/adapters/mongoid/extension.rb +27 -0
  138. data/lib/rails_admin/config.rb +322 -0
  139. data/lib/rails_admin/config/actions.rb +121 -0
  140. data/lib/rails_admin/config/actions/base.rb +117 -0
  141. data/lib/rails_admin/config/actions/bulk_delete.rb +55 -0
  142. data/lib/rails_admin/config/actions/dashboard.rb +44 -0
  143. data/lib/rails_admin/config/actions/delete.rb +53 -0
  144. data/lib/rails_admin/config/actions/edit.rb +60 -0
  145. data/lib/rails_admin/config/actions/export.rb +40 -0
  146. data/lib/rails_admin/config/actions/history_index.rb +38 -0
  147. data/lib/rails_admin/config/actions/history_show.rb +38 -0
  148. data/lib/rails_admin/config/actions/index.rb +85 -0
  149. data/lib/rails_admin/config/actions/new.rb +64 -0
  150. data/lib/rails_admin/config/actions/show.rb +32 -0
  151. data/lib/rails_admin/config/actions/show_in_app.rb +28 -0
  152. data/lib/rails_admin/config/configurable.rb +92 -0
  153. data/lib/rails_admin/config/fields.rb +88 -0
  154. data/lib/rails_admin/config/fields/association.rb +108 -0
  155. data/lib/rails_admin/config/fields/base.rb +281 -0
  156. data/lib/rails_admin/config/fields/factories/belongs_to_association.rb +29 -0
  157. data/lib/rails_admin/config/fields/factories/carrierwave.rb +31 -0
  158. data/lib/rails_admin/config/fields/factories/devise.rb +27 -0
  159. data/lib/rails_admin/config/fields/factories/dragonfly.rb +27 -0
  160. data/lib/rails_admin/config/fields/factories/enum.rb +11 -0
  161. data/lib/rails_admin/config/fields/factories/paperclip.rb +26 -0
  162. data/lib/rails_admin/config/fields/factories/password.rb +17 -0
  163. data/lib/rails_admin/config/fields/factories/serialized.rb +17 -0
  164. data/lib/rails_admin/config/fields/group.rb +78 -0
  165. data/lib/rails_admin/config/fields/types.rb +27 -0
  166. data/lib/rails_admin/config/fields/types/all.rb +26 -0
  167. data/lib/rails_admin/config/fields/types/belongs_to_association.rb +41 -0
  168. data/lib/rails_admin/config/fields/types/boolean.rb +31 -0
  169. data/lib/rails_admin/config/fields/types/bson_object_id.rb +42 -0
  170. data/lib/rails_admin/config/fields/types/carrierwave.rb +31 -0
  171. data/lib/rails_admin/config/fields/types/color.rb +37 -0
  172. data/lib/rails_admin/config/fields/types/date.rb +24 -0
  173. data/lib/rails_admin/config/fields/types/datetime.rb +165 -0
  174. data/lib/rails_admin/config/fields/types/decimal.rb +14 -0
  175. data/lib/rails_admin/config/fields/types/dragonfly.rb +41 -0
  176. data/lib/rails_admin/config/fields/types/enum.rb +35 -0
  177. data/lib/rails_admin/config/fields/types/file_upload.rb +61 -0
  178. data/lib/rails_admin/config/fields/types/float.rb +14 -0
  179. data/lib/rails_admin/config/fields/types/has_and_belongs_to_many_association.rb +14 -0
  180. data/lib/rails_admin/config/fields/types/has_many_association.rb +32 -0
  181. data/lib/rails_admin/config/fields/types/has_one_association.rb +39 -0
  182. data/lib/rails_admin/config/fields/types/hidden.rb +21 -0
  183. data/lib/rails_admin/config/fields/types/integer.rb +22 -0
  184. data/lib/rails_admin/config/fields/types/mongoid_type.rb +25 -0
  185. data/lib/rails_admin/config/fields/types/paperclip.rb +28 -0
  186. data/lib/rails_admin/config/fields/types/password.rb +39 -0
  187. data/lib/rails_admin/config/fields/types/polymorphic_association.rb +76 -0
  188. data/lib/rails_admin/config/fields/types/serialized.rb +22 -0
  189. data/lib/rails_admin/config/fields/types/string.rb +41 -0
  190. data/lib/rails_admin/config/fields/types/text.rb +36 -0
  191. data/lib/rails_admin/config/fields/types/time.rb +36 -0
  192. data/lib/rails_admin/config/fields/types/timestamp.rb +18 -0
  193. data/lib/rails_admin/config/groupable.rb +18 -0
  194. data/lib/rails_admin/config/has_fields.rb +135 -0
  195. data/lib/rails_admin/config/has_groups.rb +23 -0
  196. data/lib/rails_admin/config/hideable.rb +28 -0
  197. data/lib/rails_admin/config/model.rb +88 -0
  198. data/lib/rails_admin/config/proxyable.rb +12 -0
  199. data/lib/rails_admin/config/proxyable/proxy.rb +43 -0
  200. data/lib/rails_admin/config/sections.rb +38 -0
  201. data/lib/rails_admin/config/sections/base.rb +29 -0
  202. data/lib/rails_admin/config/sections/create.rb +11 -0
  203. data/lib/rails_admin/config/sections/edit.rb +11 -0
  204. data/lib/rails_admin/config/sections/export.rb +11 -0
  205. data/lib/rails_admin/config/sections/list.rb +27 -0
  206. data/lib/rails_admin/config/sections/nested.rb +10 -0
  207. data/lib/rails_admin/config/sections/show.rb +10 -0
  208. data/lib/rails_admin/config/sections/update.rb +10 -0
  209. data/lib/rails_admin/engine.rb +22 -0
  210. data/lib/rails_admin/extension.rb +29 -0
  211. data/lib/rails_admin/extensions/cancan.rb +5 -0
  212. data/lib/rails_admin/extensions/cancan/authorization_adapter.rb +59 -0
  213. data/lib/rails_admin/extensions/history.rb +5 -0
  214. data/lib/rails_admin/extensions/history/auditing_adapter.rb +37 -0
  215. data/lib/rails_admin/extensions/history/history.rb +69 -0
  216. data/lib/rails_admin/extensions/paper_trail.rb +5 -0
  217. data/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb +92 -0
  218. data/lib/rails_admin/i18n_support.rb +43 -0
  219. data/lib/rails_admin/support/core_extensions.rb +44 -0
  220. data/lib/rails_admin/support/csv_converter.rb +109 -0
  221. data/lib/rails_admin/version.rb +6 -0
  222. data/lib/tasks/prepare_ci_env.rake +27 -0
  223. data/lib/tasks/rails_admin.rake +18 -0
  224. data/spec/ci.sh +2 -0
  225. data/spec/controllers/application_controller_spec.rb +30 -0
  226. data/spec/controllers/main_controller_spec.rb +180 -0
  227. data/spec/database_helpers.rb +15 -0
  228. data/spec/dummy_app/Gemfile +58 -0
  229. data/spec/dummy_app/Rakefile +7 -0
  230. data/spec/dummy_app/app/assets/images/rails.png +0 -0
  231. data/spec/dummy_app/app/assets/javascripts/application.js +15 -0
  232. data/spec/dummy_app/app/assets/stylesheets/application.css +13 -0
  233. data/spec/dummy_app/app/controllers/application_controller.rb +3 -0
  234. data/spec/dummy_app/app/controllers/players_controller.rb +5 -0
  235. data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
  236. data/spec/dummy_app/app/locales/models.en.yml +16 -0
  237. data/spec/dummy_app/app/models/abstract.rb +5 -0
  238. data/spec/dummy_app/app/models/article.rb +9 -0
  239. data/spec/dummy_app/app/models/author.rb +6 -0
  240. data/spec/dummy_app/app/models/ball.rb +8 -0
  241. data/spec/dummy_app/app/models/category.rb +3 -0
  242. data/spec/dummy_app/app/models/cms.rb +5 -0
  243. data/spec/dummy_app/app/models/cms/basic_page.rb +7 -0
  244. data/spec/dummy_app/app/models/cms/unscoped_page.rb +3 -0
  245. data/spec/dummy_app/app/models/comment.rb +3 -0
  246. data/spec/dummy_app/app/models/division.rb +12 -0
  247. data/spec/dummy_app/app/models/draft.rb +11 -0
  248. data/spec/dummy_app/app/models/fan.rb +5 -0
  249. data/spec/dummy_app/app/models/field_test.rb +20 -0
  250. data/spec/dummy_app/app/models/hardball.rb +2 -0
  251. data/spec/dummy_app/app/models/league.rb +10 -0
  252. data/spec/dummy_app/app/models/mongoid_field_test.rb +22 -0
  253. data/spec/dummy_app/app/models/nested_field_test.rb +6 -0
  254. data/spec/dummy_app/app/models/player.rb +23 -0
  255. data/spec/dummy_app/app/models/rel_test.rb +6 -0
  256. data/spec/dummy_app/app/models/tag.rb +7 -0
  257. data/spec/dummy_app/app/models/team.rb +25 -0
  258. data/spec/dummy_app/app/models/user.rb +21 -0
  259. data/spec/dummy_app/app/uploaders/carrierwave_uploader.rb +53 -0
  260. data/spec/dummy_app/app/views/layouts/application.html.erb +14 -0
  261. data/spec/dummy_app/app/views/players/show.html.haml +1 -0
  262. data/spec/dummy_app/config.ru +4 -0
  263. data/spec/dummy_app/config/application.rb +62 -0
  264. data/spec/dummy_app/config/boot.rb +6 -0
  265. data/spec/dummy_app/config/database.yml +25 -0
  266. data/spec/dummy_app/config/environment.rb +5 -0
  267. data/spec/dummy_app/config/environments/development.rb +37 -0
  268. data/spec/dummy_app/config/environments/production.rb +67 -0
  269. data/spec/dummy_app/config/environments/test.rb +37 -0
  270. data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
  271. data/spec/dummy_app/config/initializers/devise.rb +148 -0
  272. data/spec/dummy_app/config/initializers/inflections.rb +15 -0
  273. data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
  274. data/spec/dummy_app/config/initializers/rails_admin.rb +11 -0
  275. data/spec/dummy_app/config/initializers/secret_token.rb +7 -0
  276. data/spec/dummy_app/config/initializers/session_store.rb +8 -0
  277. data/spec/dummy_app/config/initializers/wrap_parameters.rb +14 -0
  278. data/spec/dummy_app/config/mongoid.yml +17 -0
  279. data/spec/dummy_app/config/routes.rb +10 -0
  280. data/spec/dummy_app/db/migrate/00000000000001_create_divisions_migration.rb +13 -0
  281. data/spec/dummy_app/db/migrate/00000000000002_create_drafts_migration.rb +19 -0
  282. data/spec/dummy_app/db/migrate/00000000000003_create_leagues_migration.rb +12 -0
  283. data/spec/dummy_app/db/migrate/00000000000004_create_players_migration.rb +20 -0
  284. data/spec/dummy_app/db/migrate/00000000000005_create_teams_migration.rb +22 -0
  285. data/spec/dummy_app/db/migrate/00000000000006_devise_create_users.rb +49 -0
  286. data/spec/dummy_app/db/migrate/00000000000007_create_histories_table.rb +16 -0
  287. data/spec/dummy_app/db/migrate/00000000000008_create_fans_migration.rb +12 -0
  288. data/spec/dummy_app/db/migrate/00000000000009_create_fans_teams_migration.rb +11 -0
  289. data/spec/dummy_app/db/migrate/00000000000010_add_revenue_to_team_migration.rb +9 -0
  290. data/spec/dummy_app/db/migrate/00000000000011_add_suspended_to_player_migration.rb +9 -0
  291. data/spec/dummy_app/db/migrate/00000000000012_add_avatar_columns_to_user.rb +16 -0
  292. data/spec/dummy_app/db/migrate/00000000000013_add_roles_to_user.rb +9 -0
  293. data/spec/dummy_app/db/migrate/00000000000014_add_color_to_team_migration.rb +9 -0
  294. data/spec/dummy_app/db/migrate/20101223222233_create_rel_tests.rb +15 -0
  295. data/spec/dummy_app/db/migrate/20110103205808_create_comments.rb +15 -0
  296. data/spec/dummy_app/db/migrate/20110123042530_rename_histories_to_rails_admin_histories.rb +9 -0
  297. data/spec/dummy_app/db/migrate/20110224184303_create_field_tests.rb +22 -0
  298. data/spec/dummy_app/db/migrate/20110328193014_create_cms_basic_pages.rb +14 -0
  299. data/spec/dummy_app/db/migrate/20110329183136_remove_league_id_from_teams.rb +9 -0
  300. data/spec/dummy_app/db/migrate/20110607152842_add_format_to_field_test.rb +9 -0
  301. data/spec/dummy_app/db/migrate/20110714095433_create_balls.rb +12 -0
  302. data/spec/dummy_app/db/migrate/20110831090841_add_protected_field_and_restricted_field_to_field_tests.rb +6 -0
  303. data/spec/dummy_app/db/migrate/20110901131551_change_division_primary_key.rb +19 -0
  304. data/spec/dummy_app/db/migrate/20110901142530_rename_league_id_foreign_key_on_divisions.rb +5 -0
  305. data/spec/dummy_app/db/migrate/20110901150912_set_primary_key_not_null_for_divisions.rb +21 -0
  306. data/spec/dummy_app/db/migrate/20110901154834_change_length_for_rails_admin_histories.rb +9 -0
  307. data/spec/dummy_app/db/migrate/20111103174459_create_unscoped_pages.rb +9 -0
  308. data/spec/dummy_app/db/migrate/20111108143642_add_dragonfly_and_carrierwave_to_field_tests.rb +7 -0
  309. data/spec/dummy_app/db/migrate/20111115041025_add_type_to_balls.rb +5 -0
  310. data/spec/dummy_app/db/migrate/20111123092549_create_nested_field_tests.rb +10 -0
  311. data/spec/dummy_app/db/migrate/20111130075338_add_dragonfly_asset_name_to_field_tests.rb +5 -0
  312. data/spec/dummy_app/db/migrate/20111215083258_create_foo_bars.rb +8 -0
  313. data/spec/dummy_app/db/migrate/20120117151733_add_custom_field_to_teams.rb +5 -0
  314. data/spec/dummy_app/db/migrate/20120118122004_add_categories.rb +7 -0
  315. data/spec/dummy_app/db/seeds.rb +18 -0
  316. data/spec/dummy_app/doc/README_FOR_APP +2 -0
  317. data/spec/dummy_app/public/404.html +26 -0
  318. data/spec/dummy_app/public/422.html +26 -0
  319. data/spec/dummy_app/public/500.html +25 -0
  320. data/spec/dummy_app/public/favicon.ico +0 -0
  321. data/spec/dummy_app/public/robots.txt +5 -0
  322. data/spec/dummy_app/public/system/dragonfly/development/2011/11/24/10_36_27_888_Pensive_Parakeet.jpg +0 -0
  323. data/spec/dummy_app/public/system/dragonfly/development/2011/11/24/10_36_27_888_Pensive_Parakeet.jpg.meta +1 -0
  324. data/spec/dummy_app/public/system/dragonfly/development/2011/11/30/08_54_39_906_Costa_Rican_Frog.jpg +0 -0
  325. data/spec/dummy_app/public/system/dragonfly/development/2011/11/30/08_54_39_906_Costa_Rican_Frog.jpg.meta +1 -0
  326. data/spec/dummy_app/public/system/paperclip_assets/1/original/Boston City Flow.jpg +0 -0
  327. data/spec/dummy_app/public/system/paperclip_assets/1/thumb/Boston City Flow.jpg +0 -0
  328. data/spec/dummy_app/public/system/paperclip_assets/3/original/Costa Rican Frog.jpg +0 -0
  329. data/spec/dummy_app/public/system/paperclip_assets/3/thumb/Costa Rican Frog.jpg +0 -0
  330. data/spec/dummy_app/public/system/paperclip_assets/6/original/liste-electorale.pdf +0 -0
  331. data/spec/dummy_app/public/system/paperclip_assets/6/thumb/liste-electorale.pdf +148 -0
  332. data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/3/Boston_City_Flow.jpg +0 -0
  333. data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/3/thumb_Boston_City_Flow.jpg +0 -0
  334. data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/4/Costa_Rican_Frog.jpg +0 -0
  335. data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/4/thumb_Costa_Rican_Frog.jpg +0 -0
  336. data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/6/Pensive_Parakeet.jpg +0 -0
  337. data/spec/dummy_app/public/uploads/field_test/carrierwave_asset/6/thumb_Pensive_Parakeet.jpg +0 -0
  338. data/spec/dummy_app/script/rails +6 -0
  339. data/spec/factories.rb +89 -0
  340. data/spec/helpers/application_helper_spec.rb +277 -0
  341. data/spec/integration/authorization/cancan_spec.rb +349 -0
  342. data/spec/integration/basic/bulk_action/rails_admin_basic_bulk_action_spec.rb +25 -0
  343. data/spec/integration/basic/bulk_destroy/rails_admin_basic_bulk_destroy_spec.rb +44 -0
  344. data/spec/integration/basic/create/rails_admin_basic_create_spec.rb +154 -0
  345. data/spec/integration/basic/create/rails_admin_namespaced_model_create_spec.rb +23 -0
  346. data/spec/integration/basic/delete/rails_admin_basic_delete_spec.rb +27 -0
  347. data/spec/integration/basic/destroy/rails_admin_basic_destroy_spec.rb +56 -0
  348. data/spec/integration/basic/edit/rails_admin_basic_edit_spec.rb +109 -0
  349. data/spec/integration/basic/export/rails_admin_basic_export_spec.rb +87 -0
  350. data/spec/integration/basic/list/rails_admin_basic_list_spec.rb +392 -0
  351. data/spec/integration/basic/new/rails_admin_basic_new_spec.rb +74 -0
  352. data/spec/integration/basic/new/rails_admin_namespaced_model_new_spec.rb +31 -0
  353. data/spec/integration/basic/show/rails_admin_basic_show_spec.rb +91 -0
  354. data/spec/integration/basic/update/rails_admin_basic_update_spec.rb +219 -0
  355. data/spec/integration/config/edit/rails_admin_config_edit_spec.rb +954 -0
  356. data/spec/integration/config/list/rails_admin_config_list_spec.rb +509 -0
  357. data/spec/integration/config/show/rails_admin_config_show_spec.rb +302 -0
  358. data/spec/integration/history/rails_admin_history_spec.rb +66 -0
  359. data/spec/integration/rails_admin_spec.rb +113 -0
  360. data/spec/integration/relation_spec.rb +26 -0
  361. data/spec/spec_helper.rb +86 -0
  362. data/spec/support/tableless.rb +27 -0
  363. data/spec/unit/adapters/active_record/abstract_object_spec.rb +131 -0
  364. data/spec/unit/adapters/active_record_spec.rb +373 -0
  365. data/spec/unit/adapters/mongoid/abstract_object_spec.rb +30 -0
  366. data/spec/unit/adapters/mongoid_spec.rb +581 -0
  367. data/spec/unit/config/actions_spec.rb +181 -0
  368. data/spec/unit/config/fields/base_spec.rb +300 -0
  369. data/spec/unit/config/model_spec.rb +75 -0
  370. data/spec/unit/config/sections_spec.rb +123 -0
  371. data/spec/unit/config_spec.rb +273 -0
  372. metadata +823 -0
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe "RailsAdmin Namespaced Model Create" do
4
+
5
+ subject { page }
6
+
7
+ before(:each) do
8
+ visit new_path(:model_name => "cms~basic_page")
9
+
10
+ fill_in "cms_basic_page[title]", :with => "Hello"
11
+ fill_in "cms_basic_page[content]", :with => "World"
12
+ end
13
+
14
+ it 'should be successful' do
15
+ click_button "Save"
16
+ end
17
+
18
+ it 'should create object with correct attributes' do
19
+ expect {
20
+ click_button "Save"
21
+ }.to change(Cms::BasicPage, :count).by(1)
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe "RailsAdmin Basic Delete" do
4
+
5
+ subject { page }
6
+
7
+ describe "delete" do
8
+ before(:each) do
9
+ @player = FactoryGirl.create :player
10
+ visit delete_path(:model_name => "player", :id => @player.id)
11
+ end
12
+
13
+ it "should show \"Delete model\"" do
14
+ should have_content("delete this player")
15
+ end
16
+ end
17
+
18
+ describe "delete with missing object" do
19
+ before(:each) do
20
+ visit delete_path(:model_name => "player", :id => 1)
21
+ end
22
+
23
+ it "should raise NotFound" do
24
+ page.driver.status_code.should eql(404)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe "RailsAdmin Basic Destroy" do
4
+
5
+ subject { page }
6
+
7
+ describe "destroy" do
8
+ before(:each) do
9
+ @player = FactoryGirl.create :player
10
+ visit delete_path(:model_name => "player", :id => @player.id)
11
+ click_button "Yes, I'm sure"
12
+ @player = RailsAdmin::AbstractModel.new("Player").first
13
+ end
14
+
15
+ it "should destroy an object" do
16
+ @player.should be_nil
17
+ end
18
+ end
19
+
20
+ describe "destroy with errors" do
21
+ before(:each) do
22
+ Player.any_instance.stub(:destroy).and_return false
23
+ @player = FactoryGirl.create :player
24
+ visit delete_path(:model_name => "player", :id => @player.id)
25
+ click_button "Yes, I'm sure"
26
+ end
27
+
28
+ it "should destroy an object" do
29
+ @player.reload.should be
30
+ end
31
+ end
32
+
33
+ describe "destroy" do
34
+ before(:each) do
35
+ @player = FactoryGirl.create :player
36
+ visit delete_path(:model_name => "player", :id => @player.id)
37
+ click_button "Cancel"
38
+ @player = RailsAdmin::AbstractModel.new("Player").first
39
+ end
40
+
41
+ it "should not destroy an object" do
42
+ @player.should be
43
+ end
44
+ end
45
+
46
+ describe "destroy with missing object" do
47
+ before(:each) do
48
+ page.driver.delete(delete_path(:model_name => "player", :id => 1))
49
+ end
50
+
51
+ it "should raise NotFound" do
52
+ page.driver.status_code.should eql(404)
53
+ end
54
+ end
55
+
56
+ end
@@ -0,0 +1,109 @@
1
+ require 'spec_helper'
2
+
3
+ describe "RailsAdmin Basic Edit" do
4
+
5
+ subject { page }
6
+
7
+ describe "edit" do
8
+ before(:each) do
9
+ @player = FactoryGirl.create :player
10
+ visit edit_path(:model_name => "player", :id => @player.id)
11
+ end
12
+
13
+ it "should show \"Edit model\"" do
14
+ should have_content("Edit Player")
15
+ end
16
+
17
+ it "should show required fields as \"Required\"" do
18
+ should have_selector("div", :text => /Name\s*Required/)
19
+ should have_selector("div", :text => /Number\s*Required/)
20
+ end
21
+
22
+ it "should show non-required fields as \"Optional\"" do
23
+ find("#player_position_field .help-block").should have_content("Optional")
24
+ find("#player_born_on_field .help-block").should have_content("Optional")
25
+ find("#player_notes_field .help-block").should have_content("Optional")
26
+ end
27
+ end
28
+
29
+ describe "association with inverse_of option" do
30
+ it "should add a related id to the belongs_to create team link" do
31
+ @player = FactoryGirl.create :player
32
+ visit edit_path(:model_name => "player", :id => @player.id)
33
+ should have_selector("a", :href => 'admin/teams/new?associations[players]=' + @player.id.to_s)
34
+ end
35
+
36
+ it "should add a related id to the has_many create team link" do
37
+ @team = FactoryGirl.create :team
38
+ visit edit_path(:model_name => "team", :id => @team.id)
39
+ should have_selector("a", :href => 'admin/players/new?associations[team]=' + @team.id.to_s)
40
+ end
41
+ end
42
+
43
+ describe "readonly associations" do
44
+
45
+ it 'should not be editable' do
46
+ @league = FactoryGirl.create :league
47
+ visit edit_path(:model_name => "league", :id => @league.id)
48
+ should_not have_selector('select#league_team_ids')
49
+ should have_selector('select#league_division_ids') # decoy, fails if naming scheme changes
50
+ end
51
+ end
52
+
53
+ describe "edit with has-and-belongs-to-many association" do
54
+ before(:each) do
55
+ @teams = 3.times.map { FactoryGirl.create :team }
56
+ @fan = FactoryGirl.create :fan, :teams => [@teams[0]]
57
+ visit edit_path(:model_name => "fan", :id => @fan.id)
58
+ end
59
+
60
+ it "should show associated objects" do
61
+ should have_selector "#fan_team_ids" do |select|
62
+ select[0].should have_selector 'option[selected="selected"]'
63
+ select[1].should_not have_selector 'option[selected="selected"]'
64
+ select[2].should_not have_selector 'option[selected="selected"]'
65
+ end
66
+ end
67
+ end
68
+
69
+ describe "edit with missing object" do
70
+ before(:each) do
71
+ visit edit_path(:model_name => "player", :id => 1)
72
+ end
73
+
74
+ it "should raise NotFound" do
75
+ page.driver.status_code.should eql(404)
76
+ end
77
+ end
78
+
79
+ describe "edit with missing label", :given => ["a player exists", "three teams with no name exist"] do
80
+ before(:each) do
81
+ @player = FactoryGirl.create :player
82
+ @teams = 3.times.map { FactoryGirl.create :team, :name => "" }
83
+ visit edit_path(:model_name => "player", :id => @player.id)
84
+ end
85
+ end
86
+
87
+ describe "edit object with overridden to_param" do
88
+ before(:each) do
89
+ @ball = FactoryGirl.create :ball
90
+ visit edit_path(:model_name => "ball", :id => @ball.id)
91
+ end
92
+
93
+ it "should display a link to the delete page" do
94
+ should have_selector "a[href='/admin/ball/#{@ball.id}/delete']"
95
+ end
96
+
97
+ end
98
+
99
+ describe "clicking cancel when editing an object" do
100
+
101
+ it "should send back to previous URL" do
102
+ @ball = FactoryGirl.create :ball
103
+ visit '/admin/ball?sort=color'
104
+ click_link 'Edit'
105
+ click_button 'Cancel'
106
+ page.current_url.should == 'http://www.example.com/admin/ball?sort=color'
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,87 @@
1
+ require 'spec_helper'
2
+
3
+ describe "RailsAdmin Export" do
4
+
5
+ subject { page }
6
+
7
+ before(:each) do
8
+ Comment.all.map &:destroy # rspec bug => doesn't get destroyed with transaction
9
+
10
+ @players = 4.times.map { FactoryGirl.create :player }
11
+ @player = @players.first
12
+ @player.team = FactoryGirl.create :team
13
+ @player.draft = FactoryGirl.create :draft
14
+ @player.comments = (@comments = 2.times.map { FactoryGirl.create(:comment) })
15
+ @player.save
16
+
17
+ # removed schema=>only=>created_at
18
+ @non_default_schema = {
19
+ "only"=>["id", "updated_at", "deleted_at", "name", "position", "number", "retired", "injured", "born_on", "notes", "suspended"],
20
+ "include"=>{
21
+ "team"=>{"only"=>["id", "created_at", "updated_at", "name", "logo_url", "manager", "ballpark", "mascot", "founded", "wins", "losses", "win_percentage", "revenue", "color"]},
22
+ "draft"=>{"only"=>["id", "created_at", "updated_at", "date", "round", "pick", "overall", "college", "notes"]},
23
+ "comments"=>{"only"=>["id", "content", "created_at", "updated_at"]}
24
+ }
25
+ }
26
+ end
27
+
28
+ describe "POST /admin/players/export (prompt)" do
29
+
30
+ it "should allow to export to CSV with associations and default schema, containing properly translated header and follow configuration" do
31
+ RailsAdmin.config do |c|
32
+ c.model Player do
33
+ include_all_fields
34
+ field :name do
35
+ export_value do
36
+ "#{value} exported"
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ visit export_path(:model_name => 'player')
43
+ should have_content 'Select fields to export'
44
+ select "<comma> ','", :from => "csv_options_generator_col_sep"
45
+ click_button 'Export to csv'
46
+ should have_content "Id,Created at,Updated at,Deleted at,Name,Position,Number,Retired,Injured,Born on,Notes,Suspended"
47
+ should have_content "Id [Team],Created at [Team],Updated at [Team],Name [Team],Logo url [Team],Team Manager [Team],Ballpark [Team],Mascot [Team],Founded [Team],Wins [Team],Losses [Team],Win percentage [Team],Revenue [Team],Color [Team]"
48
+ should have_content "Id [Draft],Created at [Draft],Updated at [Draft],Date [Draft],Round [Draft],Pick [Draft],Overall [Draft],College [Draft],Notes [Draft]"
49
+ should have_content "Id [Comments],Content [Comments],Created at [Comments],Updated at [Comments]"
50
+ should have_content @player.name + " exported"
51
+ should have_content @player.team.name
52
+ should have_content @player.draft.college
53
+ should have_content @player.comments.first.content.split("\n").first.strip # can't match for more than one line
54
+ should have_content @player.comments.second.content.split("\n").first.strip
55
+ end
56
+
57
+ it "should allow to export to JSON" do
58
+ visit export_path(:model_name => 'player')
59
+ click_button 'Export to json'
60
+ should have_content @player.team.name
61
+ end
62
+
63
+ it "should allow to export to XML" do
64
+ visit export_path(:model_name => 'player')
65
+ click_button 'Export to xml'
66
+
67
+ # spec fails on non 1.9 mri rubies because of this https://github.com/rails/rails/pull/2076
68
+ # waiting for fix (rails-3.1.4?)
69
+ should have_content @player.team.name if RUBY_VERSION =~ /1\.9/
70
+ end
71
+
72
+ it "should export polymorphic fields the easy way for now" do
73
+ visit export_path(:model_name => 'comment')
74
+ select "<comma> ','", :from => "csv_options_generator_col_sep"
75
+ click_button 'Export to csv'
76
+ should have_content "Id,Commentable,Commentable type,Content,Created at,Updated at"
77
+ should have_content "#{@player.id},#{@player.class}"
78
+ end
79
+ end
80
+
81
+ describe "POST /admin/players/export :format => :csv" do
82
+ it "should export with modified schema" do
83
+ page.driver.post(export_path(:model_name => 'player', :schema => @non_default_schema, :csv => true, :all => true, :csv_options => { :generator => { :col_sep => "," } }))
84
+ should have_content "Id,Updated at,Deleted at,Name,Position,Number,Retired,Injured,Born on,Notes,Suspended" # no created_at
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,392 @@
1
+ # coding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "RailsAdmin Basic List" do
6
+
7
+ subject { page }
8
+
9
+ describe "GET /admin" do
10
+ it "should respond successfully" do
11
+ visit dashboard_path
12
+ end
13
+ end
14
+
15
+ describe "GET /admin/typo" do
16
+ it "should redirect to dashboard and inform the user the model wasn't found" do
17
+ visit '/admin/whatever'
18
+ page.driver.status_code.should eql(404)
19
+ find('.alert-error').should have_content("Model 'Whatever' could not be found")
20
+ end
21
+ end
22
+
23
+ describe "GET /admin/balls/545-typo" do
24
+ it "should redirect to balls index and inform the user the id wasn't found" do
25
+ visit '/admin/ball/545-typo'
26
+ page.driver.status_code.should eql(404)
27
+ find('.alert-error').should have_content("Ball with id '545-typo' could not be found")
28
+ end
29
+ end
30
+
31
+ describe "GET /admin/player as list" do
32
+ before do
33
+ 21.times { FactoryGirl.create :player } # two pages of players
34
+ visit index_path(:model_name => "player")
35
+ end
36
+
37
+ it "should show \"List of Models\", should show filters and should show column headers" do
38
+ should have_content("List of Players")
39
+ should have_content("Created at")
40
+ should have_content("Updated at")
41
+
42
+ # it "shows the show, edit and delete links" do
43
+ should have_selector("td a", :text => 'Show')
44
+ should have_selector("td a", :text => 'Edit')
45
+ should have_selector("td a", :text => 'Delete')
46
+
47
+ # it "has the search box with some prompt text" do
48
+ should have_selector("input[placeholder='Filter']")
49
+
50
+ # https://github.com/sferik/rails_admin/issues/362
51
+ # test that no link uses the "wildcard route" with the main
52
+ # controller and list method
53
+ # it "should not use the 'wildcard route'" do
54
+ should have_selector("a[href*='all=true']") # make sure we're fully testing pagination
55
+ should have_no_selector("a[href^='/rails_admin/main/list']")
56
+ end
57
+ end
58
+
59
+ describe "GET /admin/player" do
60
+ before do
61
+ @teams = 2.times.map do
62
+ FactoryGirl.create(:team)
63
+ end
64
+ @players = [
65
+ FactoryGirl.create(:player, :retired => true, :injured => true, :team => @teams[0]),
66
+ FactoryGirl.create(:player, :retired => true, :injured => false, :team => @teams[0]),
67
+ FactoryGirl.create(:player, :retired => false, :injured => true, :team => @teams[1]),
68
+ FactoryGirl.create(:player, :retired => false, :injured => false, :team => @teams[1]),
69
+ ]
70
+ end
71
+
72
+ it "should allow to query on any attribute" do
73
+ visit index_path(:model_name => "player", :query => @players[0].name)
74
+ should have_content(@players[0].name)
75
+ (1..3).each do |i|
76
+ should have_no_content(@players[i].name)
77
+ end
78
+ end
79
+
80
+ it "should allow to filter on one attribute" do
81
+ visit index_path(:model_name => "player", :f => {:injured => {"1" => {:v => "true"}}})
82
+ should have_content(@players[0].name)
83
+ should have_no_content(@players[1].name)
84
+ should have_content(@players[2].name)
85
+ should have_no_content(@players[3].name)
86
+ end
87
+
88
+ it "should allow to combine filters on two different attributes" do
89
+ visit index_path(:model_name => "player", :f => {:retired => {"1" => {:v => "true"}}, :injured => {"1" => {:v => "true"}}})
90
+ should have_content(@players[0].name)
91
+ (1..3).each do |i|
92
+ should have_no_content(@players[i].name)
93
+ end
94
+ end
95
+
96
+ it "should allow to filter on belongs_to relationships" do
97
+ visit index_path(:model_name => "player", :f => {:team => {"1" => { :v => @teams[0].name }}})
98
+ should have_content(@players[0].name)
99
+ should have_content(@players[1].name)
100
+ should have_no_content(@players[2].name)
101
+ should have_no_content(@players[3].name)
102
+ end
103
+
104
+ it "should allow to disable search on attributes" do
105
+ RailsAdmin.config Player do
106
+ list do
107
+ field :position
108
+ field :name do
109
+ searchable false
110
+ end
111
+ end
112
+ end
113
+ visit index_path(:model_name => "player", :query => @players[0].name)
114
+ should have_no_content(@players[0].name)
115
+ end
116
+
117
+ it "should allow to search a belongs_to attribute over the base table" do
118
+ RailsAdmin.config Player do
119
+ list do
120
+ field :id
121
+ field :name
122
+ field :team do
123
+ searchable Player => :team_id
124
+ end
125
+ end
126
+ end
127
+ visit index_path(:model_name => "player", :f => {:team => {"1" => {:v => @teams.first.id}}})
128
+ should have_content(@players[0].name)
129
+ should have_content(@players[1].name)
130
+ should have_no_content(@players[2].name)
131
+ should have_no_content(@players[3].name)
132
+ end
133
+
134
+
135
+ it "should allow to search a belongs_to attribute over the target table" do
136
+ RailsAdmin.config Player do
137
+ list do
138
+ field :id
139
+ field :name
140
+ field :team do
141
+ searchable Team => :name
142
+ end
143
+ end
144
+ end
145
+ visit index_path(:model_name => "player", :f => {:team => {"1" => {:v => @teams.first.name}}})
146
+ should have_content(@players[0].name)
147
+ should have_content(@players[1].name)
148
+ should have_no_content(@players[2].name)
149
+ should have_no_content(@players[3].name)
150
+ end
151
+
152
+ it "should allow to search a belongs_to attribute over the target table with a table name specified as a hash" do
153
+ RailsAdmin.config Player do
154
+ list do
155
+ field :id
156
+ field :name
157
+ field :team do
158
+ searchable :teams => :name
159
+ end
160
+ end
161
+ end
162
+ visit index_path(:model_name => "player", :f => {:team => {"1" => {:v => @teams.first.name}}})
163
+ should have_content(@players[0].name)
164
+ should have_content(@players[1].name)
165
+ should have_no_content(@players[2].name)
166
+ should have_no_content(@players[3].name)
167
+ end
168
+
169
+ it "should allow to search a belongs_to attribute over the target table with a table name specified as a string" do
170
+ RailsAdmin.config Player do
171
+ list do
172
+ field :id
173
+ field :name
174
+ field :team do
175
+ searchable 'teams.name'
176
+ end
177
+ end
178
+ end
179
+ visit index_path(:model_name => "player", :f => {:team => {"1" => {:v => @teams.first.name}}})
180
+ should have_content(@players[0].name)
181
+ should have_content(@players[1].name)
182
+ should have_no_content(@players[2].name)
183
+ should have_no_content(@players[3].name)
184
+ end
185
+
186
+ it "should allow to search a belongs_to attribute over the label method by default" do
187
+ RailsAdmin.config Player do
188
+ list do
189
+ field :id
190
+ field :name
191
+ field :team
192
+ end
193
+ end
194
+ visit index_path(:model_name => "player", :f => {:team => {"1" => {:v => @teams.first.name}}})
195
+ should have_content(@players[0].name)
196
+ should have_content(@players[1].name)
197
+ should have_no_content(@players[2].name)
198
+ should have_no_content(@players[3].name)
199
+ end
200
+
201
+ it "should allow to search a belongs_to attribute over the target table when an attribute is specified" do
202
+ RailsAdmin.config Player do
203
+ list do
204
+ field :id
205
+ field :name
206
+ field :team do
207
+ searchable :name
208
+ end
209
+ end
210
+ end
211
+ visit index_path(:model_name => "player", :f => {:team => {"1" => {:v => @teams.first.name}}})
212
+ should have_content(@players[0].name)
213
+ should have_content(@players[1].name)
214
+ should have_no_content(@players[2].name)
215
+ should have_no_content(@players[3].name)
216
+ end
217
+
218
+ it "should allow to search over more than one attribute" do
219
+ RailsAdmin.config Player do
220
+ list do
221
+ field :id
222
+ field :name
223
+ field :team do
224
+ searchable [:name, {Player => :team_id}]
225
+ end
226
+ end
227
+ end
228
+ visit index_path(:model_name => "player", :f => {:team => {"1" => {:v => @teams.first.name}, "2" => {:v => @teams.first.id}}})
229
+ should have_content(@players[0].name)
230
+ should have_content(@players[1].name)
231
+ should have_no_content(@players[2].name)
232
+ should have_no_content(@players[3].name)
233
+ # same with a different id
234
+ visit index_path(:model_name => "player", :f => {:team => {"1" => {:v => @teams.first.name}, "2" => {:v => @teams.last.id}}})
235
+ should have_no_content(@players[0].name)
236
+ should have_no_content(@players[1].name)
237
+ should have_no_content(@players[2].name)
238
+ should have_no_content(@players[3].name)
239
+ end
240
+
241
+ it "should display base filters when no filters are present in the params" do
242
+ RailsAdmin.config Player do
243
+ list do
244
+ filters [:name, :team]
245
+ end
246
+ end
247
+
248
+ visit index_path(:model_name => "player")
249
+ should have_content(%{$.filters.append("Name", "name", "string", null, null, "", 1);})
250
+ should have_content(%{$.filters.append("Team", "team", "belongs_to_association", null, null, "", 2);})
251
+ end
252
+ end
253
+
254
+ describe "GET /admin/player with 2 objects" do
255
+ before(:each) do
256
+ @players = 2.times.map { FactoryGirl.create :player }
257
+ visit index_path(:model_name => "player")
258
+ end
259
+
260
+ it "should show \"2 results\"" do
261
+ should have_content("2 players")
262
+ end
263
+ end
264
+
265
+ describe "GET /admin/player with 20 objects" do
266
+ before(:each) do
267
+ @players = 20.times.map { FactoryGirl.create :player }
268
+ visit index_path(:model_name => "player")
269
+ end
270
+
271
+ it "should show \"20 results\"" do
272
+ should have_content("20 players")
273
+ end
274
+ end
275
+
276
+ describe "GET /admin/player with 20 pages, page 8" do
277
+ before(:each) do
278
+ items_per_page = RailsAdmin.config.default_items_per_page
279
+ (items_per_page * 20).times { FactoryGirl.create(:player) }
280
+ visit index_path(:model_name => "player", :page => 8)
281
+ end
282
+
283
+ it "should paginate correctly" do
284
+ find('.pagination ul li:first').should have_content("« Prev")
285
+ find('.pagination ul li:last').should have_content("Next »")
286
+ find('.pagination ul li.active').should have_content("8")
287
+ end
288
+ end
289
+
290
+ describe "list with 20 pages, page 20" do
291
+ before(:each) do
292
+ items_per_page = RailsAdmin.config.default_items_per_page
293
+ @players = (items_per_page * 20).times.map { FactoryGirl.create(:player) }
294
+ visit index_path(:model_name => "player", :page => 20)
295
+ end
296
+
297
+ it "should paginate correctly and contain the right item" do
298
+ find('.pagination ul li:first').should have_content("« Prev")
299
+ find('.pagination ul li:last').should have_content("Next »")
300
+ find('.pagination ul li.active').should have_content("20")
301
+ end
302
+ end
303
+
304
+ describe "GET /admin/player show all" do
305
+ it "should respond successfully" do
306
+ 2.times.map { FactoryGirl.create :player }
307
+ visit index_path(:model_name => "player", :all => true)
308
+ end
309
+ end
310
+
311
+ describe "list as compact json" do
312
+ it "should have_content an array with 2 elements and contain an array of elements with keys id and label" do
313
+ 2.times.map { FactoryGirl.create :player }
314
+ response = page.driver.get(index_path(:model_name => "player", :compact => true, :format => :json))
315
+ ActiveSupport::JSON.decode(response.body).length.should eql(2)
316
+ ActiveSupport::JSON.decode(response.body).each do |object|
317
+ object.should have_key("id")
318
+ object.should have_key("label")
319
+ end
320
+ end
321
+ end
322
+
323
+ describe "search operator" do
324
+ let(:player) { FactoryGirl.create :player }
325
+
326
+ before do
327
+ Player.count.should == 0
328
+ end
329
+
330
+ it "finds the player if the query matches the default search opeartor" do
331
+ RailsAdmin.config do |config|
332
+ config.default_search_operator = 'ends_with'
333
+ config.model Player do
334
+ list { field :name }
335
+ end
336
+ end
337
+ visit index_path(:model_name => "player", :query => player.name[2, -1])
338
+ should have_content(player.name)
339
+ end
340
+
341
+ it "does not find the player if the query does not match the default search opeartor" do
342
+ RailsAdmin.config do |config|
343
+ config.default_search_operator = 'ends_with'
344
+ config.model Player do
345
+ list { field :name }
346
+ end
347
+ end
348
+ visit index_path(:model_name => "player", :query => player.name[0, 2])
349
+ should have_no_content(player.name)
350
+ end
351
+
352
+ it "finds the player if the query matches the specified search operator" do
353
+ RailsAdmin.config Player do
354
+ list do
355
+ field :name do
356
+ search_operator 'starts_with'
357
+ end
358
+ end
359
+ end
360
+ visit index_path(:model_name => "player", :query => player.name[0, 2])
361
+ should have_content(player.name)
362
+ end
363
+
364
+ it "does not find the player if the query does not match the specified search operator" do
365
+ RailsAdmin.config Player do
366
+ list do
367
+ field :name do
368
+ search_operator 'starts_with'
369
+ end
370
+ end
371
+ end
372
+ visit index_path(:model_name => "player", :query => player.name[1..-1])
373
+ should have_no_content(player.name)
374
+ end
375
+ end
376
+
377
+ describe "list for objects with overridden to_param" do
378
+ before(:each) do
379
+ @ball = FactoryGirl.create :ball
380
+
381
+ visit index_path(:model_name => "ball")
382
+ end
383
+
384
+ it "shows the show, edit and delete links with valid url" do
385
+ should have_selector("td a[href='/admin/ball/#{@ball.id}']")
386
+ should have_selector("td a[href='/admin/ball/#{@ball.id}/edit']")
387
+ should have_selector("td a[href='/admin/ball/#{@ball.id}/delete']")
388
+ end
389
+
390
+ end
391
+
392
+ end