activeadmin 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +5 -1
- data/.travis.yml +1 -1
- data/.yardopts +2 -3
- data/CHANGELOG.md +180 -36
- data/CONTRIBUTING.md +12 -2
- data/Gemfile +9 -3
- data/README.rdoc +38 -65
- data/Rakefile +1 -3
- data/activeadmin.gemspec +10 -11
- data/app/assets/images/active_admin/index_list_icons/block_icon.svg +1 -1
- data/app/assets/images/active_admin/index_list_icons/blog_icon.svg +1 -1
- data/app/assets/images/active_admin/index_list_icons/grid_icon.svg +1 -1
- data/app/assets/images/active_admin/index_list_icons/table_icon.svg +1 -1
- data/app/assets/javascripts/active_admin/components/jquery.aa.checkbox-toggler.js.coffee +2 -2
- data/app/assets/javascripts/active_admin/components/jquery.aa.dropdown-menu.js.coffee +2 -2
- data/app/assets/javascripts/active_admin/components/jquery.aa.popover.js.coffee +2 -2
- data/app/assets/javascripts/active_admin/components/jquery.aa.table-checkbox-toggler.js.coffee +2 -2
- data/app/assets/javascripts/active_admin/lib/namespace.js.coffee +2 -1
- data/app/assets/javascripts/active_admin/pages/application.js.coffee +6 -1
- data/app/assets/stylesheets/active_admin/_base.css.scss +29 -34
- data/app/assets/stylesheets/active_admin/_forms.css.scss +65 -62
- data/app/assets/stylesheets/active_admin/_header.css.scss +57 -45
- data/app/assets/stylesheets/active_admin/_typography.css.scss +9 -9
- data/app/assets/stylesheets/active_admin/components/_batch_actions.css.scss +1 -1
- data/app/assets/stylesheets/active_admin/components/_blank_slates.scss +5 -5
- data/app/assets/stylesheets/active_admin/components/_breadcrumbs.scss +2 -2
- data/app/assets/stylesheets/active_admin/components/_comments.css.scss +1 -1
- data/app/assets/stylesheets/active_admin/components/_date_picker.css.scss +20 -20
- data/app/assets/stylesheets/active_admin/components/_dropdown_menu.scss +16 -16
- data/app/assets/stylesheets/active_admin/components/_flash_messages.css.scss +25 -23
- data/app/assets/stylesheets/active_admin/components/_grid.scss +2 -2
- data/app/assets/stylesheets/active_admin/components/_index_list.scss +1 -1
- data/app/assets/stylesheets/active_admin/components/_pagination.scss +10 -10
- data/app/assets/stylesheets/active_admin/components/_panels.scss +1 -1
- data/app/assets/stylesheets/active_admin/components/_popovers.css.scss +27 -27
- data/app/assets/stylesheets/active_admin/components/_scopes.scss +1 -1
- data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +10 -10
- data/app/assets/stylesheets/active_admin/components/_tables.css.scss +9 -9
- data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +3 -3
- data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +4 -4
- data/app/assets/stylesheets/active_admin/mixins/_icons.css.scss +4 -7
- data/app/assets/stylesheets/active_admin/mixins/_reset.css.scss +5 -5
- data/app/assets/stylesheets/active_admin/mixins/_rounded.css.scss +3 -3
- data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +6 -6
- data/app/assets/stylesheets/active_admin/mixins/_shadows.css.scss +8 -8
- data/app/assets/stylesheets/active_admin/mixins/_typography.scss +1 -1
- data/app/assets/stylesheets/active_admin/mixins/_utilities.scss +1 -1
- data/app/assets/stylesheets/active_admin/mixins/_variables.css.scss +9 -1
- data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +1 -1
- data/app/assets/stylesheets/active_admin/print.css.scss +2 -8
- data/app/assets/stylesheets/active_admin/structure/_footer.scss +5 -5
- data/app/assets/stylesheets/active_admin/structure/_main_structure.scss +13 -13
- data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +14 -14
- data/app/views/active_admin/devise/passwords/edit.html.erb +1 -1
- data/app/views/active_admin/devise/sessions/new.html.erb +1 -1
- data/app/views/active_admin/devise/shared/_links.erb +8 -1
- data/app/views/active_admin/resource/index.csv.erb +3 -3
- data/app/views/layouts/active_admin_logged_out.html.erb +5 -3
- data/config/locales/bg.yml +101 -0
- data/{lib/active_admin → config}/locales/ca.yml +24 -7
- data/{lib/active_admin → config}/locales/cs.yml +34 -12
- data/{lib/active_admin → config}/locales/da.yml +29 -7
- data/config/locales/de-CH.yml +117 -0
- data/{lib/active_admin → config}/locales/de.yml +19 -9
- data/config/locales/en-GB.yml +90 -0
- data/{lib/active_admin → config}/locales/en.yml +16 -6
- data/config/locales/es.yml +106 -0
- data/{lib/active_admin/locales/es.yml → config/locales/es_MX.yml} +14 -8
- data/{lib/active_admin → config}/locales/fr.yml +14 -6
- data/{lib/active_admin → config}/locales/he.yml +16 -6
- data/{lib/active_admin → config}/locales/hr.yml +14 -6
- data/{lib/active_admin → config}/locales/hu.yml +31 -6
- data/{lib/active_admin → config}/locales/it.yml +14 -6
- data/{lib/active_admin → config}/locales/ja.yml +32 -7
- data/{lib/active_admin → config}/locales/ko.yml +14 -6
- data/{lib/active_admin → config}/locales/lt.yml +15 -6
- data/{lib/active_admin → config}/locales/lv.yml +14 -6
- data/{lib/active_admin → config}/locales/nl.yml +14 -6
- data/{lib/active_admin → config}/locales/no-NB.yml +14 -6
- data/{lib/active_admin → config}/locales/pl.yml +14 -6
- data/{lib/active_admin → config}/locales/pt-BR.yml +14 -6
- data/{lib/active_admin → config}/locales/pt-PT.yml +14 -6
- data/{lib/active_admin → config}/locales/ro.yml +32 -7
- data/{lib/active_admin → config}/locales/ru.yml +30 -8
- data/{lib/active_admin → config}/locales/sv-SE.yml +14 -6
- data/{lib/active_admin → config}/locales/tr.yml +15 -6
- data/config/locales/uk.yml +100 -0
- data/{lib/active_admin → config}/locales/vi.yml +15 -6
- data/{lib/active_admin → config}/locales/zh-CN.yml +15 -6
- data/{lib/active_admin → config}/locales/zh-TW.yml +15 -6
- data/docs/0-installation.md +22 -18
- data/docs/1-general-configuration.md +1 -1
- data/docs/10-custom-pages.md +3 -3
- data/docs/11-decorators.md +18 -2
- data/docs/12-arbre-components.md +53 -54
- data/docs/13-authorization-adapter.md +31 -10
- data/docs/2-resource-customization.md +16 -1
- data/docs/3-index-pages.md +13 -1
- data/docs/3-index-pages/create-an-index.md +4 -4
- data/docs/3-index-pages/index-as-block.md +1 -1
- data/docs/3-index-pages/index-as-blog.md +1 -1
- data/docs/3-index-pages/index-as-grid.md +1 -1
- data/docs/4-csv-format.md +4 -4
- data/docs/5-forms.md +46 -3
- data/docs/{6-show-screens.md → 6-show-pages.md} +3 -3
- data/docs/8-custom-actions.md +3 -3
- data/docs/9-batch-actions.md +9 -1
- data/features/action_item.feature +6 -6
- data/features/authorization_cancan.feature +1 -1
- data/features/belongs_to.feature +3 -3
- data/features/breadcrumb.feature +2 -2
- data/features/comments/commenting.feature +7 -5
- data/features/dashboard.feature +0 -51
- data/features/favicon.feature +20 -0
- data/features/global_navigation.feature +0 -1
- data/features/index/batch_actions.feature +12 -11
- data/features/index/filters.feature +6 -6
- data/features/index/format_as_csv.feature +4 -5
- data/features/index/index_as_blog.feature +20 -1
- data/features/index/index_as_table.feature +1 -1
- data/features/index/index_blank_slate.feature +3 -3
- data/features/index/index_parameters.feature +4 -10
- data/features/index/index_scope_to.feature +24 -0
- data/features/index/index_scopes.feature +17 -5
- data/features/index/pagination.feature +15 -0
- data/features/registering_pages.feature +1 -1
- data/features/registering_resources.feature +2 -2
- data/features/show/default_content.feature +3 -3
- data/features/sidebar_sections.feature +3 -3
- data/features/specifying_actions.feature +1 -1
- data/features/step_definitions/additional_web_steps.rb +3 -16
- data/features/step_definitions/asset_steps.rb +5 -1
- data/features/step_definitions/attribute_steps.rb +4 -4
- data/features/step_definitions/batch_action_steps.rb +25 -74
- data/features/step_definitions/breadcrumb_steps.rb +1 -3
- data/features/step_definitions/comment_steps.rb +0 -1
- data/features/step_definitions/configuration_steps.rb +53 -69
- data/features/step_definitions/dashboard_steps.rb +2 -2
- data/features/step_definitions/factory_steps.rb +17 -33
- data/features/step_definitions/filter_steps.rb +2 -2
- data/features/step_definitions/format_steps.rb +10 -14
- data/features/step_definitions/index_scope_steps.rb +9 -25
- data/features/step_definitions/index_views_steps.rb +1 -1
- data/features/step_definitions/sidebar_steps.rb +2 -1
- data/features/step_definitions/site_title_steps.rb +1 -1
- data/features/step_definitions/table_steps.rb +6 -1
- data/features/step_definitions/user_steps.rb +23 -38
- data/features/step_definitions/web_steps.rb +18 -147
- data/features/support/env.rb +13 -34
- data/features/support/paths.rb +2 -0
- data/features/users/logging_in.feature +2 -2
- data/features/users/logging_out.feature +0 -12
- data/features/users/resetting_password.feature +1 -1
- data/lib/active_admin.rb +4 -17
- data/lib/active_admin/abstract_view_factory.rb +1 -1
- data/lib/active_admin/application.rb +19 -28
- data/lib/active_admin/asset_registration.rb +7 -25
- data/lib/active_admin/authorization_adapter.rb +9 -5
- data/lib/active_admin/base_controller.rb +2 -2
- data/lib/active_admin/base_controller/authorization.rb +25 -27
- data/lib/active_admin/batch_actions/resource_extension.rb +3 -3
- data/lib/active_admin/batch_actions/views/batch_action_selector.rb +1 -1
- data/lib/active_admin/batch_actions/views/selection_cells.rb +1 -1
- data/lib/active_admin/callbacks.rb +1 -1
- data/lib/active_admin/cancan_adapter.rb +2 -2
- data/lib/active_admin/comments.rb +32 -38
- data/lib/active_admin/comments/comment.rb +6 -8
- data/lib/active_admin/comments/views.rb +0 -1
- data/lib/active_admin/comments/views/active_admin_comments.rb +27 -38
- data/lib/active_admin/csv_builder.rb +4 -6
- data/lib/active_admin/dependency_checker.rb +4 -0
- data/lib/active_admin/deprecation.rb +3 -3
- data/lib/active_admin/dsl.rb +5 -5
- data/lib/active_admin/engine.rb +1 -1
- data/lib/active_admin/filters.rb +2 -1
- data/lib/active_admin/filters/forms.rb +36 -43
- data/lib/active_admin/filters/formtastic_addons.rb +45 -0
- data/lib/active_admin/filters/resource_extension.rb +9 -1
- data/lib/active_admin/form_builder.rb +30 -19
- data/lib/active_admin/helpers/optional_display.rb +11 -13
- data/lib/active_admin/helpers/settings.rb +50 -8
- data/lib/active_admin/inputs/filter_base.rb +5 -18
- data/lib/active_admin/inputs/filter_base/search_method_select.rb +73 -0
- data/lib/active_admin/inputs/filter_boolean_input.rb +6 -14
- data/lib/active_admin/inputs/filter_check_boxes_input.rb +1 -1
- data/lib/active_admin/inputs/filter_numeric_input.rb +2 -47
- data/lib/active_admin/inputs/filter_select_input.rb +32 -10
- data/lib/active_admin/inputs/filter_string_input.rb +12 -14
- data/lib/active_admin/namespace.rb +8 -40
- data/lib/active_admin/page.rb +2 -2
- data/lib/active_admin/page_dsl.rb +1 -1
- data/lib/active_admin/reloader.rb +3 -3
- data/lib/active_admin/resource.rb +16 -23
- data/lib/active_admin/resource/belongs_to.rb +8 -5
- data/lib/active_admin/resource/menu.rb +10 -23
- data/lib/active_admin/resource/naming.rb +3 -3
- data/lib/active_admin/resource/page_presenters.rb +2 -2
- data/lib/active_admin/resource/routes.rb +74 -21
- data/lib/active_admin/resource/scope_to.rb +74 -0
- data/lib/active_admin/resource/scopes.rb +8 -4
- data/lib/active_admin/resource_collection.rb +20 -66
- data/lib/active_admin/resource_controller.rb +12 -16
- data/lib/active_admin/resource_controller/data_access.rb +19 -22
- data/lib/active_admin/resource_controller/resource_class_methods.rb +2 -2
- data/lib/active_admin/resource_controller/scoping.rb +4 -9
- data/lib/active_admin/resource_dsl.rb +5 -32
- data/lib/active_admin/router.rb +34 -47
- data/lib/active_admin/scope.rb +5 -3
- data/lib/active_admin/sidebar_section.rb +1 -1
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_factory.rb +1 -1
- data/lib/active_admin/view_helpers/auto_link_helper.rb +1 -1
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +8 -8
- data/lib/active_admin/view_helpers/display_helper.rb +15 -6
- data/lib/active_admin/view_helpers/download_format_links_helper.rb +2 -2
- data/lib/active_admin/view_helpers/form_helper.rb +6 -1
- data/lib/active_admin/view_helpers/icon_helper.rb +1 -1
- data/lib/active_admin/view_helpers/method_or_proc_helper.rb +5 -5
- data/lib/active_admin/view_helpers/title_helper.rb +1 -1
- data/lib/active_admin/views/components/action_list_popover.rb +6 -6
- data/lib/active_admin/views/components/attributes_table.rb +9 -12
- data/lib/active_admin/views/components/blank_slate.rb +4 -4
- data/lib/active_admin/views/components/columns.rb +1 -1
- data/lib/active_admin/views/components/index_list.rb +1 -1
- data/lib/active_admin/views/components/paginated_collection.rb +20 -12
- data/lib/active_admin/views/components/panel.rb +1 -1
- data/lib/active_admin/views/components/scopes.rb +2 -1
- data/lib/active_admin/views/components/sidebar_section.rb +1 -1
- data/lib/active_admin/views/components/status_tag.rb +1 -1
- data/lib/active_admin/views/header.rb +2 -2
- data/lib/active_admin/views/index_as_blog.rb +16 -3
- data/lib/active_admin/views/index_as_table.rb +2 -2
- data/lib/active_admin/views/pages/base.rb +8 -3
- data/lib/active_admin/views/pages/form.rb +2 -2
- data/lib/active_admin/views/pages/index.rb +19 -17
- data/lib/generators/active_admin/assets/templates/3.0/active_admin.js +1 -1
- data/lib/generators/active_admin/assets/templates/3.1/active_admin.css.scss +1 -13
- data/lib/generators/active_admin/devise/devise_generator.rb +22 -1
- data/lib/generators/active_admin/install/install_generator.rb +1 -5
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +40 -19
- data/lib/generators/active_admin/install/templates/admin_user.rb.erb +18 -18
- data/lib/generators/active_admin/install/templates/migrations/create_active_admin_comments.rb +19 -0
- data/lib/generators/active_admin/resource/resource_generator.rb +1 -1
- data/lib/generators/active_admin/resource/templates/admin.rb +1 -1
- data/script/use_rails +1 -1
- data/spec/integration/memory_spec.rb +3 -2
- data/spec/javascripts/coffeescripts/jquery.aa.checkbox-toggler-spec.js.coffee +4 -4
- data/spec/javascripts/coffeescripts/jquery.aa.popover-spec.js.coffee +1 -1
- data/spec/javascripts/coffeescripts/jquery.aa.table-checkbox-toggler-spec.js.coffee +2 -2
- data/spec/javascripts/compiled/jquery.aa.checkbox-toggler-spec.js +4 -4
- data/spec/javascripts/compiled/jquery.aa.popover-spec.js +1 -1
- data/spec/javascripts/compiled/jquery.aa.table-checkbox-toggler-spec.js +2 -2
- data/spec/spec_helper.rb +16 -6
- data/spec/spec_helper_without_rails.rb +2 -0
- data/spec/support/deferred_garbage_collection.rb +19 -0
- data/spec/support/jslint.yml +1 -1
- data/spec/support/rails_template.rb +29 -27
- data/spec/support/templates/admin/stores.rb +5 -1
- data/spec/unit/abstract_view_factory_spec.rb +1 -1
- data/spec/unit/action_builder_spec.rb +7 -7
- data/spec/unit/active_admin_spec.rb +0 -14
- data/spec/unit/application_spec.rb +16 -17
- data/spec/unit/asset_registration_spec.rb +21 -8
- data/spec/unit/authorization/authorization_adapter_spec.rb +3 -3
- data/spec/unit/authorization/controller_authorization_spec.rb +16 -24
- data/spec/unit/batch_actions/resource_spec.rb +11 -11
- data/spec/unit/belongs_to_spec.rb +1 -1
- data/spec/unit/cancan_adapter_spec.rb +11 -3
- data/spec/unit/comments_spec.rb +10 -28
- data/spec/unit/controller_filters_spec.rb +22 -24
- data/spec/unit/csv_builder_spec.rb +3 -3
- data/spec/unit/devise_spec.rb +10 -10
- data/spec/unit/filters/filter_form_builder_spec.rb +140 -45
- data/spec/unit/filters/resource_spec.rb +20 -19
- data/spec/unit/form_builder_spec.rb +122 -70
- data/spec/unit/menu_item_spec.rb +3 -3
- data/spec/unit/namespace/authorization_spec.rb +4 -8
- data/spec/unit/namespace/register_page_spec.rb +1 -1
- data/spec/unit/namespace/register_resource_spec.rb +12 -7
- data/spec/unit/namespace_spec.rb +4 -10
- data/spec/unit/page_spec.rb +1 -1
- data/spec/unit/resource/menu_spec.rb +1 -1
- data/spec/unit/resource/naming_spec.rb +9 -0
- data/spec/unit/resource/pagination_spec.rb +2 -2
- data/spec/unit/resource/routes_spec.rb +73 -0
- data/spec/unit/resource/scopes_spec.rb +1 -1
- data/spec/unit/resource_collection_spec.rb +95 -43
- data/spec/unit/resource_registration_spec.rb +3 -12
- data/spec/unit/resource_spec.rb +41 -48
- data/spec/unit/routing_spec.rb +10 -64
- data/spec/unit/scope_spec.rb +19 -0
- data/spec/unit/settings_spec.rb +88 -0
- data/spec/unit/view_factory_spec.rb +1 -0
- data/spec/unit/{breadcrumbs_spec.rb → view_helpers/breadcrumbs_spec.rb} +16 -7
- data/spec/unit/view_helpers/display_name_spec.rb +41 -0
- data/spec/unit/view_helpers/form_helper_spec.rb +36 -2
- data/spec/unit/views/components/attributes_table_spec.rb +17 -9
- data/spec/unit/views/components/batch_action_popover_spec.rb +4 -4
- data/spec/unit/views/components/index_list_spec.rb +2 -2
- data/spec/unit/views/components/paginated_collection_spec.rb +42 -0
- data/spec/unit/views/components/panel_spec.rb +8 -0
- data/spec/unit/views/components/site_title_spec.rb +2 -2
- data/spec/unit/views/components/table_for_spec.rb +4 -4
- data/spec/unit/views/pages/form_spec.rb +35 -0
- data/spec/unit/views/pages/layout_spec.rb +1 -1
- data/spec/unit/views/tabbed_navigation_spec.rb +10 -10
- data/tasks/parallel_tests.rake +1 -1
- data/tasks/test.rake +4 -1
- metadata +117 -106
- data/app/assets/stylesheets/active_admin/pages/_dashboard.scss +0 -5
- data/lib/active_admin/comments/views/active_admin_comment.rb +0 -0
- data/lib/active_admin/dashboards.rb +0 -68
- data/lib/active_admin/dashboards/dashboard_controller.rb +0 -50
- data/lib/active_admin/dashboards/section.rb +0 -34
- data/lib/active_admin/locales/bg.yml +0 -77
- data/lib/generators/active_admin/install/templates/migrations/1_create_admin_notes.rb +0 -17
- data/lib/generators/active_admin/install/templates/migrations/2_move_admin_notes_to_comments.rb +0 -26
- data/spec/unit/base_controller_spec.rb +0 -6
- data/spec/unit/dashboard_controller_spec.rb +0 -76
- data/spec/unit/dashboard_section_spec.rb +0 -56
- data/spec/unit/dashboards_spec.rb +0 -59
- data/spec/unit/display_name_spec.rb +0 -29
|
@@ -1,47 +1,39 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
+
Auth = ActiveAdmin::Authorization
|
|
2
3
|
|
|
3
4
|
describe Admin::PostsController, "Controller Authorization", :type => :controller do
|
|
4
5
|
|
|
5
|
-
let(:user) { AdminUser.create!(:email => "example@admin.com", :password => "password", :password_confirmation => "password") }
|
|
6
|
-
let(:app) { ActiveAdmin.application }
|
|
7
6
|
let(:authorization){ controller.send(:active_admin_authorization) }
|
|
8
7
|
|
|
9
8
|
before do
|
|
10
|
-
# TODO: Get these tests passing...
|
|
11
|
-
pending
|
|
12
|
-
|
|
13
9
|
load_defaults!
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
sign_in(user)
|
|
10
|
+
# HACK: the AA config is missing, so we throw it in here
|
|
11
|
+
controller.class.active_admin_config = ActiveAdmin.application.namespace(:admin).resources['Post'].controller.active_admin_config
|
|
18
12
|
end
|
|
19
13
|
|
|
20
14
|
it "should authorize the index action" do
|
|
21
|
-
authorization.should_receive(:authorized?).
|
|
22
|
-
with(ActiveAdmin::Authorization::READ, Post).
|
|
23
|
-
and_return(true)
|
|
24
|
-
|
|
15
|
+
authorization.should_receive(:authorized?).with(Auth::READ, Post).and_return true
|
|
25
16
|
get :index
|
|
17
|
+
response.should be_success
|
|
26
18
|
end
|
|
27
19
|
|
|
28
20
|
it "should authorize the new action" do
|
|
29
|
-
authorization.should_receive(:authorized?).
|
|
30
|
-
with(ActiveAdmin::Authorization::CREATE, an_instance_of(Post)).
|
|
31
|
-
and_return(true)
|
|
32
|
-
|
|
21
|
+
authorization.should_receive(:authorized?).with(Auth::CREATE, an_instance_of(Post)).and_return true
|
|
33
22
|
get :new
|
|
23
|
+
response.should be_success
|
|
34
24
|
end
|
|
35
25
|
|
|
36
26
|
it "should authorize the create action with the new resource" do
|
|
37
|
-
|
|
38
|
-
Post.should_receive(:new).at_least(:once).and_return(mock_post)
|
|
39
|
-
|
|
40
|
-
authorization.should_receive(:authorized?).
|
|
41
|
-
with(ActiveAdmin::Authorization::CREATE, mock_post).
|
|
42
|
-
and_return(true)
|
|
43
|
-
|
|
27
|
+
authorization.should_receive(:authorized?).with(Auth::CREATE, an_instance_of(Post)).and_return true
|
|
44
28
|
post :create
|
|
29
|
+
response.should redirect_to action: 'show', id: Post.last.id
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "should redirect when the user isn't authorized" do
|
|
33
|
+
authorization.should_receive(:authorized?).with(Auth::READ, Post).and_return false
|
|
34
|
+
get :index
|
|
35
|
+
response.body.should eq '<html><body>You are being <a href="http://test.host/admin">redirected</a>.</body></html>'
|
|
36
|
+
response.should redirect_to '/admin'
|
|
45
37
|
end
|
|
46
38
|
|
|
47
39
|
end
|
|
@@ -7,7 +7,7 @@ describe ActiveAdmin::BatchActions::ResourceExtension do
|
|
|
7
7
|
namespace.batch_actions = true
|
|
8
8
|
namespace.register(Post)
|
|
9
9
|
end
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
describe "default action" do
|
|
12
12
|
|
|
13
13
|
it "should have the default action by default" do
|
|
@@ -15,7 +15,7 @@ describe ActiveAdmin::BatchActions::ResourceExtension do
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
end
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
describe "adding a new batch action" do
|
|
20
20
|
|
|
21
21
|
before do
|
|
@@ -38,17 +38,17 @@ describe ActiveAdmin::BatchActions::ResourceExtension do
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
end
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
describe "removing batch action" do
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
before do
|
|
45
45
|
resource.remove_batch_action :destroy
|
|
46
46
|
end
|
|
47
|
-
|
|
47
|
+
|
|
48
48
|
it "should allow for batch action removal" do
|
|
49
49
|
resource.batch_actions.size.should == 0
|
|
50
50
|
end
|
|
51
|
-
|
|
51
|
+
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
describe "#batch_action_path" do
|
|
@@ -67,25 +67,25 @@ describe ActiveAdmin::BatchActions::ResourceExtension do
|
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
it "should return the :if block if set" do
|
|
70
|
-
action = ActiveAdmin::BatchAction.new :with_block, "With Block", :if => proc { false }
|
|
70
|
+
action = ActiveAdmin::BatchAction.new :with_block, "With Block", :if => proc { false }
|
|
71
71
|
action.display_if_block.call.should == false
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
end
|
|
75
|
-
|
|
75
|
+
|
|
76
76
|
describe "batch action priority" do
|
|
77
|
-
|
|
77
|
+
|
|
78
78
|
it "should have a default priority" do
|
|
79
79
|
action = ActiveAdmin::BatchAction.new :default, "Default"
|
|
80
80
|
action.priority.should == 10
|
|
81
81
|
end
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
it "should correctly order two actions" do
|
|
84
84
|
priority_one = ActiveAdmin::BatchAction.new :one, "One", :priority => 1
|
|
85
85
|
priority_ten = ActiveAdmin::BatchAction.new :ten, "Ten", :priority => 10
|
|
86
86
|
priority_one.should be < priority_ten
|
|
87
87
|
end
|
|
88
|
-
|
|
88
|
+
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
end
|
|
@@ -20,16 +20,24 @@ describe ActiveAdmin::CanCanAdapter do
|
|
|
20
20
|
end
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
let(:auth) { namespace.authorization_adapter.new(resource, mock) }
|
|
24
|
+
|
|
25
|
+
before do
|
|
24
26
|
namespace.authorization_adapter = ActiveAdmin::CanCanAdapter
|
|
25
27
|
namespace.cancan_ability_class = mock_ability_class
|
|
28
|
+
end
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
it "should initialize the ability stored in the namespace configuration" do
|
|
29
31
|
auth.authorized?(:read, Post).should == true
|
|
30
32
|
auth.authorized?(:update, Post).should == false
|
|
31
33
|
end
|
|
32
34
|
|
|
35
|
+
it "should scope the collection with accessible_by" do
|
|
36
|
+
collection = mock
|
|
37
|
+
collection.should_receive(:accessible_by).with(auth.cancan_ability, :edit)
|
|
38
|
+
auth.scope_collection(collection, :edit)
|
|
39
|
+
end
|
|
40
|
+
|
|
33
41
|
end
|
|
34
42
|
|
|
35
43
|
end
|
data/spec/unit/comments_spec.rb
CHANGED
|
@@ -4,16 +4,11 @@ describe "Comments" do
|
|
|
4
4
|
let(:application){ ActiveAdmin::Application.new }
|
|
5
5
|
|
|
6
6
|
describe ActiveAdmin::Comment do
|
|
7
|
-
subject { ActiveAdmin::Comment }
|
|
7
|
+
subject { ActiveAdmin::Comment.new }
|
|
8
8
|
|
|
9
9
|
describe "Associations and Validations" do
|
|
10
|
-
before do
|
|
11
|
-
pending "This is not passing on Travis-CI. See Issue #1273."
|
|
12
|
-
end
|
|
13
|
-
|
|
14
10
|
it { should belong_to :resource }
|
|
15
11
|
it { should belong_to :author }
|
|
16
|
-
|
|
17
12
|
it { should validate_presence_of :resource }
|
|
18
13
|
it { should validate_presence_of :body }
|
|
19
14
|
it { should validate_presence_of :namespace }
|
|
@@ -42,11 +37,11 @@ describe "Comments" do
|
|
|
42
37
|
ActiveAdmin::Comment.find_for_resource_in_namespace(another_post, namespace_name).should == []
|
|
43
38
|
end
|
|
44
39
|
end
|
|
45
|
-
|
|
40
|
+
|
|
46
41
|
describe ".resource_id_cast" do
|
|
47
42
|
let(:post) { Post.create!(:title => "Testing.") }
|
|
48
43
|
let(:namespace_name) { "admin" }
|
|
49
|
-
|
|
44
|
+
|
|
50
45
|
it "should cast resource_id as string" do
|
|
51
46
|
comment = ActiveAdmin::Comment.create! :resource => post,
|
|
52
47
|
:body => "Another Comment",
|
|
@@ -60,16 +55,16 @@ describe "Comments" do
|
|
|
60
55
|
ActiveAdmin::Comment.resource_id_type.should eql :string
|
|
61
56
|
end
|
|
62
57
|
end
|
|
63
|
-
|
|
58
|
+
|
|
64
59
|
describe "Commenting on resource with string id" do
|
|
65
60
|
let(:tag){ Tag.create!(:name => "cooltags") }
|
|
66
61
|
let(:namespace_name){ "admin" }
|
|
67
|
-
|
|
62
|
+
|
|
68
63
|
it "should allow commenting" do
|
|
69
|
-
comment = ActiveAdmin::Comment.create! :resource => tag,
|
|
70
|
-
:body => "Another Comment",
|
|
64
|
+
comment = ActiveAdmin::Comment.create! :resource => tag,
|
|
65
|
+
:body => "Another Comment",
|
|
71
66
|
:namespace => namespace_name
|
|
72
|
-
|
|
67
|
+
|
|
73
68
|
ActiveAdmin::Comment.find_for_resource_in_namespace(tag, namespace_name).should == [comment]
|
|
74
69
|
end
|
|
75
70
|
end
|
|
@@ -90,18 +85,6 @@ describe "Comments" do
|
|
|
90
85
|
ns.comments?.should be_false
|
|
91
86
|
end
|
|
92
87
|
|
|
93
|
-
it "should have comments when the application allows comments and no local namespace config" do
|
|
94
|
-
application.allow_comments = true
|
|
95
|
-
ns = ActiveAdmin::Namespace.new(application, :admin)
|
|
96
|
-
ns.comments?.should be_true
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it "should not have comments when the application does not allow commands and no local namespace config" do
|
|
100
|
-
application.allow_comments = false
|
|
101
|
-
ns = ActiveAdmin::Namespace.new(application, :admin)
|
|
102
|
-
ns.comments?.should be_false
|
|
103
|
-
end
|
|
104
|
-
|
|
105
88
|
end
|
|
106
89
|
end
|
|
107
90
|
|
|
@@ -113,9 +96,8 @@ describe "Comments" do
|
|
|
113
96
|
resource.comments = true
|
|
114
97
|
resource.comments.should be_true
|
|
115
98
|
end
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
ns = ActiveAdmin::Namespace.new(application, application.default_namespace)
|
|
99
|
+
it "should disable comments if set to false" do
|
|
100
|
+
ns = ActiveAdmin::Namespace.new(application, :admin)
|
|
119
101
|
resource = ActiveAdmin::Resource.new(ns, Post)
|
|
120
102
|
resource.comments = false
|
|
121
103
|
resource.comments?.should be_false
|
|
@@ -1,34 +1,32 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe ActiveAdmin
|
|
3
|
+
describe ActiveAdmin::Application do
|
|
4
4
|
let(:application){ ActiveAdmin::Application.new }
|
|
5
|
+
let(:controllers){ [ActiveAdmin::BaseController, ActiveAdmin::Devise::SessionsController,
|
|
6
|
+
ActiveAdmin::Devise::UnlocksController, ActiveAdmin::Devise::PasswordsController] }
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
application.before_filter :my_filter, :only => :show
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
describe "skip before filters" do
|
|
14
|
-
it "should add a new skip before filter to ActiveAdmin::BaseController" do
|
|
15
|
-
ActiveAdmin::BaseController.should_receive(:skip_before_filter).and_return(true)
|
|
16
|
-
application.skip_before_filter :my_filter, :only => :show
|
|
17
|
-
end
|
|
8
|
+
it 'before_filter' do
|
|
9
|
+
controllers.each{ |c| c.should_receive(:before_filter).and_return(true) }
|
|
10
|
+
application.before_filter :my_filter, :only => :show
|
|
18
11
|
end
|
|
19
12
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
application.after_filter :my_filter, :only => :show
|
|
24
|
-
end
|
|
13
|
+
it 'skip_before_filter' do
|
|
14
|
+
controllers.each{ |c| c.should_receive(:skip_before_filter).and_return(true) }
|
|
15
|
+
application.skip_before_filter :my_filter, :only => :show
|
|
25
16
|
end
|
|
26
17
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
application.around_filter :my_filter, :only => :show
|
|
31
|
-
end
|
|
18
|
+
it 'after_filter' do
|
|
19
|
+
controllers.each{ |c| c.should_receive(:after_filter).and_return(true) }
|
|
20
|
+
application.after_filter :my_filter, :only => :show
|
|
32
21
|
end
|
|
33
22
|
|
|
23
|
+
it 'around_filter' do
|
|
24
|
+
controllers.each{ |c| c.should_receive(:around_filter).and_return(true) }
|
|
25
|
+
application.around_filter :my_filter, :only => :show
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'skip_filter' do
|
|
29
|
+
controllers.each{ |c| c.should_receive(:skip_filter).and_return(true) }
|
|
30
|
+
application.skip_filter :my_filter, :only => :show
|
|
31
|
+
end
|
|
34
32
|
end
|
|
@@ -82,17 +82,17 @@ describe ActiveAdmin::CSVBuilder do
|
|
|
82
82
|
|
|
83
83
|
context "with a separator" do
|
|
84
84
|
let(:builder) do
|
|
85
|
-
ActiveAdmin::CSVBuilder.new :
|
|
85
|
+
ActiveAdmin::CSVBuilder.new :col_sep => ";"
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
it "should have proper separator" do
|
|
89
|
-
builder.
|
|
89
|
+
builder.options.should == {:col_sep => ";"}
|
|
90
90
|
end
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
context "with csv_options" do
|
|
94
94
|
let(:builder) do
|
|
95
|
-
ActiveAdmin::CSVBuilder.new :
|
|
95
|
+
ActiveAdmin::CSVBuilder.new :force_quotes => true
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
it "should have proper separator" do
|
data/spec/unit/devise_spec.rb
CHANGED
|
@@ -12,11 +12,11 @@ describe ActiveAdmin::Devise::Controller do
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
let(:controller) { controller_class.new }
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
context 'with a RAILS_RELATIVE_URL_ROOT set' do
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
before { Rails.configuration.action_controller[:relative_url_root] = '/foo' }
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
it "should set the root path to the default namespace" do
|
|
21
21
|
controller.root_path.should == "/foo/admin"
|
|
22
22
|
end
|
|
@@ -25,22 +25,22 @@ describe ActiveAdmin::Devise::Controller do
|
|
|
25
25
|
ActiveAdmin.application.stub!(:default_namespace => false)
|
|
26
26
|
controller.root_path.should == "/foo/"
|
|
27
27
|
end
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
end
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
context 'without a RAILS_RELATIVE_URL_ROOT set' do
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
before { Rails.configuration.action_controller[:relative_url_root] = nil }
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
it "should set the root path to the default namespace" do
|
|
36
36
|
controller.root_path.should == "/admin"
|
|
37
37
|
end
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
it "should set the root path to '/' when no default namespace" do
|
|
40
40
|
ActiveAdmin.application.stub!(:default_namespace => false)
|
|
41
41
|
controller.root_path.should == "/"
|
|
42
42
|
end
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
context "within a scoped route" do
|
|
@@ -71,7 +71,7 @@ describe ActiveAdmin::Devise::Controller do
|
|
|
71
71
|
end
|
|
72
72
|
|
|
73
73
|
end
|
|
74
|
-
|
|
74
|
+
|
|
75
75
|
describe "#config" do
|
|
76
76
|
let(:config) { ActiveAdmin::Devise.config }
|
|
77
77
|
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
1
|
+
require 'spec_helper'
|
|
2
2
|
|
|
3
|
+
class Post
|
|
4
|
+
scope :custom_searcher, ->stuff { where(body: stuff) }
|
|
5
|
+
search_method :custom_searcher
|
|
6
|
+
end
|
|
3
7
|
|
|
4
8
|
describe ActiveAdmin::Filters::ViewHelper do
|
|
5
9
|
|
|
6
10
|
# Setup an ActionView::Base object which can be used for
|
|
7
11
|
# generating the form for.
|
|
8
|
-
let(:helpers) do
|
|
12
|
+
let(:helpers) do
|
|
9
13
|
view = action_view
|
|
10
14
|
def view.collection_path
|
|
11
15
|
"/posts"
|
|
@@ -29,9 +33,11 @@ describe ActiveAdmin::Filters::ViewHelper do
|
|
|
29
33
|
end
|
|
30
34
|
|
|
31
35
|
def filter(name, options = {})
|
|
32
|
-
render_filter
|
|
36
|
+
render_filter scope, @filters.push(options.merge(:attribute => name))
|
|
33
37
|
end
|
|
34
38
|
|
|
39
|
+
let(:scope) { Post.search }
|
|
40
|
+
|
|
35
41
|
before(:each) { @filters = [] }
|
|
36
42
|
|
|
37
43
|
|
|
@@ -59,25 +65,53 @@ describe ActiveAdmin::Filters::ViewHelper do
|
|
|
59
65
|
describe "string attribute" do
|
|
60
66
|
let(:body) { filter :title }
|
|
61
67
|
|
|
62
|
-
it "should generate a
|
|
63
|
-
body.should have_tag("
|
|
68
|
+
it "should generate a select option for starts with" do
|
|
69
|
+
body.should have_tag("option", "Starts with", :attributes => { :value => 'title_starts_with' })
|
|
64
70
|
end
|
|
65
71
|
|
|
66
|
-
it "should
|
|
67
|
-
body.should have_tag(
|
|
72
|
+
it "should generate a select option for ends with" do
|
|
73
|
+
body.should have_tag("option", "Ends with", :attributes => { :value => 'title_ends_with' })
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "should generate a select option for contains" do
|
|
77
|
+
body.should have_tag("option", "Contains", :attributes => { :value => 'title_contains' })
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it "should generate a text field for input" do
|
|
81
|
+
body.should have_tag("input", :attributes => { :name => 'q[title_contains]' })
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "should have a proper label" do
|
|
85
|
+
body.should have_tag('label', 'Title')
|
|
68
86
|
end
|
|
69
87
|
|
|
70
88
|
it "should translate the label for text field" do
|
|
71
89
|
begin
|
|
72
90
|
I18n.backend.store_translations(:en, :activerecord => { :attributes => { :post => { :title => "Name" } } })
|
|
73
|
-
body.should have_tag('label', '
|
|
91
|
+
body.should have_tag('label', 'Name')
|
|
74
92
|
ensure
|
|
75
93
|
I18n.backend.reload!
|
|
76
94
|
end
|
|
77
95
|
end
|
|
78
96
|
|
|
97
|
+
it "should select the option which is currently being filtered"
|
|
98
|
+
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
describe "string attribute with sub filters" do
|
|
102
|
+
let(:body) { filter :title_contains }
|
|
103
|
+
|
|
104
|
+
it "should generate a search field for a string attribute with query contains" do
|
|
105
|
+
body.should have_tag("input", :attributes => { :name => "q[title_contains]"})
|
|
106
|
+
body.should have_tag('label', 'Title contains')
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "should NOT generate a select option for contains" do
|
|
110
|
+
body.should_not have_tag("option", "Contains", :attributes => { :value => 'title_contains' })
|
|
111
|
+
end
|
|
112
|
+
|
|
79
113
|
context "using starts_with and as" do
|
|
80
|
-
let(:body) { filter :title_starts_with
|
|
114
|
+
let(:body) { filter :title_starts_with }
|
|
81
115
|
|
|
82
116
|
it "should generate a search field for a string attribute with query starts_with" do
|
|
83
117
|
body.should have_tag("input", :attributes => { :name => "q[title_starts_with]" })
|
|
@@ -85,14 +119,22 @@ describe ActiveAdmin::Filters::ViewHelper do
|
|
|
85
119
|
end
|
|
86
120
|
|
|
87
121
|
context "using ends_with and as" do
|
|
88
|
-
let(:body) { filter :title_ends_with
|
|
122
|
+
let(:body) { filter :title_ends_with }
|
|
89
123
|
|
|
90
124
|
it "should generate a search field for a string attribute with query starts_with" do
|
|
91
125
|
body.should have_tag("input", :attributes => { :name => "q[title_ends_with]" })
|
|
92
126
|
end
|
|
93
127
|
end
|
|
94
|
-
|
|
128
|
+
|
|
129
|
+
context "using contains and NO AS defined" do
|
|
130
|
+
let(:body) { filter :title_contains }
|
|
95
131
|
|
|
132
|
+
it "should generate a search field for a string attribute with query contains" do
|
|
133
|
+
body.should have_tag("input", :attributes => { :name => "q[title_contains]" })
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
96
138
|
describe "text attribute" do
|
|
97
139
|
let(:body) { filter :body }
|
|
98
140
|
|
|
@@ -100,11 +142,32 @@ describe ActiveAdmin::Filters::ViewHelper do
|
|
|
100
142
|
body.should have_tag("input", :attributes => { :name => "q[body_contains]"})
|
|
101
143
|
end
|
|
102
144
|
|
|
103
|
-
it "should
|
|
104
|
-
body.should have_tag('label', '
|
|
145
|
+
it "should have a proper label" do
|
|
146
|
+
body.should have_tag('label', 'Body')
|
|
105
147
|
end
|
|
106
148
|
end
|
|
107
149
|
|
|
150
|
+
describe "string attribute, as a select" do
|
|
151
|
+
let(:body) { filter :title, as: :select }
|
|
152
|
+
let(:builder) { ActiveAdmin::Inputs::FilterSelectInput }
|
|
153
|
+
|
|
154
|
+
context "when loading collection from DB" do
|
|
155
|
+
it "should use pluck for efficiency" do
|
|
156
|
+
builder.any_instance.should_receive(:pluck_column) { [] }
|
|
157
|
+
body
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
it "should remove original ordering to prevent PostgreSQL error" do
|
|
161
|
+
scope.base.should_receive(:reorder).with('title asc') {
|
|
162
|
+
m = mock uniq: mock(pluck: ['A Title'])
|
|
163
|
+
m.uniq.should_receive(:pluck).with :title
|
|
164
|
+
m
|
|
165
|
+
}
|
|
166
|
+
body
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end unless Rails::VERSION::MAJOR == 3 && Rails::VERSION::MINOR < 2
|
|
170
|
+
|
|
108
171
|
describe "datetime attribute" do
|
|
109
172
|
let(:body) { filter :created_at }
|
|
110
173
|
|
|
@@ -123,17 +186,16 @@ describe ActiveAdmin::Filters::ViewHelper do
|
|
|
123
186
|
let(:body) { filter :id }
|
|
124
187
|
|
|
125
188
|
it "should generate a select option for equal to" do
|
|
126
|
-
body.should have_tag("option", "
|
|
189
|
+
body.should have_tag("option", "Equals", :attributes => { :value => 'id_equals' })
|
|
127
190
|
end
|
|
128
191
|
it "should generate a select option for greater than" do
|
|
129
|
-
body.should have_tag("option", "Greater
|
|
192
|
+
body.should have_tag("option", "Greater than")
|
|
130
193
|
end
|
|
131
194
|
it "should generate a select option for less than" do
|
|
132
|
-
body.should have_tag("option", "Less
|
|
195
|
+
body.should have_tag("option", "Less than")
|
|
133
196
|
end
|
|
134
197
|
it "should generate a text field for input" do
|
|
135
|
-
body.should have_tag("input", :attributes => {
|
|
136
|
-
:name => /q\[(id_eq|id_equals)\]/ })
|
|
198
|
+
body.should have_tag("input", :attributes => { :name => 'q[id_equals]' })
|
|
137
199
|
end
|
|
138
200
|
it "should select the option which is currently being filtered"
|
|
139
201
|
end
|
|
@@ -147,6 +209,15 @@ describe ActiveAdmin::Filters::ViewHelper do
|
|
|
147
209
|
:name => "q[starred_eq]",
|
|
148
210
|
:type => "checkbox" })
|
|
149
211
|
end
|
|
212
|
+
|
|
213
|
+
it "should translate the label for boolean field" do
|
|
214
|
+
begin
|
|
215
|
+
I18n.backend.store_translations(:en, :activerecord => { :attributes => { :post => { :starred => "Faved" } } })
|
|
216
|
+
body.should have_tag('label', 'Faved')
|
|
217
|
+
ensure
|
|
218
|
+
I18n.backend.reload!
|
|
219
|
+
end
|
|
220
|
+
end
|
|
150
221
|
end
|
|
151
222
|
|
|
152
223
|
context "non-boolean data types" do
|
|
@@ -160,7 +231,7 @@ describe ActiveAdmin::Filters::ViewHelper do
|
|
|
160
231
|
end
|
|
161
232
|
end
|
|
162
233
|
|
|
163
|
-
describe "
|
|
234
|
+
describe "belongs_to" do
|
|
164
235
|
before do
|
|
165
236
|
@john = User.create :first_name => "John", :last_name => "Doe", :username => "john_doe"
|
|
166
237
|
@jane = User.create :first_name => "Jane", :last_name => "Doe", :username => "jane_doe"
|
|
@@ -169,17 +240,10 @@ describe ActiveAdmin::Filters::ViewHelper do
|
|
|
169
240
|
context "when given as the _id attribute name" do
|
|
170
241
|
let(:body) { filter :author_id }
|
|
171
242
|
|
|
172
|
-
it "should
|
|
173
|
-
body.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
it "should render as belongs to select" do
|
|
177
|
-
body.should have_tag("select", :attributes => {
|
|
178
|
-
:name => "q[author_id_eq]"})
|
|
179
|
-
body.should have_tag("option", "john_doe", :attributes => {
|
|
180
|
-
:value => @john.id })
|
|
181
|
-
body.should have_tag("option", "jane_doe", :attributes => {
|
|
182
|
-
:value => @jane.id })
|
|
243
|
+
it "should generate a numeric filter" do
|
|
244
|
+
body.should have_tag 'label', 'Author' # really this should be Author ID :/
|
|
245
|
+
body.should have_tag 'option', :attributes => { :value => 'author_id_less_than' }
|
|
246
|
+
body.should have_tag 'input', :attributes => { :id => 'q_author_id', :name => 'q[author_id_equals]'}
|
|
183
247
|
end
|
|
184
248
|
end
|
|
185
249
|
|
|
@@ -187,18 +251,14 @@ describe ActiveAdmin::Filters::ViewHelper do
|
|
|
187
251
|
let(:body) { filter :author }
|
|
188
252
|
|
|
189
253
|
it "should generate a select" do
|
|
190
|
-
body.should have_tag
|
|
191
|
-
:name => "q[author_id_eq]"})
|
|
254
|
+
body.should have_tag "select", :attributes => { :name => "q[author_id_eq]" }
|
|
192
255
|
end
|
|
193
256
|
it "should set the default text to 'Any'" do
|
|
194
|
-
body.should have_tag
|
|
195
|
-
:value => "" })
|
|
257
|
+
body.should have_tag "option", "Any", :attributes => { :value => "" }
|
|
196
258
|
end
|
|
197
259
|
it "should create an option for each related object" do
|
|
198
|
-
body.should have_tag
|
|
199
|
-
|
|
200
|
-
body.should have_tag("option", "jane_doe", :attributes => {
|
|
201
|
-
:value => @jane.id })
|
|
260
|
+
body.should have_tag "option", "John Doe", :attributes => { :value => @john.id }
|
|
261
|
+
body.should have_tag "option", "Jane Doe", :attributes => { :value => @jane.id }
|
|
202
262
|
end
|
|
203
263
|
|
|
204
264
|
context "with a proc" do
|
|
@@ -228,22 +288,24 @@ describe ActiveAdmin::Filters::ViewHelper do
|
|
|
228
288
|
:value => @john.id })
|
|
229
289
|
body.should have_tag("input", :attributes => {
|
|
230
290
|
:name => "q[author_id_in][]",
|
|
231
|
-
:type => "checkbox",
|
|
291
|
+
:type => "checkbox",
|
|
232
292
|
:value => @jane.id })
|
|
233
293
|
end
|
|
234
294
|
end
|
|
235
295
|
|
|
236
296
|
context "when polymorphic relationship" do
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
body.should have_tag("form", :attributes => { :method => 'get' })
|
|
297
|
+
it "should raise an error if a collection isn't provided" do
|
|
298
|
+
expect {
|
|
299
|
+
search = ActiveAdmin::Comment.search
|
|
300
|
+
render_filter(search, [{:attribute => :resource}])
|
|
301
|
+
}.to raise_error Formtastic::PolymorphicInputWithoutCollectionError
|
|
243
302
|
end
|
|
244
303
|
end
|
|
245
304
|
end # belongs to
|
|
246
305
|
|
|
306
|
+
describe "has_and_belongs_to_many" do
|
|
307
|
+
pending "add HABTM models so this can be mocked out"
|
|
308
|
+
end
|
|
247
309
|
|
|
248
310
|
describe "conditional display" do
|
|
249
311
|
|
|
@@ -278,4 +340,37 @@ describe ActiveAdmin::Filters::ViewHelper do
|
|
|
278
340
|
end
|
|
279
341
|
end
|
|
280
342
|
|
|
343
|
+
describe "custom search methods" do
|
|
344
|
+
|
|
345
|
+
it "should work as select" do
|
|
346
|
+
body = filter :custom_searcher, as: :select, collection: ['foo']
|
|
347
|
+
body.should have_tag "select", attributes: { name: "q[custom_searcher]" }
|
|
348
|
+
end
|
|
349
|
+
|
|
350
|
+
it "should work as string" do
|
|
351
|
+
body = filter :custom_searcher, as: :string
|
|
352
|
+
body.should have_tag "input", attributes: { name: "q[custom_searcher]" }
|
|
353
|
+
end
|
|
354
|
+
end
|
|
355
|
+
|
|
356
|
+
describe "blank option" do
|
|
357
|
+
context "for a select filter" do
|
|
358
|
+
it "should be there by default" do
|
|
359
|
+
filter(:author).should have_tag "option", "Any"
|
|
360
|
+
end
|
|
361
|
+
it "should be able to be disabled" do
|
|
362
|
+
filter(:author, include_blank: false).should_not have_tag "option", "Any"
|
|
363
|
+
end
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
context "for a multi-select filter" do
|
|
367
|
+
it "should not be there by default" do
|
|
368
|
+
filter(:author, multiple: true).should_not have_tag "option", "Any"
|
|
369
|
+
end
|
|
370
|
+
it "should be able to be enabled" do
|
|
371
|
+
filter(:author, multiple: true, include_blank: true).should have_tag "option", "Any"
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
end
|
|
375
|
+
|
|
281
376
|
end
|