[PATCH conductor] RM 3560 - pool api delete
Richard Su
rwsu at redhat.com
Tue Aug 14 23:32:42 UTC 2012
https://www.aeolusproject.org/redmine/issues/3560
---
src/app/controllers/pools_controller.rb | 11 +++++++
src/app/views/pools/destroy.xml.haml | 3 ++
src/config/routes.rb | 2 +-
src/spec/controllers/pools_controller_spec.rb | 36 ++++++++++++++++++++++++-
4 files changed, 50 insertions(+), 2 deletions(-)
create mode 100644 src/app/views/pools/destroy.xml.haml
diff --git a/src/app/controllers/pools_controller.rb b/src/app/controllers/pools_controller.rb
index 931d25d..3be0ba5 100644
--- a/src/app/controllers/pools_controller.rb
+++ b/src/app/controllers/pools_controller.rb
@@ -259,7 +259,9 @@ class PoolsController < ApplicationController
failed = []
permission_failed = []
error_messages = []
+ pool_id = nil
Pool.find(ids_list(['pools_selected'])).each do |pool|
+ pool_id = pool.id
if pool.id == MetadataObject.lookup("self_service_default_pool").id
error_messages << t("pools.flash.error.default_pool_not_deleted")
elsif !check_privilege(Privilege::MODIFY, pool)
@@ -287,6 +289,15 @@ class PoolsController < ApplicationController
render :partial => 'list'
end
format.json { render :json => {:success => destroyed, :errors => failed} }
+ format.xml {
+ if failed.present?
+ raise(Aeolus::Conductor::API::Error.new(500, flash[:error]))
+ elsif error_messages.present?
+ raise(Aeolus::Conductor::API::Error.new(500, error_messages))
+ else
+ render :destroy, :locals => { :pool_id => pool_id }
+ end
+ }
end
end
diff --git a/src/app/views/pools/destroy.xml.haml b/src/app/views/pools/destroy.xml.haml
new file mode 100644
index 0000000..4ce7e46
--- /dev/null
+++ b/src/app/views/pools/destroy.xml.haml
@@ -0,0 +1,3 @@
+!!! XML
+%pool{:id => pool_id}
+ %status="DELETED"
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 8373342..54231f0 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -287,7 +287,7 @@ Conductor::Application.routes.draw do
resources :provider_accounts, :only => [:index, :show, :destroy]
resources :provider_types, :only => [:index, :show]
resources :hardware_profiles, :only => [:index, :show, :destroy, :create]
- resources :pools, :only => [:index, :show, :create, :update]
+ resources :pools, :only => [:index, :show, :create, :update, :destroy]
end
#match 'matching_profiles', :to => '/hardware_profiles/matching_profiles/:hardware_profile_id/provider/:provider_id', :controller => 'hardware_profiles', :action => 'matching_profiles', :conditions => { :method => :get }, :as =>'matching_profiles'
diff --git a/src/spec/controllers/pools_controller_spec.rb b/src/spec/controllers/pools_controller_spec.rb
index 5afc66c..87cdcdb 100644
--- a/src/spec/controllers/pools_controller_spec.rb
+++ b/src/spec/controllers/pools_controller_spec.rb
@@ -252,9 +252,43 @@ describe PoolsController do
xml = Nokogiri::XML(response.body)
xml.xpath("/errors/error/message").text.should == "Name can't be blank"
end
-
end
+ describe "#destroy" do
+
+ it "delete an existing pool" do
+ @pool = FactoryGirl.create :pool
+ get :destroy, :id => @pool.id
+
+ response.status.should be_eql(200)
+ response.should have_content_type("application/xml")
+ response.body.should be_xml
+ xml = Nokogiri::XML(response.body)
+ xml.xpath("/pool/@id").text.should == "#{@pool.id}"
+ xml.xpath("/pool/status").text.should == "DELETED"
+ end
+
+ it "delete a missing pool should throw error" do
+ get :destroy, :id => -1
+
+ response.status.should be_eql(404)
+ response.should have_content_type("application/xml")
+ response.body.should be_xml
+ xml = Nokogiri::XML(response.body)
+ xml.xpath("/error/message").text.should == "Couldn't find Pool with id=-1"
+ end
+
+ it "delete default pool should throw error" do
+ @pool = FactoryGirl.create :pool
+ get :destroy, :id => 1
+
+ response.status.should be_eql(500)
+ response.should have_content_type("application/xml")
+ response.body.should be_xml
+ xml = Nokogiri::XML(response.body)
+ xml.xpath("/error/message").text.should == "The default pool cannot be deleted"
+ end
+ end
end
--
1.7.7.6
More information about the aeolus-devel
mailing list