activeadmin 0.1.1 → 0.2.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/CHANGELOG.rdoc +15 -1
- data/Gemfile +41 -11
- data/LICENSE +5 -0
- data/README.rdoc +202 -87
- data/Rakefile +51 -15
- data/activeadmin.gemspec +310 -131
- data/cucumber.yml +1 -0
- data/features/comments/commenting.feature +81 -0
- data/features/comments/viewing_index.feature +19 -0
- data/features/edit_page.feature +77 -0
- data/features/first_boot.feature +16 -0
- data/features/global_navigation.feature +30 -0
- data/features/index/formats.feature +10 -0
- data/features/index/index_as_block.feature +15 -0
- data/features/index/index_as_blog.feature +50 -0
- data/features/index/index_as_grid.feature +45 -0
- data/features/index/index_as_table.feature +79 -0
- data/features/index/index_scopes.feature +52 -0
- data/features/index/pagination.feature +23 -0
- data/features/new_page.feature +75 -0
- data/features/registering_assets.feature +35 -0
- data/features/registering_resources.feature +33 -0
- data/features/show/default_content.feature +43 -0
- data/features/show/page_title.feature +33 -0
- data/features/sidebar_sections.feature +128 -0
- data/features/specifying_actions.feature +16 -0
- data/features/step_definitions/action_item_steps.rb +7 -0
- data/features/step_definitions/additional_web_steps.rb +67 -0
- data/features/step_definitions/asset_steps.rb +7 -0
- data/features/step_definitions/attribute_steps.rb +15 -0
- data/features/step_definitions/comment_steps.rb +8 -0
- data/features/step_definitions/configuration_steps.rb +31 -0
- data/features/step_definitions/factory_steps.rb +28 -0
- data/features/step_definitions/flash_steps.rb +3 -0
- data/features/step_definitions/format_steps.rb +7 -0
- data/features/step_definitions/index_scope_steps.rb +20 -0
- data/features/step_definitions/pagination_steps.rb +8 -0
- data/features/step_definitions/sidebar_steps.rb +11 -0
- data/features/step_definitions/tab_steps.rb +3 -0
- data/features/step_definitions/user_steps.rb +20 -0
- data/features/step_definitions/web_steps.rb +219 -0
- data/features/support/env.rb +88 -0
- data/features/support/paths.rb +48 -0
- data/features/users/logging_in.feature +34 -0
- data/features/users/logging_out.feature +13 -0
- data/lib/active_admin.rb +155 -79
- data/lib/active_admin/abstract_view_factory.rb +95 -0
- data/lib/active_admin/action_items.rb +4 -15
- data/lib/active_admin/arbre.rb +23 -0
- data/lib/active_admin/arbre/attributes.rb +20 -0
- data/lib/active_admin/arbre/class_list.rb +28 -0
- data/lib/active_admin/arbre/collection.rb +27 -0
- data/lib/active_admin/arbre/context.rb +8 -0
- data/lib/active_admin/arbre/core_extensions.rb +5 -0
- data/lib/active_admin/arbre/document.rb +42 -0
- data/lib/active_admin/arbre/element.rb +151 -0
- data/lib/active_admin/arbre/html.rb +84 -0
- data/lib/active_admin/arbre/html5_elements.rb +47 -0
- data/lib/active_admin/arbre/tag.rb +129 -0
- data/lib/active_admin/arbre/text_node.rb +35 -0
- data/lib/active_admin/callbacks.rb +87 -0
- data/lib/active_admin/comments.rb +73 -0
- data/lib/active_admin/comments/comment.rb +15 -0
- data/lib/active_admin/comments/configuration.rb +16 -0
- data/lib/active_admin/comments/namespace_helper.rb +14 -0
- data/lib/active_admin/comments/resource_helper.rb +17 -0
- data/lib/active_admin/comments/show_page_helper.rb +23 -0
- data/lib/active_admin/comments/views.rb +3 -0
- data/lib/active_admin/comments/views/active_admin_comment.rb +0 -0
- data/lib/active_admin/comments/views/active_admin_comments.rb +82 -0
- data/lib/active_admin/component.rb +22 -0
- data/lib/active_admin/controller_action.rb +12 -0
- data/lib/active_admin/dashboards.rb +0 -2
- data/lib/active_admin/dashboards/dashboard_controller.rb +10 -5
- data/lib/active_admin/dashboards/section.rb +5 -14
- data/lib/active_admin/devise.rb +43 -0
- data/lib/active_admin/dsl.rb +202 -0
- data/lib/active_admin/event.rb +31 -0
- data/lib/active_admin/form_builder.rb +68 -50
- data/lib/active_admin/iconic.rb +51 -0
- data/lib/active_admin/iconic/icons.rb +142 -0
- data/lib/active_admin/namespace.rb +102 -16
- data/lib/active_admin/renderer.rb +18 -3
- data/lib/active_admin/resource.rb +110 -9
- data/lib/active_admin/resource/belongs_to.rb +31 -0
- data/lib/active_admin/resource_controller.rb +45 -260
- data/lib/active_admin/resource_controller/action_builder.rb +21 -0
- data/lib/active_admin/resource_controller/actions.rb +53 -0
- data/lib/active_admin/resource_controller/callbacks.rb +47 -0
- data/lib/active_admin/resource_controller/collection.rb +142 -0
- data/lib/active_admin/resource_controller/filters.rb +58 -0
- data/lib/active_admin/resource_controller/form.rb +42 -0
- data/lib/active_admin/resource_controller/menu.rb +29 -0
- data/lib/active_admin/resource_controller/page_configurations.rb +53 -0
- data/lib/active_admin/resource_controller/scoping.rb +36 -0
- data/lib/active_admin/resource_controller/sidebars.rb +38 -0
- data/lib/active_admin/scope.rb +17 -0
- data/lib/active_admin/sidebar.rb +8 -47
- data/lib/active_admin/stylesheets/active_admin.scss +418 -0
- data/lib/active_admin/stylesheets/active_admin/_comments.scss +40 -0
- data/lib/active_admin/stylesheets/active_admin/_flash_messages.scss +13 -0
- data/lib/active_admin/stylesheets/active_admin/_forms.scss +168 -0
- data/lib/active_admin/stylesheets/active_admin/_header.scss +108 -0
- data/lib/active_admin/stylesheets/active_admin/_typography.scss +100 -0
- data/lib/active_admin/stylesheets/active_admin/mixins/_all.scss +8 -0
- data/lib/active_admin/stylesheets/active_admin/mixins/_buttons.scss +27 -0
- data/lib/active_admin/stylesheets/active_admin/mixins/_gradients.scss +21 -0
- data/lib/active_admin/stylesheets/active_admin/mixins/_icons.scss +20 -0
- data/lib/active_admin/stylesheets/active_admin/mixins/_reset.scss +165 -0
- data/lib/active_admin/stylesheets/active_admin/mixins/_rounded.scss +43 -0
- data/lib/active_admin/stylesheets/active_admin/mixins/_sections.scss +27 -0
- data/lib/active_admin/stylesheets/active_admin/mixins/_shadows.scss +21 -0
- data/lib/active_admin/stylesheets/active_admin/mixins/_variables.scss +12 -0
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_factory.rb +21 -0
- data/lib/active_admin/view_helpers.rb +17 -100
- data/lib/active_admin/view_helpers/assigns_with_indifferent_access_helper.rb +7 -0
- data/lib/active_admin/view_helpers/auto_link_helper.rb +41 -0
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +29 -0
- data/lib/active_admin/view_helpers/display_helper.rb +38 -0
- data/lib/active_admin/view_helpers/filter_form_helper.rb +174 -0
- data/lib/active_admin/view_helpers/form_helper.rb +12 -0
- data/lib/active_admin/view_helpers/icon_helper.rb +12 -0
- data/lib/active_admin/view_helpers/method_or_proc_helper.rb +26 -0
- data/lib/active_admin/view_helpers/renderer_helper.rb +29 -0
- data/lib/active_admin/view_helpers/sidebar_helper.rb +15 -0
- data/lib/active_admin/view_helpers/status_tag_helper.rb +13 -0
- data/lib/active_admin/view_helpers/table_helper.rb +12 -0
- data/lib/active_admin/view_helpers/title_helper.rb +11 -0
- data/lib/active_admin/view_helpers/view_factory_helper.rb +11 -0
- data/lib/active_admin/views.rb +8 -0
- data/lib/active_admin/views/action_items.rb +17 -0
- data/lib/active_admin/views/components/attributes_table.rb +66 -0
- data/lib/active_admin/views/components/columns.rb +49 -0
- data/lib/active_admin/views/components/paginated_collection.rb +74 -0
- data/lib/active_admin/views/components/panel.rb +26 -0
- data/lib/active_admin/views/components/scopes.rb +64 -0
- data/lib/active_admin/views/components/sidebar_section.rb +30 -0
- data/lib/active_admin/views/components/table_for.rb +174 -0
- data/lib/active_admin/views/dashboard_section_renderer.rb +19 -0
- data/lib/active_admin/views/header_renderer.rb +37 -0
- data/lib/active_admin/views/index_as_block.rb +24 -0
- data/lib/active_admin/views/index_as_blog.rb +89 -0
- data/lib/active_admin/views/index_as_grid.rb +49 -0
- data/lib/active_admin/views/index_as_table.rb +73 -0
- data/lib/active_admin/views/pages/base.rb +138 -0
- data/lib/active_admin/views/pages/dashboard.rb +61 -0
- data/lib/active_admin/views/pages/edit.rb +27 -0
- data/lib/active_admin/views/pages/index.rb +64 -0
- data/lib/active_admin/views/pages/new.rb +27 -0
- data/lib/active_admin/views/pages/show.rb +56 -0
- data/lib/active_admin/views/tabs_renderer.rb +52 -0
- data/lib/active_admin/views/templates/active_admin/devise/mailer/reset_password_instructions.html.erb +8 -0
- data/lib/active_admin/views/templates/active_admin/devise/mailer/unlock_instructions.html.erb +7 -0
- data/lib/active_admin/views/templates/active_admin/devise/passwords/edit.html.erb +16 -0
- data/lib/active_admin/views/templates/active_admin/devise/passwords/new.html.erb +14 -0
- data/lib/active_admin/views/templates/active_admin/devise/sessions/new.html.erb +18 -0
- data/lib/active_admin/views/templates/active_admin/devise/shared/_links.erb +20 -0
- data/lib/active_admin/views/templates/active_admin/devise/unlocks/new.html.erb +12 -0
- data/lib/active_admin/views/templates/active_admin_dashboard/index.html.arb +1 -0
- data/lib/active_admin/views/templates/active_admin_default/edit.html.arb +1 -0
- data/lib/active_admin/views/{active_admin_default → templates/active_admin_default}/index.csv.erb +0 -0
- data/lib/active_admin/views/templates/active_admin_default/index.html.arb +1 -0
- data/lib/active_admin/views/templates/active_admin_default/new.html.arb +1 -0
- data/lib/active_admin/views/templates/active_admin_default/show.html.arb +1 -0
- data/lib/active_admin/views/{layouts → templates/layouts}/active_admin.html.erb +3 -4
- data/lib/active_admin/views/templates/layouts/active_admin_logged_out.html.erb +31 -0
- data/lib/generators/active_admin/devise/devise_generator.rb +45 -0
- data/lib/generators/active_admin/install/install_generator.rb +18 -3
- data/lib/generators/active_admin/install/templates/active_admin.js +41 -0
- data/lib/generators/active_admin/install/templates/{active_admin.rb → active_admin.rb.erb} +33 -3
- data/lib/generators/active_admin/install/templates/active_admin_vendor.js +1 -1
- data/lib/generators/active_admin/install/templates/dashboards.rb +3 -4
- data/lib/generators/active_admin/install/templates/images/admin_notes_icon.png +0 -0
- data/lib/generators/active_admin/install/templates/images/loading.gif +0 -0
- data/lib/generators/active_admin/install/templates/images/nested_menu_arrow.gif +0 -0
- data/lib/generators/active_admin/install/templates/images/nested_menu_arrow_dark.gif +0 -0
- data/lib/generators/active_admin/install/templates/images/orderable.png +0 -0
- data/lib/generators/active_admin/install/templates/migrations/1_create_admin_notes.rb +16 -0
- data/lib/generators/active_admin/install/templates/migrations/2_move_admin_notes_to_comments.rb +25 -0
- data/spec/integration/belongs_to_spec.rb +42 -0
- data/spec/integration/index_as_table_spec.rb +0 -119
- data/spec/integration/layout_spec.rb +3 -37
- data/spec/spec_helper.rb +89 -50
- data/spec/support/integration_example_group.rb +37 -0
- data/spec/support/rails_template.rb +21 -9
- data/spec/support/rails_template_with_data.rb +32 -0
- data/spec/support/templates/cucumber.rb +28 -0
- data/spec/unit/abstract_view_factory_spec.rb +79 -0
- data/spec/unit/action_builder_spec.rb +19 -7
- data/spec/unit/action_items_spec.rb +16 -30
- data/spec/unit/active_admin_spec.rb +10 -22
- data/spec/unit/arbre/html/element_finder_methods_spec.rb +54 -0
- data/spec/unit/arbre/html/element_spec.rb +224 -0
- data/spec/unit/arbre/html/tag_attributes_spec.rb +61 -0
- data/spec/unit/arbre/html/tag_spec.rb +63 -0
- data/spec/unit/arbre/html_spec.rb +185 -0
- data/spec/unit/auto_link_spec.rb +38 -0
- data/spec/unit/belongs_to_spec.rb +44 -0
- data/spec/unit/breadcrumbs_spec.rb +110 -0
- data/spec/unit/comments_spec.rb +53 -0
- data/spec/unit/component_spec.rb +18 -0
- data/spec/unit/components/attributes_table_spec.rb +100 -0
- data/spec/unit/components/columns_spec.rb +75 -0
- data/spec/unit/components/panel_spec.rb +31 -0
- data/spec/unit/components/sidebar_section_spec.rb +37 -0
- data/spec/unit/components/table_for_spec.rb +130 -0
- data/spec/unit/dashboard_controller_spec.rb +26 -0
- data/spec/unit/dashboard_section_spec.rb +10 -17
- data/spec/unit/display_name_spec.rb +29 -0
- data/spec/unit/event_spec.rb +41 -0
- data/spec/unit/filter_form_builder_spec.rb +99 -77
- data/spec/unit/form_builder_spec.rb +69 -69
- data/spec/unit/namespace_spec.rb +61 -3
- data/spec/unit/pretty_format_spec.rb +35 -0
- data/spec/unit/registration_spec.rb +40 -1
- data/spec/unit/renderer_spec.rb +8 -0
- data/spec/unit/resource_controller_spec.rb +105 -6
- data/spec/unit/resource_spec.rb +78 -11
- data/spec/unit/routing_spec.rb +82 -6
- data/spec/unit/scope_spec.rb +31 -0
- data/spec/unit/tabs_renderer_spec.rb +24 -2
- data/spec/unit/view_factory_spec.rb +16 -0
- metadata +268 -82
- data/.gitignore +0 -25
- data/active_admin.gemspec +0 -22
- data/lib/active_admin/action_builder.rb +0 -60
- data/lib/active_admin/breadcrumbs.rb +0 -26
- data/lib/active_admin/dashboards/renderer.rb +0 -45
- data/lib/active_admin/dashboards/section_renderer.rb +0 -28
- data/lib/active_admin/filters.rb +0 -189
- data/lib/active_admin/pages.rb +0 -11
- data/lib/active_admin/pages/base.rb +0 -92
- data/lib/active_admin/pages/edit.rb +0 -21
- data/lib/active_admin/pages/index.rb +0 -58
- data/lib/active_admin/pages/index/blog.rb +0 -65
- data/lib/active_admin/pages/index/table.rb +0 -48
- data/lib/active_admin/pages/index/thumbnails.rb +0 -40
- data/lib/active_admin/pages/new.rb +0 -21
- data/lib/active_admin/pages/show.rb +0 -54
- data/lib/active_admin/table_builder.rb +0 -162
- data/lib/active_admin/tabs_renderer.rb +0 -39
- data/lib/active_admin/views/active_admin_dashboard/index.html.erb +0 -1
- data/lib/active_admin/views/active_admin_default/edit.html.erb +0 -1
- data/lib/active_admin/views/active_admin_default/index.html.erb +0 -1
- data/lib/active_admin/views/active_admin_default/new.html.erb +0 -1
- data/lib/active_admin/views/active_admin_default/show.html.erb +0 -1
- data/lib/generators/active_admin/install/templates/active_admin.css +0 -325
- data/lib/generators/active_admin/install/templates/images/orderable.gif +0 -0
- data/spec/integration/index_as_blog_spec.rb +0 -65
- data/spec/integration/index_as_thumbnails_spec.rb +0 -43
- data/spec/integration/new_view_spec.rb +0 -52
- data/spec/integration/show_view_spec.rb +0 -91
- data/spec/unit/sidebar_spec.rb +0 -96
- data/spec/unit/table_builder_spec.rb +0 -162
data/spec/unit/namespace_spec.rb
CHANGED
@@ -36,13 +36,14 @@ describe ActiveAdmin::Namespace do
|
|
36
36
|
defined?(Admin::DashboardController).should be_true
|
37
37
|
end
|
38
38
|
it "should create a menu item" do
|
39
|
+
namespace.load_menu!
|
39
40
|
namespace.menu["Categories"].should be_an_instance_of(ActiveAdmin::MenuItem)
|
40
41
|
namespace.menu["Categories"].url.should == "/admin/categories"
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
44
45
|
context "with a block configuration" do
|
45
|
-
it "should be evaluated in the
|
46
|
+
it "should be evaluated in the dsl" do
|
46
47
|
lambda {
|
47
48
|
namespace.register Category do
|
48
49
|
raise "Hello World"
|
@@ -53,7 +54,7 @@ describe ActiveAdmin::Namespace do
|
|
53
54
|
|
54
55
|
context "with a resource that's namespaced" do
|
55
56
|
before do
|
56
|
-
module ::Mock; class Resource; end; end
|
57
|
+
module ::Mock; class Resource; def self.has_many(arg1, arg2); end; end; end
|
57
58
|
namespace.register Mock::Resource
|
58
59
|
end
|
59
60
|
|
@@ -64,6 +65,7 @@ describe ActiveAdmin::Namespace do
|
|
64
65
|
defined?(Admin::MockResourcesController).should be_true
|
65
66
|
end
|
66
67
|
it "should create a menu item" do
|
68
|
+
namespace.load_menu!
|
67
69
|
namespace.menu["Mock Resources"].should be_an_instance_of(ActiveAdmin::MenuItem)
|
68
70
|
end
|
69
71
|
it "should use the resource as the model in the controller" do
|
@@ -71,11 +73,29 @@ describe ActiveAdmin::Namespace do
|
|
71
73
|
end
|
72
74
|
end
|
73
75
|
|
76
|
+
describe "finding resource instances" do
|
77
|
+
let(:namespace){ ActiveAdmin::Namespace.new(:admin) }
|
78
|
+
context "when registered" do
|
79
|
+
before do
|
80
|
+
@post_resource = namespace.register Post
|
81
|
+
end
|
82
|
+
it "should return the resource instance" do
|
83
|
+
namespace.resource_for(Post).should == @post_resource
|
84
|
+
end
|
85
|
+
end
|
86
|
+
context "when not registered" do
|
87
|
+
it "should be nil" do
|
88
|
+
namespace.resource_for(Post).should == nil
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
74
93
|
describe "adding to the menu" do
|
75
94
|
|
76
95
|
describe "adding as a top level item" do
|
77
96
|
before do
|
78
97
|
namespace.register Category
|
98
|
+
namespace.load_menu!
|
79
99
|
end
|
80
100
|
it "should add a new menu item" do
|
81
101
|
namespace.menu['Categories'].should_not be_nil
|
@@ -87,6 +107,7 @@ describe ActiveAdmin::Namespace do
|
|
87
107
|
namespace.register Category do
|
88
108
|
menu :parent => 'Blog'
|
89
109
|
end
|
110
|
+
namespace.load_menu!
|
90
111
|
end
|
91
112
|
it "should generate the parent menu item" do
|
92
113
|
namespace.menu['Blog'].should_not be_nil
|
@@ -100,8 +121,45 @@ describe ActiveAdmin::Namespace do
|
|
100
121
|
# TODO
|
101
122
|
it "should not create a menu item"
|
102
123
|
end
|
124
|
+
|
125
|
+
describe "adding as a belongs to" do
|
126
|
+
context "when not optional" do
|
127
|
+
before do
|
128
|
+
namespace.register Post do
|
129
|
+
belongs_to :author
|
130
|
+
end
|
131
|
+
end
|
132
|
+
it "should not show up in the menu" do
|
133
|
+
namespace.menu["Posts"].should be_nil
|
134
|
+
end
|
135
|
+
end
|
136
|
+
context "when optional" do
|
137
|
+
before do
|
138
|
+
namespace.register Post do
|
139
|
+
belongs_to :author, :optional => true
|
140
|
+
end
|
141
|
+
end
|
142
|
+
it "should show up in the menu" do
|
143
|
+
namespace.menu["Posts"].should_not be_nil
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
103
147
|
end
|
104
148
|
|
105
|
-
|
149
|
+
describe "dashboard controller name" do
|
150
|
+
context "when namespaced" do
|
151
|
+
it "should be namespaced" do
|
152
|
+
namespace = ActiveAdmin::Namespace.new(:admin)
|
153
|
+
namespace.dashboard_controller_name.should == "Admin::DashboardController"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
context "when not namespaced" do
|
157
|
+
it "should not be namespaced" do
|
158
|
+
namespace = ActiveAdmin::Namespace.new(:root)
|
159
|
+
namespace.dashboard_controller_name.should == "DashboardController"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
106
163
|
|
164
|
+
end
|
107
165
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "#pretty_format" do
|
4
|
+
include ActiveAdmin::ViewHelpers::DisplayHelper
|
5
|
+
|
6
|
+
context "when a String is passed in" do
|
7
|
+
it "should return the String passed in" do
|
8
|
+
pretty_format("hello").should == "hello"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "when a Date or a Time is passed in" do
|
13
|
+
it "should return a localized Date or Time with long format" do
|
14
|
+
t = Time.now
|
15
|
+
self.should_receive(:localize).with(t, {:format => :long}) { "Just Now!" }
|
16
|
+
pretty_format(t).should == "Just Now!"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "when an ActiveRecord object is passed in" do
|
21
|
+
it "should delegate to auto_link" do
|
22
|
+
post = Post.new
|
23
|
+
self.should_receive(:auto_link).with(post) { "model name" }
|
24
|
+
pretty_format(post).should == "model name"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when something else is passed in" do
|
29
|
+
it "should delegate to display_name" do
|
30
|
+
something = Class.new.new
|
31
|
+
self.should_receive(:display_name).with(something) { "I'm not famous" }
|
32
|
+
pretty_format(something).should == "I'm not famous"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -3,13 +3,18 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
3
3
|
describe "Registering an object to administer" do
|
4
4
|
|
5
5
|
context "with no configuration" do
|
6
|
+
let(:namespace) { ActiveAdmin::Namespace.new(:admin) }
|
6
7
|
it "should call register on the namespace" do
|
7
|
-
namespace = ActiveAdmin::Namespace.new(:admin)
|
8
8
|
ActiveAdmin.namespaces[namespace.name] = namespace
|
9
9
|
namespace.should_receive(:register)
|
10
10
|
|
11
11
|
ActiveAdmin.register Category
|
12
12
|
end
|
13
|
+
|
14
|
+
it "should dispatch a Resource::RegisterEvent" do
|
15
|
+
ActiveAdmin::Event.should_receive(:dispatch).with(ActiveAdmin::Resource::RegisterEvent, an_instance_of(ActiveAdmin::Resource))
|
16
|
+
ActiveAdmin.register Category
|
17
|
+
end
|
13
18
|
end
|
14
19
|
|
15
20
|
context "with a different namespace" do
|
@@ -25,6 +30,16 @@ describe "Registering an object to administer" do
|
|
25
30
|
reload_routes!
|
26
31
|
Rails.application.routes.url_helpers.methods.collect(&:to_s).should include("hello_world_dashboard_path")
|
27
32
|
end
|
33
|
+
it "should generate a menu item for the dashboard" do
|
34
|
+
ActiveAdmin.register Category, :namespace => :hello_world
|
35
|
+
ActiveAdmin.namespaces[:hello_world].load_menu!
|
36
|
+
ActiveAdmin.namespaces[:hello_world].menu['Dashboard'].instance_variable_get("@url").should == :hello_world_dashboard_path
|
37
|
+
end
|
38
|
+
it "should generate a Namespace::RegisterEvent and a Resource::RegisterEvent" do
|
39
|
+
ActiveAdmin::Event.should_receive(:dispatch).with(ActiveAdmin::Namespace::RegisterEvent, an_instance_of(ActiveAdmin::Namespace))
|
40
|
+
ActiveAdmin::Event.should_receive(:dispatch).with(ActiveAdmin::Resource::RegisterEvent, an_instance_of(ActiveAdmin::Resource))
|
41
|
+
ActiveAdmin.register Category, :namespace => :not_yet_created
|
42
|
+
end
|
28
43
|
end
|
29
44
|
|
30
45
|
context "with no namespace" do
|
@@ -36,6 +51,12 @@ describe "Registering an object to administer" do
|
|
36
51
|
ActiveAdmin.register Category, :namespace => false
|
37
52
|
end
|
38
53
|
|
54
|
+
it "should generate a menu item for the dashboard" do
|
55
|
+
ActiveAdmin.register Category, :namespace => false
|
56
|
+
ActiveAdmin.namespaces[:root].load_menu!
|
57
|
+
ActiveAdmin.namespaces[:root].menu['Dashboard'].instance_variable_get("@url").should == :dashboard_path
|
58
|
+
end
|
59
|
+
|
39
60
|
it "should generate a path to the dashboard" do
|
40
61
|
ActiveAdmin.register Category, :namespace => false
|
41
62
|
reload_routes!
|
@@ -43,4 +64,22 @@ describe "Registering an object to administer" do
|
|
43
64
|
end
|
44
65
|
end
|
45
66
|
|
67
|
+
context "when being registered multiple times" do
|
68
|
+
it "should run the dsl in the same config object" do
|
69
|
+
config_1 = ActiveAdmin.register(Category) { filter :name }
|
70
|
+
config_2 = ActiveAdmin.register(Category) { filter :id }
|
71
|
+
config_1.should == config_2
|
72
|
+
config_1.controller.filters_config.size.should == 2
|
73
|
+
end
|
74
|
+
|
75
|
+
context "with different resource classes" do
|
76
|
+
it "should raise an ActiveAdmin::ResourceMismatch" do
|
77
|
+
lambda {
|
78
|
+
ActiveAdmin.register Category
|
79
|
+
ActiveAdmin.register Post, :as => "Category"
|
80
|
+
}.should raise_error(ActiveAdmin::ResourceMismatchError)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
46
85
|
end
|
data/spec/unit/renderer_spec.rb
CHANGED
@@ -44,6 +44,14 @@ describe ActiveAdmin::Renderer do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
+
context "when initializing from some other object" do
|
48
|
+
it "should initialize successfully" do
|
49
|
+
lambda {
|
50
|
+
Renderer.new "Hello World"
|
51
|
+
}.should_not raise_exception
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
47
55
|
describe "rendering HAML" do
|
48
56
|
before do
|
49
57
|
@haml_renderer = Class.new(Renderer)
|
@@ -9,13 +9,13 @@ describe ActiveAdmin::ResourceController do
|
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should be set" do
|
12
|
-
Admin::PostsController.send(page)
|
12
|
+
Admin::PostsController.send(:set_page_config, page, {})
|
13
13
|
Admin::PostsController.send(:"#{page}_config").should be_an_instance_of(ActiveAdmin::PageConfig)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "should store the block" do
|
17
17
|
block = Proc.new {}
|
18
|
-
Admin::PostsController.send(:
|
18
|
+
Admin::PostsController.send(:set_page_config, page, {}, &block)
|
19
19
|
Admin::PostsController.send(:"#{page}_config").block.should == block
|
20
20
|
end
|
21
21
|
|
@@ -29,19 +29,118 @@ describe ActiveAdmin::ResourceController do
|
|
29
29
|
describe "setting the current tab" do
|
30
30
|
let(:controller) { ActiveAdmin::ResourceController.new }
|
31
31
|
before do
|
32
|
-
controller.stub!(:active_admin_config => resource)
|
32
|
+
controller.stub!(:active_admin_config => resource, :parent? => true)
|
33
33
|
controller.send :set_current_tab # Run the before filter
|
34
34
|
end
|
35
35
|
subject{ controller.instance_variable_get(:@current_tab) }
|
36
36
|
|
37
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) }
|
38
|
+
let(:resource){ mock(:menu_item_name => "Resources", :parent_menu_item_name => nil, :belongs_to? => false) }
|
39
39
|
it { should == "Resources" }
|
40
40
|
end
|
41
41
|
|
42
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" }
|
43
|
+
let(:resource){ mock(:parent_menu_item_name => "Admin", :menu_item_name => "Resources", :belongs_to? => false) }
|
44
|
+
it { should == "Admin/Resources" }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
ActiveAdmin.register Post do
|
49
|
+
after_build :call_after_build
|
50
|
+
before_save :call_before_save
|
51
|
+
after_save :call_after_save
|
52
|
+
before_create :call_before_create
|
53
|
+
after_create :call_after_create
|
54
|
+
before_update :call_before_update
|
55
|
+
after_update :call_after_update
|
56
|
+
before_destroy :call_before_destroy
|
57
|
+
after_destroy :call_after_destroy
|
58
|
+
end
|
59
|
+
|
60
|
+
class Admin::PostsController < ActiveAdmin::ResourceController
|
61
|
+
def call_after_build(obj); end
|
62
|
+
def call_before_save(obj); end
|
63
|
+
def call_after_save(obj); end
|
64
|
+
def call_before_create(obj); end
|
65
|
+
def call_after_create(obj); end
|
66
|
+
def call_before_update(obj); end
|
67
|
+
def call_after_update(obj); end
|
68
|
+
def call_before_destroy(obj); end
|
69
|
+
def call_after_destroy(obj); end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "callbacks" do
|
73
|
+
describe "performing create" do
|
74
|
+
let(:controller){ Admin::PostsController.new }
|
75
|
+
let(:resource){ mock("Resource", :save => true) }
|
76
|
+
|
77
|
+
before do
|
78
|
+
resource.should_receive(:save)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should call the before create callback" do
|
82
|
+
controller.should_receive(:call_before_create).with(resource)
|
83
|
+
controller.send :create_resource, resource
|
84
|
+
end
|
85
|
+
it "should call the before save callback" do
|
86
|
+
controller.should_receive(:call_before_save).with(resource)
|
87
|
+
controller.send :create_resource, resource
|
88
|
+
end
|
89
|
+
it "should call the after save callback" do
|
90
|
+
controller.should_receive(:call_after_save).with(resource)
|
91
|
+
controller.send :create_resource, resource
|
92
|
+
end
|
93
|
+
it "should call the after create callback" do
|
94
|
+
controller.should_receive(:call_after_create).with(resource)
|
95
|
+
controller.send :create_resource, resource
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "performing update" do
|
100
|
+
let(:controller){ Admin::PostsController.new }
|
101
|
+
let(:resource){ mock("Resource", :attributes= => true, :save => true) }
|
102
|
+
let(:attributes){ {} }
|
103
|
+
|
104
|
+
before do
|
105
|
+
resource.should_receive(:attributes=).with(attributes)
|
106
|
+
resource.should_receive(:save)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should call the before update callback" do
|
110
|
+
controller.should_receive(:call_before_update).with(resource)
|
111
|
+
controller.send :update_resource, resource, attributes
|
112
|
+
end
|
113
|
+
it "should call the before save callback" do
|
114
|
+
controller.should_receive(:call_before_save).with(resource)
|
115
|
+
controller.send :update_resource, resource, attributes
|
116
|
+
end
|
117
|
+
it "should call the after save callback" do
|
118
|
+
controller.should_receive(:call_after_save).with(resource)
|
119
|
+
controller.send :update_resource, resource, attributes
|
120
|
+
end
|
121
|
+
it "should call the after create callback" do
|
122
|
+
controller.should_receive(:call_after_update).with(resource)
|
123
|
+
controller.send :update_resource, resource, attributes
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "performing destroy" do
|
128
|
+
let(:controller){ Admin::PostsController.new }
|
129
|
+
let(:resource){ mock("Resource", :destroy => true) }
|
130
|
+
|
131
|
+
before do
|
132
|
+
resource.should_receive(:destroy)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should call the before destroy callback" do
|
136
|
+
controller.should_receive(:call_before_destroy).with(resource)
|
137
|
+
controller.send :destroy_resource, resource
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should call the after destroy callback" do
|
141
|
+
controller.should_receive(:call_after_destroy).with(resource)
|
142
|
+
controller.send :destroy_resource, resource
|
143
|
+
end
|
45
144
|
end
|
46
145
|
end
|
47
146
|
|
data/spec/unit/resource_spec.rb
CHANGED
@@ -3,6 +3,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
3
3
|
module ActiveAdmin
|
4
4
|
describe Resource do
|
5
5
|
|
6
|
+
before { load_defaults! }
|
7
|
+
|
6
8
|
let(:namespace){ Namespace.new(:admin) }
|
7
9
|
|
8
10
|
def config(options = {})
|
@@ -66,6 +68,28 @@ module ActiveAdmin
|
|
66
68
|
end
|
67
69
|
end
|
68
70
|
|
71
|
+
describe "#include_in_menu?" do
|
72
|
+
let(:namespace){ ActiveAdmin::Namespace.new(:admin) }
|
73
|
+
subject{ resource }
|
74
|
+
|
75
|
+
context "when regular resource" do
|
76
|
+
let(:resource){ namespace.register(Post) }
|
77
|
+
it { should be_include_in_menu }
|
78
|
+
end
|
79
|
+
context "when belongs to" do
|
80
|
+
let(:resource){ namespace.register(Post){ belongs_to :author } }
|
81
|
+
it { should_not be_include_in_menu }
|
82
|
+
end
|
83
|
+
context "when belongs to optional" do
|
84
|
+
let(:resource){ namespace.register(Post){ belongs_to :author, :optional => true} }
|
85
|
+
it { should be_include_in_menu }
|
86
|
+
end
|
87
|
+
context "when menu set to false" do
|
88
|
+
let(:resource){ namespace.register(Post){ menu false } }
|
89
|
+
it { should_not be_include_in_menu }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
69
93
|
describe "parent menu item name" do
|
70
94
|
it "should be nil when not set" do
|
71
95
|
config.parent_menu_item_name.should == nil
|
@@ -85,6 +109,13 @@ module ActiveAdmin
|
|
85
109
|
it "should return the route collection path" do
|
86
110
|
config.route_collection_path.should == :admin_categories_path
|
87
111
|
end
|
112
|
+
|
113
|
+
context "when in the root namespace" do
|
114
|
+
let(:config){ ActiveAdmin.register Category, :namespace => false}
|
115
|
+
it "should have a nil route_prefix" do
|
116
|
+
config.route_prefix.should == nil
|
117
|
+
end
|
118
|
+
end
|
88
119
|
end
|
89
120
|
|
90
121
|
describe "page configs" do
|
@@ -165,17 +196,6 @@ module ActiveAdmin
|
|
165
196
|
end
|
166
197
|
end
|
167
198
|
|
168
|
-
describe "dashboard controller name" do
|
169
|
-
context "when namespaced" do
|
170
|
-
subject{ config.dashboard_controller_name }
|
171
|
-
it { should == "Admin::DashboardController" }
|
172
|
-
end
|
173
|
-
context "when not namespaced" do
|
174
|
-
let(:namespace){ ActiveAdmin::Namespace.new(:root) }
|
175
|
-
subject{ config.dashboard_controller_name }
|
176
|
-
it { should == "DashboardController" }
|
177
|
-
end
|
178
|
-
end
|
179
199
|
|
180
200
|
describe "sort order" do
|
181
201
|
subject { resource_config.sort_order }
|
@@ -193,5 +213,52 @@ module ActiveAdmin
|
|
193
213
|
it { should == sort_order }
|
194
214
|
end
|
195
215
|
end
|
216
|
+
|
217
|
+
describe "adding a scope" do
|
218
|
+
|
219
|
+
it "should add a scope" do
|
220
|
+
config.scope :published
|
221
|
+
config.scopes.first.should be_a(ActiveAdmin::Scope)
|
222
|
+
config.scopes.first.name.should == "Published"
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should retrive a scope by its id" do
|
226
|
+
config.scope :published
|
227
|
+
config.get_scope_by_id(:published).name.should == "Published"
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
describe "admin notes" do
|
232
|
+
context "when not set" do
|
233
|
+
context "when global is true" do
|
234
|
+
before(:each) do
|
235
|
+
ActiveAdmin.admin_notes = true
|
236
|
+
end
|
237
|
+
it "should default to true" do
|
238
|
+
config.admin_notes?.should be_true
|
239
|
+
end
|
240
|
+
end
|
241
|
+
context "when global is false" do
|
242
|
+
before(:each) do
|
243
|
+
ActiveAdmin.admin_notes = false
|
244
|
+
end
|
245
|
+
it "should default to false" do
|
246
|
+
config.admin_notes?.should be_false
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
context "when set" do
|
251
|
+
it "should be set to the local value true" do
|
252
|
+
ActiveAdmin.admin_notes = false
|
253
|
+
config.admin_notes = true
|
254
|
+
config.admin_notes?.should be_true
|
255
|
+
end
|
256
|
+
it "should be set to the local value false" do
|
257
|
+
ActiveAdmin.admin_notes = true
|
258
|
+
config.admin_notes = false
|
259
|
+
config.admin_notes?.should be_false
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
196
263
|
end
|
197
264
|
end
|