activeadmin 0.1.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/.document +5 -0
- data/.gitignore +25 -0
- data/Gemfile +16 -0
- data/LICENSE +20 -0
- data/README.rdoc +201 -0
- data/Rakefile +71 -0
- data/active_admin.gemspec +22 -0
- data/lib/active_admin.rb +229 -0
- data/lib/active_admin/action_builder.rb +60 -0
- data/lib/active_admin/action_items.rb +48 -0
- data/lib/active_admin/asset_registration.rb +34 -0
- data/lib/active_admin/breadcrumbs.rb +26 -0
- data/lib/active_admin/dashboards.rb +50 -0
- data/lib/active_admin/dashboards/dashboard_controller.rb +40 -0
- data/lib/active_admin/dashboards/renderer.rb +45 -0
- data/lib/active_admin/dashboards/section.rb +43 -0
- data/lib/active_admin/dashboards/section_renderer.rb +28 -0
- data/lib/active_admin/filters.rb +189 -0
- data/lib/active_admin/form_builder.rb +91 -0
- data/lib/active_admin/helpers/optional_display.rb +34 -0
- data/lib/active_admin/menu.rb +42 -0
- data/lib/active_admin/menu_item.rb +67 -0
- data/lib/active_admin/namespace.rb +111 -0
- data/lib/active_admin/page_config.rb +15 -0
- data/lib/active_admin/pages.rb +11 -0
- data/lib/active_admin/pages/base.rb +92 -0
- data/lib/active_admin/pages/edit.rb +21 -0
- data/lib/active_admin/pages/index.rb +58 -0
- data/lib/active_admin/pages/index/blog.rb +65 -0
- data/lib/active_admin/pages/index/table.rb +48 -0
- data/lib/active_admin/pages/index/thumbnails.rb +40 -0
- data/lib/active_admin/pages/new.rb +21 -0
- data/lib/active_admin/pages/show.rb +54 -0
- data/lib/active_admin/renderer.rb +72 -0
- data/lib/active_admin/resource.rb +96 -0
- data/lib/active_admin/resource_controller.rb +325 -0
- data/lib/active_admin/sidebar.rb +78 -0
- data/lib/active_admin/table_builder.rb +162 -0
- data/lib/active_admin/tabs_renderer.rb +39 -0
- data/lib/active_admin/version.rb +3 -0
- data/lib/active_admin/view_helpers.rb +106 -0
- data/lib/active_admin/views/active_admin_dashboard/index.html.erb +1 -0
- data/lib/active_admin/views/active_admin_default/edit.html.erb +1 -0
- data/lib/active_admin/views/active_admin_default/index.csv.erb +2 -0
- data/lib/active_admin/views/active_admin_default/index.html.erb +1 -0
- data/lib/active_admin/views/active_admin_default/new.html.erb +1 -0
- data/lib/active_admin/views/active_admin_default/show.html.erb +1 -0
- data/lib/active_admin/views/layouts/active_admin.html.erb +40 -0
- data/lib/activeadmin.rb +1 -0
- data/lib/generators/active_admin/install/install_generator.rb +31 -0
- data/lib/generators/active_admin/install/templates/active_admin.css +325 -0
- data/lib/generators/active_admin/install/templates/active_admin.js +10 -0
- data/lib/generators/active_admin/install/templates/active_admin.rb +47 -0
- data/lib/generators/active_admin/install/templates/active_admin_vendor.js +382 -0
- data/lib/generators/active_admin/install/templates/dashboards.rb +36 -0
- data/lib/generators/active_admin/install/templates/images/orderable.gif +0 -0
- data/lib/generators/active_admin/resource/resource_generator.rb +16 -0
- data/lib/generators/active_admin/resource/templates/admin.rb +3 -0
- data/spec/integration/dashboard_spec.rb +44 -0
- data/spec/integration/index_as_blog_spec.rb +65 -0
- data/spec/integration/index_as_csv_spec.rb +40 -0
- data/spec/integration/index_as_table_spec.rb +160 -0
- data/spec/integration/index_as_thumbnails_spec.rb +43 -0
- data/spec/integration/layout_spec.rb +82 -0
- data/spec/integration/new_view_spec.rb +52 -0
- data/spec/integration/show_view_spec.rb +91 -0
- data/spec/spec_helper.rb +104 -0
- data/spec/support/rails_template.rb +19 -0
- data/spec/unit/action_builder_spec.rb +76 -0
- data/spec/unit/action_items_spec.rb +41 -0
- data/spec/unit/active_admin_spec.rb +52 -0
- data/spec/unit/asset_registration_spec.rb +37 -0
- data/spec/unit/controller_filters_spec.rb +26 -0
- data/spec/unit/dashboard_section_spec.rb +63 -0
- data/spec/unit/dashboards_spec.rb +59 -0
- data/spec/unit/filter_form_builder_spec.rb +157 -0
- data/spec/unit/form_builder_spec.rb +238 -0
- data/spec/unit/menu_item_spec.rb +137 -0
- data/spec/unit/menu_spec.rb +53 -0
- data/spec/unit/namespace_spec.rb +107 -0
- data/spec/unit/registration_spec.rb +46 -0
- data/spec/unit/renderer_spec.rb +100 -0
- data/spec/unit/resource_controller_spec.rb +48 -0
- data/spec/unit/resource_spec.rb +197 -0
- data/spec/unit/routing_spec.rb +12 -0
- data/spec/unit/sidebar_spec.rb +96 -0
- data/spec/unit/table_builder_spec.rb +162 -0
- data/spec/unit/tabs_renderer_spec.rb +34 -0
- metadata +247 -0
@@ -0,0 +1,137 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
module ActiveAdmin
|
4
|
+
describe MenuItem do
|
5
|
+
|
6
|
+
it "should have a name" do
|
7
|
+
item = MenuItem.new("Dashboard", "/admin")
|
8
|
+
item.name.should == "Dashboard"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have a url" do
|
12
|
+
item = MenuItem.new("Dashboard", "/admin")
|
13
|
+
item.url.should == "/admin"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have a priority of 10 by default" do
|
17
|
+
item = MenuItem.new("Dashboard", "/admin")
|
18
|
+
item.priority.should == 10
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should accept an optional options hash" do
|
22
|
+
item = MenuItem.new("Dashboard", "/admin", 10, :if => lambda{ logged_in? } )
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have a display if block" do
|
26
|
+
block = lambda{ logged_in? }
|
27
|
+
item = MenuItem.new("Dashboard", "/admin", 10, :if => block )
|
28
|
+
item.display_if_block.should == block
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "url generation and caching" do
|
32
|
+
it "should generate a url if it is a symbol" do
|
33
|
+
MenuItem.new("Posts", :admin_posts_path).url.should == "/admin/posts"
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should generate a url if it is a string" do
|
37
|
+
MenuItem.new("Posts", "/admin/posts").url.should == "/admin/posts"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "with no children" do
|
42
|
+
it "should be empty" do
|
43
|
+
item = MenuItem.new("Blog", "/admin/blog")
|
44
|
+
item.children.should == []
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should accept new children" do
|
48
|
+
item = MenuItem.new("Blog", "/admin/blog")
|
49
|
+
item.add "Dashboard", "/admin"
|
50
|
+
item.children.first.should be_an_instance_of(MenuItem)
|
51
|
+
item.children.first.name.should == "Dashboard"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with many children" do
|
56
|
+
let(:item) do
|
57
|
+
i = MenuItem.new("Dashboard", "/admin")
|
58
|
+
i.add "Blog", "/"
|
59
|
+
i.add "Cars", "/"
|
60
|
+
i.add "Users", "/", 1
|
61
|
+
i.add "Settings", "/", 2
|
62
|
+
i.add "Analytics", "/", 44
|
63
|
+
i
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should give access to the menu item as an array" do
|
67
|
+
item['Blog'].name.should == 'Blog'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should sort items based on priority and name" do
|
71
|
+
item.children[0].name.should == 'Users'
|
72
|
+
item.children[1].name.should == 'Settings'
|
73
|
+
item.children[2].name.should == 'Blog'
|
74
|
+
item.children[3].name.should == 'Cars'
|
75
|
+
item.children[4].name.should == 'Analytics'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "children should hold a reference to their parent" do
|
79
|
+
item["Blog"].parent.should == item
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "building children using block syntax" do
|
84
|
+
let(:item) do
|
85
|
+
MenuItem.new("Blog", "/") do |blog|
|
86
|
+
blog.add "Create New", "/blog/new"
|
87
|
+
blog.add("Comments", "/blog/comments") do |comments|
|
88
|
+
comments.add "Approved", "/blog/comments?status=approved"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should have 2 children" do
|
94
|
+
item.children.size.should == 2
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should have sub-sub items" do
|
98
|
+
item["Comments"]["Approved"].name.should == 'Approved'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "accessing ancestory" do
|
103
|
+
let(:item){ MenuItem.new "Blog", "/blog" }
|
104
|
+
|
105
|
+
context "with no parent" do
|
106
|
+
it "should return an empty array" do
|
107
|
+
item.ancestors.should == []
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
context "with one parent" do
|
112
|
+
let(:sub_item) do
|
113
|
+
item.add "Create New", "/blog/new"
|
114
|
+
item["Create New"]
|
115
|
+
end
|
116
|
+
it "should return an array with the parent" do
|
117
|
+
sub_item.ancestors.should == [item]
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context "with many parents" do
|
122
|
+
before(:each) do
|
123
|
+
item.add "C1", "/c1" do |c1|
|
124
|
+
c1.add "C2", "/c2" do |c2|
|
125
|
+
c2.add "C3", "/c3"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
let(:sub_item){ item["C1"]["C2"]["C3"] }
|
130
|
+
it "should return an array with the parents in reverse order" do
|
131
|
+
sub_item.ancestors.should == [item["C1"]["C2"], item["C1"], item]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end # accessing ancestory
|
135
|
+
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe ActiveAdmin::Menu do
|
4
|
+
|
5
|
+
context "with no items" do
|
6
|
+
it "should be empty" do
|
7
|
+
ActiveAdmin::Menu.new.items.should == []
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should accept new items" do
|
11
|
+
menu = ActiveAdmin::Menu.new
|
12
|
+
menu.add "Dashboard", "/admin"
|
13
|
+
menu.items.first.should be_an_instance_of(ActiveAdmin::MenuItem)
|
14
|
+
menu.items.first.name.should == "Dashboard"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should default new items to the priority of 10" do
|
18
|
+
menu = ActiveAdmin::Menu.new
|
19
|
+
menu.add "Dashboard", "/admin"
|
20
|
+
menu.items.first.priority.should == 10
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "with many item" do
|
25
|
+
let(:menu) do
|
26
|
+
ActiveAdmin::Menu.new do |m|
|
27
|
+
m.add "Dashboard", "/admin"
|
28
|
+
m.add "Blog", "/admin/blog"
|
29
|
+
m.add "Users", "/admin/users"
|
30
|
+
m.add "Settings", "/admin/settings" do |s|
|
31
|
+
s.add "Admin Settings", "/admin/settings/admin" do |as|
|
32
|
+
s.add "User Settings", "/admin/settings/users"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should give access to the menu item as an array" do
|
39
|
+
menu['Dashboard'].name.should == 'Dashboard'
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should find the item by a url on the top level" do
|
43
|
+
menu.find_by_url("/admin").name.should == "Dashboard"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should find the item deep in the tree" do
|
47
|
+
menu.find_by_url("/admin/settings/users").name.should == "User Settings"
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe ActiveAdmin::Namespace do
|
4
|
+
|
5
|
+
context "when new" do
|
6
|
+
let(:namespace){ ActiveAdmin::Namespace.new(:admin) }
|
7
|
+
|
8
|
+
it "should have a name" do
|
9
|
+
namespace.name.should == :admin
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have no resources" do
|
13
|
+
namespace.resources.should == {}
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have an empty menu" do
|
17
|
+
namespace.menu.items.should be_empty
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "registering a resource" do
|
22
|
+
|
23
|
+
let(:namespace){ ActiveAdmin::Namespace.new(:admin) }
|
24
|
+
|
25
|
+
context "with no configuration" do
|
26
|
+
before do
|
27
|
+
namespace.register Category
|
28
|
+
end
|
29
|
+
it "should store the namespaced registered configuration" do
|
30
|
+
namespace.resources.keys.should include('Category')
|
31
|
+
end
|
32
|
+
it "should create a new controller in the default namespace" do
|
33
|
+
defined?(Admin::CategoriesController).should be_true
|
34
|
+
end
|
35
|
+
it "should create the dashboard controller" do
|
36
|
+
defined?(Admin::DashboardController).should be_true
|
37
|
+
end
|
38
|
+
it "should create a menu item" do
|
39
|
+
namespace.menu["Categories"].should be_an_instance_of(ActiveAdmin::MenuItem)
|
40
|
+
namespace.menu["Categories"].url.should == "/admin/categories"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "with a block configuration" do
|
45
|
+
it "should be evaluated in the controller" do
|
46
|
+
lambda {
|
47
|
+
namespace.register Category do
|
48
|
+
raise "Hello World"
|
49
|
+
end
|
50
|
+
}.should raise_error
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with a resource that's namespaced" do
|
55
|
+
before do
|
56
|
+
module ::Mock; class Resource; end; end
|
57
|
+
namespace.register Mock::Resource
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should store the namespaced registered configuration" do
|
61
|
+
namespace.resources.keys.should include('MockResource')
|
62
|
+
end
|
63
|
+
it "should create a new controller in the default namespace" do
|
64
|
+
defined?(Admin::MockResourcesController).should be_true
|
65
|
+
end
|
66
|
+
it "should create a menu item" do
|
67
|
+
namespace.menu["Mock Resources"].should be_an_instance_of(ActiveAdmin::MenuItem)
|
68
|
+
end
|
69
|
+
it "should use the resource as the model in the controller" do
|
70
|
+
Admin::MockResourcesController.resource_class.should == Mock::Resource
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "adding to the menu" do
|
75
|
+
|
76
|
+
describe "adding as a top level item" do
|
77
|
+
before do
|
78
|
+
namespace.register Category
|
79
|
+
end
|
80
|
+
it "should add a new menu item" do
|
81
|
+
namespace.menu['Categories'].should_not be_nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "adding as a child" do
|
86
|
+
before do
|
87
|
+
namespace.register Category do
|
88
|
+
menu :parent => 'Blog'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
it "should generate the parent menu item" do
|
92
|
+
namespace.menu['Blog'].should_not be_nil
|
93
|
+
end
|
94
|
+
it "should generate its own child item" do
|
95
|
+
namespace.menu['Blog']['Categories'].should_not be_nil
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "disabling the menu" do
|
100
|
+
# TODO
|
101
|
+
it "should not create a menu item"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Registering an object to administer" do
|
4
|
+
|
5
|
+
context "with no configuration" do
|
6
|
+
it "should call register on the namespace" do
|
7
|
+
namespace = ActiveAdmin::Namespace.new(:admin)
|
8
|
+
ActiveAdmin.namespaces[namespace.name] = namespace
|
9
|
+
namespace.should_receive(:register)
|
10
|
+
|
11
|
+
ActiveAdmin.register Category
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "with a different namespace" do
|
16
|
+
it "should call register on the namespace" do
|
17
|
+
namespace = ActiveAdmin::Namespace.new(:hello_world)
|
18
|
+
ActiveAdmin.namespaces[namespace.name] = namespace
|
19
|
+
namespace.should_receive(:register)
|
20
|
+
|
21
|
+
ActiveAdmin.register Category, :namespace => :hello_world
|
22
|
+
end
|
23
|
+
it "should generate a path to the dashboard" do
|
24
|
+
ActiveAdmin.register Category, :namespace => :hello_world
|
25
|
+
reload_routes!
|
26
|
+
Rails.application.routes.url_helpers.methods.should include("hello_world_dashboard_path")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with no namespace" do
|
31
|
+
it "should call register on the root namespace" do
|
32
|
+
namespace = ActiveAdmin::Namespace.new(:root)
|
33
|
+
ActiveAdmin.namespaces[namespace.name] = namespace
|
34
|
+
namespace.should_receive(:register)
|
35
|
+
|
36
|
+
ActiveAdmin.register Category, :namespace => false
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should generate a path to the dashboard" do
|
40
|
+
ActiveAdmin.register Category, :namespace => false
|
41
|
+
reload_routes!
|
42
|
+
Rails.application.routes.url_helpers.methods.should include("dashboard_path")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
include ActiveAdmin
|
4
|
+
|
5
|
+
describe ActiveAdmin::Renderer do
|
6
|
+
|
7
|
+
context "when initiailizing from a view" do
|
8
|
+
it "should have a view" do
|
9
|
+
view = action_view
|
10
|
+
renderer = Renderer.new(view)
|
11
|
+
renderer.view.should == view
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should assign all local variables from the view" do
|
15
|
+
Renderer.new(action_view(:foo => "bar")).send(:instance_variable_get, "@foo").should == "bar"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should assing an instance variable to the view" do
|
19
|
+
view = action_view
|
20
|
+
renderer = Renderer.new(view)
|
21
|
+
renderer.send :set_ivar_on_view, "@my_ivar", 'Hello World'
|
22
|
+
view.instance_variable_get("@my_ivar").should == 'Hello World'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "when initializing from another renderer" do
|
27
|
+
it "should have the view" do
|
28
|
+
view = action_view
|
29
|
+
renderer = Renderer.new(Renderer.new(view))
|
30
|
+
renderer.view.should == view
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should assign local variables from the renderer" do
|
34
|
+
view = action_view(:foo => 'bar')
|
35
|
+
renderer = Renderer.new(Renderer.new(view))
|
36
|
+
renderer.send(:instance_variable_get, "@foo").should == 'bar'
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should assing an instance variable to the view" do
|
40
|
+
view = action_view
|
41
|
+
renderer = Renderer.new(Renderer.new(view))
|
42
|
+
renderer.send :set_ivar_on_view, "@my_ivar", 'Hello World'
|
43
|
+
view.instance_variable_get("@my_ivar").should == 'Hello World'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "rendering HAML" do
|
48
|
+
before do
|
49
|
+
@haml_renderer = Class.new(Renderer)
|
50
|
+
@haml_renderer.class_eval do
|
51
|
+
def hello_world
|
52
|
+
"Hello World"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
it "should render haml within the context of the renderer" do
|
57
|
+
@haml_renderer.class_eval do
|
58
|
+
def to_html
|
59
|
+
haml <<-HAML
|
60
|
+
%p
|
61
|
+
=hello_world
|
62
|
+
HAML
|
63
|
+
end
|
64
|
+
end
|
65
|
+
@renderer = @haml_renderer.new(action_view)
|
66
|
+
@renderer.to_html.should == "<p>\n Hello World\n</p>\n"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should allow for indentation at the start of the template" do
|
70
|
+
@haml_renderer.class_eval do
|
71
|
+
def to_html
|
72
|
+
haml <<-HAML
|
73
|
+
%p
|
74
|
+
=hello_world
|
75
|
+
HAML
|
76
|
+
end
|
77
|
+
end
|
78
|
+
@renderer = @haml_renderer.new(action_view)
|
79
|
+
@renderer.to_html.should == "<p>\n Hello World\n</p>\n"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#call_method_or_proc_on" do
|
84
|
+
let(:renderer){ Renderer.new(action_view) }
|
85
|
+
let(:obj){ "Hello World" }
|
86
|
+
it "should return nil if no symbol or proc given" do
|
87
|
+
renderer.send(:call_method_or_proc_on, obj, 1).should == nil
|
88
|
+
end
|
89
|
+
it "should call the method if a symbol is given" do
|
90
|
+
renderer.send(:call_method_or_proc_on, obj, :size).should == obj.size
|
91
|
+
end
|
92
|
+
it "should call the method if a string is given" do
|
93
|
+
renderer.send(:call_method_or_proc_on, obj, "size").should == obj.size
|
94
|
+
end
|
95
|
+
it "should call the proc with the object if a proc is given" do
|
96
|
+
p = Proc.new{|string| string.size }
|
97
|
+
renderer.send(:call_method_or_proc_on, obj, p).should == obj.size
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe ActiveAdmin::ResourceController do
|
4
|
+
|
5
|
+
[:index, :show].each do |page|
|
6
|
+
describe "#{page} config" do
|
7
|
+
before do
|
8
|
+
Admin::PostsController.send(:"reset_#{page}_config!")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be set" do
|
12
|
+
Admin::PostsController.send(page)
|
13
|
+
Admin::PostsController.send(:"#{page}_config").should be_an_instance_of(ActiveAdmin::PageConfig)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should store the block" do
|
17
|
+
block = Proc.new {}
|
18
|
+
Admin::PostsController.send(:"#{page}", &block)
|
19
|
+
Admin::PostsController.send(:"#{page}_config").block.should == block
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should be reset" do
|
23
|
+
Admin::PostsController.send(:"reset_#{page}_config!")
|
24
|
+
Admin::PostsController.send(:"#{page}_config").should == nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "setting the current tab" do
|
30
|
+
let(:controller) { ActiveAdmin::ResourceController.new }
|
31
|
+
before do
|
32
|
+
controller.stub!(:active_admin_config => resource)
|
33
|
+
controller.send :set_current_tab # Run the before filter
|
34
|
+
end
|
35
|
+
subject{ controller.instance_variable_get(:@current_tab) }
|
36
|
+
|
37
|
+
context "when menu item name is 'Resources' without a parent menu item" do
|
38
|
+
let(:resource){ mock(:menu_item_name => "Resources", :parent_menu_item_name => nil) }
|
39
|
+
it { should == "Resources" }
|
40
|
+
end
|
41
|
+
|
42
|
+
context "when there is a parent menu item of 'Admin'" do
|
43
|
+
let(:resource){ mock(:parent_menu_item_name => "Admin") }
|
44
|
+
it { should == "Admin" }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|