From: Jozef Zigmund <jzigmund(a)redhat.com>
---
src/features/provider.feature | 2 +-
src/features/step_definitions/template_steps.rb | 2 +-
src/features/template.feature | 6 ++--
src/spec/controllers/builds_controller_spec.rb | 4 +-
src/spec/factories/image.rb | 2 +-
src/spec/factories/provider.rb | 8 ++--
src/spec/factories/provider_type.rb | 10 ++++++
src/spec/models/image_spec.rb | 4 +-
src/spec/models/provider_spec.rb | 6 +--
src/test/fixtures/providers.yml | 20 -------------
src/test/unit/provider_test.rb | 35 -----------------------
11 files changed, 26 insertions(+), 73 deletions(-)
create mode 100644 src/spec/factories/provider_type.rb
delete mode 100644 src/test/fixtures/providers.yml
delete mode 100644 src/test/unit/provider_test.rb
diff --git a/src/features/provider.feature b/src/features/provider.feature
index 7566e61..4b6c50c 100644
--- a/src/features/provider.feature
+++ b/src/features/provider.feature
@@ -34,7 +34,7 @@ Feature: Manage Providers
Then I should be on the new admin provider page
When I fill in "provider[name]" with "testprovider"
And I fill in "provider[url]" with "http://localhost:3001/api"
- And I select "Amazon EC2" from "Provider type"
+ And I select "Amazon EC2" from "provider_provider_type_id"
And I press "Save"
Then I should be on the admin providers page
And I should see "Provider added"
diff --git a/src/features/step_definitions/template_steps.rb
b/src/features/step_definitions/template_steps.rb
index 921e47f..3491eb4 100644
--- a/src/features/step_definitions/template_steps.rb
+++ b/src/features/step_definitions/template_steps.rb
@@ -98,7 +98,7 @@ Given /^there is Amazon AWS provider account$/ do
end
Given /^there is Amazon AWS build for this template$/ do
- Image.build(@template, Provider::AWS)
+ Image.build(@template, ProviderType.find_by_codename("ec2"))
end
Given /^there is an imported template$/ do
diff --git a/src/features/template.feature b/src/features/template.feature
index e0e58d4..336b194 100644
--- a/src/features/template.feature
+++ b/src/features/template.feature
@@ -113,7 +113,7 @@ Feature: Manage Templates
And I follow "Build"
Then I should be on the new image factory build page
And I should see "Build Request"
- When I check "Ec2"
+ When I check "Amazon EC2"
And I press "Submit to Build"
Then I should be on the image factory template page
And I should see "mock1"
@@ -128,11 +128,11 @@ Feature: Manage Templates
And I follow "Build"
Then I should be on the new image factory build page
And I should see "Build Request"
- When I check "Ec2"
+ When I check "Amazon EC2"
And I press "Submit to Build"
Then I should be on the image factory template page
And I should see "mock1"
- And I should see "An attempted build of this template for the target '1'
already exists"
+ And I should see "An attempted build of this template for the target 'Amazon
EC2' already exists"
Scenario: Build imported template
Given there is an imported template
diff --git a/src/spec/controllers/builds_controller_spec.rb
b/src/spec/controllers/builds_controller_spec.rb
index 79eaa17..b0f1885 100644
--- a/src/spec/controllers/builds_controller_spec.rb
+++ b/src/spec/controllers/builds_controller_spec.rb
@@ -24,13 +24,13 @@ describe ImageFactory::BuildsController do
it "should create a new Image" do
lambda do
- post :create, :template_id => @template.id, :targets => ["0"]
+ post :create, :template_id => @template.id, :targets =>
ProviderType.find_by_codename("mock").id
end.should change(Image, :count).by(1)
end
it "should create a new ProviderImage" do
lambda do
- post :create, :template_id => @template.id, :targets => ["0"]
+ post :create, :template_id => @template.id, :targets =>
ProviderType.find_by_codename("mock").id
end.should change(ProviderImage, :count).by(1)
end
end
diff --git a/src/spec/factories/image.rb b/src/spec/factories/image.rb
index 293ac22..c8b34e3 100644
--- a/src/spec/factories/image.rb
+++ b/src/spec/factories/image.rb
@@ -4,6 +4,6 @@
Factory.define :image do |i|
i.sequence(:name) { |n| "image#{n}" }
i.status 'queued'
- i.target 'ec2'
+ i.provider_type_id { ProviderType.find_by_codename("ec2").id }
i.association(:template)
end
diff --git a/src/spec/factories/provider.rb b/src/spec/factories/provider.rb
index f6288dc..03f8773 100644
--- a/src/spec/factories/provider.rb
+++ b/src/spec/factories/provider.rb
@@ -1,11 +1,11 @@
Factory.define :provider do |p|
p.sequence(:name) { |n| "provider#{n}" }
- p.provider_type '0'
+ p.provider_type { ProviderType.find_by_codename("mock") }
p.url { |p| "http://www." + p.name + ".com/api" }
end
Factory.define :mock_provider, :parent => :provider do |p|
- p.provider_type '0'
+ p.provider_type { ProviderType.find_by_codename("mock") }
p.url 'http://localhost:3001/api'
p.hardware_profiles { |hp| [hp.association(:mock_hwp1), hp.association(:mock_hwp2)] }
p.after_create { |p| p.realms << Factory(:realm1, :provider => p) <<
Factory(:realm2, :provider => p) }
@@ -13,14 +13,14 @@ end
Factory.define :mock_provider2, :parent => :provider do |p|
p.name 'mock2'
- p.provider_type '0'
+ p.provider_type { ProviderType.find_by_codename("mock") }
p.url 'http://localhost:3001/api'
p.after_create { |p| p.realms << Factory(:realm3, :provider => p) }
end
Factory.define :ec2_provider, :parent => :provider do |p|
p.name 'amazon-ec2'
- p.provider_type '1'
+ p.provider_type { ProviderType.find_by_codename("ec2") }
p.url 'http://localhost:3001/api'
p.hardware_profiles { |hp| [hp.association(:ec2_hwp1)] }
p.after_create { |p| p.realms << Factory(:realm4, :provider => p) }
diff --git a/src/spec/factories/provider_type.rb b/src/spec/factories/provider_type.rb
new file mode 100644
index 0000000..0fed927
--- /dev/null
+++ b/src/spec/factories/provider_type.rb
@@ -0,0 +1,10 @@
+Factory.define :provider_type do |p|
+end
+
+Factory.define :mock_provider_type, :parent => :provider_type do |p|
+ p.name 'Mock'
+end
+
+Factory.define :ec2_provider_type, :parent => :provider_type do |p|
+ p.name 'Amazon EC2'
+end
diff --git a/src/spec/models/image_spec.rb b/src/spec/models/image_spec.rb
index 63b11dc..a5c3534 100644
--- a/src/spec/models/image_spec.rb
+++ b/src/spec/models/image_spec.rb
@@ -38,7 +38,7 @@ describe Image do
it "should not build image if image already exists for specified target" do
old = Factory.build(:image)
old.save!
- lambda {Image.build(old.template, old.target)}.should raise_error(ImageExistsError)
+ lambda {Image.build(old.template, old.provider_type)}.should
raise_error(ImageExistsError)
end
it "should build image if there is provider and cloud account for specified
target" do
@@ -47,7 +47,7 @@ describe Image do
acc.save!
tpl = Factory.build(:template)
tpl.save!
- img = Image.build(tpl, '0')
+ img = Image.build(tpl, ProviderType.find_by_codename("mock"))
Image.find(img).should == img
ProviderImage.find_by_image_id(img.id).should_not be_nil
end
diff --git a/src/spec/models/provider_spec.rb b/src/spec/models/provider_spec.rb
index a9cde6b..0771c9a 100644
--- a/src/spec/models/provider_spec.rb
+++ b/src/spec/models/provider_spec.rb
@@ -28,10 +28,8 @@ describe Provider do
end
it "should require a valid provider_type" do
- [nil, ""].each do |invalid_value|
- @provider.provider_type = invalid_value
+ @provider.provider_type = nil
@provider.should_not be_valid
- end
end
it "should require a valid url" do
@@ -67,7 +65,7 @@ describe Provider do
it "should set valid cloud type" do
@client.driver_name = @provider.provider_type
@provider.provider_type = nil
- @provider.provider_type = 0
+ @provider.provider_type = ProviderType.find_by_codename "mock"
@provider.should be_valid
end
diff --git a/src/test/fixtures/providers.yml b/src/test/fixtures/providers.yml
deleted file mode 100644
index 85d3c9d..0000000
--- a/src/test/fixtures/providers.yml
+++ /dev/null
@@ -1,20 +0,0 @@
-# == Schema Information
-# Schema version: 20110207110131
-#
-# Table name: providers
-#
-# id :integer not null, primary key
-# name :string(255) not null
-# url :string(255) not null
-# lock_version :integer default(0)
-# created_at :datetime
-# updated_at :datetime
-# provider_type :integer
-#
-
-# Read about fixtures at
http://ar.rubyonrails.org/classes/Fixtures.html
-
-mock_provider:
- name: mock
- provider_type: Mock
- url:
http://localhost:3001/api
diff --git a/src/test/unit/provider_test.rb b/src/test/unit/provider_test.rb
deleted file mode 100644
index 5029a3d..0000000
--- a/src/test/unit/provider_test.rb
+++ /dev/null
@@ -1,35 +0,0 @@
-require File.dirname(__FILE__) + '/../test_helper'
-
-class ProviderTest < ActiveSupport::TestCase
- fixtures :providers
-
- def setup
- @provider = Provider.new(:name => "my_ec2",
- :provider_type => "EC2")
- end
- # The following three tests assume you have the deltacloud-framework
- # running and configured on localhost:3000
-
- test "is valid with good url" do
- @provider.url = "http://localhost:3000/api"
- flunk "That URL should have worked. Is framework running?" if
@provider.invalid?
- end
-
- test "requires url" do
- flunk "Providers require a url" if @provider.valid?
- end
-
- test "fails with invalid provider url" do
- @provider.url = "http://conductor.awesome/api"
- flunk "Invalid url passed validation" unless @provider.invalid?
- end
-
- test "should return nil if no connection" do
- assert_equal(nil, @provider.connect)
- end
-
- test "should return DeltaCloud if successful connection" do
- @provider.url = "http://localhost:3000/api"
- assert_instance_of(DeltaCloud, @provider.connect)
- end
-end
--
1.7.4