activeadmin 1.0.0.pre4 → 1.0.0.pre5
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.
- checksums.yaml +4 -4
- data/.gitignore +3 -3
- data/.travis.yml +48 -26
- data/Appraisals +103 -0
- data/CHANGELOG.md +12 -1
- data/CONTRIBUTING.md +85 -32
- data/Gemfile +13 -38
- data/README.md +10 -26
- data/Rakefile +41 -9
- data/activeadmin.gemspec +7 -4
- data/app/assets/javascripts/active_admin/initializers/filters.js.coffee +10 -3
- data/app/assets/javascripts/active_admin/jquery_ui.js.erb +11 -4
- data/app/assets/javascripts/active_admin/lib/checkbox-toggler.js.coffee +8 -0
- data/app/assets/javascripts/active_admin/lib/modal_dialog.js.coffee +1 -1
- data/app/assets/javascripts/active_admin/lib/per_page.js.coffee +14 -3
- data/app/assets/stylesheets/active_admin/_forms.scss +1 -0
- data/app/views/active_admin/devise/registrations/new.html.erb +1 -1
- data/codecov.yml +23 -0
- data/config/locales/es-MX.yml +1 -1
- data/config/locales/es.yml +1 -1
- data/config/locales/ru.yml +1 -0
- data/config/locales/sk.yml +110 -0
- data/docs/0-installation.md +3 -0
- data/docs/1-general-configuration.md +11 -0
- data/docs/10-custom-pages.md +25 -0
- data/docs/11-decorators.md +3 -0
- data/docs/12-arbre-components.md +3 -0
- data/docs/13-authorization-adapter.md +3 -0
- data/docs/14-gotchas.md +19 -0
- data/docs/2-resource-customization.md +21 -2
- data/docs/3-index-pages.md +21 -0
- data/docs/3-index-pages/custom-index.md +3 -0
- data/docs/3-index-pages/index-as-block.md +3 -0
- data/docs/3-index-pages/index-as-blog.md +3 -0
- data/docs/3-index-pages/index-as-grid.md +3 -0
- data/docs/3-index-pages/index-as-table.md +22 -0
- data/docs/4-csv-format.md +15 -0
- data/docs/5-forms.md +7 -3
- data/docs/6-show-pages.md +3 -0
- data/docs/7-sidebars.md +3 -0
- data/docs/8-custom-actions.md +3 -0
- data/docs/9-batch-actions.md +4 -1
- data/docs/CNAME +1 -0
- data/docs/Gemfile +2 -0
- data/docs/_config.yml +2 -0
- data/docs/_includes/footer.html +8 -0
- data/docs/_includes/google-analytics.html +16 -0
- data/docs/_includes/head.html +7 -0
- data/docs/_includes/toc.html +97 -0
- data/docs/_includes/top-menu.html +9 -0
- data/docs/_layouts/default.html +21 -0
- data/docs/documentation.md +62 -0
- data/docs/images/activeadmin.png +0 -0
- data/docs/images/code-header.png +0 -0
- data/docs/images/divider.png +0 -0
- data/docs/images/features.png +0 -0
- data/docs/index.html +130 -0
- data/docs/stylesheets/main.css +1199 -0
- data/features/action_item.feature +2 -2
- data/features/authorization_cancan.feature +3 -3
- data/features/belongs_to.feature +60 -2
- data/features/comments/commenting.feature +7 -7
- data/features/development_reloading.feature +1 -1
- data/features/edit_page.feature +9 -9
- data/features/footer.feature +28 -0
- data/features/i18n.feature +11 -0
- data/features/index/batch_actions.feature +28 -6
- data/features/index/filters.feature +31 -11
- data/features/index/format_as_csv.feature +13 -13
- data/features/index/formats.feature +4 -4
- data/features/index/index_as_block.feature +1 -1
- data/features/index/index_as_blog.feature +6 -6
- data/features/index/index_as_grid.feature +3 -3
- data/features/index/index_as_table.feature +11 -11
- data/features/index/index_blank_slate.feature +4 -4
- data/features/index/index_parameters.feature +10 -10
- data/features/index/index_scope_to.feature +3 -3
- data/features/index/index_scopes.feature +37 -18
- data/features/index/page_title.feature +3 -3
- data/features/index/pagination.feature +1 -1
- data/features/index/switch_index_view.feature +8 -8
- data/features/menu.feature +3 -3
- data/features/new_page.feature +8 -8
- data/features/registering_assets.feature +1 -1
- data/features/registering_pages.feature +73 -2
- data/features/registering_resources.feature +1 -1
- data/features/renamed_resource.feature +1 -1
- data/features/show/page_title.feature +3 -3
- data/features/sidebar_sections.feature +6 -6
- data/features/specifying_actions.feature +29 -4
- data/features/step_definitions/factory_steps.rb +1 -1
- data/features/step_definitions/footer_steps.rb +11 -0
- data/features/step_definitions/i18n_steps.rb +8 -0
- data/features/step_definitions/index_scope_steps.rb +4 -0
- data/features/step_definitions/sidebar_steps.rb +1 -3
- data/features/step_definitions/table_steps.rb +1 -5
- data/features/step_definitions/user_steps.rb +7 -0
- data/features/support/env.rb +6 -33
- data/features/support/paths.rb +5 -0
- data/features/users/logging_in.feature +2 -0
- data/gemfiles/rails_32.gemfile +54 -0
- data/gemfiles/rails_40.gemfile +53 -0
- data/gemfiles/rails_41.gemfile +53 -0
- data/gemfiles/rails_42.gemfile +53 -0
- data/gemfiles/rails_50.gemfile +46 -0
- data/lib/active_admin.rb +1 -0
- data/lib/active_admin/application.rb +11 -0
- data/lib/active_admin/batch_actions/resource_extension.rb +0 -8
- data/lib/active_admin/batch_actions/views/batch_action_form.rb +1 -1
- data/lib/active_admin/batch_actions/views/batch_action_selector.rb +1 -1
- data/lib/active_admin/dsl.rb +0 -6
- data/lib/active_admin/filters/active.rb +9 -1
- data/lib/active_admin/filters/formtastic_addons.rb +1 -1
- data/lib/active_admin/filters/humanized.rb +1 -1
- data/lib/active_admin/filters/resource_extension.rb +2 -4
- data/lib/active_admin/form_builder.rb +12 -6
- data/lib/active_admin/helpers/collection.rb +2 -0
- data/lib/active_admin/inputs.rb +1 -0
- data/lib/active_admin/inputs/filters/date_range_input.rb +9 -4
- data/lib/active_admin/inputs/filters/text_input.rb +26 -0
- data/lib/active_admin/localizers.rb +11 -0
- data/lib/active_admin/localizers/resource_localizer.rb +35 -0
- data/lib/active_admin/namespace.rb +1 -1
- data/lib/active_admin/order_clause.rb +29 -7
- data/lib/active_admin/page.rb +18 -4
- data/lib/active_admin/page_dsl.rb +4 -0
- data/lib/active_admin/resource.rb +16 -1
- data/lib/active_admin/resource/action_items.rb +7 -4
- data/lib/active_admin/resource/belongs_to.rb +4 -0
- data/lib/active_admin/resource/menu.rb +1 -1
- data/lib/active_admin/resource/ordering.rb +11 -0
- data/lib/active_admin/resource/routes.rb +34 -13
- data/lib/active_admin/resource/scopes.rb +1 -0
- data/lib/active_admin/resource_controller/data_access.rb +3 -10
- data/lib/active_admin/resource_dsl.rb +28 -1
- data/lib/active_admin/router.rb +5 -3
- data/lib/active_admin/scope.rb +3 -3
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_helpers/auto_link_helper.rb +2 -2
- data/lib/active_admin/view_helpers/display_helper.rb +8 -3
- data/lib/active_admin/view_helpers/method_or_proc_helper.rb +5 -1
- data/lib/active_admin/views/components/active_admin_form.rb +11 -10
- data/lib/active_admin/views/components/attributes_table.rb +1 -1
- data/lib/active_admin/views/components/columns.rb +3 -3
- data/lib/active_admin/views/components/dropdown_menu.rb +2 -2
- data/lib/active_admin/views/components/index_list.rb +4 -1
- data/lib/active_admin/views/components/paginated_collection.rb +1 -0
- data/lib/active_admin/views/components/scopes.rb +8 -1
- data/lib/active_admin/views/components/site_title.rb +2 -2
- data/lib/active_admin/views/components/table_for.rb +3 -3
- data/lib/active_admin/views/footer.rb +17 -3
- data/lib/active_admin/views/index_as_table.rb +3 -3
- data/lib/active_admin/views/pages/base.rb +4 -2
- data/lib/active_admin/views/pages/form.rb +2 -3
- data/lib/active_admin/views/pages/show.rb +2 -1
- data/lib/bug_report_templates/rails_5_master.rb +120 -0
- data/lib/generators/active_admin/devise/devise_generator.rb +6 -3
- data/lib/generators/active_admin/install/install_generator.rb +1 -1
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +15 -1
- data/lib/generators/active_admin/install/templates/migrations/{create_active_admin_comments.rb → create_active_admin_comments.rb.erb} +14 -1
- data/lib/ransack_ext.rb +2 -2
- data/spec/bug_report_templates_spec.rb +27 -0
- data/spec/javascripts/support/jasmine_runner.rb +4 -17
- data/spec/rails_helper.rb +20 -109
- data/spec/requests/default_namespace_spec.rb +16 -28
- data/spec/requests/javascript_spec.rb +1 -1
- data/spec/requests/memory_spec.rb +5 -1
- data/spec/requests/stylesheets_spec.rb +1 -1
- data/spec/spec_helper.rb +5 -10
- data/spec/support/active_admin_integration_spec_helper.rb +66 -0
- data/spec/support/active_admin_request_helpers.rb +12 -0
- data/spec/support/rails_template.rb +42 -15
- data/spec/support/rails_template_with_data.rb +24 -5
- data/spec/support/templates/manifest.js +3 -0
- data/spec/support/templates/policies/application_policy.rb +1 -1
- data/spec/unit/abstract_view_factory_spec.rb +1 -1
- data/spec/unit/action_builder_spec.rb +3 -12
- data/spec/unit/active_admin_spec.rb +1 -1
- data/spec/unit/application_spec.rb +5 -1
- data/spec/unit/asset_registration_spec.rb +1 -1
- data/spec/unit/authorization/authorization_adapter_spec.rb +1 -1
- data/spec/unit/authorization/controller_authorization_spec.rb +13 -9
- data/spec/unit/authorization/index_overriding_spec.rb +6 -6
- data/spec/unit/auto_link_spec.rb +48 -24
- data/spec/unit/batch_actions/resource_spec.rb +1 -14
- data/spec/unit/batch_actions/settings_spec.rb +1 -1
- data/spec/unit/belongs_to_spec.rb +9 -1
- data/spec/unit/cancan_adapter_spec.rb +1 -1
- data/spec/unit/comments_spec.rb +26 -19
- data/spec/unit/component_spec.rb +1 -1
- data/spec/unit/config_shared_examples.rb +1 -1
- data/spec/unit/controller_filters_spec.rb +1 -1
- data/spec/unit/csv_builder_spec.rb +5 -5
- data/spec/unit/dependency_spec.rb +1 -1
- data/spec/unit/devise_spec.rb +17 -3
- data/spec/unit/dsl_spec.rb +2 -2
- data/spec/unit/filters/active_spec.rb +21 -0
- data/spec/unit/filters/filter_form_builder_spec.rb +98 -31
- data/spec/unit/filters/humanized_spec.rb +9 -1
- data/spec/unit/filters/resource_spec.rb +5 -4
- data/spec/unit/form_builder_spec.rb +180 -33
- data/spec/unit/generators/install_spec.rb +12 -5
- data/spec/unit/helpers/collection_spec.rb +10 -7
- data/spec/unit/helpers/scope_chain_spec.rb +1 -1
- data/spec/unit/helpers/settings_spec.rb +1 -1
- data/spec/unit/i18n_spec.rb +1 -1
- data/spec/unit/localizers/resource_localizer_spec.rb +36 -0
- data/spec/unit/menu_collection_spec.rb +1 -1
- data/spec/unit/menu_item_spec.rb +1 -1
- data/spec/unit/menu_spec.rb +1 -1
- data/spec/unit/namespace/authorization_spec.rb +1 -1
- data/spec/unit/namespace/register_page_spec.rb +28 -2
- data/spec/unit/namespace/register_resource_spec.rb +3 -1
- data/spec/unit/namespace_spec.rb +23 -1
- data/spec/unit/order_clause_spec.rb +7 -7
- data/spec/unit/page_controller_spec.rb +1 -1
- data/spec/unit/page_spec.rb +55 -2
- data/spec/unit/pretty_format_spec.rb +8 -7
- data/spec/unit/pundit_adapter_spec.rb +1 -1
- data/spec/unit/resource/action_items_spec.rb +1 -1
- data/spec/unit/resource/includes_spec.rb +1 -1
- data/spec/unit/resource/menu_spec.rb +1 -1
- data/spec/unit/resource/naming_spec.rb +1 -1
- data/spec/unit/resource/ordering_spec.rb +38 -0
- data/spec/unit/resource/page_presenters_spec.rb +1 -1
- data/spec/unit/resource/pagination_spec.rb +1 -1
- data/spec/unit/resource/routes_spec.rb +101 -53
- data/spec/unit/resource/scopes_spec.rb +1 -1
- data/spec/unit/resource/sidebars_spec.rb +1 -1
- data/spec/unit/resource_collection_spec.rb +1 -1
- data/spec/unit/resource_controller/data_access_spec.rb +50 -1
- data/spec/unit/resource_controller/decorators_spec.rb +2 -2
- data/spec/unit/resource_controller/sidebars_spec.rb +16 -17
- data/spec/unit/resource_controller_spec.rb +50 -56
- data/spec/unit/resource_registration_spec.rb +9 -4
- data/spec/unit/resource_spec.rb +9 -1
- data/spec/unit/routing_spec.rb +30 -2
- data/spec/unit/scope_spec.rb +26 -2
- data/spec/unit/settings_spec.rb +2 -2
- data/spec/unit/view_factory_spec.rb +1 -1
- data/spec/unit/view_helpers/breadcrumbs_spec.rb +1 -1
- data/spec/unit/view_helpers/display_helper_spec.rb +18 -3
- data/spec/unit/view_helpers/download_format_links_helper_spec.rb +1 -1
- data/spec/unit/view_helpers/fields_for_spec.rb +1 -1
- data/spec/unit/view_helpers/flash_helper_spec.rb +1 -1
- data/spec/unit/view_helpers/form_helper_spec.rb +1 -1
- data/spec/unit/view_helpers/method_or_proc_helper_spec.rb +1 -1
- data/spec/unit/views/components/attributes_table_spec.rb +1 -1
- data/spec/unit/views/components/batch_action_selector_spec.rb +1 -1
- data/spec/unit/views/components/blank_slate_spec.rb +1 -1
- data/spec/unit/views/components/columns_spec.rb +1 -1
- data/spec/unit/views/components/index_list_spec.rb +18 -4
- data/spec/unit/views/components/index_table_for_spec.rb +1 -1
- data/spec/unit/views/components/paginated_collection_spec.rb +1 -1
- data/spec/unit/views/components/panel_spec.rb +1 -1
- data/spec/unit/views/components/sidebar_section_spec.rb +1 -1
- data/spec/unit/views/components/site_title_spec.rb +1 -1
- data/spec/unit/views/components/status_tag_spec.rb +1 -1
- data/spec/unit/views/components/table_for_spec.rb +9 -7
- data/spec/unit/views/components/tabs_spec.rb +1 -1
- data/spec/unit/views/components/unsupported_browser_spec.rb +3 -3
- data/spec/unit/views/index_as_blog_spec.rb +1 -1
- data/spec/unit/views/pages/form_spec.rb +1 -1
- data/spec/unit/views/pages/index_spec.rb +1 -1
- data/spec/unit/views/pages/layout_spec.rb +1 -1
- data/spec/unit/views/pages/show_spec.rb +1 -1
- data/spec/unit/views/tabbed_navigation_spec.rb +2 -2
- data/tasks/local.rake +25 -0
- data/tasks/parallel_tests.rake +4 -4
- data/tasks/test.rake +8 -53
- metadata +61 -18
- data/Guardfile +0 -8
- data/script/local +0 -53
- data/script/travis_cache +0 -107
- data/script/use_rails +0 -53
- data/spec/javascripts/support/jasmine_config.rb +0 -23
- data/spec/support/detect_rails_version.rb +0 -34
@@ -4,19 +4,38 @@ apply File.expand_path("../rails_template.rb", __FILE__)
|
|
4
4
|
generate :'active_admin:resource', type
|
5
5
|
end
|
6
6
|
|
7
|
+
inject_into_file 'app/admin/category.rb', <<-RUBY, after: "ActiveAdmin.register Category do\n"
|
8
|
+
|
9
|
+
if Rails::VERSION::MAJOR >= 4
|
10
|
+
permit_params [:name, :description]
|
11
|
+
end
|
12
|
+
RUBY
|
13
|
+
|
14
|
+
inject_into_file 'app/admin/user.rb', <<-RUBY, after: "ActiveAdmin.register User do\n"
|
15
|
+
|
16
|
+
if Rails::VERSION::MAJOR >= 4
|
17
|
+
permit_params [:first_name, :last_name, :username, :age]
|
18
|
+
end
|
19
|
+
RUBY
|
20
|
+
|
7
21
|
inject_into_file 'app/admin/post.rb', <<-RUBY, after: "ActiveAdmin.register Post do\n"
|
22
|
+
|
23
|
+
if Rails::VERSION::MAJOR >= 4
|
24
|
+
permit_params [:custom_category_id, :author_id, :title, :body, :published_date, :position, :starred]
|
25
|
+
end
|
26
|
+
|
8
27
|
scope :all, default: true
|
9
28
|
|
10
29
|
scope :drafts do |posts|
|
11
|
-
posts.where(["
|
30
|
+
posts.where(["published_date IS NULL"])
|
12
31
|
end
|
13
32
|
|
14
33
|
scope :scheduled do |posts|
|
15
|
-
posts.where(["posts.
|
34
|
+
posts.where(["posts.published_date IS NOT NULL AND posts.published_date > ?", Time.now.utc])
|
16
35
|
end
|
17
36
|
|
18
37
|
scope :published do |posts|
|
19
|
-
posts.where(["posts.
|
38
|
+
posts.where(["posts.published_date IS NOT NULL AND posts.published_date < ?", Time.now.utc])
|
20
39
|
end
|
21
40
|
|
22
41
|
scope :my_posts do |posts|
|
@@ -42,11 +61,11 @@ append_file "db/seeds.rb", "\n\n" + <<-RUBY.strip_heredoc
|
|
42
61
|
1_000.times do |i|
|
43
62
|
user = users[i % users.size]
|
44
63
|
cat = categories[i % categories.size]
|
45
|
-
|
64
|
+
published = published_at_values[i % published_at_values.size]
|
46
65
|
Post.create title: "Blog Post \#{i}",
|
47
66
|
body: "Blog post \#{i} is written by \#{user.username} about \#{cat.name}",
|
48
67
|
category: cat,
|
49
|
-
|
68
|
+
published_date: published,
|
50
69
|
author: user,
|
51
70
|
starred: true
|
52
71
|
end
|
@@ -1,19 +1,15 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
describe 'defining actions from registration blocks', type: :controller do
|
3
|
+
RSpec.describe 'defining actions from registration blocks', type: :controller do
|
4
4
|
let(:klass){ Admin::PostsController }
|
5
|
-
render_views # https://github.com/rspec/rspec-rails/issues/860
|
6
5
|
|
7
6
|
before do
|
7
|
+
load_resources { action! }
|
8
|
+
|
8
9
|
@controller = klass.new
|
9
10
|
end
|
10
11
|
|
11
12
|
describe 'creates a member action' do
|
12
|
-
before do
|
13
|
-
action!
|
14
|
-
reload_routes!
|
15
|
-
end
|
16
|
-
|
17
13
|
after(:each) do
|
18
14
|
klass.clear_member_actions!
|
19
15
|
end
|
@@ -72,11 +68,6 @@ describe 'defining actions from registration blocks', type: :controller do
|
|
72
68
|
end
|
73
69
|
|
74
70
|
describe 'creates a collection action' do
|
75
|
-
before do
|
76
|
-
action!
|
77
|
-
reload_routes!
|
78
|
-
end
|
79
|
-
|
80
71
|
after(:each) do
|
81
72
|
klass.clear_collection_actions!
|
82
73
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
require 'fileutils'
|
3
3
|
|
4
|
-
describe ActiveAdmin::Application do
|
4
|
+
RSpec.describe ActiveAdmin::Application do
|
5
5
|
|
6
6
|
let(:application) do
|
7
7
|
ActiveAdmin::Application.new.tap do |app|
|
@@ -91,6 +91,10 @@ describe ActiveAdmin::Application do
|
|
91
91
|
expect(application.comments).to eq true
|
92
92
|
end
|
93
93
|
|
94
|
+
it "should have default order clause class" do
|
95
|
+
expect(application.order_clause).to eq ActiveAdmin::OrderClause
|
96
|
+
end
|
97
|
+
|
94
98
|
describe "authentication settings" do
|
95
99
|
|
96
100
|
it "should have no default current_user_method" do
|
@@ -1,39 +1,43 @@
|
|
1
1
|
require 'rails_helper'
|
2
|
-
Auth = ActiveAdmin::Authorization
|
3
2
|
|
4
|
-
describe
|
3
|
+
RSpec.describe "Controller Authorization", type: :controller do
|
5
4
|
|
6
5
|
let(:authorization){ controller.send(:active_admin_authorization) }
|
7
6
|
|
8
7
|
before do
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
load_resources { ActiveAdmin.register Post }
|
9
|
+
@controller = Admin::PostsController.new
|
10
|
+
allow(authorization).to receive(:authorized?)
|
12
11
|
end
|
13
12
|
|
14
13
|
it "should authorize the index action" do
|
15
|
-
expect(authorization).to receive(:authorized?).with(
|
14
|
+
expect(authorization).to receive(:authorized?).with(auth::READ, Post).and_return true
|
16
15
|
get :index
|
17
16
|
expect(response).to be_success
|
18
17
|
end
|
19
18
|
|
20
19
|
it "should authorize the new action" do
|
21
|
-
expect(authorization).to receive(:authorized?).with(
|
20
|
+
expect(authorization).to receive(:authorized?).with(auth::CREATE, an_instance_of(Post)).and_return true
|
22
21
|
get :new
|
23
22
|
expect(response).to be_success
|
24
23
|
end
|
25
24
|
|
26
25
|
it "should authorize the create action with the new resource" do
|
27
|
-
expect(authorization).to receive(:authorized?).with(
|
26
|
+
expect(authorization).to receive(:authorized?).with(auth::CREATE, an_instance_of(Post)).and_return true
|
28
27
|
post :create
|
29
28
|
expect(response).to redirect_to action: 'show', id: Post.last.id
|
30
29
|
end
|
31
30
|
|
32
31
|
it "should redirect when the user isn't authorized" do
|
33
|
-
expect(authorization).to receive(:authorized?).with(
|
32
|
+
expect(authorization).to receive(:authorized?).with(auth::READ, Post).and_return false
|
34
33
|
get :index
|
35
34
|
expect(response.body).to eq '<html><body>You are being <a href="http://test.host/admin">redirected</a>.</body></html>'
|
36
35
|
expect(response).to redirect_to '/admin'
|
37
36
|
end
|
38
37
|
|
38
|
+
private
|
39
|
+
|
40
|
+
def auth
|
41
|
+
ActiveAdmin::Authorization
|
42
|
+
end
|
39
43
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
RSpec.describe 'Index overriding', type: :controller do
|
4
4
|
before do
|
5
|
-
|
5
|
+
load_resources { ActiveAdmin.register Post }
|
6
|
+
@controller = Admin::PostsController.new
|
7
|
+
|
8
|
+
@controller.instance_eval do
|
6
9
|
def index
|
7
10
|
super do
|
8
|
-
render Dependency.rails.render_key => 'Rendered from passed block'
|
11
|
+
render ActiveAdmin::Dependency.rails.render_key => 'Rendered from passed block'
|
9
12
|
return
|
10
13
|
end
|
11
14
|
end
|
12
15
|
end
|
13
|
-
load_defaults!
|
14
|
-
# HACK: the AA config is missing, so we throw it in here
|
15
|
-
controller.class.active_admin_config = ActiveAdmin.application.namespace(:admin).resources['Post'].controller.active_admin_config
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should call block passed to overridden index' do
|
data/spec/unit/auto_link_spec.rb
CHANGED
@@ -1,24 +1,27 @@
|
|
1
1
|
require 'rails_helper'
|
2
|
+
require 'active_admin/view_helpers/active_admin_application_helper'
|
3
|
+
require 'active_admin/view_helpers/auto_link_helper'
|
4
|
+
require 'active_admin/view_helpers/display_helper'
|
5
|
+
require 'active_admin/view_helpers/method_or_proc_helper'
|
2
6
|
|
3
|
-
describe "auto linking resources" do
|
7
|
+
RSpec.describe "auto linking resources", type: :view do
|
4
8
|
include ActiveAdmin::ViewHelpers::ActiveAdminApplicationHelper
|
5
9
|
include ActiveAdmin::ViewHelpers::AutoLinkHelper
|
6
10
|
include ActiveAdmin::ViewHelpers::DisplayHelper
|
7
11
|
include MethodOrProcHelper
|
8
12
|
|
9
|
-
let(:
|
10
|
-
let(:active_admin_namespace){ ActiveAdmin::Namespace.new(ActiveAdmin::Application.new, :admin) }
|
13
|
+
let(:active_admin_namespace){ ActiveAdmin.application.namespace(:admin) }
|
11
14
|
let(:post){ Post.create! title: "Hello World" }
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def authorized?(*)
|
18
|
-
true
|
16
|
+
before do
|
17
|
+
allow(self).to receive(:authorized?).and_return(true)
|
19
18
|
end
|
20
19
|
|
21
20
|
context "when the resource is not registered" do
|
21
|
+
before do
|
22
|
+
load_resources {}
|
23
|
+
end
|
24
|
+
|
22
25
|
it "should return the display name of the object" do
|
23
26
|
expect(auto_link(post)).to eq "Hello World"
|
24
27
|
end
|
@@ -26,36 +29,57 @@ describe "auto linking resources" do
|
|
26
29
|
|
27
30
|
context "when the resource is registered" do
|
28
31
|
before do
|
29
|
-
|
32
|
+
load_resources do
|
33
|
+
active_admin_namespace.register Post
|
34
|
+
end
|
30
35
|
end
|
36
|
+
|
31
37
|
it "should return a link with the display name of the object" do
|
32
|
-
expect(
|
33
|
-
|
34
|
-
|
38
|
+
expect(auto_link(post)).to \
|
39
|
+
match(%r{<a href="/admin/posts/\d+">Hello World</a>})
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should keep locale in the url if present" do
|
43
|
+
expect(self).to receive(:url_options).and_return(locale: 'en')
|
44
|
+
|
45
|
+
expect(auto_link(post)).to \
|
46
|
+
match(%r{<a href="/admin/posts/\d+\?locale=en">Hello World</a>})
|
35
47
|
end
|
36
48
|
|
37
49
|
context "but the user doesn't have access" do
|
50
|
+
before do
|
51
|
+
allow(self).to receive(:authorized?).and_return(false)
|
52
|
+
end
|
53
|
+
|
38
54
|
it "should return the display name of the object" do
|
39
|
-
expect(self).to receive(:authorized?).twice.and_return(false)
|
40
55
|
expect(auto_link(post)).to eq "Hello World"
|
41
56
|
end
|
42
57
|
end
|
58
|
+
end
|
43
59
|
|
44
|
-
|
45
|
-
|
60
|
+
context "when the resource is registered with the show action disabled" do
|
61
|
+
before do
|
62
|
+
load_resources do
|
46
63
|
active_admin_namespace.register(Post) { actions :all, except: :show }
|
47
64
|
end
|
65
|
+
end
|
48
66
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
expect(self).to receive(:link_to).with "Hello World", url_path
|
53
|
-
auto_link(post)
|
54
|
-
end
|
67
|
+
it "should fallback to edit" do
|
68
|
+
expect(auto_link(post)).to \
|
69
|
+
match(%r{<a href="/admin/posts/\d+/edit">Hello World</a>})
|
55
70
|
end
|
56
71
|
|
57
|
-
|
58
|
-
|
72
|
+
it "should keep locale in the url if present" do
|
73
|
+
expect(self).to receive(:url_options).and_return(locale: 'en')
|
74
|
+
|
75
|
+
expect(auto_link(post)).to \
|
76
|
+
match(%r{<a href="/admin/posts/\d+/edit\?locale=en">Hello World</a>})
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "when the resource is registered with the show & edit actions disabled" do
|
81
|
+
before do
|
82
|
+
load_resources do
|
59
83
|
active_admin_namespace.register(Post) do
|
60
84
|
actions :all, except: [:show, :edit]
|
61
85
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
describe ActiveAdmin::BatchActions::ResourceExtension do
|
3
|
+
RSpec.describe ActiveAdmin::BatchActions::ResourceExtension do
|
4
4
|
|
5
5
|
let(:resource) do
|
6
6
|
namespace = ActiveAdmin::Namespace.new(ActiveAdmin::Application.new, :admin)
|
@@ -52,19 +52,6 @@ describe ActiveAdmin::BatchActions::ResourceExtension do
|
|
52
52
|
|
53
53
|
end
|
54
54
|
|
55
|
-
describe "#batch_action_path" do
|
56
|
-
|
57
|
-
it "returns the path as a symbol" do
|
58
|
-
expect(resource.batch_action_path).to eq "/admin/posts/batch_action"
|
59
|
-
end
|
60
|
-
|
61
|
-
it "includes :scope and :q params" do
|
62
|
-
params = { q: { name_equals: "Any" }, scope: :all }
|
63
|
-
batch_action_path = "/admin/posts/batch_action?q%5Bname_equals%5D=Any&scope=all"
|
64
|
-
expect(resource.batch_action_path(params)).to eq(batch_action_path)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
55
|
describe "#display_if_block" do
|
69
56
|
|
70
57
|
it "should return true by default" do
|
@@ -1,11 +1,19 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
describe ActiveAdmin::Resource::BelongsTo do
|
3
|
+
RSpec.describe ActiveAdmin::Resource::BelongsTo do
|
4
|
+
before do
|
5
|
+
load_resources do
|
6
|
+
ActiveAdmin.register User
|
7
|
+
ActiveAdmin.register Post do belongs_to :user end
|
8
|
+
end
|
9
|
+
end
|
4
10
|
|
11
|
+
let(:namespace) { ActiveAdmin.application.namespace(:admin) }
|
5
12
|
let(:user_config){ ActiveAdmin.register User }
|
6
13
|
let(:post_config){ ActiveAdmin.register Post do belongs_to :user end }
|
7
14
|
let(:belongs_to){ post_config.belongs_to_config }
|
8
15
|
|
16
|
+
|
9
17
|
it "should have an owner" do
|
10
18
|
expect(belongs_to.owner).to eq post_config
|
11
19
|
end
|
data/spec/unit/comments_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
describe "Comments" do
|
3
|
+
RSpec.describe "Comments" do
|
4
4
|
let(:application) { ActiveAdmin::Application.new }
|
5
5
|
|
6
6
|
describe ActiveAdmin::Comment do
|
@@ -39,7 +39,7 @@ describe "Comments" do
|
|
39
39
|
expect(ActiveAdmin::Comment.find_for_resource_in_namespace(another_post, namespace_name)).to eq []
|
40
40
|
end
|
41
41
|
|
42
|
-
it "should return the most recent comment first" do
|
42
|
+
it "should return the most recent comment first by default" do
|
43
43
|
ActiveAdmin::Comment.class_eval { attr_accessible :created_at } if Rails::VERSION::MAJOR == 3
|
44
44
|
another_comment = ActiveAdmin::Comment.create! resource: post,
|
45
45
|
body: "Another Comment",
|
@@ -58,24 +58,31 @@ describe "Comments" do
|
|
58
58
|
expect(comments.last).to eq(another_comment)
|
59
59
|
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
61
|
+
context "when custom ordering configured" do
|
62
|
+
around do |example|
|
63
|
+
previous_order = ActiveAdmin.application.comments_order
|
64
|
+
ActiveAdmin.application.comments_order = "created_at DESC"
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
66
|
+
example.call
|
67
|
+
|
68
|
+
ActiveAdmin.application.comments_order = previous_order
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should return the correctly ordered comments" do
|
72
|
+
another_comment = ActiveAdmin::Comment.create!(
|
73
|
+
resource: post,
|
74
|
+
body: "Another Comment",
|
75
|
+
namespace: namespace_name,
|
76
|
+
created_at: @comment.created_at + 20.minutes
|
77
|
+
)
|
78
|
+
|
79
|
+
comments = ActiveAdmin::Comment.find_for_resource_in_namespace(
|
80
|
+
post, namespace_name
|
81
|
+
)
|
82
|
+
expect(comments.size).to eq 2
|
83
|
+
expect(comments.first).to eq(another_comment)
|
84
|
+
expect(comments.last).to eq(@comment)
|
85
|
+
end
|
79
86
|
end
|
80
87
|
end
|
81
88
|
|