Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Named resources were not loading correctly in 2.0 #635

Merged
merged 3 commits into from Jun 11, 2012
@@ -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")