On Thursday 11 August 2011 10:58:46 jprovazn(a)redhat.com wrote:
From: Jan Provaznik <jprovazn(a)redhat.com>
Both methods are now regular members instead of collections, added
xml output and fixed testes. I think we don't use these methods at
this point but not sure about this.
---
src/app/controllers/instances_controller.rb | 10 ++++++++--
src/config/routes.rb | 4 +++-
src/features/step_definitions/api_steps.rb | 8 ++++----
3 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/src/app/controllers/instances_controller.rb
b/src/app/controllers/instances_controller.rb index c64380e..a315db9
100644
--- a/src/app/controllers/instances_controller.rb
+++ b/src/app/controllers/instances_controller.rb
@@ -152,17 +152,20 @@ class InstancesController < ApplicationController
respond_to do |format|
begin
provider_account =
ProviderAccount.find(params[:provider_account_id]) - @instance =
Instance.find(params[:instance_id])
+ @instance = Instance.find(params[:id])
@action_request = "can_create"
@value = Quota.can_create_instance?(@instance, provider_account)
format.html { render :partial => 'can_perform_state_change.xml' }
+ format.xml { render :partial => 'can_perform_state_change.xml' }
Maybe will be good use !!! XML prolog in this file
'can_perform_state_change.xml' , but it's not an issue of this patch.
format.json { render :json => {:action_request =>
@action_request,
:instance_id => @instance.id, :value => @value} } rescue
ActiveRecord::RecordNotFound
format.html { head :not_found }
format.json { render :json => {:error => 'Record not found'},
:status => :not_found } + format.xml { render :xml => {:error =>
'Record not found'}, :status => :not_found } rescue Exception
format.html { head :internal_server_error }
format.json { render :json => {:error => $!}, :status =>
:internal_server_error } + format.xml { render :xml => {:error =>
$!}, :status => :internal_server_error } end
end
end
@@ -171,10 +174,11 @@ class InstancesController < ApplicationController
respond_to do |format|
begin
provider_account =
ProviderAccount.find(params[:provider_account_id]) - @instance =
Instance.find(params[:instance_id])
+ @instance = Instance.find(params[:id])
@action_request = "can_start"
@value = Quota.can_start_instance?(@instance, provider_account)
format.html { render :partial => 'can_perform_state_change.xml' }
+ format.xml { render :partial => 'can_perform_state_change.xml' }
format.json { render :json => {:action_request => @action_request,
:instance_id => @instance.id, :value => @value} } rescue
ActiveRecord::RecordNotFound => e
format.html do
@@ -182,12 +186,14 @@ class InstancesController < ApplicationController
head :not_found
end
format.json { render :json => {:error => 'Record not found'},
:status => :not_found } + format.xml { render :xml => {:error =>
'Record not found'}, :status => :not_found } rescue Exception => e
format.html do
puts e.inspect
head :internal_server_error
end
format.json { render :json => {:error => $!}, :status =>
:internal_server_error } + format.xml { render :xml => {:error =>
$!}, :status => :internal_server_error } end
end
end
diff --git a/src/config/routes.rb b/src/config/routes.rb
index bde4b37..4c93e44 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -93,10 +93,12 @@ Conductor::Application.routes.draw do
get 'start'
get 'multi_stop'
get 'remove_failed'
+ end
+ member do
get 'can_start'
get 'can_create'
+ get 'key'
end
- get 'key', :on => :member
end
#map.can_start_instance
'/instances/:instance_id/can_start/:provider_account_id', :controller =>
'instances', :action => 'can_start', :conditions => { :method =>
:get }
diff --git a/src/features/step_definitions/api_steps.rb
b/src/features/step_definitions/api_steps.rb index c722b60..efe1058 100644
--- a/src/features/step_definitions/api_steps.rb
+++ b/src/features/step_definitions/api_steps.rb
@@ -40,7 +40,7 @@ end
When /^a client requests "([^"]*)" for instance "([^"]*)"
for provider
account "([^"]*)"$/ do |action, instance, provider_account| instance =
Instance.find_by_name(instance)
provider_account = ProviderAccount.find_by_label(provider_account)
- uri = url_for :action => action, :controller => 'instances',
:instance_id => instance.id, :provider_account_id => provider_account.id +
uri = url_for :action => action, :controller => 'instances', :id =>
instance.id, :provider_account_id => provider_account.id send_xml_get(uri)
end
@@ -61,7 +61,7 @@ Then /^this path should contain the following elements:$/
do |table| end
def send_xml_get(uri)
- header 'Accept', 'application/xml'
- get uri
- @xml_response = Nokogiri::XML(response.body)
+ page.driver.header 'Accept', 'application/xml'
+ visit uri
+ @xml_response = Nokogiri::XML(page.source)
end