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
@@ -1,23 +1,30 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
describe "AA installation" do
|
3
|
+
RSpec.describe "AA installation" do
|
4
4
|
context "should create" do
|
5
5
|
|
6
6
|
it "active_admin.scss" do
|
7
7
|
path = Rails.root + "app/assets/stylesheets/active_admin.scss"
|
8
|
-
|
8
|
+
|
9
|
+
expect(File.exist?(path)).to eq true
|
9
10
|
end
|
10
11
|
|
11
12
|
it "active_admin.js.coffee" do
|
12
|
-
|
13
|
+
path = Rails.root + "app/assets/javascripts/active_admin.js.coffee"
|
14
|
+
|
15
|
+
expect(File.exist?(path)).to eq true
|
13
16
|
end
|
14
17
|
|
15
18
|
it "the dashboard" do
|
16
|
-
|
19
|
+
path = Rails.root + "app/admin/dashboard.rb"
|
20
|
+
|
21
|
+
expect(File.exist?(path)).to eq true
|
17
22
|
end
|
18
23
|
|
19
24
|
it "the initializer" do
|
20
|
-
|
25
|
+
path = Rails.root + "config/initializers/active_admin.rb"
|
26
|
+
|
27
|
+
expect(File.exist?(path)).to eq true
|
21
28
|
end
|
22
29
|
|
23
30
|
end
|
@@ -1,20 +1,15 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
describe ActiveAdmin::Helpers::Collection do
|
3
|
+
RSpec.describe ActiveAdmin::Helpers::Collection do
|
4
4
|
|
5
5
|
include ActiveAdmin::Helpers::Collection
|
6
6
|
|
7
|
-
before
|
8
|
-
Post.delete_all
|
7
|
+
before do
|
9
8
|
Post.create!(title: "A post")
|
10
9
|
Post.create!(title: "A post")
|
11
10
|
Post.create!(title: "An other post")
|
12
11
|
end
|
13
12
|
|
14
|
-
after(:all) do
|
15
|
-
Post.delete_all
|
16
|
-
end
|
17
|
-
|
18
13
|
describe "#collection_size" do
|
19
14
|
it "should return the collection size for an ActiveRecord class" do
|
20
15
|
expect(collection_size(Post.where(nil))).to eq 3
|
@@ -32,6 +27,10 @@ describe ActiveAdmin::Helpers::Collection do
|
|
32
27
|
expect(collection_size(Post.select("title, count(*) as nb_posts").group(:title).order("nb_posts"))).to eq 2
|
33
28
|
end
|
34
29
|
|
30
|
+
it "should return the collection size for an Array" do
|
31
|
+
expect(collection_size(Post.where(title: "A post").to_a)).to eq 2
|
32
|
+
end
|
33
|
+
|
35
34
|
it "should take the defined collection by default" do
|
36
35
|
def collection; Post.where(nil); end
|
37
36
|
|
@@ -40,6 +39,10 @@ describe ActiveAdmin::Helpers::Collection do
|
|
40
39
|
def collection; Post.where(title: "An other post"); end
|
41
40
|
|
42
41
|
expect(collection_size).to eq 1
|
42
|
+
|
43
|
+
def collection; Post.where(title: "A post").to_a end
|
44
|
+
|
45
|
+
expect(collection_size).to eq 2
|
43
46
|
end
|
44
47
|
end
|
45
48
|
|
data/spec/unit/i18n_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
Dir.glob('config/locales/*.yml') do |locale_file|
|
4
|
-
describe locale_file do
|
4
|
+
RSpec.describe locale_file do
|
5
5
|
it { is_expected.to be_parseable }
|
6
6
|
it { is_expected.to have_one_top_level_namespace }
|
7
7
|
it { is_expected.to be_named_like_top_level_namespace }
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.shared_examples_for "ActiveAdmin::Localizers::ResourceLocalizer" do
|
4
|
+
it "should use proper translation" do
|
5
|
+
string = ActiveAdmin::Localizers::ResourceLocalizer.t(action, model: model, model_name: model_name)
|
6
|
+
expect(string).to eq translation
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should accessible via ActiveAdmin::Localizers" do
|
10
|
+
resource = double(resource_label: model, resource_name: double(i18n_key: model_name))
|
11
|
+
localizer = ActiveAdmin::Localizers.resource(resource)
|
12
|
+
expect(localizer.t(action)).to eq translation
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec.describe ActiveAdmin::Localizers::ResourceLocalizer do
|
17
|
+
let(:action) { 'new_model' }
|
18
|
+
let(:model) { 'Comment' }
|
19
|
+
let(:model_name) { 'comment' }
|
20
|
+
|
21
|
+
it_behaves_like "ActiveAdmin::Localizers::ResourceLocalizer" do
|
22
|
+
let(:translation) { 'New Comment' }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "model action specified" do
|
26
|
+
around do |example|
|
27
|
+
with_translation active_admin: {resources: {comment: {new_model: 'Write comment'}}} do
|
28
|
+
example.call
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
it_behaves_like "ActiveAdmin::Localizers::ResourceLocalizer" do
|
33
|
+
let(:translation) { 'Write comment' }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/unit/menu_item_spec.rb
CHANGED
data/spec/unit/menu_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
describe ActiveAdmin::Namespace, "registering a page" do
|
3
|
+
RSpec.describe ActiveAdmin::Namespace, "registering a page" do
|
4
4
|
let(:application){ ActiveAdmin::Application.new }
|
5
5
|
let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
|
6
6
|
let(:menu){ namespace.fetch_menu(:default) }
|
@@ -68,6 +68,32 @@ describe ActiveAdmin::Namespace, "registering a page" do
|
|
68
68
|
it "should not create a menu item" do
|
69
69
|
expect(menu["Status"]).to eq nil
|
70
70
|
end
|
71
|
+
end # describe "disabling the menu"
|
72
|
+
end # describe "adding to the menu"
|
73
|
+
|
74
|
+
describe "adding as a belongs to" do
|
75
|
+
context "when not optional" do
|
76
|
+
before do
|
77
|
+
namespace.register_page "Reports" do
|
78
|
+
belongs_to :author
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should be excluded from the menu" do
|
83
|
+
expect(menu["Reports"]).to be_nil
|
84
|
+
end
|
71
85
|
end
|
72
|
-
|
86
|
+
|
87
|
+
context "when optional" do
|
88
|
+
before do
|
89
|
+
namespace.register_page "Reports" do
|
90
|
+
belongs_to :author, :optional => true
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should be in the menu" do
|
95
|
+
expect(menu["Reports"]).to_not be_nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end # describe "adding as a belongs to"
|
73
99
|
end
|
@@ -3,11 +3,13 @@ require 'rails_helper'
|
|
3
3
|
# TODO: refactor this file so it doesn't depend on the Admin namespace in such a broken way.
|
4
4
|
# Specifically, the dashboard is already defined.
|
5
5
|
|
6
|
-
describe ActiveAdmin::Namespace, "registering a resource" do
|
6
|
+
RSpec.describe ActiveAdmin::Namespace, "registering a resource" do
|
7
7
|
let(:application){ ActiveAdmin::Application.new }
|
8
8
|
let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
|
9
9
|
let(:menu){ namespace.fetch_menu(:default) }
|
10
10
|
|
11
|
+
after { namespace.unload! }
|
12
|
+
|
11
13
|
context "with no configuration" do
|
12
14
|
before do
|
13
15
|
namespace.register Category
|
data/spec/unit/namespace_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
describe ActiveAdmin::Namespace do
|
3
|
+
RSpec.describe ActiveAdmin::Namespace do
|
4
4
|
|
5
5
|
let(:application){ ActiveAdmin::Application.new }
|
6
6
|
|
@@ -24,6 +24,28 @@ describe ActiveAdmin::Namespace do
|
|
24
24
|
end
|
25
25
|
end # context "when new"
|
26
26
|
|
27
|
+
describe "#unload!" do
|
28
|
+
context "when controller is only defined without a namespace" do
|
29
|
+
before do
|
30
|
+
# To ensure Admin::PostsController is defined
|
31
|
+
ActiveAdmin.register Post
|
32
|
+
|
33
|
+
# To ensure ::PostsController is defined
|
34
|
+
ActiveAdmin.register Post, namespace: false
|
35
|
+
|
36
|
+
# To prevent unload! from unregistering ::PostsController
|
37
|
+
ActiveAdmin.application.namespaces.instance_variable_get(:@namespaces).delete(:root)
|
38
|
+
|
39
|
+
# To force Admin::PostsController to not be there
|
40
|
+
Admin.send(:remove_const, 'PostsController')
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should not crash" do
|
44
|
+
expect { ActiveAdmin.unload! }.not_to raise_error
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
27
49
|
describe "settings" do
|
28
50
|
let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
|
29
51
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
describe ActiveAdmin::OrderClause do
|
4
|
-
subject { described_class.new clause }
|
3
|
+
RSpec.describe ActiveAdmin::OrderClause do
|
4
|
+
subject { described_class.new(config, clause) }
|
5
5
|
|
6
6
|
let(:application) { ActiveAdmin::Application.new }
|
7
|
-
let(:namespace)
|
8
|
-
let(:config)
|
7
|
+
let(:namespace) { ActiveAdmin::Namespace.new application, :admin }
|
8
|
+
let(:config) { ActiveAdmin::Resource.new namespace, Post }
|
9
9
|
|
10
10
|
describe 'id_asc (existing column)' do
|
11
11
|
let(:clause) { 'id_asc' }
|
@@ -23,7 +23,7 @@ describe ActiveAdmin::OrderClause do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
specify '#to_sql prepends table name' do
|
26
|
-
expect(subject.to_sql
|
26
|
+
expect(subject.to_sql).to eq '"posts"."id" asc'
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -43,7 +43,7 @@ describe ActiveAdmin::OrderClause do
|
|
43
43
|
end
|
44
44
|
|
45
45
|
specify '#to_sql' do
|
46
|
-
expect(subject.to_sql
|
46
|
+
expect(subject.to_sql).to eq '"virtual_column" asc'
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -63,7 +63,7 @@ describe ActiveAdmin::OrderClause do
|
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'converts to sql' do
|
66
|
-
expect(subject.to_sql
|
66
|
+
expect(subject.to_sql).to eq %Q("hstore_col"->'field' desc)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
data/spec/unit/page_spec.rb
CHANGED
@@ -4,13 +4,14 @@ require 'rails_helper'
|
|
4
4
|
require File.expand_path('config_shared_examples', File.dirname(__FILE__))
|
5
5
|
|
6
6
|
module ActiveAdmin
|
7
|
-
describe Page do
|
7
|
+
RSpec.describe Page do
|
8
8
|
|
9
9
|
it_should_behave_like "ActiveAdmin::Resource"
|
10
10
|
before { load_defaults! }
|
11
11
|
|
12
12
|
let(:application){ ActiveAdmin::Application.new }
|
13
13
|
let(:namespace){ Namespace.new(application, :admin) }
|
14
|
+
let(:page_name) { "Chocolate I lØve You!" }
|
14
15
|
|
15
16
|
def config(options = {})
|
16
17
|
@config ||= namespace.register_page("Chocolate I lØve You!", options)
|
@@ -34,7 +35,11 @@ module ActiveAdmin
|
|
34
35
|
end
|
35
36
|
|
36
37
|
it "returns the singular, lowercase name" do
|
37
|
-
|
38
|
+
if RUBY_VERSION >= '2.4.0'
|
39
|
+
expect(config.resource_name.singular).to eq "chocolate i løve you!"
|
40
|
+
else
|
41
|
+
expect(config.resource_name.singular).to eq "chocolate i lØve you!"
|
42
|
+
end
|
38
43
|
end
|
39
44
|
end
|
40
45
|
|
@@ -66,6 +71,7 @@ module ActiveAdmin
|
|
66
71
|
expect(config.belongs_to?).to eq false
|
67
72
|
end
|
68
73
|
|
74
|
+
|
69
75
|
it "should not have any action_items" do
|
70
76
|
expect(config.action_items?).to eq false
|
71
77
|
end
|
@@ -74,5 +80,52 @@ module ActiveAdmin
|
|
74
80
|
expect(config.sidebar_sections?).to eq false
|
75
81
|
end
|
76
82
|
|
83
|
+
context "with belongs to config" do
|
84
|
+
let!(:post_config) { namespace.register Post }
|
85
|
+
let!(:page_config) {
|
86
|
+
namespace.register_page page_name do
|
87
|
+
belongs_to :post
|
88
|
+
end
|
89
|
+
}
|
90
|
+
|
91
|
+
it "configures page with belongs_to" do
|
92
|
+
expect(page_config.belongs_to?).to be true
|
93
|
+
end
|
94
|
+
|
95
|
+
it "sets navigation menu to parent" do
|
96
|
+
expect(page_config.navigation_menu_name).to eq :post
|
97
|
+
end
|
98
|
+
|
99
|
+
it "builds a belongs_to relationship" do
|
100
|
+
belongs_to = page_config.belongs_to_config
|
101
|
+
|
102
|
+
expect(belongs_to.target).to eq(post_config)
|
103
|
+
expect(belongs_to.owner).to eq(page_config)
|
104
|
+
expect(belongs_to.optional?).to be_falsy
|
105
|
+
end
|
106
|
+
|
107
|
+
it "forwards belongs_to call to controller" do
|
108
|
+
options = { optional: true }
|
109
|
+
expect(page_config.controller).to receive(:belongs_to).with(:post, options)
|
110
|
+
page_config.belongs_to :post, options
|
111
|
+
end
|
112
|
+
end # context "with belongs to config" do
|
113
|
+
|
114
|
+
context "with optional belongs to config" do
|
115
|
+
let!(:post_config) { namespace.register Post }
|
116
|
+
let!(:page_config) {
|
117
|
+
namespace.register_page page_name do
|
118
|
+
belongs_to :post, optional: true
|
119
|
+
end
|
120
|
+
}
|
121
|
+
|
122
|
+
it "does not override default navigation menu" do
|
123
|
+
expect(page_config.navigation_menu_name).to eq(:default)
|
124
|
+
end
|
125
|
+
end # context "with optional belongs to config" do
|
126
|
+
|
127
|
+
it "has no belongs_to by default" do
|
128
|
+
expect(config.belongs_to?).to be_falsy
|
129
|
+
end
|
77
130
|
end
|
78
131
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rails_helper'
|
2
|
+
require 'active_admin/view_helpers/display_helper'
|
2
3
|
|
3
|
-
describe "#pretty_format" do
|
4
|
+
RSpec.describe "#pretty_format" do
|
4
5
|
include ActiveAdmin::ViewHelpers::DisplayHelper
|
5
6
|
|
6
7
|
def method_missing(*args, &block)
|
@@ -30,11 +31,11 @@ describe "#pretty_format" do
|
|
30
31
|
end
|
31
32
|
|
32
33
|
context "apply custom localize format" do
|
33
|
-
|
34
|
+
around do |example|
|
35
|
+
previous_localize_format = ActiveAdmin.application.localize_format
|
34
36
|
ActiveAdmin.application.localize_format = :short
|
35
|
-
|
36
|
-
|
37
|
-
ActiveAdmin.application = nil
|
37
|
+
example.call
|
38
|
+
ActiveAdmin.application.localize_format = previous_localize_format
|
38
39
|
end
|
39
40
|
it "should actually do the formatting" do
|
40
41
|
t = Time.utc(1985, "feb", 28, 20, 15, 1)
|
@@ -44,11 +45,11 @@ describe "#pretty_format" do
|
|
44
45
|
end
|
45
46
|
|
46
47
|
context "with non-English locale" do
|
47
|
-
before
|
48
|
+
before do
|
48
49
|
@previous_locale = I18n.locale.to_s
|
49
50
|
I18n.locale = "es"
|
50
51
|
end
|
51
|
-
after
|
52
|
+
after do
|
52
53
|
I18n.locale = @previous_locale
|
53
54
|
end
|
54
55
|
it "should return a localized Date or Time with long format for non-english locale" do
|