https://bugzilla.redhat.com/show_bug.cgi?id=642432

If the instance has a key you should see a download link,
if not, there should be no link.
---
 src/features/instance.feature             |   26 +++++++++++++++++++
 src/features/step_definitions/instance.rb |   39 +++++++++++++++++++++++++++++
 src/spec/factories/instance.rb            |   12 ++++++++-
 src/spec/factories/instance_key.rb        |   16 +++++++----
 4 files changed, 86 insertions(+), 7 deletions(-)
 create mode 100644 src/features/instance.feature
 create mode 100644 src/features/step_definitions/instance.rb

diff --git a/src/features/instance.feature b/src/features/instance.feature
new file mode 100644
index 0000000..c0a01fc
--- /dev/null
+++ b/src/features/instance.feature
@@ -0,0 +1,26 @@
+# language: en
+Feature: Mange Instances
+  In order to manage my cloud infrastructure
+  As a user
+  I want to manage instances
+
+  Background:
+    Given I am an authorised user
+    And I am logged in
+
+  Scenario: Download an Instance Key
+    Given a mock running instance exists
+    And I am viewing the mock instance detail
+    And I see "SSH key"
+    When I follow "Download"
+    Then I should see the Save dialog for a .pem file
+
+  Scenario: Don't see' an Instance Key
+    Given a mock pending instance exists
+    When I am viewing the pending instance detail
+    Then I should not see "SSH key"
+
+  Scenario: Get useful error when going to wrong url
+    Given a mock pending instance exists
+    When I manually go to the key action for this instance
+    Then I should see "SSH Key not found for this Instance."
\ No newline at end of file
diff --git a/src/features/step_definitions/instance.rb 
b/src/features/step_definitions/instance.rb
new file mode 100644
index 0000000..725f75c
--- /dev/null
+++ b/src/features/step_definitions/instance.rb
@@ -0,0 +1,39 @@
+def mock_instance
+  @mock_instance ||= Factory :mock_running_instance
+end
+
+def pending_instance
+  @pending_instance ||= Factory :mock_pending_instance
+end
+
+Given /^a mock running instance exists$/ do
+  mock_instance
+end
+
+Given /^a mock pending instance exists$/ do
+  pending_instance
+end
+
+Given /^I am viewing the mock instance detail$/ do
+  visit url_for :action => 'show', :controller => 'instance',
+    :id => mock_instance
+end
+
+When /^I am viewing the pending instance detail$/ do
+  visit url_for :action => 'show', :controller => 'instance',
+    :id => pending_instance
+end
+
+When /^I manually go to the key action for this instance$/ do
+   visit url_for :action => 'key', :controller => 'instance',
+    :id => pending_instance
+end
+
+Given /^I see "([^"]*)"$/ do |text|
+  response.should contain(text)
+end
+
+Then /^I should see the Save dialog for a (.+) file$/ do |filetype|
+  response.headers["Content-Disposition"].should
+  match(/^attachment;\sfilename=.*#{filetype}$/)
+end
\ No newline at end of file
diff --git a/src/spec/factories/instance.rb b/src/spec/factories/instance.rb
index 6bb83b2..7533ba9 100644
--- a/src/spec/factories/instance.rb
+++ b/src/spec/factories/instance.rb
@@ -9,10 +9,20 @@ Factory.define :instance do |i|
   i.state "running"
 end
 
-Factory.define :pending_instance, :parent => :instance do |i|
+Factory.define :mock_running_instance, :parent => :instance do |i|
+  i.instance_key { |k| k.association(:mock_instance_key)}
+end
+
+Factory.define :mock_pending_instance, :parent => :instance do |i|
   i.state Instance::STATE_PENDING
 end
 
 Factory.define :new_instance, :parent => :instance do |i|
   i.state Instance::STATE_NEW
 end
+
+Factory.define :ec2_instance, :parent => :instance do |i|
+  i.association :hardware_profile, :factory => :ec2_hwp1
+  i.association :cloud_account, :factory => :ec2_cloud_account
+  i.association :instance_key, :factory => :ec2_instance_key1
+end
diff --git a/src/spec/factories/instance_key.rb 
b/src/spec/factories/instance_key.rb
index f4bcaed..d5bc69a 100644
--- a/src/spec/factories/instance_key.rb
+++ b/src/spec/factories/instance_key.rb
@@ -1,11 +1,6 @@
 Factory.define :instance_key do |p|
   p.sequence(:name) { |n| "instance_key#{n}" }
-end
-
-Factory.define :ec2_instance_key1, :parent => :instance_key do |p|
-  p.cloud_account { |p| p.association(:ec2_cloud_account) }
-  p.name "1_user"
-  p.text "
+  p.pem "
 -----BEGIN RSA PRIVATE KEY-----
 MIIEpAIBAAKCAQEAm+Ri7uZz7iVTLLxtPiV2gLD37OOvovZ0VpWR3T7HK5NgxjlJssIjc8uKqPqY
 EdXssF+ZKKypiQzFkMhowthkw1sGN5R3NBrIiRKR1mcVuE7iiRBFikBoF/CaaXP2LSNtMv4xkUXO
@@ -31,3 +26,12 @@ 
uH9ebPTGZc5cTpOEV9SupUez4cAedBGeHVDHy06sATrgIwKBgQCdqFhrse+uhRacK1LAymvBsou5
 -----END RSA PRIVATE KEY-----
 "
 end
+
+Factory.define :ec2_instance_key1, :parent => :instance_key do |p|
+  p.cloud_account { |p| p.association(:ec2_cloud_account) }
+  p.name "1_user"
+end
+
+Factory.define :mock_instance_key, :parent => :instance_key do |m|
+  m.cloud_account { |c| c.association(:mock_cloud_account) }
+end
\ No newline at end of file
-- 
1.7.2.3

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to