Permalink
Browse files

Named resources were not being loaded correctly. Fixes #633

  • Loading branch information...
1 parent ccd24ab commit 78cbcf1db97a5574258c8327a891d1c444941d80 @ollym ollym committed May 30, 2012
Showing with 14 additions and 1 deletion.
  1. +1 −1 lib/cancan/controller_resource.rb
  2. +13 −0 spec/cancan/controller_resource_spec.rb
@@ -145,7 +145,7 @@ def member_action?
def resource_class
case @options[:class]
when false then name.to_sym
- when nil then namespaced_name.to_s.camelize.constantize
+ when nil then (@name || namespaced_name).to_s.classify.constantize
when String then @options[:class].constantize
else @options[:class]
end
@@ -222,6 +222,19 @@ class CustomModel
}
@controller.instance_variable_get(:@project).should be_nil
end
+
+ it "named resources should not be loaded independently of the controller" 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 "authorizes nested resource through parent association on index action" do
pending

0 comments on commit 78cbcf1

Please sign in to comment.