diff --git a/README.rdoc b/README.rdoc
index 81815fd..cc3b3cb 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -35,4 +35,23 @@ Response
MyFirstBaseImage
This is my very first base image
-
\ No newline at end of file
+
+
+==== Show Base Image
+
+Request
+
+ curl --header "Accept: application/xml" http://localhost:3000/base_images/1
+
+Response
+
+ Code: 201
+
+ Body:
+
+
+ MyFirstBaseImage
+ This is my very first base image
+
+
+
diff --git a/app/controllers/image_management/application_controller.rb b/app/controllers/image_management/application_controller.rb
index 2a282d5..26fe43b 100644
--- a/app/controllers/image_management/application_controller.rb
+++ b/app/controllers/image_management/application_controller.rb
@@ -1,5 +1,11 @@
module ImageManagement
class ApplicationController < ActionController::Base
protect_from_forgery
+
+ rescue_from ActiveRecord::RecordNotFound, :with => :render_not_found
+
+ def render_not_found
+ render :nothing => true, :status => :not_found
+ end
end
end
\ No newline at end of file
diff --git a/app/views/image_management/base_images/_base_image.xml.haml b/app/views/image_management/base_images/_base_image.xml.haml
index 16e825c..2a3894d 100644
--- a/app/views/image_management/base_images/_base_image.xml.haml
+++ b/app/views/image_management/base_images/_base_image.xml.haml
@@ -3,4 +3,7 @@
%name= base_image.name
%description= base_image.description
- if base_image.template
- = render :partial => 'image_management/templates/template_minimal', :locals => {:template => base_image.template}
\ No newline at end of file
+ = render :partial => 'image_management/templates/template_minimal', :locals => {:template => base_image.template}
+ %image_versions
+ - base_image.image_versions.each do |image_version|
+ = render :partial => 'image_management/image_versions/image_version_minimal', :locals => {:image_version => image_version}
\ No newline at end of file
diff --git a/spec/controllers/base_images_controller_spec.rb b/spec/controllers/base_images_controller_spec.rb
index d994302..6c2861d 100644
--- a/spec/controllers/base_images_controller_spec.rb
+++ b/spec/controllers/base_images_controller_spec.rb
@@ -26,7 +26,7 @@ module ImageManagement
body = Hash.from_xml(response.body)
body.keys.should == ["base_image"]
- body["base_image"].keys.should =~ ["template", "id", "href", "name", "description"]
+ body["base_image"].keys.should =~ ["template", "id", "href", "name", "description", "image_versions"]
body["base_image"]["template"].keys.should =~ ["id", "href"]
end
end
@@ -38,6 +38,56 @@ module ImageManagement
end
end
end
+
+ describe "Show Base Image" do
+ context "Success" do
+ it "should return an existing base image as XML" do
+ base_image = Factory.create(:base_image)
+ get :show, :id => base_image.id
+
+ response.code.should == "200"
+
+ body = Hash.from_xml(response.body)
+ body.keys.should == ["base_image"]
+ body["base_image"].keys.should =~ ["id", "href", "name", "description", "image_versions"]
+ end
+
+ it "should return an existing base image as XML with template" do
+ base_image = Factory.create(:base_image_with_template)
+ get :show, :id => base_image.id
+
+ response.code.should == "200"
+
+ body = Hash.from_xml(response.body)
+ body.keys.should == ["base_image"]
+ body["base_image"].keys.should =~ ["template", "id", "href", "name", "description", "image_versions"]
+ body["base_image"]["template"].keys.should =~ ["id", "href"]
+ end
+
+ it "should return an existing base image as XML with image versions" do
+ base_image = Factory.create(:base_image_with_template)
+ 2.times do
+ Factory.create(:image_version, :base_image => base_image)
+ end
+
+ get :show, :id => base_image.id
+
+ response.code.should == "200"
+
+ body = Hash.from_xml(response.body)
+ body.keys.should == ["base_image"]
+ body["base_image"].keys.should =~ ["image_versions", "template", "id", "href", "name", "description"]
+ body["base_image"]["image_versions"]["image_version"].size.should == 2
+ end
+ end
+
+ context "failure" do
+ it "should return a not found response when an base image does not exist" do
+ get :show, :id => -1
+ response.code.should == "404"
+ end
+ end
+ end
end
end
end
\ No newline at end of file