elucid-rails_admin 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (348) hide show
  1. data/Gemfile +54 -0
  2. data/LICENSE.md +20 -0
  3. data/README.md +1334 -0
  4. data/Rakefile +14 -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 +1 -0
  48. data/app/assets/javascripts/rails_admin/jquery-ui-1.8.16.custom.js +5019 -0
  49. data/app/assets/javascripts/rails_admin/jquery.colorpicker.js +484 -0
  50. data/app/assets/javascripts/rails_admin/jquery.ui.timepicker.js +1219 -0
  51. data/app/assets/javascripts/rails_admin/ra.datetimepicker.js +67 -0
  52. data/app/assets/javascripts/rails_admin/ra.filter-box.js +119 -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.remote-form.js +147 -0
  56. data/app/assets/javascripts/rails_admin/rails_admin.js.erb +17 -0
  57. data/app/assets/javascripts/rails_admin/themes/default/ui.js +1 -0
  58. data/app/assets/javascripts/rails_admin/ui.js.coffee +30 -0
  59. data/app/assets/stylesheets/rails_admin/aristo/images/bg_fallback.png +0 -0
  60. data/app/assets/stylesheets/rails_admin/aristo/images/icon_sprite.png +0 -0
  61. data/app/assets/stylesheets/rails_admin/aristo/images/progress_bar.gif +0 -0
  62. data/app/assets/stylesheets/rails_admin/aristo/images/slider_handles.png +0 -0
  63. data/app/assets/stylesheets/rails_admin/aristo/images/ui-icons_222222_256x240.png +0 -0
  64. data/app/assets/stylesheets/rails_admin/aristo/images/ui-icons_454545_256x240.png +0 -0
  65. data/app/assets/stylesheets/rails_admin/aristo/jquery-ui-1.8.7.custom.css.scss +733 -0
  66. data/app/assets/stylesheets/rails_admin/base/README +2 -0
  67. data/app/assets/stylesheets/rails_admin/base/mixins.css.scss +1 -0
  68. data/app/assets/stylesheets/rails_admin/base/theming.css.scss +102 -0
  69. data/app/assets/stylesheets/rails_admin/base/variables.css.scss +1 -0
  70. data/app/assets/stylesheets/rails_admin/custom/README +3 -0
  71. data/app/assets/stylesheets/rails_admin/custom/mixins.css.scss +9 -0
  72. data/app/assets/stylesheets/rails_admin/custom/theming.css.scss +11 -0
  73. data/app/assets/stylesheets/rails_admin/custom/variables.css.scss +11 -0
  74. data/app/assets/stylesheets/rails_admin/imports.css.scss.erb +51 -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 +53 -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/README +11 -0
  81. data/app/assets/stylesheets/rails_admin/themes/default/mixins.css.scss +1 -0
  82. data/app/assets/stylesheets/rails_admin/themes/default/theming.css.scss +1 -0
  83. data/app/assets/stylesheets/rails_admin/themes/default/variables.css.scss +1 -0
  84. data/app/controllers/rails_admin/application_controller.rb +62 -0
  85. data/app/controllers/rails_admin/history_controller.rb +26 -0
  86. data/app/controllers/rails_admin/main_controller.rb +371 -0
  87. data/app/helpers/rails_admin/application_helper.rb +65 -0
  88. data/app/helpers/rails_admin/form_builder.rb +52 -0
  89. data/app/helpers/rails_admin/main_helper.rb +100 -0
  90. data/app/models/rails_admin/history.rb +64 -0
  91. data/app/views/kaminari/twitter-bootstrap/_gap.html.haml +2 -0
  92. data/app/views/kaminari/twitter-bootstrap/_next_page.html.haml +4 -0
  93. data/app/views/kaminari/twitter-bootstrap/_page.html.haml +4 -0
  94. data/app/views/kaminari/twitter-bootstrap/_paginator.html.haml +10 -0
  95. data/app/views/kaminari/twitter-bootstrap/_prev_page.html.haml +4 -0
  96. data/app/views/layouts/rails_admin/_navigation.html.haml +19 -0
  97. data/app/views/layouts/rails_admin/_secondary_navigation.html.haml +9 -0
  98. data/app/views/layouts/rails_admin/application.html.haml +41 -0
  99. data/app/views/rails_admin/history/_dashboard.html.haml +10 -0
  100. data/app/views/rails_admin/history/show.html.haml +42 -0
  101. data/app/views/rails_admin/main/_delete_notice.html.haml +19 -0
  102. data/app/views/rails_admin/main/_form_colorpicker.html.haml +26 -0
  103. data/app/views/rails_admin/main/_form_datetime.html.haml +7 -0
  104. data/app/views/rails_admin/main/_form_enumeration.html.haml +5 -0
  105. data/app/views/rails_admin/main/_form_field.html.haml +1 -0
  106. data/app/views/rails_admin/main/_form_file_upload.html.haml +19 -0
  107. data/app/views/rails_admin/main/_form_filtering_multiselect.html.haml +57 -0
  108. data/app/views/rails_admin/main/_form_filtering_select.html.haml +47 -0
  109. data/app/views/rails_admin/main/_form_polymorphic_association.html.haml +36 -0
  110. data/app/views/rails_admin/main/_form_text.html.haml +13 -0
  111. data/app/views/rails_admin/main/_models_links.html.haml +31 -0
  112. data/app/views/rails_admin/main/_object_links.html.haml +23 -0
  113. data/app/views/rails_admin/main/_submit_buttons.html.haml +12 -0
  114. data/app/views/rails_admin/main/bulk_delete.html.haml +6 -0
  115. data/app/views/rails_admin/main/dashboard.html.haml +31 -0
  116. data/app/views/rails_admin/main/delete.html.haml +13 -0
  117. data/app/views/rails_admin/main/edit.html.haml +2 -0
  118. data/app/views/rails_admin/main/export.html.haml +70 -0
  119. data/app/views/rails_admin/main/index.html.haml +98 -0
  120. data/app/views/rails_admin/main/new.html.haml +2 -0
  121. data/app/views/rails_admin/main/show.html.haml +14 -0
  122. data/config/initializers/active_record_extensions.rb +19 -0
  123. data/config/initializers/devise_patch.rb +9 -0
  124. data/config/initializers/haml.rb +3 -0
  125. data/config/locales/devise.bg.yml +42 -0
  126. data/config/locales/devise.de.yml +39 -0
  127. data/config/locales/devise.en.yml +39 -0
  128. data/config/locales/devise.es.yml +39 -0
  129. data/config/locales/devise.fi.yml +39 -0
  130. data/config/locales/devise.fr.yml +78 -0
  131. data/config/locales/devise.hr.yml +49 -0
  132. data/config/locales/devise.it.yml +39 -0
  133. data/config/locales/devise.lt.yml +39 -0
  134. data/config/locales/devise.mn.yml +39 -0
  135. data/config/locales/devise.nb.yml +43 -0
  136. data/config/locales/devise.pt-BR.yml +39 -0
  137. data/config/locales/devise.pt-PT.yml +39 -0
  138. data/config/locales/devise.ro.yml +46 -0
  139. data/config/locales/devise.ru.yml +39 -0
  140. data/config/locales/devise.sv.yml +39 -0
  141. data/config/locales/devise.tr.yml +39 -0
  142. data/config/locales/devise.uk.yml +39 -0
  143. data/config/locales/devise.zh-CN.yml +39 -0
  144. data/config/locales/devise.zh_cn.yml +39 -0
  145. data/config/locales/rails_admin.bg.yml +104 -0
  146. data/config/locales/rails_admin.da.yml +99 -0
  147. data/config/locales/rails_admin.de.yml +110 -0
  148. data/config/locales/rails_admin.en.yml +114 -0
  149. data/config/locales/rails_admin.es.yml +112 -0
  150. data/config/locales/rails_admin.fi.yml +107 -0
  151. data/config/locales/rails_admin.fr.yml +110 -0
  152. data/config/locales/rails_admin.hr.yml +81 -0
  153. data/config/locales/rails_admin.it.yml +109 -0
  154. data/config/locales/rails_admin.ja.yml +110 -0
  155. data/config/locales/rails_admin.lt.yml +102 -0
  156. data/config/locales/rails_admin.lv.yml +100 -0
  157. data/config/locales/rails_admin.mn.yml +103 -0
  158. data/config/locales/rails_admin.nb.yml +110 -0
  159. data/config/locales/rails_admin.nl.yml +135 -0
  160. data/config/locales/rails_admin.pl.yml +111 -0
  161. data/config/locales/rails_admin.pt-BR.yml +109 -0
  162. data/config/locales/rails_admin.pt-PT.yml +109 -0
  163. data/config/locales/rails_admin.ro.yml +113 -0
  164. data/config/locales/rails_admin.ru.yml +109 -0
  165. data/config/locales/rails_admin.sv.yml +103 -0
  166. data/config/locales/rails_admin.tr.yml +103 -0
  167. data/config/locales/rails_admin.uk.yml +100 -0
  168. data/config/locales/rails_admin.zh-CN.yml +114 -0
  169. data/config/locales/rails_admin.zh_cn.yml +107 -0
  170. data/config/routes.rb +28 -0
  171. data/lib/generators/rails_admin/install_generator.rb +83 -0
  172. data/lib/generators/rails_admin/templates/drop.rb +18 -0
  173. data/lib/generators/rails_admin/templates/initializer.erb +150 -0
  174. data/lib/generators/rails_admin/templates/migration.rb +18 -0
  175. data/lib/generators/rails_admin/uninstall_generator.rb +22 -0
  176. data/lib/generators/rails_admin/utils.rb +30 -0
  177. data/lib/rails_admin.rb +57 -0
  178. data/lib/rails_admin/abstract_model.rb +73 -0
  179. data/lib/rails_admin/abstract_object.rb +28 -0
  180. data/lib/rails_admin/adapters/active_record.rb +359 -0
  181. data/lib/rails_admin/config.rb +287 -0
  182. data/lib/rails_admin/config/base.rb +111 -0
  183. data/lib/rails_admin/config/fields.rb +99 -0
  184. data/lib/rails_admin/config/fields/association.rb +101 -0
  185. data/lib/rails_admin/config/fields/base.rb +273 -0
  186. data/lib/rails_admin/config/fields/factories/carrierwave.rb +16 -0
  187. data/lib/rails_admin/config/fields/factories/devise.rb +31 -0
  188. data/lib/rails_admin/config/fields/factories/dragonfly.rb +20 -0
  189. data/lib/rails_admin/config/fields/factories/enum.rb +11 -0
  190. data/lib/rails_admin/config/fields/factories/paperclip.rb +26 -0
  191. data/lib/rails_admin/config/fields/factories/password.rb +17 -0
  192. data/lib/rails_admin/config/fields/group.rb +63 -0
  193. data/lib/rails_admin/config/fields/groupable.rb +25 -0
  194. data/lib/rails_admin/config/fields/types.rb +26 -0
  195. data/lib/rails_admin/config/fields/types/all.rb +22 -0
  196. data/lib/rails_admin/config/fields/types/belongs_to_association.rb +51 -0
  197. data/lib/rails_admin/config/fields/types/boolean.rb +29 -0
  198. data/lib/rails_admin/config/fields/types/carrierwave.rb +32 -0
  199. data/lib/rails_admin/config/fields/types/color.rb +37 -0
  200. data/lib/rails_admin/config/fields/types/date.rb +24 -0
  201. data/lib/rails_admin/config/fields/types/datetime.rb +160 -0
  202. data/lib/rails_admin/config/fields/types/decimal.rb +14 -0
  203. data/lib/rails_admin/config/fields/types/dragonfly.rb +51 -0
  204. data/lib/rails_admin/config/fields/types/enum.rb +35 -0
  205. data/lib/rails_admin/config/fields/types/file_upload.rb +54 -0
  206. data/lib/rails_admin/config/fields/types/float.rb +14 -0
  207. data/lib/rails_admin/config/fields/types/has_and_belongs_to_many_association.rb +14 -0
  208. data/lib/rails_admin/config/fields/types/has_many_association.rb +42 -0
  209. data/lib/rails_admin/config/fields/types/has_one_association.rb +31 -0
  210. data/lib/rails_admin/config/fields/types/integer.rb +24 -0
  211. data/lib/rails_admin/config/fields/types/paperclip.rb +38 -0
  212. data/lib/rails_admin/config/fields/types/password.rb +41 -0
  213. data/lib/rails_admin/config/fields/types/polymorphic_association.rb +78 -0
  214. data/lib/rails_admin/config/fields/types/string.rb +34 -0
  215. data/lib/rails_admin/config/fields/types/text.rb +39 -0
  216. data/lib/rails_admin/config/fields/types/time.rb +31 -0
  217. data/lib/rails_admin/config/fields/types/timestamp.rb +18 -0
  218. data/lib/rails_admin/config/has_fields.rb +112 -0
  219. data/lib/rails_admin/config/has_groups.rb +39 -0
  220. data/lib/rails_admin/config/hideable.rb +28 -0
  221. data/lib/rails_admin/config/model.rb +89 -0
  222. data/lib/rails_admin/config/proxy.rb +40 -0
  223. data/lib/rails_admin/config/sections.rb +51 -0
  224. data/lib/rails_admin/config/sections/create.rb +11 -0
  225. data/lib/rails_admin/config/sections/export.rb +18 -0
  226. data/lib/rails_admin/config/sections/list.rb +55 -0
  227. data/lib/rails_admin/config/sections/navigation.rb +21 -0
  228. data/lib/rails_admin/config/sections/show.rb +50 -0
  229. data/lib/rails_admin/config/sections/update.rb +11 -0
  230. data/lib/rails_admin/engine.rb +15 -0
  231. data/lib/rails_admin/extension.rb +23 -0
  232. data/lib/rails_admin/extensions/cancan.rb +5 -0
  233. data/lib/rails_admin/extensions/cancan/authorization_adapter.rb +71 -0
  234. data/lib/rails_admin/generic_support.rb +15 -0
  235. data/lib/rails_admin/i18n_support.rb +43 -0
  236. data/lib/rails_admin/support/core_extensions.rb +44 -0
  237. data/lib/rails_admin/support/csv_converter.rb +109 -0
  238. data/lib/rails_admin/version.rb +6 -0
  239. data/lib/tasks/prepare_ci_env.rake +27 -0
  240. data/lib/tasks/rails_admin.rake +18 -0
  241. data/spec/ci.sh +2 -0
  242. data/spec/controllers/application_controller_spec.rb +30 -0
  243. data/spec/controllers/main_controller_spec.rb +86 -0
  244. data/spec/database_helpers.rb +15 -0
  245. data/spec/dummy_app/Gemfile +52 -0
  246. data/spec/dummy_app/README +256 -0
  247. data/spec/dummy_app/Rakefile +7 -0
  248. data/spec/dummy_app/app/controllers/application_controller.rb +3 -0
  249. data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
  250. data/spec/dummy_app/app/locales/models.en.yml +8 -0
  251. data/spec/dummy_app/app/models/abstract.rb +5 -0
  252. data/spec/dummy_app/app/models/ball.rb +8 -0
  253. data/spec/dummy_app/app/models/cms.rb +5 -0
  254. data/spec/dummy_app/app/models/cms/basic_page.rb +7 -0
  255. data/spec/dummy_app/app/models/cms/unscoped_page.rb +3 -0
  256. data/spec/dummy_app/app/models/comment.rb +3 -0
  257. data/spec/dummy_app/app/models/division.rb +8 -0
  258. data/spec/dummy_app/app/models/draft.rb +11 -0
  259. data/spec/dummy_app/app/models/fan.rb +5 -0
  260. data/spec/dummy_app/app/models/field_test.rb +13 -0
  261. data/spec/dummy_app/app/models/league.rb +10 -0
  262. data/spec/dummy_app/app/models/player.rb +15 -0
  263. data/spec/dummy_app/app/models/rel_test.rb +6 -0
  264. data/spec/dummy_app/app/models/team.rb +25 -0
  265. data/spec/dummy_app/app/models/user.rb +21 -0
  266. data/spec/dummy_app/app/uploaders/carrierwave_uploader.rb +53 -0
  267. data/spec/dummy_app/app/views/layouts/application.html.erb +13 -0
  268. data/spec/dummy_app/config.ru +4 -0
  269. data/spec/dummy_app/config/application.rb +47 -0
  270. data/spec/dummy_app/config/boot.rb +6 -0
  271. data/spec/dummy_app/config/database.yml +22 -0
  272. data/spec/dummy_app/config/environment.rb +5 -0
  273. data/spec/dummy_app/config/environments/development.rb +27 -0
  274. data/spec/dummy_app/config/environments/production.rb +51 -0
  275. data/spec/dummy_app/config/environments/test.rb +39 -0
  276. data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
  277. data/spec/dummy_app/config/initializers/devise.rb +142 -0
  278. data/spec/dummy_app/config/initializers/inflections.rb +10 -0
  279. data/spec/dummy_app/config/initializers/mime_types.rb +5 -0
  280. data/spec/dummy_app/config/initializers/quiet_assets.rb +10 -0
  281. data/spec/dummy_app/config/initializers/rails_admin.rb +10 -0
  282. data/spec/dummy_app/config/initializers/secret_token.rb +7 -0
  283. data/spec/dummy_app/config/initializers/session_store.rb +8 -0
  284. data/spec/dummy_app/config/routes.rb +8 -0
  285. data/spec/dummy_app/db/migrate/00000000000001_create_divisions_migration.rb +13 -0
  286. data/spec/dummy_app/db/migrate/00000000000002_create_drafts_migration.rb +19 -0
  287. data/spec/dummy_app/db/migrate/00000000000003_create_leagues_migration.rb +12 -0
  288. data/spec/dummy_app/db/migrate/00000000000004_create_players_migration.rb +20 -0
  289. data/spec/dummy_app/db/migrate/00000000000005_create_teams_migration.rb +22 -0
  290. data/spec/dummy_app/db/migrate/00000000000006_devise_create_users.rb +19 -0
  291. data/spec/dummy_app/db/migrate/00000000000007_create_histories_table.rb +16 -0
  292. data/spec/dummy_app/db/migrate/00000000000008_create_fans_migration.rb +12 -0
  293. data/spec/dummy_app/db/migrate/00000000000009_create_fans_teams_migration.rb +11 -0
  294. data/spec/dummy_app/db/migrate/00000000000010_add_revenue_to_team_migration.rb +9 -0
  295. data/spec/dummy_app/db/migrate/00000000000011_add_suspended_to_player_migration.rb +9 -0
  296. data/spec/dummy_app/db/migrate/00000000000012_add_avatar_columns_to_user.rb +16 -0
  297. data/spec/dummy_app/db/migrate/00000000000013_add_roles_to_user.rb +9 -0
  298. data/spec/dummy_app/db/migrate/00000000000014_add_color_to_team_migration.rb +9 -0
  299. data/spec/dummy_app/db/migrate/20101223222233_create_rel_tests.rb +15 -0
  300. data/spec/dummy_app/db/migrate/20110103205808_create_comments.rb +15 -0
  301. data/spec/dummy_app/db/migrate/20110123042530_rename_histories_to_rails_admin_histories.rb +9 -0
  302. data/spec/dummy_app/db/migrate/20110224184303_create_field_tests.rb +22 -0
  303. data/spec/dummy_app/db/migrate/20110328193014_create_cms_basic_pages.rb +14 -0
  304. data/spec/dummy_app/db/migrate/20110329183136_remove_league_id_from_teams.rb +9 -0
  305. data/spec/dummy_app/db/migrate/20110607152842_add_format_to_field_test.rb +9 -0
  306. data/spec/dummy_app/db/migrate/20110714095433_create_balls.rb +12 -0
  307. data/spec/dummy_app/db/migrate/20110831090841_add_protected_field_and_restricted_field_to_field_tests.rb +6 -0
  308. data/spec/dummy_app/db/migrate/20110901131551_change_division_primary_key.rb +19 -0
  309. data/spec/dummy_app/db/migrate/20110901142530_rename_league_id_foreign_key_on_divisions.rb +5 -0
  310. data/spec/dummy_app/db/migrate/20110901150912_set_primary_key_not_null_for_divisions.rb +21 -0
  311. data/spec/dummy_app/db/migrate/20110901154834_change_length_for_rails_admin_histories.rb +9 -0
  312. data/spec/dummy_app/db/migrate/20111103174459_create_unscoped_pages.rb +9 -0
  313. data/spec/dummy_app/db/migrate/20111108143642_add_dragonfly_and_carrierwave_to_field_tests.rb +7 -0
  314. data/spec/dummy_app/db/seeds.rb +18 -0
  315. data/spec/dummy_app/doc/README_FOR_APP +2 -0
  316. data/spec/dummy_app/public/404.html +0 -0
  317. data/spec/dummy_app/public/favicon.ico +0 -0
  318. data/spec/dummy_app/script/rails +6 -0
  319. data/spec/factories.rb +62 -0
  320. data/spec/generator_helpers.rb +30 -0
  321. data/spec/generators/install_generator_spec.rb +85 -0
  322. data/spec/generators/uninstall_generator_spec.rb +35 -0
  323. data/spec/lib/abstract_object_spec.rb +119 -0
  324. data/spec/lib/rails_admin_spec.rb +153 -0
  325. data/spec/requests/authorization/cancan_spec.rb +260 -0
  326. data/spec/requests/basic/bulk_action/rails_admin_basic_bulk_action_spec.rb +25 -0
  327. data/spec/requests/basic/bulk_destroy/rails_admin_basic_bulk_destroy_spec.rb +55 -0
  328. data/spec/requests/basic/create/rails_admin_basic_create_spec.rb +143 -0
  329. data/spec/requests/basic/create/rails_admin_namespaced_model_create_spec.rb +24 -0
  330. data/spec/requests/basic/delete/rails_admin_basic_delete_spec.rb +35 -0
  331. data/spec/requests/basic/destroy/rails_admin_basic_destroy_spec.rb +56 -0
  332. data/spec/requests/basic/edit/rails_admin_basic_edit_spec.rb +98 -0
  333. data/spec/requests/basic/export/rails_admin_basic_export_spec.rb +84 -0
  334. data/spec/requests/basic/list/rails_admin_basic_list_spec.rb +401 -0
  335. data/spec/requests/basic/new/rails_admin_basic_new_spec.rb +74 -0
  336. data/spec/requests/basic/new/rails_admin_namespaced_model_new_spec.rb +31 -0
  337. data/spec/requests/basic/show/rails_admin_basic_show_spec.rb +83 -0
  338. data/spec/requests/basic/update/rails_admin_basic_update_spec.rb +169 -0
  339. data/spec/requests/config/edit/rails_admin_config_edit_spec.rb +744 -0
  340. data/spec/requests/config/list/rails_admin_config_list_spec.rb +549 -0
  341. data/spec/requests/config/navigation/rails_admin_config_navigation_spec.rb +107 -0
  342. data/spec/requests/config/rails_admin_config_spec.rb +180 -0
  343. data/spec/requests/config/show/rails_admin_config_show_spec.rb +275 -0
  344. data/spec/requests/history/rails_admin_history_spec.rb +57 -0
  345. data/spec/requests/rails_admin_spec.rb +103 -0
  346. data/spec/requests/relation_spec.rb +26 -0
  347. data/spec/spec_helper.rb +88 -0
  348. metadata +717 -0
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe "RailsAdmin Basic New" do
4
+
5
+ subject { page }
6
+
7
+ describe "GET /admin/player/new" do
8
+ before(:each) do
9
+ visit new_path(:model_name => "player")
10
+ end
11
+
12
+ it "should show \"Create model\"" do
13
+ should have_content("Create player")
14
+ end
15
+
16
+ it "should show required fields as \"Required\"" do
17
+ should have_selector("div", :text => /Name\s*Required/)
18
+ should have_selector("div", :text => /Number\s*Required/)
19
+ end
20
+
21
+ it "should show non-required fields as \"Optional\"" do
22
+ should have_selector("#player_position_field .help-block", :text => "Optional")
23
+ should have_selector("#player_born_on_field .help-block", :text => "Optional")
24
+ should have_selector("#player_notes_field .help-block", :text => "Optional")
25
+ end
26
+
27
+ # https://github.com/sferik/rails_admin/issues/362
28
+ # test that no link uses the "wildcard route" with the main
29
+ # controller and new method
30
+ it "should not use the 'wildcard route'" do
31
+ should have_no_selector("a[href^='/rails_admin/main/new']")
32
+ end
33
+ end
34
+
35
+ describe "GET /admin/player/new with has-one/belongs_to/has_many association" do
36
+ before(:each) do
37
+ FactoryGirl.create :draft
38
+ visit new_path(:model_name => "player")
39
+ end
40
+
41
+ it "should show selects" do
42
+ should have_selector("select#player_draft_id")
43
+ should have_selector("select#player_team_id")
44
+ should have_selector("select#player_comment_ids")
45
+ end
46
+ end
47
+
48
+ describe "GET /admin/player/new with missing label" do
49
+ before(:each) do
50
+ FactoryGirl.create :team, :name => ""
51
+ visit new_path(:model_name => "player")
52
+ end
53
+ end
54
+
55
+ describe "GET /admin/player/new with parameters for pre-population" do
56
+ it "should populate form field when corresponding parameters are passed in" do
57
+ visit new_path(:model_name => 'players', :players => {:name => 'Sam'})
58
+ page.should have_css('input[value=Sam]')
59
+ end
60
+
61
+ it "should prepropulate belongs to relationships" do
62
+ @team = FactoryGirl.create :team, :name => "belongs_to association prepopulated"
63
+ visit new_path(:model_name => 'players', :associations => { :team => @team.id } )
64
+ page.should have_css("select#player_team_id option[selected='selected'][value='#{@team.id}']")
65
+ end
66
+
67
+ it "should prepropulate has_many relationships" do
68
+ @player = FactoryGirl.create :player, :name => "has_many association prepopulated"
69
+ visit new_path(:model_name => 'teams', :associations => { :players => @player.id } )
70
+ page.should have_css("select#team_player_ids option[selected='selected'][value='#{@player.id}']")
71
+ end
72
+ end
73
+
74
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe "RailsAdmin Namespaced Model New" do
4
+
5
+ subject { page }
6
+
7
+ describe "AbstractModel#to_param" do
8
+ it 'turns namespaces into prefixes with ~' do
9
+ RailsAdmin::AbstractModel.new("Cms::BasicPage").to_param.should == 'cms~basic_pages'
10
+ end
11
+ end
12
+
13
+ describe "ApplicationController#to_model_name" do
14
+ it 'turns cms~basic_pages into Cms::BasicPage' do
15
+ RailsAdmin::ApplicationController.new.to_model_name('cms~basic_pages').should == 'Cms::BasicPage'
16
+ end
17
+ end
18
+
19
+ describe "GET /admin/cms_basic_page/new" do
20
+ before(:each) do
21
+ visit new_path(:model_name => "cms~basic_page")
22
+ end
23
+
24
+ it 'should have correct input field names' do
25
+ should have_selector("label[for=cms_basic_page_title]")
26
+ should have_selector("input#cms_basic_page_title[name='cms_basic_page[title]']")
27
+ should have_selector("label[for=cms_basic_page_content]")
28
+ should have_selector("textarea#cms_basic_page_content[name='cms_basic_page[content]']")
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,83 @@
1
+ require 'spec_helper'
2
+
3
+ describe "RailsAdmin Basic Show" do
4
+ subject { page }
5
+
6
+ describe "show" do
7
+ before(:each) do
8
+ @player = FactoryGirl.create :player
9
+ visit show_path(:model_name => "player", :id => @player.id)
10
+ end
11
+
12
+ it "should have History, Edit, Delete" do
13
+ should have_selector("a", :text => "History")
14
+ should have_selector("a", :text => "Edit")
15
+ should have_selector("a", :text => "Delete")
16
+ end
17
+
18
+ it "should show 'Details'" do
19
+ should have_content("Details")
20
+ end
21
+
22
+ it "should show attributes" do
23
+ should have_content("Name")
24
+ should have_content(@player.name)
25
+ should have_content("Number")
26
+ should have_content(@player.number)
27
+ end
28
+ end
29
+
30
+ describe "show with belongs_to association" do
31
+ before(:each) do
32
+ @player = FactoryGirl.create :player
33
+ @team = FactoryGirl.create :team
34
+ @player.update_attribute(:team, @team)
35
+ visit show_path(:model_name => "player", :id => @player.id)
36
+ end
37
+
38
+ it "should show associated objects" do
39
+ should have_css("a[href='/admin/teams/#{@team.id}']")
40
+ end
41
+ end
42
+
43
+ describe "show with has-one association" do
44
+ before(:each) do
45
+ @player = FactoryGirl.create :player
46
+ @draft = FactoryGirl.create :draft, :player => @player
47
+ visit show_path(:model_name => "player", :id => @player.id)
48
+ end
49
+
50
+ it "should show associated objects" do
51
+ should have_css("a[href='/admin/drafts/#{@draft.id}']")
52
+ end
53
+ end
54
+
55
+ describe "show with has-and-belongs-to-many association" do
56
+ before(:each) do
57
+ @player = FactoryGirl.create :player
58
+ @comment1 = FactoryGirl.create :comment, :commentable => @player
59
+ @comment2 = FactoryGirl.create :comment, :commentable => @player
60
+ @comment3 = FactoryGirl.create :comment, :commentable => FactoryGirl.create(:player)
61
+
62
+ visit show_path(:model_name => "player", :id => @player.id)
63
+ end
64
+
65
+ it "should show associated objects" do
66
+ should have_css("a[href='/admin/comments/#{@comment1.id}']")
67
+ should have_css("a[href='/admin/comments/#{@comment2.id}']")
68
+ should_not have_css("a[href='/admin/comments/#{@comment3.id}']")
69
+ end
70
+ end
71
+
72
+ describe "show for polymorphic objects" do
73
+ before(:each) do
74
+ @player = FactoryGirl.create :player
75
+ @comment = FactoryGirl.create :comment, :commentable => @player
76
+ visit show_path(:model_name => "comment", :id => @comment.id)
77
+ end
78
+
79
+ it "should show associated object" do
80
+ should have_css("a[href='/admin/players/#{@player.id}']")
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,169 @@
1
+ require 'spec_helper'
2
+
3
+ describe "RailsAdmin Basic Update" do
4
+
5
+ subject { page }
6
+
7
+ describe "update with errors" 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 return to edit page" do
14
+ fill_in "player[name]", :with => ""
15
+ click_button "Save"
16
+ page.driver.status_code.should eql(406)
17
+ should have_selector "form", :action => "/admin/players/#{@player.id}"
18
+ end
19
+ end
20
+
21
+ describe "update and add another" do
22
+ before(:each) do
23
+ @player = FactoryGirl.create :player
24
+
25
+ visit edit_path(:model_name => "player", :id => @player.id)
26
+
27
+ fill_in "player[name]", :with => "Jackie Robinson"
28
+ fill_in "player[number]", :with => "42"
29
+ fill_in "player[position]", :with => "Second baseman"
30
+ click_button "Save"
31
+
32
+ @player = RailsAdmin::AbstractModel.new("Player").first
33
+ end
34
+
35
+ it "should update an object with correct attributes" do
36
+ @player.name.should eql("Jackie Robinson")
37
+ @player.number.should eql(42)
38
+ @player.position.should eql("Second baseman")
39
+ end
40
+ end
41
+
42
+ describe "update and edit" do
43
+ before(:each) do
44
+ @player = FactoryGirl.create :player
45
+
46
+ visit edit_path(:model_name => "player", :id => @player.id)
47
+
48
+ fill_in "player[name]", :with => "Jackie Robinson"
49
+ fill_in "player[number]", :with => "42"
50
+ fill_in "player[position]", :with => "Second baseman"
51
+ click_button "Save and edit"
52
+
53
+ @player.reload
54
+ end
55
+
56
+ it "should update an object with correct attributes" do
57
+ @player.name.should eql("Jackie Robinson")
58
+ @player.number.should eql(42)
59
+ @player.position.should eql("Second baseman")
60
+ end
61
+ end
62
+
63
+ describe "update with has-one association" do
64
+ before(:each) do
65
+ @player = FactoryGirl.create :player
66
+ @draft = FactoryGirl.create :draft
67
+ page.driver.put update_path(:model_name => "player", :id => @player.id, :player => {:name => "Jackie Robinson", :draft_id => @draft.id, :number => 42, :position => "Second baseman"})
68
+ @player.reload
69
+ end
70
+
71
+ it "should update an object with correct attributes" do
72
+ @player.name.should eql("Jackie Robinson")
73
+ @player.number.should eql(42)
74
+ @player.position.should eql("Second baseman")
75
+ end
76
+
77
+ it "should update an object with correct associations" do
78
+ @draft.reload
79
+ @player.draft.should eql(@draft)
80
+ end
81
+ end
82
+
83
+ describe "update with has-many association" do
84
+ it "should be fillable and emptyable" do
85
+ @league = FactoryGirl.create :league
86
+ @divisions = 3.times.map { Division.create!(:name => "div #{Time.now.to_f}", :league => League.create!(:name => "league #{Time.now.to_f}")) }
87
+
88
+ page.driver.put update_path(:model_name => "league", :id => @league.id, :league => {:name => "National League", :division_ids => [@divisions[0].id] })
89
+
90
+ @league.reload
91
+ @league.name.should eql("National League")
92
+ @divisions[0].reload
93
+ @league.divisions.should include(@divisions[0])
94
+ @league.divisions.should_not include(@divisions[1])
95
+ @league.divisions.should_not include(@divisions[2])
96
+ RailsAdmin::History.where(:item => @league.id).collect(&:message).should include("Added Divisions ##{@divisions[0].id} associations, Changed name")
97
+
98
+ page.driver.put update_path(:model_name => "league", :id => @league.id, :league => {:division_ids => [""]})
99
+
100
+ @league.reload
101
+ @league.divisions.should be_empty
102
+ RailsAdmin::History.where(:item => @league.id).collect(&:message).should include("Removed Divisions ##{@divisions[0].id} associations")
103
+ end
104
+ end
105
+
106
+ describe "update with missing object" do
107
+ before(:each) do
108
+ page.driver.put(update_path(:model_name => "player", :id => 1), :params => {:player => {:name => "Jackie Robinson", :number => 42, :position => "Second baseman"}})
109
+ end
110
+
111
+ it "should raise NotFound" do
112
+ page.driver.status_code.should eql(404)
113
+ end
114
+ end
115
+
116
+ describe "update with invalid object" do
117
+ before(:each) do
118
+ @player = FactoryGirl.create :player
119
+
120
+ visit edit_path(:model_name => "player", :id => @player.id)
121
+
122
+ fill_in "player[name]", :with => "Jackie Robinson"
123
+ fill_in "player[number]", :with => "a"
124
+ fill_in "player[position]", :with => "Second baseman"
125
+ click_button "Save"
126
+
127
+ @player.reload
128
+ end
129
+
130
+ it "should show an error message" do
131
+ body.should have_content("Player failed to be updated")
132
+ end
133
+ end
134
+
135
+ describe "update with serialized objects" do
136
+ before(:each) do
137
+ @user = FactoryGirl.create :user
138
+
139
+ visit edit_path(:model_name => "user", :id => @user.id)
140
+
141
+ fill_in "user[roles]", :with => %{['admin', 'user']}
142
+ click_button "Save"
143
+
144
+ @user.reload
145
+ end
146
+
147
+ it "should save the serialized data" do
148
+ @user.roles.should eql(['admin','user'])
149
+ end
150
+ end
151
+
152
+ describe "update with overridden to_param" do
153
+ before(:each) do
154
+ @ball = FactoryGirl.create :ball
155
+
156
+ visit edit_path(:model_name => "ball", :id => @ball.id)
157
+
158
+ fill_in "ball[color]", :with => "gray"
159
+ click_button "Save and edit"
160
+
161
+ @ball.reload
162
+ end
163
+
164
+ it "should update an object with correct attributes" do
165
+ @ball.color.should eql("gray")
166
+ end
167
+ end
168
+
169
+ end
@@ -0,0 +1,744 @@
1
+ require 'spec_helper'
2
+
3
+ describe "RailsAdmin Config DSL Edit Section" do
4
+
5
+ subject { page }
6
+
7
+ describe "attr_accessible" do
8
+
9
+
10
+ it "should be configurable in the controller scope" do
11
+
12
+ RailsAdmin.config do |config|
13
+ config.excluded_models = []
14
+ config.attr_accessible_role do
15
+ _current_user.attr_accessible_role # sould be :custom_role
16
+ end
17
+
18
+ config.model FieldTest do
19
+ edit do
20
+ field :string_field
21
+ field :restricted_field
22
+ field :protected_field
23
+ end
24
+ end
25
+ end
26
+
27
+ visit new_path(:model_name => "field_test")
28
+ fill_in "field_test[string_field]", :with => "No problem here"
29
+ fill_in "field_test[restricted_field]", :with => "I'm allowed to do that as :custom_role only"
30
+ should have_no_selector "field_test[protected_field]"
31
+ click_button "Save"
32
+ @field_test = FieldTest.first
33
+ @field_test.string_field.should == "No problem here"
34
+ @field_test.restricted_field.should == "I'm allowed to do that as :custom_role only"
35
+ end
36
+ end
37
+
38
+ describe "field groupings" do
39
+
40
+ it "should be hideable" do
41
+ RailsAdmin.config Team do
42
+ edit do
43
+ group :default do
44
+ label "Hidden group"
45
+ hide
46
+ end
47
+ end
48
+ end
49
+ visit new_path(:model_name => "team")
50
+ # Should not have the group header
51
+ should have_no_selector("legend", :text => "Hidden Group")
52
+ # Should not have any of the group's fields either
53
+ should have_no_selector("select#team_division")
54
+ should have_no_selector("input#team_name")
55
+ should have_no_selector("input#team_logo_url")
56
+ should have_no_selector("input#team_manager")
57
+ should have_no_selector("input#team_ballpark")
58
+ should have_no_selector("input#team_mascot")
59
+ should have_no_selector("input#team_founded")
60
+ should have_no_selector("input#team_wins")
61
+ should have_no_selector("input#team_losses")
62
+ should have_no_selector("input#team_win_percentage")
63
+ should have_no_selector("input#team_revenue")
64
+ end
65
+
66
+ it "should hide association groupings by the name of the association" do
67
+ RailsAdmin.config Team do
68
+ edit do
69
+ group :players do
70
+ hide
71
+ end
72
+ end
73
+ end
74
+ visit new_path(:model_name => "team")
75
+ # Should not have the group header
76
+ should have_no_selector("legend", :text => "Players")
77
+ # Should not have any of the group's fields either
78
+ should have_no_selector("select#team_player_ids")
79
+ end
80
+
81
+ it "should be renameable" do
82
+ RailsAdmin.config Team do
83
+ edit do
84
+ group :default do
85
+ label "Renamed group"
86
+ end
87
+ end
88
+ end
89
+ visit new_path(:model_name => "team")
90
+ should have_selector("legend", :text => "Renamed group")
91
+ end
92
+
93
+ describe "help" do
94
+
95
+ it "should show help section if present" do
96
+ RailsAdmin.config Team do
97
+ edit do
98
+ group :default do
99
+ help "help paragraph to display"
100
+ end
101
+ end
102
+ end
103
+ visit new_path(:model_name => "team")
104
+ should have_selector('legend small', :text => "help paragraph to display")
105
+ end
106
+
107
+ it "should not show help if not present" do
108
+ RailsAdmin.config Team do
109
+ edit do
110
+ group :default do
111
+ label 'no help'
112
+ end
113
+ end
114
+ end
115
+ visit new_path(:model_name => "team")
116
+ should_not have_selector('legend small')
117
+ end
118
+
119
+ it "should be able to display multiple help if there are multiple sections" do
120
+ RailsAdmin.config Team do
121
+ edit do
122
+ group :default do
123
+ field :name
124
+ help 'help for default'
125
+ end
126
+ group :other_section do
127
+ label "Other Section"
128
+ field :division
129
+ help 'help for other section'
130
+ end
131
+ end
132
+ end
133
+ visit new_path(:model_name => "team")
134
+ should have_selector("legend small", :text => 'help for default')
135
+ should have_selector("legend small", :text => 'help for other section')
136
+ should have_selector("legend small", :count => 2)
137
+ end
138
+ end
139
+
140
+ it "should have accessor for its fields" do
141
+ RailsAdmin.config Team do
142
+ edit do
143
+ group :default do
144
+ field :name
145
+ field :logo_url
146
+ end
147
+ group :belongs_to_associations do
148
+ label "Belong's to associations"
149
+ field :division
150
+ end
151
+ end
152
+ end
153
+ visit new_path(:model_name => "team")
154
+ should have_selector("legend", :text => "Basic info")
155
+ should have_selector("legend", :text => "Belong's to associations")
156
+ should have_selector("label", :text => "Name")
157
+ should have_selector("label", :text => "Logo url")
158
+ should have_selector("label", :text => "Division")
159
+ should have_selector(".field", :count => 3)
160
+ end
161
+
162
+ it "should have accessor for its fields by type" do
163
+ RailsAdmin.config Team do
164
+ edit do
165
+ group :default do
166
+ field :name
167
+ field :logo_url
168
+ end
169
+ group :other do
170
+ field :division_id
171
+ field :manager
172
+ field :ballpark
173
+ fields_of_type :string do
174
+ label { "#{label} (STRING)" }
175
+ end
176
+ end
177
+ end
178
+ end
179
+ visit new_path(:model_name => "team")
180
+ should have_selector("label", :text => "Name")
181
+ should have_selector("label", :text => "Logo url")
182
+ should have_selector("label", :text => "Division")
183
+ should have_selector("label", :text => "Manager (STRING)")
184
+ should have_selector("label", :text => "Ballpark (STRING)")
185
+ end
186
+ end
187
+
188
+ describe "items' fields" do
189
+
190
+ it "should show all by default" do
191
+ visit new_path(:model_name => "team")
192
+ should have_selector("select#team_division_id")
193
+ should have_selector("input#team_name")
194
+ should have_selector("input#team_logo_url")
195
+ should have_selector("input#team_manager")
196
+ should have_selector("input#team_ballpark")
197
+ should have_selector("input#team_mascot")
198
+ should have_selector("input#team_founded")
199
+ should have_selector("input#team_wins")
200
+ should have_selector("input#team_losses")
201
+ should have_selector("input#team_win_percentage")
202
+ should have_selector("input#team_revenue")
203
+ should have_selector("select#team_player_ids")
204
+ should have_selector("select#team_fan_ids")
205
+ end
206
+
207
+ it "should appear in order defined" do
208
+ RailsAdmin.config Team do
209
+ edit do
210
+ field :manager
211
+ field :division
212
+ field :name
213
+ end
214
+ end
215
+ visit new_path(:model_name => "team")
216
+ should have_selector(:xpath, "//*[contains(@class, 'field')][1]//*[@id='team_manager']")
217
+ should have_selector(:xpath, "//*[contains(@class, 'field')][2]//*[@id='team_division_id']")
218
+ should have_selector(:xpath, "//*[contains(@class, 'field')][3]//*[@id='team_name']")
219
+ end
220
+
221
+ it "should only show the defined fields if some fields are defined" do
222
+ RailsAdmin.config Team do
223
+ edit do
224
+ field :division
225
+ field :name
226
+ end
227
+ end
228
+ visit new_path(:model_name => "team")
229
+ should have_selector("label", :text => "Division")
230
+ should have_selector("label", :text => "Name")
231
+ should have_selector(".field", :count => 2)
232
+ end
233
+
234
+ it "should delegates the label option to the ActiveModel API" do
235
+ RailsAdmin.config Team do
236
+ edit do
237
+ field :manager
238
+ field :fans
239
+ end
240
+ end
241
+ visit new_path(:model_name => "team")
242
+ should have_selector("label", :text => "Team Manager")
243
+ should have_selector("label", :text => "Some Fans")
244
+ end
245
+
246
+ it "should be renameable" do
247
+ RailsAdmin.config Team do
248
+ edit do
249
+ field :manager do
250
+ label "Renamed field"
251
+ end
252
+ field :division
253
+ field :name
254
+ end
255
+ end
256
+ visit new_path(:model_name => "team")
257
+ should have_selector("label", :text => "Renamed field")
258
+ should have_selector("label", :text => "Division")
259
+ should have_selector("label", :text => "Name")
260
+ end
261
+
262
+ it "should be renameable by type" do
263
+ RailsAdmin.config Team do
264
+ edit do
265
+ fields_of_type :string do
266
+ label { "#{label} (STRING)" }
267
+ end
268
+ end
269
+ end
270
+ visit new_path(:model_name => "team")
271
+ should have_selector("label", :text => "Division")
272
+ should have_selector("label", :text => "Name (STRING)")
273
+ should have_selector("label", :text => "Logo url (STRING)")
274
+ should have_selector("label", :text => "Manager (STRING)")
275
+ should have_selector("label", :text => "Ballpark (STRING)")
276
+ should have_selector("label", :text => "Mascot (STRING)")
277
+ should have_selector("label", :text => "Founded")
278
+ should have_selector("label", :text => "Wins")
279
+ should have_selector("label", :text => "Losses")
280
+ should have_selector("label", :text => "Win percentage")
281
+ should have_selector("label", :text => "Revenue")
282
+ should have_selector("label", :text => "Players")
283
+ should have_selector("label", :text => "Fans")
284
+ end
285
+
286
+ it "should be globally renameable by type" do
287
+ RailsAdmin::Config.models do
288
+ edit do
289
+ fields_of_type :string do
290
+ label { "#{label} (STRING)" }
291
+ end
292
+ end
293
+ end
294
+ visit new_path(:model_name => "team")
295
+ should have_selector("label", :text => "Division")
296
+ should have_selector("label", :text => "Name (STRING)")
297
+ should have_selector("label", :text => "Logo url (STRING)")
298
+ should have_selector("label", :text => "Manager (STRING)")
299
+ should have_selector("label", :text => "Ballpark (STRING)")
300
+ should have_selector("label", :text => "Mascot (STRING)")
301
+ should have_selector("label", :text => "Founded")
302
+ should have_selector("label", :text => "Wins")
303
+ should have_selector("label", :text => "Losses")
304
+ should have_selector("label", :text => "Win percentage")
305
+ should have_selector("label", :text => "Revenue")
306
+ should have_selector("label", :text => "Players")
307
+ should have_selector("label", :text => "Fans")
308
+ end
309
+
310
+ it "should be flaggable as read only and be configurable with formatted_value" do
311
+ RailsAdmin.config Team do
312
+ edit do
313
+ field :name do
314
+ read_only true
315
+ formatted_value do
316
+ "I'm outputed in the form"
317
+ end
318
+ end
319
+ end
320
+ end
321
+ visit new_path(:model_name => "team")
322
+ should have_content("I'm outputed in the form")
323
+ end
324
+
325
+ it "should be hideable" do
326
+ RailsAdmin.config Team do
327
+ edit do
328
+ field :manager do
329
+ hide
330
+ end
331
+ field :division
332
+ field :name
333
+ end
334
+ end
335
+ visit new_path(:model_name => "team")
336
+ should have_no_selector("#team_manager")
337
+ should have_selector("#team_division_id")
338
+ should have_selector("#team_name")
339
+ end
340
+
341
+ it "should be hideable by type" do
342
+ RailsAdmin.config Team do
343
+ edit do
344
+ fields_of_type :string do
345
+ hide
346
+ end
347
+ end
348
+ end
349
+ visit new_path(:model_name => "team")
350
+ should have_selector("label", :text => "Division")
351
+ should have_no_selector("label", :text => "Name")
352
+ should have_no_selector("label", :text => "Logo url")
353
+ should have_no_selector("label", :text => "Manager")
354
+ should have_no_selector("label", :text => "Ballpark")
355
+ should have_no_selector("label", :text => "Mascot")
356
+ should have_selector("label", :text => "Founded")
357
+ should have_selector("label", :text => "Wins")
358
+ should have_selector("label", :text => "Losses")
359
+ should have_selector("label", :text => "Win percentage")
360
+ should have_selector("label", :text => "Revenue")
361
+ should have_selector("label", :text => "Players")
362
+ should have_selector("label", :text => "Fans")
363
+ end
364
+
365
+ it "should be globally hideable by type" do
366
+ RailsAdmin::Config.models do
367
+ edit do
368
+ fields_of_type :string do
369
+ hide
370
+ end
371
+ end
372
+ end
373
+ visit new_path(:model_name => "team")
374
+ should have_selector("label", :text => "Division")
375
+ should have_no_selector("label", :text => "Name")
376
+ should have_no_selector("label", :text => "Logo url")
377
+ should have_no_selector("label", :text => "Manager")
378
+ should have_no_selector("label", :text => "Ballpark")
379
+ should have_no_selector("label", :text => "Mascot")
380
+ should have_selector("label", :text => "Founded")
381
+ should have_selector("label", :text => "Wins")
382
+ should have_selector("label", :text => "Losses")
383
+ should have_selector("label", :text => "Win percentage")
384
+ should have_selector("label", :text => "Revenue")
385
+ should have_selector("label", :text => "Players")
386
+ should have_selector("label", :text => "Fans")
387
+ end
388
+
389
+ it "should have option to customize the help text" do
390
+ RailsAdmin.config Team do
391
+ edit do
392
+ field :manager do
393
+ help "#{help} Additional help text for manager field."
394
+ end
395
+ field :division
396
+ field :name
397
+ end
398
+ end
399
+ visit new_path(:model_name => "team")
400
+ find("#team_manager_field .help-block").should have_content("Required. 100 characters or fewer. Additional help text for manager field.")
401
+ find("#team_division_id_field .help-block").should have_content("Required")
402
+ find("#team_name_field .help-block").should have_content("Optional. 50 characters or fewer.")
403
+ end
404
+
405
+ it "should have option to override required status" do
406
+ RailsAdmin.config Team do
407
+ edit do
408
+ field :manager do
409
+ optional true
410
+ end
411
+ field :division do
412
+ optional true
413
+ end
414
+ field :name do
415
+ required true
416
+ end
417
+ end
418
+ end
419
+ visit new_path(:model_name => "team")
420
+ find("#team_manager_field .help-block").should have_content("Optional. 100 characters or fewer.")
421
+ find("#team_division_id_field .help-block").should have_content("Optional")
422
+ find("#team_name_field .help-block").should have_content("Required. 50 characters or fewer.")
423
+ end
424
+ end
425
+
426
+ describe "input format of" do
427
+
428
+ before(:each) do
429
+ RailsAdmin::Config.excluded_models = [RelTest]
430
+ @time = ::Time.now.getutc
431
+ end
432
+
433
+ describe "a datetime field" do
434
+
435
+ it "should default to %B %d, %Y %H:%M" do
436
+ visit new_path(:model_name => "field_test")
437
+ fill_in "field_test[datetime_field]", :with => @time.strftime("%B %d, %Y %H:%M")
438
+ click_button "Save"
439
+ @record = RailsAdmin::AbstractModel.new("FieldTest").first
440
+ @record.datetime_field.strftime("%Y-%m-%d %H:%M").should eql(@time.strftime("%Y-%m-%d %H:%M"))
441
+ end
442
+
443
+ it "should have a simple customization option" do
444
+ RailsAdmin.config FieldTest do
445
+ edit do
446
+ field :datetime_field do
447
+ date_format :default
448
+ end
449
+ end
450
+ end
451
+ visit new_path(:model_name => "field_test")
452
+ fill_in "field_test[datetime_field]", :with => @time.strftime("%a, %d %b %Y %H:%M:%S")
453
+ click_button "Save"
454
+ @record = RailsAdmin::AbstractModel.new("FieldTest").first
455
+ @record.datetime_field.should eql(::DateTime.parse(@time.to_s))
456
+ end
457
+
458
+ it "should have a customization option" do
459
+ RailsAdmin.config FieldTest do
460
+ list do
461
+ field :datetime_field do
462
+ strftime_format "%Y-%m-%d %H:%M:%S"
463
+ end
464
+ end
465
+ end
466
+ visit new_path(:model_name => "field_test")
467
+ fill_in "field_test[datetime_field]", :with => @time.strftime("%Y-%m-%d %H:%M:%S")
468
+ click_button "Save"
469
+ @record = RailsAdmin::AbstractModel.new("FieldTest").first
470
+ @record.datetime_field.should eql(::DateTime.parse(@time.to_s))
471
+ end
472
+ end
473
+
474
+ describe "a timestamp field" do
475
+
476
+ it "should default to %B %d, %Y %H:%M" do
477
+ visit new_path(:model_name => "field_test")
478
+ fill_in "field_test[timestamp_field]", :with => @time.strftime("%B %d, %Y %H:%M")
479
+ click_button "Save"
480
+ @record = RailsAdmin::AbstractModel.new("FieldTest").first
481
+ @record.timestamp_field.strftime("%Y-%m-%d %H:%M").should eql(@time.strftime("%Y-%m-%d %H:%M"))
482
+ end
483
+
484
+ it "should have a simple customization option" do
485
+ RailsAdmin.config FieldTest do
486
+ edit do
487
+ field :timestamp_field do
488
+ date_format :default
489
+ end
490
+ end
491
+ end
492
+ visit new_path(:model_name => "field_test")
493
+ fill_in "field_test[timestamp_field]", :with => @time.strftime("%a, %d %b %Y %H:%M:%S")
494
+ click_button "Save"
495
+ @record = RailsAdmin::AbstractModel.new("FieldTest").first
496
+ @record.timestamp_field.should eql(::DateTime.parse(@time.to_s))
497
+ end
498
+
499
+ it "should have a customization option" do
500
+ RailsAdmin.config FieldTest do
501
+ edit do
502
+ field :timestamp_field do
503
+ strftime_format "%Y-%m-%d %H:%M:%S"
504
+ end
505
+ end
506
+ end
507
+ visit new_path(:model_name => "field_test")
508
+ fill_in "field_test[timestamp_field]", :with => @time.strftime("%Y-%m-%d %H:%M:%S")
509
+ click_button "Save"
510
+ @record = RailsAdmin::AbstractModel.new("FieldTest").first
511
+ @record.timestamp_field.should eql(::DateTime.parse(@time.to_s))
512
+ end
513
+ end
514
+
515
+ describe " a field with 'format' as a name (Kernel function)" do
516
+
517
+ it "should be updatable without any error" do
518
+ RailsAdmin.config FieldTest do
519
+ edit do
520
+ field :format
521
+ end
522
+ end
523
+ visit new_path(:model_name => "field_test")
524
+ fill_in "field_test[format]", :with => "test for format"
525
+ click_button "Save"
526
+ @record = RailsAdmin::AbstractModel.new("FieldTest").first
527
+ @record.format.should eql("test for format")
528
+ end
529
+ end
530
+
531
+
532
+ describe "a time field" do
533
+
534
+ it "should default to %H:%M" do
535
+ visit new_path(:model_name => "field_test")
536
+ fill_in "field_test[time_field]", :with => @time.strftime("%H:%M")
537
+ click_button "Save"
538
+ @record = RailsAdmin::AbstractModel.new("FieldTest").first
539
+ @record.time_field.strftime("%H:%M").should eql(@time.strftime("%H:%M"))
540
+ end
541
+
542
+ it "should have a customization option" do
543
+ RailsAdmin.config FieldTest do
544
+ edit do
545
+ field :time_field do
546
+ strftime_format "%I:%M %p"
547
+ end
548
+ end
549
+ end
550
+ visit new_path(:model_name => "field_test")
551
+ fill_in "field_test[time_field]", :with => @time.strftime("%I:%M %p")
552
+ click_button "Save"
553
+ @record = RailsAdmin::AbstractModel.new("FieldTest").first
554
+ @record.time_field.strftime("%H:%M").should eql(@time.strftime("%H:%M"))
555
+ end
556
+ end
557
+
558
+ describe "a date field" do
559
+
560
+ it "should default to %B %d, %Y" do
561
+ visit new_path(:model_name => "field_test")
562
+ fill_in "field_test[date_field]", :with => @time.strftime("%B %d, %Y")
563
+ click_button "Save"
564
+ @record = RailsAdmin::AbstractModel.new("FieldTest").first
565
+ @record.date_field.should eql(::Date.parse(@time.to_s))
566
+ end
567
+
568
+ it "should cover a timezone lag even if in UTC+n:00 timezone." do
569
+ Time.zone = 'Tokyo' # +09:00
570
+
571
+ visit new_path(:model_name => "field_test")
572
+ fill_in "field_test[date_field]", :with => @time.strftime("%B %d, %Y")
573
+ click_button "Save"
574
+ @record = RailsAdmin::AbstractModel.new("FieldTest").first
575
+ @record.date_field.should eql(::Date.parse(@time.to_s))
576
+ end
577
+
578
+ it "should have a simple customization option" do
579
+ RailsAdmin.config FieldTest do
580
+ edit do
581
+ field :date_field do
582
+ date_format :default
583
+ end
584
+ end
585
+ end
586
+ visit new_path(:model_name => "field_test")
587
+ fill_in "field_test[date_field]", :with => @time.strftime("%Y-%m-%d")
588
+ click_button "Save"
589
+ @record = RailsAdmin::AbstractModel.new("FieldTest").first
590
+ @record.date_field.should eql(::Date.parse(@time.to_s))
591
+ end
592
+
593
+ it "should have a customization option" do
594
+ RailsAdmin.config FieldTest do
595
+ edit do
596
+ field :date_field do
597
+ strftime_format "%Y-%m-%d"
598
+ end
599
+ end
600
+ end
601
+ visit new_path(:model_name => "field_test")
602
+ fill_in "field_test[date_field]", :with => @time.strftime("%Y-%m-%d")
603
+ click_button "Save"
604
+ @record = RailsAdmin::AbstractModel.new("FieldTest").first
605
+ @record.date_field.should eql(::Date.parse(@time.to_s))
606
+ end
607
+ end
608
+ end
609
+
610
+ describe "fields which are nullable and have AR validations" do
611
+
612
+ it "should be required" do
613
+ # draft.notes is nullable and has no validation
614
+ field = RailsAdmin::config("Draft").edit.fields.find{|f| f.name == :notes}
615
+ field.properties[:nullable?].should be true
616
+ field.required?.should be false
617
+
618
+ # draft.date is nullable in the schema but has an AR
619
+ # validates_presence_of validation that makes it required
620
+ field = RailsAdmin::config("Draft").edit.fields.find{|f| f.name == :date}
621
+ field.properties[:nullable?].should be true
622
+ field.required?.should be true
623
+
624
+ # draft.round is nullable in the schema but has an AR
625
+ # validates_numericality_of validation that makes it required
626
+ field = RailsAdmin::config("Draft").edit.fields.find{|f| f.name == :round}
627
+ field.properties[:nullable?].should be true
628
+ field.required?.should be true
629
+
630
+ # team.revenue is nullable in the schema but has an AR
631
+ # validates_numericality_of validation that allows nil
632
+ field = RailsAdmin::config("Team").edit.fields.find{|f| f.name == :revenue}
633
+ field.properties[:nullable?].should be true
634
+ field.required?.should be false
635
+ end
636
+ end
637
+
638
+ describe "CKEditor Support" do
639
+
640
+ it "should start with CKEditor disabled" do
641
+ field = RailsAdmin::config("Draft").edit.fields.find{|f| f.name == :notes}
642
+ field.ckeditor.should be false
643
+ end
644
+
645
+ it "should add Javascript to enable CKEditor" do
646
+ RailsAdmin.config Draft do
647
+ edit do
648
+ field :notes do
649
+ ckeditor true
650
+ end
651
+ end
652
+ end
653
+ visit new_path(:model_name => "draft")
654
+ should have_selector("script", :text => /CKEDITOR\.replace.*?draft_notes/)
655
+ end
656
+ end
657
+
658
+ describe "Paperclip Support" do
659
+
660
+ it "should show a file upload field" do
661
+ RailsAdmin.config User do
662
+ edit do
663
+ field :avatar
664
+ end
665
+ end
666
+ visit new_path(:model_name => "user")
667
+ should have_selector("input#user_avatar")
668
+ end
669
+ end
670
+
671
+ describe "Enum field support" do
672
+ it "should auto-detect enumeration when object responds to '\#{method}_enum'" do
673
+ class Team
674
+ def color_enum
675
+ ["blue", "green", "red"]
676
+ end
677
+ end
678
+ RailsAdmin.config Team do
679
+ edit do
680
+ field :color
681
+ end
682
+ end
683
+ visit new_path(:model_name => "team")
684
+ should have_selector("select.enum")
685
+ should have_content("green")
686
+ Team.send(:remove_method, :color_enum) # Reset
687
+ end
688
+
689
+ it "should allow configuration of the enum method" do
690
+ class Team
691
+ def color_list
692
+ ["blue", "green", "red"]
693
+ end
694
+ end
695
+ RailsAdmin.config Team do
696
+ edit do
697
+ field :color, :enum do
698
+ enum_method :color_list
699
+ end
700
+ end
701
+ end
702
+ visit new_path(:model_name => "team")
703
+ should have_selector("select.enum")
704
+ should have_content("green")
705
+ Team.send(:remove_method, :color_list) # Reset
706
+ end
707
+
708
+ it "should allow direct listing of enumeration options and override enum method" do
709
+ class Team
710
+ def color_list
711
+ ["blue", "green", "red"]
712
+ end
713
+ end
714
+ RailsAdmin.config Team do
715
+ edit do
716
+ field :color, :enum do
717
+ enum_method :color_list
718
+ enum do
719
+ ["yellow", "black"]
720
+ end
721
+ end
722
+ end
723
+ end
724
+ visit new_path(:model_name => "team")
725
+ should have_selector("select.enum")
726
+ should have_no_content("green")
727
+ should have_content("yellow")
728
+ Team.send(:remove_method, :color_list) # Reset
729
+ end
730
+
731
+ end
732
+
733
+ describe "ColorPicker Support" do
734
+ it "should show input with class color" do
735
+ RailsAdmin.config Team do
736
+ edit do
737
+ field :color, :color
738
+ end
739
+ end
740
+ visit new_path(:model_name => "team")
741
+ should have_selector("input.color")
742
+ end
743
+ end
744
+ end