Permalink
Browse files

Fixes Nested Resource Loading

  • Loading branch information...
1 parent 7bf683d commit d5baed6281b4628071f8737090eaaec5168eacbf @marksim marksim committed with andhapp Oct 5, 2011
Showing with 13 additions and 1 deletion.
  1. +5 −1 lib/cancan/controller_resource.rb
  2. +8 −0 spec/cancan/controller_resource_spec.rb
@@ -215,8 +215,12 @@ def resource_params
end
end
+ def namespace
+ @params[:controller].split("::")[0..-2]
+ end
+
def namespaced_name
- @name || @params[:controller].sub("Controller", "").singularize.camelize.constantize
+ [namespace, name.camelize].join('::').singularize.camelize.constantize
rescue NameError
name
end
@@ -215,6 +215,14 @@ class Project < ::Project; end
resource.should_not be_parent
end
+ it "should have the specified resource_class if 'name' is passed to load_resource" do
+ class Section
+ end
+
+ resource = CanCan::ControllerResource.new(@controller, :section)
+ resource.send(:resource_class).should == Section
+ end
+
it "should load parent resource through proper id parameter" do
project = Project.create!
@params.merge!(:controller => "categories", :action => "index", :project_id => project.id)

0 comments on commit d5baed6

Please sign in to comment.