activeadmin 0.3.4 → 0.4.0

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 (244) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +3 -0
  3. data/CHANGELOG.md +164 -5
  4. data/CONTRIBUTING.md +113 -0
  5. data/Gemfile +7 -9
  6. data/LICENSE +1 -1
  7. data/README.rdoc +19 -20
  8. data/activeadmin.gemspec +4 -2
  9. data/app/assets/javascripts/active_admin/application.js +9 -0
  10. data/app/assets/javascripts/active_admin/base.js +4 -12
  11. data/app/assets/stylesheets/active_admin/_base.css.scss +17 -341
  12. data/app/assets/stylesheets/active_admin/_forms.css.scss +13 -7
  13. data/app/assets/stylesheets/active_admin/_header.css.scss +23 -4
  14. data/app/assets/stylesheets/active_admin/components/_blank_slates.scss +31 -0
  15. data/app/assets/stylesheets/active_admin/components/_breadcrumbs.scss +20 -0
  16. data/app/assets/stylesheets/active_admin/components/_buttons.scss +12 -0
  17. data/app/assets/stylesheets/active_admin/components/_flash_messages.css.scss +2 -0
  18. data/app/assets/stylesheets/active_admin/components/_grid.scss +9 -0
  19. data/app/assets/stylesheets/active_admin/components/_links.scss +5 -0
  20. data/app/assets/stylesheets/active_admin/components/_pagination.scss +34 -0
  21. data/app/assets/stylesheets/active_admin/components/_panels.scss +6 -0
  22. data/app/assets/stylesheets/active_admin/components/_scopes.scss +10 -0
  23. data/app/assets/stylesheets/active_admin/components/_status_tags.scss +12 -0
  24. data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +101 -0
  25. data/app/assets/stylesheets/active_admin/components/_tables.css.scss +43 -2
  26. data/app/assets/stylesheets/active_admin/mixins/_all.css.scss +2 -1
  27. data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +50 -13
  28. data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +9 -1
  29. data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +7 -5
  30. data/app/assets/stylesheets/active_admin/mixins/_shadows.css.scss +1 -0
  31. data/app/assets/stylesheets/active_admin/mixins/_typography.scss +3 -0
  32. data/app/assets/stylesheets/active_admin/mixins/_utilities.scss +9 -0
  33. data/app/assets/stylesheets/active_admin/mixins/_variables.css.scss +1 -0
  34. data/app/assets/stylesheets/active_admin/pages/_dashboard.scss +5 -0
  35. data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +44 -0
  36. data/app/assets/stylesheets/active_admin/structure/_footer.scss +14 -0
  37. data/app/assets/stylesheets/active_admin/structure/_main_structure.scss +26 -0
  38. data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +44 -0
  39. data/app/views/active_admin/devise/passwords/edit.html.erb +1 -1
  40. data/app/views/active_admin/devise/passwords/new.html.erb +1 -1
  41. data/app/views/active_admin/devise/sessions/new.html.erb +1 -1
  42. data/app/views/active_admin/devise/shared/_links.erb +1 -1
  43. data/app/views/active_admin/devise/unlocks/new.html.erb +1 -1
  44. data/app/views/active_admin/page/index.html.arb +1 -0
  45. data/app/views/layouts/active_admin_logged_out.html.erb +2 -2
  46. data/cucumber.yml +3 -2
  47. data/docs/1-general-configuration.md +46 -10
  48. data/docs/6-show-screens.md +7 -0
  49. data/docs/8-custom-actions.md +12 -2
  50. data/docs/9-custom-pages.md +84 -0
  51. data/features/belongs_to.feature +27 -0
  52. data/features/comments/commenting.feature +3 -2
  53. data/features/dashboard.feature +18 -0
  54. data/features/development_reloading.feature +43 -0
  55. data/features/index/filter_with_check_boxes.feature +25 -0
  56. data/features/index/index_as_table.feature +14 -0
  57. data/features/index/index_scopes.feature +59 -0
  58. data/features/index/pagination.feature +19 -1
  59. data/features/menu.feature +22 -2
  60. data/features/registering_assets.feature +2 -2
  61. data/features/registering_pages.feature +66 -0
  62. data/features/specifying_actions.feature +5 -0
  63. data/features/step_definitions/action_item_steps.rb +2 -6
  64. data/features/step_definitions/action_link_steps.rb +7 -0
  65. data/features/step_definitions/additional_web_steps.rb +11 -3
  66. data/features/step_definitions/asset_steps.rb +5 -1
  67. data/features/step_definitions/breadcrumb_steps.rb +5 -0
  68. data/features/step_definitions/comment_steps.rb +3 -3
  69. data/features/step_definitions/configuration_steps.rb +69 -13
  70. data/features/step_definitions/dashboard_steps.rb +7 -3
  71. data/features/step_definitions/factory_steps.rb +9 -2
  72. data/features/step_definitions/flash_steps.rb +9 -1
  73. data/features/step_definitions/format_steps.rb +9 -1
  74. data/features/step_definitions/index_scope_steps.rb +18 -6
  75. data/features/step_definitions/member_link_steps.rb +7 -0
  76. data/features/step_definitions/pagination_steps.rb +2 -2
  77. data/features/step_definitions/site_title_steps.rb +15 -0
  78. data/features/step_definitions/tab_steps.rb +1 -1
  79. data/features/step_definitions/user_steps.rb +1 -1
  80. data/features/step_definitions/web_steps.rb +4 -4
  81. data/features/support/paths.rb +6 -0
  82. data/features/users/logging_out.feature +11 -0
  83. data/lib/active_admin.rb +26 -10
  84. data/lib/active_admin/application.rb +64 -22
  85. data/lib/active_admin/arbre.rb +0 -1
  86. data/lib/active_admin/arbre/builder.rb +8 -5
  87. data/lib/active_admin/arbre/context.rb +1 -1
  88. data/lib/active_admin/arbre/html/attributes.rb +1 -1
  89. data/lib/active_admin/arbre/html/class_list.rb +0 -4
  90. data/lib/active_admin/arbre/html/collection.rb +2 -2
  91. data/lib/active_admin/arbre/html/document.rb +1 -1
  92. data/lib/active_admin/arbre/html/element.rb +19 -9
  93. data/lib/active_admin/arbre/html/tag.rb +3 -3
  94. data/lib/active_admin/arbre/html/text_node.rb +2 -2
  95. data/lib/active_admin/asset_registration.rb +15 -2
  96. data/lib/active_admin/base_controller.rb +61 -0
  97. data/lib/active_admin/{resource_controller → base_controller}/menu.rb +1 -1
  98. data/lib/active_admin/callbacks.rb +16 -18
  99. data/lib/active_admin/comments.rb +48 -54
  100. data/lib/active_admin/comments/comment.rb +13 -2
  101. data/lib/active_admin/comments/namespace_helper.rb +1 -1
  102. data/lib/active_admin/comments/views/active_admin_comments.rb +7 -3
  103. data/lib/active_admin/dashboards.rb +4 -0
  104. data/lib/active_admin/dashboards/dashboard_controller.rb +21 -5
  105. data/lib/active_admin/dsl.rb +6 -159
  106. data/lib/active_admin/event.rb +5 -3
  107. data/lib/active_admin/filter_form_builder.rb +53 -0
  108. data/lib/active_admin/form_builder.rb +25 -19
  109. data/lib/active_admin/helpers/settings.rb +6 -10
  110. data/lib/active_admin/inputs.rb +14 -0
  111. data/lib/active_admin/inputs/datepicker_input.rb +11 -0
  112. data/lib/active_admin/inputs/filter_base.rb +46 -0
  113. data/lib/active_admin/inputs/filter_check_boxes_input.rb +40 -0
  114. data/lib/active_admin/inputs/filter_date_range_input.rb +34 -0
  115. data/lib/active_admin/inputs/filter_numeric_input.rb +55 -0
  116. data/lib/active_admin/inputs/filter_select_input.rb +23 -0
  117. data/lib/active_admin/inputs/filter_string_input.rb +22 -0
  118. data/lib/active_admin/locales/ca.yml +44 -0
  119. data/lib/active_admin/locales/cs.yml +14 -10
  120. data/lib/active_admin/locales/de.yml +44 -0
  121. data/lib/active_admin/locales/en.yml +5 -0
  122. data/lib/active_admin/locales/hr.yml +40 -0
  123. data/lib/active_admin/locales/hu.yml +45 -0
  124. data/lib/active_admin/locales/it.yml +11 -6
  125. data/lib/active_admin/locales/ko.yml +40 -0
  126. data/lib/active_admin/locales/lv.yml +43 -0
  127. data/lib/active_admin/locales/nl.yml +40 -0
  128. data/lib/active_admin/locales/no-NB.yml +40 -0
  129. data/lib/active_admin/locales/pl.yml +7 -1
  130. data/lib/active_admin/locales/pt-BR.yml +6 -2
  131. data/lib/active_admin/menu_item.rb +25 -17
  132. data/lib/active_admin/namespace.rb +48 -33
  133. data/lib/active_admin/page.rb +65 -0
  134. data/lib/active_admin/page_controller.rb +15 -0
  135. data/lib/active_admin/page_dsl.rb +21 -0
  136. data/lib/active_admin/page_presenter.rb +30 -0
  137. data/lib/active_admin/reloader.rb +109 -42
  138. data/lib/active_admin/resource.rb +38 -44
  139. data/lib/active_admin/resource/action_items.rb +5 -0
  140. data/lib/active_admin/resource/belongs_to.rb +4 -2
  141. data/lib/active_admin/resource/controllers.rb +35 -0
  142. data/lib/active_admin/resource/menu.rb +1 -2
  143. data/lib/active_admin/resource/naming.rb +53 -31
  144. data/lib/active_admin/resource/page_presenters.rb +28 -0
  145. data/lib/active_admin/resource/scopes.rb +16 -3
  146. data/lib/active_admin/resource/sidebars.rb +4 -0
  147. data/lib/active_admin/resource_collection.rb +88 -0
  148. data/lib/active_admin/resource_controller.rb +18 -54
  149. data/lib/active_admin/resource_controller/action_builder.rb +1 -1
  150. data/lib/active_admin/resource_controller/actions.rb +8 -8
  151. data/lib/active_admin/resource_controller/callbacks.rb +1 -1
  152. data/lib/active_admin/resource_controller/collection.rb +8 -4
  153. data/lib/active_admin/resource_controller/filters.rb +1 -1
  154. data/lib/active_admin/resource_controller/resource_class_methods.rb +24 -0
  155. data/lib/active_admin/resource_controller/scoping.rb +1 -1
  156. data/lib/active_admin/resource_controller/sidebars.rb +1 -1
  157. data/lib/active_admin/resource_dsl.rb +157 -0
  158. data/lib/active_admin/router.rb +21 -14
  159. data/lib/active_admin/scope.rb +15 -3
  160. data/lib/active_admin/version.rb +1 -1
  161. data/lib/active_admin/view_factory.rb +4 -3
  162. data/lib/active_admin/view_helpers/auto_link_helper.rb +1 -10
  163. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +25 -21
  164. data/lib/active_admin/view_helpers/filter_form_helper.rb +0 -150
  165. data/lib/active_admin/views/components/attributes_table.rb +1 -1
  166. data/lib/active_admin/views/components/columns.rb +4 -4
  167. data/lib/active_admin/views/components/paginated_collection.rb +42 -13
  168. data/lib/active_admin/views/components/panel.rb +8 -0
  169. data/lib/active_admin/views/components/scopes.rb +24 -18
  170. data/lib/active_admin/views/components/status_tag.rb +6 -5
  171. data/lib/active_admin/views/components/table_for.rb +6 -2
  172. data/lib/active_admin/views/header_renderer.rb +31 -12
  173. data/lib/active_admin/views/index_as_block.rb +2 -2
  174. data/lib/active_admin/views/index_as_blog.rb +3 -3
  175. data/lib/active_admin/views/index_as_grid.rb +4 -4
  176. data/lib/active_admin/views/index_as_table.rb +13 -6
  177. data/lib/active_admin/views/pages/base.rb +4 -4
  178. data/lib/active_admin/views/pages/form.rb +49 -0
  179. data/lib/active_admin/views/pages/index.rb +18 -6
  180. data/lib/active_admin/views/pages/page.rb +24 -0
  181. data/lib/active_admin/views/pages/show.rb +1 -1
  182. data/lib/generators/active_admin/assets/assets_generator.rb +19 -1
  183. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +38 -12
  184. data/lib/generators/active_admin/install/templates/dashboards.rb +6 -0
  185. data/script/use_rails +14 -7
  186. data/spec/spec_helper.rb +9 -14
  187. data/spec/spec_helper_without_rails.rb +10 -0
  188. data/spec/support/detect_rails_version.rb +22 -3
  189. data/spec/support/integration_example_group.rb +5 -7
  190. data/spec/support/rails_template.rb +11 -0
  191. data/spec/support/rails_template_with_data.rb +25 -0
  192. data/spec/support/templates/cucumber_with_reloading.rb +5 -0
  193. data/spec/unit/active_admin_spec.rb +8 -0
  194. data/spec/unit/application_spec.rb +48 -2
  195. data/spec/unit/arbre/context_spec.rb +1 -1
  196. data/spec/unit/arbre/html/element_finder_methods_spec.rb +58 -2
  197. data/spec/unit/arbre/html/element_spec.rb +18 -5
  198. data/spec/unit/arbre/html/tag_attributes_spec.rb +3 -3
  199. data/spec/unit/arbre/html/tag_spec.rb +1 -1
  200. data/spec/unit/arbre/html_spec.rb +32 -22
  201. data/spec/unit/asset_registration_spec.rb +9 -3
  202. data/spec/unit/auto_link_spec.rb +2 -2
  203. data/spec/unit/base_controller_shared_examples.rb +28 -0
  204. data/spec/unit/base_controller_spec.rb +8 -0
  205. data/spec/unit/belongs_to_spec.rb +30 -33
  206. data/spec/unit/comments_spec.rb +45 -15
  207. data/spec/unit/config_shared_examples.rb +119 -0
  208. data/spec/unit/dashboard_controller_spec.rb +44 -0
  209. data/spec/unit/event_spec.rb +6 -0
  210. data/spec/unit/filter_form_builder_spec.rb +9 -0
  211. data/spec/unit/form_builder_spec.rb +8 -14
  212. data/spec/unit/menu_item_spec.rb +25 -20
  213. data/spec/unit/namespace/register_page_spec.rb +102 -0
  214. data/spec/unit/namespace/register_resource_spec.rb +188 -0
  215. data/spec/unit/namespace_spec.rb +11 -183
  216. data/spec/unit/page_controller_spec.rb +8 -0
  217. data/spec/unit/page_spec.rb +60 -0
  218. data/spec/unit/reloader_spec.rb +82 -38
  219. data/spec/unit/resource/menu_spec.rb +1 -51
  220. data/spec/unit/resource/naming_spec.rb +25 -20
  221. data/spec/unit/resource/page_presenters_spec.rb +32 -0
  222. data/spec/unit/resource/scopes_spec.rb +13 -0
  223. data/spec/unit/resource_collection_spec.rb +101 -0
  224. data/spec/unit/resource_controller_spec.rb +40 -32
  225. data/spec/unit/{registration_spec.rb → resource_registration_spec.rb} +0 -0
  226. data/spec/unit/resource_spec.rb +8 -24
  227. data/spec/unit/routing_spec.rb +50 -1
  228. data/spec/unit/scope_spec.rb +18 -4
  229. data/spec/unit/views/components/paginated_collection_spec.rb +163 -0
  230. data/spec/unit/views/components/panel_spec.rb +9 -0
  231. data/spec/unit/views/components/status_tag_spec.rb +9 -0
  232. data/spec/unit/views/tabbed_navigation_spec.rb +2 -1
  233. data/tasks/test.rake +44 -26
  234. metadata +176 -69
  235. data/app/assets/javascripts/active_admin/vendor.js +0 -382
  236. data/lib/active_admin/arbre/core_extensions.rb +0 -5
  237. data/lib/active_admin/comments/configuration.rb +0 -18
  238. data/lib/active_admin/page_config.rb +0 -15
  239. data/lib/active_admin/resource_controller/form.rb +0 -42
  240. data/lib/active_admin/resource_controller/page_configurations.rb +0 -53
  241. data/lib/active_admin/views/pages/edit.rb +0 -28
  242. data/lib/active_admin/views/pages/new.rb +0 -28
  243. data/lib/generators/active_admin/assets/templates/3.0/active_admin.js +0 -427
  244. data/spec/integration/belongs_to_spec.rb +0 -42
@@ -23,4 +23,48 @@ describe ActiveAdmin::Dashboards::DashboardController do
23
23
  end
24
24
  end
25
25
 
26
+ describe "conditionally displaying sections" do
27
+ before { ActiveAdmin::Dashboards.clear_all_sections! }
28
+ let(:controller){ Admin::DashboardController.new }
29
+
30
+ context "when :if not specified" do
31
+ before do
32
+ @section = ActiveAdmin::Dashboards.add_section('Stats').last
33
+ end
34
+
35
+ it "should include section" do
36
+ controller.send(:find_sections).should include(@section)
37
+ end
38
+ end
39
+
40
+ context "when :if option specified as a method" do
41
+ before do
42
+ @section = ActiveAdmin::Dashboards.add_section('Secret Codes', :if => :i_am_awesome?).last
43
+ end
44
+
45
+ it "should call the method of the same name" do
46
+ controller.should_receive(:i_am_awesome?).and_return(true)
47
+ controller.send(:find_sections).should include(@section)
48
+
49
+ controller.should_receive(:i_am_awesome?).and_return(false)
50
+ controller.send(:find_sections).should_not include(@section)
51
+ end
52
+ end
53
+
54
+ context "when :if option specified as block" do
55
+ before do
56
+ @proc = Proc.new { true }
57
+ @section = ActiveAdmin::Dashboards.add_section('Secret Codes', :if => proc {}).last
58
+ end
59
+
60
+ it "should evaluate the block" do
61
+ controller.should_receive(:instance_exec).with(&@proc).and_return(true)
62
+ controller.send(:find_sections).should include(@section)
63
+
64
+ controller.should_receive(:instance_exec).with(&@proc).and_return(false)
65
+ controller.send(:find_sections).should_not include(@section)
66
+ end
67
+ end
68
+ end
69
+
26
70
  end
