From 75ce2bdefab3ebec7f3a06af51f11fe390112000 Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Fri, 6 Aug 2010 14:26:57 -0700 Subject: [PATCH] allow :parent => false option to work in load/authorize resource --- lib/cancan/controller_resource.rb | 2 +- spec/cancan/controller_resource_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/cancan/controller_resource.rb b/lib/cancan/controller_resource.rb index 587e9c6..ba17d1f 100644 --- a/lib/cancan/controller_resource.rb +++ b/lib/cancan/controller_resource.rb @@ -34,7 +34,7 @@ module CanCan end def parent? - @options[:parent] || @name && @name != name_from_controller.to_sym + @options.has_key?(:parent) ? @options[:parent] : @name && @name != name_from_controller.to_sym end private diff --git a/spec/cancan/controller_resource_spec.rb b/spec/cancan/controller_resource_spec.rb index 8b8e693..bc26c22 100644 --- a/spec/cancan/controller_resource_spec.rb +++ b/spec/cancan/controller_resource_spec.rb @@ -122,6 +122,11 @@ describe CanCan::ControllerResource do resource.should be_parent end + it "should not be parent if specified in options" do + resource = CanCan::ControllerResource.new(@controller, :person, {:parent => false}) + resource.should_not be_parent + end + it "should load parent resource through proper id parameter when supplying a resource with a different name" do @params.merge!(:action => "index", :person_id => 123) stub(Person).find(123) { :some_person }