From: Jan Provaznik <jprovazn(a)redhat.com>
task #1622 (
https://www.aeolusproject.org/redmine/issues/1622)
---
src/app/controllers/providers_controller.rb | 10 ++++---
src/app/views/providers/_list.xml.haml | 7 +++++
src/features/provider.feature | 19 ++++++++++++++
src/features/step_definitions/provider_steps.rb | 30 +++++++++++++++++++++++
4 files changed, 62 insertions(+), 4 deletions(-)
create mode 100644 src/app/views/providers/_list.xml.haml
diff --git a/src/app/controllers/providers_controller.rb
b/src/app/controllers/providers_controller.rb
index 2278896..a06d1f9 100644
--- a/src/app/controllers/providers_controller.rb
+++ b/src/app/controllers/providers_controller.rb
@@ -5,15 +5,17 @@ class ProvidersController < ApplicationController
def index
@params = params
@search_term = params[:q]
+
if @search_term.blank?
load_providers
- return
+ else
+ @providers = Provider.search { keywords(params[:q]) }.results
end
- search = Provider.search do
- keywords(params[:q])
+ respond_to do |format|
+ format.html
+ format.xml { render :partial => 'list.xml' }
end
- @providers = search.results
end
def new
diff --git a/src/app/views/providers/_list.xml.haml
b/src/app/views/providers/_list.xml.haml
new file mode 100644
index 0000000..53f06a0
--- /dev/null
+++ b/src/app/views/providers/_list.xml.haml
@@ -0,0 +1,7 @@
+!!! XML
+%providers
+ - @providers.each do |p|
+ %provider
+ %name= p.name
+ %url= p.url
+ %provider_type= p.provider_type.codename
diff --git a/src/features/provider.feature b/src/features/provider.feature
index 29bf918..38dc9ef 100644
--- a/src/features/provider.feature
+++ b/src/features/provider.feature
@@ -21,6 +21,25 @@ Feature: Manage Providers
| provider2 |
| provider3 |
+ Scenario: List providers in XML format
+ Given I accept XML
+ And there are these providers:
+ | name |
+ | provider1 |
+ | provider2 |
+ | provider3 |
+ When I go to the providers page
+ Then I should get a XML document
+ And XML should contain 3 providers
+ And each provider should have "name"
+ And each provider should have "url"
+ And each provider should have "provider_type"
+ And there should be these provider:
+ | name | url | provider_type |
+ | provider1 |
http://localhost:3001/api | mock |
+ | provider2 |
http://localhost:3001/api | mock |
+ | provider3 |
http://localhost:3001/api | mock |
+
Scenario: Show provider details
Given there is a provider named "testprovider"
And I am on the providers page
diff --git a/src/features/step_definitions/provider_steps.rb
b/src/features/step_definitions/provider_steps.rb
index f679ba9..334e7d1 100644
--- a/src/features/step_definitions/provider_steps.rb
+++ b/src/features/step_definitions/provider_steps.rb
@@ -68,3 +68,33 @@ end
Then /^there should not be a realm$/ do
Realm.find(:all, :conditions => { :provider_id => @provider.id} ).size.should ==
0
end
+
+Given /^I accept XML$/ do
+ header 'Accept', 'application/xml'
+end
+
+Then /^I should get a XML document$/ do
+ @xml_response = Nokogiri::XML(response.body)
+end
+
+Then /^XML should contain (\d+) providers$/ do |arg1|
+ @xml_response.root.xpath('/providers/provider').count.should == arg1.to_i
+end
+
+Then /^each provider should have "([^"]*)"$/ do |arg1|
+ @xml_response.root.xpath("/providers/provider/#{arg1}").text.should_not
be_blank
+end
+
+Then /^there should be these provider:$/ do |table|
+ providers = @xml_response.root.xpath('/providers/provider').map do |n|
+ {:name => n.xpath('name').text,
+ :url => n.xpath('url').text,
+ :provider_type => n.xpath('provider_type').text}
+ end
+ table.hashes.each do |hash|
+ p = providers.find {|n| n[:name] == hash[:name]}
+ p.should_not be_nil
+ p[:url].should == hash[:url]
+ p[:provider_type].should == hash[:provider_type]
+ end
+end
--
1.7.4