don't pass nil to 'new' call when no params are specified - closes #63

This commit is contained in:
Ryan Bates 2010-08-05 16:52:37 -07:00
parent 156839b73e
commit 67b069579e
2 changed files with 4 additions and 4 deletions

View File

@ -41,7 +41,7 @@ module CanCan
def load_resource_instance
if !parent? && new_actions.include?(@params[:action].to_sym)
resource_base.kind_of?(Class) ? resource_base.new(@params[name.to_sym]) : resource_base.build(@params[name.to_sym])
@params[name.to_sym] ? resource_base.new(@params[name.to_sym]) : resource_base.new
elsif id_param
resource_base.find(id_param)
end

View File

@ -40,8 +40,8 @@ describe CanCan::ControllerResource do
@controller.instance_variable_get(:@ability).should == :some_resource
end
it "should build a new resource even if attribute hash isn't specified" do
stub(Ability).new(nil) { :some_resource }
it "should build a new resource with no arguments if attribute hash isn't specified" do
mock(Ability).new { :some_resource }
resource = CanCan::ControllerResource.new(@controller, :controller => "abilities", :action => "new")
resource.load_resource
@controller.instance_variable_get(:@ability).should == :some_resource
@ -80,7 +80,7 @@ describe CanCan::ControllerResource do
end
it "should build a resource when on custom new action even when params[:id] exists" do
stub(Ability).new(nil) { :some_resource }
stub(Ability).new { :some_resource }
resource = CanCan::ControllerResource.new(@controller, {:controller => "abilities", :action => "build", :id => 123}, {:new => :build})
resource.load_resource
@controller.instance_variable_get(:@ability).should == :some_resource