Fixed bug where parent resources were being regarded as children

This commit is contained in:
Oliver Morgan 2012-06-04 17:44:33 +01:00
parent 245b83f6b4
commit 354e34b8ab
2 changed files with 14 additions and 2 deletions

View File

@ -145,7 +145,7 @@ module CanCan
def resource_class def resource_class
case @options[:class] case @options[:class]
when false then name.to_sym when false then name.to_sym
when nil then (@name || namespaced_name).to_s.camelize.constantize when nil then namespaced_name.to_s.camelize.constantize
when String then @options[:class].constantize when String then @options[:class].constantize
else @options[:class] else @options[:class]
end end
@ -230,7 +230,7 @@ module CanCan
end end
def namespaced_name def namespaced_name
@params[:controller].sub("Controller", "").singularize.camelize.constantize (@name || @params[:controller].sub("Controller", "")).singularize.camelize.constantize
rescue NameError rescue NameError
name name
end end

View File

@ -235,6 +235,18 @@ describe CanCan::ControllerResource do
project = @controller.instance_variable_get(:@project) project = @controller.instance_variable_get(:@project)
project.category.should eq(category) project.category.should eq(category)
end 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 it "authorizes nested resource through parent association on index action" do
pending pending