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
@@ -0,0 +1,29 @@
1
+ # Create an Index
2
+
3
+ If the supplied Active Admin index components are insufficient for your project
4
+ feel free to define your own. Index classes extend ActiveAdmin::Component and
5
+ require a build method and an index_name class method.
6
+
7
+ module ActiveAdmin
8
+ module Views
9
+ class IndexAsMyIdea < ActiveAdmin::Component
10
+
11
+ def build(page_presenter, collection)
12
+ ...
13
+ end
14
+
15
+ def self.index_name
16
+ "my_idea"
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+
23
+ The build method takes a PagePresenter object and collection of whatever you
24
+ choose.
25
+
26
+ The index_name class method takes no arguments and returns a string that should
27
+ be representative of the the class name. If this method is not defined, your
28
+ index component will not be able take advantage of Active Admin's
29
+ *multiple index pages* feature.
@@ -28,12 +28,11 @@ If the default title does not work for you, pass it as the first argument:
28
28
  column "My Custom Title", :title
29
29
  end
30
30
 
31
- Sometimes calling methods just isn't enough and you need to write some view
32
- specific code. For example, say we wanted a colum called Title which holds a
33
- link to the posts admin screen.
31
+ Sometimes that just isn't enough and you need to write some view-specific code.
32
+ For example, say we wanted a "Title" column that links to the posts admin screen.
34
33
 
35
- The column method accepts a block as an argument which will then be rendered
36
- within the context of the view for each of the objects in the collection.
34
+ `column` accepts a block that will be rendered for each of the objects in the collection.
35
+ The block is called once for each resource, which is passed as an argument to the block.
37
36
 
38
37
  index do
39
38
  column "Title" do |post|
@@ -41,21 +40,27 @@ within the context of the view for each of the objects in the collection.
41
40
  end
42
41
  end
43
42
 
44
- The block gets called once for each resource in the collection. The resource gets passed into
45
- the block as an argument.
43
+ To setup links to View, Edit and Delete a resource, use the `actions` method:
46
44
 
47
- To setup links to View, Edit and Delete a resource, use the default_actions method:
45
+ index do
46
+ column :title
47
+ actions
48
+ end
49
+
50
+ You can also append custom links to the default links:
48
51
 
49
52
  index do
50
53
  column :title
51
- default_actions
54
+ actions do |post|
55
+ link_to "Preview", admin_preview_post_path(post), :class => "member_link"
56
+ end
52
57
  end
53
58
 
54
- Alternatively, you can create a column with custom links:
59
+ Or forego the default links entirely:
55
60
 
56
61
  index do
57
62
  column :title
58
- column "Actions" do |post|
63
+ actions :defaults => false do |post|
59
64
  link_to "View", admin_post_path(post)
60
65
  end
61
66
  end
@@ -81,6 +86,25 @@ You can turn off sorting on any column by passing false:
81
86
  column :title, :sortable => false
82
87
  end
83
88
 
89
+ ## Associated Sorting
90
+
91
+ You're normally able to sort columns alphabetically, but by default you
92
+ can't sort by associated objects. Though with a few simple changes, you can.
93
+
94
+ Assuming you're on the Books index page, and Book has_one Publisher:
95
+
96
+ controller do
97
+ def scoped_collection
98
+ resource_class.includes(:publisher) # prevents N+1 queries to your database
99
+ end
100
+ end
101
+
102
+ Then it's simple to sort by any Publisher attribute from within the index table:
103
+
104
+ index do
105
+ column :publisher, sortable: 'publishers.name'
106
+ end
107
+
84
108
  ## Showing and Hiding Columns
85
109
 
86
110
  The entire index block is rendered within the context of the view, so you can
@@ -14,7 +14,7 @@ the fabulous DSL created by Formtastic (http://github.com/justinfrench/formtasti
14
14
  f.inputs "Content" do
15
15
  f.input :body
16
16
  end
17
- f.buttons
17
+ f.actions
18
18
  end
19
19
 
20
20
  end
@@ -35,5 +35,5 @@ Then implement app/views/admin/posts/_form.html.erb:
35
35
 
36
36
  <%= semantic_form_for [:admin, @post] do |f| %>
37
37
  <%= f.inputs :title, :body %>
38
- <%= f.buttons :commit %>
38
+ <%= f.actions :commit %>
39
39
  <% end %>
@@ -0,0 +1,64 @@
1
+ Feature: Authorizing Access
2
+
3
+ Ensure that access denied exceptions are managed
4
+
5
+ Background:
6
+ Given I am logged in
7
+ And 1 post exists
8
+ And a configuration of:
9
+ """
10
+ class OnlyAuthorsAuthorization < ActiveAdmin::AuthorizationAdapter
11
+
12
+ def authorized?(action, subject = nil)
13
+ case subject
14
+
15
+ when normalized(Post)
16
+ case action
17
+ when ActiveAdmin::Auth::UPDATE, ActiveAdmin::Auth::DESTROY
18
+ false
19
+ else
20
+ true
21
+ end
22
+
23
+ when ActiveAdmin::Page
24
+ if subject.name == "No Access"
25
+ false
26
+ else
27
+ true
28
+ end
29
+
30
+ else
31
+ false
32
+ end
33
+ end
34
+
35
+ end
36
+
37
+ ActiveAdmin.application.namespace(:admin).authorization_adapter = OnlyAuthorsAuthorization
38
+
39
+ ActiveAdmin.register Post do
40
+ end
41
+
42
+ ActiveAdmin.register_page "No Access" do
43
+ end
44
+ """
45
+ And I am on the index page for posts
46
+
47
+ @allow-rescue
48
+ Scenario: Attempt to access a resource I am not authorized to see
49
+ When I go to the last post's edit page
50
+ Then I should see "You are not authorized to perform this action"
51
+
52
+ Scenario: Viewing the default action items
53
+ When I follow "View"
54
+ Then I should not see an action item link to "Edit"
55
+
56
+ @allow-rescue
57
+ Scenario: Attempting to visit a Page without authorization
58
+ When I go to the admin no access page
59
+ Then I should see "You are not authorized to perform this action"
60
+
61
+ @allow-rescue
62
+ Scenario: Viewing a page with authorization
63
+ When I go to the admin dashboard page
64
+ Then I should see "Dashboard"
@@ -0,0 +1,52 @@
1
+ Feature: Authorizing Access using CanCan
2
+
3
+ Background:
4
+ Given I am logged in
5
+ And 1 post exists
6
+ And a configuration of:
7
+ """
8
+ require 'cancan'
9
+
10
+ class ::Ability
11
+ include ::CanCan::Ability
12
+
13
+ def initialize(user)
14
+ # Manage Posts
15
+ can [:edit, :destroy], Post, :author_id => user.id
16
+ can :read, Post
17
+
18
+ # View Pages
19
+ can :read, ActiveAdmin::Page, :name => "Dashboard"
20
+ cannot :read, ActiveAdmin::Page, :name => "No Access"
21
+ end
22
+
23
+ end
24
+
25
+ ActiveAdmin.application.namespace(:admin).authorization_adapter = ActiveAdmin::CanCanAdapter
26
+
27
+ ActiveAdmin.register Post do
28
+ end
29
+
30
+ ActiveAdmin.register_page "No Access" do
31
+ end
32
+ """
33
+ And I am on the index page for posts
34
+
35
+ @allow-rescue
36
+ Scenario: Attempt to access a resource I am not authorized to see
37
+ When I go to the last post's edit page
38
+ Then I should see "You are not authorized to perform this action"
39
+
40
+ Scenario: Viewing the default action items
41
+ When I follow "View"
42
+ Then I should not see an action item link to "Edit"
43
+
44
+ @allow-rescue
45
+ Scenario: Attempting to visit a Page without authorization
46
+ When I go to the admin no access page
47
+ Then I should see "You are not authorized to perform this action"
48
+
49
+ @allow-rescue
50
+ Scenario: Viewing a page with authorization
51
+ When I go to the admin dashboard page
52
+ Then I should see "Dashboard"
@@ -3,6 +3,11 @@ Feature: Belongs To
3
3
  A resource belongs to another resource
4
4
 
5
5
  Background:
6
+ Given I am logged in
7
+ And a post with the title "Hello World" written by "John Doe" exists
8
+ And a post with the title "Hello World" written by "Jane Doe" exists
9
+
10
+ Scenario: Viewing the child resource index page
6
11
  Given a configuration of:
7
12
  """
8
13
  ActiveAdmin.register User
@@ -10,18 +15,49 @@ Feature: Belongs To
10
15
  belongs_to :user
11
16
  end
12
17
  """
13
- And I am logged in
14
- And a post with the title "Hello World" written by "John Doe" exists
15
- And a post with the title "Hello World" written by "Jane Doe" exists
16
-
17
- Scenario: Viewing the child resource index page
18
18
  When I go to the last author's posts
19
19
  Then the "Users" tab should be selected
20
+ And I should not see a menu item for "Posts"
20
21
  And I should see "Displaying 1 Post"
21
22
  And I should see a link to "Users" in the breadcrumb
22
23
 
23
24
  Scenario: Viewing a child resource page
25
+ Given a configuration of:
26
+ """
27
+ ActiveAdmin.register User
28
+ ActiveAdmin.register Post do
29
+ belongs_to :user
30
+ end
31
+ """
24
32
  When I go to the last author's posts
25
33
  And I follow "View"
26
34
  Then I should be on the last author's last post page
27
35
  And the "Users" tab should be selected
36
+
37
+ Scenario: When the belongs to is optional
38
+ Given a configuration of:
39
+ """
40
+ ActiveAdmin.register User
41
+ ActiveAdmin.register Post do
42
+ belongs_to :user, :optional => true
43
+ end
44
+ """
45
+ When I go to the last author's posts
46
+ Then the "Users" tab should be selected
47
+ And I should see a menu item for "Posts"
48
+
49
+ When I follow "Posts"
50
+ Then the "Posts" tab should be selected
51
+
52
+ Scenario: Displaying belongs to resources in main menu
53
+ Given a configuration of:
54
+ """
55
+ ActiveAdmin.register User
56
+ ActiveAdmin.register Post do
57
+ belongs_to :user
58
+ navigation_menu :user
59
+ end
60
+ """
61
+ When I go to the last author's posts
62
+ And I follow "View"
63
+ Then the "Posts" tab should be selected
@@ -12,14 +12,38 @@ Feature: Batch Actions
12
12
  And I should see 10 posts in the table
13
13
 
14
14
  When I check the 1st record
15
- When I check the 2nd record
15
+ And I check the 2nd record
16
16
  And I follow "Batch Actions"
17
17
  Then I should see the batch action :destroy "Delete Selected"
18
18
 
19
+ Given I submit the batch action form with "destroy"
20
+ Then I should see a flash with "Successfully destroyed 2 posts"
21
+ And I should see 8 posts in the table
22
+
23
+ Scenario: Use default (destroy) batch action on a nested resource
24
+ Given I am logged in
25
+ And 5 posts written by "John Doe" exist
26
+ And a configuration of:
27
+ """
28
+ ActiveAdmin.register User
29
+ ActiveAdmin.register Post do
30
+ belongs_to :user
31
+ end
32
+ """
33
+ When I go to the last author's posts
34
+ Then I should see the batch action button
35
+ And I should see that the batch action button is disabled
36
+ And I should see the batch action popover exists
37
+ And I should see 5 posts in the table
38
+
39
+ When I check the 2nd record
40
+ And I check the 4th record
41
+ And I follow "Batch Actions"
42
+ Then I should see the batch action :destroy "Delete Selected"
19
43
 
20
44
  Given I submit the batch action form with "destroy"
21
- Then I should see a flash with "Successfully destroyed 1 post"
22
- And I should see 9 posts in the table
45
+ Then I should see a flash with "Successfully destroyed 2 posts"
46
+ And I should see 3 posts in the table
23
47
 
24
48
  Scenario: Using a custom batch action
25
49
  Given 10 posts exist
@@ -10,3 +10,30 @@ Feature: Index Formats
10
10
  Then I should see a link to download "CSV"
11
11
  And I should see a link to download "XML"
12
12
  And I should see a link to download "JSON"
13
+
14
+ Scenario: View index with download_links set to false
15
+ Given an index configuration of:
16
+ """
17
+ ActiveAdmin.register Post do
18
+ index :download_links => false
19
+ end
20
+ """
21
+ And 1 post exists
22
+ When I am on the index page for posts
23
+ Then I should not see a link to download "CSV"
24
+ And I should not see a link to download "XML"
25
+ And I should not see a link to download "JSON"
26
+
27
+ Scenario: View index with pdf download link set
28
+ Given an index configuration of:
29
+ """
30
+ ActiveAdmin.register Post do
31
+ index :download_links => [:pdf]
32
+ end
33
+ """
34
+ And 1 post exists
35
+ When I am on the index page for posts
36
+ Then I should not see a link to download "CSV"
37
+ And I should not see a link to download "XML"
38
+ And I should not see a link to download "JSON"
39
+ And I should see a link to download "PDF"
@@ -11,6 +11,7 @@ Feature: Index as Table
11
11
  When I am on the index page for posts
12
12
  Then I should see a sortable table header with "Id"
13
13
  And I should see a sortable table header with "Title"
14
+ And I should see a table with id "index_table_posts"
14
15
 
15
16
  Scenario: Viewing the default table with a resource
16
17
  Given a post with the title "Hello World" exists
@@ -92,6 +93,46 @@ Feature: Index as Table
92
93
  And I should see a member link to "Edit"
93
94
  And I should not see a member link to "Delete"
94
95
 
96
+ Scenario: Actions with defaults and custom actions
97
+ Given a post with the title "Hello World" and body "From the body" exists
98
+ And an index configuration of:
99
+ """
100
+ ActiveAdmin.register Post do
101
+ actions :index, :show, :edit, :update
102
+
103
+ index do
104
+ column :category
105
+ actions do |resource|
106
+ link_to 'Custom Action', edit_admin_post_path(resource), :class => 'member_link'
107
+ end
108
+ end
109
+ end
110
+ """
111
+ Then I should see a member link to "View"
112
+ And I should see a member link to "Edit"
113
+ And I should not see a member link to "Delete"
114
+ And I should see a member link to "Custom Action"
115
+
116
+ Scenario: Actions without default actions
117
+ Given a post with the title "Hello World" and body "From the body" exists
118
+ And an index configuration of:
119
+ """
120
+ ActiveAdmin.register Post do
121
+ actions :index, :show, :edit, :update
122
+
123
+ index do
124
+ column :category
125
+ actions :defaults => false do |resource|
126
+ link_to 'Custom Action', edit_admin_post_path(resource), :class => 'member_link'
127
+ end
128
+ end
129
+ end
130
+ """
131
+ Then I should not see a member link to "View"
132
+ And I should not see a member link to "Edit"
133
+ And I should not see a member link to "Delete"
134
+ And I should see a member link to "Custom Action"
135
+
95
136
  Scenario: Associations are not sortable
96
137
  Given 1 post exists
97
138
  And an index configuration of:
@@ -112,12 +153,43 @@ Feature: Index as Table
112
153
  ActiveAdmin.register Post
113
154
  """
114
155
  When I am on the index page for posts
115
- Then I should see the "posts" table:
156
+ Then I should see the "index_table_posts" table:
116
157
  | [ ] | Id | Title | Body | Published At | Starred | Created At | Updated At | |
117
158
  | [ ] | 2 | Bye bye world | Move your... | | | /.*/ | /.*/ | ViewEditDelete |
118
159
  | [ ] | 1 | Hello World | From the body | | | /.*/ | /.*/ | ViewEditDelete |
119
160
  When I follow "Id"
120
- Then I should see the "posts" table:
161
+ Then I should see the "index_table_posts" table:
121
162
  | [ ] | Id | Title | Body | Published At | Starred | Created At | Updated At | |
122
163
  | [ ] | 1 | Hello World | From the body | | | /.*/ | /.*/ | ViewEditDelete |
123
164
  | [ ] | 2 | Bye bye world | Move your... | | | /.*/ | /.*/ | ViewEditDelete |
165
+
166
+ Scenario: Sorting by a virtual column
167
+ Given a post with the title "Hello World" exists
168
+ And a post with the title "Bye bye world" exists
169
+ And an index configuration of:
170
+ """
171
+ ActiveAdmin.register Post do
172
+ controller do
173
+ def scoped_collection
174
+ Post.select("id, title, length(title) as title_length")
175
+ end
176
+ end
177
+
178
+ index do
179
+ column :id
180
+ column :title
181
+ column("Title Length", :sortable => :title_length) { |post| post.title_length }
182
+ end
183
+ end
184
+ """
185
+ When I am on the index page for posts
186
+ And I follow "Title Length"
187
+ Then I should see the "index_table_posts" table:
188
+ | Id | Title | Title Length |
189
+ | 2 | Bye bye world | 13 |
190
+ | 1 | Hello World | 11 |
191
+ When I follow "Title Length"
192
+ Then I should see the "index_table_posts" table:
193
+ | Id | Title | Title Length |
194
+ | 1 | Hello World | 11 |
195
+ | 2 | Bye bye world | 13 |