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

Commit

Permalink
properly handle Admin::AbilitiesController in params[:controller] - c…
Browse files Browse the repository at this point in the history
…loses #46
  • Loading branch information
ryanb committed Apr 15, 2010
1 parent 6e1e96c commit f2a1695
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/cancan/resource_authorization.rb
Expand Up @@ -48,7 +48,7 @@ def parent_resource
end

def model_name
params[:controller].split('/').last.singularize
params[:controller].sub("Controller", "").underscore.split('/').last.singularize
end

def collection_actions
Expand Down
7 changes: 7 additions & 0 deletions spec/cancan/resource_authorization_spec.rb
Expand Up @@ -20,6 +20,13 @@
@controller.instance_variable_get(:@ability).should == :some_resource
end

it "should properly load resource for namespaced controller when using '::' for namespace" do
stub(Ability).find(123) { :some_resource }
authorization = CanCan::ResourceAuthorization.new(@controller, :controller => "Admin::AbilitiesController", :action => "show", :id => 123)
authorization.load_resource
@controller.instance_variable_get(:@ability).should == :some_resource
end

it "should build a new resource with hash if params[:id] is not specified" do
stub(Ability).new(:foo => "bar") { :some_resource }
authorization = CanCan::ResourceAuthorization.new(@controller, :controller => "abilities", :action => "create", :ability => {:foo => "bar"})
Expand Down

0 comments on commit f2a1695

Please sign in to comment.