activeadmin 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activeadmin might be problematic. Click here for more details.
- data/.travis.yml +8 -5
- data/CHANGELOG.md +151 -0
- data/Gemfile +16 -16
- data/LICENSE +1 -1
- data/activeadmin.gemspec +1 -0
- data/app/assets/images/active_admin/index_list_icons/block_icon.svg +10 -0
- data/app/assets/images/active_admin/index_list_icons/blog_icon.svg +4 -0
- data/app/assets/images/active_admin/index_list_icons/grid_icon.svg +13 -0
- data/app/assets/images/active_admin/index_list_icons/table_icon.svg +3 -0
- data/app/assets/javascripts/active_admin/components/jquery.aa.checkbox-toggler.js.coffee +17 -44
- data/app/assets/javascripts/active_admin/components/jquery.aa.dropdown-menu.js.coffee +2 -4
- data/app/assets/javascripts/active_admin/components/jquery.aa.popover.js.coffee +0 -3
- data/app/assets/javascripts/active_admin/components/jquery.aa.table-checkbox-toggler.js.coffee +10 -12
- data/app/assets/javascripts/active_admin/pages/application.js.coffee +13 -10
- data/app/assets/javascripts/active_admin/pages/batch_actions.js.coffee +3 -3
- data/app/assets/stylesheets/active_admin/_base.css.scss +1 -0
- data/app/assets/stylesheets/active_admin/_header.css.scss +5 -2
- data/app/assets/stylesheets/active_admin/components/_dropdown_menu.scss +2 -2
- data/app/assets/stylesheets/active_admin/components/_index_list.scss +12 -0
- data/app/assets/stylesheets/active_admin/components/_popovers.css.scss +2 -2
- data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +2 -2
- data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +4 -4
- data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +5 -4
- data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +1 -1
- data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +1 -1
- data/app/assets/stylesheets/active_admin/print.css.scss +2 -2
- data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +1 -1
- data/app/views/active_admin/devise/unlocks/new.html.erb +14 -12
- data/docs/1-general-configuration.md +13 -0
- data/docs/10-custom-pages.md +40 -28
- data/docs/11-decorators.md +6 -4
- data/docs/12-arbre-components.md +1 -1
- data/docs/13-authorization-adapter.md +206 -0
- data/docs/2-resource-customization.md +129 -14
- data/docs/3-index-pages.md +65 -0
- data/docs/3-index-pages/create-an-index.md +29 -0
- data/docs/3-index-pages/index-as-table.md +35 -11
- data/docs/5-forms.md +2 -2
- data/features/authorization.feature +64 -0
- data/features/authorization_cancan.feature +52 -0
- data/features/belongs_to.feature +41 -5
- data/features/index/batch_actions.feature +27 -3
- data/features/index/formats.feature +27 -0
- data/features/index/index_as_table.feature +74 -2
- data/features/index/index_parameters.feature +69 -0
- data/features/index/index_scopes.feature +7 -11
- data/features/index/page_title.feature +18 -0
- data/features/index/switch_index_view.feature +73 -0
- data/features/menu.feature +27 -0
- data/features/registering_pages.feature +21 -0
- data/features/step_definitions/additional_web_steps.rb +4 -0
- data/features/step_definitions/batch_action_steps.rb +16 -6
- data/features/step_definitions/index_scope_steps.rb +3 -3
- data/features/step_definitions/index_views_steps.rb +3 -0
- data/features/step_definitions/menu_steps.rb +4 -0
- data/features/support/env.rb +4 -0
- data/features/support/paths.rb +3 -0
- data/lib/active_admin.rb +4 -0
- data/lib/active_admin/application.rb +43 -76
- data/lib/active_admin/authorization_adapter.rb +128 -0
- data/lib/active_admin/base_controller.rb +18 -1
- data/lib/active_admin/base_controller/authorization.rb +153 -0
- data/lib/active_admin/base_controller/menu.rb +8 -3
- data/lib/active_admin/batch_actions/resource_extension.rb +8 -7
- data/lib/active_admin/batch_actions/views/batch_action_form.rb +1 -1
- data/lib/active_admin/cancan_adapter.rb +40 -0
- data/lib/active_admin/dashboards.rb +4 -5
- data/lib/active_admin/dashboards/dashboard_controller.rb +1 -1
- data/lib/active_admin/devise.rb +22 -7
- data/lib/active_admin/dsl.rb +18 -5
- data/lib/active_admin/engine.rb +1 -1
- data/lib/active_admin/filters/dsl.rb +1 -1
- data/lib/active_admin/filters/forms.rb +9 -7
- data/lib/active_admin/filters/resource_extension.rb +20 -15
- data/lib/active_admin/form_builder.rb +44 -49
- data/lib/active_admin/helpers/optional_display.rb +4 -8
- data/lib/active_admin/inputs/filter_boolean_input.rb +1 -1
- data/lib/active_admin/inputs/filter_string_input.rb +5 -1
- data/lib/active_admin/locales/bg.yml +1 -1
- data/lib/active_admin/locales/ca.yml +1 -1
- data/lib/active_admin/locales/cs.yml +26 -25
- data/lib/active_admin/locales/da.yml +1 -1
- data/lib/active_admin/locales/de.yml +1 -1
- data/lib/active_admin/locales/en.yml +11 -1
- data/lib/active_admin/locales/es.yml +16 -16
- data/lib/active_admin/locales/fr.yml +1 -1
- data/lib/active_admin/locales/he.yml +1 -1
- data/lib/active_admin/locales/hr.yml +1 -1
- data/lib/active_admin/locales/hu.yml +1 -1
- data/lib/active_admin/locales/it.yml +1 -1
- data/lib/active_admin/locales/ja.yml +4 -1
- data/lib/active_admin/locales/ko.yml +1 -1
- data/lib/active_admin/locales/lt.yml +1 -1
- data/lib/active_admin/locales/lv.yml +12 -1
- data/lib/active_admin/locales/nl.yml +2 -2
- data/lib/active_admin/locales/no-NB.yml +22 -1
- data/lib/active_admin/locales/pl.yml +1 -1
- data/lib/active_admin/locales/pt-BR.yml +1 -1
- data/lib/active_admin/locales/pt-PT.yml +81 -0
- data/lib/active_admin/locales/ro.yml +1 -1
- data/lib/active_admin/locales/ru.yml +1 -1
- data/lib/active_admin/locales/sv-SE.yml +1 -1
- data/lib/active_admin/locales/tr.yml +1 -1
- data/lib/active_admin/locales/vi.yml +1 -1
- data/lib/active_admin/locales/zh-CN.yml +1 -1
- data/lib/active_admin/locales/zh-TW.yml +1 -1
- data/lib/active_admin/menu.rb +76 -38
- data/lib/active_admin/menu_collection.rb +96 -0
- data/lib/active_admin/menu_item.rb +61 -71
- data/lib/active_admin/namespace.rb +67 -5
- data/lib/active_admin/page.rb +6 -0
- data/lib/active_admin/page_controller.rb +13 -3
- data/lib/active_admin/resource.rb +11 -20
- data/lib/active_admin/resource/action_items.rb +3 -3
- data/lib/active_admin/resource/controllers.rb +0 -17
- data/lib/active_admin/resource/menu.rb +52 -24
- data/lib/active_admin/resource/naming.rb +6 -10
- data/lib/active_admin/resource/page_presenters.rb +57 -3
- data/lib/active_admin/resource/routes.rb +46 -0
- data/lib/active_admin/resource_controller.rb +2 -17
- data/lib/active_admin/resource_controller/data_access.rb +299 -0
- data/lib/active_admin/resource_controller/decorators.rb +2 -1
- data/lib/active_admin/resource_dsl.rb +12 -14
- data/lib/active_admin/router.rb +61 -56
- data/lib/active_admin/scope.rb +28 -18
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_factory.rb +0 -1
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +13 -19
- data/lib/active_admin/view_helpers/fields_for.rb +2 -0
- data/lib/active_admin/view_helpers/form_helper.rb +1 -1
- data/lib/active_admin/view_helpers/method_or_proc_helper.rb +66 -11
- data/lib/active_admin/views/components/attributes_table.rb +7 -4
- data/lib/active_admin/views/components/index_list.rb +68 -0
- data/lib/active_admin/views/components/paginated_collection.rb +13 -9
- data/lib/active_admin/views/components/scopes.rb +2 -8
- data/lib/active_admin/views/components/table_for.rb +1 -1
- data/lib/active_admin/views/footer.rb +1 -1
- data/lib/active_admin/views/header.rb +3 -2
- data/lib/active_admin/views/index_as_block.rb +4 -0
- data/lib/active_admin/views/index_as_blog.rb +4 -0
- data/lib/active_admin/views/index_as_grid.rb +4 -0
- data/lib/active_admin/views/index_as_table.rb +49 -7
- data/lib/active_admin/views/pages/index.rb +19 -4
- data/lib/active_admin/views/tabbed_navigation.rb +10 -54
- data/lib/generators/active_admin/install/install_generator.rb +5 -1
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +58 -0
- data/spec/integration/{default_namespace.rb → default_namespace_spec.rb} +0 -16
- data/spec/spec_helper.rb +3 -0
- data/spec/support/detect_rails_version.rb +10 -3
- data/spec/support/rails_template.rb +1 -1
- data/spec/support/templates/post_decorator.rb +6 -6
- data/spec/unit/application_spec.rb +5 -5
- data/spec/unit/authorization/authorization_adapter_spec.rb +61 -0
- data/spec/unit/authorization/controller_authorization_spec.rb +47 -0
- data/spec/unit/base_controller_spec.rb +0 -2
- data/spec/unit/batch_actions/resource_spec.rb +1 -1
- data/spec/unit/breadcrumbs_spec.rb +3 -3
- data/spec/unit/cancan_adapter_spec.rb +35 -0
- data/spec/unit/config_shared_examples.rb +9 -30
- data/spec/unit/devise_spec.rb +29 -0
- data/spec/unit/dsl_spec.rb +61 -0
- data/spec/unit/filters/filter_form_builder_spec.rb +58 -4
- data/spec/unit/filters/resource_spec.rb +17 -5
- data/spec/unit/form_builder_spec.rb +15 -0
- data/spec/unit/menu_collection_spec.rb +62 -0
- data/spec/unit/menu_item_spec.rb +51 -37
- data/spec/unit/menu_spec.rb +33 -29
- data/spec/unit/namespace/authorization_spec.rb +31 -0
- data/spec/unit/namespace/register_page_spec.rb +6 -28
- data/spec/unit/namespace/register_resource_spec.rb +11 -34
- data/spec/unit/namespace_spec.rb +63 -2
- data/spec/unit/page_controller_spec.rb +0 -3
- data/spec/unit/reloader_spec.rb +5 -5
- data/spec/unit/resource/menu_spec.rb +1 -13
- data/spec/unit/resource/naming_spec.rb +20 -2
- data/spec/unit/resource/page_presenters_spec.rb +14 -2
- data/spec/unit/resource_controller/{collection_spec.rb → data_access_spec.rb} +31 -13
- data/spec/unit/resource_controller_spec.rb +4 -5
- data/spec/unit/resource_spec.rb +33 -11
- data/spec/unit/routing_spec.rb +43 -0
- data/spec/unit/scope_spec.rb +13 -0
- data/spec/unit/view_factory_spec.rb +0 -1
- data/spec/unit/view_helpers/fields_for_spec.rb +4 -0
- data/spec/unit/view_helpers/form_helper_spec.rb +6 -2
- data/spec/unit/view_helpers/method_or_proc_helper_spec.rb +97 -0
- data/spec/unit/views/components/attributes_table_spec.rb +11 -0
- data/spec/unit/views/components/index_list_spec.rb +32 -0
- data/spec/unit/views/tabbed_navigation_spec.rb +42 -40
- data/tasks/test.rake +1 -1
- metadata +127 -40
- data/lib/active_admin/menu_builder.rb +0 -65
- data/lib/active_admin/resource_controller/callbacks.rb +0 -59
- data/lib/active_admin/resource_controller/collection.rb +0 -158
- data/lib/active_admin/views/utility_nav.rb +0 -41
- data/spec/unit/base_controller_shared_examples.rb +0 -25
- data/spec/unit/dsl_include_spec.rb +0 -20
@@ -408,4 +408,19 @@ describe ActiveAdmin::FormBuilder do
|
|
408
408
|
end
|
409
409
|
end
|
410
410
|
|
411
|
+
describe "inputs block with nil return value" do
|
412
|
+
let :body do
|
413
|
+
build_form do |f|
|
414
|
+
f.inputs do
|
415
|
+
f.input :title
|
416
|
+
nil
|
417
|
+
end
|
418
|
+
end
|
419
|
+
end
|
420
|
+
|
421
|
+
it "should generate a single input field" do
|
422
|
+
body.should have_tag("input", :attributes => { :type => "text", :name => "post[title]" })
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
411
426
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveAdmin::MenuCollection do
|
4
|
+
|
5
|
+
let(:menus) { ActiveAdmin::MenuCollection.new }
|
6
|
+
|
7
|
+
describe "#add" do
|
8
|
+
|
9
|
+
it "should initialize a new menu when first item" do
|
10
|
+
menus.add :default, :label => "Hello World"
|
11
|
+
|
12
|
+
menus.fetch(:default).items.size.should == 1
|
13
|
+
menus.fetch(:default)["Hello World"].should be_an_instance_of(ActiveAdmin::MenuItem)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should add items to an existing menu" do
|
17
|
+
menus.add :default, :label => "Hello World"
|
18
|
+
menus.add :default, :label => "Hello World Again"
|
19
|
+
|
20
|
+
menus.fetch(:default).items.size.should == 2
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#clear!" do
|
26
|
+
|
27
|
+
it "should remove all menus" do
|
28
|
+
menus.add :default, :label => "Hello World"
|
29
|
+
|
30
|
+
menus.clear!
|
31
|
+
|
32
|
+
expect {
|
33
|
+
menus.fetch(:non_default_menu)
|
34
|
+
}.to raise_error(ActiveAdmin::MenuCollection::NoMenuError)
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#on_build" do
|
41
|
+
|
42
|
+
it "runs a callback when fetching a menu" do
|
43
|
+
menus.on_build do |m|
|
44
|
+
m.add :default, :label => "Hello World"
|
45
|
+
end
|
46
|
+
|
47
|
+
menus.fetch(:default)["Hello World"].should_not be_nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it "re-runs the callbacks when the menu is cleared" do
|
51
|
+
menus.on_build do |m|
|
52
|
+
m.add :default, :label => "Hello World"
|
53
|
+
end
|
54
|
+
|
55
|
+
menus.fetch(:default)["Hello World"].should_not be_nil
|
56
|
+
menus.clear!
|
57
|
+
menus.fetch(:default)["Hello World"].should_not be_nil
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
data/spec/unit/menu_item_spec.rb
CHANGED
@@ -20,53 +20,71 @@ module ActiveAdmin
|
|
20
20
|
item.priority.should == 10
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
context "conditional display" do
|
24
|
+
it "should store a Proc internally and evaluate it when requested" do
|
25
|
+
item = MenuItem.new
|
26
|
+
item.instance_variable_get(:@should_display).should be_a Proc
|
27
|
+
item.display?.should_not be_a Proc
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should show the item by default" do
|
31
|
+
MenuItem.new.display?.should == true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should hide the item" do
|
35
|
+
MenuItem.new(:if => proc{false}).display?.should == false
|
36
|
+
end
|
27
37
|
end
|
28
38
|
|
29
|
-
it "should
|
39
|
+
it "should default to an empty hash for html_options" do
|
30
40
|
item = MenuItem.new
|
31
|
-
item.
|
32
|
-
item.display_if_block.call(self).should == true
|
41
|
+
item.html_options.should be_empty
|
33
42
|
end
|
34
43
|
|
35
|
-
|
44
|
+
it "should accept an options hash for link_to" do
|
45
|
+
item = MenuItem.new :html_options => { :target => :blank }
|
46
|
+
item.html_options.should include(:target => :blank)
|
47
|
+
end
|
48
|
+
|
49
|
+
context "with no items" do
|
36
50
|
it "should be empty" do
|
37
51
|
item = MenuItem.new
|
38
|
-
item.
|
52
|
+
item.items.should be_empty
|
39
53
|
end
|
40
54
|
|
41
55
|
it "should accept new children" do
|
42
|
-
item = MenuItem.new
|
43
|
-
item.add
|
44
|
-
item.
|
45
|
-
item.
|
56
|
+
item = MenuItem.new :label => "Dashboard"
|
57
|
+
item.add :label => "My Child Dashboard"
|
58
|
+
item.items.first.should be_a MenuItem
|
59
|
+
item.items.first.label.should == "My Child Dashboard"
|
46
60
|
end
|
47
61
|
end
|
48
62
|
|
49
63
|
context "with many children" do
|
50
64
|
let(:item) do
|
51
65
|
i = MenuItem.new(:label => "Dashboard")
|
52
|
-
i.add
|
53
|
-
i.add
|
54
|
-
i.add
|
55
|
-
i.add
|
56
|
-
i.add
|
66
|
+
i.add :label => "Blog"
|
67
|
+
i.add :label => "Cars"
|
68
|
+
i.add :label => "Users", :priority => 1
|
69
|
+
i.add :label => "Settings", :priority => 2
|
70
|
+
i.add :label => "Analytics", :priority => 44
|
57
71
|
i
|
58
72
|
end
|
59
73
|
|
74
|
+
it "should contain 5 submenu items" do
|
75
|
+
item.items.count.should == 5
|
76
|
+
end
|
77
|
+
|
60
78
|
it "should give access to the menu item as an array" do
|
61
79
|
item['Blog'].label.should == 'Blog'
|
62
80
|
end
|
63
81
|
|
64
82
|
it "should sort items based on priority and name" do
|
65
|
-
item.
|
66
|
-
item.
|
67
|
-
item.
|
68
|
-
item.
|
69
|
-
item.
|
83
|
+
item.items[0].label.should == 'Users'
|
84
|
+
item.items[1].label.should == 'Settings'
|
85
|
+
item.items[2].label.should == 'Blog'
|
86
|
+
item.items[3].label.should == 'Cars'
|
87
|
+
item.items[4].label.should == 'Analytics'
|
70
88
|
end
|
71
89
|
|
72
90
|
it "children should hold a reference to their parent" do
|
@@ -85,7 +103,7 @@ module ActiveAdmin
|
|
85
103
|
|
86
104
|
context "with one parent" do
|
87
105
|
let(:sub_item) do
|
88
|
-
item.add
|
106
|
+
item.add :label => "Create New"
|
89
107
|
item["Create New"]
|
90
108
|
end
|
91
109
|
it "should return an array with the parent" do
|
@@ -95,13 +113,11 @@ module ActiveAdmin
|
|
95
113
|
|
96
114
|
context "with many parents" do
|
97
115
|
before(:each) do
|
98
|
-
c1 =
|
99
|
-
c2 =
|
100
|
-
c3 =
|
116
|
+
c1 = {:label => "C1"}
|
117
|
+
c2 = {:label => "C2"}
|
118
|
+
c3 = {:label => "C3"}
|
101
119
|
|
102
|
-
item.add(c1)
|
103
|
-
c1.add c2
|
104
|
-
c2.add c3
|
120
|
+
item.add(c1).add(c2).add(c3)
|
105
121
|
|
106
122
|
item
|
107
123
|
end
|
@@ -113,16 +129,14 @@ module ActiveAdmin
|
|
113
129
|
end # accessing ancestory
|
114
130
|
|
115
131
|
|
116
|
-
describe "
|
117
|
-
|
118
|
-
|
119
|
-
MenuItem.generate_item_id("Identifier").should == "identifier"
|
132
|
+
describe "#id" do
|
133
|
+
it "should be normalized" do
|
134
|
+
MenuItem.new(:id => "Foo Bar").id.should == "foo_bar"
|
120
135
|
end
|
121
136
|
|
122
|
-
it "should
|
123
|
-
MenuItem.
|
137
|
+
it "should not accept Procs" do
|
138
|
+
expect{ MenuItem.new(:id => proc{"Dynamic"}).id }.to raise_error TypeError
|
124
139
|
end
|
125
|
-
|
126
140
|
end
|
127
141
|
|
128
142
|
end
|
data/spec/unit/menu_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
require 'active_admin/menu'
|
3
3
|
require 'active_admin/menu_item'
|
4
4
|
|
@@ -7,7 +7,6 @@ include ActiveAdmin
|
|
7
7
|
describe ActiveAdmin::Menu do
|
8
8
|
|
9
9
|
context "with no items" do
|
10
|
-
|
11
10
|
it "should have an empty item collection" do
|
12
11
|
menu = Menu.new
|
13
12
|
menu.items.should be_empty
|
@@ -15,18 +14,16 @@ describe ActiveAdmin::Menu do
|
|
15
14
|
|
16
15
|
it "should accept new items" do
|
17
16
|
menu = Menu.new
|
18
|
-
|
19
|
-
menu.
|
20
|
-
menu.items.first.should == item
|
17
|
+
menu.add :label => "Dashboard"
|
18
|
+
menu.items.first.label.should == "Dashboard"
|
21
19
|
end
|
22
|
-
|
23
20
|
end
|
24
21
|
|
25
|
-
context "with many
|
22
|
+
context "with many items" do
|
26
23
|
let(:menu) do
|
27
24
|
Menu.new do |m|
|
28
|
-
m.add
|
29
|
-
m.add
|
25
|
+
m.add :label => "Dashboard"
|
26
|
+
m.add :label => "Blog"
|
30
27
|
end
|
31
28
|
end
|
32
29
|
|
@@ -35,33 +32,40 @@ describe ActiveAdmin::Menu do
|
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
38
|
-
describe
|
39
|
-
|
40
|
-
|
35
|
+
describe "adding items with children" do
|
36
|
+
it "should add an empty item if the parent does not exist" do
|
37
|
+
menu = Menu.new
|
38
|
+
menu.add :parent => "Admin", :label => "Users"
|
41
39
|
|
42
|
-
|
43
|
-
collection.should be_empty
|
40
|
+
menu["Admin"]["Users"].should be_an_instance_of(ActiveAdmin::MenuItem)
|
44
41
|
end
|
45
42
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
collection.push menu_item
|
51
|
-
end
|
43
|
+
it "should add a child to a parent if it exists" do
|
44
|
+
menu = Menu.new
|
45
|
+
menu.add :parent => "Admin", :label => "Users"
|
46
|
+
menu.add :parent => "Admin", :label => "Projects"
|
52
47
|
|
53
|
-
|
54
|
-
|
55
|
-
collection.find_by_id("an_id").should == menu_item
|
56
|
-
end
|
48
|
+
menu["Admin"]["Projects"].should be_an_instance_of(ActiveAdmin::MenuItem)
|
49
|
+
end
|
57
50
|
|
58
|
-
|
59
|
-
|
60
|
-
|
51
|
+
it "should assign children regardless of resource file load order" do
|
52
|
+
menu = Menu.new
|
53
|
+
menu.add :parent => "Users", :label => "Posts"
|
54
|
+
menu.add :label => "Users", :url => "/some/url"
|
61
55
|
|
56
|
+
menu["Users"].url.should == "/some/url"
|
57
|
+
menu["Users"]["Posts"].should be_a ActiveAdmin::MenuItem
|
62
58
|
end
|
63
|
-
|
64
59
|
end
|
65
60
|
|
66
|
-
|
61
|
+
describe "sorting items" do
|
62
|
+
it "should sort children by the result of their label proc" do
|
63
|
+
menu = Menu.new
|
64
|
+
menu.add :label => proc{ "G" }, :id => "not related 1"
|
65
|
+
menu.add :label => proc{ "B" }, :id => "not related 2"
|
66
|
+
menu.add :label => proc{ "A" }, :id => "not related 3"
|
67
67
|
|
68
|
+
menu.items.map(&:label).should == %w[A B G]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveAdmin::Resource, "authorization" do
|
4
|
+
|
5
|
+
let(:app){ ActiveAdmin::Application.new }
|
6
|
+
let(:namespace){ ActiveAdmin::Namespace.new(app, :admin) }
|
7
|
+
let(:mock_auth){ mock }
|
8
|
+
|
9
|
+
describe "authorization_adapter" do
|
10
|
+
|
11
|
+
it "should return AuthorizationAdapter by default" do
|
12
|
+
namespace.authorization_adapter.should == ActiveAdmin::AuthorizationAdapter
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should be settable on the namespace" do
|
16
|
+
namespace.authorization_adapter.should == ActiveAdmin::AuthorizationAdapter
|
17
|
+
namespace.authorization_adapter = mock_auth
|
18
|
+
|
19
|
+
namespace.authorization_adapter.should == mock_auth
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should be settable on the application" do
|
23
|
+
namespace.authorization_adapter.should == ActiveAdmin::AuthorizationAdapter
|
24
|
+
app.authorization_adapter = mock_auth
|
25
|
+
|
26
|
+
namespace.authorization_adapter.should == mock_auth
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -5,6 +5,7 @@ describe ActiveAdmin::Namespace, "registering a page" do
|
|
5
5
|
let(:application){ ActiveAdmin::Application.new }
|
6
6
|
|
7
7
|
let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
|
8
|
+
let(:menu){ namespace.fetch_menu(:default) }
|
8
9
|
|
9
10
|
context "with no configuration" do
|
10
11
|
before do
|
@@ -20,7 +21,7 @@ describe ActiveAdmin::Namespace, "registering a page" do
|
|
20
21
|
end
|
21
22
|
|
22
23
|
it "should create a menu item" do
|
23
|
-
|
24
|
+
menu["Status"].should be_an_instance_of(ActiveAdmin::MenuItem)
|
24
25
|
end
|
25
26
|
end # context "with no configuration"
|
26
27
|
|
@@ -41,7 +42,7 @@ describe ActiveAdmin::Namespace, "registering a page" do
|
|
41
42
|
end
|
42
43
|
|
43
44
|
it "should add a new menu item" do
|
44
|
-
|
45
|
+
menu['Status'].should_not be_nil
|
45
46
|
end
|
46
47
|
end # describe "adding as a top level item"
|
47
48
|
|
@@ -52,10 +53,10 @@ describe ActiveAdmin::Namespace, "registering a page" do
|
|
52
53
|
end
|
53
54
|
end
|
54
55
|
it "should generate the parent menu item" do
|
55
|
-
|
56
|
+
menu['Extra'].should_not be_nil
|
56
57
|
end
|
57
58
|
it "should generate its own child item" do
|
58
|
-
|
59
|
+
menu['Extra']['Status'].should_not be_nil
|
59
60
|
end
|
60
61
|
end # describe "adding as a child"
|
61
62
|
|
@@ -66,31 +67,8 @@ describe ActiveAdmin::Namespace, "registering a page" do
|
|
66
67
|
end
|
67
68
|
end
|
68
69
|
it "should not create a menu item" do
|
69
|
-
|
70
|
+
menu["Status"].should be_nil
|
70
71
|
end
|
71
72
|
end # describe "disabling the menu"
|
72
|
-
|
73
|
-
describe "setting menu priority" do
|
74
|
-
before do
|
75
|
-
namespace.register_page "Status" do
|
76
|
-
menu :priority => 2
|
77
|
-
end
|
78
|
-
end
|
79
|
-
it "should have a custom priority of 2" do
|
80
|
-
namespace.menu["Status"].priority.should == 2
|
81
|
-
end
|
82
|
-
end # describe "setting menu priority"
|
83
|
-
|
84
|
-
describe "setting a condition for displaying" do
|
85
|
-
before do
|
86
|
-
namespace.register_page "Status" do
|
87
|
-
menu :if => proc { false }
|
88
|
-
end
|
89
|
-
end
|
90
|
-
it "should have a proc returning false" do
|
91
|
-
namespace.menu["Status"].display_if_block.should be_instance_of(Proc)
|
92
|
-
namespace.menu["Status"].display_if_block.call.should == false
|
93
|
-
end
|
94
|
-
end # describe "setting a condition for displaying"
|
95
73
|
end # describe "adding to the menu"
|
96
74
|
end
|
@@ -6,6 +6,8 @@ describe ActiveAdmin::Namespace, "registering a resource" do
|
|
6
6
|
|
7
7
|
let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
|
8
8
|
|
9
|
+
let(:menu){ namespace.fetch_menu(:default) }
|
10
|
+
|
9
11
|
context "with no configuration" do
|
10
12
|
before do
|
11
13
|
namespace.register Category
|
@@ -20,8 +22,8 @@ describe ActiveAdmin::Namespace, "registering a resource" do
|
|
20
22
|
defined?(Admin::DashboardController).should be_true
|
21
23
|
end
|
22
24
|
it "should create a menu item" do
|
23
|
-
|
24
|
-
|
25
|
+
menu["Categories"].should be_a ActiveAdmin::MenuItem
|
26
|
+
menu["Categories"].instance_variable_get(:@url).should be_a Proc
|
25
27
|
end
|
26
28
|
end # context "with no configuration"
|
27
29
|
|
@@ -48,13 +50,12 @@ describe ActiveAdmin::Namespace, "registering a resource" do
|
|
48
50
|
defined?(Admin::MockResourcesController).should be_true
|
49
51
|
end
|
50
52
|
it "should create a menu item" do
|
51
|
-
|
53
|
+
menu["Mock Resources"].should be_an_instance_of(ActiveAdmin::MenuItem)
|
52
54
|
end
|
53
55
|
|
54
56
|
it "should use the resource as the model in the controller" do
|
55
57
|
Admin::MockResourcesController.resource_class.should == Mock::Resource
|
56
58
|
end
|
57
|
-
|
58
59
|
end # context "with a resource that's namespaced"
|
59
60
|
|
60
61
|
describe "finding resource instances" do
|
@@ -79,7 +80,6 @@ describe ActiveAdmin::Namespace, "registering a resource" do
|
|
79
80
|
publisher = namespace.register Publisher
|
80
81
|
namespace.resource_for(Publisher).should == publisher
|
81
82
|
end
|
82
|
-
|
83
83
|
end # describe "finding resource instances"
|
84
84
|
|
85
85
|
describe "adding to the menu" do
|
@@ -88,7 +88,7 @@ describe ActiveAdmin::Namespace, "registering a resource" do
|
|
88
88
|
namespace.register Category
|
89
89
|
end
|
90
90
|
it "should add a new menu item" do
|
91
|
-
|
91
|
+
menu['Categories'].should_not be_nil
|
92
92
|
end
|
93
93
|
end # describe "adding as a top level item"
|
94
94
|
|
@@ -99,10 +99,10 @@ describe ActiveAdmin::Namespace, "registering a resource" do
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
it "should generate the parent menu item" do
|
102
|
-
|
102
|
+
menu['Blog'].should_not be_nil
|
103
103
|
end
|
104
104
|
it "should generate its own child item" do
|
105
|
-
|
105
|
+
menu['Blog']['Categories'].should_not be_nil
|
106
106
|
end
|
107
107
|
end # describe "adding as a child"
|
108
108
|
|
@@ -113,32 +113,9 @@ describe ActiveAdmin::Namespace, "registering a resource" do
|
|
113
113
|
end
|
114
114
|
end
|
115
115
|
it "should not create a menu item" do
|
116
|
-
|
116
|
+
menu["Categories"].should be_nil
|
117
117
|
end
|
118
118
|
end # describe "disabling the menu"
|
119
|
-
|
120
|
-
describe "setting menu priority" do
|
121
|
-
before do
|
122
|
-
namespace.register Category do
|
123
|
-
menu :priority => 2
|
124
|
-
end
|
125
|
-
end
|
126
|
-
it "should have a custom priority of 2" do
|
127
|
-
namespace.menu["Categories"].priority.should == 2
|
128
|
-
end
|
129
|
-
end # describe "setting menu priority"
|
130
|
-
|
131
|
-
describe "setting a condition for displaying" do
|
132
|
-
before do
|
133
|
-
namespace.register Category do
|
134
|
-
menu :if => proc { false }
|
135
|
-
end
|
136
|
-
end
|
137
|
-
it "should have a proc returning false" do
|
138
|
-
namespace.menu["Categories"].display_if_block.should be_instance_of(Proc)
|
139
|
-
namespace.menu["Categories"].display_if_block.call.should == false
|
140
|
-
end
|
141
|
-
end # describe "setting a condition for displaying"
|
142
119
|
|
143
120
|
describe "adding as a belongs to" do
|
144
121
|
context "when not optional" do
|
@@ -148,7 +125,7 @@ describe ActiveAdmin::Namespace, "registering a resource" do
|
|
148
125
|
end
|
149
126
|
end
|
150
127
|
it "should not show up in the menu" do
|
151
|
-
|
128
|
+
menu["Posts"].should be_nil
|
152
129
|
end
|
153
130
|
end
|
154
131
|
context "when optional" do
|
@@ -158,7 +135,7 @@ describe ActiveAdmin::Namespace, "registering a resource" do
|
|
158
135
|
end
|
159
136
|
end
|
160
137
|
it "should show up in the menu" do
|
161
|
-
|
138
|
+
menu["Posts"].should_not be_nil
|
162
139
|
end
|
163
140
|
end
|
164
141
|
end
|