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,41 @@
1
+ require "spec_helper"
2
+
3
+ module Tim
4
+ describe TemplatesController do
5
+ render_views
6
+
7
+ describe "Templates API" do
8
+
9
+ before(:each) do
10
+ send_and_accept_xml
11
+ TemplatesController.any_instance.stub(:template_exists?).and_return false
12
+ end
13
+
14
+ describe "Create Template" do
15
+
16
+ context "Success" do
17
+ it "should return a new template as xml" do
18
+ template = FactoryGirl.build(:template)
19
+ request.env['RAW_POST_DATA'] = template.xml
20
+ post :create
21
+
22
+ response.code.should == "201"
23
+ template_xml = ::Nokogiri::XML::Document.parse(response.body)
24
+ template_xml.xpath("//template/*").to_xml
25
+ .include?(template.xml_elements).should == true
26
+ template_xml.xpath("//template/@*").map { |node| node.name}
27
+ .should =~ ["id", "href"]
28
+ end
29
+ end
30
+
31
+ context "failure" do
32
+ it "should return a unprocessable entity error when the client sends invalid content" do
33
+ request.env['RAW_POST_DATA'] = "<invalid_template></invalid_template>"
34
+ post :create
35
+ response.code.should == "422"
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,13 @@
1
+ require "spec_helper"
2
+
3
+ module Tim
4
+ describe TemplatesController, :type => :controller do
5
+ describe "Controller Decorator Pattern" do
6
+ it "should allow overriding of instance variables in before filter" do
7
+ Tim::Template.stub(:limit).and_return("test")
8
+ get :index
9
+ controller.instance_variable_get(:@templates).should == "test"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :base_image, :class => Tim::BaseImage do
3
+ name "test base image"
4
+ description "description of test image"
5
+ end
6
+
7
+ factory :base_image_with_template, :parent => :base_image do
8
+ association :template, :factory => :template
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :image_factory_provider_image, :class => Tim::ImageFactory::ProviderImage do
3
+ status "New"
4
+ id "4cc3b024-5fe7-4b0b-934b-c5d463b990b0"
5
+ percent_complete "10"
6
+ provider "MockSphere"
7
+ identifier_on_provider "mock-123456"
8
+ provider_account_identifier "mock-account-123"
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :image_factory_target_image, :class => Tim::ImageFactory::TargetImage do
3
+ status "NEW"
4
+ id '4cc3b024-5fe7-4b0b-934b-c5d463b990b0'
5
+ percent_complete '0'
6
+ end
7
+ end
@@ -0,0 +1,20 @@
1
+ module Tim
2
+ FactoryGirl.define do
3
+ factory :image_version, :class => Tim::ImageVersion do
4
+ end
5
+
6
+ factory :image_version_with_base_image, :parent => :image_version do
7
+ association :base_image, :factory => :base_image
8
+ end
9
+
10
+ factory :image_version_with_full_tree, :parent => :image_version do
11
+ association :base_image, :factory => :base_image_with_template
12
+ end
13
+
14
+ factory :image_version_with_target_images, :parent => :image_version_with_full_tree do
15
+ after(:create) do |image_version, evaluator|
16
+ FactoryGirl.create_list(:target_image, 2, :image_version => image_version)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,9 @@
1
+ FactoryGirl.define do
2
+ factory :provider_image, :class => Tim::ProviderImage do
3
+ association :target_image, :factory => :target_image
4
+ end
5
+
6
+ factory :provider_image_with_full_tree, :parent => :provider_image do
7
+ association :target_image, :factory => :target_image_with_full_tree
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ FactoryGirl.define do
2
+ factory :target_image, :class => Tim::TargetImage do
3
+ association :image_version, :factory => :image_version
4
+ target 'Mock'
5
+ end
6
+
7
+ factory :target_image_with_full_tree, :parent => :target_image do
8
+ association :image_version, :factory => :image_version_with_full_tree
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ FactoryGirl.define do
2
+ factory :template, :class => Tim::Template do
3
+ xml "<template>
4
+ <name>Fedora 15</name>
5
+ <description>desc</description>
6
+ <os>
7
+ <rootpw>password</rootpw>
8
+ <name>Fedora</name>
9
+ <arch>x86_64</arch>
10
+ <version>15</version>
11
+ <install type='url'>
12
+ <url>http://download.fedoraproject.org/pub/fedora/linux/releases/15/Fedora/x86_64/os/</url>
13
+ </install>
14
+ </os>
15
+ <repositories>
16
+ <repository name='custom'>
17
+ <url>http://repos.fedorapeople.org/repos/aeolus/demo/webapp/</url>
18
+ <signed>false</signed>
19
+ </repository>
20
+ </repositories>
21
+ </template>"
22
+ end
23
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ module Tim
4
+ describe UserKeysFilter do
5
+
6
+ before(:all) do |spec|
7
+ @user_keys = {:k1 => :a1, :k2 => :a2}
8
+ end
9
+
10
+ describe "replace user keys" do
11
+ it 'should replace user keys with respective specified alternate' do
12
+ hash = UserKeysFilter.replace_user_keys({:k1 => :v1, :k2 => :v2}, @user_keys)
13
+ hash[:a1].should == :v1
14
+ hash[:a2].should == :v2
15
+ hash.has_key?(:k1).should == false
16
+ hash.has_key?(:k2).should == false
17
+ end
18
+
19
+ it 'should replace nested user keys' do
20
+ hash = UserKeysFilter.replace_user_keys({:k1 => {:k2 => :v2}}, @user_keys)
21
+ hash[:a1].should == {:a2 => :v2}
22
+ end
23
+ end
24
+
25
+ describe "replace user keys" do
26
+ it 'should get the correct hash from params via controller name' do
27
+ request = mock("Request")
28
+ request.stub(:format).and_return "application/xml"
29
+ controller = double("ApplicationController")
30
+ controller.stub(:request).and_return request
31
+ controller.stub(:controller_name).and_return "resources"
32
+ controller.stub(:params).and_return({:resource => {:k1 => {:k2 => :v2}}})
33
+
34
+ UserKeysFilter.should_receive(:replace_user_keys).with({:k1 => {:k2 => :v2}}, nil)
35
+ UserKeysFilter.stub(:replace_user_keys).and_return({:a1 => {:a2 => :v2}}, nil)
36
+
37
+ UserKeysFilter.before(controller)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,13 @@
1
+ <template>
2
+ <name>mock</name>
3
+ <description>Mock Template</description>
4
+ <os>
5
+ <name>RHELMock</name>
6
+ <version>1</version>
7
+ <arch>x86_64</arch>
8
+ <install type=\"iso\">
9
+ <iso>http://mockhost/RHELMock1-x86_64-DVD.iso</iso>
10
+ </install>
11
+ <rootpw>password</rootpw>
12
+ </os>
13
+ </template>
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ module Tim
4
+ describe BaseImage do
5
+ describe "Model relationships" do
6
+ it 'should have many image versions' do
7
+ base_image = BaseImage.new
8
+ 2.times do
9
+ base_image.image_versions << ImageVersion.new
10
+ end
11
+ base_image.save!
12
+ BaseImage.find(base_image).image_versions.size.should == 2
13
+ end
14
+
15
+ it "should have one template" do
16
+ base_image = BaseImage.new
17
+ base_image.template = FactoryGirl.build(:template)
18
+ base_image.save!
19
+ BaseImage.find(base_image).template.should == base_image.template
20
+ end
21
+ end
22
+
23
+ describe "Dummy model relationships" do
24
+ it "should have one pool family" do
25
+ base_image = BaseImage.new
26
+ base_image.pool_family = PoolFamily.new
27
+ base_image.save!
28
+ BaseImage.find(base_image).pool_family.should == base_image.pool_family
29
+ end
30
+
31
+ it "should have one user" do
32
+ base_image = BaseImage.new
33
+ base_image.user = User.new
34
+ base_image.save!
35
+ BaseImage.find(base_image).user.should == base_image.user
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe PoolFamily do
4
+ describe "Dummy Model relationships" do
5
+ it 'should have many base images' do
6
+ pool_family = PoolFamily.new
7
+ 2.times do
8
+ pool_family.base_images << Tim::BaseImage.new
9
+ end
10
+ pool_family.save!
11
+ PoolFamily.find(pool_family).base_images.size.should == 2
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe ProviderAccount do
4
+ describe "Dummy Model relationships" do
5
+ before(:each) do
6
+ Tim::ProviderImage.any_instance.stub(:create_factory_provider_image).and_return(true)
7
+ end
8
+
9
+ it 'should have many provider images' do
10
+ provider_account = ProviderAccount.new
11
+ 2.times do
12
+ provider_account.provider_images << Tim::ProviderImage.new
13
+ end
14
+ provider_account.save!
15
+ ProviderAccount.find(provider_account).provider_images.size.should == 2
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe ProviderType do
4
+ describe "Dummy Model relationships" do
5
+ before (:each) do
6
+ Tim::TargetImage.any_instance.stub(:create_factory_target_image).and_return(true)
7
+ end
8
+
9
+ it 'should have many target images' do
10
+ provider_type = ProviderType.new
11
+ 2.times do
12
+ provider_type.target_images << Tim::TargetImage.new
13
+ end
14
+ provider_type.save!
15
+ ProviderType.find(provider_type).target_images.size.should == 2
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe User do
4
+ describe "Dummy Model relationships" do
5
+ it 'should have many base images' do
6
+ user = User.new
7
+ 2.times do
8
+ user.base_images << Tim::BaseImage.new
9
+ end
10
+ user.save!
11
+ User.find(user).base_images.size.should == 2
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ module Tim
4
+ describe ImageVersion do
5
+ describe "Model relationships" do
6
+ before (:each) do
7
+ TargetImage.any_instance.stub(:create_factory_target_image).and_return(true)
8
+ end
9
+
10
+ it 'should have one base image' do
11
+ image_version = ImageVersion.new
12
+ image_version.base_image = BaseImage.new
13
+ image_version.save!
14
+ ImageVersion.find(image_version).base_image.should == image_version.base_image
15
+ end
16
+
17
+ it 'should have many target images' do
18
+ image_version = ImageVersion.new
19
+ 2.times do
20
+ image_version.target_images << TargetImage.new
21
+ end
22
+ image_version.save!
23
+ ImageVersion.find(image_version).target_images.size.should == 2
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ module Tim
4
+ describe ProviderImage do
5
+ before (:each) do
6
+ TargetImage.any_instance.stub(:create_factory_target_image).and_return(true)
7
+ end
8
+
9
+ describe "Model relationships" do
10
+ it 'should have one target image' do
11
+ provider_image = ProviderImage.new
12
+ provider_image.target_image = TargetImage.new
13
+ provider_image.stub(:create_factory_provider_image).and_return(true)
14
+ provider_image.save!
15
+ ProviderImage.find(provider_image).target_image.should == provider_image.target_image
16
+ end
17
+ end
18
+
19
+ describe "Dummy model relationships" do
20
+ it "should have one provider account" do
21
+ provider_image = ProviderImage.new
22
+ provider_image.provider_account = ProviderAccount.new
23
+ provider_image.stub(:create_factory_provider_image).and_return(true)
24
+ provider_image.save!
25
+ ProviderImage.find(provider_image).provider_account.should == provider_image.provider_account
26
+ end
27
+ end
28
+
29
+ describe "ImageFactory interactions" do
30
+ describe "Successful Requests" do
31
+ before(:each) do
32
+ ImageFactory::ProviderImage.any_instance.stub(:save!)
33
+ TargetImage.any_instance.stub(:factory_id).and_return("1234")
34
+ end
35
+
36
+ it "should create factory provider image and populate fields" do
37
+ # Needed due to ActiveRecord::Associations::Association#target
38
+ # name conflict
39
+ target = mock(:target)
40
+ target.stub(:target).and_return("mock")
41
+
42
+ pi = FactoryGirl.build(:provider_image)
43
+ pi.target_image.target = target
44
+ pi.should_receive(:populate_factory_fields)
45
+ pi.save
46
+ end
47
+
48
+ it "should add factory fields to provider image" do
49
+ status_detail = mock(:status_detail)
50
+ status_detail.stub(:activity).and_return("Building")
51
+
52
+ pi = FactoryGirl.build(:provider_image)
53
+ pi.send(:populate_factory_fields, FactoryGirl
54
+ .build(:image_factory_provider_image,
55
+ :status_detail => status_detail))
56
+
57
+ pi.factory_id.should == "4cc3b024-5fe7-4b0b-934b-c5d463b990b0"
58
+ pi.status.should == "New"
59
+ pi.status_detail.should == "Building"
60
+ pi.progress.should == "10"
61
+ pi.provider.should == "MockSphere"
62
+ pi.external_image_id.should == "mock-123456"
63
+ pi.provider_account_id.should == "mock-account-123"
64
+ end
65
+
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ module Tim
4
+ describe TargetImage do
5
+
6
+ #TODO FIX: A bug in RSpec V2.1 means that any_instance propogates across context therefore we are stubbing each
7
+ #target_image. This bug is fixed in RSpec V2.6
8
+ describe "Model relationships" do
9
+ it 'should have one images version' do
10
+ target_image = TargetImage.new
11
+ target_image.stub(:create_factory_target_image).and_return(true)
12
+ target_image.image_version = ImageVersion.new
13
+ target_image.save!
14
+ TargetImage.find(target_image).image_version.should == target_image.image_version
15
+ end
16
+
17
+ it 'should have many provider images' do
18
+ target_image = TargetImage.new
19
+ target_image.stub(:create_factory_target_image).and_return(true)
20
+ ProviderImage.any_instance.stub(:create_factory_provider_image).and_return(true)
21
+ 2.times do
22
+ target_image.provider_images << ProviderImage.new
23
+ end
24
+ target_image.save!
25
+ TargetImage.find(target_image).provider_images.size.should == 2
26
+ end
27
+ end
28
+
29
+ describe "Dummy model relationships" do
30
+ it "should have one provider type" do
31
+ target_image = TargetImage.new
32
+ target_image.stub(:create_factory_target_image).and_return(true)
33
+ target_image.provider_type = ProviderType.new
34
+ target_image.save!
35
+ TargetImage.find(target_image).provider_type.should == target_image.provider_type
36
+ end
37
+ end
38
+
39
+ describe "ImageFactory interactions" do
40
+ describe "Successful Requests" do
41
+ before(:each) do
42
+ ImageFactory::TargetImage.any_instance.stub(:save!)
43
+ end
44
+
45
+ it "should create factory provider image and populate fields" do
46
+ # Needed due to ActiveRecord::Associations::Association#target
47
+ # name conflict
48
+ target = mock(:target)
49
+ target.stub(:target).and_return("mock")
50
+
51
+ ti = FactoryGirl.build(:target_image_with_full_tree)
52
+ ti.target = target
53
+ ti.should_receive(:populate_factory_fields)
54
+ ti.save
55
+ end
56
+
57
+ it "should add factory fields to provider image" do
58
+ status_detail = mock(:status_detail)
59
+ status_detail.stub(:activity).and_return("Building")
60
+
61
+ ti = FactoryGirl.build(:target_image_with_full_tree)
62
+ ti.send(:populate_factory_fields, FactoryGirl
63
+ .build(:image_factory_target_image,
64
+ :status_detail => status_detail))
65
+
66
+ ti.factory_id.should == "4cc3b024-5fe7-4b0b-934b-c5d463b990b0"
67
+ ti.status.should == "NEW"
68
+ ti.status_detail.should == "Building"
69
+ ti.progress.should == "0"
70
+ end
71
+
72
+ end
73
+ end
74
+ end
75
+ end