activeadmin 0.5.1 → 0.6.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 (196) hide show
  1. data/.travis.yml +8 -5
  2. data/CHANGELOG.md +151 -0
  3. data/Gemfile +16 -16
  4. data/LICENSE +1 -1
  5. data/activeadmin.gemspec +1 -0
  6. data/app/assets/images/active_admin/index_list_icons/block_icon.svg +10 -0
  7. data/app/assets/images/active_admin/index_list_icons/blog_icon.svg +4 -0
  8. data/app/assets/images/active_admin/index_list_icons/grid_icon.svg +13 -0
  9. data/app/assets/images/active_admin/index_list_icons/table_icon.svg +3 -0
  10. data/app/assets/javascripts/active_admin/components/jquery.aa.checkbox-toggler.js.coffee +17 -44
  11. data/app/assets/javascripts/active_admin/components/jquery.aa.dropdown-menu.js.coffee +2 -4
  12. data/app/assets/javascripts/active_admin/components/jquery.aa.popover.js.coffee +0 -3
  13. data/app/assets/javascripts/active_admin/components/jquery.aa.table-checkbox-toggler.js.coffee +10 -12
  14. data/app/assets/javascripts/active_admin/pages/application.js.coffee +13 -10
  15. data/app/assets/javascripts/active_admin/pages/batch_actions.js.coffee +3 -3
  16. data/app/assets/stylesheets/active_admin/_base.css.scss +1 -0
  17. data/app/assets/stylesheets/active_admin/_header.css.scss +5 -2
  18. data/app/assets/stylesheets/active_admin/components/_dropdown_menu.scss +2 -2
  19. data/app/assets/stylesheets/active_admin/components/_index_list.scss +12 -0
  20. data/app/assets/stylesheets/active_admin/components/_popovers.css.scss +2 -2
  21. data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +2 -2
  22. data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +4 -4
  23. data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +5 -4
  24. data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +1 -1
  25. data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +1 -1
  26. data/app/assets/stylesheets/active_admin/print.css.scss +2 -2
  27. data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +1 -1
  28. data/app/views/active_admin/devise/unlocks/new.html.erb +14 -12
  29. data/docs/1-general-configuration.md +13 -0
  30. data/docs/10-custom-pages.md +40 -28
  31. data/docs/11-decorators.md +6 -4
  32. data/docs/12-arbre-components.md +1 -1
  33. data/docs/13-authorization-adapter.md +206 -0
  34. data/docs/2-resource-customization.md +129 -14
  35. data/docs/3-index-pages.md +65 -0
  36. data/docs/3-index-pages/create-an-index.md +29 -0
  37. data/docs/3-index-pages/index-as-table.md +35 -11
  38. data/docs/5-forms.md +2 -2
  39. data/features/authorization.feature +64 -0
  40. data/features/authorization_cancan.feature +52 -0
  41. data/features/belongs_to.feature +41 -5
  42. data/features/index/batch_actions.feature +27 -3
  43. data/features/index/formats.feature +27 -0
  44. data/features/index/index_as_table.feature +74 -2
  45. data/features/index/index_parameters.feature +69 -0
  46. data/features/index/index_scopes.feature +7 -11
  47. data/features/index/page_title.feature +18 -0
  48. data/features/index/switch_index_view.feature +73 -0
  49. data/features/menu.feature +27 -0
  50. data/features/registering_pages.feature +21 -0
  51. data/features/step_definitions/additional_web_steps.rb +4 -0
  52. data/features/step_definitions/batch_action_steps.rb +16 -6
  53. data/features/step_definitions/index_scope_steps.rb +3 -3
  54. data/features/step_definitions/index_views_steps.rb +3 -0
  55. data/features/step_definitions/menu_steps.rb +4 -0
  56. data/features/support/env.rb +4 -0
  57. data/features/support/paths.rb +3 -0
  58. data/lib/active_admin.rb +4 -0
  59. data/lib/active_admin/application.rb +43 -76
  60. data/lib/active_admin/authorization_adapter.rb +128 -0
  61. data/lib/active_admin/base_controller.rb +18 -1
  62. data/lib/active_admin/base_controller/authorization.rb +153 -0
  63. data/lib/active_admin/base_controller/menu.rb +8 -3
  64. data/lib/active_admin/batch_actions/resource_extension.rb +8 -7
  65. data/lib/active_admin/batch_actions/views/batch_action_form.rb +1 -1
  66. data/lib/active_admin/cancan_adapter.rb +40 -0
  67. data/lib/active_admin/dashboards.rb +4 -5
  68. data/lib/active_admin/dashboards/dashboard_controller.rb +1 -1
  69. data/lib/active_admin/devise.rb +22 -7
  70. data/lib/active_admin/dsl.rb +18 -5
  71. data/lib/active_admin/engine.rb +1 -1
  72. data/lib/active_admin/filters/dsl.rb +1 -1
  73. data/lib/active_admin/filters/forms.rb +9 -7
  74. data/lib/active_admin/filters/resource_extension.rb +20 -15
  75. data/lib/active_admin/form_builder.rb +44 -49
  76. data/lib/active_admin/helpers/optional_display.rb +4 -8
  77. data/lib/active_admin/inputs/filter_boolean_input.rb +1 -1
  78. data/lib/active_admin/inputs/filter_string_input.rb +5 -1
  79. data/lib/active_admin/locales/bg.yml +1 -1
  80. data/lib/active_admin/locales/ca.yml +1 -1
  81. data/lib/active_admin/locales/cs.yml +26 -25
  82. data/lib/active_admin/locales/da.yml +1 -1
  83. data/lib/active_admin/locales/de.yml +1 -1
  84. data/lib/active_admin/locales/en.yml +11 -1
  85. data/lib/active_admin/locales/es.yml +16 -16
  86. data/lib/active_admin/locales/fr.yml +1 -1
  87. data/lib/active_admin/locales/he.yml +1 -1
  88. data/lib/active_admin/locales/hr.yml +1 -1
  89. data/lib/active_admin/locales/hu.yml +1 -1
  90. data/lib/active_admin/locales/it.yml +1 -1
  91. data/lib/active_admin/locales/ja.yml +4 -1
  92. data/lib/active_admin/locales/ko.yml +1 -1
  93. data/lib/active_admin/locales/lt.yml +1 -1
  94. data/lib/active_admin/locales/lv.yml +12 -1
  95. data/lib/active_admin/locales/nl.yml +2 -2
  96. data/lib/active_admin/locales/no-NB.yml +22 -1
  97. data/lib/active_admin/locales/pl.yml +1 -1
  98. data/lib/active_admin/locales/pt-BR.yml +1 -1
  99. data/lib/active_admin/locales/pt-PT.yml +81 -0
  100. data/lib/active_admin/locales/ro.yml +1 -1
  101. data/lib/active_admin/locales/ru.yml +1 -1
  102. data/lib/active_admin/locales/sv-SE.yml +1 -1
  103. data/lib/active_admin/locales/tr.yml +1 -1
  104. data/lib/active_admin/locales/vi.yml +1 -1
  105. data/lib/active_admin/locales/zh-CN.yml +1 -1
  106. data/lib/active_admin/locales/zh-TW.yml +1 -1
  107. data/lib/active_admin/menu.rb +76 -38
  108. data/lib/active_admin/menu_collection.rb +96 -0
  109. data/lib/active_admin/menu_item.rb +61 -71
  110. data/lib/active_admin/namespace.rb +67 -5
  111. data/lib/active_admin/page.rb +6 -0
  112. data/lib/active_admin/page_controller.rb +13 -3
  113. data/lib/active_admin/resource.rb +11 -20
  114. data/lib/active_admin/resource/action_items.rb +3 -3
  115. data/lib/active_admin/resource/controllers.rb +0 -17
  116. data/lib/active_admin/resource/menu.rb +52 -24
  117. data/lib/active_admin/resource/naming.rb +6 -10
  118. data/lib/active_admin/resource/page_presenters.rb +57 -3
  119. data/lib/active_admin/resource/routes.rb +46 -0
  120. data/lib/active_admin/resource_controller.rb +2 -17
  121. data/lib/active_admin/resource_controller/data_access.rb +299 -0
  122. data/lib/active_admin/resource_controller/decorators.rb +2 -1
  123. data/lib/active_admin/resource_dsl.rb +12 -14
  124. data/lib/active_admin/router.rb +61 -56
  125. data/lib/active_admin/scope.rb +28 -18
  126. data/lib/active_admin/version.rb +1 -1
  127. data/lib/active_admin/view_factory.rb +0 -1
  128. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +13 -19
  129. data/lib/active_admin/view_helpers/fields_for.rb +2 -0
  130. data/lib/active_admin/view_helpers/form_helper.rb +1 -1
  131. data/lib/active_admin/view_helpers/method_or_proc_helper.rb +66 -11
  132. data/lib/active_admin/views/components/attributes_table.rb +7 -4
  133. data/lib/active_admin/views/components/index_list.rb +68 -0
  134. data/lib/active_admin/views/components/paginated_collection.rb +13 -9
  135. data/lib/active_admin/views/components/scopes.rb +2 -8
  136. data/lib/active_admin/views/components/table_for.rb +1 -1
  137. data/lib/active_admin/views/footer.rb +1 -1
  138. data/lib/active_admin/views/header.rb +3 -2
  139. data/lib/active_admin/views/index_as_block.rb +4 -0
  140. data/lib/active_admin/views/index_as_blog.rb +4 -0
  141. data/lib/active_admin/views/index_as_grid.rb +4 -0
  142. data/lib/active_admin/views/index_as_table.rb +49 -7
  143. data/lib/active_admin/views/pages/index.rb +19 -4
  144. data/lib/active_admin/views/tabbed_navigation.rb +10 -54
  145. data/lib/generators/active_admin/install/install_generator.rb +5 -1
  146. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +58 -0
  147. data/spec/integration/{default_namespace.rb → default_namespace_spec.rb} +0 -16
  148. data/spec/spec_helper.rb +3 -0
  149. data/spec/support/detect_rails_version.rb +10 -3
  150. data/spec/support/rails_template.rb +1 -1
  151. data/spec/support/templates/post_decorator.rb +6 -6
  152. data/spec/unit/application_spec.rb +5 -5
  153. data/spec/unit/authorization/authorization_adapter_spec.rb +61 -0
  154. data/spec/unit/authorization/controller_authorization_spec.rb +47 -0
  155. data/spec/unit/base_controller_spec.rb +0 -2
  156. data/spec/unit/batch_actions/resource_spec.rb +1 -1
  157. data/spec/unit/breadcrumbs_spec.rb +3 -3
  158. data/spec/unit/cancan_adapter_spec.rb +35 -0
  159. data/spec/unit/config_shared_examples.rb +9 -30
  160. data/spec/unit/devise_spec.rb +29 -0
  161. data/spec/unit/dsl_spec.rb +61 -0
  162. data/spec/unit/filters/filter_form_builder_spec.rb +58 -4
  163. data/spec/unit/filters/resource_spec.rb +17 -5
  164. data/spec/unit/form_builder_spec.rb +15 -0
  165. data/spec/unit/menu_collection_spec.rb +62 -0
  166. data/spec/unit/menu_item_spec.rb +51 -37
  167. data/spec/unit/menu_spec.rb +33 -29
  168. data/spec/unit/namespace/authorization_spec.rb +31 -0
  169. data/spec/unit/namespace/register_page_spec.rb +6 -28
  170. data/spec/unit/namespace/register_resource_spec.rb +11 -34
  171. data/spec/unit/namespace_spec.rb +63 -2
  172. data/spec/unit/page_controller_spec.rb +0 -3
  173. data/spec/unit/reloader_spec.rb +5 -5
  174. data/spec/unit/resource/menu_spec.rb +1 -13
  175. data/spec/unit/resource/naming_spec.rb +20 -2
  176. data/spec/unit/resource/page_presenters_spec.rb +14 -2
  177. data/spec/unit/resource_controller/{collection_spec.rb → data_access_spec.rb} +31 -13
  178. data/spec/unit/resource_controller_spec.rb +4 -5
  179. data/spec/unit/resource_spec.rb +33 -11
  180. data/spec/unit/routing_spec.rb +43 -0
  181. data/spec/unit/scope_spec.rb +13 -0
  182. data/spec/unit/view_factory_spec.rb +0 -1
  183. data/spec/unit/view_helpers/fields_for_spec.rb +4 -0
  184. data/spec/unit/view_helpers/form_helper_spec.rb +6 -2
  185. data/spec/unit/view_helpers/method_or_proc_helper_spec.rb +97 -0
  186. data/spec/unit/views/components/attributes_table_spec.rb +11 -0
  187. data/spec/unit/views/components/index_list_spec.rb +32 -0
  188. data/spec/unit/views/tabbed_navigation_spec.rb +42 -40
  189. data/tasks/test.rake +1 -1
  190. metadata +127 -40
  191. data/lib/active_admin/menu_builder.rb +0 -65
  192. data/lib/active_admin/resource_controller/callbacks.rb +0 -59
  193. data/lib/active_admin/resource_controller/collection.rb +0 -158
  194. data/lib/active_admin/views/utility_nav.rb +0 -41
  195. data/spec/unit/base_controller_shared_examples.rb +0 -25
  196. data/spec/unit/dsl_include_spec.rb +0 -20
@@ -10,3 +10,72 @@ Feature: Index Parameters
10
10
  Given 31 posts exist
11
11
  When I am on the index page for posts
12
12
  Then I should not see a link to download "CSV"
13
+
14
+ Scenario: Viewing index when download_links disabled globally
15
+ Given a configuration of:
16
+ """
17
+ ActiveAdmin.application.download_links = false
18
+ """
19
+ Given an index configuration of:
20
+ """
21
+ ActiveAdmin.register Post do
22
+ index :as => :table
23
+ end
24
+ """
25
+ Given 1 posts exist
26
+ When I am on the index page for posts
27
+ Then I should be on the index page for posts
28
+ Then I should not see a link to download "CSV"
29
+ Given a configuration of:
30
+ """
31
+ ActiveAdmin.application.download_links = true
32
+ """
33
+
34
+ Scenario: Viewing index when download_links disabled only in one namespace
35
+ Given a configuration of:
36
+ """
37
+ ActiveAdmin.setup do |config|
38
+ config.namespace :superadmin do |namespace|
39
+ namespace.download_links = false
40
+ end
41
+ end
42
+ """
43
+ Given an index configuration of:
44
+ """
45
+ ActiveAdmin.register Post do
46
+ index :as => :table
47
+ end
48
+ ActiveAdmin.register Post, :namespace => :superadmin do
49
+ index :as => :table
50
+ end
51
+ """
52
+ Given 1 posts exist
53
+ When I am on the index page for posts in the superadmin namespace
54
+ Then I should be on the index page for posts in the superadmin namespace
55
+ Then I should not see a link to download "CSV"
56
+ When I am on the index page for posts
57
+ Then I should be on the index page for posts
58
+ Then I should see a link to download "CSV"
59
+
60
+ Scenario: Viewing index when download_links enabled only for a resource
61
+ Given a configuration of:
62
+ """
63
+ ActiveAdmin.setup do |config|
64
+ config.namespace :superadmin do |namespace|
65
+ namespace.download_links = false
66
+ end
67
+ end
68
+ """
69
+ Given an index configuration of:
70
+ """
71
+ ActiveAdmin.register Post do
72
+ index :as => :table
73
+ end
74
+ ActiveAdmin.register Post, :namespace => :superadmin do
75
+ index :as => :table, :download_links => true
76
+ end
77
+ """
78
+ Given 1 posts exist
79
+ When I am on the index page for posts in the superadmin namespace
80
+ Then I should be on the index page for posts in the superadmin namespace
81
+ Then I should see a link to download "CSV"
@@ -26,21 +26,17 @@ Feature: Index Scoping
26
26
  And I should see the scope "All" with the count 3
