From: Tomas Sedovic <[email protected]>
Some of the tests are failing.
---
src/spec/models/hardware_profile_spec.rb | 134 ++++++++++++++++++++++++++++++
1 files changed, 134 insertions(+), 0 deletions(-)
create mode 100644 src/spec/models/hardware_profile_spec.rb
diff --git a/src/spec/models/hardware_profile_spec.rb
b/src/spec/models/hardware_profile_spec.rb
new file mode 100644
index 0000000..83aec74
--- /dev/null
+++ b/src/spec/models/hardware_profile_spec.rb
@@ -0,0 +1,134 @@
+require 'spec_helper'
+
+describe HardwareProfile do
+ before(:each) do
+ @valid_attributes = Factory.attributes_for(:mock_hwp1)
+ end
+
+ it "should create a new hardware profile" do
+ hp = HardwareProfile.new(@valid_attributes)
+ hp.should be_valid
+ end
+
+ it "should not validate for missing name" do
+ hp = HardwareProfile.new(@valid_attributes)
+
+ [nil, ""].each do |value|
+ hp.name = value
+ hp.should_not be_valid
+ end
+ end
+
+ it "should require unique names" do
+ hp1 = Factory.create(:mock_hwp1)
+ hp2 = Factory.create(:mock_hwp2)
+ hp1.should be_valid
+ hp2.should be_valid
+
+ hp2.name = hp1.name
+ hp2.should_not be_valid
+ end
+
+ it "should require valid amount of memory" do
+ hp = HardwareProfile.new(@valid_attributes)
+
+ [nil, "hello", -1].each do |fail_value|
+ hp.memory = fail_value
+ hp.should_not be_valid
+ end
+ end
+
+ it "should require valid amount of storage" do
+ hp = HardwareProfile.new(@valid_attributes)
+
+ [nil, "hello", -1].each do |fail_value|
+ hp.storage = fail_value
+ hp.should_not be_valid
+ end
+ end
+
+ it "should not require architecture when there's no provider" do
+ hp = HardwareProfile.new(@valid_attributes)
+ hp.architecture = nil
+ hp.should be_valid
+ end
+
+ it "should require architecture when it's with provider" do
+ provider = Factory.create(:mock_provider)
+ hp = provider.hardware_profiles[0]
+
+ hp.should be_valid
+ hp.architecture = nil
+ hp.should_not be_valid
+ end
+
+ it "should reject Aggregator profiles for custom Instance profiles" do
+ hp = HardwareProfile.new(@valid_attributes)
+ hp.aggregator_hardware_profiles << hp
+ hp.should_not be_valid
+ hp.should have(1).error_on(:aggregator_hardware_profiles)
+ hp.errors.on(:aggregator_hardware_profiles).should
+ eql("Aggregator profiles are not allowed for custom Instance profiles")
+
+ hp.aggregator_hardware_profiles.clear
+ hp.should be_valid
+ end
+
+ it "should reject Provider profiles for custom Instance profiles" do
+ hp = HardwareProfile.new(@valid_attributes)
+ hp.provider_hardware_profiles << hp
+ hp.should_not be_valid
+ hp.should have(1).error_on(:provider_hardware_profiles)
+ hp.errors.on(:provider_hardware_profiles).should
+ eql("Provider profiles are not allowed for custom Instance profiles")
+
+ hp.provider_hardware_profiles.clear
+ hp.should be_valid
+ end
+
+ it "should require either provider or pool to be blank" do
+ hp = HardwareProfile.new(@valid_attributes)
+ hp.provider = Provider.new
+ hp.portal_pool = PortalPool.new
+ hp.should_not be_valid
+ hp.should have(1).error_on(:provider)
+ hp.errors.on(:provider).should eql("provider or pool must be blank")
+ hp.should have(1).error_on(:portal_pool)
+ hp.errors.on(:portal_pool).should eql("provider or pool must be blank")
+
+ hp.provider = nil
+ hp.should be_valid
+
+ hp.provider = Provider.new
+ hp.portal_pool = nil
+ hp.should be_valid
+ end
+
+ it "should allow Provider profiles only for provider profiles" do
+ hp = HardwareProfile.new(@valid_attributes)
+ hp.provider = nil
+ hp.portal_pool = PortalPool.new
+
+ hp.provider_hardware_profiles << hp
+ hp.should have(1).error_on(:provider_hardware_profiles)
+ hp.errors.on(:provider_hardware_profiles).should eql("Provider profiles
only allowed for provider profiles")
+
+ hp.provider_hardware_profiles.clear
+ hp.should be_valid
+ end
+
+ it "should allow Aggregator profiles only for pool profiles" do
+ hp = HardwareProfile.new(@valid_attributes)
+ hp.provider = Provider.new
+ hp.portal_pool = nil
+
+ hp.aggregator_hardware_profiles << hp
+ hp.should have(1).error_on(:aggregator_hardware_profiles)
+ hp.errors.on(:aggregator_hardware_profiles).should eql(
+ "Aggregator profiles only allowed for pool profiles")
+
+ hp.aggregator_hardware_profiles.clear
+ hp.should be_valid
+ end
+
+end
--
1.6.6.1
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel