[PATCH conductor 1/1] Add pools index REST endpoint.

Crag Wolfe cwolfe at redhat.com
Tue Aug 14 00:34:42 UTC 2012


Follow the REST conventions started with provider endpoints.
---
 src/app/controllers/pools_controller.rb         |    3 +++
 src/app/views/pools/_list.xml.haml              |    4 ++++
 src/config/routes.rb                            |    1 +
 src/features/pool_api.feature                   |   16 ++++++++++++++++
 src/features/step_definitions/pool_api_steps.rb |   12 ++++++++++++
 5 files changed, 36 insertions(+), 0 deletions(-)
 create mode 100644 src/app/views/pools/_list.xml.haml
 create mode 100644 src/features/pool_api.feature
 create mode 100644 src/features/step_definitions/pool_api_steps.rb

diff --git a/src/app/controllers/pools_controller.rb b/src/app/controllers/pools_controller.rb
index 0668217..e62e08b 100644
--- a/src/app/controllers/pools_controller.rb
+++ b/src/app/controllers/pools_controller.rb
@@ -109,6 +109,9 @@ class PoolsController < ApplicationController
           :user_info => view_context.user_info_for_mustache
         }
       end
+      format.xml do
+        render :partial => 'list.xml'
+      end
     end
   end

diff --git a/src/app/views/pools/_list.xml.haml b/src/app/views/pools/_list.xml.haml
new file mode 100644
index 0000000..c9c3982
--- /dev/null
+++ b/src/app/views/pools/_list.xml.haml
@@ -0,0 +1,4 @@
+!!! XML
+%pools
+  - @pools.each do |pool|
+    %pool{:id => pool.id, :href => api_pool_url(pool)}
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 119d740..d01ca24 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -281,6 +281,7 @@ Conductor::Application.routes.draw do
   end

   scope "/api", :as => 'api' do
+    resources :pools, :only => [:index, :show]
     resources :providers, :only => [:index, :show, :create, :update, :destroy] do
       resources :provider_accounts, :only => [:index]
     end
diff --git a/src/features/pool_api.feature b/src/features/pool_api.feature
new file mode 100644
index 0000000..6800f41
--- /dev/null
+++ b/src/features/pool_api.feature
@@ -0,0 +1,16 @@
+ at api
+Feature: Manage Pools via API
+  As a client of conductor,
+  In order to manage the full life cycle of pools in the system
+  I want to be able to Create, Update and Delete pools via a RESTful API
+
+  Background:
+    Given I am an authorised user
+    And I use my authentication credentials in each request
+
+  Scenario: Get list of pools as XML
+    Given a pool "foo" exists
+    And a pool "bar" exists
+    When I request a list of pools as XML
+    # The third pool besides foo and bar is the Default pool
+    Then I should receive list of 3 pools as XML
diff --git a/src/features/step_definitions/pool_api_steps.rb b/src/features/step_definitions/pool_api_steps.rb
new file mode 100644
index 0000000..60e631b
--- /dev/null
+++ b/src/features/step_definitions/pool_api_steps.rb
@@ -0,0 +1,12 @@
+When /^I request a list of pools as XML$/ do
+  header 'Accept', 'application/xml'
+  get api_pools_path
+end
+
+Then /^I should receive list of (\d+) pools as XML$/ do |number|
+  response = last_response
+  response.headers['Content-Type'].should include('application/xml')
+  response.status.should be_eql(200)
+  xml_body = Nokogiri::XML(response.body)
+  xml_body.xpath('//pools/pool').size.should be_eql(number.to_i)
+end
-- 
1.7.1




More information about the aeolus-devel mailing list