renaming :class option to :resource for load_and_authorize_resource which now supports a symbol for non models - closes #45

This commit is contained in:
Ryan Bates
2010-04-15 14:14:22 -07:00
parent f2a1695636
commit 23a5888fe0
6 changed files with 39 additions and 11 deletions

View File

@@ -43,7 +43,17 @@ describe CanCan::ControllerResource do
it "should use the model class option if provided" do
stub(Person).find(123) { :some_resource }
CanCan::ControllerResource.new(@controller, :ability, nil, :class => Person).find(123)
CanCan::ControllerResource.new(@controller, :ability, nil, :resource => Person).find(123)
@controller.instance_variable_get(:@ability).should == :some_resource
end
it "should convert string to constant for resource" do
CanCan::ControllerResource.new(@controller, :ability, nil, :resource => "Person").model_class.should == Person
end
it "should raise an exception when specifying :class option since it is no longer used" do
lambda {
CanCan::ControllerResource.new(@controller, :ability, nil, :class => Person)
}.should raise_error
end
end

View File

@@ -115,7 +115,7 @@ describe CanCan::ResourceAuthorization do
it "should load the model using a custom class" do
stub(Person).find(123) { :some_resource }
authorization = CanCan::ResourceAuthorization.new(@controller, {:controller => "abilities", :action => "show", :id => 123}, {:class => Person})
authorization = CanCan::ResourceAuthorization.new(@controller, {:controller => "abilities", :action => "show", :id => 123}, {:resource => Person})
authorization.load_resource
@controller.instance_variable_get(:@ability).should == :some_resource
end