From 0ad856a5d34514b1ebfebcf14e2662124a23c3e8 Mon Sep 17 00:00:00 2001 From: Greg Bell Date: Tue, 26 Jul 2011 22:06:51 +0800 Subject: [PATCH] Fixed issues with default_namespace when false or nil. Closes #186 --- lib/active_admin/application.rb | 3 +- spec/integration/default_namespace.rb | 77 +++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 spec/integration/default_namespace.rb diff --git a/lib/active_admin/application.rb b/lib/active_admin/application.rb index 73cb1ed6319..741b2fa4768 100644 --- a/lib/active_admin/application.rb +++ b/lib/active_admin/application.rb @@ -79,13 +79,14 @@ def prepare! # Registers a brand new configuration for the given resource. def register(resource, options = {}, &block) - namespace_name = options[:namespace] == false ? :root : (options[:namespace] || default_namespace || :root) + namespace_name = options.has_key?(:namespace) ? options[:namespace] : default_namespace namespace = find_or_create_namespace(namespace_name) namespace.register(resource, options, &block) end # Creates a namespace for the given name def find_or_create_namespace(name) + name ||= :root return namespaces[name] if namespaces[name] namespace = Namespace.new(self, name) ActiveAdmin::Event.dispatch ActiveAdmin::Namespace::RegisterEvent, namespace diff --git a/spec/integration/default_namespace.rb b/spec/integration/default_namespace.rb new file mode 100644 index 00000000000..b2d64e1a1d7 --- /dev/null +++ b/spec/integration/default_namespace.rb @@ -0,0 +1,77 @@ +require 'spec_helper' + +describe ActiveAdmin::Application do + + include Rails.application.routes.url_helpers + + [false, nil].each do |value| + + describe "with a #{value} default namespace" do + + before(:all) do + @__original_application = ActiveAdmin.application + application = ActiveAdmin::Application.new + application.default_namespace = value + ActiveAdmin.application = application + load_defaults! + reload_routes! + end + + after(:all) do + ActiveAdmin.application = @__original_application + end + + it "should generate a dashboard controller" do + defined?(::DashboardController).should be_true + end + + it "should generate a dashboard route" do + dashboard_path.should == "/" + end + + it "should generate a log out path" do + destroy_admin_user_session_path.should == "/admin_users/logout" + end + + it "should generate a log in path" do + new_admin_user_session_path.should == "/admin_users/login" + end + + end + + end + + describe "with a test default namespace" do + + before(:all) do + @__original_application = ActiveAdmin.application + application = ActiveAdmin::Application.new + application.default_namespace = :test + ActiveAdmin.application = application + load_defaults! + reload_routes! + end + + after(:all) do + ActiveAdmin.application = @__original_application + end + + it "should generate a dashboard controller" do + defined?(::Test::DashboardController).should be_true + end + + it "should generate a dashboard route" do + test_dashboard_path.should == "/test" + end + + it "should generate a log out path" do + destroy_admin_user_session_path.should == "/test/logout" + end + + it "should generate a log in path" do + new_admin_user_session_path.should == "/test/login" + end + + end + +end