Skip to content

Commit

Permalink
Fixed issues with default_namespace when false or nil. Closes activea…
Browse files Browse the repository at this point in the history
  • Loading branch information
gregbell authored and whatthewhat committed Aug 13, 2011
1 parent 6b0b09d commit 0ad856a
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/active_admin/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
77 changes: 77 additions & 0 deletions spec/integration/default_namespace.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0ad856a

Please sign in to comment.