From: Jan Provaznik <jprovazn(a)redhat.com>
---
src/app/models/provider_image.rb | 4 ++-
.../20110221125633_add_uuid_to_providerimage.rb | 9 +++++++
src/spec/models/provider_image_spec.rb | 24 ++++++++++++++++++++
3 files changed, 36 insertions(+), 1 deletions(-)
create mode 100644 src/db/migrate/20110221125633_add_uuid_to_providerimage.rb
create mode 100644 src/spec/models/provider_image_spec.rb
diff --git a/src/app/models/provider_image.rb b/src/app/models/provider_image.rb
index 861daea..0ac23c2 100644
--- a/src/app/models/provider_image.rb
+++ b/src/app/models/provider_image.rb
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 20110207110131
+# Schema version: 20110221125633
#
# Table name: provider_images
#
@@ -9,6 +9,7 @@
# provider_image_key :string(255)
# uploaded :boolean
# registered :boolean
+# uuid :string(255)
#
class ProviderImage < ActiveRecord::Base
@@ -17,4 +18,5 @@ class ProviderImage < ActiveRecord::Base
validates_presence_of :provider_id
validates_presence_of :image_id
+ validates_uniqueness_of :uuid, :allow_nil => true
end
diff --git a/src/db/migrate/20110221125633_add_uuid_to_providerimage.rb
b/src/db/migrate/20110221125633_add_uuid_to_providerimage.rb
new file mode 100644
index 0000000..6964437
--- /dev/null
+++ b/src/db/migrate/20110221125633_add_uuid_to_providerimage.rb
@@ -0,0 +1,9 @@
+class AddUuidToProviderimage < ActiveRecord::Migration
+ def self.up
+ add_column :provider_images, :uuid, :string
+ end
+
+ def self.down
+ remove_column :provider_images, :uuid
+ end
+end
diff --git a/src/spec/models/provider_image_spec.rb
b/src/spec/models/provider_image_spec.rb
new file mode 100644
index 0000000..419d976
--- /dev/null
+++ b/src/spec/models/provider_image_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe ProviderImage do
+ it "should have a provider_id" do
+ i = Factory.build(:mock_provider_image)
+ i.should be_valid
+ i.provider = nil
+ i.should_not be_valid
+ end
+
+ it "should have an image_id" do
+ i = Factory.build(:mock_provider_image)
+ i.should be_valid
+ i.image = nil
+ i.should_not be_valid
+ end
+
+ it "should have a unique uuid" do
+ i = Factory(:mock_provider_image, :uuid => '1')
+ i.should be_valid
+ i = Factory.build(:mock_provider_image, :uuid => '1')
+ i.should_not be_valid
+ end
+end
--
1.7.4