From: Jan Provaznik <[email protected]>
---
src/app/models/template.rb | 6 +-
src/spec/controllers/templates_controller_spec.rb | 46 +++++++++---------
src/spec/factories/image.rb | 10 +---
src/spec/factories/instance.rb | 2 +-
src/spec/factories/template.rb | 21 ++++++++
src/spec/models/image_spec.rb | 52 +++-----------------
src/spec/models/instance_spec.rb | 6 +-
src/spec/models/template_spec.rb | 19 ++++++++
8 files changed, 81 insertions(+), 81 deletions(-)
create mode 100644 src/spec/factories/template.rb
create mode 100644 src/spec/models/template_spec.rb
diff --git a/src/app/models/template.rb b/src/app/models/template.rb
index 6469b04..3336081 100644
--- a/src/app/models/template.rb
+++ b/src/app/models/template.rb
@@ -3,13 +3,13 @@ require 'typhoeus'
class Template < ActiveRecord::Base
has_many :images, :dependent => :destroy
- before_validation :update_attrs
+ before_save :update_attrs
WAREHOUSE_CONFIG = YAML.load_file("#{RAILS_ROOT}/config/image_warehouse.yml")
- validates_presence_of :uuid
+ #validates_presence_of :uuid
#validates_presence_of :name
- validates_uniqueness_of :uuid
+ #validates_uniqueness_of :uuid
def update_xml_attributes!(opts = {})
doc = xml
diff --git a/src/spec/controllers/templates_controller_spec.rb
b/src/spec/controllers/templates_controller_spec.rb
index af4fb2c..ba27ecc 100644
--- a/src/spec/controllers/templates_controller_spec.rb
+++ b/src/spec/controllers/templates_controller_spec.rb
@@ -10,23 +10,23 @@ describe TemplatesController do
activate_authlogic
end
- it "should allow a user with image_modify permission to create new
image_descriptor" do
+ it "should allow a user with image_modify permission to create new template"
do
UserSession.create(@admin)
lambda do
post :new, :xml => { :name => 'fooimg', :platform => 'fedora' }, :next
=> true
- end.should change(ImageDescriptor, :count).by(1)
- id = ImageDescriptor.find(:first, :order => 'created_at DESC').id
+ end.should change(Template, :count).by(1)
+ id = Template.find(:first, :order => 'created_at DESC').id
response.should redirect_to("http://test.host/templates/services/#{id}")
end
it "should allow a user with image_modify permission to add service" do
UserSession.create(@admin)
- img = ImageDescriptor.new(:xml => '')
+ tpl = Template.new(:xml => '')
lambda do
- img.save!
- end.should change(ImageDescriptor, :count).by(1)
- post :services, :xml => { :xml => {:services => ['jboss']} }, :next =>
true, :id => img.id
- response.should
redirect_to("http://test.host/templates/software/#{img.id}")
+ tpl.save!
+ end.should change(Template, :count).by(1)
+ post :services, :xml => { :xml => {:services => ['jboss']} }, :next =>
true, :id => tpl.id
+ response.should
redirect_to("http://test.host/templates/software/#{tpl.id}")
end
# FIXME: these two tests depends on jboss repository which defines 'JBoss
Core
@@ -35,32 +35,32 @@ describe TemplatesController do
#
#it "should allow a user with image_modify permission to add and remove a
group" do
# UserSession.create(@admin)
- # img = ImageDescriptor.new(:xml => '')
+ # tpl = Template.new(:xml => '')
# lambda do
- # img.save!
- # end.should change(ImageDescriptor, :count).by(1)
- # post :select_group, :id => img.id, :group => 'JBoss Core Packages'
- # response.should
redirect_to("http://test.host/templates/software/#{img.id}")
- # post :remove_group, :id => img.id, :group => 'JBoss Core Packages'
- # response.should
redirect_to("http://test.host/templates/software/#{img.id}")
+ # tpl.save!
+ # end.should change(Template, :count).by(1)
+ # post :select_group, :id => tpl.id, :group => 'JBoss Core Packages'
+ # response.should
redirect_to("http://test.host/templates/software/#{tpl.id}")
+ # post :remove_group, :id => tpl.id, :group => 'JBoss Core Packages'
+ # response.should
redirect_to("http://test.host/templates/software/#{tpl.id}")
#end
#it "should allow a user with image_modify permission to add a package" do
# UserSession.create(@admin)
- # img = ImageDescriptor.new(:xml => '')
+ # tpl = Template.new(:xml => '')
# lambda do
- # img.save!
- # post :select_package, :id => img.id, :package => 'jboss-rails', :group
=> 'JBoss Core Packages'
- # end.should change(ImageDescriptor, :count).by(1)
- # response.should
redirect_to("http://test.host/templates/software/#{img.id}")
+ # tpl.save!
+ # post :select_package, :id => tpl.id, :package => 'jboss-rails', :group
=> 'JBoss Core Packages'
+ # end.should change(Template, :count).by(1)
+ # response.should
redirect_to("http://test.host/templates/software/#{tpl.id}")
#end
it "should allow a user with image_modify permission to build image
descriptor" do
UserSession.create(@admin)
- img = ImageDescriptor.new
+ tpl = Factory :template
lambda do
- post :summary, :id => img.id, :targets => ['rhevm'], :build => true
- end.should change(ImageDescriptorTarget, :count).by(1)
+ post :summary, :id => tpl.id, :targets => ['ec2'], :build => true
+ end.should change(Image, :count).by(1)
end
it "should deny access to new template ui without image modify permission" do
diff --git a/src/spec/factories/image.rb b/src/spec/factories/image.rb
index cc0bc17..293ac22 100644
--- a/src/spec/factories/image.rb
+++ b/src/spec/factories/image.rb
@@ -3,11 +3,7 @@
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
-
-Factory.define :front_end_image, :parent => :image do |i|
- i.provider nil
+ i.status 'queued'
+ i.target 'ec2'
+ i.association(:template)
end
diff --git a/src/spec/factories/instance.rb b/src/spec/factories/instance.rb
index 7533c64..3dc37e9 100644
--- a/src/spec/factories/instance.rb
+++ b/src/spec/factories/instance.rb
@@ -3,7 +3,7 @@ Factory.define :instance do |i|
i.sequence(:external_key) { |n| "key#{n}" }
i.association :hardware_profile, :factory => :mock_hwp1
i.association :cloud_account, :factory => :mock_cloud_account
- i.association :image, :factory => :image
+ i.association :template, :factory => :template
i.association :pool, :factory => :pool
i.state "running"
end
diff --git a/src/spec/factories/template.rb b/src/spec/factories/template.rb
new file mode 100644
index 0000000..4774148
--- /dev/null
+++ b/src/spec/factories/template.rb
@@ -0,0 +1,21 @@
+Factory.define :template do |i|
+ i.sequence(:name) { |n| "template#{n}" }
+ i.xml <<EOF
+<image>
+ <name>tpl</name>
+ <repos>
+ <repo>https://localhost/pulp/repos/jboss2</repo>
+ </repos>
+ <os>fedora</os>
+ <description/>
+ <services/>
+ <groups>
+ <group>JBoss Core Packages</group>
+ </groups>
+ <packages>
+ <package><name>jboss-as5</name><group>JBoss Core Packages</group></package>
+ <package><name>jboss-jgroups</name><group>JBoss Core
Packages</group></package>
+ </packages>
+</image>
+EOF
+end
diff --git a/src/spec/models/image_spec.rb b/src/spec/models/image_spec.rb
index a0fd8ca..030e792 100644
--- a/src/spec/models/image_spec.rb
+++ b/src/spec/models/image_spec.rb
@@ -1,23 +1,6 @@
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
@@ -38,36 +21,17 @@ describe Image do
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 provider images only if it has a provider" do
- i = Factory.create(:image, :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
+ it "should have automatically generated uuid after save" do
+ i = Factory.build(:image)
+ i.save
+ i.uuid.should_not be_nil
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")
+ it "should have template_id" do
+ i = Factory.build(:image, :template_id => nil)
+ i.should_not be_valid
- i.provider_images.clear
+ i.template_id = 1
i.should be_valid
end
-
end
diff --git a/src/spec/models/instance_spec.rb b/src/spec/models/instance_spec.rb
index 16e8eb9..49bf625 100644
--- a/src/spec/models/instance_spec.rb
+++ b/src/spec/models/instance_spec.rb
@@ -24,11 +24,11 @@ describe Instance do
@instance.should be_valid
end
- it "should require image to be set" do
- @instance.image_id = nil
+ it "should require template to be set" do
+ @instance.template_id = nil
@instance.should_not be_valid
- @instance.image_id = 1
+ @instance.template_id = 1
@instance.should be_valid
end
diff --git a/src/spec/models/template_spec.rb b/src/spec/models/template_spec.rb
new file mode 100644
index 0000000..ef30fc1
--- /dev/null
+++ b/src/spec/models/template_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+
+describe Template do
+ it "should have automatically generated uuid after validation" do
+ t = Factory.build(:template)
+ t.uuid = nil
+ t.save
+ t.uuid.should_not be_nil
+ end
+
+ it "should return list of providers who provides images built from this
template" do
+ tpl = Factory.build(:template)
+ img = Factory.build(:image, :template_id => tpl)
+ provider = Factory.build(:mock_provider)
+ rimg = ReplicatedImage.new(:provider_id => provider, :image_id => img)
+ rimg.save
+ tpl.providers.size.should eql(1)
+ end
+end
--
1.7.2.2
_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel