activeadmin 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activeadmin might be problematic. Click here for more details.
- data/.travis.yml +8 -5
- data/CHANGELOG.md +151 -0
- data/Gemfile +16 -16
- data/LICENSE +1 -1
- data/activeadmin.gemspec +1 -0
- data/app/assets/images/active_admin/index_list_icons/block_icon.svg +10 -0
- data/app/assets/images/active_admin/index_list_icons/blog_icon.svg +4 -0
- data/app/assets/images/active_admin/index_list_icons/grid_icon.svg +13 -0
- data/app/assets/images/active_admin/index_list_icons/table_icon.svg +3 -0
- data/app/assets/javascripts/active_admin/components/jquery.aa.checkbox-toggler.js.coffee +17 -44
- data/app/assets/javascripts/active_admin/components/jquery.aa.dropdown-menu.js.coffee +2 -4
- data/app/assets/javascripts/active_admin/components/jquery.aa.popover.js.coffee +0 -3
- data/app/assets/javascripts/active_admin/components/jquery.aa.table-checkbox-toggler.js.coffee +10 -12
- data/app/assets/javascripts/active_admin/pages/application.js.coffee +13 -10
- data/app/assets/javascripts/active_admin/pages/batch_actions.js.coffee +3 -3
- data/app/assets/stylesheets/active_admin/_base.css.scss +1 -0
- data/app/assets/stylesheets/active_admin/_header.css.scss +5 -2
- data/app/assets/stylesheets/active_admin/components/_dropdown_menu.scss +2 -2
- data/app/assets/stylesheets/active_admin/components/_index_list.scss +12 -0
- data/app/assets/stylesheets/active_admin/components/_popovers.css.scss +2 -2
- data/app/assets/stylesheets/active_admin/components/_table_tools.css.scss +2 -2
- data/app/assets/stylesheets/active_admin/mixins/_buttons.css.scss +4 -4
- data/app/assets/stylesheets/active_admin/mixins/_gradients.css.scss +5 -4
- data/app/assets/stylesheets/active_admin/mixins/_sections.css.scss +1 -1
- data/app/assets/stylesheets/active_admin/pages/_logged_out.scss +1 -1
- data/app/assets/stylesheets/active_admin/print.css.scss +2 -2
- data/app/assets/stylesheets/active_admin/structure/_title_bar.scss +1 -1
- data/app/views/active_admin/devise/unlocks/new.html.erb +14 -12
- data/docs/1-general-configuration.md +13 -0
- data/docs/10-custom-pages.md +40 -28
- data/docs/11-decorators.md +6 -4
- data/docs/12-arbre-components.md +1 -1
- data/docs/13-authorization-adapter.md +206 -0
- data/docs/2-resource-customization.md +129 -14
- data/docs/3-index-pages.md +65 -0
- data/docs/3-index-pages/create-an-index.md +29 -0
- data/docs/3-index-pages/index-as-table.md +35 -11
- data/docs/5-forms.md +2 -2
- data/features/authorization.feature +64 -0
- data/features/authorization_cancan.feature +52 -0
- data/features/belongs_to.feature +41 -5
- data/features/index/batch_actions.feature +27 -3
- data/features/index/formats.feature +27 -0
- data/features/index/index_as_table.feature +74 -2
- data/features/index/index_parameters.feature +69 -0
- data/features/index/index_scopes.feature +7 -11
- data/features/index/page_title.feature +18 -0
- data/features/index/switch_index_view.feature +73 -0
- data/features/menu.feature +27 -0
- data/features/registering_pages.feature +21 -0
- data/features/step_definitions/additional_web_steps.rb +4 -0
- data/features/step_definitions/batch_action_steps.rb +16 -6
- data/features/step_definitions/index_scope_steps.rb +3 -3
- data/features/step_definitions/index_views_steps.rb +3 -0
- data/features/step_definitions/menu_steps.rb +4 -0
- data/features/support/env.rb +4 -0
- data/features/support/paths.rb +3 -0
- data/lib/active_admin.rb +4 -0
- data/lib/active_admin/application.rb +43 -76
- data/lib/active_admin/authorization_adapter.rb +128 -0
- data/lib/active_admin/base_controller.rb +18 -1
- data/lib/active_admin/base_controller/authorization.rb +153 -0
- data/lib/active_admin/base_controller/menu.rb +8 -3
- data/lib/active_admin/batch_actions/resource_extension.rb +8 -7
- data/lib/active_admin/batch_actions/views/batch_action_form.rb +1 -1
- data/lib/active_admin/cancan_adapter.rb +40 -0
- data/lib/active_admin/dashboards.rb +4 -5
- data/lib/active_admin/dashboards/dashboard_controller.rb +1 -1
- data/lib/active_admin/devise.rb +22 -7
- data/lib/active_admin/dsl.rb +18 -5
- data/lib/active_admin/engine.rb +1 -1
- data/lib/active_admin/filters/dsl.rb +1 -1
- data/lib/active_admin/filters/forms.rb +9 -7
- data/lib/active_admin/filters/resource_extension.rb +20 -15
- data/lib/active_admin/form_builder.rb +44 -49
- data/lib/active_admin/helpers/optional_display.rb +4 -8
- data/lib/active_admin/inputs/filter_boolean_input.rb +1 -1
- data/lib/active_admin/inputs/filter_string_input.rb +5 -1
- data/lib/active_admin/locales/bg.yml +1 -1
- data/lib/active_admin/locales/ca.yml +1 -1
- data/lib/active_admin/locales/cs.yml +26 -25
- data/lib/active_admin/locales/da.yml +1 -1
- data/lib/active_admin/locales/de.yml +1 -1
- data/lib/active_admin/locales/en.yml +11 -1
- data/lib/active_admin/locales/es.yml +16 -16
- data/lib/active_admin/locales/fr.yml +1 -1
- data/lib/active_admin/locales/he.yml +1 -1
- data/lib/active_admin/locales/hr.yml +1 -1
- data/lib/active_admin/locales/hu.yml +1 -1
- data/lib/active_admin/locales/it.yml +1 -1
- data/lib/active_admin/locales/ja.yml +4 -1
- data/lib/active_admin/locales/ko.yml +1 -1
- data/lib/active_admin/locales/lt.yml +1 -1
- data/lib/active_admin/locales/lv.yml +12 -1
- data/lib/active_admin/locales/nl.yml +2 -2
- data/lib/active_admin/locales/no-NB.yml +22 -1
- data/lib/active_admin/locales/pl.yml +1 -1
- data/lib/active_admin/locales/pt-BR.yml +1 -1
- data/lib/active_admin/locales/pt-PT.yml +81 -0
- data/lib/active_admin/locales/ro.yml +1 -1
- data/lib/active_admin/locales/ru.yml +1 -1
- data/lib/active_admin/locales/sv-SE.yml +1 -1
- data/lib/active_admin/locales/tr.yml +1 -1
- data/lib/active_admin/locales/vi.yml +1 -1
- data/lib/active_admin/locales/zh-CN.yml +1 -1
- data/lib/active_admin/locales/zh-TW.yml +1 -1
- data/lib/active_admin/menu.rb +76 -38
- data/lib/active_admin/menu_collection.rb +96 -0
- data/lib/active_admin/menu_item.rb +61 -71
- data/lib/active_admin/namespace.rb +67 -5
- data/lib/active_admin/page.rb +6 -0
- data/lib/active_admin/page_controller.rb +13 -3
- data/lib/active_admin/resource.rb +11 -20
- data/lib/active_admin/resource/action_items.rb +3 -3
- data/lib/active_admin/resource/controllers.rb +0 -17
- data/lib/active_admin/resource/menu.rb +52 -24
- data/lib/active_admin/resource/naming.rb +6 -10
- data/lib/active_admin/resource/page_presenters.rb +57 -3
- data/lib/active_admin/resource/routes.rb +46 -0
- data/lib/active_admin/resource_controller.rb +2 -17
- data/lib/active_admin/resource_controller/data_access.rb +299 -0
- data/lib/active_admin/resource_controller/decorators.rb +2 -1
- data/lib/active_admin/resource_dsl.rb +12 -14
- data/lib/active_admin/router.rb +61 -56
- data/lib/active_admin/scope.rb +28 -18
- data/lib/active_admin/version.rb +1 -1
- data/lib/active_admin/view_factory.rb +0 -1
- data/lib/active_admin/view_helpers/breadcrumb_helper.rb +13 -19
- data/lib/active_admin/view_helpers/fields_for.rb +2 -0
- data/lib/active_admin/view_helpers/form_helper.rb +1 -1
- data/lib/active_admin/view_helpers/method_or_proc_helper.rb +66 -11
- data/lib/active_admin/views/components/attributes_table.rb +7 -4
- data/lib/active_admin/views/components/index_list.rb +68 -0
- data/lib/active_admin/views/components/paginated_collection.rb +13 -9
- data/lib/active_admin/views/components/scopes.rb +2 -8
- data/lib/active_admin/views/components/table_for.rb +1 -1
- data/lib/active_admin/views/footer.rb +1 -1
- data/lib/active_admin/views/header.rb +3 -2
- data/lib/active_admin/views/index_as_block.rb +4 -0
- data/lib/active_admin/views/index_as_blog.rb +4 -0
- data/lib/active_admin/views/index_as_grid.rb +4 -0
- data/lib/active_admin/views/index_as_table.rb +49 -7
- data/lib/active_admin/views/pages/index.rb +19 -4
- data/lib/active_admin/views/tabbed_navigation.rb +10 -54
- data/lib/generators/active_admin/install/install_generator.rb +5 -1
- data/lib/generators/active_admin/install/templates/active_admin.rb.erb +58 -0
- data/spec/integration/{default_namespace.rb → default_namespace_spec.rb} +0 -16
- data/spec/spec_helper.rb +3 -0
- data/spec/support/detect_rails_version.rb +10 -3
- data/spec/support/rails_template.rb +1 -1
- data/spec/support/templates/post_decorator.rb +6 -6
- data/spec/unit/application_spec.rb +5 -5
- data/spec/unit/authorization/authorization_adapter_spec.rb +61 -0
- data/spec/unit/authorization/controller_authorization_spec.rb +47 -0
- data/spec/unit/base_controller_spec.rb +0 -2
- data/spec/unit/batch_actions/resource_spec.rb +1 -1
- data/spec/unit/breadcrumbs_spec.rb +3 -3
- data/spec/unit/cancan_adapter_spec.rb +35 -0
- data/spec/unit/config_shared_examples.rb +9 -30
- data/spec/unit/devise_spec.rb +29 -0
- data/spec/unit/dsl_spec.rb +61 -0
- data/spec/unit/filters/filter_form_builder_spec.rb +58 -4
- data/spec/unit/filters/resource_spec.rb +17 -5
- data/spec/unit/form_builder_spec.rb +15 -0
- data/spec/unit/menu_collection_spec.rb +62 -0
- data/spec/unit/menu_item_spec.rb +51 -37
- data/spec/unit/menu_spec.rb +33 -29
- data/spec/unit/namespace/authorization_spec.rb +31 -0
- data/spec/unit/namespace/register_page_spec.rb +6 -28
- data/spec/unit/namespace/register_resource_spec.rb +11 -34
- data/spec/unit/namespace_spec.rb +63 -2
- data/spec/unit/page_controller_spec.rb +0 -3
- data/spec/unit/reloader_spec.rb +5 -5
- data/spec/unit/resource/menu_spec.rb +1 -13
- data/spec/unit/resource/naming_spec.rb +20 -2
- data/spec/unit/resource/page_presenters_spec.rb +14 -2
- data/spec/unit/resource_controller/{collection_spec.rb → data_access_spec.rb} +31 -13
- data/spec/unit/resource_controller_spec.rb +4 -5
- data/spec/unit/resource_spec.rb +33 -11
- data/spec/unit/routing_spec.rb +43 -0
- data/spec/unit/scope_spec.rb +13 -0
- data/spec/unit/view_factory_spec.rb +0 -1
- data/spec/unit/view_helpers/fields_for_spec.rb +4 -0
- data/spec/unit/view_helpers/form_helper_spec.rb +6 -2
- data/spec/unit/view_helpers/method_or_proc_helper_spec.rb +97 -0
- data/spec/unit/views/components/attributes_table_spec.rb +11 -0
- data/spec/unit/views/components/index_list_spec.rb +32 -0
- data/spec/unit/views/tabbed_navigation_spec.rb +42 -40
- data/tasks/test.rake +1 -1
- metadata +127 -40
- data/lib/active_admin/menu_builder.rb +0 -65
- data/lib/active_admin/resource_controller/callbacks.rb +0 -59
- data/lib/active_admin/resource_controller/collection.rb +0 -158
- data/lib/active_admin/views/utility_nav.rb +0 -41
- data/spec/unit/base_controller_shared_examples.rb +0 -25
- data/spec/unit/dsl_include_spec.rb +0 -20
data/spec/unit/namespace_spec.rb
CHANGED
@@ -23,9 +23,9 @@ describe ActiveAdmin::Namespace do
|
|
23
23
|
if ActiveAdmin::Dashboards.built?
|
24
24
|
# DEPRECATED behavior. If a dashboard was built while running this
|
25
25
|
# spec, then an item gets added to the menu
|
26
|
-
namespace.
|
26
|
+
namespace.fetch_menu(:default).children.should_not be_empty
|
27
27
|
else
|
28
|
-
namespace.
|
28
|
+
namespace.fetch_menu(:default).children.should be_empty
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end # context "when new"
|
@@ -45,4 +45,65 @@ describe ActiveAdmin::Namespace do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
|
49
|
+
describe "#fetch_menu" do
|
50
|
+
let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
|
51
|
+
|
52
|
+
it "returns the menu" do
|
53
|
+
namespace.fetch_menu(:default).should be_an_instance_of(ActiveAdmin::Menu)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should have utility nav menu" do
|
57
|
+
namespace.fetch_menu(:utility_navigation).should be_an_instance_of(ActiveAdmin::Menu)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should raise an exception if the menu doesn't exist" do
|
61
|
+
expect {
|
62
|
+
namespace.fetch_menu(:not_a_menu_that_exists)
|
63
|
+
}.to raise_error(KeyError)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#build_menu" do
|
68
|
+
let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
|
69
|
+
|
70
|
+
it "should set the block as a menu build callback" do
|
71
|
+
namespace.build_menu do |menu|
|
72
|
+
menu.add :label => "menu item"
|
73
|
+
end
|
74
|
+
|
75
|
+
namespace.fetch_menu(:default)["menu item"].should_not be_nil
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should set a block on a custom menu" do
|
79
|
+
namespace.build_menu :test do |menu|
|
80
|
+
menu.add :label => "menu item"
|
81
|
+
end
|
82
|
+
|
83
|
+
namespace.fetch_menu(:test)["menu item"].should_not be_nil
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "utility navigation" do
|
88
|
+
let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
|
89
|
+
let(:menu) do
|
90
|
+
namespace.build_menu :utility_navigation do |menu|
|
91
|
+
menu.add :label => "ActiveAdmin.info", :url => "http://www.activeadmin.info", :html_options => { :target => :blank }
|
92
|
+
namespace.add_logout_button_to_menu menu, 1, :class => "matt"
|
93
|
+
end
|
94
|
+
namespace.fetch_menu(:utility_navigation)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should have a logout button to the far left" do
|
98
|
+
menu["Logout"].should_not be_nil
|
99
|
+
menu["Logout"].priority.should == 1
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should have a static link with a target of :blank" do
|
103
|
+
menu["ActiveAdmin.info"].should_not be_nil
|
104
|
+
menu["ActiveAdmin.info"].html_options.should include(:target => :blank)
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
48
109
|
end
|
data/spec/unit/reloader_spec.rb
CHANGED
@@ -23,13 +23,13 @@ describe ActiveAdmin::Reloader do
|
|
23
23
|
let(:reloader){ ActiveAdmin::Reloader.build(rails_app, mock_app, rails_version) }
|
24
24
|
|
25
25
|
context "when Rails version < 3.2" do
|
26
|
-
let(:rails_version){
|
26
|
+
let(:rails_version){ TRAVIS_RAILS_VERSIONS.grep(/^3.1/).first }
|
27
27
|
|
28
28
|
describe "initialization" do
|
29
29
|
|
30
30
|
it "should initialize a new file update checker" do
|
31
31
|
ActiveSupport::FileUpdateChecker.should_receive(:new).with(mock_app.load_paths).and_return(mock(:execute_if_updated => true))
|
32
|
-
ActiveAdmin::Reloader.build(rails_app, mock_app,
|
32
|
+
ActiveAdmin::Reloader.build(rails_app, mock_app, TRAVIS_RAILS_VERSIONS.grep(/^3.1/).first)
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should build a RailsLessThan31Reloader" do
|
@@ -41,12 +41,12 @@ describe ActiveAdmin::Reloader do
|
|
41
41
|
describe "#reloader_class" do
|
42
42
|
|
43
43
|
it "should use ActionDispatch::Reloader if rails 3.1" do
|
44
|
-
reloader = ActiveAdmin::Reloader.build rails_app, mock_app,
|
44
|
+
reloader = ActiveAdmin::Reloader.build rails_app, mock_app, TRAVIS_RAILS_VERSIONS.grep(/^3.1/).first
|
45
45
|
reloader.reloader_class.should == ActionDispatch::Reloader
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should use ActionDispatch::Callbacks if rails 3.0" do
|
49
|
-
reloader = ActiveAdmin::Reloader.build rails_app, mock_app,
|
49
|
+
reloader = ActiveAdmin::Reloader.build rails_app, mock_app, TRAVIS_RAILS_VERSIONS.grep(/^3.0/).first
|
50
50
|
reloader.reloader_class.should == ActionDispatch::Callbacks
|
51
51
|
end
|
52
52
|
|
@@ -94,7 +94,7 @@ describe ActiveAdmin::Reloader do
|
|
94
94
|
end
|
95
95
|
|
96
96
|
context "when Rails >= 3.2" do
|
97
|
-
let(:rails_version){
|
97
|
+
let(:rails_version){ TRAVIS_RAILS_VERSIONS.grep(/^3.2/).first }
|
98
98
|
|
99
99
|
describe "initialization" do
|
100
100
|
|
@@ -12,19 +12,7 @@ module ActiveAdmin
|
|
12
12
|
@config ||= Resource.new(namespace, Category, options)
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
let(:namespace){ ActiveAdmin::Namespace.new(application, :admin) }
|
17
|
-
subject{ resource }
|
15
|
+
# TODO...
|
18
16
|
|
19
|
-
context "when belongs to" do
|
20
|
-
let(:resource){ namespace.register(Post){ belongs_to :author } }
|
21
|
-
it { should_not be_include_in_menu }
|
22
|
-
end
|
23
|
-
|
24
|
-
context "when belongs to optional" do
|
25
|
-
let(:resource){ namespace.register(Post){ belongs_to :author, :optional => true} }
|
26
|
-
it { should be_include_in_menu }
|
27
|
-
end
|
28
|
-
end
|
29
17
|
end
|
30
18
|
end
|
@@ -61,7 +61,7 @@ module ActiveAdmin
|
|
61
61
|
describe "I18n integration" do
|
62
62
|
describe "singular label" do
|
63
63
|
it "should return the titleized model_name.human" do
|
64
|
-
config.resource_name.should_receive(:
|
64
|
+
config.resource_name.should_receive(:translate).and_return "Da category"
|
65
65
|
|
66
66
|
config.resource_label.should == "Da category"
|
67
67
|
end
|
@@ -69,11 +69,29 @@ module ActiveAdmin
|
|
69
69
|
|
70
70
|
describe "plural label" do
|
71
71
|
it "should return the titleized plural version defined by i18n if available" do
|
72
|
-
|
72
|
+
config.resource_name.should_receive(:translate).at_least(:once).and_return "Da categories"
|
73
73
|
config.plural_resource_label.should == "Da categories"
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
context "when the :as option is given" do
|
78
|
+
describe "singular label" do
|
79
|
+
it "should translate the custom name" do
|
80
|
+
config = config(:as => 'My Category')
|
81
|
+
config.resource_name.should_receive(:translate).and_return "Translated category"
|
82
|
+
config.resource_label.should == "Translated category"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "plural label" do
|
87
|
+
it "should translate the custom name" do
|
88
|
+
config = config(:as => 'My Category')
|
89
|
+
config.resource_name.should_receive(:translate).at_least(:once).and_return "Translated categories"
|
90
|
+
config.plural_resource_label.should == "Translated categories"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
77
95
|
end
|
78
96
|
end
|
79
97
|
|
@@ -9,10 +9,16 @@ describe ActiveAdmin::Resource::PagePresenters do
|
|
9
9
|
resource.page_presenters.should == {}
|
10
10
|
end
|
11
11
|
|
12
|
-
it "should add a page presenter" do
|
12
|
+
it "should add a show page presenter" do
|
13
13
|
page_presenter = ActiveAdmin::PagePresenter.new
|
14
|
+
resource.set_page_presenter(:show, page_presenter)
|
15
|
+
resource.page_presenters[:show].should == page_presenter
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should add an index page presenter" do
|
19
|
+
page_presenter = ActiveAdmin::PagePresenter.new({:as => :table})
|
14
20
|
resource.set_page_presenter(:index, page_presenter)
|
15
|
-
resource.page_presenters[:index].should == page_presenter
|
21
|
+
resource.page_presenters[:index].default.should == page_presenter
|
16
22
|
end
|
17
23
|
|
18
24
|
describe "#get_page_presenter" do
|
@@ -23,6 +29,12 @@ describe ActiveAdmin::Resource::PagePresenters do
|
|
23
29
|
resource.get_page_presenter(:index).should == page_presenter
|
24
30
|
end
|
25
31
|
|
32
|
+
it "should return a specific index page config when set" do
|
33
|
+
page_presenter = ActiveAdmin::PagePresenter.new
|
34
|
+
resource.set_page_presenter(:index, page_presenter)
|
35
|
+
resource.get_page_presenter(:index, "table").should == page_presenter
|
36
|
+
end
|
37
|
+
|
26
38
|
it "should return nil when no page config set" do
|
27
39
|
resource.get_page_presenter(:index).should == nil
|
28
40
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe ActiveAdmin::ResourceController::
|
3
|
+
describe ActiveAdmin::ResourceController::DataAccess do
|
4
4
|
let(:params) do
|
5
5
|
{}
|
6
6
|
end
|
@@ -13,29 +13,45 @@ describe ActiveAdmin::ResourceController::Collection do
|
|
13
13
|
rc
|
14
14
|
end
|
15
15
|
|
16
|
-
describe
|
16
|
+
describe "searching" do
|
17
17
|
let(:params){ {:q => {} }}
|
18
|
+
|
18
19
|
it "should call the metasearch method" do
|
19
20
|
chain = mock("ChainObj")
|
20
21
|
chain.should_receive(:metasearch).with(params[:q]).once.and_return(Post.search)
|
21
|
-
controller.send :
|
22
|
+
controller.send :apply_filtering, chain
|
22
23
|
end
|
24
|
+
|
23
25
|
end
|
24
26
|
|
25
|
-
describe
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
describe "sorting" do
|
28
|
+
|
29
|
+
context "for table columns" do
|
30
|
+
let(:params){ {:order => "id_asc" }}
|
31
|
+
it "should prepend the table name" do
|
32
|
+
chain = mock("ChainObj")
|
33
|
+
chain.should_receive(:reorder).with("\"posts\".\"id\" asc").once.and_return(Post.search)
|
34
|
+
controller.send :apply_sorting, chain
|
35
|
+
end
|
31
36
|
end
|
37
|
+
|
38
|
+
context "for virtual columns" do
|
39
|
+
let(:params){ {:order => "virtual_id_asc" }}
|
40
|
+
it "should not prepend the table name" do
|
41
|
+
chain = mock("ChainObj")
|
42
|
+
chain.should_receive(:reorder).with("\"virtual_id\" asc").once.and_return(Post.search)
|
43
|
+
controller.send :apply_sorting, chain
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
32
47
|
end
|
33
|
-
|
34
|
-
describe
|
48
|
+
|
49
|
+
describe "scoping" do
|
50
|
+
|
35
51
|
context "when no current scope" do
|
36
52
|
it "should set collection_before_scope to the chain and return the chain" do
|
37
53
|
chain = mock("ChainObj")
|
38
|
-
controller.send(:
|
54
|
+
controller.send(:apply_scoping, chain).should == chain
|
39
55
|
controller.send(:collection_before_scope).should == chain
|
40
56
|
end
|
41
57
|
end
|
@@ -48,9 +64,11 @@ describe ActiveAdmin::ResourceController::Collection do
|
|
48
64
|
controller.stub!(:current_scope) { current_scope }
|
49
65
|
|
50
66
|
controller.should_receive(:scope_chain).with(current_scope, chain) { scoped_chain }
|
51
|
-
controller.send(:
|
67
|
+
controller.send(:apply_scoping, chain).should == scoped_chain
|
52
68
|
controller.send(:collection_before_scope).should == chain
|
53
69
|
end
|
54
70
|
end
|
71
|
+
|
55
72
|
end
|
73
|
+
|
56
74
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require File.expand_path('base_controller_shared_examples', File.dirname(__FILE__))
|
3
2
|
|
4
3
|
describe ActiveAdmin::ResourceController do
|
5
4
|
|
@@ -7,8 +6,6 @@ describe ActiveAdmin::ResourceController do
|
|
7
6
|
|
8
7
|
let(:controller) { ActiveAdmin::ResourceController.new }
|
9
8
|
|
10
|
-
it_should_behave_like "BaseController"
|
11
|
-
|
12
9
|
describe "authenticating the user" do
|
13
10
|
let(:controller){ Admin::PostsController.new }
|
14
11
|
|
@@ -115,10 +112,10 @@ describe ActiveAdmin::ResourceController do
|
|
115
112
|
describe "performing update" do
|
116
113
|
let(:controller){ Admin::PostsController.new }
|
117
114
|
let(:resource){ mock("Resource", :attributes= => true, :save => true) }
|
118
|
-
let(:attributes){ {} }
|
115
|
+
let(:attributes){ [{}] }
|
119
116
|
|
120
117
|
before do
|
121
|
-
resource.should_receive(:attributes=).with(attributes)
|
118
|
+
resource.should_receive(:attributes=).with(attributes[0])
|
122
119
|
resource.should_receive(:save)
|
123
120
|
end
|
124
121
|
|
@@ -166,6 +163,7 @@ describe Admin::PostsController, :type => "controller" do
|
|
166
163
|
describe 'retreiving the resource' do
|
167
164
|
let(:controller){ Admin::PostsController.new }
|
168
165
|
let(:post) { Post.new :title => "An incledibly unique Post Title" }
|
166
|
+
|
169
167
|
before do
|
170
168
|
Post.stub(:find).and_return(post)
|
171
169
|
controller.class_eval { public :resource }
|
@@ -173,6 +171,7 @@ describe Admin::PostsController, :type => "controller" do
|
|
173
171
|
end
|
174
172
|
|
175
173
|
subject { controller.resource }
|
174
|
+
|
176
175
|
it "returns a Post" do
|
177
176
|
subject.should be_kind_of(Post)
|
178
177
|
end
|
data/spec/unit/resource_spec.rb
CHANGED
@@ -28,6 +28,12 @@ module ActiveAdmin
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
describe "#resource_column_names" do
|
32
|
+
it "should return the resource's column names" do
|
33
|
+
config.resource_column_names.should == Category.column_names
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
31
37
|
describe '#decorator_class' do
|
32
38
|
it 'returns nil by default' do
|
33
39
|
config.decorator_class.should be_nil
|
@@ -65,26 +71,35 @@ module ActiveAdmin
|
|
65
71
|
let(:resource){ namespace.register(Post) }
|
66
72
|
it { should be_include_in_menu }
|
67
73
|
end
|
68
|
-
|
69
|
-
let(:resource){ namespace.register(Post){ belongs_to :author } }
|
70
|
-
it { should_not be_include_in_menu }
|
71
|
-
end
|
72
|
-
context "when belongs to optional" do
|
73
|
-
let(:resource){ namespace.register(Post){ belongs_to :author, :optional => true} }
|
74
|
-
it { should be_include_in_menu }
|
75
|
-
end
|
74
|
+
|
76
75
|
context "when menu set to false" do
|
77
76
|
let(:resource){ namespace.register(Post){ menu false } }
|
78
77
|
it { should_not be_include_in_menu }
|
79
78
|
end
|
80
79
|
end
|
81
80
|
|
81
|
+
describe "#belongs_to" do
|
82
|
+
|
83
|
+
it "should build a belongs to configuration" do
|
84
|
+
config.belongs_to_config.should be_nil
|
85
|
+
config.belongs_to :posts
|
86
|
+
config.belongs_to_config.should_not be_nil
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should set the target menu to the belongs to target" do
|
90
|
+
config.menu_item_menu_name.should == ActiveAdmin::DEFAULT_MENU
|
91
|
+
config.belongs_to :posts
|
92
|
+
config.menu_item_menu_name.should == :posts
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
82
97
|
describe "route names" do
|
83
98
|
it "should return the route prefix" do
|
84
99
|
config.route_prefix.should == "admin"
|
85
100
|
end
|
86
101
|
it "should return the route collection path" do
|
87
|
-
config.route_collection_path.should ==
|
102
|
+
config.route_collection_path.should == "/admin/categories"
|
88
103
|
end
|
89
104
|
|
90
105
|
context "when in the root namespace" do
|
@@ -92,14 +107,21 @@ module ActiveAdmin
|
|
92
107
|
it "should have a nil route_prefix" do
|
93
108
|
config.route_prefix.should == nil
|
94
109
|
end
|
110
|
+
|
111
|
+
it "should generate a correct route" do
|
112
|
+
config
|
113
|
+
reload_routes!
|
114
|
+
config.route_collection_path.should == "/categories"
|
115
|
+
end
|
95
116
|
end
|
96
117
|
|
97
118
|
context "when registering a plural resource" do
|
98
119
|
class ::News; def self.has_many(*); end end
|
99
120
|
|
100
|
-
let(:config){ application.register News }
|
101
121
|
it "should return the plurali route with _index" do
|
102
|
-
config.
|
122
|
+
config = application.register News
|
123
|
+
reload_routes!
|
124
|
+
config.route_collection_path.should == "/admin/news"
|
103
125
|
end
|
104
126
|
end
|
105
127
|
end
|
data/spec/unit/routing_spec.rb
CHANGED
@@ -111,6 +111,49 @@ describe ActiveAdmin, "Routing", :type => :routing do
|
|
111
111
|
edit_post_path(1).should == "/posts/1/edit"
|
112
112
|
end
|
113
113
|
end
|
114
|
+
|
115
|
+
context "with member action" do
|
116
|
+
context "without an http verb" do
|
117
|
+
before do
|
118
|
+
load_resources do
|
119
|
+
ActiveAdmin.register(Post){ member_action "do_something" }
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should default to GET" do
|
124
|
+
{:get => "/admin/posts/1/do_something"}.should be_routable
|
125
|
+
{:post => "/admin/posts/1/do_something"}.should_not be_routable
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context "with one http verb" do
|
130
|
+
before do
|
131
|
+
load_resources do
|
132
|
+
ActiveAdmin.register(Post){ member_action "do_something", :method => :post }
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should properly route" do
|
137
|
+
{:post => "/admin/posts/1/do_something"}.should be_routable
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context "with two http verbs" do
|
142
|
+
before do
|
143
|
+
load_resources do
|
144
|
+
ActiveAdmin.register(Post){ member_action "do_something", :method => [:put, :delete] }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should properly route the first verb" do
|
149
|
+
{:put => "/admin/posts/1/do_something"}.should be_routable
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should properly route the second verb" do
|
153
|
+
{:delete => "/admin/posts/1/do_something"}.should be_routable
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
114
157
|
end
|
115
158
|
|
116
159
|
describe "belongs to resource" do
|