The previous versions of these patches caused errors in the will_paginate plugin under Rails 2.3.4.
The plugin requires ActiveRecord classes to be saved in the database for array operations. Which wasn't done for these specs.
This is the fix. Please ignore previous patches for Hardware Profile and Image specs. Apply on the current HEAD of 'next'.
From: Tomas Sedovic tsedovic@redhat.com
Some of the tests are failing. --- src/spec/models/hardware_profile_spec.rb | 123 ++++++++++++++++++++++++++++++ 1 files changed, 123 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..78fc0a2 --- /dev/null +++ b/src/spec/models/hardware_profile_spec.rb @@ -0,0 +1,123 @@ +require 'spec_helper' + +describe HardwareProfile do + before(:each) do + @hp = Factory.create(:mock_hwp1) + end + + it "should create a new hardware profile" do + @hp.should be_valid + end + + it "should not validate for missing name" do + [nil, ""].each do |value| + @hp.name = value + @hp.should_not be_valid + end + + @hp.name = 'valid name' + @hp.should be_valid + end + + it "should require unique names" do + hp2 = Factory.create(:mock_hwp2) + @hp.should be_valid + hp2.should be_valid + + hp2.name = @hp.name + hp2.should_not be_valid + end + + it "should require valid amount of memory" do + [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 + [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.architecture = nil + @hp.should be_valid + end + + it "should require architecture when it's with provider" do + @hp.provider = Provider.new + + @hp.should be_valid + @hp.architecture = nil + @hp.should_not be_valid + end + + it "should reject Aggregator profiles for custom Instance profiles" do + @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.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.provider = Provider.new + @hp.pool = Pool.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(:pool) + @hp.errors.on(:pool).should eql("provider or pool must be blank") + + @hp.provider = nil + @hp.should be_valid + + @hp.provider = Provider.new + @hp.pool = nil + @hp.should be_valid + end + + it "should allow Provider profiles only for provider profiles" do + @hp.provider = nil + @hp.pool = Pool.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.provider = Provider.new + @hp.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 b65fc24..8330388 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, :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
tsedovic@redhat.com wrote:
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 b65fc24..8330388 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, :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
It works now with rails 2.3.4.
ACK to patches 1 and 2
Scott
From: Tomas Sedovic tsedovic@redhat.com
One test is failing. --- src/spec/factories/image.rb | 6 +++ src/spec/models/image_spec.rb | 98 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 104 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..5cefcc0 --- /dev/null +++ b/src/spec/factories/image.rb @@ -0,0 +1,6 @@ +Factory.define :image do |i| + i.sequence(:name) { |n| "image#{n}" } + i.sequence(:external_key) { |n| "key#{n}" } + i.architecture 'i686' + i.provider {|p| Provider.new } +end diff --git a/src/spec/models/image_spec.rb b/src/spec/models/image_spec.rb new file mode 100644 index 0000000..de68475 --- /dev/null +++ b/src/spec/models/image_spec.rb @@ -0,0 +1,98 @@ +require 'spec_helper' + +describe Image do + before(:each) do + @provider = Factory.build(:mock_provider) + @client = mock('DeltaCloud', :null_object => true) + @provider.stub!(:connect).and_return(@client) + end + + it "should have a unique external key" do + 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, :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.build(:image) + 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, :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, :provider => nil, :pool => nil) + i.should have(1).error_on(:provider) + i.should have(1).error_on(:pool) + i.errors.on(:provider).should eql( + "provider or pool must be specified") + i.errors.on(:pool).should eql( + "provider or pool must be specified") + + i.provider = @provider + i.should be_valid + + i.pool = Factory.build(:pool) + i.should have(1).error_on(:provider) + i.should have(1).error_on(:pool) + i.errors.on(:provider).should eql( + "provider or pool must be blank") + i.errors.on(: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.create(:image, :pool => Pool.new, + :provider => nil) + + 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.create(:image) + + 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
From: Tomas Sedovic tsedovic@redhat.com
--- src/app/models/image.rb | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/src/app/models/image.rb b/src/app/models/image.rb index 3936bd6..6670149 100644 --- a/src/app/models/image.rb +++ b/src/app/models/image.rb @@ -40,6 +40,7 @@ class Image < ActiveRecord::Base validates_uniqueness_of :external_key, :scope => [:provider_id, :pool_id]
validates_presence_of :name + validates_length_of :name, :maximum => 1024
validates_presence_of :architecture, :if => :provider
tsedovic@redhat.com wrote:
From: Tomas Sedovic tsedovic@redhat.com
src/app/models/image.rb | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/src/app/models/image.rb b/src/app/models/image.rb index 3936bd6..6670149 100644 --- a/src/app/models/image.rb +++ b/src/app/models/image.rb @@ -40,6 +40,7 @@ class Image < ActiveRecord::Base validates_uniqueness_of :external_key, :scope => [:provider_id, :pool_id]
validates_presence_of :name
validates_length_of :name, :maximum => 1024
validates_presence_of :architecture, :if => :provider
Ack to Patches 3 and 4
Scott
deltacloud-devel@lists.fedorahosted.org