activeadmin 0.4.4 → 0.5.0.pre

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activeadmin might be problematic. Click here for more details.

Files changed (310) hide show
  1. data/.gitignore +3 -0
  2. data/.travis.yml +5 -0
  3. data/CHANGELOG.md +50 -0
  4. data/CONTRIBUTING.md +2 -4
  5. data/Gemfile +10 -4
  6. data/Guardfile +0 -1
  7. data/LICENSE +1 -1
  8. data/README.rdoc +19 -8
  9. data/Rakefile +10 -1
  10. data/activeadmin.gemspec +2 -1
  11. data/app/assets/javascripts/active_admin/application.js +3 -9
  12. data/app/assets/javascripts/active_admin/base.js +1 -0
  13. data/app/assets/javascripts/active_admin/components/jquery.aa.checkbox-toggler.js.coffee +64 -0
  14. data/app/assets/javascripts/active_admin/components/jquery.aa.dropdown-menu.js.coffee +107 -0
  15. data/app/assets/javascripts/active_admin/components/jquery.aa.popover.js.coffee +100 -0
  16. data/app/assets/javascripts/active_admin/components/jquery.aa.table-checkbox-toggler.js.coffee +27 -0
  17. data/app/assets/javascripts/active_admin/lib/namespace.js.coffee +3 -0
  18. data/app/assets/javascripts/active_admin/pages/application.js.coffee +13 -0
  19. data/app/assets/javascripts/active_admin/pages/batch_actions.js.coffee +26 -0
  20. data/app/assets/stylesheets/active_admin/_base.css.scss +32 -26
  21. data/app/assets/stylesheets/active_admin/_forms.css.scss +12 -5
  22. data/app/assets/stylesheets/active_admin/_header.css.scss +1 -2
  23. data/app/assets/stylesheets/active_admin/_typography.css.scss +1 -1
  24. data/app/assets/stylesheets/active_admin/components/_batch_actions.css.scss +11 -0
  25. data/app/assets/stylesheets/active_admin/components/_buttons.scss +1 -2
  26. data/app/assets/stylesheets/active_admin/components/_dropdown_menu.scss +151 -0
  27. data/app/assets/stylesheets/active_admin/components/_flash_messages.css.scss +3 -3
  28. data/app/assets/stylesheets/active_admin/components/_popovers.css.scss +123 -0
  29. data/app/assets/stylesheets/active_admin/components/_status_tags.scss +1 -1
  30. data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +20 -27
  31. data/app/assets/stylesheets/active_admin/components/_tables.css.scss +1 -0
  32. data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +38 -36
  33. data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +5 -5
  34. data/app/assets/stylesheets/active_admin/mixins/_icons.css.scss +7 -3
  35. data/app/assets/stylesheets/active_admin/mixins/_variables.css.scss +19 -17
  36. data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +2 -2
  37. data/app/assets/stylesheets/active_admin/print.css.scss +290 -0
  38. data/app/views/active_admin/dashboard/index.html.arb +1 -1
  39. data/app/views/active_admin/devise/passwords/edit.html.erb +17 -14
  40. data/app/views/active_admin/devise/passwords/new.html.erb +4 -4
  41. data/app/views/active_admin/devise/sessions/new.html.erb +6 -6
  42. data/app/views/active_admin/devise/shared/_links.erb +6 -6
  43. data/app/views/active_admin/page/index.html.arb +1 -1
  44. data/app/views/active_admin/resource/edit.html.arb +1 -1
  45. data/app/views/active_admin/resource/index.csv.erb +1 -1
  46. data/app/views/active_admin/resource/index.html.arb +1 -1
  47. data/app/views/active_admin/resource/new.html.arb +1 -1
  48. data/app/views/active_admin/resource/show.html.arb +1 -1
  49. data/app/views/layouts/active_admin.html.arb +1 -1
  50. data/app/views/layouts/active_admin_logged_out.html.erb +2 -2
  51. data/cucumber.yml +1 -1
  52. data/docs/0-installation.md +10 -1
  53. data/docs/{9-custom-pages.md → 10-custom-pages.md} +0 -0
  54. data/docs/2-resource-customization.md +19 -1
  55. data/docs/3-index-pages.md +31 -0
  56. data/docs/4-csv-format.md +9 -0
  57. data/docs/6-show-screens.md +1 -1
  58. data/docs/9-batch-actions.md +161 -0
  59. data/features/dashboard.feature +31 -8
  60. data/features/development_reloading.feature +1 -1
  61. data/features/edit_page.feature +3 -3
  62. data/features/i18n.feature +35 -0
  63. data/features/index/batch_actions.feature +98 -0
  64. data/features/index/filters.feature +26 -0
  65. data/features/index/format_as_csv.feature +35 -0
  66. data/features/index/index_as_table.feature +30 -2
  67. data/features/index/index_blank_slate.feature +8 -3
  68. data/features/index/index_scopes.feature +130 -24
  69. data/features/index/page_title.feature +12 -0
  70. data/features/new_page.feature +3 -3
  71. data/features/registering_pages.feature +61 -0
  72. data/features/root_to.feature +17 -0
  73. data/features/show/default_content.feature +1 -1
  74. data/features/show/page_title.feature +14 -0
  75. data/features/sidebar_sections.feature +26 -0
  76. data/features/site_title.feature +1 -1
  77. data/features/specifying_actions.feature +7 -6
  78. data/features/step_definitions/action_link_steps.rb +1 -1
  79. data/features/step_definitions/additional_web_steps.rb +7 -1
  80. data/features/step_definitions/batch_action_steps.rb +94 -0
  81. data/features/step_definitions/configuration_steps.rb +30 -8
  82. data/features/step_definitions/factory_steps.rb +12 -0
  83. data/features/step_definitions/format_steps.rb +6 -2
  84. data/features/step_definitions/i18n_steps.rb +3 -0
  85. data/features/step_definitions/table_steps.rb +114 -0
  86. data/features/step_definitions/user_steps.rb +30 -4
  87. data/features/support/env.rb +54 -15
  88. data/features/support/paths.rb +2 -0
  89. data/features/users/logging_in.feature +1 -1
  90. data/features/users/logging_out.feature +2 -1
  91. data/features/users/resetting_password.feature +34 -0
  92. data/lib/active_admin.rb +46 -7
  93. data/lib/active_admin/application.rb +30 -15
  94. data/lib/active_admin/base_controller/menu.rb +3 -3
  95. data/lib/active_admin/batch_actions.rb +17 -0
  96. data/lib/active_admin/batch_actions/controller.rb +25 -0
  97. data/lib/active_admin/batch_actions/resource_extension.rb +126 -0
  98. data/lib/active_admin/batch_actions/views/batch_action_form.rb +35 -0
  99. data/lib/active_admin/batch_actions/views/batch_action_popover.rb +28 -0
  100. data/lib/active_admin/batch_actions/views/batch_action_selector.rb +63 -0
  101. data/lib/active_admin/batch_actions/views/selection_cells.rb +37 -0
  102. data/lib/active_admin/comments.rb +5 -2
  103. data/lib/active_admin/comments/comment.rb +4 -3
  104. data/lib/active_admin/comments/views/active_admin_comments.rb +5 -5
  105. data/lib/active_admin/component.rb +1 -18
  106. data/lib/active_admin/csv_builder.rb +8 -3
  107. data/lib/active_admin/dashboards.rb +21 -4
  108. data/lib/active_admin/dashboards/dashboard_controller.rb +1 -5
  109. data/lib/active_admin/dependency_checker.rb +1 -1
  110. data/lib/active_admin/dsl.rb +61 -4
  111. data/lib/active_admin/engine.rb +1 -1
  112. data/lib/active_admin/filters.rb +8 -0
  113. data/lib/active_admin/filters/dsl.rb +12 -0
  114. data/lib/active_admin/filters/forms.rb +93 -0
  115. data/lib/active_admin/filters/resource_extension.rb +92 -0
  116. data/lib/active_admin/form_builder.rb +88 -33
  117. data/lib/active_admin/helpers/collection.rb +23 -0
  118. data/lib/active_admin/helpers/optional_display.rb +1 -1
  119. data/lib/active_admin/inputs/filter_select_input.rb +1 -1
  120. data/lib/active_admin/locales/bg.yml +37 -1
  121. data/lib/active_admin/locales/ca.yml +36 -0
  122. data/lib/active_admin/locales/cs.yml +36 -0
  123. data/lib/active_admin/locales/da.yml +36 -0
  124. data/lib/active_admin/locales/de.yml +42 -0
  125. data/lib/active_admin/locales/en.yml +27 -2
  126. data/lib/active_admin/locales/es.yml +45 -4
  127. data/lib/active_admin/locales/fr.yml +22 -0
  128. data/lib/active_admin/locales/{he_il.yml → he.yml} +37 -2
  129. data/lib/active_admin/locales/hr.yml +49 -5
  130. data/lib/active_admin/locales/hu.yml +21 -0
  131. data/lib/active_admin/locales/it.yml +36 -1
  132. data/lib/active_admin/locales/ja.yml +36 -0
  133. data/lib/active_admin/locales/ko.yml +36 -1
  134. data/lib/active_admin/locales/lv.yml +28 -2
  135. data/lib/active_admin/locales/nl.yml +42 -1
  136. data/lib/active_admin/locales/no-NB.yml +15 -0
  137. data/lib/active_admin/locales/pl.yml +45 -1
  138. data/lib/active_admin/locales/pt-BR.yml +36 -1
  139. data/lib/active_admin/locales/ro.yml +67 -0
  140. data/lib/active_admin/locales/ru.yml +43 -3
  141. data/lib/active_admin/locales/sv-SE.yml +41 -1
  142. data/lib/active_admin/locales/tr.yml +80 -0
  143. data/lib/active_admin/locales/vi.yml +80 -0
  144. data/lib/active_admin/locales/{zh_cn.yml → zh-CN.yml} +42 -2
  145. data/lib/active_admin/locales/zh-TW.yml +36 -1
  146. data/lib/active_admin/menu.rb +55 -30
  147. data/lib/active_admin/menu_builder.rb +65 -0
  148. data/lib/active_admin/menu_item.rb +55 -14
  149. data/lib/active_admin/namespace.rb +25 -55
  150. data/lib/active_admin/page.rb +15 -10
  151. data/lib/active_admin/resource.rb +9 -0
  152. data/lib/active_admin/resource/action_items.rb +4 -4
  153. data/lib/active_admin/resource/controllers.rb +1 -1
  154. data/lib/active_admin/resource/menu.rb +19 -21
  155. data/lib/active_admin/resource/naming.rb +55 -45
  156. data/lib/active_admin/resource/sidebars.rb +0 -13
  157. data/lib/active_admin/resource_collection.rb +10 -10
  158. data/lib/active_admin/resource_controller.rb +5 -5
  159. data/lib/active_admin/resource_controller/actions.rb +2 -0
  160. data/lib/active_admin/resource_controller/collection.rb +13 -4
  161. data/lib/active_admin/resource_dsl.rb +12 -6
  162. data/lib/active_admin/router.rb +27 -8
  163. data/lib/active_admin/scope.rb +1 -0
  164. data/lib/active_admin/sidebar_section.rb +2 -6
  165. data/lib/active_admin/version.rb +1 -1
  166. data/lib/active_admin/view_factory.rb +18 -13
  167. data/lib/active_admin/view_helpers.rb +0 -2
  168. data/lib/active_admin/view_helpers/auto_link_helper.rb +2 -1
  169. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +24 -25
  170. data/lib/active_admin/view_helpers/display_helper.rb +1 -1
  171. data/lib/active_admin/view_helpers/fields_for.rb +44 -0
  172. data/lib/active_admin/view_helpers/form_helper.rb +6 -0
  173. data/lib/active_admin/view_helpers/view_factory_helper.rb +1 -1
  174. data/lib/active_admin/views/components/action_list_popover.rb +29 -0
  175. data/lib/active_admin/views/components/attributes_table.rb +6 -2
  176. data/lib/active_admin/views/components/dropdown_menu.rb +73 -0
  177. data/lib/active_admin/views/components/paginated_collection.rb +13 -14
  178. data/lib/active_admin/views/components/popover.rb +27 -0
  179. data/lib/active_admin/views/components/scopes.rb +8 -13
  180. data/lib/active_admin/views/components/sidebar_section.rb +1 -1
  181. data/lib/active_admin/views/components/site_title.rb +55 -0
  182. data/lib/active_admin/views/components/status_tag.rb +4 -4
  183. data/lib/active_admin/views/components/table_for.rb +18 -18
  184. data/lib/active_admin/views/dashboard_section_renderer.rb +1 -1
  185. data/lib/active_admin/views/footer.rb +18 -0
  186. data/lib/active_admin/views/header.rb +31 -0
  187. data/lib/active_admin/views/index_as_block.rb +3 -0
  188. data/lib/active_admin/views/index_as_blog.rb +4 -0
  189. data/lib/active_admin/views/index_as_grid.rb +2 -0
  190. data/lib/active_admin/views/index_as_table.rb +19 -6
  191. data/lib/active_admin/views/pages/base.rb +14 -48
  192. data/lib/active_admin/views/pages/form.rb +3 -3
  193. data/lib/active_admin/views/pages/index.rb +56 -24
  194. data/lib/active_admin/views/pages/layout.rb +2 -2
  195. data/lib/active_admin/views/pages/page.rb +10 -4
  196. data/lib/active_admin/views/pages/show.rb +11 -8
  197. data/lib/active_admin/views/tabbed_navigation.rb +3 -3
  198. data/lib/active_admin/views/title_bar.rb +50 -0
  199. data/lib/active_admin/views/utility_nav.rb +41 -0
  200. data/lib/generators/active_admin/assets/assets_generator.rb +1 -1
  201. data/lib/generators/active_admin/assets/templates/3.0/active_admin.js +1 -0
  202. data/lib/generators/active_admin/assets/templates/3.1/active_admin.css.scss +26 -3
  203. data/lib/generators/active_admin/devise/devise_generator.rb +2 -2
  204. data/lib/generators/active_admin/install/install_generator.rb +10 -10
  205. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +21 -1
  206. data/lib/generators/active_admin/install/templates/admin_user.rb.erb +20 -0
  207. data/lib/generators/active_admin/install/templates/dashboard.rb +33 -0
  208. data/lib/generators/active_admin/resource/templates/admin.rb +1 -1
  209. data/spec/integration/memory_spec.rb +1 -11
  210. data/spec/javascripts/coffeescripts/jquery.aa.checkbox-toggler-spec.js.coffee +50 -0
  211. data/spec/javascripts/coffeescripts/jquery.aa.popover-spec.js.coffee +82 -0
  212. data/spec/javascripts/coffeescripts/jquery.aa.table-checkbox-toggler-spec.js.coffee +34 -0
  213. data/spec/javascripts/compiled/jquery.aa.checkbox-toggler-spec.js +60 -0
  214. data/spec/javascripts/compiled/jquery.aa.popover-spec.js +106 -0
  215. data/spec/javascripts/compiled/jquery.aa.table-checkbox-toggler-spec.js +37 -0
  216. data/spec/javascripts/fixtures/checkboxes.html +9 -0
  217. data/spec/javascripts/fixtures/table_checkboxes.html +17 -0
  218. data/spec/javascripts/helpers/SpecHelper.js +3 -0
  219. data/spec/javascripts/helpers/vendor/jasmine-fixture-0.0.5.js +108 -0
  220. data/spec/javascripts/helpers/vendor/jasmine-jquery.js +288 -0
  221. data/spec/javascripts/helpers/vendor/sinon-1.2.0.js +2915 -0
  222. data/spec/javascripts/support/jasmine.yml +74 -0
  223. data/spec/javascripts/support/jasmine_config.rb +23 -0
  224. data/spec/javascripts/support/jasmine_runner.rb +32 -0
  225. data/spec/javascripts/support/jquery-ui-1.8.16.custom.min.js +34 -0
  226. data/spec/javascripts/support/jquery.min.js +4 -0
  227. data/spec/spec_helper.rb +13 -13
  228. data/spec/spec_helper_without_rails.rb +2 -3
  229. data/spec/support/detect_rails_version.rb +16 -10
  230. data/spec/support/rails_template.rb +13 -1
  231. data/spec/support/templates/admin/stores.rb +1 -0
  232. data/spec/support/templates/en.yml +6 -0
  233. data/spec/unit/action_builder_spec.rb +38 -0
  234. data/spec/unit/application_spec.rb +12 -16
  235. data/spec/unit/base_controller_shared_examples.rb +3 -6
  236. data/spec/unit/batch_actions/resource_spec.rb +91 -0
  237. data/spec/unit/batch_actions/settings_spec.rb +61 -0
  238. data/spec/unit/breadcrumbs_spec.rb +33 -0
  239. data/spec/unit/comments_spec.rb +6 -0
  240. data/spec/unit/config_shared_examples.rb +17 -64
  241. data/spec/unit/csv_builder_spec.rb +12 -2
  242. data/spec/unit/dashboard_controller_spec.rb +11 -5
  243. data/spec/unit/dsl_include_spec.rb +20 -0
  244. data/spec/unit/{filter_form_builder_spec.rb → filters/filter_form_builder_spec.rb} +10 -7
  245. data/spec/unit/filters/resource_spec.rb +60 -0
  246. data/spec/unit/form_builder_spec.rb +180 -28
  247. data/spec/unit/helpers/collection_spec.rb +65 -0
  248. data/spec/unit/menu_item_spec.rb +48 -53
  249. data/spec/unit/menu_spec.rb +46 -32
  250. data/spec/unit/namespace/register_page_spec.rb +0 -6
  251. data/spec/unit/namespace/register_resource_spec.rb +1 -8
  252. data/spec/unit/namespace_spec.rb +8 -2
  253. data/spec/unit/page_spec.rb +20 -8
  254. data/spec/unit/resource/naming_spec.rb +27 -26
  255. data/spec/unit/resource/sidebars_spec.rb +0 -7
  256. data/spec/unit/resource_collection_spec.rb +11 -11
  257. data/spec/unit/resource_controller/collection_spec.rb +23 -1
  258. data/spec/unit/resource_controller/sidebars_spec.rb +46 -0
  259. data/spec/unit/resource_controller_spec.rb +43 -0
  260. data/spec/unit/resource_registration_spec.rb +2 -13
  261. data/spec/unit/resource_spec.rb +0 -42
  262. data/spec/unit/routing_spec.rb +60 -14
  263. data/spec/unit/scope_spec.rb +7 -0
  264. data/spec/unit/view_factory_spec.rb +9 -6
  265. data/spec/unit/view_helpers/fields_for_spec.rb +41 -0
  266. data/spec/unit/view_helpers/form_helper_spec.rb +18 -0
  267. data/spec/unit/views/components/action_list_popover_spec.rb +30 -0
  268. data/spec/unit/views/components/attributes_table_spec.rb +32 -20
  269. data/spec/unit/views/components/batch_action_popover_spec.rb +33 -0
  270. data/spec/unit/views/components/blank_slate_spec.rb +5 -3
  271. data/spec/unit/views/components/columns_spec.rb +32 -22
  272. data/spec/unit/views/components/paginated_collection_spec.rb +54 -12
  273. data/spec/unit/views/components/panel_spec.rb +11 -6
  274. data/spec/unit/views/components/popover_spec.rb +33 -0
  275. data/spec/unit/views/components/sidebar_section_spec.rb +6 -6
  276. data/spec/unit/views/components/site_title_spec.rb +78 -0
  277. data/spec/unit/views/components/status_tag_spec.rb +17 -10
  278. data/spec/unit/views/components/table_for_spec.rb +37 -17
  279. data/spec/unit/views/pages/layout_spec.rb +51 -10
  280. data/spec/unit/views/tabbed_navigation_spec.rb +44 -23
  281. data/tasks/js.rake +32 -0
  282. data/tasks/test.rake +1 -1
  283. metadata +233 -200
  284. data/lib/active_admin/arbre.rb +0 -22
  285. data/lib/active_admin/arbre/builder.rb +0 -125
  286. data/lib/active_admin/arbre/context.rb +0 -45
  287. data/lib/active_admin/arbre/html/attributes.rb +0 -20
  288. data/lib/active_admin/arbre/html/class_list.rb +0 -24
  289. data/lib/active_admin/arbre/html/collection.rb +0 -27
  290. data/lib/active_admin/arbre/html/document.rb +0 -42
  291. data/lib/active_admin/arbre/html/element.rb +0 -161
  292. data/lib/active_admin/arbre/html/html5_elements.rb +0 -47
  293. data/lib/active_admin/arbre/html/tag.rb +0 -145
  294. data/lib/active_admin/arbre/html/text_node.rb +0 -35
  295. data/lib/active_admin/filter_form_builder.rb +0 -53
  296. data/lib/active_admin/renderer.rb +0 -87
  297. data/lib/active_admin/resource_controller/filters.rb +0 -58
  298. data/lib/active_admin/stylesheets/active_admin/mixins/_utilities.scss +0 -0
  299. data/lib/active_admin/view_helpers/filter_form_helper.rb +0 -36
  300. data/lib/active_admin/view_helpers/renderer_helper.rb +0 -29
  301. data/lib/active_admin/views/header_renderer.rb +0 -82
  302. data/lib/generators/active_admin/assets/templates/dashboards.rb +0 -36
  303. data/lib/generators/active_admin/install/templates/dashboards.rb +0 -44
  304. data/spec/unit/arbre/context_spec.rb +0 -35
  305. data/spec/unit/arbre/html/element_finder_methods_spec.rb +0 -110
  306. data/spec/unit/arbre/html/element_spec.rb +0 -236
  307. data/spec/unit/arbre/html/tag_attributes_spec.rb +0 -61
  308. data/spec/unit/arbre/html/tag_spec.rb +0 -63
  309. data/spec/unit/arbre/html_spec.rb +0 -228
  310. data/spec/unit/renderer_spec.rb +0 -126
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveAdmin::Filters::ResourceExtension do
4
+
5
+ let(:resource) do
6
+ namespace = ActiveAdmin::Namespace.new(ActiveAdmin::Application.new, :admin)
7
+ namespace.register(Post)
8
+ end
9
+
10
+ it "should return the defaults if no filters are set" do
11
+ resource.filters.map{|f| f[:attribute].to_s }.sort.should == %w{
12
+ author body category created_at published_at title updated_at
13
+ }
14
+ end
15
+
16
+ it "should not have defaults when filters are disabled on the resource" do
17
+ resource.filters = false
18
+ resource.filters.should be_empty
19
+ end
20
+
21
+ it "should not have defaults when the filters are disabled on the namespace" do
22
+ resource.namespace.filters = false
23
+ resource.filters.should be_empty
24
+ end
25
+
26
+ it "should not have defaults when the filters are disabled on the application" do
27
+ resource.namespace.application.filters = false
28
+ resource.filters.should be_empty
29
+ end
30
+
31
+ it "should add a filter" do
32
+ resource.add_filter :title
33
+ resource.filters.should == [{:attribute => :title}]
34
+ end
35
+
36
+ it "should add a filter with options" do
37
+ resource.add_filter :title, :as => :string
38
+ resource.filters.should == [{:attribute => :title, :as => :string}]
39
+ end
40
+
41
+ it "should raise an exception if trying to add a filter when they are disabled" do
42
+ resource.filters = false
43
+ expect {
44
+ resource.add_filter :title
45
+ }.should raise_error(RuntimeError)
46
+ end
47
+
48
+ it "should reset filters" do
49
+ resource.add_filter :title
50
+ resource.filters.size.should == 1
51
+ resource.reset_filters!
52
+ resource.filters.size.should > 1
53
+ end
54
+
55
+ it "should add a sidebar section for the filters" do
56
+ resource.sidebar_sections.first.name.should == :filters
57
+ end
58
+
59
+
60
+ end
@@ -1,12 +1,10 @@
1
- require 'spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe ActiveAdmin::FormBuilder do
4
4
 
