tim 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +392 -0
  3. data/Rakefile +33 -0
  4. data/app/assets/javascripts/tim/application.js +15 -0
  5. data/app/assets/stylesheets/tim/application.css +13 -0
  6. data/app/controllers/tim/application_controller.rb +19 -0
  7. data/app/controllers/tim/base_images_controller.rb +59 -0
  8. data/app/controllers/tim/entrypoint_controller.rb +8 -0
  9. data/app/controllers/tim/image_versions_controller.rb +48 -0
  10. data/app/controllers/tim/provider_images_controller.rb +59 -0
  11. data/app/controllers/tim/target_images_controller.rb +61 -0
  12. data/app/controllers/tim/templates_controller.rb +47 -0
  13. data/app/filters/tim/user_keys_filter.rb +59 -0
  14. data/app/helpers/tim/application_helper.rb +4 -0
  15. data/app/models/tim/base.rb +6 -0
  16. data/app/models/tim/base_image.rb +15 -0
  17. data/app/models/tim/image_version.rb +13 -0
  18. data/app/models/tim/provider_image.rb +51 -0
  19. data/app/models/tim/target_image.rb +50 -0
  20. data/app/models/tim/template.rb +19 -0
  21. data/app/responders/tim/custom_responder.rb +24 -0
  22. data/app/validators/template_validator.rb +15 -0
  23. data/app/views/layouts/tim/application.html.erb +14 -0
  24. data/app/views/tim/base_images/_base_image.xml.haml +11 -0
  25. data/app/views/tim/base_images/_base_image_minimal.xml.haml +2 -0
  26. data/app/views/tim/base_images/_form.html.erb +17 -0
  27. data/app/views/tim/base_images/edit.html.erb +6 -0
  28. data/app/views/tim/base_images/index.html.erb +17 -0
  29. data/app/views/tim/base_images/index.xml.haml +4 -0
  30. data/app/views/tim/base_images/new.html.erb +5 -0
  31. data/app/views/tim/base_images/show.html.erb +5 -0
  32. data/app/views/tim/base_images/show.xml.haml +2 -0
  33. data/app/views/tim/entrypoint/index.xml.haml +7 -0
  34. data/app/views/tim/image_versions/_form.html.erb +17 -0
  35. data/app/views/tim/image_versions/_image_version.xml.haml +9 -0
  36. data/app/views/tim/image_versions/_image_version_minimal.xml.haml +2 -0
  37. data/app/views/tim/image_versions/edit.html.erb +6 -0
  38. data/app/views/tim/image_versions/index.html.erb +17 -0
  39. data/app/views/tim/image_versions/index.xml.haml +4 -0
  40. data/app/views/tim/image_versions/new.html.erb +5 -0
  41. data/app/views/tim/image_versions/show.html.erb +5 -0
  42. data/app/views/tim/image_versions/show.xml.haml +2 -0
  43. data/app/views/tim/images/_form.html.erb +17 -0
  44. data/app/views/tim/images/edit.html.erb +6 -0
  45. data/app/views/tim/images/index.html.erb +21 -0
  46. data/app/views/tim/images/new.html.erb +5 -0
  47. data/app/views/tim/images/show.html.erb +5 -0
  48. data/app/views/tim/layouts/application.html.erb +14 -0
  49. data/app/views/tim/provider_images/_form.html.erb +17 -0
  50. data/app/views/tim/provider_images/_provider_image.xml.haml +12 -0
  51. data/app/views/tim/provider_images/_provider_image_minimal.xml.haml +2 -0
  52. data/app/views/tim/provider_images/edit.html.erb +6 -0
  53. data/app/views/tim/provider_images/index.html.erb +17 -0
  54. data/app/views/tim/provider_images/index.xml.haml +4 -0
  55. data/app/views/tim/provider_images/new.html.erb +5 -0
  56. data/app/views/tim/provider_images/show.html.erb +5 -0
  57. data/app/views/tim/provider_images/show.xml.haml +2 -0
  58. data/app/views/tim/target_images/_form.html.erb +17 -0
  59. data/app/views/tim/target_images/_target_image.xml.haml +13 -0
  60. data/app/views/tim/target_images/_target_image_minimal.xml.haml +2 -0
  61. data/app/views/tim/target_images/edit.html.erb +6 -0
  62. data/app/views/tim/target_images/index.html.erb +21 -0
  63. data/app/views/tim/target_images/index.xml.haml +4 -0
  64. data/app/views/tim/target_images/new.html.erb +5 -0
  65. data/app/views/tim/target_images/show.html.erb +5 -0
  66. data/app/views/tim/target_images/show.xml.haml +2 -0
  67. data/app/views/tim/templates/_form.html.erb +17 -0
  68. data/app/views/tim/templates/_template.xml.haml +8 -0
  69. data/app/views/tim/templates/_template_minimal.xml.haml +2 -0
  70. data/app/views/tim/templates/edit.html.erb +6 -0
  71. data/app/views/tim/templates/index.html.erb +17 -0
  72. data/app/views/tim/templates/index.xml.haml +4 -0
  73. data/app/views/tim/templates/new.html.erb +5 -0
  74. data/app/views/tim/templates/show.html.erb +5 -0
  75. data/app/views/tim/templates/show.xml.haml +2 -0
  76. data/config/cucumber.yml +8 -0
  77. data/config/initializers/haml.rb +1 -0
  78. data/config/routes.rb +9 -0
  79. data/config/schemas/tdl.rng +282 -0
  80. data/config/user_keys.yml +26 -0
  81. data/db/migrate/20120906180351_create_tim_base_images.rb +12 -0
  82. data/db/migrate/20120906210106_create_tim_image_versions.rb +10 -0
  83. data/db/migrate/20120910175233_create_tim_templates.rb +9 -0
  84. data/db/migrate/20120911202321_create_tim_target_images.rb +14 -0
  85. data/db/migrate/20120911204329_create_tim_provider_images.rb +19 -0
  86. data/lib/generators/tim/install_generator.rb +15 -0
  87. data/lib/generators/tim/templates/README +6 -0
  88. data/lib/generators/tim/templates/tim.rb +8 -0
  89. data/lib/image_factory/image_factory.rb +4 -0
  90. data/lib/image_factory/model/base.rb +88 -0
  91. data/lib/image_factory/model/provider_image.rb +6 -0
  92. data/lib/image_factory/model/target_image.rb +6 -0
  93. data/lib/tasks/cucumber.rake +59 -0
  94. data/lib/tasks/tim_tasks.rake +4 -0
  95. data/lib/tim.rb +8 -0
  96. data/lib/tim/engine.rb +9 -0
  97. data/lib/tim/version.rb +3 -0
  98. data/spec/controllers/base_images_controller_spec.rb +131 -0
  99. data/spec/controllers/entrypoint_controller_spec.rb +32 -0
  100. data/spec/controllers/image_versions_controller_spec.rb +146 -0
  101. data/spec/controllers/provider_images_controller_spec.rb +156 -0
  102. data/spec/controllers/target_images_controller_spec.rb +153 -0
  103. data/spec/controllers/templates_controller_spec.rb +41 -0
  104. data/spec/decorators/controllers/templates_controller_decorator_spec.rb +13 -0
  105. data/spec/factories/tim/base_image.rb +10 -0
  106. data/spec/factories/tim/image_factory/provider_image.rb +10 -0
  107. data/spec/factories/tim/image_factory/status_detail.rb +0 -0
  108. data/spec/factories/tim/image_factory/target_image.rb +7 -0
  109. data/spec/factories/tim/image_version.rb +20 -0
  110. data/spec/factories/tim/provider_image.rb +9 -0
  111. data/spec/factories/tim/target_image.rb +10 -0
  112. data/spec/factories/tim/template.rb +23 -0
  113. data/spec/filters/user_keys_filter_spec.rb +41 -0
  114. data/spec/fixtures/template.xml +13 -0
  115. data/spec/models/base_image_spec.rb +39 -0
  116. data/spec/models/dummy/pool_family_spec.rb +14 -0
  117. data/spec/models/dummy/provider_account_spec.rb +18 -0
  118. data/spec/models/dummy/provider_type_spec.rb +18 -0
  119. data/spec/models/dummy/user_spec.rb +14 -0
  120. data/spec/models/image_version_spec.rb +27 -0
  121. data/spec/models/provider_image_spec.rb +69 -0
  122. data/spec/models/target_image_spec.rb +75 -0
  123. data/spec/models/template_spec.rb +16 -0
  124. data/spec/spec_helper.rb +56 -0
  125. data/spec/support/routes.rb +41 -0
  126. data/spec/validators/template_validator_spec.rb +19 -0
  127. data/spec/views/base_images_spec.rb +23 -0
  128. data/spec/views/image_versions_spec.rb +25 -0
  129. data/spec/views/provider_images_spec.rb +30 -0
  130. data/spec/views/target_images_spec.rb +25 -0
  131. data/spec/views/templates_spec.rb +24 -0
  132. data/test/dummy/Rakefile +7 -0
  133. data/test/dummy/app/assets/javascripts/application.js +15 -0
  134. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  135. data/test/dummy/app/controllers/application_controller.rb +3 -0
  136. data/test/dummy/app/decorators/tim/controllers/templates_controller_decorator.rb +8 -0
  137. data/test/dummy/app/helpers/application_helper.rb +2 -0
  138. data/test/dummy/app/models/pool_family.rb +3 -0
  139. data/test/dummy/app/models/provider_account.rb +3 -0
  140. data/test/dummy/app/models/provider_type.rb +3 -0
  141. data/test/dummy/app/models/tim/base_image.rb +6 -0
  142. data/test/dummy/app/models/user.rb +3 -0
  143. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  144. data/test/dummy/app/views/tim/base_images/_custom.xml.haml +1 -0
  145. data/test/dummy/app/views/tim/image_versions/_custom.xml.haml +1 -0
  146. data/test/dummy/app/views/tim/layouts/application.html.erb +14 -0
  147. data/test/dummy/app/views/tim/provider_images/_custom.xml.haml +1 -0
  148. data/test/dummy/app/views/tim/target_images/_custom.xml.haml +1 -0
  149. data/test/dummy/app/views/tim/templates/_custom.xml.haml +1 -0
  150. data/test/dummy/config.ru +4 -0
  151. data/test/dummy/config/application.rb +58 -0
  152. data/test/dummy/config/boot.rb +10 -0
  153. data/test/dummy/config/database.yml +28 -0
  154. data/test/dummy/config/environment.rb +5 -0
  155. data/test/dummy/config/environments/development.rb +37 -0
  156. data/test/dummy/config/environments/production.rb +67 -0
  157. data/test/dummy/config/environments/test.rb +37 -0
  158. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  159. data/test/dummy/config/initializers/inflections.rb +15 -0
  160. data/test/dummy/config/initializers/mime_types.rb +5 -0
  161. data/test/dummy/config/initializers/secret_token.rb +7 -0
  162. data/test/dummy/config/initializers/session_store.rb +8 -0
  163. data/test/dummy/config/initializers/tim.rb +8 -0
  164. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  165. data/test/dummy/config/locales/en.yml +5 -0
  166. data/test/dummy/config/routes.rb +4 -0
  167. data/test/dummy/db/development.sqlite3 +0 -0
  168. data/test/dummy/db/migrate/20120326103723532622_create_users.rb +9 -0
  169. data/test/dummy/db/migrate/20120423123114264114_create_pool_families.rb +7 -0
  170. data/test/dummy/db/migrate/20120911182850_add_pool_family_id_to_tim_base_image.rb +5 -0
  171. data/test/dummy/db/migrate/20120911202845_add_provider_type_id_to_tim_target_image.rb +5 -0
  172. data/test/dummy/db/migrate/20120911203222_create_provider_types.rb +7 -0
  173. data/test/dummy/db/migrate/20120911205431_create_provider_accounts.rb +7 -0
  174. data/test/dummy/db/schema.rb +86 -0
  175. data/test/dummy/db/test.sqlite3 +0 -0
  176. data/test/dummy/log/development.log +982 -0
  177. data/test/dummy/log/test.log +8629 -0
  178. data/test/dummy/public/404.html +26 -0
  179. data/test/dummy/public/422.html +26 -0
  180. data/test/dummy/public/500.html +26 -0
  181. data/test/dummy/public/favicon.ico +0 -0
  182. data/test/dummy/script/rails +6 -0
  183. data/test/dummy/test.rb +0 -0
  184. data/test/dummy/tmp/cache/assets/C7A/BB0/sprockets%2F13445f7a19078dd2df39517062aa6711 +0 -0
  185. data/test/dummy/tmp/cache/assets/C8C/CC0/sprockets%2F95d79f3b3096348427f3e4e38b5202e3 +0 -0
  186. data/test/dummy/tmp/cache/assets/CB0/2B0/sprockets%2F79106b90879c02a115d7f6f1c8390ac4 +0 -0
  187. data/test/dummy/tmp/cache/assets/CE0/690/sprockets%2F04c628c2a636286bfa92a4966b82b92a +0 -0
  188. data/test/dummy/tmp/cache/assets/D03/040/sprockets%2Fd9e94204d4b307145f12efc109b16c1f +0 -0
  189. data/test/dummy/tmp/cache/assets/D06/DC0/sprockets%2Fcd282851b6e4c463409ba3ece67e0510 +0 -0
  190. data/test/dummy/tmp/cache/assets/D23/5F0/sprockets%2F2a521f3183c6bbcd71bd26a5490b201e +0 -0
  191. data/test/dummy/tmp/cache/assets/D64/3A0/sprockets%2F56ac1aed10c39b12a88cb1b30f668f58 +0 -0
  192. data/test/dummy/tmp/cache/assets/D69/BD0/sprockets%2F0aaf75cf34556b33a9fec534fe4d0415 +0 -0
  193. data/test/dummy/tmp/cache/assets/D87/D80/sprockets%2Fefa3c8b210e87358c7add88cd6f49597 +0 -0
  194. data/test/dummy/tmp/cache/assets/D89/200/sprockets%2Ff9b4e953c874ed6a87de6490d055d9db +0 -0
  195. data/test/dummy/tmp/cache/assets/DF4/430/sprockets%2F403bb1de60cae4325cebd7e6c389b8ad +0 -0
  196. data/test/dummy/tmp/cache/assets/E00/500/sprockets%2Faaddc5b6f2cb6b98930cc54cf4c64a95 +0 -0
  197. data/test/dummy/tmp/cache/assets/EB3/CE0/sprockets%2Fd75a89c9fffacd99bce7eed96844eafc +0 -0
  198. metadata +432 -0
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ module Tim
4
+ describe EntrypointController, :type => :controller do
5
+ render_views
6
+ Tim::Engine.routes.default_url_options = {:host => 'test.host'}
7
+
8
+ context "XML format response for " do
9
+ before do
10
+ send_and_accept_xml
11
+ end
12
+
13
+ describe "#index" do
14
+ before do
15
+ get :index
16
+ end
17
+
18
+ it { response.should be_success }
19
+ it { response.headers['Content-Type'].should include("application/xml") }
20
+ it "should have all resources URLs" do
21
+ resp = Hash.from_xml(response.body)
22
+ api = resp['api']
23
+ api['templates']['href'].should == templates_url
24
+ api['base_images']['href'].should == base_images_url
25
+ api['image_versions']['href'].should == image_versions_url
26
+ api['target_images']['href'].should == target_images_url
27
+ api['provider_images']['href'].should == provider_images_url
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,146 @@
1
+ require "spec_helper"
2
+
3
+ module Tim
4
+ describe ImageVersionsController do
5
+ render_views
6
+
7
+ describe "Image Versions API" do
8
+ before(:each) do
9
+ send_and_accept_xml
10
+ TargetImage.any_instance.stub(:create_factory_target_image).and_return(true)
11
+ ImageVersionsController.any_instance.stub(:template_exists?).and_return false
12
+ end
13
+
14
+ describe "Create Image Version" do
15
+
16
+ context "Success" do
17
+ it "should return a new image version as xml" do
18
+ post :create, { :image_version => {}}
19
+ response.code.should == "201"
20
+
21
+ body = Hash.from_xml(response.body)
22
+ body.keys.should == ["image_version"]
23
+ end
24
+
25
+ it "should return a new image version with base image as xml" do
26
+ post :create, { :image_version => {:base_image => {:name => "Name"}}}
27
+ response.code.should == "201"
28
+
29
+ body = Hash.from_xml(response.body)
30
+ body.keys.should == ["image_version"]
31
+ body["image_version"].keys.should =~ ["base_image", "id", "href", "target_images"]
32
+ body["image_version"]["base_image"].keys.should =~ ["id", "href"]
33
+ end
34
+ end
35
+
36
+ context "failure" do
37
+ it "should return a unprocessable entity error when the client sends invalid content" do
38
+ post :create, { :invalid_image => FactoryGirl.build(:image_version).attributes }
39
+ response.code.should == "422"
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "Show Image Version" do
45
+ context "Success" do
46
+ it "should return an existing image version as XML" do
47
+ image_version = FactoryGirl.create(:image_version_with_base_image)
48
+ get :show, :id => image_version.id
49
+
50
+ response.code.should == "200"
51
+
52
+ body = Hash.from_xml(response.body)
53
+ body.keys.should == ["image_version"]
54
+ body["image_version"].keys.should =~ ["id", "href", "target_images", "base_image"]
55
+ end
56
+
57
+ it "should return an existing base image as XML with target images" do
58
+ image_version = FactoryGirl.create(:image_version_with_target_images)
59
+ get :show, :id => image_version.id
60
+
61
+ response.code.should == "200"
62
+
63
+ body = Hash.from_xml(response.body)
64
+ body.keys.should == ["image_version"]
65
+ body["image_version"].keys.should =~ ["base_image", "id", "href", "target_images"]
66
+ body["image_version"]["target_images"]["target_image"].size.should == 2
67
+ end
68
+ end
69
+
70
+ context "failure" do
71
+ it "should return a not found response when an image version does not exist" do
72
+ get :show, :id => -1
73
+ response.code.should == "404"
74
+ end
75
+ end
76
+ end
77
+
78
+ describe "List Image Versions" do
79
+ context "Success" do
80
+ it "should return a list of existing base images as XML" do
81
+ 3.times do
82
+ FactoryGirl.create(:image_version_with_base_image)
83
+ end
84
+
85
+ get :index
86
+
87
+ body = Hash.from_xml(response.body)
88
+ body.keys.should == ["image_versions"]
89
+ body["image_versions"]["image_version"].first.keys.should =~ ["id", "href"]
90
+ body["image_versions"]["image_version"].size.should == ImageVersion.all.size
91
+ response.code.should == "200"
92
+ end
93
+ end
94
+ end
95
+
96
+ describe "Delete Image Version" do
97
+ context "Success" do
98
+ it "should return a no content code when deleting an image version" do
99
+ image_version = FactoryGirl.create(:image_version)
100
+ delete :destroy, :id => image_version.id
101
+ response.code.should == "204"
102
+
103
+ expect { ImageVersion.find(image_version.id) }.to raise_error(ActiveRecord::RecordNotFound)
104
+ end
105
+ end
106
+
107
+ context "Failure" do
108
+ it "should return a not found code when deleting an image version that does not exist" do
109
+ delete :destroy, :id => -1
110
+ response.code.should == "404"
111
+ end
112
+ end
113
+ end
114
+
115
+ describe "Update Image Version" do
116
+
117
+ context "Success" do
118
+ it "should return an updated image version as xml" do
119
+ image_version = FactoryGirl.create(:image_version_with_full_tree)
120
+ image_version.base_image = FactoryGirl.create(:base_image)
121
+ put :update, :id => image_version.id, :image_version => image_version.attributes
122
+ response.code.should == "200"
123
+
124
+ body = Hash.from_xml(response.body)
125
+ body.keys.should == ["image_version"]
126
+
127
+ ImageVersion.find(image_version.id).base_image.should == image_version.base_image
128
+ end
129
+ end
130
+
131
+ context "failure" do
132
+ it "should return a unprocessable entity error when the client sends invalid content" do
133
+ image_version = FactoryGirl.create(:image_version)
134
+ post :update, :id => image_version.id, :invalid_image => image_version.attributes
135
+ response.code.should == "422"
136
+ end
137
+
138
+ it "should return a not found code when updating an image version that does not exist" do
139
+ post :update, :id => -1, :image_version => FactoryGirl.build(:image_version).attributes
140
+ response.code.should == "404"
141
+ end
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,156 @@
1
+ require "spec_helper"
2
+
3
+ module Tim
4
+ describe ProviderImagesController do
5
+ render_views
6
+
7
+ describe "Provider Images API" do
8
+ before(:each) do
9
+ send_and_accept_xml
10
+ TargetImage.any_instance.stub(:template).and_return(FactoryGirl.build(:template))
11
+ ProviderImage.any_instance.stub(:create_factory_provider_image).and_return(true)
12
+ TargetImage.any_instance.stub(:create_factory_target_image).and_return(true)
13
+ @status_detail = mock(:status)
14
+ @status_detail.stub(:activity).and_return("Building")
15
+ ImageFactory::TargetImage.stub(:create).and_return(FactoryGirl.build(:image_factory_target_image, :status_detail => @status_detail))
16
+ ProviderImagesController.any_instance.stub(:template_exists?).and_return false
17
+ end
18
+
19
+ describe "Create Provider Image" do
20
+ before(:each) do
21
+ ImageFactory::ProviderImage.stub(:create).and_return(FactoryGirl.build(:image_factory_provider_image))
22
+ end
23
+
24
+ context "Success" do
25
+ it "should return a new provider image as xml" do
26
+ provider_image = FactoryGirl.build(:provider_image_with_full_tree)
27
+ post :create, { :provider_image => provider_image.attributes }
28
+ response.code.should == "201"
29
+
30
+ body = Hash.from_xml(response.body)
31
+ body.keys.should == ["provider_image"]
32
+ body["provider_image"].keys.should =~ ["external_image_id", "provider",
33
+ "snapshot", "status_detail", "progress", "href", "id","target_image", "status"]
34
+ body["provider_image"]["target_image"]["id"].should == provider_image.target_image .id.to_s
35
+ end
36
+ end
37
+
38
+ context "failure" do
39
+ it "should return a unprocessable entity error when the client sends invalid content" do
40
+ post :create, { :invalid_image => FactoryGirl.build(:provider_image).attributes }
41
+ response.code.should == "422"
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "Show Provider Image" do
47
+ context "Success" do
48
+ it "should return an existing provider image as XML" do
49
+ provider_image = FactoryGirl.create(:provider_image_with_full_tree)
50
+ get :show, :id => provider_image.id
51
+
52
+ response.code.should == "200"
53
+
54
+ body = Hash.from_xml(response.body)
55
+ body.keys.should == ["provider_image"]
56
+ body["provider_image"].keys.should =~ ["external_image_id", "provider",
57
+ "snapshot", "status_detail", "progress", "href", "id","target_image", "status"]
58
+ body["provider_image"]["target_image"]["id"].should == provider_image.target_image .id.to_s
59
+ end
60
+ end
61
+
62
+ context "failure" do
63
+ it "should return a not found response when an provider image does not exist" do
64
+ get :show, :id => -1
65
+ response.code.should == "404"
66
+ end
67
+ end
68
+ end
69
+
70
+ describe "List Image Versions" do
71
+ context "Success" do
72
+ it "should return a list of existing provider images as XML" do
73
+ 3.times do
74
+ FactoryGirl.create(:provider_image)
75
+ end
76
+
77
+ get :index
78
+
79
+ body = Hash.from_xml(response.body)
80
+ body.keys.should == ["provider_images"]
81
+ body["provider_images"]["provider_image"].first.keys.should =~ ["id", "href"]
82
+ response.code.should == "200"
83
+ end
84
+ end
85
+ end
86
+
87
+ describe "Delete Provider Image" do
88
+ context "Success" do
89
+ it "should return a no content code when deleting a provider image" do
90
+ provider_image = FactoryGirl.create(:provider_image)
91
+ delete :destroy, :id => provider_image.id
92
+ response.code.should == "204"
93
+
94
+ expect { ProviderImage.find(provider_image.id) }.to raise_error(ActiveRecord::RecordNotFound)
95
+ end
96
+ end
97
+
98
+ context "Failure" do
99
+ it "should return a not found code when deleting a provider image" do
100
+ delete :destroy, :id => -1
101
+ response.code.should == "404"
102
+ end
103
+ end
104
+ end
105
+
106
+ describe "Update Provider Image" do
107
+
108
+ context "Success" do
109
+ it "should return an updated provider image as xml" do
110
+ provider_image = FactoryGirl.create(:provider_image_with_full_tree)
111
+ provider_image.target_image = FactoryGirl.create(:target_image )
112
+ put :update, :id => provider_image.id, :provider_image => provider_image.attributes
113
+ response.code.should == "200"
114
+
115
+ body = Hash.from_xml(response.body)
116
+ body.keys.should == ["provider_image"]
117
+
118
+ ProviderImage.find(provider_image.id).target_image.should == provider_image.target_image
119
+ end
120
+ end
121
+
122
+ context "failure" do
123
+ it "should return a unprocessable entity error when the client sends invalid content" do
124
+ provider_image = FactoryGirl.create(:provider_image)
125
+ post :update, :id => provider_image.id, :invalid_image => provider_image.attributes
126
+ response.code.should == "422"
127
+ end
128
+
129
+ it "should return a not found code when updating a Provider image that does not exist" do
130
+ delete :update, :id => -1, :provider_image => FactoryGirl.create(:provider_image).attributes
131
+ response.code.should == "404"
132
+ end
133
+ end
134
+ end
135
+
136
+ describe "Update Provider Image via factory callback" do
137
+ before(:each) do
138
+ send_and_accept_json
139
+ end
140
+
141
+ it "should update provider image status attributes via json" do
142
+ provider_image = FactoryGirl.create(:provider_image_with_full_tree)
143
+ factory_attributes = {:percent_complete => "100", "status_detail" => {:activity => "Building Image"} }
144
+ hash = provider_image.attributes.merge(factory_attributes)
145
+ put :update, :id => provider_image.id, :provider_image => hash
146
+ response.code.should == "200"
147
+
148
+ body = JSON.parse(response.body)
149
+ body.keys.should == ["provider_image"]
150
+ body["provider_image"]["status_detail"].should == "Building Image"
151
+ body["provider_image"]["progress"].should == "100"
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,153 @@
1
+ require "spec_helper"
2
+
3
+ module Tim
4
+ describe TargetImagesController do
5
+ render_views
6
+
7
+ describe "Target Images API" do
8
+ before(:each) do
9
+ send_and_accept_xml
10
+ TargetImage.any_instance.stub(:template).and_return(FactoryGirl.build(:template))
11
+ TargetImage.any_instance.stub(:create_factory_target_image).and_return(true)
12
+ @status_detail = mock(:status)
13
+ @status_detail.stub(:activity).and_return("Building")
14
+ TargetImagesController.any_instance.stub(:template_exists?).and_return false
15
+ end
16
+
17
+ describe "Create Target Image" do
18
+ before(:each) do
19
+ ImageFactory::TargetImage.stub(:create).and_return(FactoryGirl.build(:image_factory_target_image, :status_detail => @status_detail))
20
+ TargetImage.any_instance.stub(:template).and_return FactoryGirl.build(:template)
21
+ end
22
+
23
+ context "Success" do
24
+ it "should return a new target image as xml" do
25
+ target_image = FactoryGirl.build(:target_image_with_full_tree)
26
+ post :create, { :target_image => target_image.attributes }
27
+ response.code.should == "201"
28
+
29
+ body = Hash.from_xml(response.body)
30
+ body.keys.should == ["target_image"]
31
+ body["target_image"].keys.should =~ ["target", "status", "status_detail", "progress", "href", "id", "provider_images", "image_version"]
32
+ body["target_image"]["image_version"]["id"].should == target_image.image_version.id.to_s
33
+ end
34
+ end
35
+
36
+ context "failure" do
37
+ it "should return a unprocessable entity error when the client sends invalid content" do
38
+ post :create, { :invalid_image => FactoryGirl.build(:target_image).attributes }
39
+ response.code.should == "422"
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "Show Target Image" do
45
+ context "Success" do
46
+ it "should return an existing target image as XML" do
47
+ target_image = FactoryGirl.create(:target_image_with_full_tree)
48
+ get :show, :id => target_image.id
49
+
50
+ response.code.should == "200"
51
+
52
+ body = Hash.from_xml(response.body)
53
+ body.keys.should == ["target_image"]
54
+ body["target_image"].keys.should =~ ["id", "href", "image_version",
55
+ "provider_images", "target", "status", "status_detail", "progress"]
56
+ end
57
+ end
58
+
59
+ context "failure" do
60
+ it "should return a not found response when an target image does not exist" do
61
+ get :show, :id => -1
62
+ response.code.should == "404"
63
+ end
64
+ end
65
+ end
66
+
67
+ describe "List Image Versions" do
68
+ context "Success" do
69
+ it "should return a list of existing target images as XML" do
70
+ 3.times do
71
+ FactoryGirl.create(:target_image)
72
+ end
73
+
74
+ get :index
75
+
76
+ body = Hash.from_xml(response.body)
77
+ body.keys.should == ["target_images"]
78
+ body["target_images"]["target_image"].first.keys.should =~ ["id", "href"]
79
+ response.code.should == "200"
80
+ end
81
+ end
82
+ end
83
+
84
+ describe "Delete Target Image" do
85
+ context "Success" do
86
+ it "should return a no content code when deleting a target image" do
87
+ target_image = FactoryGirl.create(:target_image)
88
+ delete :destroy, :id => target_image.id
89
+ response.code.should == "204"
90
+
91
+ expect { TargetImage.find(target_image.id) }.to raise_error(ActiveRecord::RecordNotFound)
92
+ end
93
+ end
94
+
95
+ context "Failure" do
96
+ it "should return a not found code when deleting a target image" do
97
+ delete :destroy, :id => -1
98
+ response.code.should == "404"
99
+ end
100
+ end
101
+ end
102
+
103
+ describe "Update Target Image" do
104
+
105
+ context "Success" do
106
+ it "should return an updated target image as xml" do
107
+ target_image = FactoryGirl.create(:target_image_with_full_tree)
108
+ target_image.image_version = FactoryGirl.create(:image_version)
109
+ put :update, :id => target_image.id, :target_image => target_image.attributes
110
+ response.code.should == "200"
111
+
112
+ body = Hash.from_xml(response.body)
113
+ body.keys.should == ["target_image"]
114
+
115
+ TargetImage.find(target_image.id).image_version.should == target_image.image_version
116
+ end
117
+ end
118
+
119
+ context "failure" do
120
+ it "should return a unprocessable entity error when the client sends invalid content" do
121
+ target_image = FactoryGirl.create(:target_image)
122
+ put :update, :id => target_image.id, :invalid_image => target_image.attributes
123
+ response.code.should == "422"
124
+ end
125
+
126
+ it "should return a not found code when updating a target image that does not exist" do
127
+ delete :update, :id => -1, :target_image => FactoryGirl.build(:target_image).attributes
128
+ response.code.should == "404"
129
+ end
130
+ end
131
+ end
132
+
133
+ describe "Update Target Image via factory callback" do
134
+ before(:each) do
135
+ send_and_accept_json
136
+ end
137
+
138
+ it "should update target image status attributes via json" do
139
+ target_image = FactoryGirl.create(:target_image_with_full_tree)
140
+ factory_attributes = {:percent_complete => "100", :status_detail => {:activity => "Building Image"} }
141
+ hash = target_image.attributes.merge(factory_attributes)
142
+ put :update, :id => target_image.id, :target_image => hash
143
+ response.code.should == "200"
144
+
145
+ body = JSON.parse(response.body)
146
+ body.keys.should == ["target_image"]
147
+ body["target_image"]["status_detail"].should == "Building Image"
148
+ body["target_image"]["progress"].should == "100"
149
+ end
150
+ end
151
+ end
152
+ end
153
+ end