andrewroth_activeadmin 0.3.4 → 0.3.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +159 -3
- data/CONTRIBUTING.md +113 -0
- data/LICENSE +1 -1
- data/README.rdoc +19 -20
- data/activeadmin.gemspec +3 -1
- data/app/assets/javascripts/active_admin/application.js +9 -0
- data/app/assets/javascripts/active_admin/base.js +4 -12
- data/app/assets/stylesheets/active_admin/_base.css.scss +16 -340
- data/app/assets/stylesheets/active_admin/_forms.css.scss +13 -7
- data/app/assets/stylesheets/active_admin/_header.css.scss +23 -4
- data/app/assets/stylesheets/active_admin/components/_blank_slates.scss +31 -0
- data/app/assets/stylesheets/active_admin/components/_breadcrumbs.scss +20 -0
- data/app/assets/stylesheets/active_admin/components/_buttons.scss +12 -0
- data/app/assets/stylesheets/active_admin/components/_flash_messages.css.scss +2 -0
- data/app/assets/stylesheets/active_admin/components/_grid.scss +9 -0
- data/app/assets/stylesheets/active_admin/components/_links.scss +5 -0
- data/app/assets/stylesheets/active_admin/components/_pagination.scss +34 -0
- data/app/assets/stylesheets/active_admin/components/_panels.scss +6 -0
- data/app/assets/stylesheets/active_admin/components/_scopes.scss +10 -0
- data/app/assets/stylesheets/active_admin/components/_status_tags.scss +12 -0
- data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +101 -0
- data/app/assets/stylesheets/active_admin/mixins/_all.css.scss +2 -1
- data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +50 -13
- data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +9 -1
- data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +7 -5
- data/app/assets/stylesheets/active_admin/mixins/_shadows.css.scss +1 -0
- data/app/assets/stylesheets/active_admin/mixins/_typography.scss +3 -0
- data/app/assets/stylesheets/active_admin/mixins/_variables.css.scss +1 -0
- data/app/assets/stylesheets/active_admin/pages/_dashboard.scss +5 -0
- data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +44 -0
- data/app/assets/stylesheets/active_admin/structure/_footer.scss +14 -0
- data/app/assets/stylesheets/active_admin/structure/_main_structure.scss +26 -0
- data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +44 -0
- data/app/views/active_admin/devise/passwords/edit.html.erb +1 -1
- data/app/views/active_admin/devise/passwords/new.html.erb +1 -1
- data/app/views/active_admin/devise/sessions/new.html.erb +1 -1
- data/app/views/active_admin/devise/shared/_links.erb +1 -1
- data/app/views/active_admin/devise/unlocks/new.html.erb +1 -1
- data/app/views/active_admin/page/index.html.arb +1 -0
- data/app/views/layouts/active_admin_logged_out.html.erb +2 -2
- data/cucumber.yml +3 -2
- data/docs/1-general-configuration.md +46 -10
- data/docs/6-show-screens.md +7 -0
- data/docs/8-custom-actions.md +12 -2
- data/docs/9-custom-pages.md +84 -0
- data/features/belongs_to.feature +27 -0
- data/features/comments/commenting.feature +3 -2
- data/features/dashboard.feature +18 -0
- data/features/development_reloading.feature +19 -0
- data/features/index/filter_with_check_boxes.feature +25 -0
- data/features/index/index_as_table.feature +14 -0
- data/features/index/index_scopes.feature +42 -0
- data/features/index/pagination.feature +19 -1
- data/features/menu.feature +22 -2
- data/features/registering_assets.feature +2 -2
- data/features/registering_pages.feature +66 -0
- data/features/specifying_actions.feature +5 -0
- data/features/step_definitions/action_item_steps.rb +2 -6
- data/features/step_definitions/action_link_steps.rb +7 -0
- data/features/step_definitions/additional_web_steps.rb +8 -0
- data/features/step_definitions/asset_steps.rb +5 -1
- data/features/step_definitions/breadcrumb_steps.rb +5 -0
- data/features/step_definitions/configuration_steps.rb +56 -8
- data/features/step_definitions/dashboard_steps.rb +5 -1
- data/features/step_definitions/factory_steps.rb +9 -2
- data/features/step_definitions/flash_steps.rb +9 -1
- data/features/step_definitions/index_scope_steps.rb +16 -4
- data/features/step_definitions/member_link_steps.rb +7 -0
- data/features/step_definitions/site_title_steps.rb +15 -0
- data/features/support/paths.rb +6 -0
- data/features/users/logging_out.feature +11 -0
- data/lib/active_admin.rb +25 -10
- data/lib/active_admin/application.rb +63 -20
- data/lib/active_admin/arbre/html/element.rb +10 -0
- data/lib/active_admin/asset_registration.rb +15 -2
- data/lib/active_admin/base_controller.rb +61 -0
- data/lib/active_admin/{resource_controller → base_controller}/menu.rb +1 -1
- data/lib/active_admin/comments.rb +48 -54
- data/lib/active_admin/comments/comment.rb +13 -2
- data/lib/active_admin/comments/namespace_helper.rb +1 -1
- data/lib/active_admin/comments/views/active_admin_comments.rb +7 -3
- data/lib/active_admin/dashboards.rb +4 -0
- data/lib/active_admin/dashboards/dashboard_controller.rb +20 -4
- data/lib/active_admin/dsl.rb +6 -159
- data/lib/active_admin/event.rb +5 -3
- data/lib/active_admin/filter_form_builder.rb +53 -0
- data/lib/active_admin/form_builder.rb +25 -19
- data/lib/active_admin/inputs.rb +14 -0
- data/lib/active_admin/inputs/datepicker_input.rb +11 -0
- data/lib/active_admin/inputs/filter_base.rb +46 -0
- data/lib/active_admin/inputs/filter_check_boxes_input.rb +40 -0
- data/lib/active_admin/inputs/filter_date_range_input.rb +34 -0
- data/lib/active_admin/inputs/filter_numeric_input.rb +55 -0
- data/lib/active_admin/inputs/filter_select_input.rb +23 -0
- data/lib/active_admin/inputs/filter_string_input.rb +22 -0
- data/lib/active_admin/locales/ca.yml +44 -0
- data/lib/active_admin/locales/cs.yml +14 -10
- data/lib/active_admin/locales/de.yml +43 -0
- data/lib/active_admin/locales/en.yml +5 -0
- data/lib/active_admin/locales/hr.yml +40 -0
- data/lib/active_admin/locales/ko.yml +40 -0
- data/lib/active_admin/locales/lv.yml +43 -0
- data/lib/active_admin/locales/nl.yml +40 -0
- data/lib/active_admin/locales/no-NB.yml +40 -0
- data/lib/active_admin/locales/pl.yml +7 -1
- data/lib/active_admin/locales/pt-BR.yml +6 -2
- data/lib/active_admin/namespace.rb +48 -33
- data/lib/active_admin/page.rb +54 -0
- data/lib/active_admin/page_controller.rb +15 -0
- data/lib/active_admin/page_dsl.rb +21 -0
- data/lib/active_admin/page_presenter.rb +30 -0
- data/lib/active_admin/resource.rb +38 -44
- data/lib/active_admin/resource/action_items.rb +5 -0
- data/lib/active_admin/resource/belongs_to.rb +4 -2
- data/lib/active_admin/resource/controllers.rb +35 -0
- data/lib/active_admin/resource/menu.rb +1 -2
- data/lib/active_admin/resource/naming.rb +43 -31
- data/lib/active_admin/resource/page_presenters.rb +28 -0
- data/lib/active_admin/resource/scopes.rb +16 -3
- data/lib/active_admin/resource/sidebars.rb +4 -0
- data/lib/active_admin/resource_collection.rb +88 -0
- data/lib/active_admin/resource_controller.rb +18 -54
- data/lib/active_admin/resource_controller/action_builder.rb +1 -1
- data/lib/active_admin/resource_controller/actions.rb +1 -1
- data/lib/active_admin/resource_controller/callbacks.rb +1 -1
- data/lib/active_admin/resource_controller/collection.rb +8 -4
- data/lib/active_admin/resource_controller/filters.rb +1 -1
- data/lib/active_admin/resource_controller/resource_class_methods.rb +24 -0
- data/lib/active_admin/resource_controller/scoping.rb +1 -1
- data/lib/active_admin/resource_controller/sidebars.rb +1 -1
- data/lib/active_admin/resource_dsl.rb +157 -0
- data/lib/active_admin/router.rb +21 -14
- data/lib/active_admin/scope.rb +15 -3
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_factory.rb +4 -3
- data/lib/active_admin/view_helpers/auto_link_helper.rb +1 -10
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +25 -21
- data/lib/active_admin/view_helpers/filter_form_helper.rb +0 -150
- data/lib/active_admin/views/components/attributes_table.rb +1 -1
- data/lib/active_admin/views/components/paginated_collection.rb +42 -13
- data/lib/active_admin/views/components/scopes.rb +17 -17
- data/lib/active_admin/views/components/status_tag.rb +6 -5
- data/lib/active_admin/views/components/table_for.rb +6 -2
- data/lib/active_admin/views/header_renderer.rb +31 -12
- data/lib/active_admin/views/index_as_block.rb +2 -2
- data/lib/active_admin/views/index_as_blog.rb +3 -3
- data/lib/active_admin/views/index_as_grid.rb +4 -4
- data/lib/active_admin/views/index_as_table.rb +13 -6
- data/lib/active_admin/views/pages/base.rb +4 -4
- data/lib/active_admin/views/pages/form.rb +49 -0
- data/lib/active_admin/views/pages/index.rb +18 -6
- data/lib/active_admin/views/pages/page.rb +24 -0
- data/lib/active_admin/views/pages/show.rb +1 -1
- data/lib/generators/active_admin/assets/assets_generator.rb +19 -1
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +38 -12
- data/lib/generators/active_admin/install/templates/dashboards.rb +6 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support/rails_template.rb +11 -0
- data/spec/support/templates/cucumber_with_reloading.rb +5 -0
- data/spec/unit/active_admin_spec.rb +8 -0
- data/spec/unit/application_spec.rb +48 -2
- data/spec/unit/arbre/html/element_finder_methods_spec.rb +58 -2
- data/spec/unit/asset_registration_spec.rb +9 -3
- data/spec/unit/auto_link_spec.rb +2 -2
- data/spec/unit/base_controller_shared_examples.rb +28 -0
- data/spec/unit/base_controller_spec.rb +8 -0
- data/spec/unit/belongs_to_spec.rb +30 -33
- data/spec/unit/comments_spec.rb +45 -15
- data/spec/unit/config_shared_examples.rb +108 -0
- data/spec/unit/dashboard_controller_spec.rb +44 -0
- data/spec/unit/event_spec.rb +6 -0
- data/spec/unit/filter_form_builder_spec.rb +9 -0
- data/spec/unit/form_builder_spec.rb +8 -14
- data/spec/unit/namespace/register_page_spec.rb +102 -0
- data/spec/unit/namespace/register_resource_spec.rb +188 -0
- data/spec/unit/namespace_spec.rb +11 -183
- data/spec/unit/page_controller_spec.rb +8 -0
- data/spec/unit/page_spec.rb +60 -0
- data/spec/unit/resource/menu_spec.rb +1 -51
- data/spec/unit/resource/naming_spec.rb +24 -19
- data/spec/unit/resource/page_presenters_spec.rb +32 -0
- data/spec/unit/resource/scopes_spec.rb +13 -0
- data/spec/unit/resource_collection_spec.rb +101 -0
- data/spec/unit/resource_controller_spec.rb +40 -32
- data/spec/unit/{registration_spec.rb → resource_registration_spec.rb} +0 -0
- data/spec/unit/resource_spec.rb +8 -24
- data/spec/unit/routing_spec.rb +50 -1
- data/spec/unit/scope_spec.rb +18 -4
- data/spec/unit/views/components/paginated_collection_spec.rb +150 -0
- data/spec/unit/views/components/status_tag_spec.rb +9 -0
- data/tasks/test.rake +43 -27
- metadata +140 -31
- data/app/assets/javascripts/active_admin/vendor.js +0 -382
- data/lib/active_admin/comments/configuration.rb +0 -18
- data/lib/active_admin/page_config.rb +0 -15
- data/lib/active_admin/resource_controller/form.rb +0 -42
- data/lib/active_admin/resource_controller/page_configurations.rb +0 -53
- data/lib/active_admin/views/pages/edit.rb +0 -28
- data/lib/active_admin/views/pages/new.rb +0 -28
- data/lib/generators/active_admin/assets/templates/3.0/active_admin.js +0 -427
- data/spec/integration/belongs_to_spec.rb +0 -42
@@ -16,65 +16,15 @@ module ActiveAdmin
|
|
16
16
|
let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
|
17
17
|
subject{ resource }
|
18
18
|
|
19
|
-
context "when regular resource" do
|
20
|
-
let(:resource){ namespace.register(Post) }
|
21
|
-
it { should be_include_in_menu }
|
22
|
-
end
|
23
19
|
context "when belongs to" do
|
24
20
|
let(:resource){ namespace.register(Post){ belongs_to :author } }
|
25
21
|
it { should_not be_include_in_menu }
|
26
22
|
end
|
23
|
+
|
27
24
|
context "when belongs to optional" do
|
28
25
|
let(:resource){ namespace.register(Post){ belongs_to :author, :optional => true} }
|
29
26
|
it { should be_include_in_menu }
|
30
27
|
end
|
31
|
-
context "when menu set to false" do
|
32
|
-
let(:resource){ namespace.register(Post){ menu false } }
|
33
|
-
it { should_not be_include_in_menu }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "menu item name" do
|
38
|
-
it "should be the resource name when not set" do
|
39
|
-
config.menu_item_name.should == "Categories"
|
40
|
-
end
|
41
|
-
it "should be settable" do
|
42
|
-
config.menu :label => "My Label"
|
43
|
-
config.menu_item_name.should == "My Label"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "parent menu item name" do
|
48
|
-
it "should be nil when not set" do
|
49
|
-
config.parent_menu_item_name.should == nil
|
50
|
-
end
|
51
|
-
it "should return the name if set" do
|
52
|
-
config.tap do |c|
|
53
|
-
c.menu :parent => "Blog"
|
54
|
-
end.parent_menu_item_name.should == "Blog"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe "menu item priority" do
|
59
|
-
it "should be 10 when not set" do
|
60
|
-
config.menu_item_priority.should == 10
|
61
|
-
end
|
62
|
-
it "should be settable" do
|
63
|
-
config.menu :priority => 2
|
64
|
-
config.menu_item_priority.should == 2
|
65
|
-
end
|
66
28
|
end
|
67
|
-
|
68
|
-
describe "menu item display if" do
|
69
|
-
it "should be a proc always returning true if not set" do
|
70
|
-
config.menu_item_display_if.should be_instance_of(Proc)
|
71
|
-
config.menu_item_display_if.call.should == true
|
72
|
-
end
|
73
|
-
it "should be settable" do
|
74
|
-
config.menu :if => proc { false }
|
75
|
-
config.menu_item_display_if.call.should == false
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
29
|
end
|
80
30
|
end
|
@@ -26,48 +26,53 @@ module ActiveAdmin
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
context "when you pass the 'as' option" do
|
29
|
-
it "should underscore the passed through string
|
30
|
-
config(:as => "Blog
|
29
|
+
it "should underscore the passed through string" do
|
30
|
+
config(:as => "Blog Category").underscored_resource_name.should == "blog_category"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
describe "camelized resource name" do
|
36
36
|
it "should return a camelized version of the underscored resource name" do
|
37
|
-
config(:as => "Blog
|
37
|
+
config(:as => "Blog category").camelized_resource_name.should == "BlogCategory"
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
describe "plural underscored resource name" do
|
42
|
-
before(:all) do
|
43
|
-
class ::CandyCane; end
|
44
|
-
@config = Resource.new(namespace, CandyCane, {})
|
45
|
-
end
|
46
|
-
|
47
|
-
it "should return an underscored and pluralized resource name" do
|
48
|
-
config.plural_underscored_resource_name.should == "candy_canes"
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
41
|
describe "resource name" do
|
53
42
|
it "should return a pretty name" do
|
54
43
|
config.resource_name.should == "Category"
|
55
44
|
end
|
45
|
+
|
56
46
|
it "should return the plural version" do
|
57
47
|
config.plural_resource_name.should == "Categories"
|
58
48
|
end
|
49
|
+
|
59
50
|
context "when the :as option is given" do
|
60
51
|
it "should return the custom name" do
|
61
52
|
config(:as => "My Category").resource_name.should == "My Category"
|
62
53
|
end
|
63
54
|
end
|
64
|
-
|
65
|
-
|
66
|
-
|
55
|
+
|
56
|
+
describe "I18n integration" do
|
57
|
+
describe "singular name" do
|
58
|
+
it "should return the titleized model_name.human" do
|
59
|
+
Category.model_name.should_receive(:human).and_return "Da category"
|
60
|
+
|
61
|
+
config.resource_name.should == "Da Category"
|
62
|
+
end
|
67
63
|
end
|
68
|
-
|
69
|
-
|
64
|
+
|
65
|
+
describe "plural name" do
|
66
|
+
it "should return the titleized plural version defined by i18n if available" do
|
67
|
+
Category.model_name.should_receive(:underscore).and_return "category"
|
68
|
+
Category.model_name.should_not_receive(:i18n_key) # Not implemented in Rails 3.0.0
|
69
|
+
I18n.should_receive(:translate!).
|
70
|
+
with("activerecord.models.category.other").
|
71
|
+
and_return("Da categories")
|
72
|
+
config.plural_resource_name.should == "Da Categories"
|
73
|
+
end
|
70
74
|
end
|
75
|
+
|
71
76
|
end
|
72
77
|
end
|
73
78
|
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ActiveAdmin::Resource::PagePresenters do
|
4
|
+
|
5
|
+
let(:namespace){ ActiveAdmin::Namespace.new(ActiveAdmin::Application.new, :admin) }
|
6
|
+
let(:resource){ namespace.register(Post) }
|
7
|
+
|
8
|
+
it "should have an empty set of configs on initialize" do
|
9
|
+
resource.page_presenters.should == {}
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should add a page presenter" do
|
13
|
+
page_presenter = ActiveAdmin::PagePresenter.new
|
14
|
+
resource.set_page_presenter(:index, page_presenter)
|
15
|
+
resource.page_presenters[:index].should == page_presenter
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#get_page_presenter" do
|
19
|
+
|
20
|
+
it "should return a page config when set" do
|
21
|
+
page_presenter = ActiveAdmin::PagePresenter.new
|
22
|
+
resource.set_page_presenter(:index, page_presenter)
|
23
|
+
resource.get_page_presenter(:index).should == page_presenter
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should return nil when no page config set" do
|
27
|
+
resource.get_page_presenter(:index).should == nil
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -25,6 +25,19 @@ module ActiveAdmin
|
|
25
25
|
config.get_scope_by_id(:published).name.should == "Published"
|
26
26
|
end
|
27
27
|
|
28
|
+
it "should not add a scope with the same name twice" do
|
29
|
+
config.scope :published
|
30
|
+
config.scope :published
|
31
|
+
config.scopes.size.should == 1
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should update a scope with the same id" do
|
35
|
+
config.scope :published
|
36
|
+
config.scopes.first.scope_block.should be_nil
|
37
|
+
config.scope(:published){ }
|
38
|
+
config.scopes.first.scope_block.should_not be_nil
|
39
|
+
end
|
40
|
+
|
28
41
|
end
|
29
42
|
end
|
30
43
|
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'active_admin/resource_collection'
|
3
|
+
|
4
|
+
include ActiveAdmin
|
5
|
+
|
6
|
+
describe ActiveAdmin::ResourceCollection do
|
7
|
+
|
8
|
+
let(:collection){ ResourceCollection.new }
|
9
|
+
|
10
|
+
it "should have no resources when new" do
|
11
|
+
collection.resources.should == []
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should be enumerable" do
|
15
|
+
resource = mock(:resource_key => "MyResource")
|
16
|
+
collection.add(resource)
|
17
|
+
collection.each{|r| r.should == resource }
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return the available keys" do
|
21
|
+
resource = mock(:resource_key => "MyResource")
|
22
|
+
collection.add resource
|
23
|
+
collection.keys.should == [resource.resource_key]
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "adding a new resource" do
|
27
|
+
let(:resource){ mock(:resource_key => "MyResource") }
|
28
|
+
|
29
|
+
it "should return the resource" do
|
30
|
+
collection.add(resource).should == resource
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should add a new resource" do
|
34
|
+
collection.add(resource)
|
35
|
+
collection.resources.should == [resource]
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be available by name" do
|
39
|
+
collection.add(resource)
|
40
|
+
collection.find_by_key(resource.resource_key).should == resource
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "adding a new resource when the key already exists" do
|
45
|
+
let(:stored_resource){ mock(:resource_key => "MyResource") }
|
46
|
+
let(:resource){ mock(:resource_key => "MyResource") }
|
47
|
+
|
48
|
+
before do
|
49
|
+
collection.add(stored_resource)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should return the original resource" do
|
53
|
+
collection.add(resource).should == stored_resource
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should not add a new resource" do
|
57
|
+
collection.add(resource)
|
58
|
+
collection.resources.should == [stored_resource]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "adding an existing resource key with a different resource class" do
|
63
|
+
let(:stored_resource){ mock(:resource_key => "MyResource", :resource_class => mock) }
|
64
|
+
let(:resource){ mock(:resource_key => "MyResource", :resource_class => mock) }
|
65
|
+
|
66
|
+
it "should raise a ActiveAdmin::ResourceMismatchError" do
|
67
|
+
collection.add(stored_resource)
|
68
|
+
lambda {
|
69
|
+
collection.add(resource)
|
70
|
+
}.should raise_error(ActiveAdmin::ResourceMismatchError)
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#find_by_resource_class" do
|
76
|
+
|
77
|
+
let(:base_class){ mock(:to_s => "BaseClass")}
|
78
|
+
let(:resource_from_base_class){ mock(:resource_key => "MyBaseClassResource", :resource_class => base_class )}
|
79
|
+
let(:resource_class){ mock(:base_class => base_class, :to_s => "ResourceClass") }
|
80
|
+
let(:resource){ mock(:resource_key => "MyResource", :resource_class => resource_class) }
|
81
|
+
|
82
|
+
it "should find a resource when it's in the collection" do
|
83
|
+
collection.add resource
|
84
|
+
collection.find_by_resource_class(resource_class).should == resource
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should return nil when the resource class is not in the collection" do
|
88
|
+
collection.find_by_resource_class(resource_class).should == nil
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should return the resource when it and it's base class is in the collection" do
|
92
|
+
collection.add resource_from_base_class
|
93
|
+
collection.find_by_resource_class(resource_class).should == resource_from_base_class
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should return nil the resource_class does not repond to base_class and it's not in the collection" do
|
97
|
+
collection.find_by_resource_class(mock).should == nil
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
@@ -1,47 +1,55 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require File.expand_path('base_controller_shared_examples', File.dirname(__FILE__))
|
2
3
|
|
3
4
|
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
5
|
|
11
|
-
|
12
|
-
Admin::PostsController.send(:set_page_config, page, {})
|
13
|
-
Admin::PostsController.send(:"#{page}_config").should be_an_instance_of(ActiveAdmin::PageConfig)
|
14
|
-
end
|
6
|
+
let(:controller) { ActiveAdmin::ResourceController.new }
|
15
7
|
|
16
|
-
|
17
|
-
block = Proc.new {}
|
18
|
-
Admin::PostsController.send(:set_page_config, page, {}, &block)
|
19
|
-
Admin::PostsController.send(:"#{page}_config").block.should == block
|
20
|
-
end
|
8
|
+
it_should_behave_like "BaseController"
|
21
9
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
10
|
+
describe "authenticating the user" do
|
11
|
+
let(:controller){ Admin::PostsController.new }
|
12
|
+
|
13
|
+
it "should do nothing when no authentication_method set" do
|
14
|
+
namespace = controller.class.active_admin_config.namespace
|
15
|
+
namespace.should_receive(:authentication_method).once.and_return(nil)
|
16
|
+
|
17
|
+
controller.send(:authenticate_active_admin_user)
|
26
18
|
end
|
27
|
-
end
|
28
19
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
20
|
+
it "should call the authentication_method when set" do
|
21
|
+
namespace = controller.class.active_admin_config.namespace
|
22
|
+
|
23
|
+
namespace.should_receive(:authentication_method).twice.
|
24
|
+
and_return(:authenticate_admin_user!)
|
25
|
+
|
26
|
+
controller.should_receive(:authenticate_admin_user!).and_return(true)
|
27
|
+
|
28
|
+
controller.send(:authenticate_active_admin_user)
|
34
29
|
end
|
35
|
-
subject{ controller.instance_variable_get(:@current_tab) }
|
36
30
|
|
37
|
-
|
38
|
-
|
39
|
-
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "retrieving the current user" do
|
34
|
+
let(:controller){ Admin::PostsController.new }
|
35
|
+
|
36
|
+
it "should return nil when no current_user_method set" do
|
37
|
+
namespace = controller.class.active_admin_config.namespace
|
38
|
+
namespace.should_receive(:current_user_method).once.and_return(nil)
|
39
|
+
|
40
|
+
controller.send(:current_active_admin_user).should == nil
|
40
41
|
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
it "should call the current_user_method when set" do
|
44
|
+
user = mock
|
45
|
+
namespace = controller.class.active_admin_config.namespace
|
46
|
+
|
47
|
+
namespace.should_receive(:current_user_method).twice.
|
48
|
+
and_return(:current_admin_user)
|
49
|
+
|
50
|
+
controller.should_receive(:current_admin_user).and_return(user)
|
51
|
+
|
52
|
+
controller.send(:current_active_admin_user).should == user
|
45
53
|
end
|
46
54
|
end
|
47
55
|
|
File without changes
|
data/spec/unit/resource_spec.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require File.expand_path('config_shared_examples', File.dirname(__FILE__))
|
2
3
|
|
3
4
|
module ActiveAdmin
|
4
5
|
describe Resource do
|
5
6
|
|
7
|
+
it_should_behave_like "ActiveAdmin::Config"
|
8
|
+
|
6
9
|
before { load_defaults! }
|
7
10
|
|
8
11
|
let(:application){ ActiveAdmin::Application.new }
|
@@ -12,6 +15,8 @@ module ActiveAdmin
|
|
12
15
|
@config ||= Resource.new(namespace, Category, options)
|
13
16
|
end
|
14
17
|
|
18
|
+
it { respond_to :resource_class }
|
19
|
+
|
15
20
|
describe "#resource_table_name" do
|
16
21
|
it "should return the resource's table name" do
|
17
22
|
config.resource_table_name.should == '"categories"'
|
@@ -23,12 +28,6 @@ module ActiveAdmin
|
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
26
|
-
describe "namespace" do
|
27
|
-
it "should return the namespace" do
|
28
|
-
config.namespace.should == namespace
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
31
|
describe "controller name" do
|
33
32
|
it "should return a namespaced controller name" do
|
34
33
|
config.controller_name.should == "Admin::CategoriesController"
|
@@ -106,7 +105,6 @@ module ActiveAdmin
|
|
106
105
|
end
|
107
106
|
|
108
107
|
describe "route names" do
|
109
|
-
let(:config){ application.register Category }
|
110
108
|
it "should return the route prefix" do
|
111
109
|
config.route_prefix.should == "admin"
|
112
110
|
end
|
@@ -131,18 +129,6 @@ module ActiveAdmin
|
|
131
129
|
end
|
132
130
|
end
|
133
131
|
|
134
|
-
describe "page configs" do
|
135
|
-
context "when initialized" do
|
136
|
-
it "should be empty" do
|
137
|
-
config.page_configs.should == {}
|
138
|
-
end
|
139
|
-
end
|
140
|
-
it "should be set-able" do
|
141
|
-
config.page_configs[:index] = "hello world"
|
142
|
-
config.page_configs[:index].should == "hello world"
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
132
|
describe "scoping" do
|
147
133
|
context "when using a block" do
|
148
134
|
before do
|
@@ -214,17 +200,15 @@ module ActiveAdmin
|
|
214
200
|
|
215
201
|
context "when resource class responds to primary_key" do
|
216
202
|
it "should sort by primary key desc by default" do
|
217
|
-
|
218
|
-
|
219
|
-
config = Resource.new(namespace, mock_resource)
|
203
|
+
MockResource.should_receive(:primary_key).and_return("pk")
|
204
|
+
config = Resource.new(namespace, MockResource)
|
220
205
|
config.sort_order.should == "pk_desc"
|
221
206
|
end
|
222
207
|
end
|
223
208
|
|
224
209
|
context "when resource class does not respond to primary_key" do
|
225
210
|
it "should default to id" do
|
226
|
-
|
227
|
-
config = Resource.new(namespace, mock_resource)
|
211
|
+
config = Resource.new(namespace, MockResource)
|
228
212
|
config.sort_order.should == "id_desc"
|
229
213
|
end
|
230
214
|
end
|