@@ -12,6 +12,12 @@ describe ActiveAdmin::EventDispatcher do
12
12
  dispatcher.subscribers(test_event).size.should == 1
13
13
  end
14
14
 
15
+ it "should add a subscriber for multiple events" do
16
+ dispatcher.subscribe(test_event, test_event + "1"){ true }
17
+ dispatcher.subscribers(test_event).size.should == 1
18
+ dispatcher.subscribers(test_event + "1").size.should == 1
19
+ end
20
+
15
21
  it "should call the dispatch block with no arguments" do
16
22
  dispatcher.subscribe(test_event){ raise StandardError, "From Event Handler" }
17
23
  lambda {
@@ -56,6 +56,15 @@ describe ActiveAdmin::ViewHelpers::FilterFormHelper do
56
56
  it "should label a text field with search" do
57
57
  body.should have_tag('label', 'Search Title')
58
58
  end
59
+
60
+ it "should translate the label for text field" do
61
+ begin
62
+ I18n.backend.store_translations(:en, :activerecord => { :attributes => { :post => { :title => "Name" } } })
63
+ body.should have_tag('label', 'Search Name')
64
+ ensure
65
+ I18n.backend.reload!
66
+ end
67
+ end
59
68
  end
60
69
 
61
70
  describe "text attribute" do
@@ -65,19 +65,13 @@ describe ActiveAdmin::FormBuilder do
65
65
  end
66
66
 
67
67
  context "when polymorphic relationship" do
68
-
69
- let(:body) do
70
- comment = ActiveAdmin::Comment.new
71
-
72
- active_admin_form_for comment, :url => "admins/comments" do |f|
73
- f.inputs :resource
74
- end
75
-
76
- end
77
-
78
- it "should not generate any field" do
79
- body.should have_tag("form", :attributes => { :method => 'post' })
80
- body.should_not have_tag("select")
68
+ it "should raise error" do
69
+ lambda {
70
+ comment = ActiveAdmin::Comment.new
71
+ active_admin_form_for comment, :url => "admins/comments" do |f|
72
+ f.inputs :resource
73
+ end
74
+ }.should raise_error(Formtastic::PolymorphicInputWithoutCollectionError)
81
75
  end
82
76
  end
83
77
 
@@ -215,7 +209,7 @@ describe ActiveAdmin::FormBuilder do
215
209
  body = build_form do |f|
216
210
  f.input :title, :wrapper_html => { :class => "important" }
217
211
  end
218
- body.should have_tag("li", :attributes => {:class => "string optional important"})
212
+ body.should have_tag("li", :attributes => {:class => "important string input optional stringish"})
219
213
  end
220
214
  end
221
215
 
@@ -1,4 +1,5 @@
1
- require 'spec_helper'
1
+ require 'spec_helper_without_rails'
2
+ require 'active_admin/menu_item'
2
3
 
3
4
  module ActiveAdmin
4
5
  describe MenuItem do
@@ -7,27 +8,27 @@ module ActiveAdmin
7
8
  item = MenuItem.new("Dashboard", "/admin")
8
9
  item.name.should == "Dashboard"
9
10
  end
10
-
11
+
11
12
  it "should have a url" do
12
13
  item = MenuItem.new("Dashboard", "/admin")
13
14
  item.url.should == "/admin"
14
15
  end
15
-
16
+
16
17
  it "should have a priority of 10 by default" do
17
18
  item = MenuItem.new("Dashboard", "/admin")
18
19
  item.priority.should == 10
19
20
  end
20
-
21
+
21
22
  it "should accept an optional options hash" do
22
23
  item = MenuItem.new("Dashboard", "/admin", 10, :if => lambda{ logged_in? } )
23
24
  end
24
-
25
+
25
26
  it "should have a display if block" do
26
27
  block = lambda{ logged_in? }
27
28
  item = MenuItem.new("Dashboard", "/admin", 10, :if => block )
28
29
  item.display_if_block.should == block
29
30
  end
30
-
31
+
31
32
  it "should have a default display if block always returning true" do
32
33
  item = MenuItem.new("Dashboard", "/admin")
33
34
  item.display_if_block.should be_instance_of(Proc)
@@ -36,20 +37,24 @@ module ActiveAdmin
36
37
 
37
38
  describe "url generation and caching" do
38
39
  it "should generate a url if it is a symbol" do
39
- MenuItem.new("Posts", :admin_posts_path).url.should == "/admin/posts"
40
+ item = MenuItem.new("Posts", :admin_posts_path)
41
+ MenuItem.should_receive(:generate_url).with(:admin_posts_path).
42
+ and_return("/admin/posts")
43
+
44
+ item.url.should == "/admin/posts"
40
45
  end
41
46
 
42
47
  it "should generate a url if it is a string" do
43
48
  MenuItem.new("Posts", "/admin/posts").url.should == "/admin/posts"
44
49
  end
45
50
  end
46
-
51
+
47
52
  context "with no children" do
48
53
  it "should be empty" do
49
54
  item = MenuItem.new("Blog", "/admin/blog")
50
55
  item.children.should == []
51
56
  end
52
-
57
+
53
58
  it "should accept new children" do
54
59
  item = MenuItem.new("Blog", "/admin/blog")
55
60
  item.add "Dashboard", "/admin"
@@ -57,7 +62,7 @@ module ActiveAdmin
57
62
  item.children.first.name.should == "Dashboard"
58
63
  end
59
64
  end
60
-
65
+
61
66
  context "with many children" do
62
67
  let(:item) do
63
68
  i = MenuItem.new("Dashboard", "/admin")
@@ -68,11 +73,11 @@ module ActiveAdmin
68
73
  i.add "Analytics", "/", 44
69
74
  i
70
75
  end
71
-
76
+
72
77
  it "should give access to the menu item as an array" do
73
78
  item['Blog'].name.should == 'Blog'
74
79
  end
75
-
80
+
76
81
  it "should sort items based on priority and name" do
77
82
  item.children[0].name.should == 'Users'
78
83
  item.children[1].name.should == 'Settings'
@@ -80,12 +85,12 @@ module ActiveAdmin
80
85
  item.children[3].name.should == 'Cars'
81
86
  item.children[4].name.should == 'Analytics'
82
87
  end
83
-
88
+
84
89
  it "children should hold a reference to their parent" do
85
90
  item["Blog"].parent.should == item
86
91
  end
87
92
  end
88
-
93
+
89
94
  describe "building children using block syntax" do
90
95
  let(:item) do
91
96
  MenuItem.new("Blog", "/") do |blog|
@@ -95,25 +100,25 @@ module ActiveAdmin
95
100
  end
96
101
  end
97
102
  end
98
-
103
+
99
104
  it "should have 2 children" do
100
105
  item.children.size.should == 2
101
106
  end
102
-
107
+
103
108
  it "should have sub-sub items" do
104
109
  item["Comments"]["Approved"].name.should == 'Approved'
105
110
  end
106
111
  end
107
-
112
+
108
113
  describe "accessing ancestory" do
109
114
  let(:item){ MenuItem.new "Blog", "/blog" }
110
-
115
+
111
116
  context "with no parent" do
112
117
  it "should return an empty array" do
113
118
  item.ancestors.should == []
114
119
  end
115
120
  end
116
-
121
+
117
122
  context "with one parent" do
118
123
  let(:sub_item) do
119
124
  item.add "Create New", "/blog/new"
@@ -123,7 +128,7 @@ module ActiveAdmin
123
128
  sub_item.ancestors.should == [item]
124
129
  end
125
130
  end
126
-
131
+
127
132
  context "with many parents" do
128
133
  before(:each) do
129
134
  item.add "C1", "/c1" do |c1|
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveAdmin::Namespace, "registering a page" do
4
+
5
+ let(:application){ ActiveAdmin::Application.new }
6
+
7
+ let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
8
+
9
+ context "with no configuration" do
10
+ before do
11
+ namespace.register_page "Status"
12
+ end
13
+
14
+ it "should store the namespaced registered configuration" do
15
+ namespace.resources.keys.should include('Status')
16
+ end
17
+
18
+ it "should create a new controller in the default namespace" do
19
+ defined?(Admin::StatusController).should be_true
20
+ end
21
+
22
+ it "should create a menu item" do
23
+ namespace.load_menu!
24
+ namespace.menu["Status"].should be_an_instance_of(ActiveAdmin::MenuItem)
25
+ end
26
+ end # context "with no configuration"
27
+
28
+ context "with a block configuration" do
29
+ it "should be evaluated in the dsl" do
30
+ lambda {
31
+ namespace.register_page "Status" do
32
+ raise "Hello World"
33
+ end
34
+ }.should raise_error
35
+ end
36
+ end # context "with a block configuration"
37
+
38
+ describe "adding to the menu" do
39
+ describe "adding as a top level item" do
40
+ before do
41
+ namespace.register_page "Status"
42
+ namespace.load_menu!
43
+ end
44
+
45
+ it "should add a new menu item" do
46
+ namespace.menu['Status'].should_not be_nil
47
+ end
48
+ end # describe "adding as a top level item"
49
+
50
+ describe "adding as a child" do
51
+ before do
52
+ namespace.register_page "Status" do
53
+ menu :parent => 'Extra'
54
+ end
55
+ namespace.load_menu!
56
+ end
57
+ it "should generate the parent menu item" do
58
+ namespace.menu['Extra'].should_not be_nil
59
+ end
60
+ it "should generate its own child item" do
61
+ namespace.menu['Extra']['Status'].should_not be_nil
62
+ end
63
+ end # describe "adding as a child"
64
+
65
+ describe "disabling the menu" do
66
+ before do
67
+ namespace.register_page "Status" do
68
+ menu false
69
+ end
70
+ namespace.load_menu!
71
+ end
72
+ it "should not create a menu item" do
73
+ namespace.menu["Status"].should be_nil
74
+ end
75
+ end # describe "disabling the menu"
76
+
77
+ describe "setting menu priority" do
78
+ before do
79
+ namespace.register_page "Status" do
80
+ menu :priority => 2
81
+ end
82
+ namespace.load_menu!
83
+ end
84
+ it "should have a custom priority of 2" do
85
+ namespace.menu["Status"].priority.should == 2
86
+ end
87
+ end # describe "setting menu priority"
88
+
89
+ describe "setting a condition for displaying" do
90
+ before do
91
+ namespace.register_page "Status" do
92
+ menu :if => proc { false }
93
+ end
94
+ namespace.load_menu!
95
+ end
96
+ it "should have a proc returning false" do
97
+ namespace.menu["Status"].display_if_block.should be_instance_of(Proc)
98
+ namespace.menu["Status"].display_if_block.call.should == false
99
+ end
100
+ end # describe "setting a condition for displaying"
101
+ end # describe "adding to the menu"
102
+ end
@@ -0,0 +1,188 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveAdmin::Namespace, "registering a resource" do
4
+
5
+ let(:application){ ActiveAdmin::Application.new }
6
+
7
+ let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
8
+
9
+ context "with no configuration" do
10
+ before do
11
+ namespace.register Category
12
+ end
13
+ it "should store the namespaced registered configuration" do
14
+ namespace.resources.keys.should include('Category')
15
+ end
16
+ it "should create a new controller in the default namespace" do
17
+ defined?(Admin::CategoriesController).should be_true
18
+ end
19
+ it "should create the dashboard controller" do
20
+ defined?(Admin::DashboardController).should be_true
21
+ end
22
+ it "should create a menu item" do
23
+ namespace.load_menu!
24
+ namespace.menu["Categories"].should be_an_instance_of(ActiveAdmin::MenuItem)
25
+ namespace.menu["Categories"].url.should == "/admin/categories"
26
+ end
27
+ end # context "with no configuration"
28
+
29
+ context "with a block configuration" do
30
+ it "should be evaluated in the dsl" do
31
+ lambda {
32
+ namespace.register Category do
33
+ raise "Hello World"
34
+ end
35
+ }.should raise_error
36
+ end
37
+ end # context "with a block configuration"
38
+
39
+ context "with a resource that's namespaced" do
40
+ before do
41
+ module ::Mock; class Resource; def self.has_many(arg1, arg2); end; end; end
42
+ namespace.register Mock::Resource
43
+ end
44
+
45
+ it "should store the namespaced registered configuration" do
46
+ namespace.resources.keys.should include('MockResource')
47
+ end
48
+ it "should create a new controller in the default namespace" do
49
+ defined?(Admin::MockResourcesController).should be_true
50
+ end
51
+ it "should create a menu item" do
52
+ namespace.load_menu!
53
+ namespace.menu["Mock Resources"].should be_an_instance_of(ActiveAdmin::MenuItem)
54
+ end
55
+
56
+ it "should use the resource as the model in the controller" do
57
+ Admin::MockResourcesController.resource_class.should == Mock::Resource
58
+ end
59
+
60
+ end # context "with a resource that's namespaced"
61
+
62
+ describe "finding resource instances" do
63
+ let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
64
+
65
+ it "should return the resource when its been registered" do
66
+ post = namespace.register Post
67
+ namespace.resource_for(Post).should == post
68
+ end
69
+
70
+ it 'should return nil when the resource has not been registered' do
71
+ namespace.resource_for(Post).should == nil
72
+ end
73
+
74
+ it "should return the parent when the parent class has been registered and the child has not" do
75
+ user = namespace.register User
76
+ namespace.resource_for(Publisher).should == user
77
+ end
78
+
79
+ it "should return the resource if it and it's parent were registered" do
80
+ user = namespace.register User
81
+ publisher = namespace.register Publisher
82
+ namespace.resource_for(Publisher).should == publisher
83
+ end
84
+
85
+ end # describe "finding resource instances"
86
+
87
+ describe "adding to the menu" do
88
+ describe "adding as a top level item" do
89
+ before do
90
+ namespace.register Category
91
+ namespace.load_menu!
92
+ end
93
+ it "should add a new menu item" do
94
+ namespace.menu['Categories'].should_not be_nil
95
+ end
96
+ end # describe "adding as a top level item"
97
+
98
+ describe "adding as a child" do
99
+ before do
100
+ namespace.register Category do
101
+ menu :parent => 'Blog'
102
+ end
103
+ namespace.load_menu!
104
+ end
105
+ it "should generate the parent menu item" do
106
+ namespace.menu['Blog'].should_not be_nil
107
+ end
108
+ it "should generate its own child item" do
109
+ namespace.menu['Blog']['Categories'].should_not be_nil
110
+ end
111
+ end # describe "adding as a child"
112
+
113
+ describe "disabling the menu" do
114
+ before do
115
+ namespace.register Category do
116
+ menu false
117
+ end
118
+ namespace.load_menu!
119
+ end
120
+ it "should not create a menu item" do
121
+ namespace.menu["Categories"].should be_nil
122
+ end
123
+ end # describe "disabling the menu"
124
+
125
+ describe "setting menu priority" do
126
+ before do
127
+ namespace.register Category do
128
+ menu :priority => 2
129
+ end
130
+ namespace.load_menu!
131
+ end
132
+ it "should have a custom priority of 2" do
133
+ namespace.menu["Categories"].priority.should == 2
134
+ end
135
+ end # describe "setting menu priority"
136
+
137
+ describe "setting a condition for displaying" do
138
+ before do
139
+ namespace.register Category do
140
+ menu :if => proc { false }
141
+ end
142
+ namespace.load_menu!
143
+ end
144
+ it "should have a proc returning false" do
145
+ namespace.menu["Categories"].display_if_block.should be_instance_of(Proc)
146
+ namespace.menu["Categories"].display_if_block.call.should == false
147
+ end
148
+ end # describe "setting a condition for displaying"
149
+
150
+ describe "adding as a belongs to" do
151
+ context "when not optional" do
152
+ before do
153
+ namespace.register Post do
154
+ belongs_to :author
155
+ end
156
+ end
157
+ it "should not show up in the menu" do
158
+ namespace.menu["Posts"].should be_nil
159
+ end
160
+ end
161
+ context "when optional" do
162
+ before do
163
+ namespace.register Post do
164
+ belongs_to :author, :optional => true
165
+ end
166
+ end
167
+ it "should show up in the menu" do
168
+ namespace.menu["Posts"].should_not be_nil
169
+ end
170
+ end
171
+ end
172
+ end # describe "adding to the menu"
173
+
174
+ describe "dashboard controller name" do
175
+ context "when namespaced" do
176
+ it "should be namespaced" do
177
+ namespace = ActiveAdmin::Namespace.new(application, :admin)
178
+ namespace.dashboard_controller_name.should == "Admin::DashboardController"
179
+ end
180
+ end
181
+ context "when not namespaced" do
182
+ it "should not be namespaced" do
183
+ namespace = ActiveAdmin::Namespace.new(application, :root)
184
+ namespace.dashboard_controller_name.should == "DashboardController"
185
+ end
186
+ end
187
+ end # describe "dashboard controller name"
188
+ end # describe "registering a resource"