27
27
  And I should see 3 posts in the table
28
28
 
29
- Scenario: Viewing resources with one scope and no results
29
+ Scenario: Viewing resources with a scope and no results
30
30
  Given 3 posts exist
31
31
  And an index configuration of:
32
- """
33
- ActiveAdmin.register Post do
34
- scope :all, :default => true
35
- filter :title
36
- end
37
- """
38
-
32
+ """
33
+ ActiveAdmin.register Post do
34
+ scope :all, :default => true
35
+ filter :title
36
+ end
37
+ """
39
38
  When I fill in "Search Title" with "Non Existing Post"
40
39
  And I press "Filter"
41
- And I should not see the scope "All"
42
-
43
- When I am on the index page for posts
44
40
  Then I should see the scope "All" selected
45
41
 
46
42
  Scenario: Viewing resources with a scope but scope_count turned off
@@ -10,3 +10,21 @@ Feature: Index - Page Title
10
10
  end
11
11
  """
12
12
  Then I should see the page title "Awesome Title"
13
+
14
+ Scenario: Set the title using a proc
15
+ Given an index configuration of:
16
+ """
17
+ ActiveAdmin.register Post do
18
+ index :title => proc{ 'Custom title from proc' }
19
+ end
20
+ """
21
+ Then I should see the page title "Custom title from proc"
22
+
23
+ Scenario: Set the title using a proc that uses the available resource class
24
+ Given an index configuration of:
25
+ """
26
+ ActiveAdmin.register Post do
27
+ index :title => proc{ "List of #{resource_class.model_name.plural}" }
28
+ end
29
+ """
30
+ Then I should see the page title "List of posts"
@@ -0,0 +1,73 @@
1
+ Feature: Switch Index View
2
+
3
+ In order to switch index views
4
+ As a user
5
+ I want to view links to views
6
+
7
+ Scenario: Show default Page Presenter
8
+ Given a post with the title "Hello World from Table" exists
9
+ And an index configuration of:
10
+ """
11
+ ActiveAdmin.register Post do
12
+ index :as => :table do
13
+ column :title
14
+ end
15
+ index :as => :block do |post|
16
+ span(link_to(post.title, admin_post_path(post)))
17
+ end
18
+ end
19
+ """
20
+ Then I should see "Hello World from Table" within ".index_as_table"
21
+
22
+ Scenario: Show default Page Presenter when default is specified
23
+ Given a post with the title "Hello World from Table" exists
24
+ And an index configuration of:
25
+ """
26
+ ActiveAdmin.register Post do
27
+ index :as => :block do |post|
28
+ span(link_to(post.title, admin_post_path(post)))
29
+ end
30
+ index :as => :table, :default => true do
31
+ column :title
32
+ end
33
+ end
34
+ """
35
+ Then I should see "Hello World from Table" within ".index_as_table"
36
+
37
+ Scenario: Show links to different page views
38
+ Given a post with the title "Hello World from Table" exists
39
+ And an index configuration of:
40
+ """
41
+ ActiveAdmin.register Post do
42
+ index :as => :block do |post|
43
+ span(link_to(post.title, admin_post_path(post)))
44
+ end
45
+ index :as => :table, :default => true do
46
+ column :title
47
+ end
48
+ end
49
+ """
50
+ Then I should see "Hello World from Table" within ".index_as_table"
51
+ And I should see a link to "Table"
52
+ And I should see a link to "List"
53
+
54
+ Scenario: Show change between page views
55
+ Given a post with the title "Hey from Table" and body "My body is awesome" exists
56
+ And an index configuration of:
57
+ """
58
+ ActiveAdmin.register Post do
59
+ index :as => :block do |post|
60
+ span(link_to(post.title, admin_post_path(post)))
61
+ end
62
+ index :as => :table, :default => true do
63
+ column :title
64
+ column :body
65
+ end
66
+ end
67
+ """
68
+ Then I should see "My body is awesome" within ".index_as_table"
69
+ When I click "List"
70
+ Then I should not see "My body is awesome" within ".index_as_block"
71
+
72
+
73
+
@@ -24,3 +24,30 @@ Feature: Menu
24
24
  Then I should see a menu item for "Articles"
25
25
  And I should not see a menu item for "Posts"
26
26
 
27
+ Scenario: Add a non-resource menu item
28
+ Given a configuration of:
29
+ """
30
+ ActiveAdmin.application.namespace :admin do |admin|
31
+ admin.build_menu do |menu|
32
+ menu.add :label => "Custom Menu", :url => :admin_dashboard_path
33
+ end
34
+ end
35
+ """
36
+ When I am on the dashboard
37
+ Then I should see a menu item for "Custom Menu"
38
+ When I follow "Custom Menu"
39
+ Then I should be on the admin dashboard page
40
+
41
+ Scenario: Adding a resource as a sub menu item
42
+ Given a configuration of:
43
+ """
44
+ ActiveAdmin.register User
45
+ ActiveAdmin.register Post do
46
+ menu :parent => 'User'
47
+ end
48
+ """
49
+ When I am on the dashboard
50
+ Then I should see a menu item for "Users"
51
+ When I follow "Users"
52
+ Then the "Users" tab should be selected
53
+ And I should see a nested menu item for "Posts"
@@ -123,5 +123,26 @@ Feature: Registering Pages
123
123
  And I follow "Status"
124
124
  And I follow "Check"
125
125
  Then I should see the content "Chocolate I lØve You!"
126
+ And I should see the Active Admin layout
126
127
 
128
+ Scenario: Adding a page action to a page with erb view
129
+ Given a configuration of:
130
+ """
131
+ ActiveAdmin.register_page "Status" do
132
+ page_action :check do
133
+ end
127
134
 
