Permalink
Browse files

Merge pull request #635 from ollym/2.0

Named resources were not loading correctly in 2.0
  • Loading branch information...
ryanb committed Jun 11, 2012
2 parents ccd24ab + 354e34b commit 76d465ae13cabb1e803d61ea3972189290163fd0
Showing with 26 additions and 1 deletion.
  1. +1 −1 lib/cancan/controller_resource.rb
  2. +25 −0 spec/cancan/controller_resource_spec.rb
@@ -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
@@ -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")

0 comments on commit 76d465a

Please sign in to comment.