Skip to content

Commit

Permalink
812346 - fixing org deletion envrionment error
Browse files Browse the repository at this point in the history
we need to delete environments in reverse
order of the promotion paths so that
we do not  leave any orphaned environments
which causes the deletion to fail
(cherry picked from commit 20794eb)
  • Loading branch information
jlsherrill committed Apr 16, 2012
1 parent f054729 commit f4b6a0e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/app/models/glue/candlepin/owner.rb
Expand Up @@ -50,7 +50,12 @@ def del_owner

def del_environments
Rails.logger.debug _("All environments for owner %s in candlepin") % name
self.environments.destroy_all
#need to destroy environments in the proper order to not leave orphans
self.promotion_paths.each{|path|
path.reverse.each{|env|
env.reload.destroy #if we do not reload, the environment may think its successor still exists
}
}
self.library.destroy
self.library = nil
return true
Expand Down
11 changes: 11 additions & 0 deletions src/spec/models/organization_spec.rb
Expand Up @@ -105,5 +105,16 @@
KTEnvironment.where(:name => env_name).first.should == @env2
KTEnvironment.where(:name => env_name).size.should == 1
end

it "can delete an org where there is a full environment path" do
dev = KTEnvironment.create!(:name => "Dev", :organization => @organization, :prior => @organization.library)
qa = KTEnvironment.create!(:name => "QA", :organization => @organization, :prior => dev)
prod = KTEnvironment.create!(:name => "prod", :organization => @organization, :prior => qa)
@organization = @organization.reload
@organization.destroy
lambda{Organization.find(@organization.id)}.should raise_error(ActiveRecord::RecordNotFound)
KTEnvironment.where(:name =>'Dev').size.should == 0
end

end
end

0 comments on commit f4b6a0e

Please sign in to comment.