5
- setup_arbre_context!
6
-
7
5
  # Setup an ActionView::Base object which can be used for
8
6
  # generating the form for.
9
- let(:helpers) do
7
+ let(:helpers) do
10
8
  view = action_view
11
9
  def view.posts_path
12
10
  "/posts"
@@ -31,21 +29,56 @@ describe ActiveAdmin::FormBuilder do
31
29
  view
32
30
  end
33
31
 
34
- def build_form(options = {}, &block)
35
- options.merge!({:url => posts_path})
36
- active_admin_form_for Post.new, options, &block
32
+ def build_form(options = {}, form_object = Post.new, &block)
33
+ options = {:url => helpers.posts_path}.merge(options)
34
+
35
+ render_arbre_component({:form_object => form_object, :form_options => options, :form_block => block}, helpers)do
36
+ text_node active_admin_form_for(assigns[:form_object], assigns[:form_options], &assigns[:form_block])
37
+ end.to_s
37
38
  end
38
39
 
39
- context "in general" do
40
+ context "in general with actions" do
40
41
  let :body do
41
42
  build_form do |f|
42
43
  f.inputs do
43
44
  f.input :title
44
45
  f.input :body
45
46
  end
46
- f.buttons do
47
- f.commit_button "Submit Me"
48
- f.commit_button "Another Button"
47
+ f.actions do
48
+ f.action :submit, :label => "Submit Me"
49
+ f.action :submit, :label => "Another Button"
50
+ end
51
+ end
52
+ end
53
+
54
+ it "should generate a text input" do
55
+ body.should have_tag("input", :attributes => { :type => "text",
56
+ :name => "post[title]" })
57
+ end
58
+ it "should generate a textarea" do
59
+ body.should have_tag("textarea", :attributes => { :name => "post[body]" })
60
+ end
61
+ it "should only generate the form once" do
62
+ body.scan(/Title/).size.should == 1
63
+ end
64
+ it "should generate actions" do
65
+ body.should have_tag("input", :attributes => { :type => "submit",
66
+ :value => "Submit Me" })
67
+ body.should have_tag("input", :attributes => { :type => "submit",
68
+ :value => "Another Button" })
69
+ end
70
+ end
71
+
72
+ context "in general with actions" do
73
+ let :body do
74
+ build_form do |f|
75
+ f.inputs do
76
+ f.input :title
77
+ f.input :body
78
+ end
79
+ f.actions do
80
+ f.action :submit, :button_html => { :value => "Submit Me" }
81
+ f.action :submit, :button_html => { :value => "Another Button" }
49
82
  end
