Merge pull request #635 from ollym/2.0
Named resources were not loading correctly in 2.0
This commit is contained in:
commit
76d465ae13
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue
Block a user