use Item.new instead of build_item for singleton resource so it doesn't mess up database - closes #304

This commit is contained in:
Ryan Bates
2011-03-15 23:37:05 -07:00
parent fdd5ad022d
commit 3f6cecbfcf
3 changed files with 16 additions and 11 deletions
+3 -3
View File
@@ -268,14 +268,14 @@ describe CanCan::ControllerResource do
@controller.instance_variable_get(:@project).should == :some_project
end
it "should build record through has_one association with :singleton option" do
it "should not build record through has_one association with :singleton option because it can cause it to delete it in the database" do
@params.merge!(:action => "create", :project => {:name => "foobar"})
category = Object.new
category = Category.new
@controller.instance_variable_set(:@category, category)
stub(category).build_project { |attributes| Project.new(attributes) }
resource = CanCan::ControllerResource.new(@controller, :through => :category, :singleton => true)
resource.load_resource
@controller.instance_variable_get(:@project).name.should == "foobar"
@controller.instance_variable_get(:@project).category.should == category
end
it "should find record through has_one association with :singleton and :shallow options" do