allow :find_by option to be full find method name - closes #335

This commit is contained in:
Ryan Bates
2011-05-19 23:37:36 -04:00
parent 6a01427317
commit c031f82dd2
4 changed files with 26 additions and 2 deletions
+8
View File
@@ -336,6 +336,14 @@ describe CanCan::ControllerResource do
@controller.instance_variable_get(:@project).should == project
end
it "should allow full find method to be passed into find_by option" do
project = Project.create!(:name => "foo")
@params.merge!(:action => "show", :id => "foo")
resource = CanCan::ControllerResource.new(@controller, :find_by => :find_by_name)
resource.load_resource
@controller.instance_variable_get(:@project).should == project
end
it "should raise ImplementationRemoved when adding :name option" do
lambda {
CanCan::ControllerResource.new(@controller, :name => :foo)
+8
View File
@@ -30,4 +30,12 @@ end
class Project < SuperModel::Base
belongs_to :category
attr_accessor :category # why doesn't SuperModel do this automatically?
def self.respond_to?(method, include_private = false)
if method.to_s == "find_by_name!" # hack to simulate ActiveRecord
true
else
super
end
end
end