From: Tomas Sedovic <[email protected]>
One test is failing.
---
src/spec/factories/image.rb | 14 ++++++
src/spec/models/image_spec.rb | 91 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 105 insertions(+), 0 deletions(-)
create mode 100644 src/spec/factories/image.rb
create mode 100644 src/spec/models/image_spec.rb
diff --git a/src/spec/factories/image.rb b/src/spec/factories/image.rb
new file mode 100644
index 0000000..fdb1e32
--- /dev/null
+++ b/src/spec/factories/image.rb
@@ -0,0 +1,14 @@
+Factory.define :image do |i|
+ i.sequence(:name) { |n| "image#{n}" }
+ i.sequence(:external_key) { |n| "key#{n}" }
+ i.architecture 'i686'
+end
+
+Factory.define :image_with_provider, :parent => :image do |i|
+ i.association :provider, :factory => :mock_provider
+ i.architecture 'x86_64'
+end
+
+Factory.define :image_with_pool, :parent => :image do |i|
+ i.association :portal_pool, :factory => :portal_pool
+end
diff --git a/src/spec/models/image_spec.rb b/src/spec/models/image_spec.rb
new file mode 100644
index 0000000..c75eace
--- /dev/null
+++ b/src/spec/models/image_spec.rb
@@ -0,0 +1,91 @@
+require 'spec_helper'
+
+describe Image do
+ before(:each) do
+ end
+
+ it "should have a unique external key" do
+ provider = Factory.create(:mock_provider)
+ i1 = Factory.create(:image, :provider => provider)
+ i2 = Factory.create(:image, :provider => provider)
+ provider.images = [i1, i2]
+ i1.should be_valid
+ i2.should be_valid
+
+ i2.external_key = i1.external_key
+ i2.should_not be_valid
+ end
+
+ it "should have a name" do
+ i = Factory.build(:image_with_provider, :name => nil)
+ i.should_not be_valid
+
+ i.name = ''
+ i.should_not be_valid
+
+ i.name = "valid name"
+ i.should be_valid
+ end
+
+ it "should not have a name that is too long" do
+ i = Factory.create(:image_with_provider)
+ i.name = 'x' * 1025
+ i.should_not be_valid
+
+ i.name = 'x' * 1024
+ i.should be_valid
+ end
+
+ it "should have an architecture if it has a provider" do
+ i = Factory.build(:image_with_provider, :architecture => nil)
+ i.should_not be_valid
+
+ i.architecture = 'i686'
+ i.should be_valid
+ end
+
+ it "should have either a provider or a pool specified" do
+ i = Factory.build(:image)
+ i.should have(1).error_on(:provider)
+ i.should have(1).error_on(:portal_pool)
+ i.errors.on(:provider).should eql("provider or pool must be specified")
+ i.errors.on(:portal_pool).should eql("provider or pool must be specified")
+
+ i.provider = Factory.build(:mock_provider)
+ i.should be_valid
+
+ i.portal_pool = Factory.build(:portal_pool)
+ i.should have(1).error_on(:provider)
+ i.should have(1).error_on(:portal_pool)
+ i.errors.on(:provider).should eql("provider or pool must be blank")
+ i.errors.on(:portal_pool).should eql("provider or pool must be blank")
+
+ i.provider = nil
+ i.should be_valid
+ end
+
+ it "should have provider images only if it has a provider" do
+ i = Factory.build(:image_with_pool)
+
+ i.aggregator_images << i
+ i.should have(1).error_on(:aggregator_images)
+ i.errors.on(:aggregator_images).should
+ eql "Aggregator image only allowed for provider images"
+
+ i.aggregator_images.clear
+ i.should be_valid
+ end
+
+ it "should have aggregator images only if it has a pool" do
+ i = Factory.build(:image_with_provider)
+
+ i.provider_images << i
+ i.should have(1).error_on(:provider_images)
+ i.errors.on(:provider_images).should
+ eql "Provider images only allowed for aggregator images"
+
+ i.provider_images.clear
+ i.should be_valid
+ end
+
+end
--
1.6.6.1
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel