Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change FactoryGirl to FactoryBot #505

Merged
merged 1 commit into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions spec/factories/cloud_object_store.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :aws_object, :class => ManageIQ::Providers::Amazon::StorageManager::S3::CloudObjectStoreObject.name do |object|
object.sequence(:key) { |n| "object-key-#{n}" }
end
Expand All @@ -9,7 +9,7 @@
bucket.sequence(:ems_ref) { |n| "stubbed-ems-ref-#{n}" }

after(:create) do |bucket|
bucket.cloud_object_store_objects = FactoryGirl.create_list(
bucket.cloud_object_store_objects = FactoryBot.create_list(
:aws_object, 5, :ext_management_system => bucket.ext_management_system
)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/cloud_volume.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :cloud_volume_amazon, :parent => :cloud_volume,
:class => "ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolume"
factory :cloud_volume_amazon_standard,
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/cloud_volume_snapshot.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :cloud_volume_snapshot_amazon, :parent => :cloud_volume_snapshot,
:class => "ManageIQ::Providers::Amazon::StorageManager::Ebs::CloudVolumeSnapshot"
end
4 changes: 2 additions & 2 deletions spec/factories/ext_management_system.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :ems_amazon_ebs,
:aliases => ["manageiq/providers/amazon/storage_manager/ebs"],
:class => "ManageIQ::Providers::Amazon::StorageManager::Ebs",
Expand All @@ -20,7 +20,7 @@
:password => client_key
}

ems.authentications << FactoryGirl.create(:authentication, cred)
ems.authentications << FactoryBot.create(:authentication, cred)
end
end
end
2 changes: 1 addition & 1 deletion spec/factories/floating_ip.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :floating_ip_amazon, :parent => :floating_ip,
:class => "ManageIQ::Providers::Amazon::NetworkManager::FloatingIp"
end
4 changes: 2 additions & 2 deletions spec/factories/orchestration_template.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FactoryGirl.define do
FactoryBot.define do
factory :orchestration_template_amazon,
:parent => :orchestration_template,
:class => "ManageIQ::Providers::Amazon::CloudManager::OrchestrationTemplate" do
sequence(:content) { |n| "{\"AWSTemplateFormatVersion\" : \"version(#{seq_padded_for_sorting(n)})\"}" }
end

factory :orchestration_template_amazon_with_stacks, :parent => :orchestration_template_amazon do
stacks { [FactoryGirl.create(:orchestration_stack)] }
stacks { [FactoryBot.create(:orchestration_stack)] }
end

factory :orchestration_template_amazon_in_json, :parent => :orchestration_template_amazon do
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/service_parameters_set.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FactoryGirl.define do
FactoryBot.define do
factory :service_parameters_set_amazon, :class => "ManageIQ::Providers::Amazon::CloudManager::ServiceParametersSet"
end
8 changes: 4 additions & 4 deletions spec/models/authenticator/amazon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

subject { Authenticator::Amazon.new(config) }

