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

Allow ControllerResource#resource_class to utilize Proc's. #901

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions lib/cancan/controller_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def resource_class
when false then name.to_sym
when nil then namespaced_name.to_s.camelize.constantize
when String then @options[:class].constantize
when Proc then @options[:class].call(@controller)
else @options[:class]
end
end
Expand Down
5 changes: 5 additions & 0 deletions spec/cancan/controller_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ class Section
resource.send(:resource_class).should == Section
end

it "should have the specified resource_class if Proc is passed to load_resource" do
resource = CanCan::ControllerResource.new(@controller, :class => Proc.new { |controller| CanCan::ControllerResource })
resource.send(:resource_class).should == resource.class
end

it "should load parent resource through proper id parameter" do
project = Project.create!
@params.merge!(:controller => "categories", :action => "index", :project_id => project.id)
Expand Down