From: Maros Zatko <mzatko(a)redhat.com>
---
src/spec/controllers/api/builds_controller_spec.rb | 46 +++++++++++++++++++-
.../api/provider_images_controller_spec.rb | 34 ++++++++++++++
.../api/target_images_controller_spec.rb | 29 ++++++++++++
3 files changed, 107 insertions(+), 2 deletions(-)
diff --git a/src/spec/controllers/api/builds_controller_spec.rb
b/src/spec/controllers/api/builds_controller_spec.rb
index feafaf2..86376d0 100644
--- a/src/spec/controllers/api/builds_controller_spec.rb
+++ b/src/spec/controllers/api/builds_controller_spec.rb
@@ -38,6 +38,21 @@ describe Api::BuildsController do
:id => '10',
:image => @image,
:target_images => [@target_image])
+
+
+ @other_image = mock(Aeolus::Image::Warehouse::Image,
+ :id => '6',
+ :os => @os,
+ :name => 'other test',
+ :description => 'other test image')
+
+ @other_target_image = mock(Aeolus::Image::Warehouse::TargetImage,
+ :id => "2")
+
+ @other_build = mock(Aeolus::Image::Warehouse::ImageBuild,
+ :id => '11',
+ :image => @other_image,
+ :target_images => [@other_target_image])
end
context "when authenticated as admin" do
@@ -52,7 +67,7 @@ describe Api::BuildsController do
context "when there are 3 builds" do
before(:each) do
- @build_collection = [@build, @build, @build]
+ @build_collection = [@build, @build, @other_build]
Aeolus::Image::Warehouse::ImageBuild.stub(:all).and_return(@build_collection)
get :index
@@ -66,12 +81,16 @@ describe Api::BuildsController do
end
it "should have builds with correct attributes" do
resp = Hash.from_xml(response.body)
- @build_collection.each_with_index do |build, index|
+ @build_collection[0..1].each_with_index do |build, index|
resp['builds']['build'][index]['id'].should ==
build.id
resp['builds']['build'][index]['image'].should ==
@image.id
end
+
+ resp['builds']['build'][2]['id'].should ==
@build_collection[2].id
+ resp['builds']['build'][2]['image'].should ==
@other_image.id
end
end
+
context "when there is only 1 build" do
before(:each) do
@@ -102,6 +121,29 @@ describe Api::BuildsController do
resp['builds']['build'].should be_nil
end
end
+
+ context "when accessing as image subcollection" do
+
+ before(:each) do
+ @build_collection = [@build, @build]
+
Aeolus::Image::Warehouse::ImageBuild.stub(:find_all_by_image_uuid).and_return(@build_collection)
+ get :index, :image_id => @image.id
+ end
+
+ it { response.should be_success }
+ it { response.headers['Content-Type'].should
include("application/xml") }
+ it "should have 2 builds" do
+ resp = Hash.from_xml(response.body)
+ resp['builds']['build'].size.should
be_equal((a)build_collection.size)
+ end
+ it "should have builds with correct attributes" do
+ resp = Hash.from_xml(response.body)
+ @build_collection.each_with_index do |build, index|
+ resp['builds']['build'][index]['id'].should ==
build.id
+ resp['builds']['build'][index]['image'].should ==
@image.id
+ end
+ end
+ end
end
describe "#show" do
diff --git a/src/spec/controllers/api/provider_images_controller_spec.rb
b/src/spec/controllers/api/provider_images_controller_spec.rb
index b2f49ac..7f17877 100644
--- a/src/spec/controllers/api/provider_images_controller_spec.rb
+++ b/src/spec/controllers/api/provider_images_controller_spec.rb
@@ -35,6 +35,14 @@ describe Api::ProviderImagesController do
:target_identifier => '80',
:target_image => @timage)
+ @other_timage = mock(Aeolus::Image::Warehouse::TargetImage,
+ :id => '301')
+ @other_pimage = mock(Aeolus::Image::Warehouse::ProviderImage,
+ :id => '18',
+ :provider_name => 'other_provider_name',
+ :object_type => 'other_provider_image',
+ :target_identifier => '80',
+ :target_image => @other_timage)
end
context "when authenticated as admin" do
@@ -105,6 +113,32 @@ describe Api::ProviderImagesController do
end
end
+ context "when accessing as subcollection from target image" do
+
+ before(:each) do
+ @provider_image_collection = [@other_pimage, @other_pimage]
+ Aeolus::Image::Warehouse::TargetImage.stub(:find).and_return(@other_timage)
+ @other_timage.stub(:provider_images).and_return(@provider_image_collection)
+ get :index, :target_image_id => @other_timage.id
+ end
+
+ it { response.should be_success }
+ it { response.headers['Content-Type'].should
include("application/xml") }
+ it "should have 3 provider images" do
+ resp = Hash.from_xml(response.body)
+ resp['provider_images']['provider_image'].size.should
be_equal((a)provider_image_collection.size)
+ end
+ it "should have provider images with corrent attributes" do
+ resp = Hash.from_xml(response.body)
+ @provider_image_collection.each_with_index do |pimage, index|
+
resp['provider_images']['provider_image'][index]['id'].should ==
pimage.id
+
resp['provider_images']['provider_image'][index]['object_type'].should
== pimage.object_type
+
resp['provider_images']['provider_image'][index]['target_identifier'].should
== pimage.target_identifier
+
resp['provider_images']['provider_image'][index]['target_image']['id'].should
== pimage.target_image.id
+ end
+ end
+ end
+
end
describe "#show" do
diff --git a/src/spec/controllers/api/target_images_controller_spec.rb
b/src/spec/controllers/api/target_images_controller_spec.rb
index 56d1f4e..0f56ee8 100644
--- a/src/spec/controllers/api/target_images_controller_spec.rb
+++ b/src/spec/controllers/api/target_images_controller_spec.rb
@@ -107,6 +107,35 @@ describe Api::TargetImagesController do
resp['target_images']['target_image'].should be_nil
end
end
+
+ context "when accessed as subcollection from provider image" do
+ before(:each) do
+ send_and_accept_xml
+ @timage_collection = [@timage, @timage, @timage]
+ Aeolus::Image::Warehouse::ImageBuild.stub(:find).and_return(@build)
+ @build.stub(:target_images).and_return(@timage_collection)
+
+ get :index, :build_id => 543
+ end
+
+ it { response.should be_success }
+ it { response.headers['Content-Type'].should
include("application/xml") }
+ it "should have 3 target images" do
+ resp = Hash.from_xml(response.body)
+ resp['target_images']['target_image'].size.should
be_equal((a)timage_collection.size)
+ end
+ it "should have target images with correct attributes" do
+ resp = Hash.from_xml(response.body)
+ @timage_collection.each_with_index do |timage, index|
+
resp['target_images']['target_image'][index]['id'].should ==
timage.id
+
resp['target_images']['target_image'][index]['object_type'].should
== timage.object_type
+
resp['target_images']['target_image'][index]['template'].should ==
timage.template
+
resp['target_images']['target_image'][index]['build']['id'].should
== timage.build.id
+ pimgs =
resp['target_images']['target_image'][index]['provider_image']
+ pimgs['provider_image']['id'].should == @pimage.id
+ end
+ end
+ end
end
describe "#show" do
--
1.7.6.4