From ce7d3fecdb8550c5c7f6f105a8293d847781ca61 Mon Sep 17 00:00:00 2001 From: Nugroho Herucahyono Date: Fri, 29 Jun 2012 18:27:11 +0700 Subject: [PATCH] porting #668 to 1.6.x --- lib/cancan/controller_resource.rb | 2 +- spec/cancan/controller_resource_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/cancan/controller_resource.rb b/lib/cancan/controller_resource.rb index 3b90c0f..64a3053 100644 --- a/lib/cancan/controller_resource.rb +++ b/lib/cancan/controller_resource.rb @@ -220,7 +220,7 @@ module CanCan end def namespace - @params[:controller].split("::")[0..-2] + @params[:controller].split(/::|\//)[0..-2] end def namespaced_name diff --git a/spec/cancan/controller_resource_spec.rb b/spec/cancan/controller_resource_spec.rb index 34f3868..33da049 100644 --- a/spec/cancan/controller_resource_spec.rb +++ b/spec/cancan/controller_resource_spec.rb @@ -67,6 +67,16 @@ describe CanCan::ControllerResource do @controller.instance_variable_get(:@project).should == project end + it "has the specified nested resource_class when using / for namespace" do + module Admin + class Dashboard; end + end + @ability.can(:index, "admin/dashboard") + @params.merge!(:controller => "admin/dashboard", :action => "index") + resource = CanCan::ControllerResource.new(@controller, :authorize => true) + resource.send(:resource_class).should == Admin::Dashboard + end + it "should build a new resource with hash if params[:id] is not specified" do @params.merge!(:action => "create", :project => {:name => "foobar"}) resource = CanCan::ControllerResource.new(@controller)