Named resources were not being loaded correctly. Fixes #633

This commit is contained in:
Oliver Morgan 2012-05-30 12:39:10 +01:00
parent ccd24ab30f
commit 78cbcf1db9
2 changed files with 14 additions and 1 deletions

View File

@ -145,7 +145,7 @@ module CanCan
def resource_class
case @options[:class]
when false then name.to_sym
when nil then namespaced_name.to_s.camelize.constantize
when nil then (@name || namespaced_name).to_s.classify.constantize
when String then @options[:class].constantize
else @options[:class]
end

View File

@ -223,6 +223,19 @@ describe CanCan::ControllerResource do
@controller.instance_variable_get(:@project).should be_nil
end
it "named resources should not be loaded independently of the controller" do
category = Category.create!
@params.merge!(:action => "new", :category_id => category.id)
CanCan::ControllerResource.new(@controller, :category, :load => true).process
CanCan::ControllerResource.new(@controller, :project, :load => true, :through => :category).process
@controller.instance_variable_get(:@category).should eq(category)
project = @controller.instance_variable_get(:@project)
project.category.should eq(category)
end
it "authorizes nested resource through parent association on index action" do
pending
@params.merge!(:action => "index")