50
83
  end
51
84
  end
@@ -60,7 +93,7 @@ describe ActiveAdmin::FormBuilder do
60
93
  it "should only generate the form once" do
61
94
  body.scan(/Title/).size.should == 1
62
95
  end
63
- it "should generate buttons" do
96
+ it "should generate actions" do
64
97
  body.should have_tag("input", :attributes => { :type => "submit",
65
98
  :value => "Submit Me" })
66
99
  body.should have_tag("input", :attributes => { :type => "submit",
@@ -72,18 +105,18 @@ describe ActiveAdmin::FormBuilder do
72
105
  it "should raise error" do
73
106
  lambda {
74
107
  comment = ActiveAdmin::Comment.new
75
- active_admin_form_for comment, :url => "admins/comments" do |f|
108
+ build_form({:url => "admins/comments"}, comment) do |f|
76
109
  f.inputs :resource
77
110
  end
78
111
  }.should raise_error(Formtastic::PolymorphicInputWithoutCollectionError)
79
112
  end
80
113
  end
81
114
 
82
- describe "passing in options" do
115
+ describe "passing in options with actions" do
83
116
  let :body do
84
117
  build_form :html => { :multipart => true } do |f|
85
118
  f.inputs :title
86
- f.buttons
119
+ f.actions
87
120
  end
88
121
  end
89
122
  it "should pass the options on to the form" do
@@ -91,28 +124,41 @@ describe ActiveAdmin::FormBuilder do
91
124
  end
92
125
  end
93
126
 
94
- context "with buttons" do
127
+ describe "passing in options with actions" do
128
+ let :body do
129
+ build_form :html => { :multipart => true } do |f|
130
+ f.inputs :title
131
+ f.actions
132
+ end
133
+ end
134
+ it "should pass the options on to the form" do
135
+ body.should have_tag("form", :attributes => { :enctype => "multipart/form-data" })
136
+ end
137
+ end
138
+
139
+
140
+ context "with actions" do
95
141
  it "should generate the form once" do
96
142
  body = build_form do |f|
97
143
  f.inputs do
98
144
  f.input :title
99
145
  end
100
- f.buttons
146
+ f.actions
101
147
  end
102
148
  body.scan(/id=\"post_title\"/).size.should == 1
103
149
  end
104
150
  it "should generate one button and a cancel link" do
105
151
  body = build_form do |f|
106
- f.buttons
152
+ f.actions
107
153
  end
108
154
  body.scan(/type=\"submit\"/).size.should == 1
109
155
  body.scan(/class=\"cancel\"/).size.should == 1
110
156
  end
111
- it "should generate multiple buttons" do
157
+ it "should generate multiple actions" do
112
158
  body = build_form do |f|
113
- f.buttons do
114
- f.commit_button "Create & Continue"
115
- f.commit_button "Create & Edit"
159
+ f.actions do
160
+ f.action :submit, :label => "Create & Continue"
161
+ f.action :submit, :label => "Create & Edit"
116
162
  end
117
163
  end
118
164
  body.scan(/type=\"submit\"/).size.should == 2
@@ -121,6 +167,35 @@ describe ActiveAdmin::FormBuilder do
121
167
 
122
168
  end
123
169
 
170
+ context "with actons" do
171
+ it "should generate the form once" do
172
+ body = build_form do |f|
173
+ f.inputs do
174
+ f.input :title
175
+ end
176
+ f.actions
177
+ end
178
+ body.scan(/id=\"post_title\"/).size.should == 1
179
+ end
180
+ it "should generate one button and a cancel link" do
181
+ body = build_form do |f|
182
+ f.actions
183
+ end
184
+ body.scan(/type=\"submit\"/).size.should == 1
185
+ body.scan(/class=\"cancel\"/).size.should == 1
186
+ end
187
+ it "should generate multiple actions" do
188
+ body = build_form do |f|
189
+ f.actions do
190
+ f.action :submit, :label => "Create & Continue"
191
+ f.action :submit, :label => "Create & Edit"
192
+ end
193
+ end
194
+ body.scan(/type=\"submit\"/).size.should == 2
195
+ body.scan(/class=\"cancel\"/).size.should == 0
196
+ end
197
+ end
198
+
124
199
  context "without passing a block to inputs" do
125
200
  let :body do
126
201
  build_form do |f|
@@ -218,13 +293,90 @@ describe ActiveAdmin::FormBuilder do
218
293
  end
219
294
  end
220
295
 
296
+ context "with has many inputs" do
297
+ describe "with simple block" do
298
+ let :body do
299
+ build_form({:url => '/categories'}, Category.new) do |f|
300
+ f.object.posts.build
301
+ f.has_many :posts do |p|
302
+ p.input :title
303
+ end
304
+ end
305
+ end
306
+
307
+ it "should translate the association name in header" do
308
+ begin
309
+ I18n.backend.store_translations(:en, :activerecord => { :models => { :post => { :one => "Blog Post", :other => "Blog Posts" } } })
310
+ body.should have_tag('h3', 'Blog Posts')
311
+ ensure
312
+ I18n.backend.reload!
313
+ end
314
+ end
315
+
316
+ it "should use model name when there is no translation for given model in header" do
317
+ body.should have_tag('h3', 'Post')
318
+ end
319
+
320
+ it "should translate the association name in has many new button" do
321
+ begin
322
+ I18n.backend.store_translations(:en, :activerecord => { :models => { :post => { :one => "Blog Post", :other => "Blog Posts" } } })
323
+ body.should have_tag('a', 'Add New Blog Post')
324
+ ensure
325
+ I18n.backend.reload!
326
+ end
327
+ end
328
+
329
+ it "should use model name when there is no translation for given model in has many new button" do
330
+ body.should have_tag('a', 'Add New Post')
331
+ end
332
+
333
+ it "should render the nested form" do
334
+ body.should have_tag("input", :attributes => {:name => "category[posts_attributes][0][title]"})
335
+ end
336
+
337
+ it "should add a link to remove new nested records" do
338
+ Capybara.string(body).should have_css(".has_many > fieldset > ol > li > a", :class => "button", :href => "#", :content => "Delete")
339
+ end
340
+
341
+ it "should add a link to add new nested records" do
342
+ Capybara.string(body).should have_css(".has_many > fieldset > ol > li > a", :class => "button", :href => "#", :content => "Add New Post")
343
+ end
344
+ end
345
+
346
+ describe "with complex block" do
347
+ let :body do
348
+ build_form({:url => '/categories'}, Category.new) do |f|
349
+ f.object.posts.build
350
+ f.has_many :posts do |p,i|
351
+ p.input :title, :label => "Title #{i}"
352
+ end
353
+ end
354
+ end
355
+
356
+ it "should accept a block with a second argument" do
357
+ body.should have_tag("label", "Title 1")
358
+ end
359
+ end
360
+
361
+ pending "should render the block if it returns nil" do
362
+ body = build_form({:url => '/categories'}, Category.new) do |f|
363
+ f.object.posts.build
364
+ f.has_many :posts do |p|
365
+ p.input :title
366
+ nil
367
+ end
368
+ end
369
+
370
+ body.should have_tag("input", :attributes => {:name => "category[posts_attributes][0][title]"})
371
+ end
372
+ end
221
373
 
222
- {
223
- "input :title, :as => :string" => /id\=\"post_title\"/,
224
- "input :title, :as => :text" => /id\=\"post_title\"/,
225
- "input :created_at, :as => :time" => /id\=\"post_created_at_2i\"/,
226
- "input :created_at, :as => :datetime" => /id\=\"post_created_at_2i\"/,
227
- "input :created_at, :as => :date" => /id\=\"post_created_at_2i\"/,
374
+ {
375
+ "input :title, :as => :string" => /id\=\"post_title\"/,
376
+ "input :title, :as => :text" => /id\=\"post_title\"/,
377
+ "input :created_at, :as => :time_select" => /id\=\"post_created_at_2i\"/,
378
+ "input :created_at, :as => :datetime_select" => /id\=\"post_created_at_2i\"/,
379
+ "input :created_at, :as => :date_select" => /id\=\"post_created_at_2i\"/,
228
380
  }.each do |source, regex|
229
381
  it "should properly buffer #{source}" do
230
382
  body = build_form do |f|
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveAdmin::Helpers::Collection do
4
+
5
+ include ActiveAdmin::Helpers::Collection
6
+
7
+ before(:all) do
8
+ Post.delete_all
9
+ Post.create!(:title => "A post")
10
+ Post.create!(:title => "A post")
11
+ Post.create!(:title => "An other post")
12
+ end
13
+
14
+ after(:all) do
15
+ Post.delete_all
16
+ end
17
+
18
+ describe "#collection_size" do
19
+ it "should return the collection size for an ActiveRecord class" do
20
+ collection_size(Post).should == 3
21
+ end
22
+
23
+ it "should return the collection size for an ActiveRecord::Relation" do
24
+ collection_size(Post.where(:title => "A post")).should == 2
25
+ end
26
+
27
+ it "should return the collection size for a collection with group by" do
28
+ collection_size(Post.group(:title)).should == 2
29
+ end
30
+
31
+ it "should return the collection size for a collection with group by, select and custom order" do
32
+ collection_size(Post.select("title, count(*) as nb_posts").group(:title).order("nb_posts")).should == 2
33
+ end
34
+
35
+ it "should take the defined collection by default" do
36
+ def collection; Post; end
37
+
38
+ collection_size.should == 3
39
+
40
+ def collection; Post.where(:title => "An other post"); end
41
+
42
+ collection_size.should == 1
43
+ end
44
+ end
45
+
46
+ describe "#collection_is_empty?" do
47
+ it "should return true when the collection is empty" do
48
+ collection_is_empty?(Post.where(:title => "Non existing post")).should be_true
49
+ end
50
+
51
+ it "should return false when the collection is not empty" do
52
+ collection_is_empty?(Post.where(:title => "A post")).should be_false
53
+ end
54
+
55
+ it "should take the defined collection by default" do
56
+ def collection; Post; end
57
+
58
+ collection_is_empty?.should be_false
59
+
60
+ def collection; Post.where(:title => "Non existing post"); end
61
+
62
+ collection_is_empty?.should be_true
63
+ end
64
+ end
65
+ end
@@ -1,75 +1,72 @@
1
1
  require 'spec_helper_without_rails'
2
+ require 'active_admin/menu'
2
3
  require 'active_admin/menu_item'
3
4
 
4
5
  module ActiveAdmin
5
6
  describe MenuItem do
6
7
 
7
- it "should have a name" do
8
- item = MenuItem.new("Dashboard", "/admin")
9
- item.name.should == "Dashboard"
8
+ it "should have a label" do
9
+ item = MenuItem.new(:label => "Dashboard")
10
+ item.label.should == "Dashboard"
10
11
  end
11
12
 
12
13
  it "should have a url" do
13
- item = MenuItem.new("Dashboard", "/admin")
14
+ item = MenuItem.new(:url => "/admin")
14
15
  item.url.should == "/admin"
15
16
  end
16
17
 
17
18
  it "should have a priority of 10 by default" do
18
- item = MenuItem.new("Dashboard", "/admin")
19
+ item = MenuItem.new
19
20
  item.priority.should == 10
20
21
  end
21
22
 
22
- it "should accept an optional options hash" do
23
- item = MenuItem.new("Dashboard", "/admin", 10, :if => lambda{ logged_in? } )
24
- end
25
-
26
23
  it "should have a display if block" do
27
24
  block = lambda{ logged_in? }
28
- item = MenuItem.new("Dashboard", "/admin", 10, :if => block )
25
+ item = MenuItem.new(:if => block )
29
26
  item.display_if_block.should == block
30
27
  end
31
28
 
32
29
  it "should have a default display if block always returning true" do
33
- item = MenuItem.new("Dashboard", "/admin")
30
+ item = MenuItem.new
34
31
  item.display_if_block.should be_instance_of(Proc)
35
32
  item.display_if_block.call(self).should == true
36
33
  end
37
34
 
38
35
  context "with no children" do
39
36
  it "should be empty" do
40
- item = MenuItem.new("Blog", "/admin/blog")
37
+ item = MenuItem.new
41
38
  item.children.should == []
42
39
  end
43
40
 
44
41
  it "should accept new children" do
45
- item = MenuItem.new("Blog", "/admin/blog")
46
- item.add "Dashboard", "/admin"
42
+ item = MenuItem.new
43
+ item.add MenuItem.new(:label => "Dashboard")
47
44
  item.children.first.should be_an_instance_of(MenuItem)
48
- item.children.first.name.should == "Dashboard"
45
+ item.children.first.label.should == "Dashboard"
49
46
  end
50
47
  end
51
48
 
52
49
  context "with many children" do
53
50
  let(:item) do
54
- i = MenuItem.new("Dashboard", "/admin")
55
- i.add "Blog", "/"
56
- i.add "Cars", "/"
57
- i.add "Users", "/", 1
58
- i.add "Settings", "/", 2
59
- i.add "Analytics", "/", 44
51
+ i = MenuItem.new(:label => "Dashboard")
52
+ i.add MenuItem.new(:label => "Blog")
53
+ i.add MenuItem.new(:label => "Cars")
54
+ i.add MenuItem.new(:label => "Users", :priority => 1)
55
+ i.add MenuItem.new(:label => "Settings", :priority => 2)
56
+ i.add MenuItem.new(:label => "Analytics", :priority => 44)
60
57
  i
61
58
  end
62
59
 
63
60
  it "should give access to the menu item as an array" do
64
- item['Blog'].name.should == 'Blog'
61
+ item['Blog'].label.should == 'Blog'
65
62
  end
66
63
 
67
64
  it "should sort items based on priority and name" do
68
- item.children[0].name.should == 'Users'
69
- item.children[1].name.should == 'Settings'
70
- item.children[2].name.should == 'Blog'
71
- item.children[3].name.should == 'Cars'
72
- item.children[4].name.should == 'Analytics'
65
+ item.children[0].label.should == 'Users'
66
+ item.children[1].label.should == 'Settings'
67
+ item.children[2].label.should == 'Blog'
68
+ item.children[3].label.should == 'Cars'
69
+ item.children[4].label.should == 'Analytics'
73
70
  end
74
71
 
75
72
  it "children should hold a reference to their parent" do
@@ -77,27 +74,8 @@ module ActiveAdmin
77
74
  end
78
75
  end
79
76
 
80
- describe "building children using block syntax" do
81
- let(:item) do
82
- MenuItem.new("Blog", "/") do |blog|
83
- blog.add "Create New", "/blog/new"
84
- blog.add("Comments", "/blog/comments") do |comments|
85
- comments.add "Approved", "/blog/comments?status=approved"
86
- end
87
- end
88
- end
89
-
90
- it "should have 2 children" do
91
- item.children.size.should == 2
92
- end
93
-
94
- it "should have sub-sub items" do
95
- item["Comments"]["Approved"].name.should == 'Approved'
96
- end
97
- end
98
-
99
77
  describe "accessing ancestory" do
100
- let(:item){ MenuItem.new "Blog", "/blog" }
78
+ let(:item){ MenuItem.new :label => "Blog" }
101
79
 
102
80
  context "with no parent" do
103
81
  it "should return an empty array" do
@@ -107,7 +85,7 @@ module ActiveAdmin
107
85
 
108
86
  context "with one parent" do
109
87
  let(:sub_item) do
110
- item.add "Create New", "/blog/new"
88
+ item.add MenuItem.new(:label => "Create New")
111
89
  item["Create New"]
112
90
  end
113
91
  it "should return an array with the parent" do
@@ -117,11 +95,15 @@ module ActiveAdmin
117
95
 
118
96
  context "with many parents" do
119
97
  before(:each) do
120
- item.add "C1", "/c1" do |c1|
121
- c1.add "C2", "/c2" do |c2|
122
- c2.add "C3", "/c3"
123
- end
124
- end
98
+ c1 = MenuItem.new(:label => "C1")
99
+ c2 = MenuItem.new(:label => "C2")
100
+ c3 = MenuItem.new(:label => "C3")
101
+
102
+ item.add(c1)
103
+ c1.add c2
104
+ c2.add c3
105
+
106
+ item
125
107
  end
126
108
  let(:sub_item){ item["C1"]["C2"]["C3"] }
127
109
  it "should return an array with the parents in reverse order" do
@@ -130,5 +112,18 @@ module ActiveAdmin
130
112
  end
131
113
  end # accessing ancestory
132
114
 
115
+
116
+ describe ".generate_item_id" do
117
+
118
+ it "downcases the id" do
119
+ MenuItem.generate_item_id("Identifier").should == "identifier"
120
+ end
121
+
122
+ it "should set underscore any spaces" do
123
+ MenuItem.generate_item_id("An Id").should == "an_id"
124
+ end
125
+
126
+ end
127
+
133
128
  end
134
129
  end