From: Jan Provaznik jprovazn@redhat.com
--- src/app/models/deployment.rb | 2 +- src/spec/models/deployment_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb index 68b5a57..535629b 100644 --- a/src/app/models/deployment.rb +++ b/src/app/models/deployment.rb @@ -158,7 +158,7 @@ class Deployment < ActiveRecord::Base
# stop all deployment's instances instances.each do |instance| - break unless instance.state == Instance::STATE_RUNNING + next unless instance.state == Instance::STATE_RUNNING
@task = instance.queue_action(instance.owner, 'stop') unless @task diff --git a/src/spec/models/deployment_spec.rb b/src/spec/models/deployment_spec.rb index 38b2b19..a62c298 100644 --- a/src/spec/models/deployment_spec.rb +++ b/src/spec/models/deployment_spec.rb @@ -109,6 +109,19 @@ describe Deployment do @deployment.should be_destroyable expect { @deployment.destroy }.to change(Deployment, :count).by(-1) end + + it "should send stop request to all running instances before it's destroyed" do + @deployment.save! + inst1 = Factory.create :mock_running_instance, :deployment_id => @deployment.id + inst2 = Factory.create :mock_running_instance, :deployment_id => @deployment.id + inst2.state = Instance::STATE_STOPPED + inst2.save! + inst3 = Factory.create :mock_running_instance, :deployment_id => @deployment.id + Taskomatic.stub!(:stop_instance).and_return(nil) + @deployment.stop_instances_and_destroy! + inst1.tasks.last.action.should == 'stop' + inst3.tasks.last.action.should == 'stop' + end end
describe ".provider" do