Skip to content

Commit

Permalink
Fixes Nested Resource Loading
Browse files Browse the repository at this point in the history
  • Loading branch information
marksim authored and andhapp committed Jun 18, 2012
1 parent 7bf683d commit d5baed6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/cancan/controller_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions spec/cancan/controller_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d5baed6

Please sign in to comment.