Skip to content

Commit

Permalink
Added Show Base Image Support
Browse files Browse the repository at this point in the history
  • Loading branch information
mtaylor committed Jun 18, 2012
1 parent 01ced75 commit dfdfd69
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
21 changes: 20 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,23 @@ Response
<base_image href='http://localhost:3000/base_images/1' id='1'>
<name>MyFirstBaseImage</name>
<description>This is my very first base image</description>
</base_image>
</base_image>

==== Show Base Image

Request

curl --header "Accept: application/xml" http://localhost:3000/base_images/1

Response

Code: 201

Body:

<base_image href='http://localhost:3000/base_images/1' id='1'>
<name>MyFirstBaseImage</name>
<description>This is my very first base image</description>
<image_versions>
</image_versions>
</base_image>
6 changes: 6 additions & 0 deletions app/controllers/image_management/application_controller.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion app/views/image_management/base_images/_base_image.xml.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
= 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}
52 changes: 51 additions & 1 deletion spec/controllers/base_images_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit dfdfd69

Please sign in to comment.