Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…loses #46
  • Loading branch information...
commit f2a16956363b73b4f3dd0db4622aa257e9e865ad 1 parent 6e1e96c
@ryanb authored
View
2  lib/cancan/resource_authorization.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
View
7 spec/cancan/resource_authorization_spec.rb
@@ -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"})
Please sign in to comment.
Something went wrong with that request. Please try again.