activeadmin 0.3.4 → 0.4.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/.gitignore +1 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +164 -5
- data/CONTRIBUTING.md +113 -0
- data/Gemfile +7 -9
- data/LICENSE +1 -1
- data/README.rdoc +19 -20
- data/activeadmin.gemspec +4 -2
- 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 +17 -341
- 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/components/_tables.css.scss +43 -2
- 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/_utilities.scss +9 -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 +43 -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 +59 -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 +11 -3
- data/features/step_definitions/asset_steps.rb +5 -1
- data/features/step_definitions/breadcrumb_steps.rb +5 -0
- data/features/step_definitions/comment_steps.rb +3 -3
- data/features/step_definitions/configuration_steps.rb +69 -13
- data/features/step_definitions/dashboard_steps.rb +7 -3
- data/features/step_definitions/factory_steps.rb +9 -2
- data/features/step_definitions/flash_steps.rb +9 -1
- data/features/step_definitions/format_steps.rb +9 -1
- data/features/step_definitions/index_scope_steps.rb +18 -6
- data/features/step_definitions/member_link_steps.rb +7 -0
- data/features/step_definitions/pagination_steps.rb +2 -2
- data/features/step_definitions/site_title_steps.rb +15 -0
- data/features/step_definitions/tab_steps.rb +1 -1
- data/features/step_definitions/user_steps.rb +1 -1
- data/features/step_definitions/web_steps.rb +4 -4
- data/features/support/paths.rb +6 -0
- data/features/users/logging_out.feature +11 -0
- data/lib/active_admin.rb +26 -10
- data/lib/active_admin/application.rb +64 -22
- data/lib/active_admin/arbre.rb +0 -1
- data/lib/active_admin/arbre/builder.rb +8 -5
- data/lib/active_admin/arbre/context.rb +1 -1
- data/lib/active_admin/arbre/html/attributes.rb +1 -1
- data/lib/active_admin/arbre/html/class_list.rb +0 -4
- data/lib/active_admin/arbre/html/collection.rb +2 -2
- data/lib/active_admin/arbre/html/document.rb +1 -1
- data/lib/active_admin/arbre/html/element.rb +19 -9
- data/lib/active_admin/arbre/html/tag.rb +3 -3
- data/lib/active_admin/arbre/html/text_node.rb +2 -2
- 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/callbacks.rb +16 -18
- 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 +21 -5
- 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/helpers/settings.rb +6 -10
- 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 +44 -0
- data/lib/active_admin/locales/en.yml +5 -0
- data/lib/active_admin/locales/hr.yml +40 -0
- data/lib/active_admin/locales/hu.yml +45 -0
- data/lib/active_admin/locales/it.yml +11 -6
- 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/menu_item.rb +25 -17
- data/lib/active_admin/namespace.rb +48 -33
- data/lib/active_admin/page.rb +65 -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/reloader.rb +109 -42
- 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 +53 -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 +8 -8
- 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/columns.rb +4 -4
- data/lib/active_admin/views/components/paginated_collection.rb +42 -13
- data/lib/active_admin/views/components/panel.rb +8 -0
- data/lib/active_admin/views/components/scopes.rb +24 -18
- 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/script/use_rails +14 -7
- data/spec/spec_helper.rb +9 -14
- data/spec/spec_helper_without_rails.rb +10 -0
- data/spec/support/detect_rails_version.rb +22 -3
- data/spec/support/integration_example_group.rb +5 -7
- data/spec/support/rails_template.rb +11 -0
- data/spec/support/rails_template_with_data.rb +25 -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/context_spec.rb +1 -1
- data/spec/unit/arbre/html/element_finder_methods_spec.rb +58 -2
- data/spec/unit/arbre/html/element_spec.rb +18 -5
- data/spec/unit/arbre/html/tag_attributes_spec.rb +3 -3
- data/spec/unit/arbre/html/tag_spec.rb +1 -1
- data/spec/unit/arbre/html_spec.rb +32 -22
- 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 +119 -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/menu_item_spec.rb +25 -20
- 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/reloader_spec.rb +82 -38
- data/spec/unit/resource/menu_spec.rb +1 -51
- data/spec/unit/resource/naming_spec.rb +25 -20
- 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 +163 -0
- data/spec/unit/views/components/panel_spec.rb +9 -0
- data/spec/unit/views/components/status_tag_spec.rb +9 -0
- data/spec/unit/views/tabbed_navigation_spec.rb +2 -1
- data/tasks/test.rake +44 -26
- metadata +176 -69
- data/app/assets/javascripts/active_admin/vendor.js +0 -382
- data/lib/active_admin/arbre/core_extensions.rb +0 -5
- 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
@@ -19,7 +19,7 @@ describe Arbre::HTML::Tag do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "creating a tag 'for' an object" do
|
22
|
-
let(:model_name){ mock(:singular => "resource_class")}
|
22
|
+
let(:model_name){ mock(:singular => "resource_class", :param_key => 'resource_class')}
|
23
23
|
let(:resource_class){ mock(:model_name => model_name) }
|
24
24
|
let(:resource){ mock(:class => resource_class, :to_key => ['5'])}
|
25
25
|
|
@@ -6,7 +6,7 @@ describe Arbre do
|
|
6
6
|
|
7
7
|
it "should render a single element" do
|
8
8
|
content = span("Hello World")
|
9
|
-
content.
|
9
|
+
content.to_s.should == <<-HTML
|
10
10
|
<span>Hello World</span>
|
11
11
|
HTML
|
12
12
|
end
|
@@ -15,7 +15,7 @@ HTML
|
|
15
15
|
content = span do
|
16
16
|
span "Hello World"
|
17
17
|
end
|
18
|
-
content.
|
18
|
+
content.to_s.should == <<-HTML
|
19
19
|
<span>
|
20
20
|
<span>Hello World</span>
|
21
21
|
</span>
|
@@ -28,7 +28,7 @@ HTML
|
|
28
28
|
li "Second"
|
29
29
|
li "Third"
|
30
30
|
end
|
31
|
-
content.
|
31
|
+
content.to_s.should == <<-HTML
|
32
32
|
<ul>
|
33
33
|
<li>First</li>
|
34
34
|
<li>Second</li>
|
@@ -51,7 +51,7 @@ HTML
|
|
51
51
|
li first
|
52
52
|
li second
|
53
53
|
end
|
54
|
-
content.
|
54
|
+
content.to_s.should == <<-EOS
|
55
55
|
<ul>
|
56
56
|
<li>First</li>
|
57
57
|
<li>Second</li>
|
@@ -66,7 +66,7 @@ EOS
|
|
66
66
|
li
|
67
67
|
end
|
68
68
|
end
|
69
|
-
content.
|
69
|
+
content.to_s.should == <<-HTML
|
70
70
|
<div>
|
71
71
|
<ul></ul>
|
72
72
|
<li>
|
@@ -82,7 +82,7 @@ HTML
|
|
82
82
|
li
|
83
83
|
end
|
84
84
|
end
|
85
|
-
content.
|
85
|
+
content.to_s.should == <<-HTML
|
86
86
|
<div>
|
87
87
|
<ul>
|
88
88
|
<li></li>
|
@@ -95,7 +95,7 @@ HTML
|
|
95
95
|
content = div do
|
96
96
|
span(ul(li))
|
97
97
|
end
|
98
|
-
content.
|
98
|
+
content.to_s.should == <<-HTML
|
99
99
|
<div>
|
100
100
|
<span>
|
101
101
|
<ul>
|
@@ -113,7 +113,7 @@ HTML
|
|
113
113
|
li
|
114
114
|
end
|
115
115
|
end
|
116
|
-
content.
|
116
|
+
content.to_s.should == <<-HTML
|
117
117
|
<div id="my-tag">
|
118
118
|
<ul>
|
119
119
|
<li></li>
|
@@ -131,12 +131,22 @@ HTML
|
|
131
131
|
item.parent.should == list
|
132
132
|
end
|
133
133
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
134
|
+
|
135
|
+
["Hello World", 1, 1.5].each do |value|
|
136
|
+
it "should append the return value of '#{value}' when no other children added to the DOM" do
|
137
|
+
li do
|
138
|
+
value
|
139
|
+
end.to_s.should == "<li>#{value}</li>\n"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
["Hello World", 1, 1.5].each do |value|
|
144
|
+
it "should not append the return value of '#{value}' when children have been added to the DOM" do
|
145
|
+
li do
|
146
|
+
text_node("Already Added")
|
147
|
+
value
|
148
|
+
end.to_s.should == "<li>Already Added</li>\n"
|
149
|
+
end
|
140
150
|
end
|
141
151
|
|
142
152
|
describe "text nodes" do
|
@@ -150,19 +160,19 @@ HTML
|
|
150
160
|
describe "self-closing nodes" do
|
151
161
|
it "should not self-close script tags" do
|
152
162
|
tag = script :type => 'text/javascript'
|
153
|
-
tag.
|
163
|
+
tag.to_s.should == <<-HTML
|
154
164
|
<script type="text/javascript"></script>
|
155
165
|
HTML
|
156
166
|
end
|
157
167
|
it "should self-close meta tags" do
|
158
168
|
tag = meta :content => "text/html; charset=utf-8"
|
159
|
-
tag.
|
169
|
+
tag.to_s.should == <<-HTML
|
160
170
|
<meta content="text/html; charset=utf-8\"/>
|
161
171
|
HTML
|
162
172
|
end
|
163
173
|
it "should self-close link tags" do
|
164
174
|
tag = link :rel => "stylesheet"
|
165
|
-
tag.
|
175
|
+
tag.to_s.should == <<-HTML
|
166
176
|
<link rel="stylesheet"/>
|
167
177
|
HTML
|
168
178
|
end
|
@@ -170,17 +180,17 @@ HTML
|
|
170
180
|
|
171
181
|
describe "html safe" do
|
172
182
|
it "should escape the contents" do
|
173
|
-
span("<br />").
|
183
|
+
span("<br />").to_s.should == <<-HTML
|
174
184
|
<span><br /></span>
|
175
185
|
HTML
|
176
186
|
end
|
177
187
|
|
178
188
|
it "should return html safe strings" do
|
179
|
-
span("<br />").
|
189
|
+
span("<br />").to_s.should be_html_safe
|
180
190
|
end
|
181
191
|
|
182
192
|
it "should not escape html passed in" do
|
183
|
-
span(span("<br />")).
|
193
|
+
span(span("<br />")).to_s.should == <<-HTML
|
184
194
|
<span>
|
185
195
|
<span><br /></span>
|
186
196
|
</span>
|
@@ -192,7 +202,7 @@ HTML
|
|
192
202
|
span {
|
193
203
|
"<br />"
|
194
204
|
}
|
195
|
-
}.
|
205
|
+
}.to_s.should == <<-HTML
|
196
206
|
<span>
|
197
207
|
<span><br /></span>
|
198
208
|
</span>
|
@@ -200,7 +210,7 @@ HTML
|
|
200
210
|
end
|
201
211
|
|
202
212
|
it "should escape the contents of attributes" do
|
203
|
-
span(:class => "<br />").
|
213
|
+
span(:class => "<br />").to_s.should == <<-HTML
|
204
214
|
<span class="<br />"></span>
|
205
215
|
HTML
|
206
216
|
end
|
@@ -13,14 +13,20 @@ describe ActiveAdmin::AssetRegistration do
|
|
13
13
|
|
14
14
|
it "should register a stylesheet file" do
|
15
15
|
MockRegistration.register_stylesheet "active_admin.css"
|
16
|
-
MockRegistration.stylesheets.should ==
|
16
|
+
MockRegistration.stylesheets.length.should == 1
|
17
|
+
MockRegistration.stylesheets.first.path.should == "active_admin.css"
|
17
18
|
end
|
18
19
|
|
19
20
|
it "should clear all existing stylesheets" do
|
20
21
|
MockRegistration.register_stylesheet "active_admin.css"
|
21
|
-
MockRegistration.stylesheets.should ==
|
22
|
+
MockRegistration.stylesheets.length.should == 1
|
22
23
|
MockRegistration.clear_stylesheets!
|
23
|
-
MockRegistration.stylesheets.should ==
|
24
|
+
MockRegistration.stylesheets.length.should == 0
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should allow media option when registering stylesheet" do
|
28
|
+
MockRegistration.register_stylesheet "active_admin.css", :media => :print
|
29
|
+
MockRegistration.stylesheets.first.options[:media].should == :print
|
24
30
|
end
|
25
31
|
|
26
32
|
it "should register a javascript file" do
|
data/spec/unit/auto_link_spec.rb
CHANGED
@@ -13,7 +13,7 @@ describe "auto linking resources" do
|
|
13
13
|
include ActiveAdmin::ViewHelpers::DisplayHelper
|
14
14
|
|
15
15
|
let(:active_admin_config) { AutoLinkMockResource.new(namespace) }
|
16
|
-
let(:
|
16
|
+
let(:active_admin_namespace){ ActiveAdmin::Namespace.new(ActiveAdmin::Application.new, :admin) }
|
17
17
|
let(:post){ Post.create! :title => "Hello World" }
|
18
18
|
|
19
19
|
def admin_post_path(post)
|
@@ -28,7 +28,7 @@ describe "auto linking resources" do
|
|
28
28
|
|
29
29
|
context "when the resource is registered" do
|
30
30
|
before do
|
31
|
-
|
31
|
+
active_admin_namespace.register Post
|
32
32
|
end
|
33
33
|
it "should return a link with the display name of the object" do
|
34
34
|
self.should_receive(:link_to).with("Hello World", admin_post_path(post))
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Required methods:
|
2
|
+
# * controller_class
|
3
|
+
# * controller
|
4
|
+
#
|
5
|
+
shared_examples_for "BaseController" do
|
6
|
+
let(:controller_class) { described_class }
|
7
|
+
|
8
|
+
describe "Menu" do
|
9
|
+
describe "setting the current tab" do
|
10
|
+
before do
|
11
|
+
controller.stub!(:active_admin_config => resource, :parent? => true)
|
12
|
+
controller.send :set_current_tab # Run the before filter
|
13
|
+
end
|
14
|
+
subject{ controller.instance_variable_get(:@current_tab) }
|
15
|
+
|
16
|
+
context "when menu item name is 'Resources' without a parent menu item" do
|
17
|
+
let(:resource){ mock(:menu_item_name => "Resources", :parent_menu_item_name => nil, :belongs_to? => false) }
|
18
|
+
it { should == "Resources" }
|
19
|
+
end
|
20
|
+
|
21
|
+
context "when there is a parent menu item of 'Admin'" do
|
22
|
+
let(:resource){ mock(:parent_menu_item_name => "Admin", :menu_item_name => "Resources", :belongs_to? => false) }
|
23
|
+
it { should == "Admin/Resources" }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -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,119 @@
|
|
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
|
+
it "implements #safe_resource_name" do
|
33
|
+
expect { config.safe_resource_name }.should_not raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#camelized_resource_name" do
|
37
|
+
it "returns a camelized version of the safe_resource_name" do
|
38
|
+
config.should_receive(:safe_resource_name).and_return "My resource"
|
39
|
+
config.camelized_resource_name.should == "MyResource"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#plural_camelized_resource_name" do
|
44
|
+
it "returns a camelized version of the plural_safe_resource_name" do
|
45
|
+
config.should_receive(:safe_resource_name).and_return "My resource"
|
46
|
+
config.camelized_resource_name.should == "MyResource"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#underscored_resource_name" do
|
51
|
+
it "returns the camelized_resource_name underscored" do
|
52
|
+
config.should_receive(:camelized_resource_name).and_return "MyResource"
|
53
|
+
config.underscored_resource_name.should == "my_resource"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#plural_underscored_resource_name" do
|
58
|
+
it "returns the plural_camelized_resource_name underscored" do
|
59
|
+
config.should_receive(:plural_camelized_resource_name).and_return "MyResources"
|
60
|
+
config.plural_underscored_resource_name.should == "my_resources"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "Menu" do
|
66
|
+
describe "menu item name" do
|
67
|
+
it "should be the plural resource name when not set" do
|
68
|
+
config.menu_item_name.should == config.plural_resource_name
|
69
|
+
end
|
70
|
+
it "should be settable" do
|
71
|
+
config.menu :label => "My Label"
|
72
|
+
config.menu_item_name.should == "My Label"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#include_in_menu?" do
|
77
|
+
it "should be included in menu by default" do
|
78
|
+
config.include_in_menu?.should == true
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should not be included in menu when menu set to false" do
|
82
|
+
config.menu false
|
83
|
+
config.include_in_menu?.should == false
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "parent menu item name" do
|
88
|
+
it "should be nil when not set" do
|
89
|
+
config.parent_menu_item_name.should == nil
|
90
|
+
end
|
91
|
+
it "should return the name if set" do
|
92
|
+
config.tap do |c|
|
93
|
+
c.menu :parent => "Blog"
|
94
|
+
end.parent_menu_item_name.should == "Blog"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "menu item priority" do
|
99
|
+
it "should be 10 when not set" do
|
100
|
+
config.menu_item_priority.should == 10
|
101
|
+
end
|
102
|
+
it "should be settable" do
|
103
|
+
config.menu :priority => 2
|
104
|
+
config.menu_item_priority.should == 2
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "menu item display if" do
|
109
|
+
it "should be a proc always returning true if not set" do
|
110
|
+
config.menu_item_display_if.should be_instance_of(Proc)
|
111
|
+
config.menu_item_display_if.call.should == true
|
112
|
+
end
|
113
|
+
it "should be settable" do
|
114
|
+
config.menu :if => proc { false }
|
115
|
+
config.menu_item_display_if.call.should == false
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|