On 05/30/2011 01:15 PM, jprovazn(a)redhat.com wrote:
From: Jan Provaznik<jprovazn(a)redhat.com>
task #1621 (
https://www.aeolusproject.org/redmine/issues/1621)
---
src/app/controllers/provider_types_controller.rb | 10 +++++++++
src/app/views/provider_types/_list.xml.haml | 7 ++++++
src/config/routes.rb | 1 +
src/db/seeds.rb | 1 +
src/features/provider_type.feature | 22 ++++++++++++++++++++
.../step_definitions/provider_type_steps.rb | 13 +++++++++++
6 files changed, 54 insertions(+), 0 deletions(-)
create mode 100644 src/app/controllers/provider_types_controller.rb
create mode 100644 src/app/views/provider_types/_list.xml.haml
create mode 100644 src/features/provider_type.feature
create mode 100644 src/features/step_definitions/provider_type_steps.rb
diff --git a/src/app/controllers/provider_types_controller.rb
b/src/app/controllers/provider_types_controller.rb
new file mode 100644
index 0000000..8b65f89
--- /dev/null
+++ b/src/app/controllers/provider_types_controller.rb
@@ -0,0 +1,10 @@
+class ProviderTypesController< ApplicationController
+ before_filter :require_user
+
+ def index
+ @provider_types = ProviderType.all
+ respond_to do |format|
+ format.xml { render :partial => 'list.xml' }
+ end
+ end
+end
diff --git a/src/app/views/provider_types/_list.xml.haml
b/src/app/views/provider_types/_list.xml.haml
new file mode 100644
index 0000000..6363806
--- /dev/null
+++ b/src/app/views/provider_types/_list.xml.haml
@@ -0,0 +1,7 @@
+!!! XML
+%provider_types
+ - @provider_types.each do |p|
+ %provider_type
+ %name= p.name
+ %codename= p.codename
+ %build_supported= p.build_supported
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 5d48373..5aa6414 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -48,6 +48,7 @@ ActionController::Routing::Routes.draw do |map|
map.resources :hardware_profiles, :collection => { :multi_destroy => :delete
}
map.resources :providers, :collection => { :multi_destroy => :delete }
+ map.resources :provider_types
It create RESTful routes, but you defined only
index, so maybe it would
be better to limit it on
map.resources :provider_types, :only => :index
map.resources :users, :collection => { :multi_destroy =>
:delete }
map.resources :provider_accounts, :collection => { :multi_destroy => :delete,
:set_selected_provider => :get}
map.resources :roles, :collection => { :multi_destroy => :delete }
diff --git a/src/db/seeds.rb b/src/db/seeds.rb
index 3ab3131..ad2c770 100644
--- a/src/db/seeds.rb
+++ b/src/db/seeds.rb
@@ -120,6 +120,7 @@ if ProviderType.all.empty?
ProviderType.create!(:name => "Rackspace", :codename
=>"rackspace")
ProviderType.create!(:name => "RHEV-M", :codename
=>"rhev-m")
ProviderType.create!(:name => "OpenNebula", :codename
=>"opennebula")
+ ProviderType.create!(:name => "CondorCloud", :codename
=>"condorcloud", :build_supported => 'true')
end
# fill table CredentialDefinitions by default values
diff --git a/src/features/provider_type.feature b/src/features/provider_type.feature
new file mode 100644
index 0000000..5948533
--- /dev/null
+++ b/src/features/provider_type.feature
@@ -0,0 +1,22 @@
+Feature: Manage Providers
+ In order to manage my cloud infrastructure
+ As a user
+ I want to manage cloud providers
+
+ Background:
+ Given I am an authorised user
+ And I am logged in
+
+ Scenario: List providers in XML format
+ Given I accept XML
+ When I go to the provider types page
+ Then I should get a XML document
+ And there should be these provider types:
+ | name | codename | build_supported |
+ | Mock | mock | true |
+ | GoGrid | gogrid | false |
+ | Rackspace | rackspace | false |
+ | OpenNebula | opennebula | false |
+ | Amazon EC2 | ec2 | true |
+ | CondorCloud | condorcloud | true |
+ | RHEV-M | rhev-m | false |
diff --git a/src/features/step_definitions/provider_type_steps.rb
b/src/features/step_definitions/provider_type_steps.rb
new file mode 100644
index 0000000..0b0760a
--- /dev/null
+++ b/src/features/step_definitions/provider_type_steps.rb
@@ -0,0 +1,13 @@
+Then /^there should be these provider types:$/ do |table|
+ types = @xml_response.root.xpath('/provider_types/provider_type').map do |n|
+ {:name => n.xpath('name').text,
+ :codename => n.xpath('codename').text,
+ :build_supported => n.xpath('build_supported').text}
+ end
+ table.hashes.each do |hash|
+ p = types.find {|n| n[:name] == hash[:name]}
+ p.should_not be_nil
+ p[:codename].should == hash[:codename]
+ p[:build_supported].should == hash[:build_supported]
+ end
+end
It works well. ACK. (I have one suggestion look to inline comment)
--
Jozef Zigmund