Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #668 from bukalapak/2.0
Browse files Browse the repository at this point in the history
Fix namespace split
  • Loading branch information
ryanb committed Jul 2, 2012
2 parents 6886aec + 6c1828a commit aed9f26
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cancan/controller_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def resource_params
end

def namespace
@params[:controller].split("::")[0..-2]
@params[:controller].split(/::|\//)[0..-2]
end

def namespaced_name
Expand Down
11 changes: 11 additions & 0 deletions spec/cancan/controller_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aed9f26

Please sign in to comment.