Merge pull request #635 from ollym/2.0

Named resources were not loading correctly in 2.0
This commit is contained in:
Ryan Bates 2012-06-11 09:56:41 -07:00
commit 76d465ae13
2 changed files with 26 additions and 1 deletions

View File

@ -230,7 +230,7 @@ module CanCan
end
def namespaced_name
@params[:controller].sub("Controller", "").singularize.camelize.constantize
(@name || @params[:controller].sub("Controller", "")).singularize.camelize.constantize
rescue NameError
name
end

View File

@ -223,6 +223,31 @@ describe CanCan::ControllerResource do
@controller.instance_variable_get(:@project).should be_nil
end
it "named resources should be loaded independently of the controller name" 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 "parent resources shouldn't be altered" do
category = Category.create!
@params.merge!(:action => "create", :category_id => category.id, :project => { :name => 'foo' })
CanCan::ControllerResource.new(@controller, :category, :load => true).process
CanCan::ControllerResource.new(@controller, :project, :load => true, :through => :category).process
project = @controller.instance_variable_get(:@project)
project.new_record?.should eq(true)
project.name.should eq('foo')
end
it "authorizes nested resource through parent association on index action" do
pending
@params.merge!(:action => "index")