Permalink
Browse files

properly handle Admin::AbilitiesController in params[:controller] - c…

…loses #46
  • Loading branch information...
1 parent 6e1e96c commit f2a16956363b73b4f3dd0db4622aa257e9e865ad @ryanb committed Apr 15, 2010
Showing with 8 additions and 1 deletion.
  1. +1 −1 lib/cancan/resource_authorization.rb
  2. +7 −0 spec/cancan/resource_authorization_spec.rb
@@ -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
@@ -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"})

0 comments on commit f2a1695

Please sign in to comment.