let(:local_user) { FactoryGirl.create(:user, :userid => username) }
let(:local_user) { FactoryBot.create(:user, :userid => username) }
let(:username) { 'some_user' }
let(:config) do
{
Expand Down Expand Up @@ -72,7 +72,7 @@ def aws_allow_list_groups!(resource)
# Authenticator#uses_stored_password? whether it's allowed to do anything.
allow(User).to receive(:authenticator).and_return(subject)

miq_group = FactoryGirl.create(:miq_group, :description => miq_group_name)
miq_group = FactoryBot.create(:miq_group, :description => miq_group_name)
allow(MiqLdap).to receive(:using_ldap?) { false }

allow_any_instance_of(described_class).to receive(:aws_connect) do |_instance, access_key_id, _secret_access_key, service|
Expand Down Expand Up @@ -172,7 +172,7 @@ def authenticate
end

context "with correct password" do
let!(:local_user) { FactoryGirl.create(:user, :userid => username) }
let!(:local_user) { FactoryBot.create(:user, :userid => username) }

context "using local authorization" do
it "succeeds" do
Expand Down Expand Up @@ -473,7 +473,7 @@ def authenticate
it 'stores passwords encrypted' do
password = "pa$$word"
encrypted = MiqPassword.encrypt(password)
miq_server = FactoryGirl.create(:miq_server)
miq_server = FactoryBot.create(:miq_server)

Vmdb::Settings.save!(miq_server,
:authentication => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe "OrchestrationTemplateServiceDialog for Amazon" do
let(:dialog_service) { Dialog::OrchestrationTemplateServiceDialog.new }
let(:template_amazon) { FactoryGirl.create(:orchestration_template_amazon_in_json) }
let(:template_amazon) { FactoryBot.create(:orchestration_template_amazon_in_json) }

describe "#create_dialog" do
it "creates a dialog from CloudFormation template with stack basic info and parameters" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1438,11 +1438,11 @@ def assert_specific_labels_on_vm
end

def create_tag_mapping
@all_tag_mapping = FactoryGirl.create(:tag_mapping_with_category,
@all_tag_mapping = FactoryBot.create(:tag_mapping_with_category,
:label_name => "owner")
@all_tag_mapping_category = @all_tag_mapping.tag.classification

@image_tag_mapping = FactoryGirl.create(:tag_mapping_with_category,
@image_tag_mapping = FactoryBot.create(:tag_mapping_with_category,
:label_name => "Name", :labeled_resource_type => "Image")
@image_tag_mapping_category = @image_tag_mapping.tag.classification
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe ManageIQ::Providers::Amazon::CloudManager::EventCatcher::Stream do
subject do
ems = FactoryGirl.create(:ems_amazon_with_authentication)
ems = FactoryBot.create(:ems_amazon_with_authentication)
described_class.new(ems)
end
let(:queue_url) { "https://sqs.eu-central-1.amazonaws.com/995412904407/the_queue_name" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
describe ManageIQ::Providers::Amazon::CloudManager::EventTargetParser do
before :each do
_guid, _server, zone = EvmSpecHelper.create_guid_miq_server_zone
@ems = FactoryGirl.create(:ems_amazon, :zone => zone)
@ems = FactoryBot.create(:ems_amazon, :zone => zone)

allow_any_instance_of(EmsEvent).to receive(:handle_event)
allow(EmsEvent).to receive(:create_completed_event)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
describe ManageIQ::Providers::Amazon::CloudManager::MetricsCapture do
let(:vm_name) { 'amazon-perf-vm' }

let(:ems) { FactoryGirl.create(:ems_amazon_with_authentication) }
let(:vm) { FactoryGirl.build(:vm_amazon, :ems_ref => vm_name, :ext_management_system => ems) }
let(:ems) { FactoryBot.create(:ems_amazon_with_authentication) }
let(:vm) { FactoryBot.build(:vm_amazon, :ems_ref => vm_name, :ext_management_system => ems) }

context "#perf_collect_metrics" do
it "raises an error when no EMS is defined" do
vm = FactoryGirl.build(:vm_amazon, :ext_management_system => nil)
vm = FactoryBot.build(:vm_amazon, :ext_management_system => nil)
expect { vm.perf_collect_metrics('interval_name') }.to raise_error(RuntimeError, /No EMS defined/)
end

it "raises an error with no EMS credentials defined" do
vm = FactoryGirl.build(:vm_amazon, :ext_management_system => FactoryGirl.create(:ems_amazon))
vm = FactoryBot.build(:vm_amazon, :ext_management_system => FactoryBot.create(:ems_amazon))
expect { vm.perf_collect_metrics('interval_name') }.to raise_error(RuntimeError, /no credentials defined/)
end

Expand Down Expand Up @@ -59,7 +59,7 @@

context 'counters present' do
let(:vm_name) { 'i-091369dd8a8d470ab' }
let(:ems) { FactoryGirl.create(:ems_amazon_with_vcr_authentication, :provider_region => 'eu-central-1') }
let(:ems) { FactoryBot.create(:ems_amazon_with_vcr_authentication, :provider_region => 'eu-central-1') }

subject do
with_vcr_data { vm.perf_collect_metrics('realtime').last.first.last.first.last }
Expand All @@ -69,7 +69,7 @@
it { is_expected.to have_key('mem_swapped_absolute_average') }

context 'and stored in the database' do
let(:vm) { FactoryGirl.create(:vm_amazon, :ext_management_system => ems, :name => vm_name) }
let(:vm) { FactoryBot.create(:vm_amazon, :ext_management_system => ems, :name => vm_name) }

subject do
with_vcr_data { vm.perf_capture('realtime') }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require_relative "../aws_helper"

describe ManageIQ::Providers::Amazon::CloudManager::OrchestrationStack do
let(:ems) { FactoryGirl.create(:ems_amazon_with_authentication) }
let(:template) { FactoryGirl.create(:orchestration_template) }
let(:ems) { FactoryBot.create(:ems_amazon_with_authentication) }
let(:template) { FactoryBot.create(:orchestration_template) }
let(:orchestration_stack) do
FactoryGirl.create(:orchestration_stack_amazon, :ext_management_system => ems, :name => 'test')
FactoryBot.create(:orchestration_stack_amazon, :ext_management_system => ems, :name => 'test')
end
let(:describe_stacks_repsonse) do
{
Expand Down Expand Up @@ -169,22 +169,22 @@
end

context '#tenant_identity' do
let(:admin) { FactoryGirl.create(:user_with_group, :userid => "admin") }
let(:tenant) { FactoryGirl.create(:tenant) }
let(:admin) { FactoryBot.create(:user_with_group, :userid => "admin") }
let(:tenant) { FactoryBot.create(:tenant) }
before { admin }

subject { @stack.tenant_identity }

it "has tenant from provider" do
@stack = FactoryGirl.create(:orchestration_stack_amazon, :ems_id => ems.id)
@stack = FactoryBot.create(:orchestration_stack_amazon, :ems_id => ems.id)

expect(subject).to eq(admin)
expect(subject.current_group).to eq(ems.tenant.default_miq_group)
expect(subject.current_tenant).to eq(ems.tenant)
end

it "without a provider, has tenant from root tenant" do
@stack = FactoryGirl.create(:orchestration_stack_amazon)
@stack = FactoryBot.create(:orchestration_stack_amazon)

expect(subject).to eq(admin)
expect(subject.current_group).to eq(Tenant.root_tenant.default_miq_group)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
end
end

let(:json_template) { FactoryGirl.create(:orchestration_template_amazon_in_json) }
let(:yaml_template) { FactoryGirl.create(:orchestration_template_amazon_in_yaml) }
let(:json_template) { FactoryBot.create(:orchestration_template_amazon_in_json) }
let(:yaml_template) { FactoryBot.create(:orchestration_template_amazon_in_yaml) }

shared_examples_for "a template with content" do
it "parses parameters from a template" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe ManageIQ::Providers::Amazon::CloudManager::Provision::Configuration do
it "#userdata_payload is Base64 encoded" do
template = FactoryGirl.build(:customization_template, :script => "#cloud-init")
template = FactoryBot.build(:customization_template, :script => "#cloud-init")
provision = ManageIQ::Providers::Amazon::CloudManager::Provision.new
allow(provision).to receive(:customization_template).and_return(template)
allow(provision).to receive(:post_install_callback_url).and_return("")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require_relative '../aws_helper'

describe ManageIQ::Providers::Amazon::CloudManager::Provision do
let(:provider) { FactoryGirl.create(:ems_amazon_with_authentication) }
let(:template) { FactoryGirl.create(:template_amazon, :ext_management_system => provider, :ems_ref => 'id-123') }
let(:provider) { FactoryBot.create(:ems_amazon_with_authentication) }
let(:template) { FactoryBot.create(:template_amazon, :ext_management_system => provider, :ems_ref => 'id-123') }

before(:each) do
subject.source = template
Expand All @@ -11,20 +11,20 @@
context "Cloning" do
describe "#find_destination_in_vmdb" do
it "finds VM in same sub-class" do
vm = FactoryGirl.create(:vm_amazon, :ext_management_system => provider, :ems_ref => "vm_1")
vm = FactoryBot.create(:vm_amazon, :ext_management_system => provider, :ems_ref => "vm_1")
expect(subject.find_destination_in_vmdb("vm_1")).to eq(vm)
end

it "does not find VM in different sub-class" do
FactoryGirl.create(:vm_openstack, :ext_management_system => provider, :ems_ref => "vm_1")
FactoryBot.create(:vm_openstack, :ext_management_system => provider, :ems_ref => "vm_1")
expect(subject.find_destination_in_vmdb("vm_1")).to be_nil
end
end

describe "#prepare_for_clone_task" do
before do
flavor = FactoryGirl.create(:flavor_amazon)
availability_zone = FactoryGirl.create(:availability_zone_amazon)
flavor = FactoryBot.create(:flavor_amazon)
availability_zone = FactoryBot.create(:availability_zone_amazon)
allow(subject).to receive(:source).and_return(template)
allow(subject).to receive(:instance_type).and_return(flavor)
allow(subject).to receive(:dest_availability_zone).and_return(availability_zone)
Expand All @@ -43,21 +43,21 @@
end

it "with one security group" do
security_group = FactoryGirl.create(:security_group_amazon, :name => "group_1")
security_group = FactoryBot.create(:security_group_amazon, :name => "group_1")
subject.options[:security_groups] = [security_group.id]
expect(subject.prepare_for_clone_task[:security_group_ids]).to eq([security_group.ems_ref])
end

it "with two security group" do
security_group_1 = FactoryGirl.create(:security_group_amazon, :name => "group_1")
security_group_2 = FactoryGirl.create(:security_group_amazon, :name => "group_2")
security_group_1 = FactoryBot.create(:security_group_amazon, :name => "group_1")
security_group_2 = FactoryBot.create(:security_group_amazon, :name => "group_2")
subject.options[:security_groups] = [security_group_1.id, security_group_2.id]
expect(subject.prepare_for_clone_task[:security_group_ids])
.to match_array([security_group_1.ems_ref, security_group_2.ems_ref])
end

it "with a missing security group" do
security_group = FactoryGirl.create(:security_group_amazon, :name => "group_1")
security_group = FactoryBot.create(:security_group_amazon, :name => "group_1")
bad_security_group_id = security_group.id + 1
subject.options[:security_groups] = [security_group.id, bad_security_group_id]
expect(subject.prepare_for_clone_task[:security_group_ids]).to eq([security_group.ems_ref])
Expand All @@ -70,7 +70,7 @@
end

it "with a subnet" do
cloud_subnet = FactoryGirl.create(:cloud_subnet)
cloud_subnet = FactoryBot.create(:cloud_subnet)
subject.options[:cloud_subnet] = [cloud_subnet.id, cloud_subnet.name]
expect(subject.prepare_for_clone_task[:subnet_id]).to eq(cloud_subnet.ems_ref)
end
Expand All @@ -79,9 +79,9 @@

describe "#workflow_class" do
it "returns the correct class" do
user = FactoryGirl.create(:user)
user = FactoryBot.create(:user)
options = {:src_vm_id => [template.id, template.name]}
vm_prov = FactoryGirl.create(:miq_provision_amazon,
vm_prov = FactoryBot.create(:miq_provision_amazon,
:userid => user.userid,
:source => template,
:request_type => 'template',
Expand All @@ -98,7 +98,7 @@

describe "#start_clone" do
it "starts an instance" do
flavor = FactoryGirl.create(:flavor_amazon)
flavor = FactoryBot.create(:flavor_amazon)
allow(subject).to receive(:source).and_return(template)
allow(subject).to receive(:instance_type).and_return(flavor)
allow(subject).to receive(:dest_name).and_return(template.ems_ref)
Expand Down
Loading