Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Named resources were not loading correctly in 2.0 #635

Merged
merged 3 commits into from
Jun 11, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cancan/controller_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def resource_params
end

def namespaced_name
@params[:controller].sub("Controller", "").singularize.camelize.constantize
(@name || @params[:controller].sub("Controller", "")).singularize.camelize.constantize
rescue NameError
name
end
Expand Down
25 changes: 25 additions & 0 deletions spec/cancan/controller_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,31 @@ class CustomModel
@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")
Expand Down