The first patch adds the spec, making a few tests to fail. The second one makes them pass again.
From: Tomas Sedovic tsedovic@redhat.com
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
From: Tomas Sedovic tsedovic@redhat.com
--- src/app/models/hardware_profile.rb | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/app/models/hardware_profile.rb b/src/app/models/hardware_profile.rb index 7714acb..fd7fbe3 100644 --- a/src/app/models/hardware_profile.rb +++ b/src/app/models/hardware_profile.rb @@ -42,11 +42,12 @@ class HardwareProfile < ActiveRecord::Base validates_uniqueness_of :external_key, :scope => [:provider_id, :portal_pool_id]
validates_presence_of :name + validates_uniqueness_of :name
validates_presence_of :storage - validates_numericality_of :storage + validates_numericality_of :storage, :greater_than => 0 validates_presence_of :memory - validates_numericality_of :memory + validates_numericality_of :memory, :greater_than => 0
validates_presence_of :architecture, :if => :provider
deltacloud-devel@lists.fedorahosted.org