From: Tomas Sedovic tsedovic@redhat.com
--- src/features/pool.feature | 3 +- .../step_definitions/provider_account_steps.rb | 5 +++- src/spec/models/pool_spec.rb | 26 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/src/features/pool.feature b/src/features/pool.feature index 7f1a00b..6a12f19 100644 --- a/src/features/pool.feature +++ b/src/features/pool.feature @@ -51,7 +51,8 @@ Feature: Manage Pools And I press "Destroy" Then there should only be 1 pools And I should be on the resources pools page - And I should not see "Redhat Voyager Pool" + When I go to the resources pools page + Then I should not see "Redhat Voyager Pool" And I should not see "Amazon Startrek Pool"
Scenario: Create multiple pools diff --git a/src/features/step_definitions/provider_account_steps.rb b/src/features/step_definitions/provider_account_steps.rb index 2dcd427..2b6c49c 100644 --- a/src/features/step_definitions/provider_account_steps.rb +++ b/src/features/step_definitions/provider_account_steps.rb @@ -3,7 +3,10 @@ Given /^the account has an instance associated with it$/ do end
When /^I delete all instances from the account$/ do - @provider_account.instances.each { |i| i.destroy } + @provider_account.instances.each do |i| + i.state = Instance::STATE_STOPPED + i.destroy + end end
Then /^there should be no provider accounts$/ do diff --git a/src/spec/models/pool_spec.rb b/src/spec/models/pool_spec.rb index ca754fa..58ddec4 100644 --- a/src/spec/models/pool_spec.rb +++ b/src/spec/models/pool_spec.rb @@ -22,4 +22,30 @@ describe Pool do u.errors[:name].should =~ /^is too long.*/ end
+ it "should not be destroyable when it has running instances" do + pool = Factory.create(:pool) + Pool.find(pool.id).should be_destroyable + + instance = Factory.create(:instance, :pool_id => pool.id) + Pool.find(pool.id).should_not be_destroyable + + instance.state = Instance::STATE_STOPPED + instance.save! + Pool.find(pool.id).should be_destroyable + end + + it "should not be destroyable when it has stopped stateful instances" do + pool = Factory.build(:pool) + pool.should be_destroyable + + instance = Factory.build(:instance, :pool_id => pool.id) + instance.stub!(:restartable?).and_return(true) + pool.instances << instance + pool.should_not be_destroyable + + instance.state = Instance::STATE_STOPPED + instance.stub!(:restartable?).and_return(true) + pool.should_not be_destroyable + end + end