Permalink
Browse files

fix namespace split, so we can use / for namespace

  • Loading branch information...
1 parent 6886aec commit 6c1828acb6a8dbd8c1a258401a484a41665ce7f9 @xinuc xinuc committed Jun 29, 2012
Showing with 12 additions and 1 deletion.
  1. +1 −1 lib/cancan/controller_resource.rb
  2. +11 −0 spec/cancan/controller_resource_spec.rb
@@ -237,7 +237,7 @@ def resource_params
end
def namespace
- @params[:controller].split("::")[0..-2]
+ @params[:controller].split(/::|\//)[0..-2]
end
def namespaced_name
@@ -62,6 +62,17 @@ class Project < ::Project; end
@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")
+ @controller.authorize!(:index, "admin/dashboard")
+ resource = CanCan::ControllerResource.new(@controller, :authorize => true)
+ resource.send(:resource_class).should == Admin::Dashboard
+ end
+
it "builds a new resource with hash if params[:id] is not specified and authorize on each attribute" do
@params.merge!(:action => "create", :project => {:name => "foobar"})
CanCan::ControllerResource.new(@controller, :load => true).process

0 comments on commit 6c1828a

Please sign in to comment.