135
+ content do
136
+ ("Chocolate I lØve You!" + link_to("Check", admin_status_check_path)).html_safe
137
+ end
138
+ end
139
+ """
140
+ Given "app/views/admin/status/check.html.erb" contains:
141
+ """
142
+ <div>Chocolate lØves You Too!</div>
143
+ """
144
+ When I go to the dashboard
145
+ And I follow "Status"
146
+ And I follow "Check"
147
+ Then I should see the content "Chocolate lØves You Too!"
148
+ And I should see the Active Admin layout
@@ -89,3 +89,7 @@ end
89
89
  Then /^I should see a validation error "([^"]*)"$/ do |error_message|
90
90
  page.should have_css(".inline-errors", :text => error_message)
91
91
  end
92
+
93
+ Then /^I should see a table with id "([^"]*)"$/ do |dom_id|
94
+ page.should have_css('table', :id => dom_id)
95
+ end
@@ -29,7 +29,7 @@ Then /^the (\d+)(?:st|nd|rd|th) batch action should be "([^"]*)"$/ do |index, ti
29
29
  within "#batch_actions_selector" do
30
30
  page.all( "a.batch_action" )[index.to_i - 1].text.should match( title )
31
31
  end
32
- end
32
+ end
33
33
 
34
34
  When /^I check the (\d+)(?:st|nd|rd|th) record$/ do |index|
35
35
  page.all( "table.index_table input[type=checkbox]" )[index.to_i].set( true )
@@ -39,7 +39,7 @@ When /^I uncheck the (\d+)(?:st|nd|rd|th) record$/ do |index|
39
39
  page.all( "table.index_table input[type='checkbox']" )[index.to_i].set( false )
40
40
  end
41
41
 
42
- When /^I toggle the collection selection$/ do
42
+ When /^I toggle the collection selection$/ do
43
43
  toggle_box = page.find( "#collection_selection_toggle_all" )
44
44
  toggle_box.click
45
45
  end
@@ -48,7 +48,7 @@ Then /^I should see (\d+) record(?:s)? selected$/ do |count|
48
48
  within "table.index_table" do
49
49
  unless count.to_i == 0
50
50
  page.should have_xpath(".//input[@type='checkbox' and @checked='checked']", :count => count)
51
- else
51
+ else
52
52
  page.should have_no_xpath(".//input[@type='checkbox' and @checked='checked']")
53
53
  end
54
54
  end
@@ -60,7 +60,7 @@ end
60
60
 
61
61
  Then /^I (should|should not) see the batch action button$/ do |maybe|
62
62
  if maybe == "should not"
63
- page.should_not have_css("div.table_tools #batch_actions_selector .dropdown_menu_button")
63
+ page.should_not have_css("div.table_tools #batch_actions_selector .dropdown_menu_button")
64
64
  else
65
65
  page.should have_css("div.table_tools #batch_actions_selector .dropdown_menu_button")
66
66
  end
@@ -75,11 +75,21 @@ Then /^I should see the batch action popover exists$/ do
75
75
  end
76
76
 
77
77
  Given /^I submit the batch action form with "([^"]*)"$/ do |action|
78
- page.find(:css, "#batch_action").set(action)
78
+ page.find(:css, "#batch_action").set(action)
79
79
 
80
80
  within("#main_content") do
81
81
  @params = page.all("input").reduce({}) do |acc, input|
82
- acc.store(input['name'], input['value'])
82
+ param_key = input['name']
83
+ param_value = input['value']
84
+
85
+ if param_key == 'collection_selection[]'
86
+ # the collection_selection should be sent as an array containing only IDs of checked rows
87
+ acc[param_key] ||= Array.new
88
+ acc[param_key] << param_value if input.checked?
89
+ else
90
+ # other inputs, just send the value normally
91
+ acc.store(param_key, param_value)
92
+ end
83
93
  acc
84
94
  end
85
95
  end
@@ -26,11 +26,11 @@ end
26
26
 
27
27
  Then /^I should see (\d+) ([\w]*) in the table$/ do |count, resource_type|
28
28
  begin
29
- page.should have_css("table##{resource_type} tr > td:first", :count => count.to_i)
29
+ page.should have_css("table#index_table_#{resource_type} tr > td:first", :count => count.to_i)
30
30
  rescue
31
31
  current_count = 0
32
-
33
- all("table##{resource_type} tr > td:first").each { current_count += 1 }
32
+
33
+ all("table#index_table_#{resource_type} tr > td:first").each { current_count += 1 }
34
34
 
35
35
  raise "There were #{current_count} rows in the table not #{count}"
36
36
  end
@@ -0,0 +1,3 @@
1
+ When /^I click "(.*?)"$/ do |link|
2
+ click_link(link)
3
+ end
@@ -5,3 +5,7 @@ end
5
5
  Then /^I should not see a menu item for "([^"]*)"$/ do |name|
6
6
  page.should_not have_css('#tabs li a', :text => name)
7
7
  end
8
+
9
+ Then /^I should see a nested menu item for "([^"]*)"$/ do |name|
10
+ page.should have_css('#tabs > li > ul > li > a', :text => name)
11
+ end
@@ -107,6 +107,10 @@ include Warden::Test::Helpers
107
107
  After do
108
108
  add_default_dashboard
109
109
  Warden.test_reset!
110
+
111
+ # Reset back to the default auth adapter
112
+ ActiveAdmin.application.namespace(:admin).
113
+ authorization_adapter = ActiveAdmin::AuthorizationAdapter
110
114
  end
111
115
 
112
116
  Before '@dashboard' do
@@ -36,6 +36,9 @@ module NavigationHelpers
36
36
  when /^the last author's last post page$/
37
37
  admin_user_post_path(User.last, Post.where(:author_id => User.last.id).last)
38
38
 
39
+ when /^the last post's edit page$/
40
+ edit_admin_post_path(Post.last)
41
+
39
42
  # Add more mappings here.
40
43
  # Here is an example that pulls values out of the Regexp:
41
44
  #
@@ -16,7 +16,10 @@ module ActiveAdmin
16
16
  autoload :VERSION, 'active_admin/version'
17
17
  autoload :Application, 'active_admin/application'
18
18
  autoload :AssetRegistration, 'active_admin/asset_registration'
19
+ autoload :Authorization, 'active_admin/authorization_adapter'
20
+ autoload :AuthorizationAdapter, 'active_admin/authorization_adapter'
19
21
  autoload :Breadcrumbs, 'active_admin/breadcrumbs'
22
+ autoload :CanCanAdapter, 'active_admin/cancan_adapter'
20
23
  autoload :Callbacks, 'active_admin/callbacks'
21
24
  autoload :Component, 'active_admin/component'
22
25
  autoload :BaseController, 'active_admin/base_controller'
@@ -31,6 +34,7 @@ module ActiveAdmin
31
34
  autoload :Inputs, 'active_admin/inputs'
32
35
  autoload :Iconic, 'active_admin/iconic'
33
36
  autoload :Menu, 'active_admin/menu'
37
+ autoload :MenuCollection, 'active_admin/menu_collection'
34
38
  autoload :MenuItem, 'active_admin/menu_item'
35
39
  autoload :Namespace, 'active_admin/namespace'
36
40
  autoload :Page, 'active_admin/page'
@@ -74,6 +74,15 @@ module ActiveAdmin
74
74
  # Default CSV options
75
75
  inheritable_setting :csv_options, {}
76
76
 
77
+ # Default Download Links options
78
+ inheritable_setting :download_links, true
79
+
80
+ # The authorization adapter to use
81
+ inheritable_setting :authorization_adapter, ActiveAdmin::AuthorizationAdapter
82
+
83
+ # A proc to be used when a user is not authorized to view the current resource
84
+ inheritable_setting :on_unauthorized_access, :rescue_active_admin_access_denied
85
+
77
86
  # Active Admin makes educated guesses when displaying objects, this is
78
87
  # the list of methods it tries calling in order
79
88
  setting :display_name_methods, [ :display_name,
@@ -115,9 +124,8 @@ module ActiveAdmin
115
124
 
116
125
  # Registers a brand new configuration for the given resource.
117
126
  def register(resource, options = {}, &block)
118
- namespace_name = extract_namespace_name(options)
119
- namespace = find_or_create_namespace(namespace_name)
120
- namespace.register(resource, options, &block)
127
+ ns_name = namespace_name(options)
128
+ namespace(ns_name).register resource, options, &block
121
129
  end
122
130
 
123
131
  # Creates a namespace for the given name
@@ -125,14 +133,13 @@ module ActiveAdmin
125
133
  # Yields the namespace if a block is given
126
134
  #
127
135
  # @returns [Namespace] the new or existing namespace
128
- def find_or_create_namespace(name)
136
+ def namespace(name)
129
137
  name ||= :root
130
138
 
131
139
  if namespaces[name]
132
140
  namespace = namespaces[name]
133
141
  else
134
- namespace = Namespace.new(self, name)
135
- namespaces[name] = namespace
142
+ namespace = namespaces[name] = Namespace.new(self, name)
136
143
  ActiveAdmin::Event.dispatch ActiveAdmin::Namespace::RegisterEvent, namespace
137
144
  end
138
145
 
@@ -141,8 +148,6 @@ module ActiveAdmin
141
148
  namespace
142
149
  end
143
150
 
144
- alias_method :namespace, :find_or_create_namespace
145
-
146
151
  # Register a page
147
152
  #
148
153
  # @param name [String] The page name
@@ -150,96 +155,57 @@ module ActiveAdmin
150
155
  # @&block The registration block.
151
156
  #
152
157
  def register_page(name, options = {}, &block)
153
- namespace_name = extract_namespace_name(options)
154
- namespace = find_or_create_namespace(namespace_name)
155
- namespace.register_page(name, options, &block)
158
+ ns_name = namespace_name(options)
159
+ namespace(ns_name).register_page name, options, &block
156
160
  end
157
161
 
158
- # Stores if everything has been loaded or we need to reload
159
- @@loaded = false
160
-
161
- # Returns true if all the configuration files have been loaded.
162
+ # Whether all configuration files have been loaded
162
163
  def loaded?
163
- @@loaded
164
+ @@loaded ||= false
164
165
  end
165
166
 
166
- # Removes all the controllers that were defined by registering
167
- # resources for administration.
168
- #
169
- # We remove them, then load them on each request in development
170
- # to allow for changes without having to restart the server.
167
+ # Removes all defined controllers from memory. Useful in
168
+ # development, where they are reloaded on each request.
171
169
  def unload!
172
- namespaces.values.each{|namespace| namespace.unload! }
170
+ namespaces.values.each{ |namespace| namespace.unload! }
173
171
  @@loaded = false
174
172
  end
175
173
 
176
- # Loads all of the ruby files that are within the load path of
177
- # ActiveAdmin.load_paths. This should load all of the administration
178
- # UIs so that they are available for the router to proceed.
179
- #
180
- # The files are only loaded if we haven't already loaded all the files
181
- # and they aren't marked for re-loading. To mark the files for re-loading
182
- # you must first call ActiveAdmin.unload!
174
+ # Loads all ruby files that are within the load_paths setting.
175
+ # To reload everything simply call `ActiveAdmin.unload!`
183
176
  def load!
184
- # No work to do if we've already loaded
185
- return false if loaded?
186
-
187
- ActiveAdmin::Event.dispatch BeforeLoadEvent, self
188
-
189
- # Load files
190
- files_in_load_path.each{|file| load file }
191
-
192
- # If no configurations, let's make sure you can still login
193
- load_default_namespace if namespaces.values.empty?
194
-
195
- # Dispatch an ActiveAdmin::Application::LoadEvent with the Application
196
- ActiveAdmin::Event.dispatch AfterLoadEvent, self
197
-
198
- @@loaded = true
177
+ unless loaded?
178
+ ActiveAdmin::Event.dispatch BeforeLoadEvent, self # before_load hook
179
+ files.each{ |file| load file } # load files
180
+ namespace(nil) # init AA resources
181
+ ActiveAdmin::Event.dispatch AfterLoadEvent, self # after_load hook
182
+ @@loaded = true
183
+ end
199
184
  end
200
185
 
201
- # Returns ALL the files to load from all the load paths
202
- def files_in_load_path
203
- load_paths.flatten.compact.uniq.collect{|path| Dir["#{path}/**/*.rb"] }.flatten
186
+ # Returns ALL the files to be loaded
187
+ def files
188
+ load_paths.flatten.compact.uniq.map{ |path| Dir["#{path}/**/*.rb"] }.flatten
204
189
  end
205
190
 
206
191
  def router
207
192
  @router ||= Router.new(self)
208
193
  end
209
194
 
195
+ # One-liner called by user's config/routes.rb file
210
196
  def routes(rails_router)
211
- # Ensure that all the configurations (which define the routes)
212
- # are all loaded
213
197
  load!
214
-
215
198
  router.apply(rails_router)
216
199
  end
217
200
 
218
- def load_default_namespace
219
- find_or_create_namespace(default_namespace)
220
- end
221
-
222
- #
223
201
  # Add before, around and after filters to each registered resource and pages.
224
- #
225
- # eg:
226
- #
202
+ # For example:
227
203
  # ActiveAdmin.before_filter :authenticate_admin!
228
204
  #
229
- def before_filter(*args, &block)
230
- BaseController.before_filter(*args, &block)
231
- end
232
-
233
- def skip_before_filter(*args, &block)
234
- BaseController.skip_before_filter(*args, &block)
235
- end
236
-
237
- def after_filter(*args, &block)
238
- BaseController.after_filter(*args, &block)
239
- end
240
-
241
- def around_filter(*args, &block)
242
- BaseController.around_filter(*args, &block)
205
+ %w(before_filter skip_before_filter after_filter around_filter).each do |name|
206
+ define_method name do |*args, &block|
207
+ BaseController.send name, *args, &block
208
+ end
243
209
  end
244
210
 
245
211
  # Helper method to add a dashboard section
@@ -249,6 +215,11 @@ module ActiveAdmin
249
215
 
250
216
  private
251
217
 
218
+ # Return either the passed in namespace or the default
219
+ def namespace_name(options)
220
+ options.fetch(:namespace){ default_namespace }
221
+ end
222
+
252
223
  def register_default_assets
253
224
  register_stylesheet 'active_admin.css', :media => 'screen'
254
225
  register_stylesheet 'active_admin/print.css', :media => 'print'
@@ -262,10 +233,6 @@ module ActiveAdmin
262
233
  register_javascript 'active_admin.js'
263
234
  end
264
235
 
265
- def extract_namespace_name(options)
266
- options.has_key?(:namespace) ? options[:namespace] : default_namespace
267
- end
268
-
269
236
  # Since we're dealing with all our own file loading, we need
270
237
  # to remove our paths from the ActiveSupport autoload paths.
271
238
  # If not, file naming becomes very important and can cause clashes.