On 07/13/2011 02:32 PM, jtomasek(a)redhat.com wrote:
From: Jiri Tomasek<jtomasek(a)redhat.com>
---
src/app/models/provider_account.rb | 2 +-
src/features/provider_account.feature | 12 ++++++++++++
.../step_definitions/provider_account_steps.rb | 7 +++++++
3 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/src/app/models/provider_account.rb b/src/app/models/provider_account.rb
index 9c5f316..a05b764 100644
--- a/src/app/models/provider_account.rb
+++ b/src/app/models/provider_account.rb
@@ -126,7 +126,7 @@ class ProviderAccount< ActiveRecord::Base
end
def destroyable?
- instances.empty?
+ instances.empty? || instances.all? { |i| i.destroyable? }
end
def connect
diff --git a/src/features/provider_account.feature
b/src/features/provider_account.feature
index 348fa5b..e4d8d0b 100644
--- a/src/features/provider_account.feature
+++ b/src/features/provider_account.feature
@@ -78,6 +78,18 @@ Feature: Manage Provider Accounts
And I should see "was deleted"
And there should be no provider accounts
+ Scenario: Delete a provider account with stopped instances
+ Given there is a provider named "testprovider"
+ And there is a provider account named "testaccount"
+ And the account has an instance associated with it
+ And all the account instances are stopped
+ And I am on the provider accounts page
+ When I check the "testaccount" account
+ And I press "Delete"
+ Then I should be on the provider accounts page
+ And I should see "was deleted"
+ And there should be no provider accounts
+
Scenario: Edit a existing Provider Account
Given there is a provider named "testprovider"
And there is a provider account named "testaccount"
diff --git a/src/features/step_definitions/provider_account_steps.rb
b/src/features/step_definitions/provider_account_steps.rb
index 881a176..f4f7312 100644
--- a/src/features/step_definitions/provider_account_steps.rb
+++ b/src/features/step_definitions/provider_account_steps.rb
@@ -2,6 +2,13 @@ Given /^the account has an instance associated with it$/ do
Factory :instance, :provider_account => @provider_account
end
+Given /^all the account instances are stopped$/ do
+ @provider_account.instances.each do |i|
+ i.state = Instance::STATE_STOPPED
+ i.save
+ end
+end
+
When /^I delete all instances from the account$/ do
@provider_account.instances.each do |i|
i.state = Instance::STATE_STOPPED
Looks good, only one minor thing: could you please update provider
account rspec test "should not be destroyable if it has instances" to
check instance state?
Jan