From a0a4c8b1000016bf3c64fe18189280e89089d9a5 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Tue, 24 Jul 2012 22:02:02 +0600 Subject: [PATCH] [refs #581] dont destroy child projects --- app/models/project.rb | 2 +- spec/models/project_spec.rb | 41 ++++++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index 927e7da61..24ab4d1ab 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -49,7 +49,7 @@ class Project < ActiveRecord::Base after_commit(:on => :create) {|p| p.import_attached_srpm if p.srpm?}# later with resque # should be after create_git_repo # after_rollback lambda { destroy_git_repo rescue true if new_record? } - has_ancestry + has_ancestry :orphan_strategy => :rootify #:adopt not available yet has_attached_file :srpm diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 572af1b76..b50c1e6a4 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1,6 +1,41 @@ # -*- encoding : utf-8 -*- require 'spec_helper' -#describe Project do -# pending "add some examples to (or delete) #{__FILE__}" -#end +describe Project do + before(:each) do + stub_symlink_methods + @root_project = FactoryGirl.create(:project) + @child_project = @root_project.fork(FactoryGirl.create(:user)) + @child_child_project = @child_project.fork(FactoryGirl.create(:user)) + end + + context 'for destroy root' do + before(:each) do + @root_project.destroy + end + + it "should not be delete child" do + Project.where(:id => @child_project).count.should == 1 + end + + it "should not be delete child of the child" do + Project.where(:id => @child_child_project).count.should == 1 + end + end + + # uncommit when will be available :orphan_strategy => :adopt + + #context 'for destroy middle node' do + # before(:each) do + # @child_project.destroy + # end + + # it "should set root project as a parent for orphan child" do + # Project.find(@child_child_project).ancestry == @root_project + # end + + # it "should not be delete child of the child" do + # Project.where(:id => @child_child_project).count.should == 1 + # end + #end +end \ No newline at end of file