porting #668 to master branch #675

Merged
merged 1 commit into from May 3, 2013
View
2 lib/cancan/controller_resource.rb
@@ -220,7 +220,7 @@ def resource_params
end
def namespace
- @params[:controller].split("::")[0..-2]
+ @params[:controller].split(/::|\//)[0..-2]
end
def namespaced_name
View
10 spec/cancan/controller_resource_spec.rb
@@ -67,6 +67,16 @@ 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")
+ 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)