andrewroth_activeadmin 0.3.4 → 0.3.4.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/CHANGELOG.md +159 -3
- data/CONTRIBUTING.md +113 -0
- data/LICENSE +1 -1
- data/README.rdoc +19 -20
- data/activeadmin.gemspec +3 -1
- data/app/assets/javascripts/active_admin/application.js +9 -0
- data/app/assets/javascripts/active_admin/base.js +4 -12
- data/app/assets/stylesheets/active_admin/_base.css.scss +16 -340
- data/app/assets/stylesheets/active_admin/_forms.css.scss +13 -7
- data/app/assets/stylesheets/active_admin/_header.css.scss +23 -4
- data/app/assets/stylesheets/active_admin/components/_blank_slates.scss +31 -0
- data/app/assets/stylesheets/active_admin/components/_breadcrumbs.scss +20 -0
- data/app/assets/stylesheets/active_admin/components/_buttons.scss +12 -0
- data/app/assets/stylesheets/active_admin/components/_flash_messages.css.scss +2 -0
- data/app/assets/stylesheets/active_admin/components/_grid.scss +9 -0
- data/app/assets/stylesheets/active_admin/components/_links.scss +5 -0
- data/app/assets/stylesheets/active_admin/components/_pagination.scss +34 -0
- data/app/assets/stylesheets/active_admin/components/_panels.scss +6 -0
- data/app/assets/stylesheets/active_admin/components/_scopes.scss +10 -0
- data/app/assets/stylesheets/active_admin/components/_status_tags.scss +12 -0
- data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +101 -0
- data/app/assets/stylesheets/active_admin/mixins/_all.css.scss +2 -1
- data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +50 -13
- data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +9 -1
- data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +7 -5
- data/app/assets/stylesheets/active_admin/mixins/_shadows.css.scss +1 -0
- data/app/assets/stylesheets/active_admin/mixins/_typography.scss +3 -0
- data/app/assets/stylesheets/active_admin/mixins/_variables.css.scss +1 -0
- data/app/assets/stylesheets/active_admin/pages/_dashboard.scss +5 -0
- data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +44 -0
- data/app/assets/stylesheets/active_admin/structure/_footer.scss +14 -0
- data/app/assets/stylesheets/active_admin/structure/_main_structure.scss +26 -0
- data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +44 -0
- data/app/views/active_admin/devise/passwords/edit.html.erb +1 -1
- data/app/views/active_admin/devise/passwords/new.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 +1 -1
- data/app/views/active_admin/devise/unlocks/new.html.erb +1 -1
- data/app/views/active_admin/page/index.html.arb +1 -0
- data/app/views/layouts/active_admin_logged_out.html.erb +2 -2
- data/cucumber.yml +3 -2
- data/docs/1-general-configuration.md +46 -10
- data/docs/6-show-screens.md +7 -0
- data/docs/8-custom-actions.md +12 -2
- data/docs/9-custom-pages.md +84 -0
- data/features/belongs_to.feature +27 -0
- data/features/comments/commenting.feature +3 -2
- data/features/dashboard.feature +18 -0
- data/features/development_reloading.feature +19 -0
- data/features/index/filter_with_check_boxes.feature +25 -0
- data/features/index/index_as_table.feature +14 -0
- data/features/index/index_scopes.feature +42 -0
- data/features/index/pagination.feature +19 -1
- data/features/menu.feature +22 -2
- data/features/registering_assets.feature +2 -2
- data/features/registering_pages.feature +66 -0
- data/features/specifying_actions.feature +5 -0
- data/features/step_definitions/action_item_steps.rb +2 -6
- data/features/step_definitions/action_link_steps.rb +7 -0
- data/features/step_definitions/additional_web_steps.rb +8 -0
- data/features/step_definitions/asset_steps.rb +5 -1
- data/features/step_definitions/breadcrumb_steps.rb +5 -0
- data/features/step_definitions/configuration_steps.rb +56 -8
- data/features/step_definitions/dashboard_steps.rb +5 -1
- data/features/step_definitions/factory_steps.rb +9 -2
- data/features/step_definitions/flash_steps.rb +9 -1
- data/features/step_definitions/index_scope_steps.rb +16 -4
- data/features/step_definitions/member_link_steps.rb +7 -0
- data/features/step_definitions/site_title_steps.rb +15 -0
- data/features/support/paths.rb +6 -0
- data/features/users/logging_out.feature +11 -0
- data/lib/active_admin.rb +25 -10
- data/lib/active_admin/application.rb +63 -20
- data/lib/active_admin/arbre/html/element.rb +10 -0
- data/lib/active_admin/asset_registration.rb +15 -2
- data/lib/active_admin/base_controller.rb +61 -0
- data/lib/active_admin/{resource_controller → base_controller}/menu.rb +1 -1
- data/lib/active_admin/comments.rb +48 -54
- data/lib/active_admin/comments/comment.rb +13 -2
- data/lib/active_admin/comments/namespace_helper.rb +1 -1
- data/lib/active_admin/comments/views/active_admin_comments.rb +7 -3
- data/lib/active_admin/dashboards.rb +4 -0
- data/lib/active_admin/dashboards/dashboard_controller.rb +20 -4
- data/lib/active_admin/dsl.rb +6 -159
- data/lib/active_admin/event.rb +5 -3
- data/lib/active_admin/filter_form_builder.rb +53 -0
- data/lib/active_admin/form_builder.rb +25 -19
- data/lib/active_admin/inputs.rb +14 -0
- data/lib/active_admin/inputs/datepicker_input.rb +11 -0
- data/lib/active_admin/inputs/filter_base.rb +46 -0
- data/lib/active_admin/inputs/filter_check_boxes_input.rb +40 -0
- data/lib/active_admin/inputs/filter_date_range_input.rb +34 -0
- data/lib/active_admin/inputs/filter_numeric_input.rb +55 -0
- data/lib/active_admin/inputs/filter_select_input.rb +23 -0
- data/lib/active_admin/inputs/filter_string_input.rb +22 -0
- data/lib/active_admin/locales/ca.yml +44 -0
- data/lib/active_admin/locales/cs.yml +14 -10
- data/lib/active_admin/locales/de.yml +43 -0
- data/lib/active_admin/locales/en.yml +5 -0
- data/lib/active_admin/locales/hr.yml +40 -0
- data/lib/active_admin/locales/ko.yml +40 -0
- data/lib/active_admin/locales/lv.yml +43 -0
- data/lib/active_admin/locales/nl.yml +40 -0
- data/lib/active_admin/locales/no-NB.yml +40 -0
- data/lib/active_admin/locales/pl.yml +7 -1
- data/lib/active_admin/locales/pt-BR.yml +6 -2
- data/lib/active_admin/namespace.rb +48 -33
- data/lib/active_admin/page.rb +54 -0
- data/lib/active_admin/page_controller.rb +15 -0
- data/lib/active_admin/page_dsl.rb +21 -0
- data/lib/active_admin/page_presenter.rb +30 -0
- data/lib/active_admin/resource.rb +38 -44
- data/lib/active_admin/resource/action_items.rb +5 -0
- data/lib/active_admin/resource/belongs_to.rb +4 -2
- data/lib/active_admin/resource/controllers.rb +35 -0
- data/lib/active_admin/resource/menu.rb +1 -2
- data/lib/active_admin/resource/naming.rb +43 -31
- data/lib/active_admin/resource/page_presenters.rb +28 -0
- data/lib/active_admin/resource/scopes.rb +16 -3
- data/lib/active_admin/resource/sidebars.rb +4 -0
- data/lib/active_admin/resource_collection.rb +88 -0
- data/lib/active_admin/resource_controller.rb +18 -54
- data/lib/active_admin/resource_controller/action_builder.rb +1 -1
- data/lib/active_admin/resource_controller/actions.rb +1 -1
- data/lib/active_admin/resource_controller/callbacks.rb +1 -1
- data/lib/active_admin/resource_controller/collection.rb +8 -4
- data/lib/active_admin/resource_controller/filters.rb +1 -1
- data/lib/active_admin/resource_controller/resource_class_methods.rb +24 -0
- data/lib/active_admin/resource_controller/scoping.rb +1 -1
- data/lib/active_admin/resource_controller/sidebars.rb +1 -1
- data/lib/active_admin/resource_dsl.rb +157 -0
- data/lib/active_admin/router.rb +21 -14
- data/lib/active_admin/scope.rb +15 -3
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_factory.rb +4 -3
- data/lib/active_admin/view_helpers/auto_link_helper.rb +1 -10
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +25 -21
- data/lib/active_admin/view_helpers/filter_form_helper.rb +0 -150
- data/lib/active_admin/views/components/attributes_table.rb +1 -1
- data/lib/active_admin/views/components/paginated_collection.rb +42 -13
- data/lib/active_admin/views/components/scopes.rb +17 -17
- data/lib/active_admin/views/components/status_tag.rb +6 -5
- data/lib/active_admin/views/components/table_for.rb +6 -2
- data/lib/active_admin/views/header_renderer.rb +31 -12
- data/lib/active_admin/views/index_as_block.rb +2 -2
- data/lib/active_admin/views/index_as_blog.rb +3 -3
- data/lib/active_admin/views/index_as_grid.rb +4 -4
- data/lib/active_admin/views/index_as_table.rb +13 -6
- data/lib/active_admin/views/pages/base.rb +4 -4
- data/lib/active_admin/views/pages/form.rb +49 -0
- data/lib/active_admin/views/pages/index.rb +18 -6
- data/lib/active_admin/views/pages/page.rb +24 -0
- data/lib/active_admin/views/pages/show.rb +1 -1
- data/lib/generators/active_admin/assets/assets_generator.rb +19 -1
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +38 -12
- data/lib/generators/active_admin/install/templates/dashboards.rb +6 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support/rails_template.rb +11 -0
- data/spec/support/templates/cucumber_with_reloading.rb +5 -0
- data/spec/unit/active_admin_spec.rb +8 -0
- data/spec/unit/application_spec.rb +48 -2
- data/spec/unit/arbre/html/element_finder_methods_spec.rb +58 -2
- data/spec/unit/asset_registration_spec.rb +9 -3
- data/spec/unit/auto_link_spec.rb +2 -2
- data/spec/unit/base_controller_shared_examples.rb +28 -0
- data/spec/unit/base_controller_spec.rb +8 -0
- data/spec/unit/belongs_to_spec.rb +30 -33
- data/spec/unit/comments_spec.rb +45 -15
- data/spec/unit/config_shared_examples.rb +108 -0
- data/spec/unit/dashboard_controller_spec.rb +44 -0
- data/spec/unit/event_spec.rb +6 -0
- data/spec/unit/filter_form_builder_spec.rb +9 -0
- data/spec/unit/form_builder_spec.rb +8 -14
- data/spec/unit/namespace/register_page_spec.rb +102 -0
- data/spec/unit/namespace/register_resource_spec.rb +188 -0
- data/spec/unit/namespace_spec.rb +11 -183
- data/spec/unit/page_controller_spec.rb +8 -0
- data/spec/unit/page_spec.rb +60 -0
- data/spec/unit/resource/menu_spec.rb +1 -51
- data/spec/unit/resource/naming_spec.rb +24 -19
- data/spec/unit/resource/page_presenters_spec.rb +32 -0
- data/spec/unit/resource/scopes_spec.rb +13 -0
- data/spec/unit/resource_collection_spec.rb +101 -0
- data/spec/unit/resource_controller_spec.rb +40 -32
- data/spec/unit/{registration_spec.rb → resource_registration_spec.rb} +0 -0
- data/spec/unit/resource_spec.rb +8 -24
- data/spec/unit/routing_spec.rb +50 -1
- data/spec/unit/scope_spec.rb +18 -4
- data/spec/unit/views/components/paginated_collection_spec.rb +150 -0
- data/spec/unit/views/components/status_tag_spec.rb +9 -0
- data/tasks/test.rake +43 -27
- metadata +140 -31
- data/app/assets/javascripts/active_admin/vendor.js +0 -382
- data/lib/active_admin/comments/configuration.rb +0 -18
- data/lib/active_admin/page_config.rb +0 -15
- data/lib/active_admin/resource_controller/form.rb +0 -42
- data/lib/active_admin/resource_controller/page_configurations.rb +0 -53
- data/lib/active_admin/views/pages/edit.rb +0 -28
- data/lib/active_admin/views/pages/new.rb +0 -28
- data/lib/generators/active_admin/assets/templates/3.0/active_admin.js +0 -427
- data/spec/integration/belongs_to_spec.rb +0 -42
@@ -1,45 +1,42 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
class Resource
|
5
|
-
describe BelongsTo do
|
3
|
+
describe ActiveAdmin::Resource::BelongsTo do
|
6
4
|
|
7
|
-
let(:application){ ActiveAdmin::Application.new }
|
8
|
-
let(:namespace){ Namespace.new(application, :admin) }
|
9
|
-
let(:post){ namespace.register(Post) }
|
10
|
-
let(:belongs_to){ BelongsTo.new(post, :user) }
|
11
5
|
|
12
|
-
|
13
|
-
|
14
|
-
|
6
|
+
let(:application){ ActiveAdmin::Application.new }
|
7
|
+
let(:namespace){ Namespace.new(application, :admin) }
|
8
|
+
let(:post){ namespace.register(Post) }
|
9
|
+
let(:belongs_to){ ActiveAdmin::Resource::BelongsTo.new(post, :user) }
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
it "should have an owner" do
|
12
|
+
belongs_to.owner.should == post
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have a namespace" do
|
16
|
+
belongs_to.namespace.should == namespace
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
context "when the resource has not been registered" do
|
31
|
-
it "should raise a ActiveAdmin::BelongsTo::TargetNotFound" do
|
32
|
-
lambda {
|
33
|
-
belongs_to.target
|
34
|
-
}.should raise_error(ActiveAdmin::Resource::BelongsTo::TargetNotFound)
|
35
|
-
end
|
36
|
-
end
|
19
|
+
describe "finding the target" do
|
20
|
+
context "when the resource has been registered" do
|
21
|
+
let(:user){ namespace.register(User) }
|
22
|
+
before { user } # Ensure user is registered
|
23
|
+
|
24
|
+
it "should return the target resource" do
|
25
|
+
belongs_to.target.should == user
|
37
26
|
end
|
27
|
+
end
|
38
28
|
|
39
|
-
|
40
|
-
|
41
|
-
|
29
|
+
context "when the resource has not been registered" do
|
30
|
+
it "should raise a ActiveAdmin::BelongsTo::TargetNotFound" do
|
31
|
+
lambda {
|
32
|
+
belongs_to.target
|
33
|
+
}.should raise_error(ActiveAdmin::Resource::BelongsTo::TargetNotFound)
|
42
34
|
end
|
43
35
|
end
|
44
36
|
end
|
37
|
+
|
38
|
+
it "should be optional" do
|
39
|
+
belongs_to = ActiveAdmin::Resource::BelongsTo.new post, :user, :optional => true
|
40
|
+
belongs_to.should be_optional
|
41
|
+
end
|
45
42
|
end
|
data/spec/unit/comments_spec.rb
CHANGED
@@ -3,38 +3,68 @@ require 'spec_helper'
|
|
3
3
|
describe "Comments" do
|
4
4
|
let(:application){ ActiveAdmin::Application.new }
|
5
5
|
|
6
|
-
describe "Configuration" do
|
7
|
-
it "should have an array of namespaces which allow comments" do
|
8
|
-
application.allow_comments_in.should be_an_instance_of(Array)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should allow comments in the default namespace by default" do
|
12
|
-
application.allow_comments_in.should include(application.default_namespace)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
6
|
describe ActiveAdmin::Comment do
|
17
7
|
describe "Associations and Validations" do
|
18
8
|
it { should belong_to :resource }
|
19
9
|
it { should belong_to :author }
|
20
10
|
|
21
|
-
it { should validate_presence_of :
|
22
|
-
it { should validate_presence_of :resource_type }
|
11
|
+
it { should validate_presence_of :resource }
|
23
12
|
it { should validate_presence_of :body }
|
24
13
|
it { should validate_presence_of :namespace }
|
25
14
|
end
|
15
|
+
|
16
|
+
describe ".find_for_resource_in_namespace" do
|
17
|
+
let(:post){ Post.create!(:title => "Hello World") }
|
18
|
+
let(:namespace_name){ "admin" }
|
19
|
+
|
20
|
+
before do
|
21
|
+
@comment = ActiveAdmin::Comment.create! :resource => post,
|
22
|
+
:body => "A Comment",
|
23
|
+
:namespace => namespace_name
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return a comment for the resource in the same namespace" do
|
27
|
+
ActiveAdmin::Comment.find_for_resource_in_namespace(post, namespace_name).should == [@comment]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should not return a comment for the same resource in a different namespace" do
|
31
|
+
ActiveAdmin::Comment.find_for_resource_in_namespace(post, 'public').should == []
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should not return a comment for a different resource" do
|
35
|
+
another_post = Post.create! :title => "Another Hello World"
|
36
|
+
ActiveAdmin::Comment.find_for_resource_in_namespace(another_post, namespace_name).should == []
|
37
|
+
end
|
38
|
+
end
|
26
39
|
end
|
27
40
|
|
28
41
|
describe ActiveAdmin::Comments::NamespaceHelper do
|
29
42
|
describe "#comments?" do
|
30
|
-
|
43
|
+
|
44
|
+
it "should have comments when the namespace allows comments" do
|
31
45
|
ns = ActiveAdmin::Namespace.new(application, :admin)
|
46
|
+
ns.allow_comments = true
|
32
47
|
ns.comments?.should be_true
|
33
48
|
end
|
34
|
-
|
35
|
-
|
49
|
+
|
50
|
+
it "should not have comments when the namespace does not allow comments" do
|
51
|
+
ns = ActiveAdmin::Namespace.new(application, :admin)
|
52
|
+
ns.allow_comments = false
|
36
53
|
ns.comments?.should be_false
|
37
54
|
end
|
55
|
+
|
56
|
+
it "should have comments when the application allows comments and no local namespace config" do
|
57
|
+
application.allow_comments = true
|
58
|
+
ns = ActiveAdmin::Namespace.new(application, :admin)
|
59
|
+
ns.comments?.should be_true
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should not have comments when the application does not allow commands and no local namespace config" do
|
63
|
+
application.allow_comments = false
|
64
|
+
ns = ActiveAdmin::Namespace.new(application, :admin)
|
65
|
+
ns.comments?.should be_false
|
66
|
+
end
|
67
|
+
|
38
68
|
end
|
39
69
|
end
|
40
70
|
|
@@ -0,0 +1,108 @@
|
|
1
|
+
shared_examples_for "ActiveAdmin::Config" do
|
2
|
+
describe "namespace" do
|
3
|
+
it "should return the namespace" do
|
4
|
+
config.namespace.should == namespace
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "page_presenters" do
|
9
|
+
it "should return an empty hash by default" do
|
10
|
+
config.page_presenters.should == {}
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it { respond_to :controller_name }
|
15
|
+
it { respond_to :controller }
|
16
|
+
it { respond_to :route_prefix }
|
17
|
+
it { respond_to :route_collection_path }
|
18
|
+
it { respond_to :comments? }
|
19
|
+
it { respond_to :belongs_to? }
|
20
|
+
it { respond_to :action_items? }
|
21
|
+
it { respond_to :sidebar_sections? }
|
22
|
+
|
23
|
+
describe "Naming" do
|
24
|
+
it "implements #resource_name" do
|
25
|
+
expect { config.resource_name }.should_not raise_error
|
26
|
+
end
|
27
|
+
|
28
|
+
it "implements #plural_resource_name" do
|
29
|
+
expect { config.plural_resource_name }.should_not raise_error
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#camelized_resource_name" do
|
33
|
+
it "returns a camelized version of the resource_name" do
|
34
|
+
config.should_receive(:resource_name).and_return "My resource"
|
35
|
+
config.camelized_resource_name.should == "MyResource"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#underscored_resource_name" do
|
40
|
+
it "returns the camelized_resource_name underscored" do
|
41
|
+
config.should_receive(:camelized_resource_name).and_return "MyResource"
|
42
|
+
config.underscored_resource_name.should == "my_resource"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#plural_underscored_resource_name" do
|
47
|
+
it "returns the plural_camelized_resource_name underscored" do
|
48
|
+
config.should_receive(:plural_camelized_resource_name).and_return "MyResources"
|
49
|
+
config.plural_underscored_resource_name.should == "my_resources"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "Menu" do
|
55
|
+
describe "menu item name" do
|
56
|
+
it "should be the plural resource name when not set" do
|
57
|
+
config.menu_item_name.should == config.plural_resource_name
|
58
|
+
end
|
59
|
+
it "should be settable" do
|
60
|
+
config.menu :label => "My Label"
|
61
|
+
config.menu_item_name.should == "My Label"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#include_in_menu?" do
|
66
|
+
it "should be included in menu by default" do
|
67
|
+
config.include_in_menu?.should == true
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should not be included in menu when menu set to false" do
|
71
|
+
config.menu false
|
72
|
+
config.include_in_menu?.should == false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "parent menu item name" do
|
77
|
+
it "should be nil when not set" do
|
78
|
+
config.parent_menu_item_name.should == nil
|
79
|
+
end
|
80
|
+
it "should return the name if set" do
|
81
|
+
config.tap do |c|
|
82
|
+
c.menu :parent => "Blog"
|
83
|
+
end.parent_menu_item_name.should == "Blog"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "menu item priority" do
|
88
|
+
it "should be 10 when not set" do
|
89
|
+
config.menu_item_priority.should == 10
|
90
|
+
end
|
91
|
+
it "should be settable" do
|
92
|
+
config.menu :priority => 2
|
93
|
+
config.menu_item_priority.should == 2
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "menu item display if" do
|
98
|
+
it "should be a proc always returning true if not set" do
|
99
|
+
config.menu_item_display_if.should be_instance_of(Proc)
|
100
|
+
config.menu_item_display_if.call.should == true
|
101
|
+
end
|
102
|
+
it "should be settable" do
|
103
|
+
config.menu :if => proc { false }
|
104
|
+
config.menu_item_display_if.call.should == false
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -23,4 +23,48 @@ describe ActiveAdmin::Dashboards::DashboardController do
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
+
describe "conditionally displaying sections" do
|
27
|
+
before { ActiveAdmin::Dashboards.clear_all_sections! }
|
28
|
+
let(:controller){ Admin::DashboardController.new }
|
29
|
+
|
30
|
+
context "when :if not specified" do
|
31
|
+
before do
|
32
|
+
@section = ActiveAdmin::Dashboards.add_section('Stats').last
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should include section" do
|
36
|
+
controller.send(:find_sections).should include(@section)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when :if option specified as a method" do
|
41
|
+
before do
|
42
|
+
@section = ActiveAdmin::Dashboards.add_section('Secret Codes', :if => :i_am_awesome?).last
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should call the method of the same name" do
|
46
|
+
controller.should_receive(:i_am_awesome?).and_return(true)
|
47
|
+
controller.send(:find_sections).should include(@section)
|
48
|
+
|
49
|
+
controller.should_receive(:i_am_awesome?).and_return(false)
|
50
|
+
controller.send(:find_sections).should_not include(@section)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when :if option specified as block" do
|
55
|
+
before do
|
56
|
+
@proc = Proc.new { true }
|
57
|
+
@section = ActiveAdmin::Dashboards.add_section('Secret Codes', :if => proc {}).last
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should evaluate the block" do
|
61
|
+
controller.should_receive(:instance_exec).with(&@proc).and_return(true)
|
62
|
+
controller.send(:find_sections).should include(@section)
|
63
|
+
|
64
|
+
controller.should_receive(:instance_exec).with(&@proc).and_return(false)
|
65
|
+
controller.send(:find_sections).should_not include(@section)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
26
70
|
end
|
data/spec/unit/event_spec.rb
CHANGED
@@ -12,6 +12,12 @@ describe ActiveAdmin::EventDispatcher do
|
|
12
12
|
dispatcher.subscribers(test_event).size.should == 1
|
13
13
|
end
|
14
14
|
|
15
|
+
it "should add a subscriber for multiple events" do
|
16
|
+
dispatcher.subscribe(test_event, test_event + "1"){ true }
|
17
|
+
dispatcher.subscribers(test_event).size.should == 1
|
18
|
+
dispatcher.subscribers(test_event + "1").size.should == 1
|
19
|
+
end
|
20
|
+
|
15
21
|
it "should call the dispatch block with no arguments" do
|
16
22
|
dispatcher.subscribe(test_event){ raise StandardError, "From Event Handler" }
|
17
23
|
lambda {
|
@@ -56,6 +56,15 @@ describe ActiveAdmin::ViewHelpers::FilterFormHelper do
|
|
56
56
|
it "should label a text field with search" do
|
57
57
|
body.should have_tag('label', 'Search Title')
|
58
58
|
end
|
59
|
+
|
60
|
+
it "should translate the label for text field" do
|
61
|
+
begin
|
62
|
+
I18n.backend.store_translations(:en, :activerecord => { :attributes => { :post => { :title => "Name" } } })
|
63
|
+
body.should have_tag('label', 'Search Name')
|
64
|
+
ensure
|
65
|
+
I18n.backend.reload!
|
66
|
+
end
|
67
|
+
end
|
59
68
|
end
|
60
69
|
|
61
70
|
describe "text attribute" do
|
@@ -65,19 +65,13 @@ describe ActiveAdmin::FormBuilder do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
context "when polymorphic relationship" do
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
it "should not generate any field" do
|
79
|
-
body.should have_tag("form", :attributes => { :method => 'post' })
|
80
|
-
body.should_not have_tag("select")
|
68
|
+
it "should raise error" do
|
69
|
+
lambda {
|
70
|
+
comment = ActiveAdmin::Comment.new
|
71
|
+
active_admin_form_for comment, :url => "admins/comments" do |f|
|
72
|
+
f.inputs :resource
|
73
|
+
end
|
74
|
+
}.should raise_error(Formtastic::PolymorphicInputWithoutCollectionError)
|
81
75
|
end
|
82
76
|
end
|
83
77
|
|
@@ -215,7 +209,7 @@ describe ActiveAdmin::FormBuilder do
|
|
215
209
|
body = build_form do |f|
|
216
210
|
f.input :title, :wrapper_html => { :class => "important" }
|
217
211
|
end
|
218
|
-
body.should have_tag("li", :attributes => {:class => "string optional
|
212
|
+
body.should have_tag("li", :attributes => {:class => "important string input optional stringish"})
|
219
213
|
end
|
220
214
|
end
|
221
215
|
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveAdmin::Namespace, "registering a page" do
|
4
|
+
|
5
|
+
let(:application){ ActiveAdmin::Application.new }
|
6
|
+
|
7
|
+
let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
|
8
|
+
|
9
|
+
context "with no configuration" do
|
10
|
+
before do
|
11
|
+
namespace.register_page "Status"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should store the namespaced registered configuration" do
|
15
|
+
namespace.resources.keys.should include('Status')
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should create a new controller in the default namespace" do
|
19
|
+
defined?(Admin::StatusController).should be_true
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should create a menu item" do
|
23
|
+
namespace.load_menu!
|
24
|
+
namespace.menu["Status"].should be_an_instance_of(ActiveAdmin::MenuItem)
|
25
|
+
end
|
26
|
+
end # context "with no configuration"
|
27
|
+
|
28
|
+
context "with a block configuration" do
|
29
|
+
it "should be evaluated in the dsl" do
|
30
|
+
lambda {
|
31
|
+
namespace.register_page "Status" do
|
32
|
+
raise "Hello World"
|
33
|
+
end
|
34
|
+
}.should raise_error
|
35
|
+
end
|
36
|
+
end # context "with a block configuration"
|
37
|
+
|
38
|
+
describe "adding to the menu" do
|
39
|
+
describe "adding as a top level item" do
|
40
|
+
before do
|
41
|
+
namespace.register_page "Status"
|
42
|
+
namespace.load_menu!
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should add a new menu item" do
|
46
|
+
namespace.menu['Status'].should_not be_nil
|
47
|
+
end
|
48
|
+
end # describe "adding as a top level item"
|
49
|
+
|
50
|
+
describe "adding as a child" do
|
51
|
+
before do
|
52
|
+
namespace.register_page "Status" do
|
53
|
+
menu :parent => 'Extra'
|
54
|
+
end
|
55
|
+
namespace.load_menu!
|
56
|
+
end
|
57
|
+
it "should generate the parent menu item" do
|
58
|
+
namespace.menu['Extra'].should_not be_nil
|
59
|
+
end
|
60
|
+
it "should generate its own child item" do
|
61
|
+
namespace.menu['Extra']['Status'].should_not be_nil
|
62
|
+
end
|
63
|
+
end # describe "adding as a child"
|
64
|
+
|
65
|
+
describe "disabling the menu" do
|
66
|
+
before do
|
67
|
+
namespace.register_page "Status" do
|
68
|
+
menu false
|
69
|
+
end
|
70
|
+
namespace.load_menu!
|
71
|
+
end
|
72
|
+
it "should not create a menu item" do
|
73
|
+
namespace.menu["Status"].should be_nil
|
74
|
+
end
|
75
|
+
end # describe "disabling the menu"
|
76
|
+
|
77
|
+
describe "setting menu priority" do
|
78
|
+
before do
|
79
|
+
namespace.register_page "Status" do
|
80
|
+
menu :priority => 2
|
81
|
+
end
|
82
|
+
namespace.load_menu!
|
83
|
+
end
|
84
|
+
it "should have a custom priority of 2" do
|
85
|
+
namespace.menu["Status"].priority.should == 2
|
86
|
+
end
|
87
|
+
end # describe "setting menu priority"
|
88
|
+
|
89
|
+
describe "setting a condition for displaying" do
|
90
|
+
before do
|
91
|
+
namespace.register_page "Status" do
|
92
|
+
menu :if => proc { false }
|
93
|
+
end
|
94
|
+
namespace.load_menu!
|
95
|
+
end
|
96
|
+
it "should have a proc returning false" do
|
97
|
+
namespace.menu["Status"].display_if_block.should be_instance_of(Proc)
|
98
|
+
namespace.menu["Status"].display_if_block.call.should == false
|
99
|
+
end
|
100
|
+
end # describe "setting a condition for displaying"
|
101
|
+
end # describe "adding to the menu"
|
102
|
+
end
|