properly handle Admin::AbilitiesController in params[:controller] - closes #46

This commit is contained in:
Ryan Bates 2010-04-15 13:10:12 -07:00
parent 6e1e96c85a
commit f2a1695636
2 changed files with 8 additions and 1 deletions

View File

@ -48,7 +48,7 @@ module CanCan
end end
def model_name def model_name
params[:controller].split('/').last.singularize params[:controller].sub("Controller", "").underscore.split('/').last.singularize
end end
def collection_actions def collection_actions

View File

@ -20,6 +20,13 @@ describe CanCan::ResourceAuthorization do
@controller.instance_variable_get(:@ability).should == :some_resource @controller.instance_variable_get(:@ability).should == :some_resource
end 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 it "should build a new resource with hash if params[:id] is not specified" do
stub(Ability).new(:foo => "bar") { :some_resource } stub(Ability).new(:foo => "bar") { :some_resource }
authorization = CanCan::ResourceAuthorization.new(@controller, :controller => "abilities", :action => "create", :ability => {:foo => "bar"}) authorization = CanCan::ResourceAuthorization.new(@controller, :controller => "abilities", :action => "create", :ability => {:foo => "bar"})