diff --git a/Gemfile b/Gemfile index 8aaa0b56ea8..907fa90e604 100644 --- a/Gemfile +++ b/Gemfile @@ -229,7 +229,7 @@ unless ENV["APPLIANCE"] gem "brakeman", "~>3.3", :require => false gem "capybara", "~>2.5.0", :require => false gem "coveralls", :require => false - gem "factory_girl", "~>4.5.0", :require => false + gem "factory_bot", "~>4.11.1", :require => false gem "timecop", "~>0.7.3", :require => false gem "vcr", "~>3.0.2", :require => false gem "webmock", "~>2.3.1", :require => false diff --git a/config/environments/test.rb b/config/environments/test.rb index 11f6005d399..a12b028bd04 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -62,7 +62,7 @@ end require "minitest" -require "factory_girl" +require "factory_bot" require "timecop" require "vcr" require "webmock/rspec" diff --git a/spec/factories/account.rb b/spec/factories/account.rb index 9bf1bd18346..c3ac2483bd9 100644 --- a/spec/factories/account.rb +++ b/spec/factories/account.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :account factory :account_user, :parent => :account do diff --git a/spec/factories/assigned_server_role.rb b/spec/factories/assigned_server_role.rb index e15a2f23902..f72caef4a28 100644 --- a/spec/factories/assigned_server_role.rb +++ b/spec/factories/assigned_server_role.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :assigned_server_role do active { true } priority { AssignedServerRole::HIGH_PRIORITY } @@ -6,6 +6,6 @@ factory :assigned_server_role_in_master_region, :parent => :assigned_server_role do # GOAL: master_supported? = true, regional_role? = true - server_role { FactoryGirl.create(:server_role, :role_scope => "region", :max_concurrent => 1) } + server_role { FactoryBot.create(:server_role, :role_scope => "region", :max_concurrent => 1) } end end diff --git a/spec/factories/authentication.rb b/spec/factories/authentication.rb index b7c762a0026..bf1ccb1d9f3 100644 --- a/spec/factories/authentication.rb +++ b/spec/factories/authentication.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :authentication do userid "testuser" password "secret" diff --git a/spec/factories/automate_workspace.rb b/spec/factories/automate_workspace.rb index 5d75e08bad7..48d010ce7d1 100644 --- a/spec/factories/automate_workspace.rb +++ b/spec/factories/automate_workspace.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :automate_workspace do user tenant diff --git a/spec/factories/availability_zone.rb b/spec/factories/availability_zone.rb index b627abbcdb1..987bf61db18 100644 --- a/spec/factories/availability_zone.rb +++ b/spec/factories/availability_zone.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :availability_zone do sequence(:name) { |n| "availability_zone_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/blacklisted_event.rb b/spec/factories/blacklisted_event.rb index 649bcbb15c1..7c0fdce249c 100644 --- a/spec/factories/blacklisted_event.rb +++ b/spec/factories/blacklisted_event.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :blacklisted_event do enabled true end diff --git a/spec/factories/categories.rb b/spec/factories/categories.rb index 11346c17698..f00c85a358b 100644 --- a/spec/factories/categories.rb +++ b/spec/factories/categories.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory(:category) do sequence(:name) { |n| "category_#{seq_padded_for_sorting(n)}" } sequence(:description) { |n| "category #{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/chargeable_field.rb b/spec/factories/chargeable_field.rb index 7f74a1db465..2f0d4ed7c8b 100644 --- a/spec/factories/chargeable_field.rb +++ b/spec/factories/chargeable_field.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :chargeable_field do metric 'unknown' group 'unknown' @@ -18,7 +18,7 @@ metric 'cpu_usagemhz_rate_average' group 'cpu' source 'used' - detail_measure { FactoryGirl.build(:chargeback_measure_hz) } + detail_measure { FactoryBot.build(:chargeback_measure_hz) } end factory :chargeable_field_cpu_allocated, :parent => :chargeable_field do @@ -33,7 +33,7 @@ metric 'derived_memory_available' group 'memory' source 'allocated' - detail_measure { FactoryGirl.build(:chargeback_measure_bytes) } + detail_measure { FactoryBot.build(:chargeback_measure_bytes) } end factory :chargeable_field_storage_allocated, :parent => :chargeable_field do @@ -41,7 +41,7 @@ metric 'derived_vm_allocated_disk_storage' group 'storage' source 'allocated' - detail_measure { FactoryGirl.build(:chargeback_measure_bytes) } + detail_measure { FactoryBot.build(:chargeback_measure_bytes) } end factory :chargeable_field_cpu_cores_used, :parent => :chargeable_field do @@ -63,7 +63,7 @@ metric 'derived_memory_used' group 'memory' source 'used' - detail_measure { FactoryGirl.build(:chargeback_measure_bytes) } + detail_measure { FactoryBot.build(:chargeback_measure_bytes) } end factory :chargeable_field_net_io_used, :parent => :chargeable_field do @@ -71,7 +71,7 @@ metric 'net_usage_rate_average' group 'net_io' source 'used' - detail_measure { FactoryGirl.build(:chargeback_measure_bps) } + detail_measure { FactoryBot.build(:chargeback_measure_bps) } end factory :chargeable_field_disk_io_used, :parent => :chargeable_field do @@ -79,7 +79,7 @@ metric 'disk_usage_rate_average' group 'disk_io' source 'used' - detail_measure { FactoryGirl.build(:chargeback_measure_bps) } + detail_measure { FactoryBot.build(:chargeback_measure_bps) } end factory :chargeable_field_storage_used, :parent => :chargeable_field do @@ -87,7 +87,7 @@ metric 'derived_vm_used_disk_storage' group 'storage' source 'used' - detail_measure { FactoryGirl.build(:chargeback_measure_bytes) } + detail_measure { FactoryBot.build(:chargeback_measure_bytes) } end factory :chargeable_field_metering_used, :parent => :chargeable_field do diff --git a/spec/factories/chargeback_rate.rb b/spec/factories/chargeback_rate.rb index 32808b4b296..e3fe573e770 100644 --- a/spec/factories/chargeback_rate.rb +++ b/spec/factories/chargeback_rate.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :chargeback_rate do guid { SecureRandom.uuid } sequence(:description) { |n| "Chargeback Rate ##{n}" } @@ -19,14 +19,14 @@ params_hash.merge!(chargeback_rate_params[:detail]) if chargeback_rate_params[:detail] params = [factory_name, :tiers, params_hash] - chargeback_rate.chargeback_rate_details << FactoryGirl.create(*params) + chargeback_rate.chargeback_rate_details << FactoryBot.create(*params) end end trait :with_details do chargeback_rate_details do - [FactoryGirl.create(:chargeback_rate_detail_memory_allocated, :tiers_with_three_intervals), - FactoryGirl.create(:chargeback_rate_detail_memory_used, :tiers)] + [FactoryBot.create(:chargeback_rate_detail_memory_allocated, :tiers_with_three_intervals), + FactoryBot.create(:chargeback_rate_detail_memory_used, :tiers)] end end @@ -43,7 +43,7 @@ chargeback_rate_detail_memory_used chargeback_rate_detail_net_io_used ).each do |factory_name| - chargeback_rate.chargeback_rate_details << FactoryGirl.create(factory_name, + chargeback_rate.chargeback_rate_details << FactoryBot.create(factory_name, :tiers_with_three_intervals, :per_time => evaluator.per_time) end @@ -60,7 +60,7 @@ chargeback_rate_detail_fixed_storage_cost chargeback_rate_detail_fixed_storage_cost ).each do |factory_name| - chargeback_rate.chargeback_rate_details << FactoryGirl.create(factory_name, + chargeback_rate.chargeback_rate_details << FactoryBot.create(factory_name, :tiers_with_three_intervals, :per_time => evaluator.per_time) end diff --git a/spec/factories/chargeback_rate_detail.rb b/spec/factories/chargeback_rate_detail.rb index c2e9dbe01ef..828ede21edd 100644 --- a/spec/factories/chargeback_rate_detail.rb +++ b/spec/factories/chargeback_rate_detail.rb @@ -1,7 +1,7 @@ -FactoryGirl.define do +FactoryBot.define do factory :chargeback_rate_detail do chargeback_rate - detail_currency { FactoryGirl.create(:chargeback_rate_detail_currency) } + detail_currency { FactoryBot.create(:chargeback_rate_detail_currency) } transient do tiers_params nil @@ -11,10 +11,10 @@ after(:create) do |chargeback_rate_detail, evaluator| if evaluator.tiers_params evaluator.tiers_params.each do |tier| - chargeback_rate_detail.chargeback_tiers << FactoryGirl.create(*[:chargeback_tier, tier]) + chargeback_rate_detail.chargeback_tiers << FactoryBot.create(*[:chargeback_tier, tier]) end else - chargeback_rate_detail.chargeback_tiers << FactoryGirl.create(:chargeback_tier) + chargeback_rate_detail.chargeback_tiers << FactoryBot.create(:chargeback_tier) end end end @@ -22,9 +22,9 @@ trait :tiers_with_three_intervals do chargeback_tiers do [ - FactoryGirl.create(:chargeback_tier_first_of_three), - FactoryGirl.create(:chargeback_tier_second_of_three), - FactoryGirl.create(:chargeback_tier_third_of_three) + FactoryBot.create(:chargeback_tier_first_of_three), + FactoryBot.create(:chargeback_tier_second_of_three), + FactoryBot.create(:chargeback_tier_third_of_three) ] end end @@ -52,54 +52,54 @@ factory :chargeback_rate_detail_cpu_used, :parent => :chargeback_rate_detail do per_unit "megahertz" - chargeable_field { FactoryGirl.build(:chargeable_field_cpu_used) } + chargeable_field { FactoryBot.build(:chargeable_field_cpu_used) } end factory :chargeback_rate_detail_cpu_cores_used, :parent => :chargeback_rate_detail do per_unit "cores" - chargeable_field { FactoryGirl.build(:chargeable_field_cpu_cores_used) } + chargeable_field { FactoryBot.build(:chargeable_field_cpu_cores_used) } end factory :chargeback_rate_detail_cpu_cores_allocated, :parent => :chargeback_rate_detail do per_unit "cores" - chargeable_field { FactoryGirl.build(:chargeable_field_cpu_cores_allocated) } + chargeable_field { FactoryBot.build(:chargeable_field_cpu_cores_allocated) } end factory :chargeback_rate_detail_cpu_allocated, :traits => [:daily], :parent => :chargeback_rate_detail do per_unit "cpu" - chargeable_field { FactoryGirl.build(:chargeable_field_cpu_allocated) } + chargeable_field { FactoryBot.build(:chargeable_field_cpu_allocated) } end factory :chargeback_rate_detail_memory_allocated, :traits => [:megabytes, :daily], :parent => :chargeback_rate_detail do - chargeable_field { FactoryGirl.build(:chargeable_field_memory_allocated) } + chargeable_field { FactoryBot.build(:chargeable_field_memory_allocated) } end factory :chargeback_rate_detail_memory_used, :traits => [:megabytes, :hourly], :parent => :chargeback_rate_detail do - chargeable_field { FactoryGirl.build(:chargeable_field_memory_used) } + chargeable_field { FactoryBot.build(:chargeable_field_memory_used) } end factory :chargeback_rate_detail_disk_io_used, :traits => [:kbps], :parent => :chargeback_rate_detail do - chargeable_field { FactoryGirl.build(:chargeable_field_disk_io_used) } + chargeable_field { FactoryBot.build(:chargeable_field_disk_io_used) } end factory :chargeback_rate_detail_net_io_used, :traits => [:kbps], :parent => :chargeback_rate_detail do - chargeable_field { FactoryGirl.build(:chargeable_field_net_io_used) } + chargeable_field { FactoryBot.build(:chargeable_field_net_io_used) } end factory :chargeback_rate_detail_storage_used, :traits => [:gigabytes], :parent => :chargeback_rate_detail do - chargeable_field { FactoryGirl.build(:chargeable_field_storage_used) } + chargeable_field { FactoryBot.build(:chargeable_field_storage_used) } end factory :chargeback_rate_detail_storage_allocated, :traits => [:gigabytes], :parent => :chargeback_rate_detail do - chargeable_field { FactoryGirl.build(:chargeable_field_storage_allocated) } + chargeable_field { FactoryBot.build(:chargeable_field_storage_allocated) } end factory :chargeback_rate_detail_fixed_compute_cost, :traits => [:daily], :parent => :chargeback_rate_detail do - chargeable_field { FactoryGirl.build(:chargeable_field_fixed_compute_1) } + chargeable_field { FactoryBot.build(:chargeable_field_fixed_compute_1) } end end diff --git a/spec/factories/chargeback_rate_detail_currency.rb b/spec/factories/chargeback_rate_detail_currency.rb index abf194f4be7..936eb4014ea 100644 --- a/spec/factories/chargeback_rate_detail_currency.rb +++ b/spec/factories/chargeback_rate_detail_currency.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :chargeback_rate_detail_currency do code "EUR" name "Euro" diff --git a/spec/factories/chargeback_rate_detail_measure.rb b/spec/factories/chargeback_rate_detail_measure.rb index d8a1e40e213..50a949de596 100644 --- a/spec/factories/chargeback_rate_detail_measure.rb +++ b/spec/factories/chargeback_rate_detail_measure.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :chargeback_rate_detail_measure do step "1024" name "Bytes Units" diff --git a/spec/factories/chargeback_tier.rb b/spec/factories/chargeback_tier.rb index 475bb31335c..20a01786988 100644 --- a/spec/factories/chargeback_tier.rb +++ b/spec/factories/chargeback_tier.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :chargeback_tier do start 0 finish Float::INFINITY diff --git a/spec/factories/classification.rb b/spec/factories/classification.rb index 1e42cd9c132..b18d2e52f72 100644 --- a/spec/factories/classification.rb +++ b/spec/factories/classification.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :classification do sequence(:name) { |n| "category_#{seq_padded_for_sorting(n)}" } sequence(:description) { |n| "category #{seq_padded_for_sorting(n)}" } @@ -31,7 +31,7 @@ factory :classification_cost_center_with_tags, :parent => :classification_cost_center do children do [ - FactoryGirl.create(:classification_tag, :name => "001", :description => "Cost Center 001"), + FactoryBot.create(:classification_tag, :name => "001", :description => "Cost Center 001"), ] end end @@ -39,9 +39,9 @@ factory :classification_department_with_tags, :parent => :classification_department do children do [ - FactoryGirl.create(:classification_tag, :name => "accounting", :description => "Accounting"), - FactoryGirl.create(:classification_tag, :name => "finance", :description => "Financial Services"), - FactoryGirl.create(:classification_tag, :name => "hr", :description => "Human Resources"), + FactoryBot.create(:classification_tag, :name => "accounting", :description => "Accounting"), + FactoryBot.create(:classification_tag, :name => "finance", :description => "Financial Services"), + FactoryBot.create(:classification_tag, :name => "hr", :description => "Human Resources"), ] end end diff --git a/spec/factories/cloud_network.rb b/spec/factories/cloud_network.rb index 21fb4d665e6..3654c069e46 100644 --- a/spec/factories/cloud_network.rb +++ b/spec/factories/cloud_network.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :cloud_network do sequence(:name) { |n| "cloud_network_#{seq_padded_for_sorting(n)}" } sequence(:ems_ref) { |n| "ems_ref_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/cloud_service.rb b/spec/factories/cloud_service.rb index 8f0ccdd94f3..70deb9ae603 100644 --- a/spec/factories/cloud_service.rb +++ b/spec/factories/cloud_service.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :cloud_service do sequence(:executable_name) { |n| "cloud_service_#{seq_padded_for_sorting(n)}" } scheduling_disabled false diff --git a/spec/factories/cloud_subnet.rb b/spec/factories/cloud_subnet.rb index 353f6251a7e..7adf615f981 100644 --- a/spec/factories/cloud_subnet.rb +++ b/spec/factories/cloud_subnet.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :cloud_subnet do sequence(:name) { |n| "cloud_subnet_#{seq_padded_for_sorting(n)}" } sequence(:ems_ref) { |n| "ems_ref_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/cloud_tenants.rb b/spec/factories/cloud_tenants.rb index 2acd52a3ed1..de2182ccc7a 100644 --- a/spec/factories/cloud_tenants.rb +++ b/spec/factories/cloud_tenants.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :cloud_tenant do sequence(:name) { |n| "cloud_tenant_#{seq_padded_for_sorting(n)}" } sequence(:description) { |n| "cloud_tenant_description_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/cloud_volume.rb b/spec/factories/cloud_volume.rb index 78186755c11..b1072894221 100644 --- a/spec/factories/cloud_volume.rb +++ b/spec/factories/cloud_volume.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :cloud_volume do sequence(:volume_type) { |n| "volume_type_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/cloud_volume_backup.rb b/spec/factories/cloud_volume_backup.rb index 75b4b6fce1c..9bc0ea26104 100644 --- a/spec/factories/cloud_volume_backup.rb +++ b/spec/factories/cloud_volume_backup.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :cloud_volume_backup do sequence(:name) { |n| "cloud_volume_backup_#{seq_padded_for_sorting(n)}" } sequence(:ems_ref) { |n| "ems_ref_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/cloud_volume_snapshot.rb b/spec/factories/cloud_volume_snapshot.rb index e35605e7712..c7b957418b8 100644 --- a/spec/factories/cloud_volume_snapshot.rb +++ b/spec/factories/cloud_volume_snapshot.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :cloud_volume_snapshot do sequence(:name) { |n| "cloud_volume_snapshot_#{seq_padded_for_sorting(n)}" } sequence(:ems_ref) { |n| "ems_ref_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/compliance.rb b/spec/factories/compliance.rb index 5b47a01ee82..a000a8f2cc6 100644 --- a/spec/factories/compliance.rb +++ b/spec/factories/compliance.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :compliance do sequence(:id) { |n| 10_000_000 + n } sequence(:resource_id) { |n| 10_000_010 + n } diff --git a/spec/factories/compliance_detail.rb b/spec/factories/compliance_detail.rb index a58d28a4003..8463769bafa 100644 --- a/spec/factories/compliance_detail.rb +++ b/spec/factories/compliance_detail.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :compliance_detail do sequence(:id) { |n| 10_000_000 + n } created_on DateTime .current diff --git a/spec/factories/condition.rb b/spec/factories/condition.rb index 8fe173e0bf0..ab64d35c114 100644 --- a/spec/factories/condition.rb +++ b/spec/factories/condition.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :condition do sequence(:name) { |num| "condition_#{seq_padded_for_sorting(num)}" } sequence(:description) { |num| "Condition #{seq_padded_for_sorting(num)}" } diff --git a/spec/factories/configuration_location.rb b/spec/factories/configuration_location.rb index 47e597089ae..96d019e89f4 100644 --- a/spec/factories/configuration_location.rb +++ b/spec/factories/configuration_location.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :configuration_location do sequence(:name) { |n| "configuration_location#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/configuration_organization.rb b/spec/factories/configuration_organization.rb index 6d5efd8f34a..c6f6ae20595 100644 --- a/spec/factories/configuration_organization.rb +++ b/spec/factories/configuration_organization.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :configuration_organization do sequence(:name) { |n| "configuration_organization#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/configuration_profile.rb b/spec/factories/configuration_profile.rb index 33b8721f15c..9af13fb9eb7 100644 --- a/spec/factories/configuration_profile.rb +++ b/spec/factories/configuration_profile.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :configuration_profile factory :configuration_profile_foreman, diff --git a/spec/factories/configuration_script.rb b/spec/factories/configuration_script.rb index 21fd5fa7cfd..7850badf622 100644 --- a/spec/factories/configuration_script.rb +++ b/spec/factories/configuration_script.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :configuration_script_base do sequence(:name) { |n| "Configuration_script_base_#{seq_padded_for_sorting(n)}" } sequence(:manager_ref) { SecureRandom.random_number(100) } diff --git a/spec/factories/configuration_script_source.rb b/spec/factories/configuration_script_source.rb index e046767cc2e..90d5b56e4c5 100644 --- a/spec/factories/configuration_script_source.rb +++ b/spec/factories/configuration_script_source.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :configuration_script_source do sequence(:name) { |n| "configuration_script_source#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/configured_system.rb b/spec/factories/configured_system.rb index 2da6d6f170f..35229861ee2 100644 --- a/spec/factories/configured_system.rb +++ b/spec/factories/configured_system.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :configured_system do sequence(:name) { |n| "Configured_system_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/container_group.rb b/spec/factories/container_group.rb index b2590642927..791ba87ca4d 100644 --- a/spec/factories/container_group.rb +++ b/spec/factories/container_group.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :container_group do sequence(:name) { |n| "container_group_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/container_image.rb b/spec/factories/container_image.rb index 3e763c81aa6..865dd3bd237 100644 --- a/spec/factories/container_image.rb +++ b/spec/factories/container_image.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :container_image do sequence(:name) { |n| "container_image_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/container_image_registry.rb b/spec/factories/container_image_registry.rb index 43b25199b9d..f81d054e8a8 100644 --- a/spec/factories/container_image_registry.rb +++ b/spec/factories/container_image_registry.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :container_image_registry do sequence(:name) { |n| "image_registry_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/container_label_tag_mapping.rb b/spec/factories/container_label_tag_mapping.rb index 8164c182cc7..2ff6814d9c1 100644 --- a/spec/factories/container_label_tag_mapping.rb +++ b/spec/factories/container_label_tag_mapping.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :container_label_tag_mapping do label_name 'name' @@ -15,7 +15,7 @@ end tag do - category = FactoryGirl.create(:classification, + category = FactoryBot.create(:classification, :name => category_name, :description => category_description, :single_value => true, diff --git a/spec/factories/container_nodes.rb b/spec/factories/container_nodes.rb index 11edaccab66..ffb74f806ae 100644 --- a/spec/factories/container_nodes.rb +++ b/spec/factories/container_nodes.rb @@ -1,7 +1,7 @@ -FactoryGirl.define do +FactoryBot.define do factory :container_node do after(:create) do |x| - x.computer_system = FactoryGirl.create(:computer_system) + x.computer_system = FactoryBot.create(:computer_system) end end diff --git a/spec/factories/container_project.rb b/spec/factories/container_project.rb index f1c5f37b753..706cf955a5a 100644 --- a/spec/factories/container_project.rb +++ b/spec/factories/container_project.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :container_project do sequence(:name) { |n| "container_project_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/container_quota_scope.rb b/spec/factories/container_quota_scope.rb index cd708c30a62..f7111e46e30 100644 --- a/spec/factories/container_quota_scope.rb +++ b/spec/factories/container_quota_scope.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :container_quota_scope do scope "NotTerminating" end diff --git a/spec/factories/container_replicator.rb b/spec/factories/container_replicator.rb index 4d538c13da0..51f8a8fc9e2 100644 --- a/spec/factories/container_replicator.rb +++ b/spec/factories/container_replicator.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :container_replicator do sequence(:name) { |n| "container_replicator_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/container_routes.rb b/spec/factories/container_routes.rb index 7f745cae44a..dc59b7ab6c3 100644 --- a/spec/factories/container_routes.rb +++ b/spec/factories/container_routes.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :container_route do sequence(:name) { |n| "container_route_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/container_services.rb b/spec/factories/container_services.rb index f2d8900a88e..92afcf198d4 100644 --- a/spec/factories/container_services.rb +++ b/spec/factories/container_services.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :container_service do sequence(:name) { |n| "container_service_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/container_template.rb b/spec/factories/container_template.rb index 4b334b73f3d..4748b078c5e 100644 --- a/spec/factories/container_template.rb +++ b/spec/factories/container_template.rb @@ -1 +1 @@ -FactoryGirl.define { factory(:container_template) } +FactoryBot.define { factory(:container_template) } diff --git a/spec/factories/container_volume.rb b/spec/factories/container_volume.rb index 699431f1519..e10c733a646 100644 --- a/spec/factories/container_volume.rb +++ b/spec/factories/container_volume.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :container_volume do sequence(:name) { |n| "container_volume_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/containers.rb b/spec/factories/containers.rb index ce3cc8006bc..297b43ce00b 100644 --- a/spec/factories/containers.rb +++ b/spec/factories/containers.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :container do sequence(:name) { |n| "container_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/conversion_host.rb b/spec/factories/conversion_host.rb index 18f1842e414..aaf241e2223 100644 --- a/spec/factories/conversion_host.rb +++ b/spec/factories/conversion_host.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :conversion_host do sequence(:name) { |n| "conversion_host_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/custom_attribute.rb b/spec/factories/custom_attribute.rb index 5be8725c01e..3c0c9c4da3b 100644 --- a/spec/factories/custom_attribute.rb +++ b/spec/factories/custom_attribute.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :custom_attribute factory :miq_custom_attribute, :parent => :custom_attribute do diff --git a/spec/factories/custom_button.rb b/spec/factories/custom_button.rb index d80626d6b53..5e120280c02 100644 --- a/spec/factories/custom_button.rb +++ b/spec/factories/custom_button.rb @@ -1,10 +1,10 @@ -FactoryGirl.define do +FactoryBot.define do factory :custom_button do sequence(:name) { |n| "custom_button_#{seq_padded_for_sorting(n)}" } sequence(:description) { |n| "custom_button_#{seq_padded_for_sorting(n)}" } trait :with_resource_action_dialog do - resource_action { FactoryGirl.create(:resource_action, :dialog_id => FactoryGirl.create(:dialog).id) } + resource_action { FactoryBot.create(:resource_action, :dialog_id => FactoryBot.create(:dialog).id) } end end end diff --git a/spec/factories/custom_button_set.rb b/spec/factories/custom_button_set.rb index 78d1defaf9f..c3cc95b5bcd 100644 --- a/spec/factories/custom_button_set.rb +++ b/spec/factories/custom_button_set.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :custom_button_set do sequence(:name) { |n| "custom_button_set_#{seq_padded_for_sorting(n)}" } sequence(:description) { |n| "custom_button_set_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/customization_spec_factory.rb b/spec/factories/customization_spec_factory.rb index dd332e3e26a..eda1afc9f27 100644 --- a/spec/factories/customization_spec_factory.rb +++ b/spec/factories/customization_spec_factory.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :customization_spec do sequence(:name) { |n| "customization_spec_#{seq_padded_for_sorting(n)}" } typ { "Windows" } diff --git a/spec/factories/customization_template.rb b/spec/factories/customization_template.rb index c6cf2d3a40e..e42b7b3ca36 100644 --- a/spec/factories/customization_template.rb +++ b/spec/factories/customization_template.rb @@ -1,10 +1,10 @@ -FactoryGirl.define do +FactoryBot.define do factory :customization_template do sequence(:name) { |n| "customization_template_#{seq_padded_for_sorting(n)}" } sequence(:description) { |n| "Customization Template #{seq_padded_for_sorting(n)}" } sequence(:script) { |n| "script_name_#{seq_padded_for_sorting(n)}" } after(:build) do |x| - x.pxe_image_type ||= FactoryGirl.create(:pxe_image_type) + x.pxe_image_type ||= FactoryBot.create(:pxe_image_type) end end @@ -12,7 +12,7 @@ :parent => :customization_template, :class => "CustomizationTemplateCloudInit" do after(:build) do |x| - x.pxe_image_type ||= FactoryGirl.create(:pxe_image_type) + x.pxe_image_type ||= FactoryBot.create(:pxe_image_type) end end @@ -22,7 +22,7 @@ sequence(:name) { |n| "customization_template_kickstart_#{seq_padded_for_sorting(n)}" } sequence(:description) { |n| "Customization Template Kickstart #{seq_padded_for_sorting(n)}" } after(:build) do |x| - x.pxe_image_type ||= FactoryGirl.create(:pxe_image_type) + x.pxe_image_type ||= FactoryBot.create(:pxe_image_type) end end @@ -32,7 +32,7 @@ sequence(:name) { |n| "customization_template_sysprep_#{seq_padded_for_sorting(n)}" } sequence(:description) { |n| "Customization Template Sysprep #{seq_padded_for_sorting(n)}" } after(:build) do |x| - x.pxe_image_type ||= FactoryGirl.create(:pxe_image_type) + x.pxe_image_type ||= FactoryBot.create(:pxe_image_type) end end end diff --git a/spec/factories/database_backup.rb b/spec/factories/database_backup.rb index fa4de91bf2d..51a1c7fe2ef 100644 --- a/spec/factories/database_backup.rb +++ b/spec/factories/database_backup.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :database_backup do sequence(:name) { |val| "db_backup_#{val}" } end diff --git a/spec/factories/dialog.rb b/spec/factories/dialog.rb index d4a3a12e4ae..96e993f853b 100644 --- a/spec/factories/dialog.rb +++ b/spec/factories/dialog.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :dialog do sequence(:name) { |n| "Dialog #{n}" } diff --git a/spec/factories/dialog_field.rb b/spec/factories/dialog_field.rb index 9ae70379355..4ff406ff8fd 100644 --- a/spec/factories/dialog_field.rb +++ b/spec/factories/dialog_field.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :dialog_field do name "Dialog Field" end diff --git a/spec/factories/dialog_group.rb b/spec/factories/dialog_group.rb index 146a4a03ac0..2f13fc56515 100644 --- a/spec/factories/dialog_group.rb +++ b/spec/factories/dialog_group.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :dialog_group do sequence(:label) { |n| "Dialog Group #{n}" } diff --git a/spec/factories/dialog_tab.rb b/spec/factories/dialog_tab.rb index 3b7ded75a49..1c8a4839f71 100644 --- a/spec/factories/dialog_tab.rb +++ b/spec/factories/dialog_tab.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :dialog_tab do sequence(:label) { |n| "Dialog Tab #{n}" } diff --git a/spec/factories/ems_cluster.rb b/spec/factories/ems_cluster.rb index 4689a5e9be0..dba268147f2 100644 --- a/spec/factories/ems_cluster.rb +++ b/spec/factories/ems_cluster.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :ems_cluster do sequence(:name) { |n| "cluster_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/ems_folder.rb b/spec/factories/ems_folder.rb index 59b164306e8..02a7edbace4 100644 --- a/spec/factories/ems_folder.rb +++ b/spec/factories/ems_folder.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :ems_folder do sequence(:name) { |n| "Test Folder #{seq_padded_for_sorting(n)}" } end @@ -78,21 +78,21 @@ def build_vmware_folder_structure!(ems) ems.add_child( - FactoryGirl.create(:vmware_folder_root, :ems_id => ems.id).tap do |root| + FactoryBot.create(:vmware_folder_root, :ems_id => ems.id).tap do |root| root.add_child( - FactoryGirl.create(:vmware_folder, :name => "yellow1", :ems_id => ems.id).tap do |f| + FactoryBot.create(:vmware_folder, :name => "yellow1", :ems_id => ems.id).tap do |f| f.add_child( - FactoryGirl.create(:vmware_datacenter, :ems_id => ems.id).tap do |dc| + FactoryBot.create(:vmware_datacenter, :ems_id => ems.id).tap do |dc| dc.add_children( - FactoryGirl.create(:vmware_folder_vm_root, :ems_id => ems.id) do |vm| + FactoryBot.create(:vmware_folder_vm_root, :ems_id => ems.id) do |vm| vm.add_children( - FactoryGirl.create(:vmware_folder_vm, :name => "blue1", :ems_id => ems.id), - FactoryGirl.create(:vmware_folder_vm, :name => "blue2", :ems_id => ems.id) + FactoryBot.create(:vmware_folder_vm, :name => "blue1", :ems_id => ems.id), + FactoryBot.create(:vmware_folder_vm, :name => "blue2", :ems_id => ems.id) ) end, - FactoryGirl.create(:vmware_folder_host_root, :ems_id => ems.id), - FactoryGirl.create(:vmware_folder_datastore_root, :ems_id => ems.id), - FactoryGirl.create(:vmware_folder_network_root, :ems_id => ems.id) + FactoryBot.create(:vmware_folder_host_root, :ems_id => ems.id), + FactoryBot.create(:vmware_folder_datastore_root, :ems_id => ems.id), + FactoryBot.create(:vmware_folder_network_root, :ems_id => ems.id) ) end ) diff --git a/spec/factories/endpoint.rb b/spec/factories/endpoint.rb index 515e4ec26b9..74ff96b0181 100644 --- a/spec/factories/endpoint.rb +++ b/spec/factories/endpoint.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :endpoint do port 443 hostname "example.com" diff --git a/spec/factories/entitlement.rb b/spec/factories/entitlement.rb index 293a42cd319..4a7d3c92d99 100644 --- a/spec/factories/entitlement.rb +++ b/spec/factories/entitlement.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :entitlement do transient do features nil @@ -7,7 +7,7 @@ after :build do |entitlement, e| if e.role || e.features - entitlement.miq_user_role = FactoryGirl.create(:miq_user_role, + entitlement.miq_user_role = FactoryBot.create(:miq_user_role, :features => e.features, :role => e.role) end diff --git a/spec/factories/ext_management_system.rb b/spec/factories/ext_management_system.rb index 4f40f3fbff7..c46e56c74e0 100644 --- a/spec/factories/ext_management_system.rb +++ b/spec/factories/ext_management_system.rb @@ -1,10 +1,10 @@ -FactoryGirl.define do +FactoryBot.define do factory :ext_management_system do sequence(:name) { |n| "ems_#{seq_padded_for_sorting(n)}" } sequence(:hostname) { |n| "ems-#{seq_padded_for_sorting(n)}" } sequence(:ipaddress) { |n| ip_from_seq(n) } guid { SecureRandom.uuid } - zone { FactoryGirl.create(:zone) } + zone { FactoryBot.create(:zone) } storage_profiles { [] } # Traits @@ -31,7 +31,7 @@ trait :with_invalid_authentication do after(:create) do |x| - x.authentications << FactoryGirl.create(:authentication, :status => "invalid") + x.authentications << FactoryBot.create(:authentication, :status => "invalid") end end end @@ -125,14 +125,14 @@ factory :ems_vmware_with_authentication, :parent => :ems_vmware do after(:create) do |x| - x.authentications << FactoryGirl.create(:authentication) + x.authentications << FactoryBot.create(:authentication) end end factory :ems_vmware_with_valid_authentication, :parent => :ems_vmware do after(:create) do |x| - x.authentications << FactoryGirl.create(:authentication, :status => "Valid") + x.authentications << FactoryBot.create(:authentication, :status => "Valid") end end @@ -144,7 +144,7 @@ factory :ems_microsoft_with_authentication, :parent => :ems_microsoft do after(:create) do |x| - x.authentications << FactoryGirl.create(:authentication) + x.authentications << FactoryBot.create(:authentication) end end @@ -166,7 +166,7 @@ factory :ems_redhat_with_authentication, :parent => :ems_redhat do after(:create) do |x| - x.authentications << FactoryGirl.create(:authentication) + x.authentications << FactoryBot.create(:authentication) end end @@ -178,14 +178,14 @@ :parent => :ems_redhat do certificate_authority "cert108" after(:create) do |x| - x.authentications << FactoryGirl.create(:authentication) + x.authentications << FactoryBot.create(:authentication) end end factory :ems_redhat_with_metrics_authentication, :parent => :ems_redhat do after(:create) do |x| - x.authentications << FactoryGirl.create(:authentication_redhat_metric) + x.authentications << FactoryBot.create(:authentication_redhat_metric) end end @@ -197,25 +197,25 @@ factory :ems_openstack_infra_with_stack, :parent => :ems_openstack_infra do after :create do |x| - x.orchestration_stacks << FactoryGirl.create(:orchestration_stack_openstack_infra) - 4.times { x.hosts << FactoryGirl.create(:host_openstack_infra) } + x.orchestration_stacks << FactoryBot.create(:orchestration_stack_openstack_infra) + 4.times { x.hosts << FactoryBot.create(:host_openstack_infra) } end end factory :ems_openstack_infra_with_stack_and_compute_nodes, :parent => :ems_openstack_infra do after :create do |x| - x.orchestration_stacks << FactoryGirl.create(:orchestration_stack_openstack_infra) - x.hosts += [FactoryGirl.create(:host_openstack_infra_compute), - FactoryGirl.create(:host_openstack_infra_compute_maintenance)] + x.orchestration_stacks << FactoryBot.create(:orchestration_stack_openstack_infra) + x.hosts += [FactoryBot.create(:host_openstack_infra_compute), + FactoryBot.create(:host_openstack_infra_compute_maintenance)] end end factory :ems_openstack_infra_with_authentication, :parent => :ems_openstack_infra do after :create do |x| - x.authentications << FactoryGirl.create(:authentication) - x.authentications << FactoryGirl.create(:authentication, :authtype => "amqp") + x.authentications << FactoryBot.create(:authentication) + x.authentications << FactoryBot.create(:authentication, :authtype => "amqp") end end @@ -248,14 +248,14 @@ factory :ems_amazon_with_authentication, :parent => :ems_amazon do after(:create) do |x| - x.authentications << FactoryGirl.create(:authentication) + x.authentications << FactoryBot.create(:authentication) end end factory :ems_amazon_with_cloud_networks, :parent => :ems_amazon do after(:create) do |x| - 2.times { x.cloud_networks << FactoryGirl.create(:cloud_network_amazon) } + 2.times { x.cloud_networks << FactoryBot.create(:cloud_network_amazon) } end end @@ -274,7 +274,7 @@ azure_tenant_id "ABCDEFGHIJABCDEFGHIJ0123456789AB" subscription "0123456789ABCDEFGHIJABCDEFGHIJKL" after :create do |x| - x.authentications << FactoryGirl.create(:authentication) + x.authentications << FactoryBot.create(:authentication) end end @@ -286,8 +286,8 @@ factory :ems_openstack_with_authentication, :parent => :ems_openstack do after :create do |x| - x.authentications << FactoryGirl.create(:authentication) - x.authentications << FactoryGirl.create(:authentication, :authtype => "amqp") + x.authentications << FactoryBot.create(:authentication) + x.authentications << FactoryBot.create(:authentication, :authtype => "amqp") end end @@ -309,7 +309,7 @@ factory :ems_google_with_authentication, :parent => :ems_google do after(:create) do |x| - x.authentications << FactoryGirl.create(:authentication) + x.authentications << FactoryBot.create(:authentication) end end @@ -328,7 +328,7 @@ factory :ems_kubernetes_with_authentication_err, :parent => :ems_kubernetes do after :create do |x| - x.authentications << FactoryGirl.create(:authentication_status_error) + x.authentications << FactoryBot.create(:authentication_status_error) end end @@ -352,14 +352,14 @@ trait(:configuration_script) do after(:create) do |x| type = (x.type.split("::")[0..2] + ["AutomationManager", "ConfigurationScript"]).join("::") - x.configuration_scripts << FactoryGirl.create(:configuration_script, :type => type) + x.configuration_scripts << FactoryBot.create(:configuration_script, :type => type) end end trait(:configuration_workflow) do after(:create) do |x| type = (x.type.split("::")[0..2] + %w(AutomationManager ConfigurationWorkflow)).join("::") - x.configuration_scripts << FactoryGirl.create(:configuration_workflow, :type => type) + x.configuration_scripts << FactoryBot.create(:configuration_workflow, :type => type) end end diff --git a/spec/factories/file_depot.rb b/spec/factories/file_depot.rb index ca4bc8b8e38..32141bf370e 100644 --- a/spec/factories/file_depot.rb +++ b/spec/factories/file_depot.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :file_depot do name "File Depot" uri "nfs://somehost/export" @@ -6,6 +6,6 @@ factory(:file_depot_ftp, :class => "FileDepotFtp", :parent => :file_depot) { uri "ftp://somehost/export" } factory :file_depot_ftp_with_authentication, :parent => :file_depot_ftp do - after(:create) { |x| x.authentications << FactoryGirl.create(:authentication) } + after(:create) { |x| x.authentications << FactoryBot.create(:authentication) } end end diff --git a/spec/factories/filesystem.rb b/spec/factories/filesystem.rb index abe57490740..4d462edf72e 100644 --- a/spec/factories/filesystem.rb +++ b/spec/factories/filesystem.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :filesystem do sequence(:name) { |n| "filesystem_#{seq_padded_for_sorting(n)}" } size 200 diff --git a/spec/factories/firewall_rule.rb b/spec/factories/firewall_rule.rb index 92f76ba6874..9cc13a4560d 100644 --- a/spec/factories/firewall_rule.rb +++ b/spec/factories/firewall_rule.rb @@ -1,3 +1,3 @@ -FactoryGirl.define do +FactoryBot.define do factory :firewall_rule end diff --git a/spec/factories/flavor.rb b/spec/factories/flavor.rb index 9106da93736..b7b115e3983 100644 --- a/spec/factories/flavor.rb +++ b/spec/factories/flavor.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :flavor do sequence(:name) { |n| "flavor_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/floating_ip.rb b/spec/factories/floating_ip.rb index b658227242b..bb2e311657f 100644 --- a/spec/factories/floating_ip.rb +++ b/spec/factories/floating_ip.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :floating_ip do sequence(:address) { |n| ip_from_seq(n) } end diff --git a/spec/factories/generic_object.rb b/spec/factories/generic_object.rb index 4261a6128bc..980dc0794cf 100644 --- a/spec/factories/generic_object.rb +++ b/spec/factories/generic_object.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :generic_object do sequence(:name) { |n| "generic_object_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/generic_object_definition.rb b/spec/factories/generic_object_definition.rb index f7cdb3edc8e..e69f2b415cd 100644 --- a/spec/factories/generic_object_definition.rb +++ b/spec/factories/generic_object_definition.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :generic_object_definition do sequence(:name) { |n| "generic_object_definition_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/git_reference.rb b/spec/factories/git_reference.rb index ce282221fc4..a5516427f04 100644 --- a/spec/factories/git_reference.rb +++ b/spec/factories/git_reference.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :git_reference do sequence(:name) { |n| "git_ref#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/git_repositories.rb b/spec/factories/git_repositories.rb index 25721574b26..ddc0a7e5f11 100644 --- a/spec/factories/git_repositories.rb +++ b/spec/factories/git_repositories.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :git_repository do sequence(:name) { |n| "git_repo_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/guest_device.rb b/spec/factories/guest_device.rb index aa4d6ad8032..70a048e4448 100644 --- a/spec/factories/guest_device.rb +++ b/spec/factories/guest_device.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :guest_device factory :guest_device_nic, :parent => :guest_device do @@ -10,7 +10,7 @@ factory :guest_device_nic_with_network, :parent => :guest_device_nic do after(:build) do |x| - x.network = FactoryGirl.build(:network, :hardware_id => x.hardware_id) + x.network = FactoryBot.build(:network, :hardware_id => x.hardware_id) end end end diff --git a/spec/factories/hardware.rb b/spec/factories/hardware.rb index 6353397f978..bc6d23bfb26 100644 --- a/spec/factories/hardware.rb +++ b/spec/factories/hardware.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :hardware do trait(:cpu1x1) do cpu_sockets 1 diff --git a/spec/factories/host.rb b/spec/factories/host.rb index fa96cd41b67..b15cc6349e8 100644 --- a/spec/factories/host.rb +++ b/spec/factories/host.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :host do sequence(:name) { |n| "host_#{seq_padded_for_sorting(n)}" } sequence(:hostname) { |n| "host-#{seq_padded_for_sorting(n)}" } @@ -15,13 +15,13 @@ factory :host_with_authentication, :parent => :host do after(:create) do |x| - x.authentications = [FactoryGirl.build(:authentication, :resource => x)] + x.authentications = [FactoryBot.build(:authentication, :resource => x)] end end factory :host_vmware_esx_with_authentication, :parent => :host_vmware_esx do after(:create) do |x| - x.authentications = [FactoryGirl.build(:authentication, :resource => x)] + x.authentications = [FactoryBot.build(:authentication, :resource => x)] end end @@ -29,7 +29,7 @@ factory :host_target_vmware, :parent => :host, :class => 'ManageIQ::Providers::Vmware::InfraManager::Host' do after(:create) do |x| x.perf_capture_enabled = toggle_on_name_seq(x) - 2.times { x.vms << FactoryGirl.create(:vm_target_vmware, :ext_management_system => x.ext_management_system) } + 2.times { x.vms << FactoryBot.create(:vm_target_vmware, :ext_management_system => x.ext_management_system) } end end @@ -37,7 +37,7 @@ ipmi_address "127.0.0.1" mac_address "aa:bb:cc:dd:ee:ff" after(:create) do |x| - x.authentications = [FactoryGirl.build(:authentication_ipmi, :resource => x)] + x.authentications = [FactoryBot.build(:authentication_ipmi, :resource => x)] end end diff --git a/spec/factories/host_aggregate.rb b/spec/factories/host_aggregate.rb index 84882e358da..a8662714d09 100644 --- a/spec/factories/host_aggregate.rb +++ b/spec/factories/host_aggregate.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :host_aggregate do sequence(:name) { |n| " host_aggregate_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/host_service_group.rb b/spec/factories/host_service_group.rb index 0842ea5c4b9..2f2eefee06f 100644 --- a/spec/factories/host_service_group.rb +++ b/spec/factories/host_service_group.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :host_service_group do sequence(:name) { |n| "host_service_group_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/host_service_group_openstack.rb b/spec/factories/host_service_group_openstack.rb index 5dd3dada769..5afcabc594f 100644 --- a/spec/factories/host_service_group_openstack.rb +++ b/spec/factories/host_service_group_openstack.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :host_service_group_openstack, :class => "ManageIQ::Providers::Openstack::InfraManager::HostServiceGroup" do sequence(:name) { |n| "host_service_group_openstack_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/lan.rb b/spec/factories/lan.rb index fe35e8621a2..a1c2b53f9c7 100644 --- a/spec/factories/lan.rb +++ b/spec/factories/lan.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :lan do sequence(:name) { |n| "Lan #{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/load_balancer.rb b/spec/factories/load_balancer.rb index abeba975559..7fd54c564a2 100644 --- a/spec/factories/load_balancer.rb +++ b/spec/factories/load_balancer.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :load_balancer do sequence(:name) { |n| "load_balancer_#{seq_padded_for_sorting(n)}" } sequence(:ems_ref) { |n| "ems_ref_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/load_balancer_health_check.rb b/spec/factories/load_balancer_health_check.rb index 38e1f1a3c23..c92b5ec8edf 100644 --- a/spec/factories/load_balancer_health_check.rb +++ b/spec/factories/load_balancer_health_check.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :load_balancer_health_check do sequence(:name) { |n| "load_balancer_health_check_#{seq_padded_for_sorting(n)}" } sequence(:ems_ref) { |n| "ems_ref_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/load_balancer_listener.rb b/spec/factories/load_balancer_listener.rb index dbc52232e65..c492b467eb2 100644 --- a/spec/factories/load_balancer_listener.rb +++ b/spec/factories/load_balancer_listener.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :load_balancer_listener do sequence(:name) { |n| "load_balancer_listener_#{seq_padded_for_sorting(n)}" } sequence(:ems_ref) { |n| "ems_ref_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/load_balancer_pool.rb b/spec/factories/load_balancer_pool.rb index d3befdca24f..0cf9a5c937e 100644 --- a/spec/factories/load_balancer_pool.rb +++ b/spec/factories/load_balancer_pool.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :load_balancer_pool do sequence(:name) { |n| "load_balancer_pool_#{seq_padded_for_sorting(n)}" } sequence(:ems_ref) { |n| "ems_ref_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/load_balancer_pool_member.rb b/spec/factories/load_balancer_pool_member.rb index 5a783c8d862..69817435690 100644 --- a/spec/factories/load_balancer_pool_member.rb +++ b/spec/factories/load_balancer_pool_member.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :load_balancer_pool_member do sequence(:ems_ref) { |n| "ems_ref_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/log_file.rb b/spec/factories/log_file.rb index 563f7755cc0..ba202663939 100644 --- a/spec/factories/log_file.rb +++ b/spec/factories/log_file.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :log_file do state "collecting" historical true diff --git a/spec/factories/metric.rb b/spec/factories/metric.rb index c637a920ab8..21db5dfe5f9 100644 --- a/spec/factories/metric.rb +++ b/spec/factories/metric.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :metric do timestamp { Time.now.utc } end diff --git a/spec/factories/metric_rollup.rb b/spec/factories/metric_rollup.rb index 757f531afe0..733ae1bfe74 100644 --- a/spec/factories/metric_rollup.rb +++ b/spec/factories/metric_rollup.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :metric_rollup do timestamp { Time.now.utc } trait :with_data do diff --git a/spec/factories/middleware_datasource.rb b/spec/factories/middleware_datasource.rb index 607a7e1e151..3c26e7ad963 100644 --- a/spec/factories/middleware_datasource.rb +++ b/spec/factories/middleware_datasource.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :middleware_datasource factory :hawkular_middleware_datasource, @@ -10,6 +10,6 @@ :parent => :hawkular_middleware_datasource do name 'ExampleDS' nativeid 'Local~/subsystem=datasources/data-source=ExampleDS' - middleware_server { FactoryGirl.create(:middleware_server) } + middleware_server { FactoryBot.create(:middleware_server) } end end diff --git a/spec/factories/middleware_deployment.rb b/spec/factories/middleware_deployment.rb index 0a276e130a8..bc46df4d51b 100644 --- a/spec/factories/middleware_deployment.rb +++ b/spec/factories/middleware_deployment.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :middleware_deployment do ext_management_system name "A Middleware Deployment" diff --git a/spec/factories/middleware_domain.rb b/spec/factories/middleware_domain.rb index c663ff5c25c..e62d21eda1e 100644 --- a/spec/factories/middleware_domain.rb +++ b/spec/factories/middleware_domain.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :middleware_domain do sequence(:name) { |n| "middleware_domain_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/middleware_messaging.rb b/spec/factories/middleware_messaging.rb index 0ae5d1a5efc..629d33a2819 100644 --- a/spec/factories/middleware_messaging.rb +++ b/spec/factories/middleware_messaging.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :middleware_messaging factory :hawkular_middleware_messaging, diff --git a/spec/factories/middleware_server_group.rb b/spec/factories/middleware_server_group.rb index 17dbef49c49..1bfea4bdac7 100644 --- a/spec/factories/middleware_server_group.rb +++ b/spec/factories/middleware_server_group.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :middleware_server_group do sequence(:name) { |n| "middleware_server_group_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/middleware_servers.rb b/spec/factories/middleware_servers.rb index 5bb215e73d0..2487068a7c2 100644 --- a/spec/factories/middleware_servers.rb +++ b/spec/factories/middleware_servers.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :middleware_server do sequence(:name) { |n| "middleware_server_#{seq_padded_for_sorting(n)}" } sequence(:feed) { |n| "feed_#{n}" } diff --git a/spec/factories/miq_action.rb b/spec/factories/miq_action.rb index 00df66e43df..023b82ab2d8 100644 --- a/spec/factories/miq_action.rb +++ b/spec/factories/miq_action.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_action do sequence(:name) { |num| "action_#{seq_padded_for_sorting(num)}" } sequence(:description) { |num| "Test Action_#{seq_padded_for_sorting(num)}" } diff --git a/spec/factories/miq_ae_class.rb b/spec/factories/miq_ae_class.rb index 9c73e68788b..8befe49b7d6 100644 --- a/spec/factories/miq_ae_class.rb +++ b/spec/factories/miq_ae_class.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_ae_class do sequence(:name) { |n| "miq_ae_class_#{seq_padded_for_sorting(n)}" } @@ -11,18 +11,18 @@ after :create do |aeclass, evaluator| aeclass.ae_fields << evaluator.ae_fields.collect do |name, f| - FactoryGirl.build(:miq_ae_field, {:name => name}.merge(f)) + FactoryBot.build(:miq_ae_field, {:name => name}.merge(f)) end evaluator.ae_instances.each do |name, values| - FactoryGirl.create(:miq_ae_instance, :with_values, + FactoryBot.create(:miq_ae_instance, :with_values, :class_id => aeclass.id, :name => name, 'values' => values) end evaluator.ae_methods.each do |name, aemethod| - FactoryGirl.create(:miq_ae_method, :with_params, + FactoryBot.create(:miq_ae_method, :with_params, {:class_id => aeclass.id, :name => name}.merge(aemethod)) end @@ -35,7 +35,7 @@ end before(:create) do |ae_class, evaluator| - ae_class.namespace_id = FactoryGirl.create(:miq_ae_namespace, :parent => evaluator.domain).id + ae_class.namespace_id = FactoryBot.create(:miq_ae_namespace, :parent => evaluator.domain).id end end end diff --git a/spec/factories/miq_ae_domain.rb b/spec/factories/miq_ae_domain.rb index 608b4258944..cff04c3cff1 100644 --- a/spec/factories/miq_ae_domain.rb +++ b/spec/factories/miq_ae_domain.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_ae_domain_user_locked, :parent => :miq_ae_domain_disabled do source { MiqAeDomain::USER_LOCKED_SOURCE } end @@ -23,7 +23,7 @@ factory :miq_ae_git_domain, :parent => :miq_ae_domain do source { MiqAeDomain::REMOTE_SOURCE } - git_repository { FactoryGirl.create(:git_repository, :url => 'https://www.example.com/abc') } + git_repository { FactoryBot.create(:git_repository, :url => 'https://www.example.com/abc') } end factory :miq_ae_domain, :parent => :miq_ae_namespace, :class => "MiqAeDomain" do @@ -82,7 +82,7 @@ items = %w(ae_fields ae_instances ae_methods) items.each { |f| args[f] = evaluator.respond_to?(f) ? evaluator.send(f) : {} } - FactoryGirl.create(:miq_ae_class, :with_instances_and_methods, args) if evaluator.respond_to?('ae_class') + FactoryBot.create(:miq_ae_class, :with_instances_and_methods, args) if evaluator.respond_to?('ae_class') end end end diff --git a/spec/factories/miq_ae_instance.rb b/spec/factories/miq_ae_instance.rb index 45803e36780..abb2f394b4a 100644 --- a/spec/factories/miq_ae_instance.rb +++ b/spec/factories/miq_ae_instance.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_ae_instance do sequence(:name) { |n| "miq_ae_instance_#{seq_padded_for_sorting(n)}" } @@ -10,7 +10,7 @@ after :create do |aeinstance, evaluator| aeinstance.ae_values << aeinstance.ae_class.ae_fields.collect do |field| next unless evaluator.values.key?(field.name) - FactoryGirl.build(:miq_ae_value, {:field_id => field.id}.merge(evaluator.values[field.name])) + FactoryBot.build(:miq_ae_value, {:field_id => field.id}.merge(evaluator.values[field.name])) end end end diff --git a/spec/factories/miq_ae_method.rb b/spec/factories/miq_ae_method.rb index cf8cb576816..5db69508c47 100644 --- a/spec/factories/miq_ae_method.rb +++ b/spec/factories/miq_ae_method.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_ae_method do sequence(:name) { |n| "miq_ae_method#{seq_padded_for_sorting(n)}" } @@ -9,7 +9,7 @@ after :create do |aemethod, evaluator| evaluator.params.each do |name, f| - FactoryGirl.create(:miq_ae_field, + FactoryBot.create(:miq_ae_field, :name => name, :datatype => f['datatype'], :aetype => f['aetype'], diff --git a/spec/factories/miq_ae_namespace.rb b/spec/factories/miq_ae_namespace.rb index 4ae8b29cefc..72528a0f29f 100644 --- a/spec/factories/miq_ae_namespace.rb +++ b/spec/factories/miq_ae_namespace.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_ae_namespace do sequence(:name) { |n| "miq_ae_namespace_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/miq_alert.rb b/spec/factories/miq_alert.rb index e72f56e8402..53457f650b2 100644 --- a/spec/factories/miq_alert.rb +++ b/spec/factories/miq_alert.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_alert do sequence(:description) { |n| "Test Alert #{n}" } enabled true diff --git a/spec/factories/miq_alert_set.rb b/spec/factories/miq_alert_set.rb index c066cb64b91..7f7a5c56e7c 100644 --- a/spec/factories/miq_alert_set.rb +++ b/spec/factories/miq_alert_set.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_alert_set do transient { alerts nil } sequence(:name) { |n| "alert_profile_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/miq_alert_status_action.rb b/spec/factories/miq_alert_status_action.rb index 925a8709853..33932eea9e8 100644 --- a/spec/factories/miq_alert_status_action.rb +++ b/spec/factories/miq_alert_status_action.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_alert_status_action do action_type 'comment' comment 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' diff --git a/spec/factories/miq_compare.rb b/spec/factories/miq_compare.rb index c3e3621539e..d97619bba69 100644 --- a/spec/factories/miq_compare.rb +++ b/spec/factories/miq_compare.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_compare do report nil options nil diff --git a/spec/factories/miq_database.rb b/spec/factories/miq_database.rb index 315ebd07eed..31fc6828d62 100644 --- a/spec/factories/miq_database.rb +++ b/spec/factories/miq_database.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_database do session_secret_token { SecureRandom.hex(64) } csrf_secret_token { SecureRandom.hex(64) } diff --git a/spec/factories/miq_dialog.rb b/spec/factories/miq_dialog.rb index b6248b4dc3a..38ff098ce0f 100644 --- a/spec/factories/miq_dialog.rb +++ b/spec/factories/miq_dialog.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_dialog do sequence(:name) { |n| "miq_dialog_#{n}" } sequence(:description) { |n| "MiqDialog #{n}" } diff --git a/spec/factories/miq_ems_refresh_core_worker.rb b/spec/factories/miq_ems_refresh_core_worker.rb index 29ee362ab75..a282541030d 100644 --- a/spec/factories/miq_ems_refresh_core_worker.rb +++ b/spec/factories/miq_ems_refresh_core_worker.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_ems_refresh_core_worker do pid { Process.pid } end diff --git a/spec/factories/miq_enterprise.rb b/spec/factories/miq_enterprise.rb index eb4cca9f242..022562cbec3 100644 --- a/spec/factories/miq_enterprise.rb +++ b/spec/factories/miq_enterprise.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_enterprise do sequence(:name) { |n| "miq_enterprise_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/miq_event_definition.rb b/spec/factories/miq_event_definition.rb index 6c00e5cb9f3..d30e558cca4 100644 --- a/spec/factories/miq_event_definition.rb +++ b/spec/factories/miq_event_definition.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_event_definition do sequence(:name) { |num| "event_definition_#{num}" } description "Test event_definition" diff --git a/spec/factories/miq_group.rb b/spec/factories/miq_group.rb index 113837a29be..4fd729fb9d4 100644 --- a/spec/factories/miq_group.rb +++ b/spec/factories/miq_group.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do sequence(:miq_group_description) { |n| "Test Group #{seq_padded_for_sorting(n)}" } factory :miq_group do @@ -17,7 +17,7 @@ after :build do |g, e| if e.role || e.features || e.miq_user_role_id || e.miq_user_role - g.entitlement = FactoryGirl.create(:entitlement, + g.entitlement = FactoryBot.create(:entitlement, :features => e.features, :role => e.role, :miq_user_role_id => e.miq_user_role_id, diff --git a/spec/factories/miq_policy.rb b/spec/factories/miq_policy.rb index 84e8a17239a..3d43dc1c5c2 100644 --- a/spec/factories/miq_policy.rb +++ b/spec/factories/miq_policy.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_policy do sequence(:name) { |num| "policy_#{seq_padded_for_sorting(num)}" } sequence(:description) { |num| "Test Policy_#{seq_padded_for_sorting(num)}" } diff --git a/spec/factories/miq_policy_set.rb b/spec/factories/miq_policy_set.rb index 8060225456b..5e8948e1a22 100644 --- a/spec/factories/miq_policy_set.rb +++ b/spec/factories/miq_policy_set.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_policy_set do description "Test Policy Set" end diff --git a/spec/factories/miq_product_feature.rb b/spec/factories/miq_product_feature.rb index e5f0c05086a..28933eacbd9 100644 --- a/spec/factories/miq_product_feature.rb +++ b/spec/factories/miq_product_feature.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_product_feature factory :miq_product_feature_everything, :parent => :miq_product_feature do diff --git a/spec/factories/miq_queue.rb b/spec/factories/miq_queue.rb index 91ba0e07798..2fd75a2c101 100644 --- a/spec/factories/miq_queue.rb +++ b/spec/factories/miq_queue.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_queue do state 'ready' args [] diff --git a/spec/factories/miq_region.rb b/spec/factories/miq_region.rb index 2233f6593c0..fa62786ef7c 100644 --- a/spec/factories/miq_region.rb +++ b/spec/factories/miq_region.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do region_remote = MiqRegion.my_region_number factory :miq_region do diff --git a/spec/factories/miq_report.rb b/spec/factories/miq_report.rb index d5322d38843..2fcc470ca9d 100644 --- a/spec/factories/miq_report.rb +++ b/spec/factories/miq_report.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_report do sequence(:name) { |n| "Test Report #{seq_padded_for_sorting(n)}" } db 'Vm' @@ -21,7 +21,7 @@ end factory :miq_report_with_results, :parent => :miq_report do - miq_report_results { [FactoryGirl.create(:miq_report_result, :miq_group => miq_group)] } + miq_report_results { [FactoryBot.create(:miq_report_result, :miq_group => miq_group)] } end factory :miq_report_chargeback, :parent => :miq_report do @@ -35,7 +35,7 @@ end factory :miq_report_chargeback_with_results, :parent => :miq_report do - miq_report_results { [FactoryGirl.create(:miq_chargeback_report_result)] } + miq_report_results { [FactoryBot.create(:miq_chargeback_report_result)] } sequence(:name) { |n| "Test Report #{seq_padded_for_sorting(n)}" } db 'ChargebackVm' title 'some title' diff --git a/spec/factories/miq_report_result.rb b/spec/factories/miq_report_result.rb index 0afa28799ce..ec784a9fb5d 100644 --- a/spec/factories/miq_report_result.rb +++ b/spec/factories/miq_report_result.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_report_result factory :miq_chargeback_report_result, :parent => :miq_report_result do diff --git a/spec/factories/miq_request.rb b/spec/factories/miq_request.rb index b65a4f1a32c..fefb1b09d11 100644 --- a/spec/factories/miq_request.rb +++ b/spec/factories/miq_request.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_request do requester { create(:user) } @@ -26,7 +26,7 @@ end after(:create) do |request, evaluator| - request.miq_approvals << FactoryGirl.create(:miq_approval, :reason => evaluator.reason) + request.miq_approvals << FactoryBot.create(:miq_approval, :reason => evaluator.reason) end end end diff --git a/spec/factories/miq_request_task.rb b/spec/factories/miq_request_task.rb index 68746607b8d..d71a26cd844 100644 --- a/spec/factories/miq_request_task.rb +++ b/spec/factories/miq_request_task.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_request_task do status "Ok" end diff --git a/spec/factories/miq_request_workflow.rb b/spec/factories/miq_request_workflow.rb index bf17c3196cc..edad116e1ae 100644 --- a/spec/factories/miq_request_workflow.rb +++ b/spec/factories/miq_request_workflow.rb @@ -1,18 +1,18 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_request_workflow do skip_create end factory :miq_provision_workflow, :class => "MiqProvisionWorkflow", :parent => :miq_request_workflow do initialize_with do - dialog = MiqDialog.find_by(:name => FactoryGirl.attributes_for(:miq_dialog_provision)[:name]) || create(:miq_dialog_provision) + dialog = MiqDialog.find_by(:name => FactoryBot.attributes_for(:miq_dialog_provision)[:name]) || create(:miq_dialog_provision) new({:provision_dialog_name => dialog.name}, create(:user_with_group).userid) end end factory :miq_provision_configured_system_foreman_workflow, :parent => :miq_request_workflow, :class => "ManageIQ::Providers::Foreman::ConfigurationManager::ProvisionWorkflow" do initialize_with do - dialog = MiqDialog.find_by(:name => FactoryGirl.attributes_for(:miq_provision_configured_system_foreman_dialog)[:name]) || create(:miq_provision_configured_system_foreman_dialog) + dialog = MiqDialog.find_by(:name => FactoryBot.attributes_for(:miq_provision_configured_system_foreman_dialog)[:name]) || create(:miq_provision_configured_system_foreman_dialog) new({:provision_dialog_name => dialog.name}, create(:user_with_group).userid) end end diff --git a/spec/factories/miq_schedule.rb b/spec/factories/miq_schedule.rb index 829f45c219d..9a18519dbd4 100644 --- a/spec/factories/miq_schedule.rb +++ b/spec/factories/miq_schedule.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_schedule_validation, :class => :MiqSchedule do sequence(:name) { |n| "schedule_#{seq_padded_for_sorting(n)}" } description "test" diff --git a/spec/factories/miq_scsi_lun.rb b/spec/factories/miq_scsi_lun.rb index f35bc561431..f7e08497682 100644 --- a/spec/factories/miq_scsi_lun.rb +++ b/spec/factories/miq_scsi_lun.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_scsi_lun do sequence(:device_name) { |n| "miq_scsi_lun_#{n}" } sequence(:lun) { 0 } diff --git a/spec/factories/miq_scsi_target.rb b/spec/factories/miq_scsi_target.rb index f411cc3f0ea..2d0dc2cf5a4 100644 --- a/spec/factories/miq_scsi_target.rb +++ b/spec/factories/miq_scsi_target.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_scsi_target do sequence(:iscsi_name) { |n| "miq_scsi_target_#{n}" } sequence(:target) { 5 } diff --git a/spec/factories/miq_search.rb b/spec/factories/miq_search.rb index dfae5d9bd9b..99c56160365 100644 --- a/spec/factories/miq_search.rb +++ b/spec/factories/miq_search.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_search do sequence(:name) { |n| "miq_search_#{seq_padded_for_sorting(n)}" } sequence(:description) { |n| "MiqSearch #{seq_padded_for_sorting(n)}" } @@ -14,6 +14,6 @@ factory :miq_search_user, :parent => :miq_search do search_type "user" - search_key { FactoryGirl.create(:user).id } + search_key { FactoryBot.create(:user).id } end end diff --git a/spec/factories/miq_server.rb b/spec/factories/miq_server.rb index 4880d2c3423..d229cb42a35 100644 --- a/spec/factories/miq_server.rb +++ b/spec/factories/miq_server.rb @@ -1,7 +1,7 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_server do guid { SecureRandom.uuid } - zone { FactoryGirl.build(:zone) } + zone { FactoryBot.build(:zone) } sequence(:name) { |n| "miq_server_#{seq_padded_for_sorting(n)}" } last_heartbeat { Time.now.utc } status "started" diff --git a/spec/factories/miq_task.rb b/spec/factories/miq_task.rb index 6b49d5969d0..ab470c2ee68 100644 --- a/spec/factories/miq_task.rb +++ b/spec/factories/miq_task.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_task do status "Ok" state "Active" diff --git a/spec/factories/miq_user_role.rb b/spec/factories/miq_user_role.rb index 014a0b160cf..e851f1b777e 100644 --- a/spec/factories/miq_user_role.rb +++ b/spec/factories/miq_user_role.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do sequence(:miq_user_role_name) { |n| "UserRole #{seq_padded_for_sorting(n)}" } factory :miq_user_role do @@ -34,7 +34,7 @@ if f.kind_of?(MiqProductFeature) # TODO: remove class reference f else - MiqProductFeature.find_by(:identifier => f) || FactoryGirl.create(:miq_product_feature, :identifier => f) + MiqProductFeature.find_by(:identifier => f) || FactoryBot.create(:miq_product_feature, :identifier => f) end end end diff --git a/spec/factories/miq_widget.rb b/spec/factories/miq_widget.rb index 68dd129044d..f7a422b506b 100644 --- a/spec/factories/miq_widget.rb +++ b/spec/factories/miq_widget.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_widget do sequence(:title) { |n| "widget_#{seq_padded_for_sorting(n)}" } sequence(:description) { |n| "widget_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/miq_widget_set.rb b/spec/factories/miq_widget_set.rb index e7ce7e7b5d4..5d4bdaffc1f 100644 --- a/spec/factories/miq_widget_set.rb +++ b/spec/factories/miq_widget_set.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_widget_set do sequence(:name) { |n| "widget_set_#{seq_padded_for_sorting(n)}" } sequence(:description) { |n| "widget_set_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/miq_worker.rb b/spec/factories/miq_worker.rb index 4baee7deb4e..0d72fbaeb48 100644 --- a/spec/factories/miq_worker.rb +++ b/spec/factories/miq_worker.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :miq_worker do pid { rand(99999) } status "ready" diff --git a/spec/factories/network.rb b/spec/factories/network.rb index f77e3850ca3..f2465464ad7 100644 --- a/spec/factories/network.rb +++ b/spec/factories/network.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :network do sequence(:ipaddress) { |n| ip_from_seq(n) } end diff --git a/spec/factories/network_port.rb b/spec/factories/network_port.rb index 6e6f79d37fb..8e002c986a3 100644 --- a/spec/factories/network_port.rb +++ b/spec/factories/network_port.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :network_port do sequence(:name) { |n| "cloud_network_#{seq_padded_for_sorting(n)}" } sequence(:ems_ref) { |n| "ems_ref_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/network_router.rb b/spec/factories/network_router.rb index 3c84f531bac..0cb3a9a78a6 100644 --- a/spec/factories/network_router.rb +++ b/spec/factories/network_router.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :network_router do sequence(:name) { |n| "network_router_#{seq_padded_for_sorting(n)}" } sequence(:ems_ref) { |n| "ems_ref_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/notification.rb b/spec/factories/notification.rb index 648b5abfae5..d30ed155e13 100644 --- a/spec/factories/notification.rb +++ b/spec/factories/notification.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :notification do notification_type end diff --git a/spec/factories/notification_type.rb b/spec/factories/notification_type.rb index f94a5ac4aea..73e4f728526 100644 --- a/spec/factories/notification_type.rb +++ b/spec/factories/notification_type.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :notification_type do sequence(:name) { |n| "notification_type_#{seq_padded_for_sorting(n)}" } sequence(:message) { |n| "message_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/openscap_result.rb b/spec/factories/openscap_result.rb index e7f19c21851..775ee2902ab 100644 --- a/spec/factories/openscap_result.rb +++ b/spec/factories/openscap_result.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :openscap_result_skip_callback, :class => OpenscapResult do # This callback can be very annoying and handicaping in tests after(:build) { |r| r.class.skip_callback(:save, :before, :create_rule_results, :raise => false) } diff --git a/spec/factories/openscap_rule_result.rb b/spec/factories/openscap_rule_result.rb index 271e5bbace3..140b342eddb 100644 --- a/spec/factories/openscap_rule_result.rb +++ b/spec/factories/openscap_rule_result.rb @@ -1,3 +1,3 @@ -FactoryGirl.define do +FactoryBot.define do factory :openscap_rule_result end diff --git a/spec/factories/orchestration_stack.rb b/spec/factories/orchestration_stack.rb index 3c059059012..4dd5ce49ed5 100644 --- a/spec/factories/orchestration_stack.rb +++ b/spec/factories/orchestration_stack.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :orchestration_stack do ems_ref "1" end @@ -6,7 +6,7 @@ factory :orchestration_stack_cloud, :parent => :orchestration_stack, :class => "ManageIQ::Providers::CloudManager::OrchestrationStack" factory :orchestration_stack_cloud_with_template, :parent => :orchestration_stack, :class => "ManageIQ::Providers::CloudManager::OrchestrationStack" do - orchestration_template { FactoryGirl.create(:orchestration_template) } + orchestration_template { FactoryBot.create(:orchestration_template) } end factory :orchestration_stack_amazon, :parent => :orchestration_stack, :class => "ManageIQ::Providers::Amazon::CloudManager::OrchestrationStack" @@ -19,10 +19,10 @@ :parent => :orchestration_stack, :class => "ManageIQ::Providers::Openstack::InfraManager::OrchestrationStack" do after :create do |x| - x.parameters << FactoryGirl.create(:orchestration_stack_parameter_openstack_infra_compute) - x.parameters << FactoryGirl.create(:orchestration_stack_parameter_openstack_infra_controller) - x.resources << FactoryGirl.create(:orchestration_stack_resource_openstack_infra_compute) - x.resources << FactoryGirl.create(:orchestration_stack_resource_openstack_infra_compute_parent) + x.parameters << FactoryBot.create(:orchestration_stack_parameter_openstack_infra_compute) + x.parameters << FactoryBot.create(:orchestration_stack_parameter_openstack_infra_controller) + x.resources << FactoryBot.create(:orchestration_stack_resource_openstack_infra_compute) + x.resources << FactoryBot.create(:orchestration_stack_resource_openstack_infra_compute_parent) end end @@ -57,7 +57,7 @@ :parent => :orchestration_stack_resource_openstack_infra do after :create do |x| x.physical_resource = "openstack-perf-host-nova-instance" - x.stack = FactoryGirl.create(:orchestration_stack_openstack_infra_nested) + x.stack = FactoryBot.create(:orchestration_stack_openstack_infra_nested) end end diff --git a/spec/factories/orchestration_template.rb b/spec/factories/orchestration_template.rb index 0ed0236b7b5..486ad297849 100644 --- a/spec/factories/orchestration_template.rb +++ b/spec/factories/orchestration_template.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :orchestration_template do sequence(:name) { |n| "template name #{seq_padded_for_sorting(n)}" } sequence(:content) { |n| "any template text #{seq_padded_for_sorting(n)}" } @@ -6,6 +6,6 @@ end factory :orchestration_template_with_stacks, :parent => :orchestration_template do - stacks { [FactoryGirl.create(:orchestration_stack)] } + stacks { [FactoryBot.create(:orchestration_stack)] } end end diff --git a/spec/factories/persistent_volume.rb b/spec/factories/persistent_volume.rb index a8995180de4..4fe13c3c1f9 100644 --- a/spec/factories/persistent_volume.rb +++ b/spec/factories/persistent_volume.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :persistent_volume do sequence(:name) { |n| "persistent_volume_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/persistent_volume_claim.rb b/spec/factories/persistent_volume_claim.rb index af5cedc7d70..8f8a2a8ecda 100644 --- a/spec/factories/persistent_volume_claim.rb +++ b/spec/factories/persistent_volume_claim.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :persistent_volume_claim do sequence(:name) { |n| "persistent_volume_claim_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/physical_server.rb b/spec/factories/physical_server.rb index ff979a37b37..0a4085c9e04 100644 --- a/spec/factories/physical_server.rb +++ b/spec/factories/physical_server.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :physical_server do vendor "lenovo" end diff --git a/spec/factories/picture.rb b/spec/factories/picture.rb index 2541613c4c4..0674d211179 100644 --- a/spec/factories/picture.rb +++ b/spec/factories/picture.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :picture do content 'foo' extension 'png' diff --git a/spec/factories/provider.rb b/spec/factories/provider.rb index acc1139b703..c2b52758962 100644 --- a/spec/factories/provider.rb +++ b/spec/factories/provider.rb @@ -1,15 +1,15 @@ -FactoryGirl.define do +FactoryBot.define do factory :provider do sequence(:name) { |n| "provider_#{seq_padded_for_sorting(n)}" } guid { SecureRandom.uuid } - zone { FactoryGirl.create(:zone) } + zone { FactoryBot.create(:zone) } end factory :provider_foreman, :class => "ManageIQ::Providers::Foreman::Provider", :parent => :provider do url "example.com" after(:build) do |provider| - provider.authentications << FactoryGirl.build(:authentication, + provider.authentications << FactoryBot.build(:authentication, :userid => "admin", :password => "smartvm") end @@ -20,7 +20,7 @@ url "example.com" trait(:with_authentication) do after(:create) do |x| - x.authentications << FactoryGirl.create(:authentication, :status => "Valid") + x.authentications << FactoryBot.create(:authentication, :status => "Valid") end end end diff --git a/spec/factories/pxe_image.rb b/spec/factories/pxe_image.rb index 585781d1177..4ab52df8315 100644 --- a/spec/factories/pxe_image.rb +++ b/spec/factories/pxe_image.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :pxe_image, :class => 'PxeImage' do sequence(:name) { |n| "pxe_image_#{seq_padded_for_sorting(n)}" } sequence(:description) { |n| "pxe_desc_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/pxe_image_type.rb b/spec/factories/pxe_image_type.rb index 4f81d594523..6aaced17411 100644 --- a/spec/factories/pxe_image_type.rb +++ b/spec/factories/pxe_image_type.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :pxe_image_type do sequence(:name) { |n| "pxe_image_type_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/pxe_server.rb b/spec/factories/pxe_server.rb index 0ef7e1f4caf..ea067695a7a 100644 --- a/spec/factories/pxe_server.rb +++ b/spec/factories/pxe_server.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :pxe_server do sequence(:name) { |n| "pxe_server_#{seq_padded_for_sorting(n)}" } sequence(:uri) { |n| "http://test.example.com/pxe_server_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/relationship.rb b/spec/factories/relationship.rb index a1bc2b2ae4a..f4c123b0910 100644 --- a/spec/factories/relationship.rb +++ b/spec/factories/relationship.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :relationship do trait :membership do relationship 'membership' diff --git a/spec/factories/resource_action.rb b/spec/factories/resource_action.rb index d271d69abfc..3758cb1c91c 100644 --- a/spec/factories/resource_action.rb +++ b/spec/factories/resource_action.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :resource_action do trait :with_dialog do dialog diff --git a/spec/factories/resource_groups.rb b/spec/factories/resource_groups.rb index a45fc0d0fb7..69931f5f0fe 100644 --- a/spec/factories/resource_groups.rb +++ b/spec/factories/resource_groups.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :resource_group do sequence(:name) { |n| "rg_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/resource_pool.rb b/spec/factories/resource_pool.rb index ccefd557fd5..4e4105e3325 100644 --- a/spec/factories/resource_pool.rb +++ b/spec/factories/resource_pool.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :resource_pool do sequence(:name) { |n| "rp_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/rss_feed.rb b/spec/factories/rss_feed.rb index 6d535932598..dce991ce00b 100644 --- a/spec/factories/rss_feed.rb +++ b/spec/factories/rss_feed.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :rss_feed do sequence(:name) { |n| "feed_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/scan_item.rb b/spec/factories/scan_item.rb index 720b78bc844..3c0aefd6015 100644 --- a/spec/factories/scan_item.rb +++ b/spec/factories/scan_item.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :scan_item factory :scan_item_category_default, :parent => :scan_item do diff --git a/spec/factories/scan_item_set.rb b/spec/factories/scan_item_set.rb index f6d0588cf3a..72eb888a4f3 100644 --- a/spec/factories/scan_item_set.rb +++ b/spec/factories/scan_item_set.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :scan_item_set do sequence(:name) { |i| "scan_item_set#{i}" } description 'ScanItemSet description' diff --git a/spec/factories/security_group.rb b/spec/factories/security_group.rb index f90c7a8864a..80a4082787d 100644 --- a/spec/factories/security_group.rb +++ b/spec/factories/security_group.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :security_group do sequence(:name) { |n| "security_group_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/server_role.rb b/spec/factories/server_role.rb index 4a6e4fe5265..d6cdba93d95 100644 --- a/spec/factories/server_role.rb +++ b/spec/factories/server_role.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :server_role do sequence(:name) { |i| "role#{i}"} end diff --git a/spec/factories/service.rb b/spec/factories/service.rb index 496448c3ad3..6ed631c5ba8 100644 --- a/spec/factories/service.rb +++ b/spec/factories/service.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :service do sequence(:name) { |n| "service_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/service_order.rb b/spec/factories/service_order.rb index dd9ff0f3c6e..6234b6ab462 100644 --- a/spec/factories/service_order.rb +++ b/spec/factories/service_order.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory(:service_order) do name "service order" state "ordered" diff --git a/spec/factories/service_template.rb b/spec/factories/service_template.rb index 19e51fa3ff6..79d52d19401 100644 --- a/spec/factories/service_template.rb +++ b/spec/factories/service_template.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :service_template factory :service_template_orchestration, :class => 'ServiceTemplateOrchestration', :parent => :service_template factory :service_template_ansible_playbook, :class => 'ServiceTemplateAnsiblePlaybook', :parent => :service_template @@ -9,7 +9,7 @@ trait :with_provision_resource_action_and_dialog do after(:create) do |x| - x.resource_actions << FactoryGirl.create(:resource_action, :with_dialog, :action => 'Provision') + x.resource_actions << FactoryBot.create(:resource_action, :with_dialog, :action => 'Provision') end end diff --git a/spec/factories/service_template_catalog.rb b/spec/factories/service_template_catalog.rb index 7afbc12a678..8c1cfc3721e 100644 --- a/spec/factories/service_template_catalog.rb +++ b/spec/factories/service_template_catalog.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :service_template_catalog do sequence(:name) { |num| "service_template_catalog_#{num}" } end diff --git a/spec/factories/small_environment.rb b/spec/factories/small_environment.rb index 4c6d51167d0..a72d5a861dc 100644 --- a/spec/factories/small_environment.rb +++ b/spec/factories/small_environment.rb @@ -1,8 +1,8 @@ -FactoryGirl.define do +FactoryBot.define do factory :small_environment, :parent => :zone do sequence(:name) { |n| "small_environment_#{seq_padded_for_sorting(n)}" } sequence(:description) { |n| "Small Environment #{seq_padded_for_sorting(n)}" } - ext_management_systems { [FactoryGirl.create(:ems_small_environment)] } + ext_management_systems { [FactoryBot.create(:ems_small_environment)] } # Hackery: Due to ntp reload occurring on save, we need to add the servers after saving the zone. after(:create) do |z| @@ -11,7 +11,7 @@ end factory :ems_small_environment, :parent => :ems_vmware do - hosts { [FactoryGirl.create(:host_small_environment)] } + hosts { [FactoryBot.create(:host_small_environment)] } after(:create) do |x| x.hosts.each { |h| h.vms.each { |v| v.update_attribute(:ems_id, x.id) } } end @@ -19,6 +19,6 @@ factory :host_small_environment, :parent => :host_with_ref do vmm_product "Workstation" - vms { [FactoryGirl.create(:vm_with_ref, :name => "vmtest1"), FactoryGirl.create(:vm_with_ref, :name => "vmtest2")] } + vms { [FactoryBot.create(:vm_with_ref, :name => "vmtest1"), FactoryBot.create(:vm_with_ref, :name => "vmtest2")] } end end diff --git a/spec/factories/snapshot.rb b/spec/factories/snapshot.rb index 4741d3672f5..b22c3ee2c94 100644 --- a/spec/factories/snapshot.rb +++ b/spec/factories/snapshot.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :snapshot do vm_or_template { create(:vm_vmware) } create_time { 1.minute.ago } diff --git a/spec/factories/storage.rb b/spec/factories/storage.rb index 1ec5b592ca7..e54847884b3 100644 --- a/spec/factories/storage.rb +++ b/spec/factories/storage.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :storage do sequence(:name) { |n| "storage_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/storage_file.rb b/spec/factories/storage_file.rb index 0aadfde73fe..8d7b6f2622a 100644 --- a/spec/factories/storage_file.rb +++ b/spec/factories/storage_file.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :storage_file do sequence(:name) { |n| "path/to/file#{seq_padded_for_sorting(n)}/file#{n}.log" } vm_or_template_id 1000 diff --git a/spec/factories/switch.rb b/spec/factories/switch.rb index c53d4561441..2c323827b7e 100644 --- a/spec/factories/switch.rb +++ b/spec/factories/switch.rb @@ -1,3 +1,3 @@ -FactoryGirl.define do +FactoryBot.define do factory :switch_vmware, :class => 'ManageIQ::Providers::Vmware::InfraManager::HostVirtualSwitch' end diff --git a/spec/factories/system_console.rb b/spec/factories/system_console.rb index 96135fd5fd3..cebe99d9aca 100644 --- a/spec/factories/system_console.rb +++ b/spec/factories/system_console.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory(:system_console) do host_name 'manageiq.org' port '80' diff --git a/spec/factories/system_service.rb b/spec/factories/system_service.rb index b32f321a233..021c1b703de 100644 --- a/spec/factories/system_service.rb +++ b/spec/factories/system_service.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :system_service do sequence(:name) { |n| "system_service_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/tag.rb b/spec/factories/tag.rb index b0ede669c2b..37a3f3da0bb 100644 --- a/spec/factories/tag.rb +++ b/spec/factories/tag.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :tag do sequence(:name) { |n| "/namespace/cat/tag_#{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/tenant.rb b/spec/factories/tenant.rb index 45fd5d65a16..82614e6fe66 100644 --- a/spec/factories/tenant.rb +++ b/spec/factories/tenant.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :tenant do sequence(:name) { |n| "Tenant #{n}" } sequence(:subdomain) { |n| "tenant#{n}" } @@ -6,7 +6,7 @@ end factory :tenant_with_cloud_tenant, :parent => :tenant do - source { FactoryGirl.create(:cloud_tenant) } + source { FactoryBot.create(:cloud_tenant) } end factory :tenant_project, :parent => :tenant do diff --git a/spec/factories/tenant_quota.rb b/spec/factories/tenant_quota.rb index 143bbd6bbda..bcac5e052be 100644 --- a/spec/factories/tenant_quota.rb +++ b/spec/factories/tenant_quota.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :tenant_quota do factory :tenant_quota_cpu do name :cpu_allocated diff --git a/spec/factories/time_profile.rb b/spec/factories/time_profile.rb index 6f894d7e168..76f5fdd0bf3 100644 --- a/spec/factories/time_profile.rb +++ b/spec/factories/time_profile.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :time_profile do sequence(:description) { |n| "Time Profile #{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/transformation_mapping.rb b/spec/factories/transformation_mapping.rb index 1605c01a9d4..933194db310 100644 --- a/spec/factories/transformation_mapping.rb +++ b/spec/factories/transformation_mapping.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :transformation_mapping do sequence(:name) { |n| "Transformation Mapping #{seq_padded_for_sorting(n)}" } end diff --git a/spec/factories/transformation_mapping_item.rb b/spec/factories/transformation_mapping_item.rb index 75098ae6034..ced53a0d638 100644 --- a/spec/factories/transformation_mapping_item.rb +++ b/spec/factories/transformation_mapping_item.rb @@ -1,3 +1,3 @@ -FactoryGirl.define do +FactoryBot.define do factory :transformation_mapping_item end diff --git a/spec/factories/user.rb b/spec/factories/user.rb index 70748f4d821..39be0789193 100644 --- a/spec/factories/user.rb +++ b/spec/factories/user.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :user do transient do # e.g. "super_administrtor" @@ -18,7 +18,7 @@ if e.miq_groups.blank? && (e.role || e.features) u.miq_groups = [ (e.role && MiqGroup.find_by(:description => "EvmGroup-#{e.role}")) || - FactoryGirl.create(:miq_group, :features => e.features, :role => e.role, :tenant => e.tenant) + FactoryBot.create(:miq_group, :features => e.features, :role => e.role, :tenant => e.tenant) ] end end @@ -44,7 +44,7 @@ end factory :user_with_group, :parent => :user do - miq_groups { FactoryGirl.build_list(:miq_group, 1, :tenant => tenant) } + miq_groups { FactoryBot.build_list(:miq_group, 1, :tenant => tenant) } end factory :user_admin, :parent => :user do diff --git a/spec/factories/vim_performance_state.rb b/spec/factories/vim_performance_state.rb index b761faad72c..db02222af7c 100644 --- a/spec/factories/vim_performance_state.rb +++ b/spec/factories/vim_performance_state.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :vim_performance_state, :class => :VimPerformanceState do timestamp { Time.now.utc } state_data {{}} diff --git a/spec/factories/vm_or_template.rb b/spec/factories/vm_or_template.rb index 502f3c2f7e0..d9f395c5a12 100644 --- a/spec/factories/vm_or_template.rb +++ b/spec/factories/vm_or_template.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :vm_or_template do sequence(:name) { |n| "vm_#{seq_padded_for_sorting(n)}" } location "unknown" @@ -70,7 +70,7 @@ trait :with_provider do after(:create) do |x| - FactoryGirl.create(:ems_amazon, :vms => [x]) + FactoryBot.create(:ems_amazon, :vms => [x]) end end @@ -89,7 +89,7 @@ trait :with_provider do after(:create) do |x| - FactoryGirl.create(:ems_azure, :vms => [x]) + FactoryBot.create(:ems_azure, :vms => [x]) end end end @@ -99,7 +99,7 @@ trait :with_provider do after(:create) do |x| - FactoryGirl.create(:ems_google, :vms => [x]) + FactoryBot.create(:ems_google, :vms => [x]) end end end @@ -114,7 +114,7 @@ vendor "openstack" raw_power_state "ACTIVE" sequence(:ems_ref) { |n| "some-uuid-#{seq_padded_for_sorting(n)}" } - cloud_tenant { FactoryGirl.create(:cloud_tenant_openstack) } + cloud_tenant { FactoryBot.create(:cloud_tenant_openstack) } factory :vm_perf_openstack, :parent => :vm_openstack do ems_ref "openstack-perf-vm" @@ -122,7 +122,7 @@ trait :with_provider do after(:create) do |x| - FactoryGirl.create(:ems_openstack, :vms => [x]) + FactoryBot.create(:ems_openstack, :vms => [x]) end end end diff --git a/spec/factories/vm_performance.rb b/spec/factories/vm_performance.rb index 3453e2c6430..7568d85d8f2 100644 --- a/spec/factories/vm_performance.rb +++ b/spec/factories/vm_performance.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :vm_performance do timestamp { Time.now.utc } end diff --git a/spec/factories/vmdb_metric.rb b/spec/factories/vmdb_metric.rb index f96d1e13d39..a59e47b42ae 100644 --- a/spec/factories/vmdb_metric.rb +++ b/spec/factories/vmdb_metric.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :vmdb_metric factory :vmdb_metric_hourly, :parent => :vmdb_metric do diff --git a/spec/factories/vmdb_table.rb b/spec/factories/vmdb_table.rb index b852c8c61a3..787fc7f1934 100644 --- a/spec/factories/vmdb_table.rb +++ b/spec/factories/vmdb_table.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :vmdb_table factory :vmdb_table_evm, :parent => :vmdb_table, :class => "VmdbTableEvm" factory :vmdb_table_text, :parent => :vmdb_table, :class => "VmdbTableText" diff --git a/spec/factories/vmware_refresh_worker.rb b/spec/factories/vmware_refresh_worker.rb index 0327ceeb4e4..ed33abc195c 100644 --- a/spec/factories/vmware_refresh_worker.rb +++ b/spec/factories/vmware_refresh_worker.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :vmware_refresh_worker, :class => 'ManageIQ::Providers::Vmware::InfraManager::RefreshWorker' do pid { Process.pid } end diff --git a/spec/factories/windows_image.rb b/spec/factories/windows_image.rb index 9a2bb757f17..a6c6179ff8d 100644 --- a/spec/factories/windows_image.rb +++ b/spec/factories/windows_image.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :windows_image do sequence(:name) { |n| "windows_image_#{seq_padded_for_sorting(n)}" } sequence(:description) { |n| "windows_desc_#{seq_padded_for_sorting(n)}" } diff --git a/spec/factories/zone.rb b/spec/factories/zone.rb index 8a50425146f..a6bf4c81f15 100644 --- a/spec/factories/zone.rb +++ b/spec/factories/zone.rb @@ -1,4 +1,4 @@ -FactoryGirl.define do +FactoryBot.define do factory :zone do sequence(:name) { |n| "Zone #{n}" } sequence(:description) { |n| "Zone #{n}" } diff --git a/spec/lib/acts_as_ar_scope_spec.rb b/spec/lib/acts_as_ar_scope_spec.rb index e25e3aabe1b..bb77b0c6906 100644 --- a/spec/lib/acts_as_ar_scope_spec.rb +++ b/spec/lib/acts_as_ar_scope_spec.rb @@ -18,8 +18,8 @@ def self.aar_scope end it "delegates to :aar_scope" do - good = FactoryGirl.create_list(:vm, 3) - bad = FactoryGirl.create_list(:vm, 1) + good = FactoryBot.create_list(:vm, 3) + bad = FactoryBot.create_list(:vm, 1) important_vm_model.vm_ids += good.map(&:id) diff --git a/spec/lib/ansible/runner_spec.rb b/spec/lib/ansible/runner_spec.rb index ff6180c28fe..b2d9b6ed158 100644 --- a/spec/lib/ansible/runner_spec.rb +++ b/spec/lib/ansible/runner_spec.rb @@ -76,8 +76,8 @@ describe ".run_queue" do let(:playbook) { "/path/to/my/playbook" } - let(:zone) { FactoryGirl.create(:zone) } - let(:user) { FactoryGirl.create(:user) } + let(:zone) { FactoryBot.create(:zone) } + let(:user) { FactoryBot.create(:user) } it "queues Ansible::Runner.run in the right zone" do described_class.run_queue(env_vars, extra_vars, playbook, user.name, :zone => zone.name) @@ -135,8 +135,8 @@ describe ".run_role_queue" do let(:role_name) { "my-custom-role" } let(:role_path) { "/path/to/my/roles" } - let(:zone) { FactoryGirl.create(:zone) } - let(:user) { FactoryGirl.create(:user) } + let(:zone) { FactoryBot.create(:zone) } + let(:user) { FactoryBot.create(:user) } it "queues Ansible::Runner.run in the right zone" do described_class.run_role_queue(env_vars, extra_vars, role_name, user.name, {:zone => zone.name}, :roles_path => role_path) diff --git a/spec/lib/embedded_ansible/appliance_embedded_ansible_spec.rb b/spec/lib/embedded_ansible/appliance_embedded_ansible_spec.rb index 2550b49677f..52434210005 100644 --- a/spec/lib/embedded_ansible/appliance_embedded_ansible_spec.rb +++ b/spec/lib/embedded_ansible/appliance_embedded_ansible_spec.rb @@ -133,7 +133,7 @@ end before do - FactoryGirl.create(:miq_region, :region => ApplicationRecord.my_region_number) + FactoryBot.create(:miq_region, :region => ApplicationRecord.my_region_number) MiqDatabase.seed EvmSpecHelper.create_guid_miq_server_zone end diff --git a/spec/lib/embedded_ansible/container_embedded_ansible_spec.rb b/spec/lib/embedded_ansible/container_embedded_ansible_spec.rb index a667f87e154..d6bf075aa67 100644 --- a/spec/lib/embedded_ansible/container_embedded_ansible_spec.rb +++ b/spec/lib/embedded_ansible/container_embedded_ansible_spec.rb @@ -11,7 +11,7 @@ allow(Docker).to receive(:validate_version!).and_raise(RuntimeError) allow(ContainerOrchestrator).to receive(:new).and_return(orchestrator) - FactoryGirl.create(:miq_region, :region => ApplicationRecord.my_region_number) + FactoryBot.create(:miq_region, :region => ApplicationRecord.my_region_number) MiqDatabase.seed EvmSpecHelper.create_guid_miq_server_zone end diff --git a/spec/lib/embedded_ansible_spec.rb b/spec/lib/embedded_ansible_spec.rb index 7ff3916dab3..a9c9aa1192d 100644 --- a/spec/lib/embedded_ansible_spec.rb +++ b/spec/lib/embedded_ansible_spec.rb @@ -100,7 +100,7 @@ let(:miq_database) { MiqDatabase.first } before do - FactoryGirl.create(:miq_region, :region => ApplicationRecord.my_region_number) + FactoryBot.create(:miq_region, :region => ApplicationRecord.my_region_number) MiqDatabase.seed EvmSpecHelper.create_guid_miq_server_zone end diff --git a/spec/lib/ems_event_helper_spec.rb b/spec/lib/ems_event_helper_spec.rb index 9497cd9ebbb..8042e380019 100644 --- a/spec/lib/ems_event_helper_spec.rb +++ b/spec/lib/ems_event_helper_spec.rb @@ -3,18 +3,18 @@ before do [Zone, ExtManagementSystem, Host, Vm, Storage, EmsEvent, MiqEventDefinition, MiqPolicy, MiqAction, MiqPolicyContent, MiqPolicySet].each(&:delete_all) - @zone = FactoryGirl.create(:zone) - @ems = FactoryGirl.create(:ems_vmware, + @zone = FactoryBot.create(:zone) + @ems = FactoryBot.create(:ems_vmware, :zone => @zone, :name => 'vc7', :hostname => 'vc7.manageiq.com', :ipaddress => '10.10.10.2' ) - @storage = FactoryGirl.create(:storage, + @storage = FactoryBot.create(:storage, :name => 'StarM1-Demo5', :store_type => 'VMFS' ) - @host = FactoryGirl.create(:host, + @host = FactoryBot.create(:host, :name => 'host7', :ext_management_system => @ems, :vmm_vendor => 'vmware', @@ -24,7 +24,7 @@ :ipaddress => '192.168.252.28', :hostname => 'host7.manageiq.com' ) - @vm = FactoryGirl.create(:vm_vmware, + @vm = FactoryBot.create(:vm_vmware, :ext_management_system => @ems, :name => 'vm42', :location => 'vm42/vm42.vmx', @@ -34,7 +34,7 @@ @username = 'fred' @chain_id = 12345 @ems_events = [] - @ems_events << FactoryGirl.create(:ems_event, + @ems_events << FactoryBot.create(:ems_event, :event_type => 'PowerOnVM_Task', :message => 'Task: Power On virtual machine', :host_name => @host.ipaddress, @@ -50,7 +50,7 @@ :username => @username ) - @ems_events << FactoryGirl.create(:ems_event, + @ems_events << FactoryBot.create(:ems_event, :event_type => 'VmStartingEvent', :message => "#{@vm.name} on host #{@host.ipaddress} in DC1 is starting", :host_name => @host.ipaddress, @@ -66,7 +66,7 @@ :username => @username ) - @ems_events << FactoryGirl.create(:ems_event, + @ems_events << FactoryBot.create(:ems_event, :event_type => 'VmPoweredOnEvent', :message => "#{@vm.name} on #{@host.ipaddress} in DC1 is powered on", :host_name => @host.ipaddress, @@ -82,7 +82,7 @@ :username => @username ) - @ems_events << FactoryGirl.create(:ems_event, + @ems_events << FactoryBot.create(:ems_event, :event_type => 'PowerOnVM_Task_Complete', :message => 'PowerOnVM_Task Completed', :host_name => @host.ipaddress, @@ -98,15 +98,15 @@ :username => @username ) - @miq_event_vm_start = FactoryGirl.create(:miq_event_definition, :name => 'vm_start', :description => 'VM Power On') + @miq_event_vm_start = FactoryBot.create(:miq_event_definition, :name => 'vm_start', :description => 'VM Power On') - @policy_set = FactoryGirl.create(:miq_policy_set) - @policy = FactoryGirl.create(:miq_policy, :towhat => 'Vm', :active => true, :mode => 'control') + @policy_set = FactoryBot.create(:miq_policy_set) + @policy = FactoryBot.create(:miq_policy, :towhat => 'Vm', :active => true, :mode => 'control') automate_options = {:ae_message => 'create', :ae_hash => {"kevin" => "1", "q" => "1"}} - @action = FactoryGirl.create(:miq_action, :description => 'create_incident', :action_type => 'custom_automation', :options => automate_options) + @action = FactoryBot.create(:miq_action, :description => 'create_incident', :action_type => 'custom_automation', :options => automate_options) @policy_set.add_member(@policy) - @policy_content = FactoryGirl.create(:miq_policy_content, + @policy_content = FactoryBot.create(:miq_policy_content, :miq_policy => @policy, :miq_action => @action, :miq_event_definition => @miq_event_vm_start, diff --git a/spec/lib/extensions/ar_extract_objects_spec.rb b/spec/lib/extensions/ar_extract_objects_spec.rb index 57bdb69c423..fcbcf809a2e 100644 --- a/spec/lib/extensions/ar_extract_objects_spec.rb +++ b/spec/lib/extensions/ar_extract_objects_spec.rb @@ -1,7 +1,7 @@ describe "ArExtractObjects" do context "ArExtractObjectsTest" do before do - vms = (0...2).collect { FactoryGirl.create(:vm_vmware) } + vms = (0...2).collect { FactoryBot.create(:vm_vmware) } @vm1, @vm2 = *vms @id1, @id2 = vms.collect(&:id) end diff --git a/spec/lib/extensions/ar_nested_count_by_spec.rb b/spec/lib/extensions/ar_nested_count_by_spec.rb index 0518a828fb9..0a71e81ab51 100644 --- a/spec/lib/extensions/ar_nested_count_by_spec.rb +++ b/spec/lib/extensions/ar_nested_count_by_spec.rb @@ -1,21 +1,21 @@ describe "AR Nested Count By extension" do context "miq_queue with messages" do let(:zone1) { EvmSpecHelper.local_miq_server.zone } - let(:zone2) { FactoryGirl.create(:zone) } - let(:zone3) { FactoryGirl.create(:zone) } + let(:zone2) { FactoryBot.create(:zone) } + let(:zone3) { FactoryBot.create(:zone) } before do - FactoryGirl.create(:miq_queue, :zone => zone1.name, :state => MiqQueue::STATE_DEQUEUE, :role => "role1", :priority => 20) - FactoryGirl.create(:miq_queue, :zone => zone1.name, :state => MiqQueue::STATE_DEQUEUE, :role => "role1", :priority => 20) - FactoryGirl.create(:miq_queue, :zone => zone1.name, :state => MiqQueue::STATE_DEQUEUE, :role => "role2", :priority => 20) - FactoryGirl.create(:miq_queue, :zone => zone1.name, :state => MiqQueue::STATE_READY, :role => "role1", :priority => 20) - FactoryGirl.create(:miq_queue, :zone => zone1.name, :state => MiqQueue::STATE_READY, :role => "role1", :priority => 20) - FactoryGirl.create(:miq_queue, :zone => zone1.name, :state => MiqQueue::STATE_READY, :role => "role1", :priority => 20) - FactoryGirl.create(:miq_queue, :zone => zone2.name, :state => MiqQueue::STATE_DEQUEUE, :role => "role1", :priority => 20) - FactoryGirl.create(:miq_queue, :zone => zone3.name, :state => MiqQueue::STATE_READY, :role => "role3", :priority => 20) - FactoryGirl.create(:miq_queue, :zone => zone1.name, :state => MiqQueue::STATE_ERROR, :role => "role1", :priority => 20) - FactoryGirl.create(:miq_queue, :zone => zone1.name, :state => MiqQueue::STATE_WARN, :role => "role3", :priority => 20) - FactoryGirl.create(:miq_queue, :zone => zone2.name, :state => MiqQueue::STATE_DEQUEUE, :role => "role1", :priority => 20) - FactoryGirl.create(:miq_queue, :zone => zone3.name, :state => MiqQueue::STATE_ERROR, :role => "role2", :priority => 20) + FactoryBot.create(:miq_queue, :zone => zone1.name, :state => MiqQueue::STATE_DEQUEUE, :role => "role1", :priority => 20) + FactoryBot.create(:miq_queue, :zone => zone1.name, :state => MiqQueue::STATE_DEQUEUE, :role => "role1", :priority => 20) + FactoryBot.create(:miq_queue, :zone => zone1.name, :state => MiqQueue::STATE_DEQUEUE, :role => "role2", :priority => 20) + FactoryBot.create(:miq_queue, :zone => zone1.name, :state => MiqQueue::STATE_READY, :role => "role1", :priority => 20) + FactoryBot.create(:miq_queue, :zone => zone1.name, :state => MiqQueue::STATE_READY, :role => "role1", :priority => 20) + FactoryBot.create(:miq_queue, :zone => zone1.name, :state => MiqQueue::STATE_READY, :role => "role1", :priority => 20) + FactoryBot.create(:miq_queue, :zone => zone2.name, :state => MiqQueue::STATE_DEQUEUE, :role => "role1", :priority => 20) + FactoryBot.create(:miq_queue, :zone => zone3.name, :state => MiqQueue::STATE_READY, :role => "role3", :priority => 20) + FactoryBot.create(:miq_queue, :zone => zone1.name, :state => MiqQueue::STATE_ERROR, :role => "role1", :priority => 20) + FactoryBot.create(:miq_queue, :zone => zone1.name, :state => MiqQueue::STATE_WARN, :role => "role3", :priority => 20) + FactoryBot.create(:miq_queue, :zone => zone2.name, :state => MiqQueue::STATE_DEQUEUE, :role => "role1", :priority => 20) + FactoryBot.create(:miq_queue, :zone => zone3.name, :state => MiqQueue::STATE_ERROR, :role => "role2", :priority => 20) end it "should count by state, zone and role" do diff --git a/spec/lib/extensions/ar_number_of_spec.rb b/spec/lib/extensions/ar_number_of_spec.rb index c607fec771c..735fb9cb79a 100644 --- a/spec/lib/extensions/ar_number_of_spec.rb +++ b/spec/lib/extensions/ar_number_of_spec.rb @@ -1,7 +1,7 @@ describe "#number_of" do it "caches the results" do - h = FactoryGirl.create(:host) - FactoryGirl.create_list(:vm, 2, :host => h) + h = FactoryBot.create(:host) + FactoryBot.create_list(:vm, 2, :host => h) expect(h).to receive(:vms).once.and_call_original @@ -10,16 +10,16 @@ end it "doesn't load a whole relation" do - h = FactoryGirl.create(:host) - FactoryGirl.create_list(:vm, 2, :host => h) + h = FactoryBot.create(:host) + FactoryBot.create_list(:vm, 2, :host => h) expect(h.number_of(:vms)).to eq(2) expect(h.vms).not_to be_loaded end it "uses the relation if it is available" do - h = FactoryGirl.create(:host) - FactoryGirl.create_list(:vm, 2, :host => h) + h = FactoryBot.create(:host) + FactoryBot.create_list(:vm, 2, :host => h) h.vms.load expect do diff --git a/spec/lib/extensions/ar_region_spec.rb b/spec/lib/extensions/ar_region_spec.rb index 4535f6ccb87..4e70f5cc59c 100644 --- a/spec/lib/extensions/ar_region_spec.rb +++ b/spec/lib/extensions/ar_region_spec.rb @@ -10,7 +10,7 @@ context "#miq_region" do before { MiqRegion.seed } - let!(:vm) { FactoryGirl.create(:vm) } + let!(:vm) { FactoryBot.create(:vm) } it "returns the MiqRegion record" do expect(vm.miq_region).to eq(MiqRegion.first) @@ -27,12 +27,12 @@ context "#region_description" do it "when the region exists" do MiqRegion.seed - vm = FactoryGirl.create(:vm) + vm = FactoryBot.create(:vm) expect(vm.region_description).to eq(MiqRegion.first.description) end it "when the region does not exist" do - vm = FactoryGirl.create(:vm) + vm = FactoryBot.create(:vm) expect(vm.region_description).to be_nil end end diff --git a/spec/lib/extensions/ar_taggable_spec.rb b/spec/lib/extensions/ar_taggable_spec.rb index 2b8663afe7c..d00aae615aa 100644 --- a/spec/lib/extensions/ar_taggable_spec.rb +++ b/spec/lib/extensions/ar_taggable_spec.rb @@ -1,14 +1,14 @@ describe ActsAsTaggable do before do - @host1 = FactoryGirl.create(:host, :name => "HOST1") + @host1 = FactoryBot.create(:host, :name => "HOST1") @host1.tag_with("red blue yellow", :ns => "/test", :cat => "tags") - @host2 = FactoryGirl.create(:host, :name => "HOST2") - @host3 = FactoryGirl.create(:host, :name => "HOST3") + @host2 = FactoryBot.create(:host, :name => "HOST2") + @host3 = FactoryBot.create(:host, :name => "HOST3") - @vm1 = FactoryGirl.create(:vm_vmware, :name => "VM1") - @vm2 = FactoryGirl.create(:vm_vmware, :name => "VM2") - @vm3 = FactoryGirl.create(:vm_vmware, :name => "VM3") - @vm4 = FactoryGirl.create(:vm_vmware, :name => "VM4") + @vm1 = FactoryBot.create(:vm_vmware, :name => "VM1") + @vm2 = FactoryBot.create(:vm_vmware, :name => "VM2") + @vm3 = FactoryBot.create(:vm_vmware, :name => "VM3") + @vm4 = FactoryBot.create(:vm_vmware, :name => "VM4") @vm1.tag_with("red blue yellow", :ns => "/test", :cat => "tags") @vm3.tag_with("Red Blue Yellow", :ns => "/Test", :cat => "MixedCase") @@ -17,8 +17,8 @@ end describe '#writable_classification_tags' do - let(:parent_classification) { FactoryGirl.create(:classification, :description => "Environment", :name => "environment", :read_only => false) } - let(:classification) { FactoryGirl.create(:classification, :name => "prod", :description => "Production", :parent => parent_classification, :read_only => true) } + let(:parent_classification) { FactoryBot.create(:classification, :description => "Environment", :name => "environment", :read_only => false) } + let(:classification) { FactoryBot.create(:classification, :name => "prod", :description => "Production", :parent => parent_classification, :read_only => true) } before do classification.assign_entry_to(@vm1) @@ -53,7 +53,7 @@ end it "STI classes" do - vm_template = FactoryGirl.create(:template_vmware, :name => "template", :host => @host) + vm_template = FactoryBot.create(:template_vmware, :name => "template", :host => @host) vm_template.tag_with("red blue yellow", :ns => "/test", :cat => "tags") expect(Vm.find_tagged_with(:all => 'red', :ns => '/test/tags')).to eq([@vm1]) @@ -161,8 +161,8 @@ end it "with virtual reflections" do - lan = FactoryGirl.create(:lan, :name => "VM NFS Network") - vm = FactoryGirl.create(:vm_vmware, :hardware => FactoryGirl.create(:hardware, :guest_devices => [FactoryGirl.create(:guest_device_nic, :lan => lan)])) + lan = FactoryBot.create(:lan, :name => "VM NFS Network") + vm = FactoryBot.create(:vm_vmware, :hardware => FactoryBot.create(:hardware, :guest_devices => [FactoryBot.create(:guest_device_nic, :lan => lan)])) expect(vm).to be_is_tagged_with("/virtual/lans/name/VM NFS Network", :ns => "*") end end diff --git a/spec/lib/extensions/ar_virtual_spec.rb b/spec/lib/extensions/ar_virtual_spec.rb index 26cda687985..d03e82fe4ac 100644 --- a/spec/lib/extensions/ar_virtual_spec.rb +++ b/spec/lib/extensions/ar_virtual_spec.rb @@ -779,7 +779,7 @@ def col2 end it "supports #includes with #references" do - vm = FactoryGirl.create :vm_vmware + vm = FactoryBot.create :vm_vmware table = Vm.arel_table dash = Arel::Nodes::SqlLiteral.new("'-'") name_dash_id = Arel::Nodes::NamedFunction.new("CONCAT", [table[:name], dash, table[:id]]) @@ -940,12 +940,12 @@ def col2 context "preloading" do before do - FactoryGirl.create(:vm_vmware, - :hardware => FactoryGirl.create(:hardware), - :operating_system => FactoryGirl.create(:operating_system), - :host => FactoryGirl.create(:host, - :hardware => FactoryGirl.create(:hardware), - :operating_system => FactoryGirl.create(:operating_system) + FactoryBot.create(:vm_vmware, + :hardware => FactoryBot.create(:hardware), + :operating_system => FactoryBot.create(:operating_system), + :host => FactoryBot.create(:host, + :hardware => FactoryBot.create(:hardware), + :operating_system => FactoryBot.create(:operating_system) ) ) end @@ -999,7 +999,7 @@ def col2 describe "ActiveRecord attributes" do it "doesn't botch up the attributes" do - hardware = Hardware.select(:id, :model).find(FactoryGirl.create(:hardware).id) + hardware = Hardware.select(:id, :model).find(FactoryBot.create(:hardware).id) expect(hardware.attributes.size).to eq(2) hardware.save expect(hardware.attributes.size).to eq(2) diff --git a/spec/lib/extensions/virtual_total_spec.rb b/spec/lib/extensions/virtual_total_spec.rb index 88f9ac5a43e..323388a906a 100644 --- a/spec/lib/extensions/virtual_total_spec.rb +++ b/spec/lib/extensions/virtual_total_spec.rb @@ -333,8 +333,8 @@ class VtAuthor < VitualTotalTestBase end def model_with_children(count) - FactoryGirl.create(:ext_management_system).tap do |ems| - FactoryGirl.create_list(:vm, count, :ext_management_system => ems) if count > 0 + FactoryBot.create(:ext_management_system).tap do |ems| + FactoryBot.create_list(:vm, count, :ext_management_system => ems) if count > 0 end end end @@ -353,9 +353,9 @@ def model_with_children(count) end def model_with_children(count) - FactoryGirl.create(:resource_pool).tap do |pool| + FactoryBot.create(:resource_pool).tap do |pool| count.times do |_i| - vm = FactoryGirl.create(:vm) + vm = FactoryBot.create(:vm) vm.with_relationship_type("ems_metadata") { vm.set_parent pool } end end @@ -375,9 +375,9 @@ def model_with_children(count) end def model_with_children(count) - FactoryGirl.create(:ext_management_system).tap do |ems| - ems.hosts.create(FactoryGirl.attributes_for(:host)).tap do |host| - count.times { host.storages.create(FactoryGirl.attributes_for(:storage)) } + FactoryBot.create(:ext_management_system).tap do |ems| + ems.hosts.create(FactoryBot.attributes_for(:host)).tap do |host| + count.times { host.storages.create(FactoryBot.attributes_for(:storage)) } end end.reload end @@ -410,7 +410,7 @@ def model_with_children(count) end def model_with_children(count) - FactoryGirl.create(:vm_vmware, :hardware => FactoryGirl.create(:hardware)).tap do |vm| + FactoryBot.create(:vm_vmware, :hardware => FactoryBot.create(:hardware)).tap do |vm| count.times { vm.hardware.disks.create(:size => 10.0) } end.reload end diff --git a/spec/lib/miq_cockpit_spec.rb b/spec/lib/miq_cockpit_spec.rb index 6aa42a2b9f4..2dbedd4dd95 100644 --- a/spec/lib/miq_cockpit_spec.rb +++ b/spec/lib/miq_cockpit_spec.rb @@ -1,6 +1,6 @@ describe MiqCockpit::WS do before do - @server = FactoryGirl.create(:miq_server, :hostname => "hostname") + @server = FactoryBot.create(:miq_server, :hostname => "hostname") @miq_server = EvmSpecHelper.local_miq_server @miq_server.ipaddress = "10.0.0.1" @miq_server.has_active_userinterface = true @@ -125,7 +125,7 @@ context "when using a active region" do it "it uses the full domain for the url" do MiqRegion.seed - server = FactoryGirl.create(:miq_server, :hostname => "hostname") + server = FactoryBot.create(:miq_server, :hostname => "hostname") expect(MiqRegion.my_region).to receive(:remote_ui_miq_server).once.and_return(server) ins = MiqCockpit::WS.new(nil) diff --git a/spec/lib/miq_expression_spec.rb b/spec/lib/miq_expression_spec.rb index 1a0cde3f527..4e6f89473a8 100644 --- a/spec/lib/miq_expression_spec.rb +++ b/spec/lib/miq_expression_spec.rb @@ -1,7 +1,7 @@ describe MiqExpression do describe '#reporting_available_fields' do - let(:vm) { FactoryGirl.create(:vm) } - let!(:custom_attribute) { FactoryGirl.create(:custom_attribute, :name => 'my_attribute_1', :resource => vm) } + let(:vm) { FactoryBot.create(:vm) } + let!(:custom_attribute) { FactoryBot.create(:custom_attribute, :name => 'my_attribute_1', :resource => vm) } let(:extra_fields) do %w(start_date end_date @@ -29,9 +29,9 @@ context 'with ChargebackVm' do context 'with dynamic fields' do - let(:volume_1) { FactoryGirl.create(:cloud_volume, :volume_type => 'TYPE1') } - let(:volume_2) { FactoryGirl.create(:cloud_volume, :volume_type => 'TYPE2') } - let(:volume_3) { FactoryGirl.create(:cloud_volume, :volume_type => 'TYPE3') } + let(:volume_1) { FactoryBot.create(:cloud_volume, :volume_type => 'TYPE1') } + let(:volume_2) { FactoryBot.create(:cloud_volume, :volume_type => 'TYPE2') } + let(:volume_3) { FactoryBot.create(:cloud_volume, :volume_type => 'TYPE3') } let(:model) { "ChargebackVm" } let(:volume_1_type_field_cost) { "#{model}-storage_allocated_#{volume_1.volume_type}_cost" } let(:volume_2_type_field_cost) { "#{model}-storage_allocated_#{volume_2.volume_type}_cost" } @@ -464,8 +464,8 @@ end it "generates the SQL for a CONTAINS expression with tag" do - tag = FactoryGirl.create(:tag, :name => "/managed/operations/analysis_failed") - vm = FactoryGirl.create(:vm_vmware, :tags => [tag]) + tag = FactoryBot.create(:tag, :name => "/managed/operations/analysis_failed") + vm = FactoryBot.create(:vm_vmware, :tags => [tag]) exp = {"CONTAINS" => {"tag" => "VmInfra.managed-operations", "value" => "analysis_failed"}} sql, * = MiqExpression.new(exp).to_sql expect(sql).to eq("\"vms\".\"id\" IN (#{vm.id})") @@ -659,18 +659,18 @@ describe "integration" do context "date/time support" do it "finds the correct instances for an gt expression with a dynamic integer field" do - _vm1 = FactoryGirl.create(:vm_vmware, :memory_reserve => 1, :cpu_reserve => 2) - vm2 = FactoryGirl.create(:vm_vmware, :memory_reserve => 2, :cpu_reserve => 1) + _vm1 = FactoryBot.create(:vm_vmware, :memory_reserve => 1, :cpu_reserve => 2) + vm2 = FactoryBot.create(:vm_vmware, :memory_reserve => 2, :cpu_reserve => 1) filter = MiqExpression.new(">" => {"field" => "Vm-memory_reserve", "value" => "Vm-cpu_reserve"}) result = Vm.where(filter.to_sql.first) expect(result).to eq([vm2]) end it "finds the correct instances for an gt expression with a custom attribute dynamic integer field" do - custom_attribute = FactoryGirl.create(:custom_attribute, :name => "example", :value => 10) - vm1 = FactoryGirl.create(:vm, :memory_reserve => 2) + custom_attribute = FactoryBot.create(:custom_attribute, :name => "example", :value => 10) + vm1 = FactoryBot.create(:vm, :memory_reserve => 2) vm1.custom_attributes << custom_attribute - _vm2 = FactoryGirl.create(:vm, :memory_reserve => 0) + _vm2 = FactoryBot.create(:vm, :memory_reserve => 0) name_of_attribute = "VmOrTemplate-#{CustomAttributeMixin::CUSTOM_ATTRIBUTES_PREFIX}example" filter = MiqExpression.new("<" => {"field" => "VmOrTemplate-memory_reserve", "value" => name_of_attribute}) result = Rbac.search(:targets => Vm, :filter => filter).first.first @@ -679,89 +679,89 @@ end it "finds the correct instances for an AFTER expression with a datetime field" do - _vm1 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-11 9:00") - vm2 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-11 9:00:00.000001") + _vm1 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-11 9:00") + vm2 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-11 9:00:00.000001") filter = MiqExpression.new("AFTER" => {"field" => "Vm-last_scan_on", "value" => "2011-01-11 9:00"}) result = Vm.where(filter.to_sql.first) expect(result).to eq([vm2]) end it "finds the correct instances for an IS EMPTY expression with a datetime field" do - _vm1 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-11 9:01") - vm2 = FactoryGirl.create(:vm_vmware, :last_scan_on => nil) + _vm1 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-11 9:01") + vm2 = FactoryBot.create(:vm_vmware, :last_scan_on => nil) filter = MiqExpression.new("IS EMPTY" => {"field" => "Vm-last_scan_on"}) result = Vm.where(filter.to_sql.first) expect(result).to eq([vm2]) end it "finds the correct instances for an IS EMPTY expression with a date field" do - _vm1 = FactoryGirl.create(:vm_vmware, :retires_on => "2011-01-11") - vm2 = FactoryGirl.create(:vm_vmware, :retires_on => nil) + _vm1 = FactoryBot.create(:vm_vmware, :retires_on => "2011-01-11") + vm2 = FactoryBot.create(:vm_vmware, :retires_on => nil) filter = MiqExpression.new("IS EMPTY" => {"field" => "Vm-retires_on"}) result = Vm.where(filter.to_sql.first) expect(result).to eq([vm2]) end it "finds the correct instances for an IS NOT EMPTY expression with a datetime field" do - vm1 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-11 9:01") - _vm2 = FactoryGirl.create(:vm_vmware, :last_scan_on => nil) + vm1 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-11 9:01") + _vm2 = FactoryBot.create(:vm_vmware, :last_scan_on => nil) filter = MiqExpression.new("IS NOT EMPTY" => {"field" => "Vm-last_scan_on"}) result = Vm.where(filter.to_sql.first) expect(result).to eq([vm1]) end it "finds the correct instances for an IS NOT EMPTY expression with a date field" do - vm1 = FactoryGirl.create(:vm_vmware, :retires_on => "2011-01-11") - _vm2 = FactoryGirl.create(:vm_vmware, :retires_on => nil) + vm1 = FactoryBot.create(:vm_vmware, :retires_on => "2011-01-11") + _vm2 = FactoryBot.create(:vm_vmware, :retires_on => nil) filter = MiqExpression.new("IS NOT EMPTY" => {"field" => "Vm-retires_on"}) result = Vm.where(filter.to_sql.first) expect(result).to eq([vm1]) end it "finds the correct instances for an IS expression with a date field" do - _vm1 = FactoryGirl.create(:vm_vmware, :retires_on => "2011-01-09") - vm2 = FactoryGirl.create(:vm_vmware, :retires_on => "2011-01-10") - _vm3 = FactoryGirl.create(:vm_vmware, :retires_on => "2011-01-11") + _vm1 = FactoryBot.create(:vm_vmware, :retires_on => "2011-01-09") + vm2 = FactoryBot.create(:vm_vmware, :retires_on => "2011-01-10") + _vm3 = FactoryBot.create(:vm_vmware, :retires_on => "2011-01-11") filter = MiqExpression.new("IS" => {"field" => "Vm-retires_on", "value" => "2011-01-10"}) result = Vm.where(filter.to_sql.first) expect(result).to eq([vm2]) end it "finds the correct instances for an IS expression with a datetime field" do - _vm1 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-10 23:59:59.999999") - vm2 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-11 0:00") - vm3 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-11 23:59:59.999999") - _vm4 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-12 0:00") + _vm1 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-10 23:59:59.999999") + vm2 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-11 0:00") + vm3 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-11 23:59:59.999999") + _vm4 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-12 0:00") filter = MiqExpression.new("IS" => {"field" => "Vm-last_scan_on", "value" => "2011-01-11"}) result = Vm.where(filter.to_sql.first) expect(result).to contain_exactly(vm2, vm3) end it "finds the correct instances for a FROM expression with a datetime field, given date values" do - _vm1 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2010-07-10 23:59:59.999999") - vm2 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2010-07-11 00:00:00") - vm3 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2010-12-31 23:59:59.999999") - _vm4 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-01 00:00:00") + _vm1 = FactoryBot.create(:vm_vmware, :last_scan_on => "2010-07-10 23:59:59.999999") + vm2 = FactoryBot.create(:vm_vmware, :last_scan_on => "2010-07-11 00:00:00") + vm3 = FactoryBot.create(:vm_vmware, :last_scan_on => "2010-12-31 23:59:59.999999") + _vm4 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-01 00:00:00") filter = MiqExpression.new("FROM" => {"field" => "Vm-last_scan_on", "value" => ["2010-07-11", "2010-12-31"]}) result = Vm.where(filter.to_sql.first) expect(result).to contain_exactly(vm2, vm3) end it "finds the correct instances for a FROM expression with a date field" do - _vm1 = FactoryGirl.create(:vm_vmware, :retires_on => "2010-07-10") - vm2 = FactoryGirl.create(:vm_vmware, :retires_on => "2010-07-11") - vm3 = FactoryGirl.create(:vm_vmware, :retires_on => "2010-12-31") - _vm4 = FactoryGirl.create(:vm_vmware, :retires_on => "2011-01-01") + _vm1 = FactoryBot.create(:vm_vmware, :retires_on => "2010-07-10") + vm2 = FactoryBot.create(:vm_vmware, :retires_on => "2010-07-11") + vm3 = FactoryBot.create(:vm_vmware, :retires_on => "2010-12-31") + _vm4 = FactoryBot.create(:vm_vmware, :retires_on => "2011-01-01") filter = MiqExpression.new("FROM" => {"field" => "Vm-retires_on", "value" => ["2010-07-11", "2010-12-31"]}) result = Vm.where(filter.to_sql.first) expect(result).to contain_exactly(vm2, vm3) end it "finds the correct instances for a FROM expression with a datetime field, given datetimes" do - _vm1 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-09 16:59:59.999999") - vm2 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-09 17:30:00") - vm3 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-10 23:30:59") - _vm4 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-10 23:31:00") + _vm1 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-09 16:59:59.999999") + vm2 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-09 17:30:00") + vm3 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-10 23:30:59") + _vm4 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-10 23:31:00") filter = MiqExpression.new("FROM" => {"field" => "Vm-last_scan_on", "value" => ["2011-01-09 17:00", "2011-01-10 23:30:59"]}) result = Vm.where(filter.to_sql.first) @@ -773,79 +773,79 @@ around { |example| Timecop.freeze("2011-01-11 17:30 UTC") { example.run } } it "finds the correct instances for an IS expression with 'Today'" do - _vm1 = FactoryGirl.create(:vm_vmware, :last_scan_on => Time.zone.yesterday.end_of_day) - vm2 = FactoryGirl.create(:vm_vmware, :last_scan_on => Time.zone.today) - _vm3 = FactoryGirl.create(:vm_vmware, :last_scan_on => Time.zone.tomorrow.beginning_of_day) + _vm1 = FactoryBot.create(:vm_vmware, :last_scan_on => Time.zone.yesterday.end_of_day) + vm2 = FactoryBot.create(:vm_vmware, :last_scan_on => Time.zone.today) + _vm3 = FactoryBot.create(:vm_vmware, :last_scan_on => Time.zone.tomorrow.beginning_of_day) filter = MiqExpression.new("IS" => {"field" => "Vm-last_scan_on", "value" => "Today"}) result = Vm.where(filter.to_sql.first) expect(result).to eq([vm2]) end it "finds the correct instances for an IS expression with a datetime field and 'n Hours Ago'" do - _vm1 = FactoryGirl.create(:vm_vmware, :last_scan_on => Time.zone.parse("13:59:59.999999")) - vm2 = FactoryGirl.create(:vm_vmware, :last_scan_on => Time.zone.parse("14:00:00")) - vm3 = FactoryGirl.create(:vm_vmware, :last_scan_on => Time.zone.parse("14:59:59.999999")) - _vm4 = FactoryGirl.create(:vm_vmware, :last_scan_on => Time.zone.parse("15:00:00")) + _vm1 = FactoryBot.create(:vm_vmware, :last_scan_on => Time.zone.parse("13:59:59.999999")) + vm2 = FactoryBot.create(:vm_vmware, :last_scan_on => Time.zone.parse("14:00:00")) + vm3 = FactoryBot.create(:vm_vmware, :last_scan_on => Time.zone.parse("14:59:59.999999")) + _vm4 = FactoryBot.create(:vm_vmware, :last_scan_on => Time.zone.parse("15:00:00")) filter = MiqExpression.new("IS" => {"field" => "Vm-last_scan_on", "value" => "3 Hours Ago"}) result = Vm.where(filter.to_sql.first) expect(result).to contain_exactly(vm2, vm3) end it "finds the correct instances for an IS expression with 'Last Month'" do - _vm1 = FactoryGirl.create(:vm_vmware, :last_scan_on => (1.month.ago.beginning_of_month - 1.day).end_of_day) - vm2 = FactoryGirl.create(:vm_vmware, :last_scan_on => 1.month.ago.beginning_of_month) - vm3 = FactoryGirl.create(:vm_vmware, :last_scan_on => 1.month.ago.end_of_month) - _vm4 = FactoryGirl.create(:vm_vmware, :last_scan_on => (1.month.ago.end_of_month + 1.day).beginning_of_day) + _vm1 = FactoryBot.create(:vm_vmware, :last_scan_on => (1.month.ago.beginning_of_month - 1.day).end_of_day) + vm2 = FactoryBot.create(:vm_vmware, :last_scan_on => 1.month.ago.beginning_of_month) + vm3 = FactoryBot.create(:vm_vmware, :last_scan_on => 1.month.ago.end_of_month) + _vm4 = FactoryBot.create(:vm_vmware, :last_scan_on => (1.month.ago.end_of_month + 1.day).beginning_of_day) filter = MiqExpression.new("IS" => {"field" => "Vm-last_scan_on", "value" => "Last Month"}) result = Vm.where(filter.to_sql.first) expect(result).to contain_exactly(vm2, vm3) end it "finds the correct instances for a FROM expression with a date field and 'Last Week'" do - _vm1 = FactoryGirl.create(:vm_vmware, :retires_on => 1.week.ago.beginning_of_week - 1.day) - vm2 = FactoryGirl.create(:vm_vmware, :retires_on => 1.week.ago.beginning_of_week) - vm3 = FactoryGirl.create(:vm_vmware, :retires_on => 1.week.ago.end_of_week) - _vm4 = FactoryGirl.create(:vm_vmware, :retires_on => 1.week.ago.end_of_week + 1.day) + _vm1 = FactoryBot.create(:vm_vmware, :retires_on => 1.week.ago.beginning_of_week - 1.day) + vm2 = FactoryBot.create(:vm_vmware, :retires_on => 1.week.ago.beginning_of_week) + vm3 = FactoryBot.create(:vm_vmware, :retires_on => 1.week.ago.end_of_week) + _vm4 = FactoryBot.create(:vm_vmware, :retires_on => 1.week.ago.end_of_week + 1.day) filter = MiqExpression.new("FROM" => {"field" => "Vm-retires_on", "value" => ["Last Week", "Last Week"]}) result = Vm.where(filter.to_sql.first) expect(result).to contain_exactly(vm2, vm3) end it "finds the correct instances for a FROM expression with a datetime field and 'Last Week'" do - _vm1 = FactoryGirl.create(:vm_vmware, :last_scan_on => 1.week.ago.beginning_of_week - 1.second) - vm2 = FactoryGirl.create(:vm_vmware, :last_scan_on => 1.week.ago.beginning_of_week.beginning_of_day) - vm3 = FactoryGirl.create(:vm_vmware, :last_scan_on => 1.week.ago.end_of_week.end_of_day) - _vm4 = FactoryGirl.create(:vm_vmware, :last_scan_on => 1.week.ago.end_of_week + 1.second) + _vm1 = FactoryBot.create(:vm_vmware, :last_scan_on => 1.week.ago.beginning_of_week - 1.second) + vm2 = FactoryBot.create(:vm_vmware, :last_scan_on => 1.week.ago.beginning_of_week.beginning_of_day) + vm3 = FactoryBot.create(:vm_vmware, :last_scan_on => 1.week.ago.end_of_week.end_of_day) + _vm4 = FactoryBot.create(:vm_vmware, :last_scan_on => 1.week.ago.end_of_week + 1.second) filter = MiqExpression.new("FROM" => {"field" => "Vm-last_scan_on", "value" => ["Last Week", "Last Week"]}) result = Vm.where(filter.to_sql.first) expect(result).to contain_exactly(vm2, vm3) end it "finds the correct instances for a FROM expression with 'Last Week' and 'This Week'" do - _vm1 = FactoryGirl.create(:vm_vmware, :last_scan_on => 1.week.ago.beginning_of_week - 1.second) - vm2 = FactoryGirl.create(:vm_vmware, :last_scan_on => 1.week.ago.beginning_of_week.beginning_of_day) - vm3 = FactoryGirl.create(:vm_vmware, :last_scan_on => 1.week.from_now.beginning_of_week - 1.second) - _vm4 = FactoryGirl.create(:vm_vmware, :last_scan_on => 1.week.from_now.beginning_of_week.beginning_of_day) + _vm1 = FactoryBot.create(:vm_vmware, :last_scan_on => 1.week.ago.beginning_of_week - 1.second) + vm2 = FactoryBot.create(:vm_vmware, :last_scan_on => 1.week.ago.beginning_of_week.beginning_of_day) + vm3 = FactoryBot.create(:vm_vmware, :last_scan_on => 1.week.from_now.beginning_of_week - 1.second) + _vm4 = FactoryBot.create(:vm_vmware, :last_scan_on => 1.week.from_now.beginning_of_week.beginning_of_day) filter = MiqExpression.new("FROM" => {"field" => "Vm-last_scan_on", "value" => ["Last Week", "This Week"]}) result = Vm.where(filter.to_sql.first) expect(result).to contain_exactly(vm2, vm3) end it "finds the correct instances for a FROM expression with 'n Months Ago'" do - _vm1 = FactoryGirl.create(:vm_vmware, :last_scan_on => 2.months.ago.beginning_of_month - 1.second) - vm2 = FactoryGirl.create(:vm_vmware, :last_scan_on => 2.months.ago.beginning_of_month.beginning_of_day) - vm3 = FactoryGirl.create(:vm_vmware, :last_scan_on => 1.month.ago.end_of_month.end_of_day) - _vm4 = FactoryGirl.create(:vm_vmware, :last_scan_on => 1.month.ago.end_of_month + 1.second) + _vm1 = FactoryBot.create(:vm_vmware, :last_scan_on => 2.months.ago.beginning_of_month - 1.second) + vm2 = FactoryBot.create(:vm_vmware, :last_scan_on => 2.months.ago.beginning_of_month.beginning_of_day) + vm3 = FactoryBot.create(:vm_vmware, :last_scan_on => 1.month.ago.end_of_month.end_of_day) + _vm4 = FactoryBot.create(:vm_vmware, :last_scan_on => 1.month.ago.end_of_month + 1.second) filter = MiqExpression.new("FROM" => {"field" => "Vm-last_scan_on", "value" => ["2 Months Ago", "1 Month Ago"]}) result = Vm.where(filter.to_sql.first) expect(result).to contain_exactly(vm2, vm3) end it "finds the correct instances for a FROM expression with 'Last Month'" do - _vm1 = FactoryGirl.create(:vm_vmware, :last_scan_on => 1.month.ago.beginning_of_month - 1.second) - vm2 = FactoryGirl.create(:vm_vmware, :last_scan_on => 1.month.ago.beginning_of_month.beginning_of_day) - vm3 = FactoryGirl.create(:vm_vmware, :last_scan_on => 1.month.ago.end_of_month.end_of_day) - _vm4 = FactoryGirl.create(:vm_vmware, :last_scan_on => 1.month.ago.end_of_month + 1.second) + _vm1 = FactoryBot.create(:vm_vmware, :last_scan_on => 1.month.ago.beginning_of_month - 1.second) + vm2 = FactoryBot.create(:vm_vmware, :last_scan_on => 1.month.ago.beginning_of_month.beginning_of_day) + vm3 = FactoryBot.create(:vm_vmware, :last_scan_on => 1.month.ago.end_of_month.end_of_day) + _vm4 = FactoryBot.create(:vm_vmware, :last_scan_on => 1.month.ago.end_of_month + 1.second) filter = MiqExpression.new("FROM" => {"field" => "Vm-last_scan_on", "value" => ["Last Month", "Last Month"]}) result = Vm.where(filter.to_sql.first) expect(result).to contain_exactly(vm2, vm3) @@ -855,10 +855,10 @@ context "timezone support" do it "finds the correct instances for a FROM expression with a datetime field and timezone" do timezone = "Eastern Time (US & Canada)" - _vm1 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-09 21:59:59.999999") - vm2 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-09 22:00:00") - vm3 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-11 04:30:59") - _vm4 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-11 04:31:00") + _vm1 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-09 21:59:59.999999") + vm2 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-09 22:00:00") + vm3 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-11 04:30:59") + _vm4 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-11 04:31:00") filter = MiqExpression.new("FROM" => {"field" => "Vm-last_scan_on", "value" => ["2011-01-09 17:00", "2011-01-10 23:30:59"]}) result = Vm.where(filter.to_sql(timezone).first) @@ -867,9 +867,9 @@ it "finds the correct instances for a FROM expression with a date field and timezone" do timezone = "Eastern Time (US & Canada)" - _vm1 = FactoryGirl.create(:vm_vmware, :retires_on => "2011-01-09T23:59:59Z") - vm2 = FactoryGirl.create(:vm_vmware, :retires_on => "2011-01-10T06:30:00Z") - _vm3 = FactoryGirl.create(:vm_vmware, :retires_on => "2011-01-11T08:00:00Z") + _vm1 = FactoryBot.create(:vm_vmware, :retires_on => "2011-01-09T23:59:59Z") + vm2 = FactoryBot.create(:vm_vmware, :retires_on => "2011-01-10T06:30:00Z") + _vm3 = FactoryBot.create(:vm_vmware, :retires_on => "2011-01-11T08:00:00Z") filter = MiqExpression.new("IS" => {"field" => "Vm-retires_on", "value" => "2011-01-10"}) result = Vm.where(filter.to_sql(timezone).first) expect(result).to eq([vm2]) @@ -877,10 +877,10 @@ it "finds the correct instances for an IS expression with timezone" do timezone = "Eastern Time (US & Canada)" - _vm1 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-11 04:59:59.999999") - vm2 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-11 05:00:00") - vm3 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-12 04:59:59.999999") - _vm4 = FactoryGirl.create(:vm_vmware, :last_scan_on => "2011-01-12 05:00:00") + _vm1 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-11 04:59:59.999999") + vm2 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-11 05:00:00") + vm3 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-12 04:59:59.999999") + _vm4 = FactoryBot.create(:vm_vmware, :last_scan_on => "2011-01-12 05:00:00") filter = MiqExpression.new("IS" => {"field" => "Vm-last_scan_on", "value" => "2011-01-11"}) result = Vm.where(filter.to_sql(timezone).first) expect(result).to contain_exactly(vm2, vm3) @@ -892,15 +892,15 @@ describe "#lenient_evaluate" do describe "integration" do it "with a find/checkany expression" do - host1, host2, host3, host4, host5, host6, host7, host8 = FactoryGirl.create_list(:host, 8) - FactoryGirl.create(:vm_vmware, :host => host1, :description => "foo", :last_scan_on => "2011-01-08 16:59:59.999999") - FactoryGirl.create(:vm_vmware, :host => host2, :description => nil, :last_scan_on => "2011-01-08 16:59:59.999999") - FactoryGirl.create(:vm_vmware, :host => host3, :description => "bar", :last_scan_on => "2011-01-08 17:00:00") - FactoryGirl.create(:vm_vmware, :host => host4, :description => nil, :last_scan_on => "2011-01-08 17:00:00") - FactoryGirl.create(:vm_vmware, :host => host5, :description => "baz", :last_scan_on => "2011-01-09 23:30:59.999999") - FactoryGirl.create(:vm_vmware, :host => host6, :description => nil, :last_scan_on => "2011-01-09 23:30:59.999999") - FactoryGirl.create(:vm_vmware, :host => host7, :description => "qux", :last_scan_on => "2011-01-09 23:31:00") - FactoryGirl.create(:vm_vmware, :host => host8, :description => nil, :last_scan_on => "2011-01-09 23:31:00") + host1, host2, host3, host4, host5, host6, host7, host8 = FactoryBot.create_list(:host, 8) + FactoryBot.create(:vm_vmware, :host => host1, :description => "foo", :last_scan_on => "2011-01-08 16:59:59.999999") + FactoryBot.create(:vm_vmware, :host => host2, :description => nil, :last_scan_on => "2011-01-08 16:59:59.999999") + FactoryBot.create(:vm_vmware, :host => host3, :description => "bar", :last_scan_on => "2011-01-08 17:00:00") + FactoryBot.create(:vm_vmware, :host => host4, :description => nil, :last_scan_on => "2011-01-08 17:00:00") + FactoryBot.create(:vm_vmware, :host => host5, :description => "baz", :last_scan_on => "2011-01-09 23:30:59.999999") + FactoryBot.create(:vm_vmware, :host => host6, :description => nil, :last_scan_on => "2011-01-09 23:30:59.999999") + FactoryBot.create(:vm_vmware, :host => host7, :description => "qux", :last_scan_on => "2011-01-09 23:31:00") + FactoryBot.create(:vm_vmware, :host => host8, :description => nil, :last_scan_on => "2011-01-09 23:31:00") filter = MiqExpression.new( "FIND" => { "checkany" => {"FROM" => {"field" => "Host.vms-last_scan_on", @@ -911,20 +911,20 @@ end it "with a find/checkall expression" do - host1, host2, host3, host4, host5 = FactoryGirl.create_list(:host, 5) + host1, host2, host3, host4, host5 = FactoryBot.create_list(:host, 5) - FactoryGirl.create(:vm_vmware, :host => host1, :description => "foo", :last_scan_on => "2011-01-08 16:59:59.999999") + FactoryBot.create(:vm_vmware, :host => host1, :description => "foo", :last_scan_on => "2011-01-08 16:59:59.999999") - FactoryGirl.create(:vm_vmware, :host => host2, :description => "bar", :last_scan_on => "2011-01-08 17:00:00") - FactoryGirl.create(:vm_vmware, :host => host2, :description => "baz", :last_scan_on => "2011-01-09 23:30:59.999999") + FactoryBot.create(:vm_vmware, :host => host2, :description => "bar", :last_scan_on => "2011-01-08 17:00:00") + FactoryBot.create(:vm_vmware, :host => host2, :description => "baz", :last_scan_on => "2011-01-09 23:30:59.999999") - FactoryGirl.create(:vm_vmware, :host => host3, :description => "qux", :last_scan_on => "2011-01-08 17:00:00") - FactoryGirl.create(:vm_vmware, :host => host3, :description => nil, :last_scan_on => "2011-01-09 23:30:59.999999") + FactoryBot.create(:vm_vmware, :host => host3, :description => "qux", :last_scan_on => "2011-01-08 17:00:00") + FactoryBot.create(:vm_vmware, :host => host3, :description => nil, :last_scan_on => "2011-01-09 23:30:59.999999") - FactoryGirl.create(:vm_vmware, :host => host4, :description => nil, :last_scan_on => "2011-01-08 17:00:00") - FactoryGirl.create(:vm_vmware, :host => host4, :description => "quux", :last_scan_on => "2011-01-09 23:30:59.999999") + FactoryBot.create(:vm_vmware, :host => host4, :description => nil, :last_scan_on => "2011-01-08 17:00:00") + FactoryBot.create(:vm_vmware, :host => host4, :description => "quux", :last_scan_on => "2011-01-09 23:30:59.999999") - FactoryGirl.create(:vm_vmware, :host => host5, :description => "corge", :last_scan_on => "2011-01-09 23:31:00") + FactoryBot.create(:vm_vmware, :host => host5, :description => "corge", :last_scan_on => "2011-01-09 23:31:00") filter = MiqExpression.new( "FIND" => { @@ -937,7 +937,7 @@ end it "cannot execute non-attribute methods on target objects" do - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) expect do described_class.new("=" => {"field" => "Vm-destroy", "value" => true}).lenient_evaluate(vm) @@ -2181,8 +2181,8 @@ # tags contain the root tenant's name Tenant.seed - category = FactoryGirl.create(:classification, :name => 'environment', :description => 'Environment') - FactoryGirl.create(:classification, :parent_id => category.id, :name => 'prod', :description => 'Production') + category = FactoryBot.create(:classification, :name => 'environment', :description => 'Environment') + FactoryBot.create(:classification, :parent_id => category.id, :name => 'prod', :description => 'Production') tags = MiqExpression.model_details('Host', :typ => 'tag', :include_model => true, @@ -2194,23 +2194,23 @@ context "._custom_details_for" do let(:klass) { Vm } - let(:vm) { FactoryGirl.create(:vm) } - let!(:custom_attr1) { FactoryGirl.create(:custom_attribute, :resource => vm, :name => "CATTR_1", :value => "Value 1") } - let!(:custom_attr2) { FactoryGirl.create(:custom_attribute, :resource => vm, :name => nil, :value => "Value 2") } + let(:vm) { FactoryBot.create(:vm) } + let!(:custom_attr1) { FactoryBot.create(:custom_attribute, :resource => vm, :name => "CATTR_1", :value => "Value 1") } + let!(:custom_attr2) { FactoryBot.create(:custom_attribute, :resource => vm, :name => nil, :value => "Value 2") } it "ignores custom_attibutes with a nil name" do expect(MiqExpression._custom_details_for("Vm", {})).to eq([["Custom Attribute: CATTR_1", "Vm-virtual_custom_attribute_CATTR_1"]]) end - let(:conatiner_image) { FactoryGirl.create(:container_image) } + let(:conatiner_image) { FactoryBot.create(:container_image) } let!(:custom_attribute_with_section_1) do - FactoryGirl.create(:custom_attribute, :resource => conatiner_image, :name => 'CATTR_3', :value => "Value 3", + FactoryBot.create(:custom_attribute, :resource => conatiner_image, :name => 'CATTR_3', :value => "Value 3", :section => 'section_3') end let!(:custom_attribute_with_section_2) do - FactoryGirl.create(:custom_attribute, :resource => conatiner_image, :name => 'CATTR_3', :value => "Value 3", + FactoryBot.create(:custom_attribute, :resource => conatiner_image, :name => 'CATTR_3', :value => "Value 3", :section => 'docker_labels') end @@ -2269,8 +2269,8 @@ # tags contain the root tenant's name Tenant.seed - category = FactoryGirl.create(:classification, :name => 'environment', :description => 'Environment') - FactoryGirl.create(:classification, :parent_id => category.id, :name => 'prod', :description => 'Production') + category = FactoryBot.create(:classification, :name => 'environment', :description => 'Environment') + FactoryBot.create(:classification, :parent_id => category.id, :name => 'prod', :description => 'Production') end it "generates a human readable string for a TAG expression" do @@ -2473,13 +2473,13 @@ describe ".get_col_type" do subject { described_class.get_col_type(@field) } let(:string_custom_attribute) do - FactoryGirl.create(:custom_attribute, + FactoryBot.create(:custom_attribute, :name => "foo", :value => "string", :resource_type => 'ExtManagementSystem') end let(:date_custom_attribute) do - FactoryGirl.create(:custom_attribute, + FactoryBot.create(:custom_attribute, :name => "foo", :value => DateTime.current, :resource_type => 'ExtManagementSystem') @@ -2548,7 +2548,7 @@ # tags contain the root tenant's name Tenant.seed - cat = FactoryGirl.create(:classification, + cat = FactoryBot.create(:classification, :description => "Auto Approve - Max CPU", :name => "prov_max_cpu", :single_value => true, @@ -3205,7 +3205,7 @@ it "adds mapping 'result'=>false to expression if expression evaluates to false on supplied object" do expression = {">=" => {"field" => "Vm-num_cpu", "value" => "2"}} - result = described_class.evaluate_atoms(expression, FactoryGirl.build(:vm)) + result = described_class.evaluate_atoms(expression, FactoryBot.build(:vm)) expect(result).to include( ">=" => {"field" => "Vm-num_cpu", "value" => "2"}, @@ -3370,11 +3370,11 @@ it "returns the tags when no path is given" do Tenant.seed - FactoryGirl.create( + FactoryBot.create( :classification, :name => "env", :description => "Environment", - :children => [FactoryGirl.create(:classification)] + :children => [FactoryBot.create(:classification)] ) actual = described_class.tag_details(nil, {}) expect(actual).to eq([["My Company Tags : Environment", "managed-env"]]) @@ -3382,17 +3382,17 @@ it "returns the added classification when no_cache option is used" do Tenant.seed - FactoryGirl.create(:classification, + FactoryBot.create(:classification, :name => "first_classification", :description => "First Classification", - :children => [FactoryGirl.create(:classification)]) + :children => [FactoryBot.create(:classification)]) actual = described_class.tag_details(nil, {}) expect(actual).to eq([["My Company Tags : First Classification", "managed-first_classification"]]) - FactoryGirl.create(:classification, + FactoryBot.create(:classification, :name => "second_classification", :description => "Second Classification", - :children => [FactoryGirl.create(:classification)]) + :children => [FactoryBot.create(:classification)]) actual = described_class.tag_details(nil, :no_cache => true) expect(actual).to eq([["My Company Tags : First Classification", "managed-first_classification"], ["My Company Tags : Second Classification", "managed-second_classification"]]) end diff --git a/spec/lib/miq_preloader_spec.rb b/spec/lib/miq_preloader_spec.rb index a17c5673a61..35fa3018b0d 100644 --- a/spec/lib/miq_preloader_spec.rb +++ b/spec/lib/miq_preloader_spec.rb @@ -1,7 +1,7 @@ describe MiqPreloader do describe ".preload" do it "preloads once from an object" do - ems = FactoryGirl.create(:ems_infra) + ems = FactoryBot.create(:ems_infra) expect(ems.vms).not_to be_loaded expect { preload(ems, :vms) }.to match_query_limit_of(1) expect(ems.vms).to be_loaded @@ -9,14 +9,14 @@ end it "preloads from an array" do - emses = FactoryGirl.create_list(:ems_infra, 2) + emses = FactoryBot.create_list(:ems_infra, 2) expect { preload(emses, :vms) }.to match_query_limit_of(1) expect(emses[0].vms).to be_loaded end it "preloads from an association" do - ems = FactoryGirl.create(:ems_infra) - FactoryGirl.create_list(:vm, 2, :ext_management_system => ems) + ems = FactoryBot.create(:ems_infra) + FactoryBot.create_list(:vm, 2, :ext_management_system => ems) emses = ExtManagementSystem.all expect { preload(emses, :vms) }.to match_query_limit_of(2) @@ -29,8 +29,8 @@ def preload(*args) describe ".preload_and_map" do it "preloads from an object" do - ems = FactoryGirl.create(:ems_infra) - FactoryGirl.create_list(:vm, 2, :ext_management_system => ems) + ems = FactoryBot.create(:ems_infra) + FactoryBot.create_list(:vm, 2, :ext_management_system => ems) vms = nil expect { vms = preload_and_map(ems, :vms) }.to match_query_limit_of(1) @@ -38,8 +38,8 @@ def preload(*args) end it "preloads from an association" do - ems = FactoryGirl.create(:ems_infra) - FactoryGirl.create_list(:vm, 2, :ext_management_system => ems) + ems = FactoryBot.create(:ems_infra) + FactoryBot.create_list(:vm, 2, :ext_management_system => ems) emses = ExtManagementSystem.all expect { preload_and_map(emses, :vms) }.to match_query_limit_of(2) @@ -52,8 +52,8 @@ def preload_and_map(*args) describe ".preload_and_scope" do it "preloads (object).has_many" do - ems = FactoryGirl.create(:ems_infra) - FactoryGirl.create_list(:vm, 2, :ext_management_system => ems) + ems = FactoryBot.create(:ems_infra) + FactoryBot.create_list(:vm, 2, :ext_management_system => ems) vms = nil expect { vms = preload_and_scope(ems, :vms) }.to match_query_limit_of(0) @@ -61,8 +61,8 @@ def preload_and_map(*args) end it "preloads (object.all).has_many" do - FactoryGirl.create_list(:vm, 2, :ext_management_system => FactoryGirl.create(:ems_infra)) - FactoryGirl.create(:template, :ext_management_system => FactoryGirl.create(:ems_infra)) + FactoryBot.create_list(:vm, 2, :ext_management_system => FactoryBot.create(:ems_infra)) + FactoryBot.create(:template, :ext_management_system => FactoryBot.create(:ems_infra)) vms = nil expect { vms = preload_and_scope(ExtManagementSystem.all, :vms_and_templates) }.to match_query_limit_of(0) @@ -70,19 +70,19 @@ def preload_and_map(*args) end it "respects scopes (object.all).has_many {with scope}" do - FactoryGirl.create_list(:vm, 2, :ext_management_system => FactoryGirl.create(:ems_infra)) - FactoryGirl.create(:template, :ext_management_system => FactoryGirl.create(:ems_infra)) + FactoryBot.create_list(:vm, 2, :ext_management_system => FactoryBot.create(:ems_infra)) + FactoryBot.create(:template, :ext_management_system => FactoryBot.create(:ems_infra)) expect { expect(preload_and_scope(ExtManagementSystem.all, :vms).count).to eq(2) }.to match_query_limit_of(1) end it "preloads (object.all).has_many.belongs_to" do - ems = FactoryGirl.create(:ems_infra) - FactoryGirl.create_list(:vm, 2, + ems = FactoryBot.create(:ems_infra) + FactoryBot.create_list(:vm, 2, :ext_management_system => ems, - :host => FactoryGirl.create(:host, :ext_management_system => ems)) - FactoryGirl.create(:vm, :ext_management_system => ems, - :host => FactoryGirl.create(:host, :ext_management_system => ems)) + :host => FactoryBot.create(:host, :ext_management_system => ems)) + FactoryBot.create(:vm, :ext_management_system => ems, + :host => FactoryBot.create(:host, :ext_management_system => ems)) hosts = nil vms = nil @@ -92,13 +92,13 @@ def preload_and_map(*args) end it "preloads (object.all).belongs_to.has_many" do - ems = FactoryGirl.create(:ems_infra) - host = FactoryGirl.create(:host, :ext_management_system => ems) - FactoryGirl.create_list(:vm, 2, + ems = FactoryBot.create(:ems_infra) + host = FactoryBot.create(:host, :ext_management_system => ems) + FactoryBot.create_list(:vm, 2, :ext_management_system => ems, :host => host) - host = FactoryGirl.create(:host, :ext_management_system => ems) - FactoryGirl.create(:vm, :ext_management_system => ems, + host = FactoryBot.create(:host, :ext_management_system => ems) + FactoryBot.create(:vm, :ext_management_system => ems, :host => host) emses = nil diff --git a/spec/lib/rbac/filterer_spec.rb b/spec/lib/rbac/filterer_spec.rb index 69bbf4bd134..115e191a209 100644 --- a/spec/lib/rbac/filterer_spec.rb +++ b/spec/lib/rbac/filterer_spec.rb @@ -8,8 +8,8 @@ ] ) group = create_group_with_expression(filter) - user = FactoryGirl.create(:user, :miq_groups => [group]) - vm1, vm2, _vm3 = FactoryGirl.create_list(:vm_vmware, 3) + user = FactoryBot.create(:user, :miq_groups => [group]) + vm1, vm2, _vm3 = FactoryBot.create_list(:vm_vmware, 3) vm1.tag_with("/managed/environment/prod", :ns => "*") vm2.tag_with("/managed/location/ny", :ns => "*") @@ -27,8 +27,8 @@ ] ) group = create_group_with_expression(filter) - user = FactoryGirl.create(:user, :miq_groups => [group]) - vm1, vm2, vm3 = FactoryGirl.create_list(:vm_vmware, 3) + user = FactoryBot.create(:user, :miq_groups => [group]) + vm1, vm2, vm3 = FactoryBot.create_list(:vm_vmware, 3) vm1.tag_with("/managed/environment/prod /managed/environment/test", :ns => "*") vm2.tag_with("/managed/environment/prod", :ns => "*") vm3.tag_with("/managed/environment/test", :ns => "*") @@ -47,8 +47,8 @@ ] ) group = create_group_with_expression(filter) - user = FactoryGirl.create(:user, :miq_groups => [group]) - request = FactoryGirl.create(:miq_provision_request, :tenant => owner_tenant, :requester => user) + user = FactoryBot.create(:user, :miq_groups => [group]) + request = FactoryBot.create(:miq_provision_request, :tenant => owner_tenant, :requester => user) actual, = Rbac::Filterer.search(:targets => MiqProvisionRequest, :user => user) @@ -58,8 +58,8 @@ end def create_group_with_expression(expression) - role = FactoryGirl.create(:miq_user_role) - group = FactoryGirl.create(:miq_group, :tenant => Tenant.root_tenant, :miq_user_role => role) + role = FactoryBot.create(:miq_user_role) + group = FactoryBot.create(:miq_group, :tenant => Tenant.root_tenant, :miq_user_role => role) group.entitlement = Entitlement.new group.entitlement.filter_expression = expression group.save! @@ -126,38 +126,38 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt let(:default_tenant) { Tenant.seed } - let(:admin_user) { FactoryGirl.create(:user, :role => "super_administrator") } + let(:admin_user) { FactoryBot.create(:user, :role => "super_administrator") } - let(:owner_tenant) { FactoryGirl.create(:tenant) } - let(:owner_group) { FactoryGirl.create(:miq_group, :tenant => owner_tenant) } - let(:owner_user) { FactoryGirl.create(:user, :miq_groups => [owner_group]) } - let(:owned_vm) { FactoryGirl.create(:vm_vmware, :tenant => owner_tenant) } + let(:owner_tenant) { FactoryBot.create(:tenant) } + let(:owner_group) { FactoryBot.create(:miq_group, :tenant => owner_tenant) } + let(:owner_user) { FactoryBot.create(:user, :miq_groups => [owner_group]) } + let(:owned_vm) { FactoryBot.create(:vm_vmware, :tenant => owner_tenant) } - let(:other_tenant) { FactoryGirl.create(:tenant) } - let(:other_group) { FactoryGirl.create(:miq_group, :tenant => other_tenant) } - let(:other_user) { FactoryGirl.create(:user, :miq_groups => [other_group]) } - let(:other_vm) { FactoryGirl.create(:vm_vmware, :tenant => other_tenant) } + let(:other_tenant) { FactoryBot.create(:tenant) } + let(:other_group) { FactoryBot.create(:miq_group, :tenant => other_tenant) } + let(:other_user) { FactoryBot.create(:user, :miq_groups => [other_group]) } + let(:other_vm) { FactoryBot.create(:vm_vmware, :tenant => other_tenant) } - let(:child_tenant) { FactoryGirl.create(:tenant, :divisible => false, :parent => owner_tenant) } - let(:child_group) { FactoryGirl.create(:miq_group, :tenant => child_tenant) } - let(:child_user) { FactoryGirl.create(:user, :miq_groups => [child_group]) } - let(:child_openstack_vm) { FactoryGirl.create(:vm_openstack, :tenant => child_tenant, :miq_group => child_group) } + let(:child_tenant) { FactoryBot.create(:tenant, :divisible => false, :parent => owner_tenant) } + let(:child_group) { FactoryBot.create(:miq_group, :tenant => child_tenant) } + let(:child_user) { FactoryBot.create(:user, :miq_groups => [child_group]) } + let(:child_openstack_vm) { FactoryBot.create(:vm_openstack, :tenant => child_tenant, :miq_group => child_group) } describe ".search" do context 'for MiqRequests' do # MiqRequest for owner group - let!(:miq_request_user_owner) { FactoryGirl.create(:miq_provision_request, :tenant => owner_tenant, :requester => owner_user) } + let!(:miq_request_user_owner) { FactoryBot.create(:miq_provision_request, :tenant => owner_tenant, :requester => owner_user) } # User for owner group - let(:user_a) { FactoryGirl.create(:user, :miq_groups => [owner_group]) } + let(:user_a) { FactoryBot.create(:user, :miq_groups => [owner_group]) } # MiqRequests for other group - let!(:miq_request_user_a) { FactoryGirl.create(:miq_provision_request, :tenant => owner_tenant, :requester => other_user) } - let!(:miq_request_user_b) { FactoryGirl.create(:miq_provision_request, :tenant => owner_tenant, :requester => user_b) } + let!(:miq_request_user_a) { FactoryBot.create(:miq_provision_request, :tenant => owner_tenant, :requester => other_user) } + let!(:miq_request_user_b) { FactoryBot.create(:miq_provision_request, :tenant => owner_tenant, :requester => user_b) } # other_group is from owner_tenant - let(:other_group) { FactoryGirl.create(:miq_group, :tenant => owner_tenant) } + let(:other_group) { FactoryBot.create(:miq_group, :tenant => owner_tenant) } # User for other group - let(:user_b) { FactoryGirl.create(:user, :miq_groups => [other_group]) } + let(:user_b) { FactoryBot.create(:user, :miq_groups => [other_group]) } context "self service user (User or group owned)" do before do @@ -201,9 +201,9 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt end context 'with tags' do - let(:role) { FactoryGirl.create(:miq_user_role) } - let(:tagged_group) { FactoryGirl.create(:miq_group, :tenant => Tenant.root_tenant, :miq_user_role => role) } - let(:user) { FactoryGirl.create(:user, :miq_groups => [tagged_group]) } + let(:role) { FactoryBot.create(:miq_user_role) } + let(:tagged_group) { FactoryBot.create(:miq_group, :tenant => Tenant.root_tenant, :miq_user_role => role) } + let(:user) { FactoryBot.create(:user, :miq_groups => [tagged_group]) } before do tagged_group.entitlement = Entitlement.new @@ -213,7 +213,7 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt end context 'searching for instances of Switches' do - let!(:switch) { FactoryGirl.create_list(:switch, 2).first } + let!(:switch) { FactoryBot.create_list(:switch, 2).first } before do switch.tag_with('/managed/environment/prod', :ns => '*') @@ -231,7 +231,7 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt end context 'searching for instances of ConfigurationScriptSource' do - let!(:configuration_script_source) { FactoryGirl.create_list(:embedded_ansible_configuration_script_source, 2).first } + let!(:configuration_script_source) { FactoryBot.create_list(:embedded_ansible_configuration_script_source, 2).first } it 'lists only tagged ConfigurationScriptSources' do configuration_script_source.tag_with('/managed/environment/prod', :ns => '*') @@ -246,7 +246,7 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt embedded_automation_manager_authentication ManageIQ::Providers::EmbeddedAutomationManager::Authentication ).slice(2) do |factory, klass| context "searching for instances of #{klass}" do - let!(:automation_manager_authentication) { FactoryGirl.create(factory) } + let!(:automation_manager_authentication) { FactoryBot.create(factory) } automation_manager_authentication.tag_with('/managed/environment/prod', :ns => '*') results = described_class.search(:class => automation_manager_authentication.class.name, :user => user).first @@ -255,8 +255,8 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt end it "tag entitled playbook with no tagged authentications" do - auth = FactoryGirl.create(:automation_manager_authentication) - playbook = FactoryGirl.create(:ansible_playbook, :authentications => [auth]) + auth = FactoryBot.create(:automation_manager_authentication) + playbook = FactoryBot.create(:ansible_playbook, :authentications => [auth]) playbook.tag_with('/managed/environment/prod', :ns => '*') results = described_class.search(:class => playbook.class, :user => user).first @@ -267,8 +267,8 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt end it "tag entitled ansible authentications without a playbook for it" do - auth = FactoryGirl.create(:automation_manager_authentication) - playbook = FactoryGirl.create(:ansible_playbook, :authentications => [auth]) + auth = FactoryBot.create(:automation_manager_authentication) + playbook = FactoryBot.create(:ansible_playbook, :authentications => [auth]) auth.tag_with('/managed/environment/prod', :ns => '*') results = described_class.search(:class => playbook.class, :user => user).first @@ -279,7 +279,7 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt end context 'searching for instances of AuthKeyPair' do - let!(:auth_key_pair_cloud) { FactoryGirl.create_list(:auth_key_pair_cloud, 2).first } + let!(:auth_key_pair_cloud) { FactoryBot.create_list(:auth_key_pair_cloud, 2).first } it 'lists only tagged AuthKeyPairs' do auth_key_pair_cloud.tag_with('/managed/environment/prod', :ns => '*') @@ -290,7 +290,7 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt end context 'searching for instances of HostAggregate' do - let!(:host_aggregate) { FactoryGirl.create_list(:host_aggregate, 2).first } + let!(:host_aggregate) { FactoryBot.create_list(:host_aggregate, 2).first } it 'lists only tagged HostAggregates' do host_aggregate.tag_with('/managed/environment/prod', :ns => '*') @@ -315,15 +315,15 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt context 'with virtual custom attributes' do let(:virtual_custom_attribute_1) { "virtual_custom_attribute_attribute_1" } let(:virtual_custom_attribute_2) { "virtual_custom_attribute_attribute_2" } - let!(:vm_1) { FactoryGirl.create(:vm) } - let!(:vm_2) { FactoryGirl.create(:vm) } + let!(:vm_1) { FactoryBot.create(:vm) } + let!(:vm_2) { FactoryBot.create(:vm) } let!(:custom_attribute_1) do - FactoryGirl.create(:custom_attribute, :name => 'attribute_1', :value => vm_1.name, :resource => vm_1) + FactoryBot.create(:custom_attribute, :name => 'attribute_1', :value => vm_1.name, :resource => vm_1) end let!(:custom_attribute_2) do - FactoryGirl.create(:custom_attribute, :name => 'attribute_2', :value => 'any_value', :resource => vm_1) + FactoryBot.create(:custom_attribute, :name => 'attribute_2', :value => 'any_value', :resource => vm_1) end let(:miq_expression) do @@ -354,8 +354,8 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt "Vm" => :vm_vmware }.each do |klass, factory_name| it "with :user finds #{klass}" do - owned_resource = FactoryGirl.create(factory_name, :tenant => owner_tenant) - _other_resource = FactoryGirl.create(factory_name, :tenant => other_tenant) + owned_resource = FactoryBot.create(factory_name, :tenant => owner_tenant) + _other_resource = FactoryBot.create(factory_name, :tenant => other_tenant) results = described_class.filtered(klass, :user => owner_user) expect(results).to match_array [owned_resource] end @@ -364,12 +364,12 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt context 'when class does not participate in RBAC' do before do - @vm = FactoryGirl.create(:vm_vmware, :name => "VM1", :host => @host1, :ext_management_system => @ems) + @vm = FactoryBot.create(:vm_vmware, :name => "VM1", :host => @host1, :ext_management_system => @ems) ["2010-04-14T20:52:30Z", "2010-04-14T21:51:10Z"].each do |t| - @vm.metric_rollups << FactoryGirl.create(:metric_rollup_vm_hr, :timestamp => t) + @vm.metric_rollups << FactoryBot.create(:metric_rollup_vm_hr, :timestamp => t) end end - let(:miq_ae_domain) { FactoryGirl.create(:miq_ae_domain) } + let(:miq_ae_domain) { FactoryBot.create(:miq_ae_domain) } it 'returns the same class as input for MiqAeDomain' do User.with_user(admin_user) do @@ -520,7 +520,7 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt let(:search_attributes) { { :class => "Service", :extra_cols => extra_cols } } let(:results) { described_class.search(search_attributes).first } - before { FactoryGirl.create :service, :evm_owner => owner_user } + before { FactoryBot.create :service, :evm_owner => owner_user } it "finds the Service" do expect(results.first.attributes["owned_by_current_user"]).to be false @@ -596,7 +596,7 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt end it "can see descendant tenant's Vms" do - child_vm = FactoryGirl.create(:vm_vmware, :tenant => child_tenant) + child_vm = FactoryBot.create(:vm_vmware, :tenant => child_tenant) results = described_class.search(:class => "Vm", :miq_group => owner_group).first expect(results).to match_array [owned_vm, child_vm] @@ -626,13 +626,13 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt context "with accessible_tenant_ids filtering (strategy = :parent_ids)" do it "can see parent tenant's EMS" do - ems = FactoryGirl.create(:ems_vmware, :tenant => owner_tenant) + ems = FactoryBot.create(:ems_vmware, :tenant => owner_tenant) results = described_class.search(:class => "ExtManagementSystem", :miq_group => child_group).first expect(results).to match_array [ems] end it "can't see descendant tenant's EMS" do - _ems = FactoryGirl.create(:ems_vmware, :tenant => child_tenant) + _ems = FactoryBot.create(:ems_vmware, :tenant => child_tenant) results = described_class.search(:class => "ExtManagementSystem", :miq_group => owner_group).first expect(results).to match_array [] end @@ -640,19 +640,19 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt context "with accessible_tenant_ids filtering (strategy = nil aka tenant only)" do it "can see tenant's request task" do - task = FactoryGirl.create(:miq_request_task, :tenant => owner_tenant) + task = FactoryBot.create(:miq_request_task, :tenant => owner_tenant) results = described_class.search(:class => "MiqRequestTask", :miq_group => owner_group).first expect(results).to match_array [task] end it "can't see parent tenant's request task" do - _task = FactoryGirl.create(:miq_request_task, :tenant => owner_tenant) + _task = FactoryBot.create(:miq_request_task, :tenant => owner_tenant) results = described_class.search(:class => "MiqRequestTask", :miq_group => child_group).first expect(results).to match_array [] end it "can't see descendant tenant's request task" do - _task = FactoryGirl.create(:miq_request_task, :tenant => child_tenant) + _task = FactoryBot.create(:miq_request_task, :tenant => child_tenant) results = described_class.search(:class => "MiqRequestTask", :miq_group => owner_group).first expect(results).to match_array [] end @@ -660,7 +660,7 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt context "with accessible_tenant_ids filtering (strategy = :descendants_id) through" do it "can see their own request in the same tenant" do - request = FactoryGirl.create(:miq_provision_request, :tenant => owner_tenant, :requester => owner_user) + request = FactoryBot.create(:miq_provision_request, :tenant => owner_tenant, :requester => owner_user) results = described_class.search(:class => "MiqRequest", :user => owner_user).first expect(results).to match_array [request] end @@ -671,42 +671,42 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt child_group.entitlement.set_belongsto_filters([]) child_group.save! - request = FactoryGirl.create(:miq_provision_request, :tenant => child_tenant, :requester => child_user) + request = FactoryBot.create(:miq_provision_request, :tenant => child_tenant, :requester => child_user) results = described_class.search(:class => "MiqRequest", :user => child_user).first expect(results).to match_array [request] end it "can see other's request in the same tenant" do - group = FactoryGirl.create(:miq_group, :tenant => owner_tenant) - user = FactoryGirl.create(:user, :miq_groups => [group]) + group = FactoryBot.create(:miq_group, :tenant => owner_tenant) + user = FactoryBot.create(:user, :miq_groups => [group]) - request = FactoryGirl.create(:miq_provision_request, :tenant => owner_tenant, :requester => owner_user) + request = FactoryBot.create(:miq_provision_request, :tenant => owner_tenant, :requester => owner_user) results = described_class.search(:class => "MiqRequest", :user => user).first expect(results).to match_array [request] end it "can't see parent tenant's request" do - FactoryGirl.create(:miq_provision_request, :tenant => owner_tenant, :requester => owner_user) + FactoryBot.create(:miq_provision_request, :tenant => owner_tenant, :requester => owner_user) results = described_class.search(:class => "MiqRequest", :miq_group => child_group).first expect(results).to match_array [] end it "can see descendant tenant's request" do - request = FactoryGirl.create(:miq_provision_request, :tenant => child_tenant, :requester => child_user) + request = FactoryBot.create(:miq_provision_request, :tenant => child_tenant, :requester => child_user) results = described_class.search(:class => "MiqRequest", :miq_group => owner_group).first expect(results).to match_array [request] end end context "tenant access strategy VMs and Templates" do - let(:owned_template) { FactoryGirl.create(:template_vmware, :tenant => owner_tenant) } - let(:child_tenant) { FactoryGirl.create(:tenant, :divisible => false, :parent => owner_tenant) } - let(:child_group) { FactoryGirl.create(:miq_group, :tenant => child_tenant) } + let(:owned_template) { FactoryBot.create(:template_vmware, :tenant => owner_tenant) } + let(:child_tenant) { FactoryBot.create(:tenant, :divisible => false, :parent => owner_tenant) } + let(:child_group) { FactoryBot.create(:miq_group, :tenant => child_tenant) } context 'with Vm as resource of VmPerformance model' do - let!(:root_tenant_vm) { FactoryGirl.create(:vm_vmware, :tenant => Tenant.root_tenant) } - let!(:vm_performance_root_tenant) { FactoryGirl.create(:vm_performance, :resource => root_tenant_vm) } - let!(:vm_performance_other_tenant) { FactoryGirl.create(:vm_performance, :resource => other_vm) } + let!(:root_tenant_vm) { FactoryBot.create(:vm_vmware, :tenant => Tenant.root_tenant) } + let!(:vm_performance_root_tenant) { FactoryBot.create(:vm_performance, :resource => root_tenant_vm) } + let!(:vm_performance_other_tenant) { FactoryBot.create(:vm_performance, :resource => other_vm) } it 'list only other_user\'s VmPerformances' do results = described_class.search(:class => VmPerformance, :user => other_user).first @@ -719,9 +719,9 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt end context 'with tags' do - let(:role) { FactoryGirl.create(:miq_user_role) } - let(:tagged_group) { FactoryGirl.create(:miq_group, :tenant => Tenant.root_tenant, :miq_user_role => role) } - let(:user) { FactoryGirl.create(:user, :miq_groups => [tagged_group]) } + let(:role) { FactoryBot.create(:miq_user_role) } + let(:tagged_group) { FactoryBot.create(:miq_group, :tenant => Tenant.root_tenant, :miq_user_role => role) } + let(:user) { FactoryBot.create(:user, :miq_groups => [tagged_group]) } before do tagged_group.entitlement = Entitlement.new @@ -765,8 +765,8 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt end context "searching VmOrTemplate" do - let(:child_child_tenant) { FactoryGirl.create(:tenant, :divisible => false, :parent => child_tenant) } - let(:child_child_group) { FactoryGirl.create(:miq_group, :tenant => child_child_tenant) } + let(:child_child_tenant) { FactoryBot.create(:tenant, :divisible => false, :parent => child_tenant) } + let(:child_child_group) { FactoryBot.create(:miq_group, :tenant => child_child_tenant) } it "can't see descendant tenant's templates but can see descendant tenant's VMs" do owned_template.update_attributes!(:tenant_id => child_child_tenant.id, :miq_group_id => child_child_group.id) @@ -797,13 +797,13 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt end context "searching CloudTemplate" do - let(:group) { FactoryGirl.create(:miq_group, :tenant => default_tenant) } # T1 - let(:admin_user) { FactoryGirl.create(:user, :role => "super_administrator") } - let!(:cloud_template_root) { FactoryGirl.create(:template_cloud, :publicly_available => false) } + let(:group) { FactoryBot.create(:miq_group, :tenant => default_tenant) } # T1 + let(:admin_user) { FactoryBot.create(:user, :role => "super_administrator") } + let!(:cloud_template_root) { FactoryBot.create(:template_cloud, :publicly_available => false) } - let(:tenant_2) { FactoryGirl.create(:tenant, :parent => default_tenant, :source_type => 'CloudTenant') } # T2 - let(:group_2) { FactoryGirl.create(:miq_group, :tenant => tenant_2) } # T1 - let(:user_2) { FactoryGirl.create(:user, :miq_groups => [group_2]) } + let(:tenant_2) { FactoryBot.create(:tenant, :parent => default_tenant, :source_type => 'CloudTenant') } # T2 + let(:group_2) { FactoryBot.create(:miq_group, :tenant => tenant_2) } # T1 + let(:user_2) { FactoryBot.create(:user, :miq_groups => [group_2]) } context "when tenant is not mapped to cloud tenant" do it 'returns all cloud templates when user is admin' do @@ -813,8 +813,8 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt end context "when user is restricted user" do - let(:tenant_3) { FactoryGirl.create(:tenant, :parent => tenant_2) } # T3 - let!(:cloud_template) { FactoryGirl.create(:template_cloud, :tenant => tenant_3, :publicly_available => true) } + let(:tenant_3) { FactoryBot.create(:tenant, :parent => tenant_2) } # T3 + let!(:cloud_template) { FactoryBot.create(:template_cloud, :tenant => tenant_3, :publicly_available => true) } it "returns all public cloud templates" do User.current_user = user_2 @@ -823,7 +823,7 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt end context "should ignore other tenant's private cloud templates" do - let!(:cloud_template) { FactoryGirl.create(:template_cloud, :tenant => tenant_3, :publicly_available => false) } + let!(:cloud_template) { FactoryBot.create(:template_cloud, :tenant => tenant_3, :publicly_available => false) } it "returns public templates" do User.current_user = user_2 results = described_class.filtered(TemplateCloud, :user => user_2) @@ -834,37 +834,37 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt end context "when tenant is mapped to cloud tenant" do - let(:tenant_2) { FactoryGirl.create(:tenant, :parent => default_tenant, :source_type => 'CloudTenant', :source_id => 1) } + let(:tenant_2) { FactoryBot.create(:tenant, :parent => default_tenant, :source_type => 'CloudTenant', :source_id => 1) } it "finds tenant's private cloud templates" do - cloud_template2 = FactoryGirl.create(:template_cloud, :tenant => tenant_2, :publicly_available => false) + cloud_template2 = FactoryBot.create(:template_cloud, :tenant => tenant_2, :publicly_available => false) User.current_user = user_2 results = described_class.filtered(TemplateCloud, :user => user_2) expect(results).to match_array([cloud_template2]) end it "finds tenant's private and public cloud templates" do - cloud_template2 = FactoryGirl.create(:template_cloud, :tenant => tenant_2, :publicly_available => false) - cloud_template3 = FactoryGirl.create(:template_cloud, :tenant => tenant_2, :publicly_available => true) + cloud_template2 = FactoryBot.create(:template_cloud, :tenant => tenant_2, :publicly_available => false) + cloud_template3 = FactoryBot.create(:template_cloud, :tenant => tenant_2, :publicly_available => true) User.current_user = user_2 results = described_class.filtered(TemplateCloud, :user => user_2) expect(results).to match_array([cloud_template2, cloud_template3]) end it "ignores other tenant's private templates" do - cloud_template2 = FactoryGirl.create(:template_cloud, :tenant => tenant_2, :publicly_available => false) - cloud_template3 = FactoryGirl.create(:template_cloud, :tenant => tenant_2, :publicly_available => true) - FactoryGirl.create(:template_cloud, :tenant => default_tenant, :publicly_available => false) + cloud_template2 = FactoryBot.create(:template_cloud, :tenant => tenant_2, :publicly_available => false) + cloud_template3 = FactoryBot.create(:template_cloud, :tenant => tenant_2, :publicly_available => true) + FactoryBot.create(:template_cloud, :tenant => default_tenant, :publicly_available => false) User.current_user = user_2 results = described_class.filtered(TemplateCloud, :user => user_2) expect(results).to match_array([cloud_template2, cloud_template3]) end it "finds other tenant's public templates" do - cloud_template2 = FactoryGirl.create(:template_cloud, :tenant => tenant_2, :publicly_available => false) - cloud_template3 = FactoryGirl.create(:template_cloud, :tenant => tenant_2, :publicly_available => true) - cloud_template4 = FactoryGirl.create(:template_cloud, :tenant => default_tenant, :publicly_available => true) - FactoryGirl.create(:template_cloud, :tenant => default_tenant, :publicly_available => false) + cloud_template2 = FactoryBot.create(:template_cloud, :tenant => tenant_2, :publicly_available => false) + cloud_template3 = FactoryBot.create(:template_cloud, :tenant => tenant_2, :publicly_available => true) + cloud_template4 = FactoryBot.create(:template_cloud, :tenant => default_tenant, :publicly_available => true) + FactoryBot.create(:template_cloud, :tenant => default_tenant, :publicly_available => false) User.current_user = user_2 results = described_class.filtered(TemplateCloud, :user => user_2) expect(results).to match_array([cloud_template2, cloud_template3, cloud_template4]) @@ -875,8 +875,8 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt context "tenant 0" do it "can see requests owned by any tenants" do - request_task = FactoryGirl.create(:miq_request_task, :tenant => owner_tenant) - t0_group = FactoryGirl.create(:miq_group, :tenant => default_tenant) + request_task = FactoryBot.create(:miq_request_task, :tenant => owner_tenant) + t0_group = FactoryBot.create(:miq_group, :tenant => default_tenant) results = described_class.search(:class => "MiqRequestTask", :miq_group => t0_group).first expect(results).to match_array [request_task] end @@ -885,7 +885,7 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt context "searching for hosts" do it "can filter results by vmm_vendor" do - host = FactoryGirl.create(:host, :vmm_vendor => "vmware") + host = FactoryBot.create(:host, :vmm_vendor => "vmware") expression = MiqExpression.new("=" => {"field" => "Host-vmm_vendor", "value" => "vmware"}) results = described_class.search(:class => "Host", :filter => expression).first @@ -896,7 +896,7 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt context "searching for vms" do it "can filter results by vendor" do - vm = FactoryGirl.create(:vm_vmware, :vendor => "vmware") + vm = FactoryBot.create(:vm_vmware, :vendor => "vmware") expression = MiqExpression.new("=" => {"field" => "Vm-vendor", "value" => "vmware"}) results = described_class.search(:class => "Vm", :filter => expression).first @@ -907,8 +907,8 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt context "for Metrics::Rollup" do before do - vm = FactoryGirl.create(:vm_vmware) - FactoryGirl.create( + vm = FactoryBot.create(:vm_vmware) + FactoryBot.create( :metric_rollup_vm_daily, :resource_id => vm.id, :timestamp => "2010-04-14T00:00:00Z" @@ -953,8 +953,8 @@ def combine_filtered_ids(user_filtered_ids, belongsto_filtered_ids, managed_filt end context "common setup" do - let(:group) { FactoryGirl.create(:miq_group, :tenant => default_tenant) } - let(:user) { FactoryGirl.create(:user, :miq_groups => [group]) } + let(:group) { FactoryBot.create(:miq_group, :tenant => default_tenant) } + let(:user) { FactoryBot.create(:user, :miq_groups => [group]) } before do @tags = { @@ -992,7 +992,7 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) MiddlewareServerGroup ).each do |middleware_model| it "returns tagged instance of #{middleware_model}" do - middleware_instances = FactoryGirl.create_list(middleware_model.tableize.singularize.to_sym, + middleware_instances = FactoryBot.create_list(middleware_model.tableize.singularize.to_sym, count_of_created_instances) middleware_instances[0].tag_with('/managed/environment/prod', :ns => '*') middleware_model_class = middleware_model.constantize @@ -1005,9 +1005,9 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) context "with User and Group" do context 'with tags' do - let!(:tagged_group) { FactoryGirl.create(:miq_group, :tenant => default_tenant) } - let!(:user) { FactoryGirl.create(:user, :miq_groups => [tagged_group]) } - let!(:other_user) { FactoryGirl.create(:user, :miq_groups => [group]) } + let!(:tagged_group) { FactoryBot.create(:miq_group, :tenant => default_tenant) } + let!(:user) { FactoryBot.create(:user, :miq_groups => [tagged_group]) } + let!(:other_user) { FactoryBot.create(:user, :miq_groups => [group]) } before do tagged_group.entitlement = Entitlement.new @@ -1030,7 +1030,7 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) end let(:tenant_administrator_user_role) do - FactoryGirl.create(:miq_user_role, :name => MiqUserRole::DEFAULT_TENANT_ROLE_NAME) + FactoryBot.create(:miq_user_role, :name => MiqUserRole::DEFAULT_TENANT_ROLE_NAME) end it 'returns tagged groups when user\'s role has disallowed other roles' do @@ -1068,30 +1068,30 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) context 'with EvmRole-tenant_administrator' do let(:rbac_tenant) do - FactoryGirl.create(:miq_product_feature, :identifier => MiqProductFeature::TENANT_ADMIN_FEATURE) + FactoryBot.create(:miq_product_feature, :identifier => MiqProductFeature::TENANT_ADMIN_FEATURE) end let(:tenant_administrator_user_role) do - FactoryGirl.create(:miq_user_role, :name => MiqUserRole::DEFAULT_TENANT_ROLE_NAME, :miq_product_features => [rbac_tenant]) + FactoryBot.create(:miq_user_role, :name => MiqUserRole::DEFAULT_TENANT_ROLE_NAME, :miq_product_features => [rbac_tenant]) end let!(:super_administrator_user_role) do - FactoryGirl.create(:miq_user_role, :role => "super_administrator") + FactoryBot.create(:miq_user_role, :role => "super_administrator") end let(:group) do - FactoryGirl.create(:miq_group, :tenant => default_tenant, :miq_user_role => tenant_administrator_user_role) + FactoryBot.create(:miq_group, :tenant => default_tenant, :miq_user_role => tenant_administrator_user_role) end let!(:user_role) do - FactoryGirl.create(:miq_user_role, :role => "user") + FactoryBot.create(:miq_user_role, :role => "user") end let!(:other_group) do - FactoryGirl.create(:miq_group, :tenant => default_tenant, :miq_user_role => user_role) + FactoryBot.create(:miq_group, :tenant => default_tenant, :miq_user_role => user_role) end - let!(:user) { FactoryGirl.create(:user, :miq_groups => [group]) } + let!(:user) { FactoryBot.create(:user, :miq_groups => [group]) } it 'can see all roles except for EvmRole-super_administrator' do expect(MiqUserRole.count).to eq(3) @@ -1106,8 +1106,8 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) end it 'can see all groups in the current tenant only' do - another_tenant = FactoryGirl.create(:tenant) - another_tenant_group = FactoryGirl.create(:miq_group, :tenant => another_tenant) + another_tenant = FactoryBot.create(:tenant) + another_tenant_group = FactoryBot.create(:miq_group, :tenant => another_tenant) group.tenant = another_tenant default_group_for_tenant = user.current_tenant.miq_groups.where(:group_type => "tenant").first @@ -1115,10 +1115,10 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) end let(:super_admin_group) do - FactoryGirl.create(:miq_group, :tenant => default_tenant, :miq_user_role => super_administrator_user_role) + FactoryBot.create(:miq_group, :tenant => default_tenant, :miq_user_role => super_administrator_user_role) end - let!(:super_admin_user) { FactoryGirl.create(:user, :miq_groups => [super_admin_group]) } + let!(:super_admin_user) { FactoryBot.create(:user, :miq_groups => [super_admin_group]) } it 'can see all users except for user with group with role EvmRole-super_administrator' do expect(User.count).to eq(2) @@ -1130,8 +1130,8 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) context "with Hosts" do let(:hosts) { [@host1, @host2] } before do - @host1 = FactoryGirl.create(:host, :name => "Host1", :hostname => "host1.local") - @host2 = FactoryGirl.create(:host, :name => "Host2", :hostname => "host2.local") + @host1 = FactoryBot.create(:host, :name => "Host1", :hostname => "host1.local") + @host2 = FactoryBot.create(:host, :name => "Host2", :hostname => "host2.local") end context "having Metric data" do @@ -1147,7 +1147,7 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) ] @timestamps.each do |t, v| [@host1, @host2].each do |h| - h.metric_rollups << FactoryGirl.create(:metric_rollup_host_hr, + h.metric_rollups << FactoryBot.create(:metric_rollup_host_hr, :timestamp => t, :cpu_usage_rate_average => v, :cpu_ready_delta_summation => v * 1000, # Multiply by a factor of 1000 to make it more realistic and enable testing virtual col v_pct_cpu_ready_delta_summation @@ -1179,7 +1179,7 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) end it ".search filters out the wrong HostPerformance rows with :match_via_descendants option" do - @vm = FactoryGirl.create(:vm_vmware, :name => "VM1", :host => @host2) + @vm = FactoryBot.create(:vm_vmware, :name => "VM1", :host => @host2) @vm.tag_with(@tags.join(' '), :ns => '*') results, attrs = described_class.search(:targets => HostPerformance, :class => "HostPerformance", :user => user, :match_via_descendants => Vm) @@ -1206,15 +1206,15 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) group.entitlement.set_managed_filters([]) group.save! - ems1 = FactoryGirl.create(:ems_vmware, :name => 'ems1') + ems1 = FactoryBot.create(:ems_vmware, :name => 'ems1') @host1.update_attributes(:ext_management_system => ems1) @host2.update_attributes(:ext_management_system => ems1) - root = FactoryGirl.create(:ems_folder, :name => "Datacenters") + root = FactoryBot.create(:ems_folder, :name => "Datacenters") root.parent = ems1 - dc = FactoryGirl.create(:ems_folder, :name => "Datacenter1") + dc = FactoryBot.create(:ems_folder, :name => "Datacenter1") dc.parent = root - hfolder = FactoryGirl.create(:ems_folder, :name => "Hosts") + hfolder = FactoryBot.create(:ems_folder, :name => "Hosts") hfolder.parent = dc @host1.parent = hfolder end @@ -1239,23 +1239,23 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) context "with VMs and Templates" do before do - @ems = FactoryGirl.create(:ems_vmware, :name => 'ems1') + @ems = FactoryBot.create(:ems_vmware, :name => 'ems1') @host1.update_attributes(:ext_management_system => @ems) @host2.update_attributes(:ext_management_system => @ems) - root = FactoryGirl.create(:ems_folder, :name => "Datacenters") + root = FactoryBot.create(:ems_folder, :name => "Datacenters") root.parent = @ems - dc = FactoryGirl.create(:datacenter, :name => "Datacenter1") + dc = FactoryBot.create(:datacenter, :name => "Datacenter1") dc.parent = root - hfolder = FactoryGirl.create(:ems_folder, :name => "host") + hfolder = FactoryBot.create(:ems_folder, :name => "host") hfolder.parent = dc - @vfolder = FactoryGirl.create(:ems_folder, :name => "vm") + @vfolder = FactoryBot.create(:ems_folder, :name => "vm") @vfolder.parent = dc @host1.parent = hfolder @vm_folder_path = "/belongsto/ExtManagementSystem|#{@ems.name}/EmsFolder|#{root.name}/EmsFolder|#{dc.name}/EmsFolder|#{@vfolder.name}" - @vm = FactoryGirl.create(:vm_vmware, :name => "VM1", :host => @host1, :ext_management_system => @ems) - @template = FactoryGirl.create(:template_vmware, :name => "Template1", :host => @host1, :ext_management_system => @ems) + @vm = FactoryBot.create(:vm_vmware, :name => "VM1", :host => @host1, :ext_management_system => @ems) + @template = FactoryBot.create(:template_vmware, :name => "Template1", :host => @host1, :ext_management_system => @ems) end it "honors ems_id conditions" do @@ -1271,12 +1271,12 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) context "search on EMSes" do before do - @ems2 = FactoryGirl.create(:ems_vmware, :name => 'ems2') + @ems2 = FactoryBot.create(:ems_vmware, :name => 'ems2') end it "preserves order of targets" do - @ems3 = FactoryGirl.create(:ems_vmware, :name => 'ems3') - @ems4 = FactoryGirl.create(:ems_vmware, :name => 'ems4') + @ems3 = FactoryBot.create(:ems_vmware, :name => 'ems3') + @ems4 = FactoryBot.create(:ems_vmware, :name => 'ems4') targets = [@ems2, @ems4, @ems3, @ems] @@ -1287,8 +1287,8 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) end it "returns the correct class for different classes of targets" do - @ems3 = FactoryGirl.create(:ems_vmware, :name => 'ems3') - @ems4 = FactoryGirl.create(:ems_microsoft, :name => 'ems4') + @ems3 = FactoryBot.create(:ems_vmware, :name => 'ems3') + @ems4 = FactoryBot.create(:ems_microsoft, :name => 'ems4') targets = [@ems2, @ems4, @ems3, @ems] @@ -1403,14 +1403,14 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) end context "when applying a filter to the provider" do - let(:ems_cloud) { FactoryGirl.create(:ems_cloud) } + let(:ems_cloud) { FactoryBot.create(:ems_cloud) } let!(:vm_1) do - FactoryGirl.create(:vm, :ext_management_system => ems_cloud) + FactoryBot.create(:vm, :ext_management_system => ems_cloud) end let!(:vm_2) do - FactoryGirl.create(:vm, :ext_management_system => ems_cloud) + FactoryBot.create(:vm, :ext_management_system => ems_cloud) end it "returns all host's VMs and templates when host filter is set up" do @@ -1425,32 +1425,32 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) context "when applying a filter to the host and it's cluster (FB17114)" do before do - @ems = FactoryGirl.create(:ems_vmware, :name => 'ems') + @ems = FactoryBot.create(:ems_vmware, :name => 'ems') @ems_folder_path = "/belongsto/ExtManagementSystem|#{@ems.name}" - @root = FactoryGirl.create(:ems_folder, :name => "Datacenters") + @root = FactoryBot.create(:ems_folder, :name => "Datacenters") @root.parent = @ems - @mtc = FactoryGirl.create(:datacenter, :name => "MTC") + @mtc = FactoryBot.create(:datacenter, :name => "MTC") @mtc.parent = @root @mtc_folder_path = "/belongsto/ExtManagementSystem|#{@ems.name}/EmsFolder|#{@root.name}/EmsFolder|#{@mtc.name}" - @hfolder = FactoryGirl.create(:ems_folder, :name => "host") + @hfolder = FactoryBot.create(:ems_folder, :name => "host") @hfolder.parent = @mtc - @cluster = FactoryGirl.create(:ems_cluster, :name => "MTC Development") + @cluster = FactoryBot.create(:ems_cluster, :name => "MTC Development") @cluster.parent = @hfolder @cluster_folder_path = "#{@mtc_folder_path}/EmsFolder|#{@hfolder.name}/EmsCluster|#{@cluster.name}" - @rp = FactoryGirl.create(:resource_pool, :name => "Default for MTC Development") + @rp = FactoryBot.create(:resource_pool, :name => "Default for MTC Development") @rp.parent = @cluster - @host_1 = FactoryGirl.create(:host, :name => "Host_1", :ems_cluster => @cluster, :ext_management_system => @ems) - @host_2 = FactoryGirl.create(:host, :name => "Host_2", :ext_management_system => @ems) + @host_1 = FactoryBot.create(:host, :name => "Host_1", :ems_cluster => @cluster, :ext_management_system => @ems) + @host_2 = FactoryBot.create(:host, :name => "Host_2", :ext_management_system => @ems) - @vm1 = FactoryGirl.create(:vm_vmware, :name => "VM1", :host => @host_1, :ext_management_system => @ems) - @vm2 = FactoryGirl.create(:vm_vmware, :name => "VM2", :host => @host_2, :ext_management_system => @ems) + @vm1 = FactoryBot.create(:vm_vmware, :name => "VM1", :host => @host_1, :ext_management_system => @ems) + @vm2 = FactoryBot.create(:vm_vmware, :name => "VM2", :host => @host_2, :ext_management_system => @ems) - @template1 = FactoryGirl.create(:template_vmware, :name => "Template1", :host => @host_1, :ext_management_system => @ems) - @template2 = FactoryGirl.create(:template_vmware, :name => "Template2", :host => @host_2, :ext_management_system => @ems) + @template1 = FactoryBot.create(:template_vmware, :name => "Template1", :host => @host_1, :ext_management_system => @ems) + @template2 = FactoryBot.create(:template_vmware, :name => "Template2", :host => @host_2, :ext_management_system => @ems) end it "returns all host's VMs and templates when host filter is set up" do @@ -1556,11 +1556,11 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) context "with services" do before do - @service1 = FactoryGirl.create(:service) - @service2 = FactoryGirl.create(:service) - @service3 = FactoryGirl.create(:service, :evm_owner => user) - @service4 = FactoryGirl.create(:service, :miq_group => group) - @service5 = FactoryGirl.create(:service, :evm_owner => user, :miq_group => group) + @service1 = FactoryBot.create(:service) + @service2 = FactoryBot.create(:service) + @service3 = FactoryBot.create(:service, :evm_owner => user) + @service4 = FactoryBot.create(:service, :miq_group => group) + @service5 = FactoryBot.create(:service, :evm_owner => user, :miq_group => group) end context ".search" do @@ -1621,10 +1621,10 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) context 'with ansible ConfigurationScripts' do describe ".search" do - let!(:ansible_configuration_script) { FactoryGirl.create(:ansible_configuration_script) } - let!(:ansible_configuration_script_with_tag) { FactoryGirl.create(:ansible_configuration_script) } - let!(:ansible_playbook) { FactoryGirl.create(:ansible_playbook) } - let!(:ansible_playbook_with_tag) { FactoryGirl.create(:ansible_playbook) } + let!(:ansible_configuration_script) { FactoryBot.create(:ansible_configuration_script) } + let!(:ansible_configuration_script_with_tag) { FactoryBot.create(:ansible_configuration_script) } + let!(:ansible_playbook) { FactoryBot.create(:ansible_playbook) } + let!(:ansible_playbook_with_tag) { FactoryBot.create(:ansible_playbook) } it 'works when targets are empty' do User.with_user(user) do @@ -1666,8 +1666,8 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) end context "with cloud network and network manager" do - let!(:network_manager) { FactoryGirl.create(:ems_openstack).network_manager } - let!(:network_manager_1) { FactoryGirl.create(:ems_openstack).network_manager } + let!(:network_manager) { FactoryBot.create(:ems_openstack).network_manager } + let!(:network_manager_1) { FactoryBot.create(:ems_openstack).network_manager } context "with belongs_to_filter" do before do @@ -1681,12 +1681,12 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) describe ".search" do let!(:network_object) do return network_manager if network_model == ManageIQ::Providers::NetworkManager - FactoryGirl.create(network_model.underscore, :ext_management_system => network_manager) + FactoryBot.create(network_model.underscore, :ext_management_system => network_manager) end let!(:network_object_with_different_network_manager) do return network_manager_1 if network_model == ManageIQ::Providers::NetworkManager - FactoryGirl.create(network_model.underscore, :ext_management_system => network_manager_1) + FactoryBot.create(network_model.underscore, :ext_management_system => network_manager_1) end context "when records match belogns to filter" do @@ -1719,8 +1719,8 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) end context "network manager with/without tagging" do - let!(:cloud_network) { FactoryGirl.create(:cloud_network, :ext_management_system => network_manager) } - let!(:cloud_network_1) { FactoryGirl.create(:cloud_network, :ext_management_system => network_manager_1) } + let!(:cloud_network) { FactoryBot.create(:cloud_network, :ext_management_system => network_manager) } + let!(:cloud_network_1) { FactoryBot.create(:cloud_network, :ext_management_system => network_manager_1) } context "network manager is tagged" do before do @@ -1786,8 +1786,8 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) NETWORK_MODELS.each do |network_model| describe ".search" do - let!(:network_object) { FactoryGirl.create(network_model.underscore) } - let!(:network_object_with_tag) { FactoryGirl.create(network_model.underscore) } + let!(:network_object) { FactoryBot.create(network_model.underscore) } + let!(:network_object_with_tag) { FactoryBot.create(network_model.underscore) } let(:network_object_ids) { [network_object.id, network_object_with_tag.id] } it 'works when targets are empty' do @@ -1820,19 +1820,19 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) end context "with tagged VMs" do - let(:ems) { FactoryGirl.create(:ext_management_system) } + let(:ems) { FactoryBot.create(:ext_management_system) } before do [ - FactoryGirl.create(:host, :name => "Host1", :hostname => "host1.local"), - FactoryGirl.create(:host, :name => "Host2", :hostname => "host2.local"), - FactoryGirl.create(:host, :name => "Host3", :hostname => "host3.local"), - FactoryGirl.create(:host, :name => "Host4", :hostname => "host4.local") + FactoryBot.create(:host, :name => "Host1", :hostname => "host1.local"), + FactoryBot.create(:host, :name => "Host2", :hostname => "host2.local"), + FactoryBot.create(:host, :name => "Host3", :hostname => "host3.local"), + FactoryBot.create(:host, :name => "Host4", :hostname => "host4.local") ].each_with_index do |host, i| grp = i + 1 guest_os = %w(_none_ windows ubuntu windows ubuntu)[grp] - vm = FactoryGirl.build(:vm_vmware, :name => "Test Group #{grp} VM #{i}") - vm.hardware = FactoryGirl.build(:hardware, :cpu_sockets => (grp * 2), :memory_mb => (grp * 1.megabytes), :guest_os => guest_os) + vm = FactoryBot.build(:vm_vmware, :name => "Test Group #{grp} VM #{i}") + vm.hardware = FactoryBot.build(:hardware, :cpu_sockets => (grp * 2), :memory_mb => (grp * 1.megabytes), :guest_os => guest_os) vm.host = host vm.evm_owner_id = user.id if i.even? vm.miq_group_id = group.id if i.odd? @@ -1999,7 +1999,7 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) it "works when class does not participate in RBAC and user filters are passed" do 2.times do |i| - FactoryGirl.create(:ems_event, :timestamp => Time.now.utc, :message => "Event #{i}") + FactoryBot.create(:ems_event, :timestamp => Time.now.utc, :message => "Event #{i}") end exp = YAML.load '--- !ruby/object:MiqExpression @@ -2020,12 +2020,12 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) end context "with group's VMs" do - let(:group_user) { FactoryGirl.create(:user, :miq_groups => [group2, group]) } - let(:group2) { FactoryGirl.create(:miq_group, :role => 'support') } + let(:group_user) { FactoryBot.create(:user, :miq_groups => [group2, group]) } + let(:group2) { FactoryBot.create(:miq_group, :role => 'support') } before do 4.times do |i| - FactoryGirl.create(:vm_vmware, + FactoryBot.create(:vm_vmware, :name => "Test VM #{i}", :connection_state => i < 2 ? 'connected' : 'disconnected', :miq_group => i.even? ? group : group2) @@ -2087,8 +2087,8 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) end describe ".filtered" do - let(:matched_vms) { FactoryGirl.create_list(:vm_vmware, 2, :location => "good") } - let(:other_vms) { FactoryGirl.create_list(:vm_vmware, 1, :location => "other") } + let(:matched_vms) { FactoryBot.create_list(:vm_vmware, 2, :location => "good") } + let(:other_vms) { FactoryBot.create_list(:vm_vmware, 1, :location => "other") } let(:all_vms) { matched_vms + other_vms } it "skips rbac on empty empty arrays" do @@ -2140,8 +2140,8 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) # force this filter to be evaluated in ruby expect(filter).to receive(:sql_supports_atom?).and_return(false) - FactoryGirl.create_list(:vm_vmware, 3, :location => "a") - FactoryGirl.create_list(:vm_vmware, 3, :location => "b") + FactoryBot.create_list(:vm_vmware, 3, :location => "a") + FactoryBot.create_list(:vm_vmware, 3, :location => "b") # ordering by location, so the bad records come first # if we limit in sql, then only bad results will come back - and final result size will be 0 # if we limit in ruby, then all 6 records will come back, we'll filter to 3 and then limit to 2. @@ -2150,9 +2150,9 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) end it "supports order on scopes" do - FactoryGirl.create(:vm_vmware, :location => "a") - FactoryGirl.create(:vm_vmware, :location => "b") - FactoryGirl.create(:vm_vmware, :location => "a") + FactoryBot.create(:vm_vmware, :location => "a") + FactoryBot.create(:vm_vmware, :location => "b") + FactoryBot.create(:vm_vmware, :location => "a") expect(described_class.filtered(Vm.all.order(:location)).map(&:location)).to eq(%w(a a b)) end end @@ -2299,10 +2299,10 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) end describe "find_targets_with_direct_rbac" do - let(:host_match) { FactoryGirl.create(:host, :hostname => 'good') } - let(:host_other) { FactoryGirl.create(:host, :hostname => 'bad') } - let(:vms_match) { FactoryGirl.create_list(:vm_vmware, 2, :host => host_match) } - let(:vm_host2) { FactoryGirl.create_list(:vm_vmware, 1, :host => host_other) } + let(:host_match) { FactoryBot.create(:host, :hostname => 'good') } + let(:host_other) { FactoryBot.create(:host, :hostname => 'bad') } + let(:vms_match) { FactoryBot.create_list(:vm_vmware, 2, :host => host_match) } + let(:vm_host2) { FactoryBot.create_list(:vm_vmware, 1, :host => host_other) } let(:all_vms) { vms_match + vm_host2 } it "works with no filters" do @@ -2320,9 +2320,9 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) context ".lookup_user_group" do let(:filter) { described_class.new } - let(:user1) { FactoryGirl.create(:user_with_group) } - let(:group_list) { FactoryGirl.create_list(:miq_group, 2) } - let(:user2) { FactoryGirl.create(:user, :miq_groups => group_list) } + let(:user1) { FactoryBot.create(:user_with_group) } + let(:group_list) { FactoryBot.create_list(:miq_group, 2) } + let(:user2) { FactoryBot.create(:user, :miq_groups => group_list) } context "user_group" do it "uses user.current_group" do @@ -2374,28 +2374,28 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) it "fallsback to current_group if not member of group" do user1_group = user1.current_group - _, group = filter.send(:lookup_user_group, user1, nil, FactoryGirl.create(:miq_group), nil) + _, group = filter.send(:lookup_user_group, user1, nil, FactoryBot.create(:miq_group), nil) expect(group).to eq(user1_group) end it "uses group passed in when not member of group when super admin" do - admin = FactoryGirl.create(:user_admin) - random_group = FactoryGirl.create(:miq_group) + admin = FactoryBot.create(:user_admin) + random_group = FactoryBot.create(:miq_group) _, group = filter.send(:lookup_user_group, admin, nil, random_group, nil) expect(group).to eq(random_group) end it "uses group_id passed in when not member of group when super admin" do - admin = FactoryGirl.create(:user_admin) - random_group = FactoryGirl.create(:miq_group) + admin = FactoryBot.create(:user_admin) + random_group = FactoryBot.create(:miq_group) _, group = filter.send(:lookup_user_group, admin, nil, nil, random_group.id) expect(group).to eq(random_group) end it "does not update user.current_group if user is super admin" do - admin = FactoryGirl.create(:user_admin) + admin = FactoryBot.create(:user_admin) admin_group = admin.current_group - random_group = FactoryGirl.create(:miq_group) + random_group = FactoryBot.create(:miq_group) filter.send(:lookup_user_group, admin, nil, nil, random_group.id) expect(admin.current_group).to eq(admin_group) end @@ -2415,27 +2415,27 @@ def get_rbac_results_for_and_expect_objects(klass, expected_objects) end describe "cloud_tenant based search" do - let(:ems_openstack) { FactoryGirl.create(:ems_cloud) } - let(:project1_tenant) { FactoryGirl.create(:tenant, :source_type => 'CloudTenant') } - let(:project1_cloud_tenant) { FactoryGirl.create(:cloud_tenant, :source_tenant => project1_tenant, :ext_management_system => ems_openstack) } - let(:project1_group) { FactoryGirl.create(:miq_group, :tenant => project1_tenant) } - let(:project1_user) { FactoryGirl.create(:user, :miq_groups => [project1_group]) } - let(:project1_volume) { FactoryGirl.create(:cloud_volume, :ext_management_system => ems_openstack, :cloud_tenant => project1_cloud_tenant) } - let(:project1_flavor) { FactoryGirl.create(:flavor, :ext_management_system => ems_openstack) } - let(:project1_c_t_flavor) { FactoryGirl.create(:cloud_tenant_flavor, :cloud_tenant => project1_cloud_tenant, :flavor => project1_flavor) } - let(:project2_tenant) { FactoryGirl.create(:tenant, :source_type => 'CloudTenant') } - let(:project2_cloud_tenant) { FactoryGirl.create(:cloud_tenant, :source_tenant => project2_tenant, :ext_management_system => ems_openstack) } - let(:project2_group) { FactoryGirl.create(:miq_group, :tenant => project2_tenant) } - let(:project2_user) { FactoryGirl.create(:user, :miq_groups => [project2_group]) } - let(:project2_volume) { FactoryGirl.create(:cloud_volume, :ext_management_system => ems_openstack, :cloud_tenant => project2_cloud_tenant) } - let(:project2_flavor) { FactoryGirl.create(:flavor, :ext_management_system => ems_openstack) } - let(:project2_c_t_flavor) { FactoryGirl.create(:cloud_tenant_flavor, :cloud_tenant => project2_cloud_tenant, :flavor => project2_flavor) } - let(:ems_other) { FactoryGirl.create(:ems_cloud, :name => 'ems_other', :tenant_mapping_enabled => false) } - let(:volume_other) { FactoryGirl.create(:cloud_volume, :ext_management_system => ems_other) } - let(:tenant_other) { FactoryGirl.create(:tenant, :source_type => 'CloudTenant') } - let(:cloud_tenant_other) { FactoryGirl.create(:cloud_tenant, :source_tenant => tenant_other, :ext_management_system => ems_other) } - let(:flavor_other) { FactoryGirl.create(:flavor, :ext_management_system => ems_other) } - let(:c_t_flavor_other) { FactoryGirl.create(:cloud_tenant_flavor, :cloud_tenant => cloud_tenant_other, :flavor => flavor_other) } + let(:ems_openstack) { FactoryBot.create(:ems_cloud) } + let(:project1_tenant) { FactoryBot.create(:tenant, :source_type => 'CloudTenant') } + let(:project1_cloud_tenant) { FactoryBot.create(:cloud_tenant, :source_tenant => project1_tenant, :ext_management_system => ems_openstack) } + let(:project1_group) { FactoryBot.create(:miq_group, :tenant => project1_tenant) } + let(:project1_user) { FactoryBot.create(:user, :miq_groups => [project1_group]) } + let(:project1_volume) { FactoryBot.create(:cloud_volume, :ext_management_system => ems_openstack, :cloud_tenant => project1_cloud_tenant) } + let(:project1_flavor) { FactoryBot.create(:flavor, :ext_management_system => ems_openstack) } + let(:project1_c_t_flavor) { FactoryBot.create(:cloud_tenant_flavor, :cloud_tenant => project1_cloud_tenant, :flavor => project1_flavor) } + let(:project2_tenant) { FactoryBot.create(:tenant, :source_type => 'CloudTenant') } + let(:project2_cloud_tenant) { FactoryBot.create(:cloud_tenant, :source_tenant => project2_tenant, :ext_management_system => ems_openstack) } + let(:project2_group) { FactoryBot.create(:miq_group, :tenant => project2_tenant) } + let(:project2_user) { FactoryBot.create(:user, :miq_groups => [project2_group]) } + let(:project2_volume) { FactoryBot.create(:cloud_volume, :ext_management_system => ems_openstack, :cloud_tenant => project2_cloud_tenant) } + let(:project2_flavor) { FactoryBot.create(:flavor, :ext_management_system => ems_openstack) } + let(:project2_c_t_flavor) { FactoryBot.create(:cloud_tenant_flavor, :cloud_tenant => project2_cloud_tenant, :flavor => project2_flavor) } + let(:ems_other) { FactoryBot.create(:ems_cloud, :name => 'ems_other', :tenant_mapping_enabled => false) } + let(:volume_other) { FactoryBot.create(:cloud_volume, :ext_management_system => ems_other) } + let(:tenant_other) { FactoryBot.create(:tenant, :source_type => 'CloudTenant') } + let(:cloud_tenant_other) { FactoryBot.create(:cloud_tenant, :source_tenant => tenant_other, :ext_management_system => ems_other) } + let(:flavor_other) { FactoryBot.create(:flavor, :ext_management_system => ems_other) } + let(:c_t_flavor_other) { FactoryBot.create(:cloud_tenant_flavor, :cloud_tenant => cloud_tenant_other, :flavor => flavor_other) } let!(:all_objects) { [project1_volume, project2_volume, volume_other, cloud_tenant_other, project1_c_t_flavor, project2_c_t_flavor, c_t_flavor_other] } it "lists its own project's objects and other objects where tenant_mapping is not enabled" do diff --git a/spec/lib/rbac_spec.rb b/spec/lib/rbac_spec.rb index 201bed400a8..2198ae8b23a 100644 --- a/spec/lib/rbac_spec.rb +++ b/spec/lib/rbac_spec.rb @@ -3,13 +3,13 @@ describe ".resources_shared_with" do let(:user) do - FactoryGirl.create(:user, + FactoryBot.create(:user, :role => "user", - :tenant => FactoryGirl.create(:tenant, :name => "Tenant under root"), + :tenant => FactoryBot.create(:tenant, :name => "Tenant under root"), :features => user_allowed_feature) end let(:user_allowed_feature) { "service" } - let(:resource_to_be_shared) { FactoryGirl.create(:vm_vmware, :tenant => user.current_tenant) } + let(:resource_to_be_shared) { FactoryBot.create(:vm_vmware, :tenant => user.current_tenant) } let(:tenants) { [sharee.current_tenant] } let(:features) { :all } let!(:share) do @@ -19,9 +19,9 @@ :features => features) end let(:sharee) do - FactoryGirl.create(:user, - :miq_groups => [FactoryGirl.create(:miq_group, - :tenant => FactoryGirl.create(:tenant, :name => "Sibling tenant"))]) + FactoryBot.create(:user, + :miq_groups => [FactoryBot.create(:miq_group, + :tenant => FactoryBot.create(:tenant, :name => "Sibling tenant"))]) end before { Tenant.seed } @@ -39,11 +39,11 @@ end context "with tenant inheritance" do - let(:sibling_tenant) { FactoryGirl.create(:tenant, :name => "Sibling tenant") } - let(:siblings_child) { FactoryGirl.create(:tenant, :parent => sibling_tenant, :name => "Sibling's child tenant") } + let(:sibling_tenant) { FactoryBot.create(:tenant, :name => "Sibling tenant") } + let(:siblings_child) { FactoryBot.create(:tenant, :parent => sibling_tenant, :name => "Sibling's child tenant") } let(:sharee) do - FactoryGirl.create(:user, - :miq_groups => [FactoryGirl.create(:miq_group, + FactoryBot.create(:user, + :miq_groups => [FactoryBot.create(:miq_group, :tenant => siblings_child)]) end let!(:share) do diff --git a/spec/lib/remote_console/web_mks_legacy_spec.rb b/spec/lib/remote_console/web_mks_legacy_spec.rb index 033630ad713..b5c991fd2e0 100644 --- a/spec/lib/remote_console/web_mks_legacy_spec.rb +++ b/spec/lib/remote_console/web_mks_legacy_spec.rb @@ -1,5 +1,5 @@ describe RemoteConsole::WebMKSLegacy do - let(:record) { FactoryGirl.create(:system_console, :url => '/12345') } + let(:record) { FactoryBot.create(:system_console, :url => '/12345') } subject { described_class.new(record, nil) } before do diff --git a/spec/lib/remote_console/web_mks_spec.rb b/spec/lib/remote_console/web_mks_spec.rb index 86f8e9f7c89..b3c8214ff78 100644 --- a/spec/lib/remote_console/web_mks_spec.rb +++ b/spec/lib/remote_console/web_mks_spec.rb @@ -1,5 +1,5 @@ describe RemoteConsole::WebMKS do - let(:record) { FactoryGirl.create(:system_console, :secret => '12345') } + let(:record) { FactoryBot.create(:system_console, :secret => '12345') } subject { described_class.new(record, nil) } before do diff --git a/spec/lib/remote_console_spec.rb b/spec/lib/remote_console_spec.rb index 64a24e40109..c7e71016dbb 100644 --- a/spec/lib/remote_console_spec.rb +++ b/spec/lib/remote_console_spec.rb @@ -1,6 +1,6 @@ describe RemoteConsole do describe '.new' do - let(:record) { FactoryGirl.create(:system_console, :protocol => protocol, :ssl => ssl) } + let(:record) { FactoryBot.create(:system_console, :protocol => protocol, :ssl => ssl) } let(:ssl) { false } context 'VNC' do diff --git a/spec/lib/services/container_deployment_service_spec.rb b/spec/lib/services/container_deployment_service_spec.rb index 7a27efdc5c9..91ef3053292 100644 --- a/spec/lib/services/container_deployment_service_spec.rb +++ b/spec/lib/services/container_deployment_service_spec.rb @@ -1,19 +1,19 @@ RSpec.describe ContainerDeploymentService do before do %w(amazon openstack google azure redhat vmware).each do |p| - network = FactoryGirl.create(:network, :ipaddress => "127.0.0.1") - hardware = FactoryGirl.create(:hardware) + network = FactoryBot.create(:network, :ipaddress => "127.0.0.1") + hardware = FactoryBot.create(:hardware) hardware.networks << network - vm = FactoryGirl.create("vm_#{p}".to_sym, :hardware => hardware) + vm = FactoryBot.create("vm_#{p}".to_sym, :hardware => hardware) if %w(amazon redhat).include?(p) - template = FactoryGirl.create("template_#{p}".to_sym) - provider = FactoryGirl.create("ems_#{p}".to_sym, :miq_templates => [template]) + template = FactoryBot.create("template_#{p}".to_sym) + provider = FactoryBot.create("ems_#{p}".to_sym, :miq_templates => [template]) else - provider = FactoryGirl.create("ems_#{p}".to_sym) + provider = FactoryBot.create("ems_#{p}".to_sym) end provider.vms << vm end - @foreman_provider = FactoryGirl.create(:configuration_manager_foreman) + @foreman_provider = FactoryBot.create(:configuration_manager_foreman) end context "possible_providers_and_vms" do diff --git a/spec/lib/services/dialog_import_service_spec.rb b/spec/lib/services/dialog_import_service_spec.rb index 899ca4bbe3e..4997c9c6e5f 100644 --- a/spec/lib/services/dialog_import_service_spec.rb +++ b/spec/lib/services/dialog_import_service_spec.rb @@ -74,7 +74,7 @@ context "when there is an existing dialog" do before do - FactoryGirl.create(:dialog, :label => "Test2") + FactoryBot.create(:dialog, :label => "Test2") end it "does not create a third dialog" do @@ -154,7 +154,7 @@ context "when there is already an existing dialog" do before do - FactoryGirl.create(:dialog, :label => "Test2", :description => "not potato") + FactoryBot.create(:dialog, :label => "Test2", :description => "not potato") end it "overwrites the existing dialog" do @@ -261,7 +261,7 @@ context "when the list of dialogs to import from the yaml includes an existing dialog" do before do - FactoryGirl.create(:dialog, :label => "Test2", :description => "not potato") + FactoryBot.create(:dialog, :label => "Test2", :description => "not potato") end it_behaves_like "DialogImportService#import_service_dialogs that destroys temporary data" diff --git a/spec/lib/services/resource_sharer_spec.rb b/spec/lib/services/resource_sharer_spec.rb index ac25a9cce95..39fa720dd51 100644 --- a/spec/lib/services/resource_sharer_spec.rb +++ b/spec/lib/services/resource_sharer_spec.rb @@ -10,13 +10,13 @@ end let(:user) do - FactoryGirl.create(:user, + FactoryBot.create(:user, :role => "user", :features => user_allowed_feature) end let(:user_allowed_feature) { "service" } - let(:resource_to_be_shared) { FactoryGirl.create(:miq_template) } - let(:tenants) { [FactoryGirl.create(:tenant)] } + let(:resource_to_be_shared) { FactoryBot.create(:miq_template) } + let(:tenants) { [FactoryBot.create(:tenant)] } let(:features) { :all } context "with valid arguments" do @@ -75,7 +75,7 @@ end context "with an invalid resource" do - let(:resource_to_be_shared) { FactoryGirl.build(:miq_group) } + let(:resource_to_be_shared) { FactoryBot.build(:miq_group) } it "is invalid" do User.with_user(user) do @@ -87,14 +87,14 @@ context "attempting to share a resource the user doesn't have access to via RBAC" do let(:user) do - FactoryGirl.create(:user, + FactoryBot.create(:user, :role => "user", :features => user_allowed_feature, - :tenant => FactoryGirl.create(:tenant, :name => "Tenant under root")) + :tenant => FactoryBot.create(:tenant, :name => "Tenant under root")) end let(:resource_to_be_shared) do - FactoryGirl.create(:miq_template, - :tenant => FactoryGirl.create(:tenant, + FactoryBot.create(:miq_template, + :tenant => FactoryBot.create(:tenant, :name => "Sibling tenant")) end let(:tenants) { [user.current_tenant] } # Attempt to share a resource in Sibling tenant to one's own tenant @@ -108,7 +108,7 @@ end context "with tenants that aren't tenants" do - let(:tenants) { [FactoryGirl.build(:miq_group)] } + let(:tenants) { [FactoryBot.build(:miq_group)] } it "is invalid" do expect(subject).not_to be_valid diff --git a/spec/lib/task_helpers/exports/alert_sets_spec.rb b/spec/lib/task_helpers/exports/alert_sets_spec.rb index 883fdee3a37..408c1ba1987 100644 --- a/spec/lib/task_helpers/exports/alert_sets_spec.rb +++ b/spec/lib/task_helpers/exports/alert_sets_spec.rb @@ -31,7 +31,7 @@ end before do - FactoryGirl.create(:miq_alert_set_vm, alert_set_create_attrs) + FactoryBot.create(:miq_alert_set_vm, alert_set_create_attrs) @export_dir = Dir.mktmpdir('miq_exp_dir') end diff --git a/spec/lib/task_helpers/exports/alerts_spec.rb b/spec/lib/task_helpers/exports/alerts_spec.rb index 895cb7c8ce9..faeeb2a1ba9 100644 --- a/spec/lib/task_helpers/exports/alerts_spec.rb +++ b/spec/lib/task_helpers/exports/alerts_spec.rb @@ -29,7 +29,7 @@ end before do - FactoryGirl.create(:miq_alert, alert_create_attrs) + FactoryBot.create(:miq_alert, alert_create_attrs) @export_dir = Dir.mktmpdir('miq_exp_dir') end diff --git a/spec/lib/task_helpers/exports/custom_buttons_spec.rb b/spec/lib/task_helpers/exports/custom_buttons_spec.rb index dd3ced705bc..79cbb358a15 100644 --- a/spec/lib/task_helpers/exports/custom_buttons_spec.rb +++ b/spec/lib/task_helpers/exports/custom_buttons_spec.rb @@ -1,7 +1,7 @@ describe TaskHelpers::Exports::CustomButtons do - let!(:custom_button) { FactoryGirl.create(:custom_button, :name => "export_test_button", :description => "Export Test", :applies_to_class => "Vm") } - let!(:custom_button2) { FactoryGirl.create(:custom_button, :name => "export_test_button2", :description => "Export Test", :applies_to_class => "Service") } - let!(:custom_button_set) { FactoryGirl.create(:custom_button_set, :name => "custom_button_set", :description => "Default Export Test") } + let!(:custom_button) { FactoryBot.create(:custom_button, :name => "export_test_button", :description => "Export Test", :applies_to_class => "Vm") } + let!(:custom_button2) { FactoryBot.create(:custom_button, :name => "export_test_button2", :description => "Export Test", :applies_to_class => "Service") } + let!(:custom_button_set) { FactoryBot.create(:custom_button_set, :name => "custom_button_set", :description => "Default Export Test") } let(:export_dir) { Dir.mktmpdir('miq_exp_dir') } let(:custom_button_export_test) do diff --git a/spec/lib/task_helpers/exports/customization_templates_spec.rb b/spec/lib/task_helpers/exports/customization_templates_spec.rb index 215abf5a4ee..3d2423d9c3b 100644 --- a/spec/lib/task_helpers/exports/customization_templates_spec.rb +++ b/spec/lib/task_helpers/exports/customization_templates_spec.rb @@ -42,21 +42,21 @@ end before do - pit1 = FactoryGirl.create(:pxe_image_type, + pit1 = FactoryBot.create(:pxe_image_type, :name => image_type_name1) - pit2 = FactoryGirl.create(:pxe_image_type, + pit2 = FactoryBot.create(:pxe_image_type, :name => image_type_name2, :provision_type => provision_type2) - FactoryGirl.create(:customization_template, + FactoryBot.create(:customization_template, :name => template_name, :type => template_type, :description => template_desc, :script => template_script, :pxe_image_type => pit1) - FactoryGirl.create(:customization_template, + FactoryBot.create(:customization_template, :name => template_name, :type => template_type, :description => template_desc, diff --git a/spec/lib/task_helpers/exports/policies_spec.rb b/spec/lib/task_helpers/exports/policies_spec.rb index 3dc299c6cc3..e1f27ec0ac7 100644 --- a/spec/lib/task_helpers/exports/policies_spec.rb +++ b/spec/lib/task_helpers/exports/policies_spec.rb @@ -69,8 +69,8 @@ end before do - FactoryGirl.create(:miq_policy, policy_create_attrs) - FactoryGirl.create(:miq_policy_read_only, policy2_create_attrs) + FactoryBot.create(:miq_policy, policy_create_attrs) + FactoryBot.create(:miq_policy_read_only, policy2_create_attrs) end after do diff --git a/spec/lib/task_helpers/exports/policy_sets_spec.rb b/spec/lib/task_helpers/exports/policy_sets_spec.rb index ec5f22f9fde..be1ca238511 100644 --- a/spec/lib/task_helpers/exports/policy_sets_spec.rb +++ b/spec/lib/task_helpers/exports/policy_sets_spec.rb @@ -65,8 +65,8 @@ end before do - FactoryGirl.create(:miq_policy_set, policy_set_create_attrs) - FactoryGirl.create(:miq_policy_set_read_only, policy2_set_create_attrs) + FactoryBot.create(:miq_policy_set, policy_set_create_attrs) + FactoryBot.create(:miq_policy_set_read_only, policy2_set_create_attrs) end after do diff --git a/spec/lib/task_helpers/exports/provision_dialogs_spec.rb b/spec/lib/task_helpers/exports/provision_dialogs_spec.rb index d27559e2031..54b15c33d90 100644 --- a/spec/lib/task_helpers/exports/provision_dialogs_spec.rb +++ b/spec/lib/task_helpers/exports/provision_dialogs_spec.rb @@ -51,14 +51,14 @@ end before do - FactoryGirl.create(:miq_dialog, + FactoryBot.create(:miq_dialog, :dialog_type => dialog_type1, :name => dialog_name1, :description => dialog_desc1, :content => content, :default => true) - FactoryGirl.create(:miq_dialog, + FactoryBot.create(:miq_dialog, :dialog_type => dialog_type2, :name => dialog_name2, :description => dialog_desc2, @@ -104,7 +104,7 @@ let(:dialog_filename2) { "#{export_dir}/#{dialog_type3}-custom_dialog.yaml" } before do - FactoryGirl.create(:miq_dialog, + FactoryBot.create(:miq_dialog, :dialog_type => dialog_type3, :name => dialog_name2, :description => dialog_desc2, diff --git a/spec/lib/task_helpers/exports/roles_spec.rb b/spec/lib/task_helpers/exports/roles_spec.rb index a5ee584ca52..79c5fadb797 100644 --- a/spec/lib/task_helpers/exports/roles_spec.rb +++ b/spec/lib/task_helpers/exports/roles_spec.rb @@ -18,8 +18,8 @@ end before do - FactoryGirl.create(:miq_user_role, :name => "Test Role", :features => "about") - FactoryGirl.create(:miq_user_role, :role => "super_administrator") + FactoryBot.create(:miq_user_role, :name => "Test Role", :features => "about") + FactoryBot.create(:miq_user_role, :role => "super_administrator") end after do diff --git a/spec/lib/task_helpers/exports/service_dialogs_spec.rb b/spec/lib/task_helpers/exports/service_dialogs_spec.rb index 873a5bfeb53..827c89519a5 100644 --- a/spec/lib/task_helpers/exports/service_dialogs_spec.rb +++ b/spec/lib/task_helpers/exports/service_dialogs_spec.rb @@ -28,8 +28,8 @@ end before do - FactoryGirl.create(:dialog, :name => label1, :description => description1, :buttons => buttons) - FactoryGirl.create(:dialog, :name => label2, :description => description2, :buttons => buttons) + FactoryBot.create(:dialog, :name => label1, :description => description1, :buttons => buttons) + FactoryBot.create(:dialog, :name => label2, :description => description2, :buttons => buttons) end after do diff --git a/spec/lib/task_helpers/exports/tags_spec.rb b/spec/lib/task_helpers/exports/tags_spec.rb index 25bd5a7036c..4ec8862c308 100644 --- a/spec/lib/task_helpers/exports/tags_spec.rb +++ b/spec/lib/task_helpers/exports/tags_spec.rb @@ -1,7 +1,7 @@ describe TaskHelpers::Exports::Tags do - let(:parent) { FactoryGirl.create(:classification, :name => "export_test_category", :description => "Export Test") } - let(:def_parent) { FactoryGirl.create(:classification, :name => "default_test_category", :description => "Default Export Test", :default => true) } - let(:def_parent2) { FactoryGirl.create(:classification, :name => "default_test2_category", :description => "Default Export Test 2", :default => true) } + let(:parent) { FactoryBot.create(:classification, :name => "export_test_category", :description => "Export Test") } + let(:def_parent) { FactoryBot.create(:classification, :name => "default_test_category", :description => "Default Export Test", :default => true) } + let(:def_parent2) { FactoryBot.create(:classification, :name => "default_test2_category", :description => "Default Export Test 2", :default => true) } let(:export_dir) { Dir.mktmpdir('miq_exp_dir') } let(:tag_export_test) do @@ -97,11 +97,11 @@ end before do - FactoryGirl.create(:classification_tag, :name => "test_entry", :description => "Test Entry", :parent => parent) - FactoryGirl.create(:classification_tag, :name => "another_test_entry", :description => "Another Test Entry", :parent => parent) - FactoryGirl.create(:classification_tag, :name => "def_test_entry", :description => "Default Test Entry", :parent => def_parent, :default => true) - FactoryGirl.create(:classification_tag, :name => "def_test_entry_2", :description => "Default Test Entry 2", :parent => def_parent2, :default => true) - FactoryGirl.create(:classification_tag, :name => "def_test_entry_3", :description => "Default Test Entry 3", :parent => def_parent2) + FactoryBot.create(:classification_tag, :name => "test_entry", :description => "Test Entry", :parent => parent) + FactoryBot.create(:classification_tag, :name => "another_test_entry", :description => "Another Test Entry", :parent => parent) + FactoryBot.create(:classification_tag, :name => "def_test_entry", :description => "Default Test Entry", :parent => def_parent, :default => true) + FactoryBot.create(:classification_tag, :name => "def_test_entry_2", :description => "Default Test Entry 2", :parent => def_parent2, :default => true) + FactoryBot.create(:classification_tag, :name => "def_test_entry_3", :description => "Default Test Entry 3", :parent => def_parent2) end after do diff --git a/spec/lib/task_helpers/imports/tags_spec.rb b/spec/lib/task_helpers/imports/tags_spec.rb index 986017969ad..2735e715b47 100644 --- a/spec/lib/task_helpers/imports/tags_spec.rb +++ b/spec/lib/task_helpers/imports/tags_spec.rb @@ -45,8 +45,8 @@ let(:source) { "#{data_dir}/#{tag_file2}" } it 'updates attributes' do - parent = FactoryGirl.create(:classification, :name => "location", :description => "Location", :single_value => 1, :default => 1) - FactoryGirl.create(:classification_tag, :name => "london", :description => "London", :parent => parent) + parent = FactoryBot.create(:classification, :name => "location", :description => "Location", :single_value => 1, :default => 1) + FactoryBot.create(:classification_tag, :name => "london", :description => "London", :parent => parent) expect do TaskHelpers::Imports::Tags.new.import(options) diff --git a/spec/lib/tasks/evm_application_spec.rb b/spec/lib/tasks/evm_application_spec.rb index a3f0442d936..6b9398d529d 100644 --- a/spec/lib/tasks/evm_application_spec.rb +++ b/spec/lib/tasks/evm_application_spec.rb @@ -18,12 +18,12 @@ end describe ".servers_status" do - let(:local_zone) { FactoryGirl.create(:zone, :name => 'A Zone') } + let(:local_zone) { FactoryBot.create(:zone, :name => 'A Zone') } let(:local) { EvmSpecHelper.local_miq_server(:started_on => 1.hour.ago, :last_heartbeat => 2.days.ago, :zone => local_zone) } let(:remote) { EvmSpecHelper.remote_miq_server(:is_master => true, :last_heartbeat => nil) } - let!(:ui) { FactoryGirl.create(:miq_ui_worker, :miq_server => local, :pid => 80_000) } - let!(:generic) { FactoryGirl.create(:miq_generic_worker, :miq_server => remote, :pid => 7_000) } - let!(:refresh) { FactoryGirl.create(:miq_ems_refresh_worker, :miq_server => remote) } + let!(:ui) { FactoryBot.create(:miq_ui_worker, :miq_server => local, :pid => 80_000) } + let!(:generic) { FactoryBot.create(:miq_generic_worker, :miq_server => remote, :pid => 7_000) } + let!(:refresh) { FactoryBot.create(:miq_ems_refresh_worker, :miq_server => remote) } it "displays server status for local and remote servers" do expect(described_class.servers_status([local, remote])).to eq( @@ -62,12 +62,12 @@ end describe ".worker_status" do - let(:local_zone) { FactoryGirl.create(:zone, :name => 'A Zone') } + let(:local_zone) { FactoryBot.create(:zone, :name => 'A Zone') } let(:local) { EvmSpecHelper.local_miq_server(:started_on => 1.hour.ago, :last_heartbeat => 2.days.ago, :zone => local_zone) } let(:remote) { EvmSpecHelper.remote_miq_server(:is_master => true, :last_heartbeat => nil) } - let!(:ui) { FactoryGirl.create(:miq_ui_worker, :miq_server => local, :pid => 80_000) } - let!(:generic) { FactoryGirl.create(:miq_generic_worker, :miq_server => remote, :pid => 7_000) } - let!(:refresh) { FactoryGirl.create(:miq_ems_refresh_worker, :miq_server => remote) } + let!(:ui) { FactoryBot.create(:miq_ui_worker, :miq_server => local, :pid => 80_000) } + let!(:generic) { FactoryBot.create(:miq_generic_worker, :miq_server => remote, :pid => 7_000) } + let!(:refresh) { FactoryBot.create(:miq_ems_refresh_worker, :miq_server => remote) } it "displays worker status for local and remote server" do expect(described_class.workers_status([local, remote])).to eq( @@ -130,13 +130,13 @@ def pad(val, col, adjust = :rjust) val.to_s.send(adjust, send("#{col.downcase}_padding")) end - let(:local_zone) { FactoryGirl.create(:zone, :name => 'A Zone') } + let(:local_zone) { FactoryBot.create(:zone, :name => 'A Zone') } let(:local) { EvmSpecHelper.local_miq_server(:started_on => 1.hour.ago, :last_heartbeat => 2.days.ago, :zone => local_zone) } let(:remote) { EvmSpecHelper.remote_miq_server(:is_master => true, :last_heartbeat => nil) } let(:rgn) { local.region_number } - let!(:ui) { FactoryGirl.create(:miq_ui_worker, :miq_server => local, :pid => 80_000) } - let!(:generic) { FactoryGirl.create(:miq_generic_worker, :miq_server => remote, :pid => 7_000) } - let!(:refresh) { FactoryGirl.create(:miq_ems_refresh_worker, :miq_server => remote) } + let!(:ui) { FactoryBot.create(:miq_ui_worker, :miq_server => local, :pid => 80_000) } + let!(:generic) { FactoryBot.create(:miq_generic_worker, :miq_server => remote, :pid => 7_000) } + let!(:refresh) { FactoryBot.create(:miq_ems_refresh_worker, :miq_server => remote) } let(:local_started_on) { local.started_on.strftime("%H:%M:%S%Z") } let(:local_heartbeat) { local.last_heartbeat.strftime("%Y-%m-%d") } @@ -202,7 +202,7 @@ def pad(val, col, adjust = :rjust) context ".queue_status" do it "calculates oldest and counts" do tgt_time = 2.hours.ago - zone = FactoryGirl.create(:zone) + zone = FactoryBot.create(:zone) MiqQueue.put(:zone => zone.name, :class_name => "X", :method_name => "x", :created_on => 1.hour.ago) MiqQueue.put(:zone => zone.name, :class_name => "X", :method_name => "x", :created_on => tgt_time) MiqQueue.put(:zone => zone.name, @@ -226,8 +226,8 @@ def pad(val, col, adjust = :rjust) it "groups zone together" do tgt_time = 2.hours.ago - zone1 = FactoryGirl.create(:zone, :name => "zone1") - zone2 = FactoryGirl.create(:zone, :name => "zone2") + zone1 = FactoryBot.create(:zone, :name => "zone1") + zone2 = FactoryBot.create(:zone, :name => "zone2") MiqQueue.put(:zone => zone1.name, :class_name => "X", :method_name => "x", :created_on => tgt_time) MiqQueue.put(:zone => zone2.name, :class_name => "X", :method_name => "x", :created_on => tgt_time) expect(described_class.queue_status).to eq( diff --git a/spec/lib/token_store/sql_store_spec.rb b/spec/lib/token_store/sql_store_spec.rb index 901bd0f1d9e..551cfbe78e7 100644 --- a/spec/lib/token_store/sql_store_spec.rb +++ b/spec/lib/token_store/sql_store_spec.rb @@ -17,7 +17,7 @@ it "updates a session if it exists" do store = build_sql_store("TEST") token = SecureRandom.hex - session = FactoryGirl.create( + session = FactoryBot.create( :session, :session_id => "TEST:#{token}", :raw_data => {:expires_on => 1.second.from_now} @@ -33,7 +33,7 @@ it "reads a valid token" do store = build_sql_store("TEST") token = SecureRandom.hex - FactoryGirl.create( + FactoryBot.create( :session, :session_id => "TEST:#{token}", :raw_data => {:userid => "alice", :expires_on => 1.second.from_now} @@ -47,7 +47,7 @@ it "returns nil for an expired token" do store = build_sql_store("TEST") token = SecureRandom.hex - FactoryGirl.create( + FactoryBot.create( :session, :session_id => "TEST:#{token}", :raw_data => {:userid => "alice", :expires_on => 1.second.ago} @@ -72,7 +72,7 @@ it "deletes a token" do store = build_sql_store("TEST") token = SecureRandom.hex - FactoryGirl.create( + FactoryBot.create( :session, :session_id => "TEST:#{token}", :raw_data => {:userid => "alice", :expires_on => 1.hour.from_now} diff --git a/spec/lib/unique_within_region_validator_spec.rb b/spec/lib/unique_within_region_validator_spec.rb index d9f921c9148..8eae64dfd7c 100644 --- a/spec/lib/unique_within_region_validator_spec.rb +++ b/spec/lib/unique_within_region_validator_spec.rb @@ -20,7 +20,7 @@ let(:test_name) { "thename" } let(:in_first_region_id) do - FactoryGirl.create( + FactoryBot.create( :user, :id => case_sensitive_class.id_in_region(1, 0), :name => test_name @@ -28,7 +28,7 @@ end let(:also_in_first_region_id) do - FactoryGirl.create( + FactoryBot.create( :user, :id => case_sensitive_class.id_in_region(2, 0), :name => test_name.upcase @@ -36,7 +36,7 @@ end let(:in_second_region_id) do - FactoryGirl.create( + FactoryBot.create( :user, :id => case_sensitive_class.id_in_region(2, 1), :name => test_name diff --git a/spec/lib/vmdb/settings_spec.rb b/spec/lib/vmdb/settings_spec.rb index ec7515558a6..74cfabc99bb 100644 --- a/spec/lib/vmdb/settings_spec.rb +++ b/spec/lib/vmdb/settings_spec.rb @@ -68,7 +68,7 @@ end describe ".save!" do - let(:miq_server) { FactoryGirl.create(:miq_server) } + let(:miq_server) { FactoryBot.create(:miq_server) } it "does not allow invalid configuration values" do expect do @@ -362,7 +362,7 @@ end describe "save_yaml!" do - let(:miq_server) { FactoryGirl.create(:miq_server) } + let(:miq_server) { FactoryBot.create(:miq_server) } it "saves the settings" do data = {:api => {:token_ttl => "1.day"}}.to_yaml @@ -492,7 +492,7 @@ end describe ".for_resource" do - let(:server) { FactoryGirl.create(:miq_server) } + let(:server) { FactoryBot.create(:miq_server) } it "without database changes" do settings = Vmdb::Settings.for_resource(server) @@ -549,7 +549,7 @@ describe ".for_resource_yaml" do it "fetches the yaml with changes" do - miq_server = FactoryGirl.create(:miq_server) + miq_server = FactoryBot.create(:miq_server) described_class.save!(miq_server, :api => {:token_ttl => "1.day"}) yaml = described_class.for_resource_yaml(miq_server) @@ -564,7 +564,7 @@ password = "pa$$word" encrypted = MiqPassword.encrypt(password) - miq_server = FactoryGirl.create(:miq_server) + miq_server = FactoryBot.create(:miq_server) described_class.save!(miq_server, :authentication => {:bind_pwd => password}) yaml = described_class.for_resource_yaml(miq_server) diff --git a/spec/lib/websocket_adapter_spec.rb b/spec/lib/websocket_adapter_spec.rb index cd3d4daff44..a99756ca6aa 100644 --- a/spec/lib/websocket_adapter_spec.rb +++ b/spec/lib/websocket_adapter_spec.rb @@ -1,6 +1,6 @@ describe WebsocketAdapter do describe '.new' do - let(:record) { FactoryGirl.create(:system_console, :protocol => protocol) } + let(:record) { FactoryBot.create(:system_console, :protocol => protocol) } context 'legacy vcloud console' do let(:protocol) { 'webmks-uint8utf8' } diff --git a/spec/lib/websocket_server_spec.rb b/spec/lib/websocket_server_spec.rb index 70bab32d051..4195c2fa9eb 100644 --- a/spec/lib/websocket_server_spec.rb +++ b/spec/lib/websocket_server_spec.rb @@ -52,7 +52,7 @@ let(:proxy) { subject.instance_variable_get(:@proxy) } let(:protocol) { 'vnc' } let(:url) { 'console/12345' } - let!(:console) { FactoryGirl.create(:system_console, :url_secret => '12345', :protocol => protocol) } + let!(:console) { FactoryBot.create(:system_console, :url_secret => '12345', :protocol => protocol) } let(:init) { subject.send(:init_proxy, env, '12345') } before do diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 3a53882a10e..d0d2103d66b 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -1,9 +1,9 @@ describe Account do - let(:user_account1) { FactoryGirl.create(:account_user) } - let(:group_account1) { FactoryGirl.create(:account_group) } + let(:user_account1) { FactoryBot.create(:account_user) } + let(:group_account1) { FactoryBot.create(:account_group) } context 'when host has users and groups' do - let(:host) { FactoryGirl.create(:host) } + let(:host) { FactoryBot.create(:host) } let(:test_xml) do REXML::Document.new(" @@ -56,7 +56,7 @@ end describe 'group methods' do - let(:user_account2) { FactoryGirl.create(:account_user) } + let(:user_account2) { FactoryBot.create(:account_user) } it '#add_user' do expect(group_account1.add_member(user_account1)).not_to be_empty @@ -81,7 +81,7 @@ end describe 'user methods' do - let(:group_account2) { FactoryGirl.create(:account_group) } + let(:group_account2) { FactoryBot.create(:account_group) } it '#add_group' do expect(user_account1.add_member(group_account1)).not_to be_empty diff --git a/spec/models/assigned_server_role_spec.rb b/spec/models/assigned_server_role_spec.rb index 40c9a60214f..9d82041a24c 100644 --- a/spec/models/assigned_server_role_spec.rb +++ b/spec/models/assigned_server_role_spec.rb @@ -6,7 +6,7 @@ context "Server Role" do before do - @server_role = FactoryGirl.create( + @server_role = FactoryBot.create( :server_role, :name => "smartproxy", :description => "SmartProxy", @@ -16,7 +16,7 @@ ) @priority = AssignedServerRole::DEFAULT_PRIORITY - @assigned_server_role = FactoryGirl.create( + @assigned_server_role = FactoryBot.create( :assigned_server_role, :miq_server_id => @miq_server.id, :server_role_id => @server_role.id, @@ -77,18 +77,18 @@ context "and Server Roles seeded for 1 Region and 2 Zones" do before do - @miq_region = FactoryGirl.create(:miq_region, :region => 1) + @miq_region = FactoryBot.create(:miq_region, :region => 1) allow(MiqRegion).to receive(:my_region).and_return(@miq_region) - @miq_zone1 = FactoryGirl.create(:zone, :name => "Zone 1", :description => "Test Zone One") - @miq_server_11 = FactoryGirl.create(:miq_server, :zone => @miq_zone1) - @miq_server_12 = FactoryGirl.create(:miq_server, :zone => @miq_zone1) + @miq_zone1 = FactoryBot.create(:zone, :name => "Zone 1", :description => "Test Zone One") + @miq_server_11 = FactoryBot.create(:miq_server, :zone => @miq_zone1) + @miq_server_12 = FactoryBot.create(:miq_server, :zone => @miq_zone1) - @miq_zone2 = FactoryGirl.create(:zone, :name => "Zone 2", :description => "Test Zone Two") - @miq_server_21 = FactoryGirl.create(:miq_server, :zone => @miq_zone2) - @miq_server_22 = FactoryGirl.create(:miq_server, :zone => @miq_zone2) + @miq_zone2 = FactoryBot.create(:zone, :name => "Zone 2", :description => "Test Zone Two") + @miq_server_21 = FactoryBot.create(:miq_server, :zone => @miq_zone2) + @miq_server_22 = FactoryBot.create(:miq_server, :zone => @miq_zone2) - @server_role_zu = FactoryGirl.create( + @server_role_zu = FactoryBot.create( :server_role, :name => "zu", :description => "Zone Unlimited", @@ -97,7 +97,7 @@ :role_scope => "zone" ) - @server_role_zl = FactoryGirl.create( + @server_role_zl = FactoryBot.create( :server_role, :name => "zl", :description => "Zone Limited", @@ -106,7 +106,7 @@ :role_scope => "zone" ) - @server_role_ru = FactoryGirl.create( + @server_role_ru = FactoryBot.create( :server_role, :name => "ru", :description => "Region Unlimited", @@ -115,7 +115,7 @@ :role_scope => "region" ) - @server_role_rl = FactoryGirl.create( + @server_role_rl = FactoryBot.create( :server_role, :name => "rl", :description => "Region Limited", @@ -126,7 +126,7 @@ @priority = AssignedServerRole::DEFAULT_PRIORITY - @assigned_server_role_11_zu = FactoryGirl.create( + @assigned_server_role_11_zu = FactoryBot.create( :assigned_server_role, :miq_server_id => @miq_server_11.id, :server_role_id => @server_role_zu.id, @@ -134,7 +134,7 @@ :priority => AssignedServerRole::DEFAULT_PRIORITY ) - @assigned_server_role_11_zl = FactoryGirl.create( + @assigned_server_role_11_zl = FactoryBot.create( :assigned_server_role, :miq_server_id => @miq_server_11.id, :server_role_id => @server_role_zl.id, @@ -142,7 +142,7 @@ :priority => AssignedServerRole::HIGH_PRIORITY ) - @assigned_server_role_11_ru = FactoryGirl.create( + @assigned_server_role_11_ru = FactoryBot.create( :assigned_server_role, :miq_server_id => @miq_server_11.id, :server_role_id => @server_role_ru.id, @@ -150,7 +150,7 @@ :priority => AssignedServerRole::DEFAULT_PRIORITY ) - @assigned_server_role_11_rl = FactoryGirl.create( + @assigned_server_role_11_rl = FactoryBot.create( :assigned_server_role, :miq_server_id => @miq_server_11.id, :server_role_id => @server_role_rl.id, @@ -158,7 +158,7 @@ :priority => AssignedServerRole::DEFAULT_PRIORITY ) - @assigned_server_role_12_zu = FactoryGirl.create( + @assigned_server_role_12_zu = FactoryBot.create( :assigned_server_role, :miq_server_id => @miq_server_12.id, :server_role_id => @server_role_zu.id, @@ -166,7 +166,7 @@ :priority => AssignedServerRole::DEFAULT_PRIORITY ) - @assigned_server_role_12_zl = FactoryGirl.create( + @assigned_server_role_12_zl = FactoryBot.create( :assigned_server_role, :miq_server_id => @miq_server_12.id, :server_role_id => @server_role_zl.id, @@ -174,7 +174,7 @@ :priority => AssignedServerRole::DEFAULT_PRIORITY ) - @assigned_server_role_12_ru = FactoryGirl.create( + @assigned_server_role_12_ru = FactoryBot.create( :assigned_server_role, :miq_server_id => @miq_server_12.id, :server_role_id => @server_role_ru.id, @@ -182,7 +182,7 @@ :priority => AssignedServerRole::DEFAULT_PRIORITY ) - @assigned_server_role_12_rl = FactoryGirl.create( + @assigned_server_role_12_rl = FactoryBot.create( :assigned_server_role, :miq_server_id => @miq_server_12.id, :server_role_id => @server_role_rl.id, @@ -190,7 +190,7 @@ :priority => AssignedServerRole::DEFAULT_PRIORITY ) - @assigned_server_role_21_zu = FactoryGirl.create( + @assigned_server_role_21_zu = FactoryBot.create( :assigned_server_role, :miq_server_id => @miq_server_21.id, :server_role_id => @server_role_zu.id, @@ -198,7 +198,7 @@ :priority => AssignedServerRole::DEFAULT_PRIORITY ) - @assigned_server_role_21_zl = FactoryGirl.create( + @assigned_server_role_21_zl = FactoryBot.create( :assigned_server_role, :miq_server_id => @miq_server_21.id, :server_role_id => @server_role_zl.id, @@ -206,7 +206,7 @@ :priority => AssignedServerRole::DEFAULT_PRIORITY ) - @assigned_server_role_21_ru = FactoryGirl.create( + @assigned_server_role_21_ru = FactoryBot.create( :assigned_server_role, :miq_server_id => @miq_server_21.id, :server_role_id => @server_role_ru.id, @@ -214,7 +214,7 @@ :priority => AssignedServerRole::DEFAULT_PRIORITY ) - @assigned_server_role_21_rl = FactoryGirl.create( + @assigned_server_role_21_rl = FactoryBot.create( :assigned_server_role, :miq_server_id => @miq_server_21.id, :server_role_id => @server_role_rl.id, @@ -222,7 +222,7 @@ :priority => AssignedServerRole::DEFAULT_PRIORITY ) - @assigned_server_role_22_zu = FactoryGirl.create( + @assigned_server_role_22_zu = FactoryBot.create( :assigned_server_role, :miq_server_id => @miq_server_22.id, :server_role_id => @server_role_zu.id, @@ -230,7 +230,7 @@ :priority => AssignedServerRole::DEFAULT_PRIORITY ) - @assigned_server_role_22_zl = FactoryGirl.create( + @assigned_server_role_22_zl = FactoryBot.create( :assigned_server_role, :miq_server_id => @miq_server_22.id, :server_role_id => @server_role_zl.id, @@ -238,7 +238,7 @@ :priority => AssignedServerRole::DEFAULT_PRIORITY ) - @assigned_server_role_22_ru = FactoryGirl.create( + @assigned_server_role_22_ru = FactoryBot.create( :assigned_server_role, :miq_server_id => @miq_server_22.id, :server_role_id => @server_role_ru.id, @@ -246,7 +246,7 @@ :priority => AssignedServerRole::DEFAULT_PRIORITY ) - @assigned_server_role_22_rl = FactoryGirl.create( + @assigned_server_role_22_rl = FactoryBot.create( :assigned_server_role, :miq_server_id => @miq_server_22.id, :server_role_id => @server_role_rl.id, diff --git a/spec/models/async_delete_mixin_spec.rb b/spec/models/async_delete_mixin_spec.rb index ff3adde44d4..98402191c3d 100644 --- a/spec/models/async_delete_mixin_spec.rb +++ b/spec/models/async_delete_mixin_spec.rb @@ -2,7 +2,7 @@ def common_setup(klass) objects = [] 3.times do |i| - obj = FactoryGirl.create(klass, :name => "test_#{klass}_#{i}") + obj = FactoryBot.create(klass, :name => "test_#{klass}_#{i}") objects << obj end diff --git a/spec/models/authentication_spec.rb b/spec/models/authentication_spec.rb index de7268873c2..dd8912acad7 100644 --- a/spec/models/authentication_spec.rb +++ b/spec/models/authentication_spec.rb @@ -22,7 +22,7 @@ context "with an authentication" do let(:pwd_plain) { "smartvm" } - let(:auth) { FactoryGirl.create(:authentication, :password => pwd_plain) } + let(:auth) { FactoryBot.create(:authentication, :password => pwd_plain) } it "should return decrypted password" do expect(auth.password).to eq(pwd_plain) diff --git a/spec/models/authenticator/database_spec.rb b/spec/models/authenticator/database_spec.rb index 782ae843c00..dc1af7ddc06 100644 --- a/spec/models/authenticator/database_spec.rb +++ b/spec/models/authenticator/database_spec.rb @@ -1,7 +1,7 @@ describe Authenticator::Database do subject { Authenticator::Database.new({}) } - let!(:alice) { FactoryGirl.create(:user, :userid => 'alice', :password => 'secret') } - let!(:vincent) { FactoryGirl.create(:user, :userid => 'Vincent', :password => 'secret') } + let!(:alice) { FactoryBot.create(:user, :userid => 'alice', :password => 'secret') } + let!(:vincent) { FactoryBot.create(:user, :userid => 'Vincent', :password => 'secret') } describe '#uses_stored_password?' do it "is true" do diff --git a/spec/models/authenticator/httpd_spec.rb b/spec/models/authenticator/httpd_spec.rb index 161b7499dde..33ff3e6ba30 100644 --- a/spec/models/authenticator/httpd_spec.rb +++ b/spec/models/authenticator/httpd_spec.rb @@ -1,7 +1,7 @@ describe Authenticator::Httpd do subject { Authenticator::Httpd.new(config) } - let!(:alice) { FactoryGirl.create(:user, :userid => 'alice') } - let!(:cheshire) { FactoryGirl.create(:user, :userid => 'cheshire@example.com') } + let!(:alice) { FactoryBot.create(:user, :userid => 'alice') } + let!(:cheshire) { FactoryBot.create(:user, :userid => 'cheshire@example.com') } let(:user_groups) { 'wibble@fqdn:bubble@fqdn' } let(:config) { {:httpd_role => false} } let(:request) do @@ -28,8 +28,8 @@ end before do - FactoryGirl.create(:miq_group, :description => 'wibble') - FactoryGirl.create(:miq_group, :description => 'wobble') + FactoryBot.create(:miq_group, :description => 'wibble') + FactoryBot.create(:miq_group, :description => 'wobble') allow(MiqLdap).to receive(:using_ldap?) { false } end @@ -48,7 +48,7 @@ describe '#lookup_by_identity' do let(:dn) { 'cn=towmater,ou=people,ou=prod,dc=example,dc=com' } - let!(:towmater_dn) { FactoryGirl.create(:user, :userid => dn) } + let!(:towmater_dn) { FactoryBot.create(:user, :userid => dn) } let(:headers) do { @@ -108,7 +108,7 @@ let(:identity_upn) { [user_attrs_upn, %w(mumble bumble bee)] } - let(:upn_sal) { FactoryGirl.create(:user, :userid => 'sal@example.com') } + let(:upn_sal) { FactoryBot.create(:user, :userid => 'sal@example.com') } before do upn_sal @@ -273,9 +273,9 @@ def authenticate end context "when user record with userid in upn format already exists" do - let!(:sally_username) { FactoryGirl.create(:user, :userid => 'sAlly') } - let!(:sally_dn) { FactoryGirl.create(:user, :userid => dn) } - let!(:sally_upn) { FactoryGirl.create(:user, :userid => 'sAlly@example.com') } + let!(:sally_username) { FactoryBot.create(:user, :userid => 'sAlly') } + let!(:sally_dn) { FactoryBot.create(:user, :userid => dn) } + let!(:sally_upn) { FactoryBot.create(:user, :userid => 'sAlly@example.com') } it "leaves user record with userid in username format unchanged" do expect(-> { authenticate }).to_not change { sally_username.reload.userid } @@ -293,17 +293,17 @@ def authenticate context "when user record with userid in upn format does not already exists" do it "updates userid from username format to upn format" do - sally_username = FactoryGirl.create(:user, :userid => 'sally') + sally_username = FactoryBot.create(:user, :userid => 'sally') expect(-> { authenticate }).to change { sally_username.reload.userid }.from("sally").to("sally@example.com") end it "updates userid from distinguished name format to upn format" do - sally_dn = FactoryGirl.create(:user, :userid => dn) + sally_dn = FactoryBot.create(:user, :userid => dn) expect(-> { authenticate }).to change { sally_dn.reload.userid }.from(dn).to("sally@example.com") end it "does not modify userid if already in upn format" do - sally_upn = FactoryGirl.create(:user, :userid => 'sally@example.com') + sally_upn = FactoryBot.create(:user, :userid => 'sally@example.com') expect(-> { authenticate }).to_not change { sally_upn.reload.userid } end end @@ -314,17 +314,17 @@ def authenticate let(:other_region_id) { other_region * ApplicationRecord.rails_sequence_factor + 1 } it "does not modify the user record when userid is in username format" do - sally_username = FactoryGirl.create(:user, :userid => 'sally', :id => other_region_id) + sally_username = FactoryBot.create(:user, :userid => 'sally', :id => other_region_id) expect(-> { authenticate }).to_not change { sally_username.reload.userid } end it "does not modify the user record when userid is in distinguished name format" do - sally_dn = FactoryGirl.create(:user, :userid => dn, :id => other_region_id) + sally_dn = FactoryBot.create(:user, :userid => dn, :id => other_region_id) expect(-> { authenticate }).to_not change { sally_dn.reload.userid } end it "does not modify the user record when userid is in already upn format" do - sally_upn = FactoryGirl.create(:user, :userid => 'sally@example.com', :id => other_region_id) + sally_upn = FactoryBot.create(:user, :userid => 'sally@example.com', :id => other_region_id) expect(-> { authenticate }).to_not change { sally_upn.reload.userid } end end @@ -518,7 +518,7 @@ def authenticate end context "with a userid record in mixed case" do - let!(:testuser_mixedcase) { FactoryGirl.create(:user, :userid => 'TestUser') } + let!(:testuser_mixedcase) { FactoryBot.create(:user, :userid => 'TestUser') } let(:username) { 'testuser' } let(:headers) do super().merge('X-Remote-User-FullName' => 'Test User', diff --git a/spec/models/authenticator/ldap_spec.rb b/spec/models/authenticator/ldap_spec.rb index 1ec6bbbe4c3..2b7c3f4740c 100644 --- a/spec/models/authenticator/ldap_spec.rb +++ b/spec/models/authenticator/ldap_spec.rb @@ -1,6 +1,6 @@ describe Authenticator::Ldap do subject { Authenticator::Ldap.new(config) } - let!(:alice) { FactoryGirl.create(:user, :userid => 'alice') } + let!(:alice) { FactoryBot.create(:user, :userid => 'alice') } let(:config) do { :ldap_role => false, @@ -57,8 +57,8 @@ def normalize(dn) end before do - FactoryGirl.create(:miq_group, :description => 'wibble') - FactoryGirl.build_stubbed(:miq_group, :description => 'wobble') + FactoryBot.create(:miq_group, :description => 'wibble') + FactoryBot.build_stubbed(:miq_group, :description => 'wobble') end let(:user_data) do diff --git a/spec/models/authenticator_spec.rb b/spec/models/authenticator_spec.rb index 30c35c8c28b..3b2b6ea9892 100644 --- a/spec/models/authenticator_spec.rb +++ b/spec/models/authenticator_spec.rb @@ -16,9 +16,9 @@ describe '#authorize' do let(:authenticator) { Authenticator::Httpd.new({}) } - let(:user) { FactoryGirl.create(:user_with_group) } - let(:task) { FactoryGirl.create(:miq_task) } - let(:groups) { FactoryGirl.create_list(:miq_group, 2) } + let(:user) { FactoryBot.create(:user_with_group) } + let(:task) { FactoryBot.create(:miq_task) } + let(:groups) { FactoryBot.create_list(:miq_group, 2) } before do EvmSpecHelper.create_guid_miq_server_zone @@ -45,7 +45,7 @@ let(:authenticator) { Authenticator::Httpd.new({}) } def create_groups(group_descriptions) - group_descriptions.each { |d| FactoryGirl.create(:miq_group, :description => d) } + group_descriptions.each { |d| FactoryBot.create(:miq_group, :description => d) } end it "returns external groups matching internal ones" do @@ -67,11 +67,11 @@ def create_groups(group_descriptions) end it "only returns matched group for the current region" do - FactoryGirl.create(:miq_group, + FactoryBot.create(:miq_group, :description => "group2", :id => ApplicationRecord.id_in_region(1, ApplicationRecord.my_region_number + 1)) - FactoryGirl.create(:miq_group, :description => "group1") - group2 = FactoryGirl.create(:miq_group, :description => "group2") + FactoryBot.create(:miq_group, :description => "group1") + group2 = FactoryBot.create(:miq_group, :description => "group2") matched_groups = authenticator.send(:match_groups, %w(group2)) expect(MiqGroup.where(:description => "group2").count).to eq(2) diff --git a/spec/models/automate_workspace_spec.rb b/spec/models/automate_workspace_spec.rb index e438c7ac800..26d4cc7f925 100644 --- a/spec/models/automate_workspace_spec.rb +++ b/spec/models/automate_workspace_spec.rb @@ -1,6 +1,6 @@ describe AutomateWorkspace do describe "#merge_output!" do - let(:aw) { FactoryGirl.create(:automate_workspace, :input => input) } + let(:aw) { FactoryBot.create(:automate_workspace, :input => input) } let(:password) { "ca$hc0w" } let(:encrypted) { MiqPassword.encrypt(password) } let(:input) do diff --git a/spec/models/automation_request_spec.rb b/spec/models/automation_request_spec.rb index 72734076dcd..f9e27e7b84d 100644 --- a/spec/models/automation_request_spec.rb +++ b/spec/models/automation_request_spec.rb @@ -1,9 +1,9 @@ describe AutomationRequest do - let(:admin) { FactoryGirl.create(:user, :role => "admin") } + let(:admin) { FactoryBot.create(:user, :role => "admin") } before do allow(MiqServer).to receive(:my_zone).and_return(Zone.seed.name) - @zone = FactoryGirl.create(:zone, :name => "fred") - @approver = FactoryGirl.create(:user_miq_request_approver) + @zone = FactoryBot.create(:zone, :name => "fred") + @approver = FactoryBot.create(:user_miq_request_approver) @version = 1 @ae_instance = "IIII" @@ -107,7 +107,7 @@ end context ".create_from_scheduled_task" do - let(:admin) { FactoryGirl.create(:user_miq_request_approver) } + let(:admin) { FactoryBot.create(:user_miq_request_approver) } it "with prescheduled task" do ar = described_class.create_from_scheduled_task(admin, @uri_parts, @parameters) diff --git a/spec/models/automation_task_spec.rb b/spec/models/automation_task_spec.rb index 6e57cf1de7d..9f60a4abe83 100644 --- a/spec/models/automation_task_spec.rb +++ b/spec/models/automation_task_spec.rb @@ -1,7 +1,7 @@ describe AutomationTask do before do allow(MiqServer).to receive(:my_zone).and_return("default") - @admin = FactoryGirl.create(:user_admin) + @admin = FactoryBot.create(:user_admin) @ae_instance = "IIII" @ae_message = "MMMM" @@ -11,8 +11,8 @@ @attrs = {:var1 => @ae_var1, :var2 => @ae_var2, :var3 => @ae_var3, :userid => @admin.userid} @options = {:attrs => @attrs, :instance => @instance, :message => @message, :user_id => @admin.id, :delivered_on => Time.now.utc.to_s} - @at = FactoryGirl.create(:automation_task, :state => 'pending', :status => 'Ok', :userid => @admin.userid, :options => @options) - @ar = FactoryGirl.create(:automation_request) + @at = FactoryBot.create(:automation_task, :state => 'pending', :status => 'Ok', :userid => @admin.userid, :options => @options) + @ar = FactoryBot.create(:automation_request) @ar.automation_tasks << @at @ar.save! end diff --git a/spec/models/availability_zone_spec.rb b/spec/models/availability_zone_spec.rb index f7af8d1258b..851f9847b83 100644 --- a/spec/models/availability_zone_spec.rb +++ b/spec/models/availability_zone_spec.rb @@ -1,15 +1,15 @@ describe AvailabilityZone do it ".available" do - FactoryGirl.create(:availability_zone_amazon) - FactoryGirl.create(:availability_zone_openstack) - FactoryGirl.create(:availability_zone_openstack_null) + FactoryBot.create(:availability_zone_amazon) + FactoryBot.create(:availability_zone_openstack) + FactoryBot.create(:availability_zone_openstack_null) expect(described_class.available.length).to eq(2) described_class.available.each { |az| expect(az.class).not_to eq(ManageIQ::Providers::Openstack::CloudManager::AvailabilityZoneNull) } end it ".event_where_clause" do - zone = FactoryGirl.create(:availability_zone_amazon) + zone = FactoryBot.create(:availability_zone_amazon) expect(zone.event_where_clause).not_to be nil expect(EmsEvent.where(zone.event_where_clause).length).to eq(0) end diff --git a/spec/models/binary_blob_part_spec.rb b/spec/models/binary_blob_part_spec.rb index b3ff3b71c42..0835bb620f0 100644 --- a/spec/models/binary_blob_part_spec.rb +++ b/spec/models/binary_blob_part_spec.rb @@ -2,7 +2,7 @@ describe BinaryBlobPart do context "#data= and #data" do - let(:part) { FactoryGirl.build(:binary_blob_part) } + let(:part) { FactoryBot.build(:binary_blob_part) } subject do part.data = @data diff --git a/spec/models/binary_blob_spec.rb b/spec/models/binary_blob_spec.rb index c6c66ee66cd..dd09216408c 100644 --- a/spec/models/binary_blob_spec.rb +++ b/spec/models/binary_blob_spec.rb @@ -2,7 +2,7 @@ describe BinaryBlob do context "#binary= and #binary" do - before { @blob = FactoryGirl.build(:binary_blob, :name => "test") } + before { @blob = FactoryBot.build(:binary_blob, :name => "test") } subject do @blob.binary = @data.dup # binary= is descructive (it changes the object passed to it) @@ -47,7 +47,7 @@ end context "#dump_binary" do - before { @blob = FactoryGirl.build(:binary_blob, :name => "test") } + before { @blob = FactoryBot.build(:binary_blob, :name => "test") } subject do @blob.binary = @data.dup @@ -77,7 +77,7 @@ describe "serializing and deserializing data" do it "can store and load data as YAML" do - bb = FactoryGirl.build(:binary_blob) + bb = FactoryBot.build(:binary_blob) data = "foo" bb.store_data("YAML", data) @@ -86,7 +86,7 @@ end it "can store and load Marshaled data" do - bb = FactoryGirl.build(:binary_blob) + bb = FactoryBot.build(:binary_blob) data = "foo" bb.store_data("Marshal", data) @@ -97,12 +97,12 @@ describe "#serializer" do it "returns YAML if the data_type is YAML" do - bb = FactoryGirl.build(:binary_blob, :data_type => "YAML") + bb = FactoryBot.build(:binary_blob, :data_type => "YAML") expect(bb.serializer).to be(YAML) end it "returns Marshal if data_type is not YAML" do - bb = FactoryGirl.build(:binary_blob, :data_type => "unknown") + bb = FactoryBot.build(:binary_blob, :data_type => "unknown") expect(bb.serializer).to be(Marshal) end end diff --git a/spec/models/blacklisted_event_spec.rb b/spec/models/blacklisted_event_spec.rb index ed9c5831a43..bb901bd5989 100644 --- a/spec/models/blacklisted_event_spec.rb +++ b/spec/models/blacklisted_event_spec.rb @@ -22,8 +22,8 @@ end it 'does not re-seed existing event filters' do - User.current_user = FactoryGirl.create(:user) - filter = FactoryGirl.create(:blacklisted_event, + User.current_user = FactoryBot.create(:user) + filter = FactoryBot.create(:blacklisted_event, :event_name => 'AlarmActionTriggeredEvent', :provider_model => 'ManageIQ::Providers::Vmware::InfraManager' ) @@ -35,8 +35,8 @@ end it '#enabled=' do - User.current_user = FactoryGirl.create(:user) - f = FactoryGirl.create(:blacklisted_event, :event_name => 'event_1') + User.current_user = FactoryBot.create(:user) + f = FactoryBot.create(:blacklisted_event, :event_name => 'event_1') expect(f.enabled).to be_truthy f.enabled = false diff --git a/spec/models/bottleneck_event_spec.rb b/spec/models/bottleneck_event_spec.rb index f38de8fded5..e68983372bd 100644 --- a/spec/models/bottleneck_event_spec.rb +++ b/spec/models/bottleneck_event_spec.rb @@ -8,68 +8,68 @@ describe ".event_where_clause" do it "queries enterprises" do - ent = FactoryGirl.create(:miq_enterprise) + ent = FactoryBot.create(:miq_enterprise) query = described_class.event_where_clause(ent) expect(query).to match(/resource_type = 'MiqEnterprise'/) end it "queries enterprises with ems" do - ent = FactoryGirl.create(:miq_enterprise) - FactoryGirl.create(:ext_management_system) + ent = FactoryBot.create(:miq_enterprise) + FactoryBot.create(:ext_management_system) query = described_class.event_where_clause(ent) expect(query).to match(/resource_type = 'MiqEnterprise'.*resource_type = 'ExtManagementSystem'/) end it "queries enterprises with storage" do - ent = FactoryGirl.create(:miq_enterprise) - FactoryGirl.create(:storage) + ent = FactoryBot.create(:miq_enterprise) + FactoryBot.create(:storage) query = described_class.event_where_clause(ent) expect(query).to match(/resource_type = 'MiqEnterprise'.*resource_type = 'Storage'/) end it "queries regions" do - reg = FactoryGirl.create(:miq_region) + reg = FactoryBot.create(:miq_region) query = described_class.event_where_clause(reg) expect(query).to match(/resource_type = 'MiqRegion'/) end it "queries regions with ems" do - reg = FactoryGirl.create(:miq_region) - FactoryGirl.create(:ext_management_system) + reg = FactoryBot.create(:miq_region) + FactoryBot.create(:ext_management_system) query = described_class.event_where_clause(reg) expect(query).to match(/resource_type = 'MiqRegion'.*resource_type = 'ExtManagementSystem'/) end it "queries regions with storage" do - reg = FactoryGirl.create(:miq_region) - FactoryGirl.create(:storage) + reg = FactoryBot.create(:miq_region) + FactoryBot.create(:storage) query = described_class.event_where_clause(reg) expect(query).to match(/resource_type = 'MiqRegion'.*resource_type = 'Storage'/) end it "queries ems" do - ems = FactoryGirl.create(:ext_management_system) + ems = FactoryBot.create(:ext_management_system) query = described_class.event_where_clause(ems) expect(query).to match(/resource_type = 'ExtManagementSystem'/) end it "queries ems with cluster" do - ems = FactoryGirl.create(:ext_management_system) - FactoryGirl.create(:ems_cluster, :ext_management_system => ems) + ems = FactoryBot.create(:ext_management_system) + FactoryBot.create(:ems_cluster, :ext_management_system => ems) query = described_class.event_where_clause(ems) expect(query).to match(/resource_type = 'ExtManagementSystem'.*resource_type = 'EmsCluster'/) end it "queries ems with host" do - ems = FactoryGirl.create(:ext_management_system) - FactoryGirl.create(:host, :ext_management_system => ems) + ems = FactoryBot.create(:ext_management_system) + FactoryBot.create(:host, :ext_management_system => ems) query = described_class.event_where_clause(ems) expect(query).to match(/resource_type = 'ExtManagementSystem'.*resource_type = 'Host'/) end it "queries cluster with host" do - cluster = FactoryGirl.create(:ems_cluster) - FactoryGirl.create(:host, :ems_cluster => cluster) + cluster = FactoryBot.create(:ems_cluster) + FactoryBot.create(:host, :ems_cluster => cluster) query = described_class.event_where_clause(cluster) expect(query).to match(/resource_type = 'EmsCluster'.*resource_type = 'Host'/) end @@ -77,7 +77,7 @@ describe ".last_created_on" do subject { described_class.last_created_on(resource) } - let(:resource) { FactoryGirl.create(resource_name) } + let(:resource) { FactoryBot.create(resource_name) } let!(:bottleneck_event) { BottleneckEvent.create!(:resource => resource) } context "for a host_redhat resource" do @@ -107,7 +107,7 @@ end describe ".delete_future_events_for_obj" do - let(:resource) { FactoryGirl.create(resource_name) } + let(:resource) { FactoryBot.create(resource_name) } let!(:bottleneck_event) { BottleneckEvent.create!(:resource => resource, :future => true) } before { BottleneckEvent.delete_future_events_for_obj(resource) } diff --git a/spec/models/category_spec.rb b/spec/models/category_spec.rb index 37f59256110..728ece6f8c9 100644 --- a/spec/models/category_spec.rb +++ b/spec/models/category_spec.rb @@ -1,10 +1,10 @@ describe Category do describe "#tags" do it "works" do - clergy = FactoryGirl.create(:classification, :name => "clergy", :single_value => 1) - clergy_bishop = FactoryGirl.create(:classification_tag, :name => "bishop", :parent => clergy) - chess = FactoryGirl.create(:classification, :name => "chess", :single_value => 1) - chess_bishop = FactoryGirl.create(:classification_tag, :name => "bishop", :parent => chess) + clergy = FactoryBot.create(:classification, :name => "clergy", :single_value => 1) + clergy_bishop = FactoryBot.create(:classification_tag, :name => "bishop", :parent => clergy) + chess = FactoryBot.create(:classification, :name => "chess", :single_value => 1) + chess_bishop = FactoryBot.create(:classification_tag, :name => "bishop", :parent => chess) cat_cl = Category.find_by(:id => clergy.id) tag_clb = clergy_bishop.tag diff --git a/spec/models/chargeable_field_spec.rb b/spec/models/chargeable_field_spec.rb index 852f27d247d..d50c9e4b088 100644 --- a/spec/models/chargeable_field_spec.rb +++ b/spec/models/chargeable_field_spec.rb @@ -2,7 +2,7 @@ describe '#rate_name' do let(:source) { 'used' } let(:group) { 'cpu' } - let(:field) { FactoryGirl.build(:chargeable_field, :source => source, :group => group) } + let(:field) { FactoryBot.build(:chargeable_field, :source => source, :group => group) } subject { field.send :rate_name } it { is_expected.to eq("#{group}_#{source}") } end diff --git a/spec/models/chargeback/consumption_with_rollups_spec.rb b/spec/models/chargeback/consumption_with_rollups_spec.rb index c5f94228178..cc146e47158 100644 --- a/spec/models/chargeback/consumption_with_rollups_spec.rb +++ b/spec/models/chargeback/consumption_with_rollups_spec.rb @@ -1,13 +1,13 @@ describe Chargeback::ConsumptionWithRollups do - let(:vm) { FactoryGirl.create(:vm_microsoft) } + let(:vm) { FactoryBot.create(:vm_microsoft) } let(:consumption) { described_class.new(pluck_rollup([metric_rollup]), starting_date, starting_date + 1.day) } describe '#sub_metric_rollups' do let(:starting_date) { Time.parse('2012-09-01 23:59:59Z').utc } let(:sub_metric) { 'ssd' } - let(:ssd_volume) { FactoryGirl.create(:cloud_volume_openstack, :volume_type => sub_metric) } - let!(:state) { FactoryGirl.create(:vim_performance_state, :resource => vm, :state_data => nil, :timestamp => starting_date, :capture_interval => 3_600) } - let!(:metric_rollup) { FactoryGirl.create(:metric_rollup_vm_hr, :timestamp => starting_date + 1.hour, :resource => vm) } + let(:ssd_volume) { FactoryBot.create(:cloud_volume_openstack, :volume_type => sub_metric) } + let!(:state) { FactoryBot.create(:vim_performance_state, :resource => vm, :state_data => nil, :timestamp => starting_date, :capture_interval => 3_600) } + let!(:metric_rollup) { FactoryBot.create(:metric_rollup_vm_hr, :timestamp => starting_date + 1.hour, :resource => vm) } def pluck_rollup(metric_rollup_records) metric_rollup_records.pluck(*ChargeableField.cols_on_metric_rollup) @@ -47,13 +47,13 @@ def pluck_rollup(metric_rollup_records) end end - let(:ems) { FactoryGirl.build(:ems_vmware) } + let(:ems) { FactoryBot.build(:ems_vmware) } context "Containers" do describe "#tag_list_with_prefix" do - let(:tag) { FactoryGirl.create(:tag, :name => "/managed/operations/analysis_failed") } - let(:vm) { FactoryGirl.create(:vm_vmware, :tags => [tag]) } - let(:metric_rollup) { FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm, :tag_names => "environment/prod|environment/dev") } + let(:tag) { FactoryBot.create(:tag, :name => "/managed/operations/analysis_failed") } + let(:vm) { FactoryBot.create(:vm_vmware, :tags => [tag]) } + let(:metric_rollup) { FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :tag_names => "environment/prod|environment/dev") } let(:consumption) { described_class.new(pluck_rollup([metric_rollup]), starting_date, starting_date + 1.day) } it 'returns array of tags' do @@ -65,15 +65,15 @@ def pluck_rollup(metric_rollup_records) context "Containers" do describe "#tag_list_with_prefix" do let(:timestamp) { Time.parse('2012-09-01 23:59:59Z').utc } - let(:vim_performance_state) { FactoryGirl.create(:vim_performance_state, :timestamp => timestamp, :image_tag_names => "environment/stage") } - - let(:image) { FactoryGirl.create(:container_image, :ext_management_system => ems, :docker_labels => [label]) } - let(:label) { FactoryGirl.create(:custom_attribute, :name => "version/1.2/_label-1", :value => "test/1.0.0 rc_2", :section => 'docker_labels') } - let(:project) { FactoryGirl.create(:container_project, :name => "my project", :ext_management_system => ems) } - let(:node) { FactoryGirl.create(:container_node, :name => "node") } - let(:group) { FactoryGirl.create(:container_group, :ext_management_system => ems, :container_project => project, :container_node => node) } - let(:container) { FactoryGirl.create(:kubernetes_container, :container_group => group, :container_image => image, :vim_performance_states => [vim_performance_state]) } - let(:metric_rollup_container) { FactoryGirl.create(:metric_rollup_vm_hr, :timestamp => timestamp, :resource => container, :tag_names => "environment/cont|environment/cust") } + let(:vim_performance_state) { FactoryBot.create(:vim_performance_state, :timestamp => timestamp, :image_tag_names => "environment/stage") } + + let(:image) { FactoryBot.create(:container_image, :ext_management_system => ems, :docker_labels => [label]) } + let(:label) { FactoryBot.create(:custom_attribute, :name => "version/1.2/_label-1", :value => "test/1.0.0 rc_2", :section => 'docker_labels') } + let(:project) { FactoryBot.create(:container_project, :name => "my project", :ext_management_system => ems) } + let(:node) { FactoryBot.create(:container_node, :name => "node") } + let(:group) { FactoryBot.create(:container_group, :ext_management_system => ems, :container_project => project, :container_node => node) } + let(:container) { FactoryBot.create(:kubernetes_container, :container_group => group, :container_image => image, :vim_performance_states => [vim_performance_state]) } + let(:metric_rollup_container) { FactoryBot.create(:metric_rollup_vm_hr, :timestamp => timestamp, :resource => container, :tag_names => "environment/cont|environment/cust") } let(:consumption) { described_class.new(pluck_rollup([metric_rollup_container]), starting_date, starting_date + 1.day) } it 'returns array of tags' do diff --git a/spec/models/chargeback/consumption_without_rollups_spec.rb b/spec/models/chargeback/consumption_without_rollups_spec.rb index cf48475d417..fa4e7196237 100644 --- a/spec/models/chargeback/consumption_without_rollups_spec.rb +++ b/spec/models/chargeback/consumption_without_rollups_spec.rb @@ -3,12 +3,12 @@ let(:mem_mb) { 1777 } let(:disk_size) { 12_345 } let(:hardware) do - FactoryGirl.build(:hardware, + FactoryBot.build(:hardware, :cpu_total_cores => cores, :memory_mb => mem_mb, - :disks => [FactoryGirl.build(:disk, :size => disk_size)]) + :disks => [FactoryBot.build(:disk, :size => disk_size)]) end - let(:vm) { FactoryGirl.build(:vm_microsoft, :hardware => hardware) } + let(:vm) { FactoryBot.build(:vm_microsoft, :hardware => hardware) } let(:consumption) { described_class.new(vm, nil, nil) } describe '#avg' do diff --git a/spec/models/chargeback_container_image_spec.rb b/spec/models/chargeback_container_image_spec.rb index 2b9cd3986b6..d3476935959 100644 --- a/spec/models/chargeback_container_image_spec.rb +++ b/spec/models/chargeback_container_image_spec.rb @@ -11,7 +11,7 @@ let(:month_beginning) { ts.beginning_of_month.utc } let(:month_end) { ts.end_of_month.utc } let(:hours_in_month) { Time.days_in_month(month_beginning.month, month_beginning.year) * 24 } - let(:ems) { FactoryGirl.create(:ems_openshift) } + let(:ems) { FactoryBot.create(:ems_openshift) } let(:hourly_variable_tier_rate) { {:variable_rate => hourly_rate.to_s} } let(:count_hourly_variable_tier_rate) { {:variable_rate => count_hourly_rate.to_s} } @@ -25,7 +25,7 @@ end let!(:chargeback_rate) do - FactoryGirl.create(:chargeback_rate, :detail_params => detail_params) + FactoryBot.create(:chargeback_rate, :detail_params => detail_params) end let(:metric_rollup_params) { {:parent_ems_id => ems.id, :tag_names => ""} } @@ -37,16 +37,16 @@ MiqEnterprise.seed EvmSpecHelper.create_guid_miq_server_zone - @node = FactoryGirl.create(:container_node, :name => "node") - @image = FactoryGirl.create(:container_image, :ext_management_system => ems) - @label = FactoryGirl.build(:custom_attribute, :name => "version/1.2/_label-1", :value => "test/1.0.0 rc_2", :section => 'docker_labels') - @project = FactoryGirl.create(:container_project, :name => "my project", :ext_management_system => ems) - @group = FactoryGirl.create(:container_group, :ext_management_system => ems, :container_project => @project, + @node = FactoryBot.create(:container_node, :name => "node") + @image = FactoryBot.create(:container_image, :ext_management_system => ems) + @label = FactoryBot.build(:custom_attribute, :name => "version/1.2/_label-1", :value => "test/1.0.0 rc_2", :section => 'docker_labels') + @project = FactoryBot.create(:container_project, :name => "my project", :ext_management_system => ems) + @group = FactoryBot.create(:container_group, :ext_management_system => ems, :container_project => @project, :container_node => @node) - @container = FactoryGirl.create(:kubernetes_container, :container_group => @group, :container_image => @image, + @container = FactoryBot.create(:kubernetes_container, :container_group => @group, :container_image => @image, :limit_memory_bytes => 1.megabytes, :limit_cpu_cores => 1.0) - cat = FactoryGirl.create(:classification, :description => "Environment", :name => "environment", :single_value => true, :show => true) - c = FactoryGirl.create(:classification, :name => "prod", :description => "Production", :parent_id => cat.id) + cat = FactoryBot.create(:classification, :description => "Environment", :name => "environment", :single_value => true, :show => true) + c = FactoryBot.create(:classification, :name => "prod", :description => "Production", :parent_id => cat.id) ChargebackRate.set_assignments(:compute, [{ :cb_rate => chargeback_rate, :tag => [c, "container_image"] }]) @tag = c.tag @@ -70,7 +70,7 @@ add_metric_rollups_for(@container, month_beginning...month_end, 12.hours, metric_rollup_params) Range.new(start_time, finish_time, true).step_value(1.hour).each do |t| - @container.vim_performance_states << FactoryGirl.create(:vim_performance_state, + @container.vim_performance_states << FactoryBot.create(:vim_performance_state, :timestamp => t, :image_tag_names => "environment/prod") end @@ -107,7 +107,7 @@ add_metric_rollups_for(@container, month_beginning...month_end, 12.hours, metric_rollup_params) Range.new(month_beginning, month_end, true).step_value(12.hours).each do |time| - @container.vim_performance_states << FactoryGirl.create(:vim_performance_state, + @container.vim_performance_states << FactoryBot.create(:vim_performance_state, :timestamp => time, :image_tag_names => "environment/prod") end @@ -138,7 +138,7 @@ add_metric_rollups_for(@container, month_beginning...month_end, 12.hours, metric_rollup_params) Range.new(month_beginning, month_end, true).step_value(12.hours).each do |time| - @container.vim_performance_states << FactoryGirl.create(:vim_performance_state, + @container.vim_performance_states << FactoryBot.create(:vim_performance_state, :timestamp => time, :image_tag_names => "") end diff --git a/spec/models/chargeback_container_project_spec.rb b/spec/models/chargeback_container_project_spec.rb index 40f74c415f7..5ffae076eeb 100644 --- a/spec/models/chargeback_container_project_spec.rb +++ b/spec/models/chargeback_container_project_spec.rb @@ -10,7 +10,7 @@ let(:month_beginning) { ts.beginning_of_month.utc } let(:month_end) { ts.end_of_month.utc } let(:hours_in_month) { Time.days_in_month(month_beginning.month, month_beginning.year) * 24 } - let(:ems) {FactoryGirl.create(:ems_openshift) } + let(:ems) {FactoryBot.create(:ems_openshift) } let(:hourly_variable_tier_rate) { {:variable_rate => hourly_rate.to_s} } @@ -24,7 +24,7 @@ end let!(:chargeback_rate) do - FactoryGirl.create(:chargeback_rate, :detail_params => detail_params) + FactoryBot.create(:chargeback_rate, :detail_params => detail_params) end let(:metric_rollup_params) { {:parent_ems_id => ems.id, :tag_names => ""} } @@ -37,14 +37,14 @@ ManageIQ::Showback::InputMeasure.seed EvmSpecHelper.create_guid_miq_server_zone - @project = FactoryGirl.create(:container_project, :name => "my project", :ext_management_system => ems, + @project = FactoryBot.create(:container_project, :name => "my project", :ext_management_system => ems, :created_on => month_beginning) temp = {:cb_rate => chargeback_rate, :object => ems} ChargebackRate.set_assignments(:compute, [temp]) - cat = FactoryGirl.create(:classification, :description => "Environment", :name => "environment", :single_value => true, :show => true) - c = FactoryGirl.create(:classification, :name => "prod", :description => "Production", :parent_id => cat.id) + cat = FactoryBot.create(:classification, :description => "Environment", :name => "environment", :single_value => true, :show => true) + c = FactoryBot.create(:classification, :name => "prod", :description => "Production", :parent_id => cat.id) @tag = c.tag @project.tag_with(@tag.name, :ns => '*') diff --git a/spec/models/chargeback_rate_detail_currency_spec.rb b/spec/models/chargeback_rate_detail_currency_spec.rb index a6f33778a10..09462860e88 100644 --- a/spec/models/chargeback_rate_detail_currency_spec.rb +++ b/spec/models/chargeback_rate_detail_currency_spec.rb @@ -1,17 +1,17 @@ describe ChargebackRateDetailCurrency do it "has a valid factory" do - expect(FactoryGirl.create(:chargeback_rate_detail_currency)).to be_valid + expect(FactoryBot.create(:chargeback_rate_detail_currency)).to be_valid end it "is invalid without a code" do - expect(FactoryGirl.build(:chargeback_rate_detail_currency, :code => nil)).not_to be_valid + expect(FactoryBot.build(:chargeback_rate_detail_currency, :code => nil)).not_to be_valid end it "is invalid without a name" do - expect(FactoryGirl.build(:chargeback_rate_detail_currency, :name => nil)).not_to be_valid + expect(FactoryBot.build(:chargeback_rate_detail_currency, :name => nil)).not_to be_valid end it "is invalid without a full_name" do - expect(FactoryGirl.build(:chargeback_rate_detail_currency, :full_name => nil)).not_to be_valid + expect(FactoryBot.build(:chargeback_rate_detail_currency, :full_name => nil)).not_to be_valid end it "is invalid without a symbol" do - expect(FactoryGirl.build(:chargeback_rate_detail_currency, :symbol => nil)).not_to be_valid + expect(FactoryBot.build(:chargeback_rate_detail_currency, :symbol => nil)).not_to be_valid end end diff --git a/spec/models/chargeback_rate_detail_measure_spec.rb b/spec/models/chargeback_rate_detail_measure_spec.rb index 91accdb8aa8..e738bcc0358 100644 --- a/spec/models/chargeback_rate_detail_measure_spec.rb +++ b/spec/models/chargeback_rate_detail_measure_spec.rb @@ -1,30 +1,30 @@ describe ChargebackRateDetailMeasure do it "has a valid factory" do - expect(FactoryGirl.create(:chargeback_rate_detail_measure)).to be_valid + expect(FactoryBot.create(:chargeback_rate_detail_measure)).to be_valid end it "is invalid without a name" do - expect(FactoryGirl.build(:chargeback_rate_detail_measure, :name => nil)).not_to be_valid + expect(FactoryBot.build(:chargeback_rate_detail_measure, :name => nil)).not_to be_valid end it "is invalid without a step" do - expect(FactoryGirl.build(:chargeback_rate_detail_measure, :step => nil)).not_to be_valid + expect(FactoryBot.build(:chargeback_rate_detail_measure, :step => nil)).not_to be_valid end it "is invalid with a step less than 0" do - expect(FactoryGirl.build(:chargeback_rate_detail_measure, :step => -9)).not_to be_valid + expect(FactoryBot.build(:chargeback_rate_detail_measure, :step => -9)).not_to be_valid end it "is invalid with a empty array units" do - expect(FactoryGirl.build(:chargeback_rate_detail_measure, :units => [])).not_to be_valid + expect(FactoryBot.build(:chargeback_rate_detail_measure, :units => [])).not_to be_valid end it "is invalid with a only one array units" do - expect(FactoryGirl.build(:chargeback_rate_detail_measure, :units => ["KB"])).not_to be_valid + expect(FactoryBot.build(:chargeback_rate_detail_measure, :units => ["KB"])).not_to be_valid end it "is invalid with a units_display lenght diferent that the units lenght" do - expect(FactoryGirl.build(:chargeback_rate_detail_measure, + expect(FactoryBot.build(:chargeback_rate_detail_measure, :units => %w(Bs KBs GBs), :units_display => %w(kbps mbps))).not_to be_valid end diff --git a/spec/models/chargeback_rate_detail_spec.rb b/spec/models/chargeback_rate_detail_spec.rb index b5b2ab34423..e20f25d831f 100644 --- a/spec/models/chargeback_rate_detail_spec.rb +++ b/spec/models/chargeback_rate_detail_spec.rb @@ -1,9 +1,9 @@ describe ChargebackRateDetail do - let(:field) { FactoryGirl.build(:chargeable_field) } + let(:field) { FactoryBot.build(:chargeable_field) } describe "#chargeback_rate" do it "is invalid without a valid chargeback_rate" do invalid_chargeback_rate_id = (ChargebackRate.maximum(:id) || -1) + 1 - chargeback_rate_detail = FactoryGirl.build(:chargeback_rate_detail, + chargeback_rate_detail = FactoryBot.build(:chargeback_rate_detail, :chargeable_field => field, :chargeback_rate_id => invalid_chargeback_rate_id) expect(chargeback_rate_detail).to be_invalid @@ -48,7 +48,7 @@ end context 'when cloud volumes are present' do - let!(:cloud_volumes) { FactoryGirl.create_list(:cloud_volume_openstack, 3) } + let!(:cloud_volumes) { FactoryBot.create_list(:cloud_volume_openstack, 3) } it 'loads chargeback rates with sub metric from CloudVolumes' do rates = ChargebackRateDetail.default_rate_details_for('Storage') @@ -64,11 +64,11 @@ describe "#find_rate" do let(:cvalue) { {"val1" => 0.0, "val2" => 10.0, "val3" => 20.0, "val4" => 50.0} } - let(:cbt1) { FactoryGirl.build(:chargeback_tier, :start => 0, :finish => 10, :fixed_rate => 3.0, :variable_rate => 0.3) } - let(:cbt2) { FactoryGirl.build(:chargeback_tier, :start => 10, :finish => 50, :fixed_rate => 2.0, :variable_rate => 0.2) } - let(:cbt3) { FactoryGirl.build(:chargeback_tier, :start => 50, :finish => Float::INFINITY, :fixed_rate => 1.0, :variable_rate => 0.1) } + let(:cbt1) { FactoryBot.build(:chargeback_tier, :start => 0, :finish => 10, :fixed_rate => 3.0, :variable_rate => 0.3) } + let(:cbt2) { FactoryBot.build(:chargeback_tier, :start => 10, :finish => 50, :fixed_rate => 2.0, :variable_rate => 0.2) } + let(:cbt3) { FactoryBot.build(:chargeback_tier, :start => 50, :finish => Float::INFINITY, :fixed_rate => 1.0, :variable_rate => 0.1) } let(:cbd) do - FactoryGirl.build(:chargeback_rate_detail, :chargeback_tiers => [cbt3, cbt2, cbt1], + FactoryBot.build(:chargeback_rate_detail, :chargeback_tiers => [cbt3, cbt2, cbt1], :chargeable_field => field) end @@ -81,14 +81,14 @@ context 'with rate adjustment' do let(:measure) do - FactoryGirl.build(:chargeback_rate_detail_measure, + FactoryBot.build(:chargeback_rate_detail_measure, :units_display => %w(B KB MB GB TB), :units => %w(bytes kilobytes megabytes gigabytes terabytes)) end - let(:field) { FactoryGirl.create(:chargeable_field_storage_allocated, :detail_measure => measure) } + let(:field) { FactoryBot.create(:chargeable_field_storage_allocated, :detail_measure => measure) } let(:cbd) do # This charges per gigabyte, tiers are per gigabytes - FactoryGirl.build(:chargeback_rate_detail, + FactoryBot.build(:chargeback_rate_detail, :chargeback_tiers => [cbt1, cbt2, cbt3], :chargeable_field => field, :per_unit => 'gigabytes') @@ -113,12 +113,12 @@ tier_finish = Float::INFINITY per_time = 'monthly' per_unit = 'megabytes' - cbd = FactoryGirl.build(:chargeback_rate_detail, + cbd = FactoryBot.build(:chargeback_rate_detail, :chargeable_field => field, :per_time => per_time, :per_unit => per_unit, :enabled => true) - cbt = FactoryGirl.create(:chargeback_tier, + cbt = FactoryBot.create(:chargeback_tier, :chargeback_rate_detail_id => cbd.id, :start => tier_start, :finish => tier_finish, @@ -127,7 +127,7 @@ cbd.update(:chargeback_tiers => [cbt]) expect(cbd.hourly_cost(cvalue, consumption)).to eq(cvalue * cbd.hourly(variable_rate, consumption) + cbd.hourly(fixed_rate, consumption)) - cbd.chargeable_field = FactoryGirl.build(:chargeable_field_fixed_compute_1) + cbd.chargeable_field = FactoryBot.build(:chargeable_field_fixed_compute_1) expect(cbd.hourly_cost(1, consumption)).to eq(cbd.hourly(variable_rate, consumption) + cbd.hourly(fixed_rate, consumption)) cbd.enabled = false @@ -142,7 +142,7 @@ 0.0, 0.00 ].each do |zero| - cbd = FactoryGirl.build(:chargeback_rate_detail, :per_time => 'hourly') + cbd = FactoryBot.build(:chargeback_rate_detail, :per_time => 'hourly') expect(cbd.hourly(zero, consumption)).to eq(0.0) end end @@ -155,18 +155,18 @@ 'monthly', 'megabytes', rate / 24 / 30, 'yearly', 'megabytes', rate / 24 / 365 ].each_slice(3) do |per_time, per_unit, hourly_rate| - cbd = FactoryGirl.build(:chargeback_rate_detail, :per_time => per_time, :per_unit => per_unit) + cbd = FactoryBot.build(:chargeback_rate_detail, :per_time => per_time, :per_unit => per_unit) expect(cbd.hourly(rate, consumption)).to eq(hourly_rate) end end - let(:annual_rate) { FactoryGirl.build(:chargeback_rate_detail, :per_time => 'annually') } + let(:annual_rate) { FactoryBot.build(:chargeback_rate_detail, :per_time => 'annually') } it 'cannot calculate for unknown time interval' do expect { annual_rate.hourly(rate, consumption) }.to raise_error(RuntimeError, "rate time unit of 'annually' not supported") end - let(:monthly_rate) { FactoryGirl.build(:chargeback_rate_detail, :per_time => 'monthly') } + let(:monthly_rate) { FactoryBot.build(:chargeback_rate_detail, :per_time => 'monthly') } let(:weekly_consumption) { Chargeback::ConsumptionWithRollups.new([], Time.current - 1.week, Time.current) } it 'monhtly rate returns correct hourly(_rate) when consumption slice is weekly' do expect(monthly_rate.hourly(rate, weekly_consumption)).to eq(rate / (1.month / 1.hour)) @@ -175,40 +175,40 @@ it "#rate_adjustment" do value = 10.gigabytes - field = FactoryGirl.build(:chargeable_field_memory_allocated) # the core metric is in megabytes + field = FactoryBot.build(:chargeable_field_memory_allocated) # the core metric is in megabytes [ 'megabytes', value, 'gigabytes', value / 1024, ].each_slice(2) do |per_unit, rate_adjustment| - cbd = FactoryGirl.build(:chargeback_rate_detail, :per_unit => per_unit, :chargeable_field => field) + cbd = FactoryBot.build(:chargeback_rate_detail, :per_unit => per_unit, :chargeable_field => field) expect(cbd.rate_adjustment * value).to eq(rate_adjustment) end end it "#friendly_rate" do friendly_rate = "My Rate" - cbd = FactoryGirl.build(:chargeback_rate_detail, :friendly_rate => friendly_rate) + cbd = FactoryBot.build(:chargeback_rate_detail, :friendly_rate => friendly_rate) expect(cbd.friendly_rate).to eq(friendly_rate) - cbd = FactoryGirl.build(:chargeback_rate_detail, + cbd = FactoryBot.build(:chargeback_rate_detail, :per_time => 'monthly', - :chargeable_field => FactoryGirl.build(:chargeable_field_fixed_compute_1)) - cbt = FactoryGirl.create(:chargeback_tier, :start => 0, :chargeback_rate_detail_id => cbd.id, + :chargeable_field => FactoryBot.build(:chargeable_field_fixed_compute_1)) + cbt = FactoryBot.create(:chargeback_tier, :start => 0, :chargeback_rate_detail_id => cbd.id, :finish => Float::INFINITY, :fixed_rate => 1.0, :variable_rate => 2.0) cbd.update(:chargeback_tiers => [cbt]) expect(cbd.friendly_rate).to eq("3.0 Monthly") - cbd = FactoryGirl.build(:chargeback_rate_detail, :per_unit => 'cpu', :per_time => 'monthly', :chargeable_field => field) - cbt = FactoryGirl.create(:chargeback_tier, :start => 0, :chargeback_rate_detail_id => cbd.id, + cbd = FactoryBot.build(:chargeback_rate_detail, :per_unit => 'cpu', :per_time => 'monthly', :chargeable_field => field) + cbt = FactoryBot.create(:chargeback_tier, :start => 0, :chargeback_rate_detail_id => cbd.id, :finish => Float::INFINITY, :fixed_rate => 1.0, :variable_rate => 2.0) cbd.update(:chargeback_tiers => [cbt]) expect(cbd.friendly_rate).to eq("Monthly @ 1.0 + 2.0 per Cpu from 0.0 to Infinity") - cbd = FactoryGirl.build(:chargeback_rate_detail, :per_unit => 'megabytes', :per_time => 'monthly', + cbd = FactoryBot.build(:chargeback_rate_detail, :per_unit => 'megabytes', :per_time => 'monthly', :chargeable_field => field) - cbt1 = FactoryGirl.create(:chargeback_tier, :start => 0.0, :chargeback_rate_detail_id => cbd.id, + cbt1 = FactoryBot.create(:chargeback_tier, :start => 0.0, :chargeback_rate_detail_id => cbd.id, :finish => 5.0, :fixed_rate => 1.0, :variable_rate => 2.0) - cbt2 = FactoryGirl.create(:chargeback_tier, :start => 5.0, :chargeback_rate_detail_id => cbd.id, + cbt2 = FactoryBot.create(:chargeback_tier, :start => 5.0, :chargeback_rate_detail_id => cbd.id, :finish => Float::INFINITY, :fixed_rate => 5.0, :variable_rate => 2.5) cbd.update(:chargeback_tiers => [cbt1, cbt2]) expect(cbd.friendly_rate).to eq("Monthly @ 1.0 + 2.0 per Megabytes from 0.0 to 5.0\n\ @@ -221,33 +221,33 @@ 'cpu', 'Cpu', 'ohms', 'Ohms' ].each_slice(2) do |per_unit, per_unit_display| - cbd = FactoryGirl.build(:chargeback_rate_detail, :per_unit => per_unit, :chargeable_field => field) + cbd = FactoryBot.build(:chargeback_rate_detail, :per_unit => per_unit, :chargeable_field => field) expect(cbd.per_unit_display).to eq(per_unit_display) end end it "#per_unit_display_with_measurements" do - cbdm = FactoryGirl.create(:chargeback_rate_detail_measure, + cbdm = FactoryBot.create(:chargeback_rate_detail_measure, :units_display => %w(B KB MB GB TB), :units => %w(bytes kilobytes megabytes gigabytes terabytes)) - field = FactoryGirl.create(:chargeable_field, :detail_measure => cbdm) - cbd = FactoryGirl.build(:chargeback_rate_detail, :per_unit => 'megabytes', :chargeable_field => field) + field = FactoryBot.create(:chargeable_field, :detail_measure => cbdm) + cbd = FactoryBot.build(:chargeback_rate_detail, :per_unit => 'megabytes', :chargeable_field => field) expect(cbd.per_unit_display).to eq('MB') end it "#rate_type" do rate_type = 'ad-hoc' - cb = FactoryGirl.create(:chargeback_rate, :rate_type => rate_type) - cbd = FactoryGirl.build(:chargeback_rate_detail, :chargeback_rate => cb) + cb = FactoryBot.create(:chargeback_rate, :rate_type => rate_type) + cbd = FactoryBot.build(:chargeback_rate_detail, :chargeback_rate => cb) expect(cbd.rate_type).to eq(rate_type) end it 'is valid without per_unit' do ['cpu', nil].each do |per_unit| - cbd = FactoryGirl.build(:chargeback_rate_detail, + cbd = FactoryBot.build(:chargeback_rate_detail, :chargeable_field => field, :per_unit => per_unit) - cbt = FactoryGirl.create(:chargeback_tier, + cbt = FactoryBot.create(:chargeback_tier, :chargeback_rate_detail_id => cbd.id, :start => 0, :finish => Float::INFINITY, @@ -260,11 +260,11 @@ it "diferents_per_units_rates_should_have_the_same_cost" do # should be the same cost. bytes to megabytes and gigabytes to megabytes - cbd_bytes = FactoryGirl.build(:chargeback_rate_detail, + cbd_bytes = FactoryBot.build(:chargeback_rate_detail, :chargeable_field => field, :per_unit => 'bytes', :per_time => 'monthly') - cbd_gigabytes = FactoryGirl.build(:chargeback_rate_detail, + cbd_gigabytes = FactoryBot.build(:chargeback_rate_detail, :chargeable_field => field, :per_unit => 'gigabytes', :per_time => 'monthly') @@ -272,35 +272,35 @@ end it "#show_rates" do - cbc = FactoryGirl.create(:chargeback_rate_detail_currency, :code => "EUR") + cbc = FactoryBot.create(:chargeback_rate_detail_currency, :code => "EUR") - cbd = FactoryGirl.build(:chargeback_rate_detail_fixed_compute_cost, :detail_currency => cbc) + cbd = FactoryBot.build(:chargeback_rate_detail_fixed_compute_cost, :detail_currency => cbc) expect(cbd.show_rates).to eq("EUR / Day") - cbd = FactoryGirl.build(:chargeback_rate_detail_memory_allocated, :detail_currency => cbc) + cbd = FactoryBot.build(:chargeback_rate_detail_memory_allocated, :detail_currency => cbc) expect(cbd.show_rates).to eq("EUR / Day / MB") end context "tier set correctness" do it "add an initial invalid tier" do - cbt1 = FactoryGirl.build(:chargeback_tier, :start => 0, :finish => 5) - cbd = FactoryGirl.build(:chargeback_rate_detail, :chargeback_tiers => [cbt1]) + cbt1 = FactoryBot.build(:chargeback_tier, :start => 0, :finish => 5) + cbd = FactoryBot.build(:chargeback_rate_detail, :chargeback_tiers => [cbt1]) expect(cbd.contiguous_tiers?).to be false end it "add an initial valid tier" do - cbt1 = FactoryGirl.build(:chargeback_tier, :start => 0, :finish => Float::INFINITY) - cbd = FactoryGirl.build(:chargeback_rate_detail, :chargeback_tiers => [cbt1], :chargeable_field => field) + cbt1 = FactoryBot.build(:chargeback_tier, :start => 0, :finish => Float::INFINITY) + cbd = FactoryBot.build(:chargeback_rate_detail, :chargeback_tiers => [cbt1], :chargeable_field => field) expect(cbd.contiguous_tiers?).to be true end it "add an invalid tier to an existing tier set" do - cbt1 = FactoryGirl.create(:chargeback_tier, :start => 0, :finish => Float::INFINITY) - cbd = FactoryGirl.create(:chargeback_rate_detail, :chargeback_tiers => [cbt1], :chargeable_field => field) + cbt1 = FactoryBot.create(:chargeback_tier, :start => 0, :finish => Float::INFINITY) + cbd = FactoryBot.create(:chargeback_rate_detail, :chargeback_tiers => [cbt1], :chargeable_field => field) - cbt2 = FactoryGirl.build(:chargeback_tier, :start => 6, :finish => Float::INFINITY) + cbt2 = FactoryBot.build(:chargeback_tier, :start => 6, :finish => Float::INFINITY) cbt1.finish = 5 cbd.chargeback_tiers << cbt2 @@ -308,10 +308,10 @@ end it "add a valid tier to an existing tier set" do - cbt1 = FactoryGirl.create(:chargeback_tier, :start => 0, :finish => Float::INFINITY) - cbd = FactoryGirl.create(:chargeback_rate_detail, :chargeback_tiers => [cbt1], :chargeable_field => field) + cbt1 = FactoryBot.create(:chargeback_tier, :start => 0, :finish => Float::INFINITY) + cbd = FactoryBot.create(:chargeback_rate_detail, :chargeback_tiers => [cbt1], :chargeable_field => field) - cbt2 = FactoryGirl.build(:chargeback_tier, :start => 5, :finish => Float::INFINITY) + cbt2 = FactoryBot.build(:chargeback_tier, :start => 5, :finish => Float::INFINITY) cbt1.finish = 5 cbd.chargeback_tiers << cbt2 @@ -319,9 +319,9 @@ end it "remove a tier from an existing tier set, leaving the set invalid" do - cbt1 = FactoryGirl.create(:chargeback_tier, :start => 0, :finish => 5) - cbt2 = FactoryGirl.create(:chargeback_tier, :start => 5, :finish => Float::INFINITY) - cbd = FactoryGirl.create(:chargeback_rate_detail, :chargeback_tiers => [cbt1, cbt2], :chargeable_field => field) + cbt1 = FactoryBot.create(:chargeback_tier, :start => 0, :finish => 5) + cbt2 = FactoryBot.create(:chargeback_tier, :start => 5, :finish => Float::INFINITY) + cbd = FactoryBot.create(:chargeback_rate_detail, :chargeback_tiers => [cbt1, cbt2], :chargeable_field => field) cbd.chargeback_tiers = [cbt1] @@ -329,9 +329,9 @@ end it "remove a tier from an existing set of tiers" do - cbt1 = FactoryGirl.create(:chargeback_tier, :start => 0, :finish => 5) - cbt2 = FactoryGirl.create(:chargeback_tier, :start => 5, :finish => Float::INFINITY) - cbd = FactoryGirl.create(:chargeback_rate_detail, :chargeback_tiers => [cbt1, cbt2], :chargeable_field => field) + cbt1 = FactoryBot.create(:chargeback_tier, :start => 0, :finish => 5) + cbt2 = FactoryBot.create(:chargeback_tier, :start => 5, :finish => Float::INFINITY) + cbd = FactoryBot.create(:chargeback_rate_detail, :chargeback_tiers => [cbt1, cbt2], :chargeable_field => field) cbt1.finish = Float::INFINITY cbd.chargeback_tiers = [cbt1] @@ -340,50 +340,50 @@ end it "remove last tier" do - cbt1 = FactoryGirl.create(:chargeback_tier, :start => 0, :finish => Float::INFINITY) - cbd = FactoryGirl.create(:chargeback_rate_detail, :chargeback_tiers => [cbt1], :chargeable_field => field) + cbt1 = FactoryBot.create(:chargeback_tier, :start => 0, :finish => Float::INFINITY) + cbd = FactoryBot.create(:chargeback_rate_detail, :chargeback_tiers => [cbt1], :chargeable_field => field) cbd.chargeback_tiers = [] expect(cbd.contiguous_tiers?).to be true end it "tiers should contain no gaps" do - cbt1 = FactoryGirl.build(:chargeback_tier, :start => 0, :finish => 5) - cbt2 = FactoryGirl.build(:chargeback_tier, :start => 6, :finish => Float::INFINITY) - cbd = FactoryGirl.build(:chargeback_rate_detail, :chargeback_tiers => [cbt2, cbt1]) + cbt1 = FactoryBot.build(:chargeback_tier, :start => 0, :finish => 5) + cbt2 = FactoryBot.build(:chargeback_tier, :start => 6, :finish => Float::INFINITY) + cbd = FactoryBot.build(:chargeback_rate_detail, :chargeback_tiers => [cbt2, cbt1]) expect(cbd.contiguous_tiers?).to be false end it "must contain one start" do - cbt1 = FactoryGirl.build(:chargeback_tier, :start => 0, :finish => 1) - cbt2 = FactoryGirl.build(:chargeback_tier, :start => 0, :finish => Float::INFINITY) - cbd = FactoryGirl.build(:chargeback_rate_detail, :chargeback_tiers => [cbt2, cbt1]) + cbt1 = FactoryBot.build(:chargeback_tier, :start => 0, :finish => 1) + cbt2 = FactoryBot.build(:chargeback_tier, :start => 0, :finish => Float::INFINITY) + cbd = FactoryBot.build(:chargeback_rate_detail, :chargeback_tiers => [cbt2, cbt1]) expect(cbd).not_to be_valid end it "must start at 0" do - cbt1 = FactoryGirl.build(:chargeback_tier, :start => 1, :finish => 10) - cbt2 = FactoryGirl.build(:chargeback_tier, :start => 10, :finish => Float::INFINITY) - cbd = FactoryGirl.build(:chargeback_rate_detail, :chargeback_tiers => [cbt2, cbt1]) + cbt1 = FactoryBot.build(:chargeback_tier, :start => 1, :finish => 10) + cbt2 = FactoryBot.build(:chargeback_tier, :start => 10, :finish => Float::INFINITY) + cbd = FactoryBot.build(:chargeback_rate_detail, :chargeback_tiers => [cbt2, cbt1]) expect(cbd).not_to be_valid end it "must end at infinity" do - cbt1 = FactoryGirl.build(:chargeback_tier, :start => 0, :finish => 1) - cbt2 = FactoryGirl.build(:chargeback_tier, :start => 1, :finish => 1000) - cbd = FactoryGirl.build(:chargeback_rate_detail, :chargeback_tiers => [cbt2, cbt1]) + cbt1 = FactoryBot.build(:chargeback_tier, :start => 0, :finish => 1) + cbt2 = FactoryBot.build(:chargeback_tier, :start => 1, :finish => 1000) + cbd = FactoryBot.build(:chargeback_rate_detail, :chargeback_tiers => [cbt2, cbt1]) expect(cbd).not_to be_valid expect(cbd.errors[:chargeback_tiers]).to be_present end it "middle tier must not start infinity" do - cbt1 = FactoryGirl.build(:chargeback_tier, :start => 0, :finish => Float::INFINITY) - cbt2 = FactoryGirl.build(:chargeback_tier, :start => Float::INFINITY, :finish => Float::INFINITY) - cbd = FactoryGirl.build(:chargeback_rate_detail, :chargeback_tiers => [cbt2, cbt1]) + cbt1 = FactoryBot.build(:chargeback_tier, :start => 0, :finish => Float::INFINITY) + cbt2 = FactoryBot.build(:chargeback_tier, :start => Float::INFINITY, :finish => Float::INFINITY) + cbd = FactoryBot.build(:chargeback_rate_detail, :chargeback_tiers => [cbt2, cbt1]) expect(cbd).not_to be_valid end diff --git a/spec/models/chargeback_rate_spec.rb b/spec/models/chargeback_rate_spec.rb index ae52dc08c3e..b301c52938a 100644 --- a/spec/models/chargeback_rate_spec.rb +++ b/spec/models/chargeback_rate_spec.rb @@ -3,7 +3,7 @@ let(:count_hourly_variable_tier_rate) { {:variable_rate => '10'} } let!(:chargeback_rate) do - FactoryGirl.create(:chargeback_rate, :detail_params => {:chargeback_rate_detail_cpu_cores_allocated => {:tiers => [count_hourly_variable_tier_rate]}}) + FactoryBot.create(:chargeback_rate, :detail_params => {:chargeback_rate_detail_cpu_cores_allocated => {:tiers => [count_hourly_variable_tier_rate]}}) end it "skips cpu_cores_allocated column" do @@ -25,13 +25,13 @@ context "#assigned?" do it "when unassigned" do - cbr = FactoryGirl.create(:chargeback_rate) + cbr = FactoryBot.create(:chargeback_rate) expect(cbr).to_not be_assigned end it "when assigned" do - cbr = FactoryGirl.create(:chargeback_rate) - host = FactoryGirl.create(:host) + cbr = FactoryBot.create(:chargeback_rate) + host = FactoryBot.create(:host) cbr.assign_to_objects(host) expect(cbr).to be_assigned end @@ -39,7 +39,7 @@ context "#destroy" do it "when unassigned" do - cbr = FactoryGirl.create(:chargeback_rate) + cbr = FactoryBot.create(:chargeback_rate) cbr.destroy @@ -48,8 +48,8 @@ end it "when assigned" do - cbr = FactoryGirl.create(:chargeback_rate, :description => "Unassigned Rate") - host = FactoryGirl.create(:host) + cbr = FactoryBot.create(:chargeback_rate, :description => "Unassigned Rate") + host = FactoryBot.create(:host) cbr.assign_to_objects(host) cbr.destroy @@ -61,7 +61,7 @@ end it "when default" do - cbr = FactoryGirl.create(:chargeback_rate, :description => "Default", :default => true) + cbr = FactoryBot.create(:chargeback_rate, :description => "Default", :default => true) cbr.destroy expect(cbr).to_not be_destroyed expect(cbr.errors.count).to be(1) @@ -69,7 +69,7 @@ end it "when non-default with default description" do - cbr = FactoryGirl.create(:chargeback_rate, :description => "Default Container Image Rate", :default => false) + cbr = FactoryBot.create(:chargeback_rate, :description => "Default Container Image Rate", :default => false) cbr.destroy expect(cbr).to_not be_destroyed expect(cbr.errors.count).to be(1) @@ -77,7 +77,7 @@ end it "when non-default" do - cbr = FactoryGirl.create(:chargeback_rate, :description => "Non-default", :default => false) + cbr = FactoryBot.create(:chargeback_rate, :description => "Non-default", :default => false) cbr.destroy expect(cbr).to be_destroyed expect(cbr.errors.count).to be(0) @@ -85,7 +85,7 @@ end describe '#currency_symbol' do - let(:rate) { FactoryGirl.build(:chargeback_rate, :chargeback_rate_details => details) } + let(:rate) { FactoryBot.build(:chargeback_rate, :chargeback_rate_details => details) } subject { rate.currency_symbol } context 'when there are no rate details' do @@ -95,9 +95,9 @@ context 'when there are valid rate details' do let(:symbol) { '฿' } - let(:currency) { FactoryGirl.create(:chargeback_rate_detail_currency, :symbol => symbol) } - let(:field) { FactoryGirl.create(:chargeable_field) } - let(:details) { [FactoryGirl.create(:chargeback_rate_detail, :detail_currency => currency, :chargeable_field => field)] } + let(:currency) { FactoryBot.create(:chargeback_rate_detail_currency, :symbol => symbol) } + let(:field) { FactoryBot.create(:chargeable_field) } + let(:details) { [FactoryBot.create(:chargeback_rate_detail, :detail_currency => currency, :chargeable_field => field)] } it { is_expected.to eq(symbol) } end end diff --git a/spec/models/chargeback_vm/ongoing_time_period_spec.rb b/spec/models/chargeback_vm/ongoing_time_period_spec.rb index faad79f25f5..fa6eb7807b8 100644 --- a/spec/models/chargeback_vm/ongoing_time_period_spec.rb +++ b/spec/models/chargeback_vm/ongoing_time_period_spec.rb @@ -1,5 +1,5 @@ describe ChargebackVm do - let(:admin) { FactoryGirl.create(:user_admin) } + let(:admin) { FactoryBot.create(:user_admin) } let(:start_of_all_intervals) { Time.parse('2007-01-01 00:00:00Z').utc } # 0hours, Monday, 1st of month let(:consumed_hours) { 17 } let(:midle_of_the_first_day) { start_of_all_intervals + consumed_hours.hours } # it is a Monday @@ -14,19 +14,19 @@ end let(:tag) { Tag.find_by(:name => '/managed/environment/prod') } let(:vm) do - ems = FactoryGirl.create(:ems_vmware) - vm = FactoryGirl.create(:vm_vmware, :name => 'test_vm', :evm_owner => admin, :ems_ref => 'ems_ref', + ems = FactoryBot.create(:ems_vmware) + vm = FactoryBot.create(:vm_vmware, :name => 'test_vm', :evm_owner => admin, :ems_ref => 'ems_ref', :created_on => start_of_all_intervals) vm.tag_with(tag.name, :ns => '*') - host = FactoryGirl.create(:host, :hardware => FactoryGirl.create(:hardware, + host = FactoryBot.create(:host, :hardware => FactoryBot.create(:hardware, :memory_mb => 8124, :cpu_total_cores => 1, :cpu_speed => 9576), :vms => [vm]) - ems_cluster = FactoryGirl.create(:ems_cluster, :ext_management_system => ems) + ems_cluster = FactoryBot.create(:ems_cluster, :ext_management_system => ems) ems_cluster.hosts << host - storage = FactoryGirl.create(:storage_target_vmware) + storage = FactoryBot.create(:storage_target_vmware) Range.new(start_of_all_intervals, midle_of_the_first_day, true).step_value(1.hour).each do |time| - vm.metric_rollups << FactoryGirl.create(:metric_rollup_vm_hr, + vm.metric_rollups << FactoryBot.create(:metric_rollup_vm_hr, :derived_vm_numvcpus => number_of_cpus, :cpu_usagemhz_rate_average => cpu_usagemhz, :timestamp => time, @@ -52,10 +52,10 @@ end let!(:chargeback_rate) do - cat = FactoryGirl.create(:classification, :description => 'Environment', :name => 'environment', + cat = FactoryBot.create(:classification, :description => 'Environment', :name => 'environment', :single_value => true, :show => true) - c = FactoryGirl.create(:classification, :name => 'prod', :description => 'Production', :parent_id => cat.id) - chargeback_rate = FactoryGirl.create(:chargeback_rate, :detail_params => detail_params) + c = FactoryBot.create(:classification, :name => 'prod', :description => 'Production', :parent_id => cat.id) + chargeback_rate = FactoryBot.create(:chargeback_rate, :detail_params => detail_params) temp = { :cb_rate => chargeback_rate, :tag => [c, 'vm'] } ChargebackRate.set_assignments(:compute, [temp]) end diff --git a/spec/models/chargeback_vm_spec.rb b/spec/models/chargeback_vm_spec.rb index cdf171a9254..73f171171b8 100644 --- a/spec/models/chargeback_vm_spec.rb +++ b/spec/models/chargeback_vm_spec.rb @@ -2,7 +2,7 @@ shared_examples_for "ChargebackVm" do include Spec::Support::ChargebackHelper - let(:admin) { FactoryGirl.create(:user_admin) } + let(:admin) { FactoryBot.create(:user_admin) } let(:base_options) do {:interval_size => 2, :end_interval_offset => 0, @@ -21,7 +21,7 @@ let(:month_beginning) { ts.beginning_of_month.utc } let(:month_end) { ts.end_of_month.utc } let(:hours_in_month) { Time.days_in_month(month_beginning.month, month_beginning.year) * 24 } - let(:ems) { FactoryGirl.create(:ems_vmware) } + let(:ems) { FactoryBot.create(:ems_vmware) } let(:hourly_variable_tier_rate) { {:variable_rate => hourly_rate.to_s} } let(:count_hourly_variable_tier_rate) { {:variable_rate => count_hourly_rate.to_s} } @@ -41,7 +41,7 @@ end let!(:chargeback_rate) do - FactoryGirl.create(:chargeback_rate, :detail_params => detail_params) + FactoryBot.create(:chargeback_rate, :detail_params => detail_params) end let(:metric_rollup_params) do @@ -66,8 +66,8 @@ def pluck_rollup(metric_rollup_records) MiqEnterprise.seed EvmSpecHelper.create_guid_miq_server_zone - cat = FactoryGirl.create(:classification, :description => "Environment", :name => "environment", :single_value => true, :show => true) - c = FactoryGirl.create(:classification, :name => "prod", :description => "Production", :parent_id => cat.id) + cat = FactoryBot.create(:classification, :description => "Environment", :name => "environment", :single_value => true, :show => true) + c = FactoryBot.create(:classification, :name => "prod", :description => "Production", :parent_id => cat.id) @tag = Tag.find_by(:name => "/managed/environment/prod") temp = {:cb_rate => chargeback_rate, :tag => [c, "vm"]} @@ -82,15 +82,15 @@ def pluck_rollup(metric_rollup_records) context 'with metric rollups' do before do - @vm1 = FactoryGirl.create(:vm_vmware, :name => "test_vm", :evm_owner => admin, :ems_ref => "ems_ref", + @vm1 = FactoryBot.create(:vm_vmware, :name => "test_vm", :evm_owner => admin, :ems_ref => "ems_ref", :created_on => month_beginning) @vm1.tag_with(@tag.name, :ns => '*') - @host1 = FactoryGirl.create(:host, :hardware => FactoryGirl.create(:hardware, :memory_mb => 8124, :cpu_total_cores => 1, :cpu_speed => 9576), :vms => [@vm1]) - @storage = FactoryGirl.create(:storage_target_vmware) + @host1 = FactoryBot.create(:host, :hardware => FactoryBot.create(:hardware, :memory_mb => 8124, :cpu_total_cores => 1, :cpu_speed => 9576), :vms => [@vm1]) + @storage = FactoryBot.create(:storage_target_vmware) @host1.storages << @storage - @ems_cluster = FactoryGirl.create(:ems_cluster, :ext_management_system => ems) + @ems_cluster = FactoryBot.create(:ems_cluster, :ext_management_system => ems) @ems_cluster.hosts << @host1 end @@ -108,11 +108,11 @@ def pluck_rollup(metric_rollup_records) context "by service" do let(:options) { base_options.merge(:interval => 'monthly', :interval_size => 4, :service_id => @service.id) } before do - @service = FactoryGirl.create(:service) + @service = FactoryBot.create(:service) @service << @vm1 @service.save - @vm2 = FactoryGirl.create(:vm_vmware, :name => "test_vm 2", :evm_owner => admin, :created_on => month_beginning) + @vm2 = FactoryBot.create(:vm_vmware, :name => "test_vm 2", :evm_owner => admin, :created_on => month_beginning) add_metric_rollups_for([@vm1, @vm2], month_beginning...month_end, 12.hours, metric_rollup_params) end @@ -131,7 +131,7 @@ def pluck_rollup(metric_rollup_records) let(:start_time) { report_run_time - 17.hours } let(:finish_time) { report_run_time - 14.hours } - let(:cloud_volume) { FactoryGirl.create(:cloud_volume_openstack) } + let(:cloud_volume) { FactoryBot.create(:cloud_volume_openstack) } it 'contains also columns with sub_metric(from cloud_volume)' do skip('this feature needs to be added to new chargeback rating') if Settings.new_chargeback @@ -151,8 +151,8 @@ def pluck_rollup(metric_rollup_records) end context 'with cloud volume types' do - let!(:cloud_volume_sdd) { FactoryGirl.create(:cloud_volume_openstack, :volume_type => 'sdd') } - let!(:cloud_volume_hdd) { FactoryGirl.create(:cloud_volume_openstack, :volume_type => 'hdd') } + let!(:cloud_volume_sdd) { FactoryBot.create(:cloud_volume_openstack, :volume_type => 'sdd') } + let!(:cloud_volume_hdd) { FactoryBot.create(:cloud_volume_openstack, :volume_type => 'hdd') } let(:state_data) do { :allocated_disk_types => { @@ -211,23 +211,23 @@ def pluck_rollup(metric_rollup_records) context 'without including metrics' do let(:ssd_volume_type) { 'ssd' } let(:ssd_size_1) { 1_234 } - let!(:cloud_volume_1) { FactoryGirl.create(:cloud_volume_openstack, :volume_type => ssd_volume_type, :size => ssd_size_1) } + let!(:cloud_volume_1) { FactoryBot.create(:cloud_volume_openstack, :volume_type => ssd_volume_type, :size => ssd_size_1) } - let(:ssd_disk_1) { FactoryGirl.create(:disk, :size => ssd_size_1, :backing => cloud_volume_1) } + let(:ssd_disk_1) { FactoryBot.create(:disk, :size => ssd_size_1, :backing => cloud_volume_1) } let(:ssd_size_2) { 4_234 } - let!(:cloud_volume_2) { FactoryGirl.create(:cloud_volume_openstack, :volume_type => ssd_volume_type, :size => ssd_size_2) } + let!(:cloud_volume_2) { FactoryBot.create(:cloud_volume_openstack, :volume_type => ssd_volume_type, :size => ssd_size_2) } - let(:ssd_disk_2) { FactoryGirl.create(:disk, :size => ssd_size_2, :backing => cloud_volume_2) } + let(:ssd_disk_2) { FactoryBot.create(:disk, :size => ssd_size_2, :backing => cloud_volume_2) } - let(:hardware) { FactoryGirl.create(:hardware, :disks => [ssd_disk_1, ssd_disk_2]) } + let(:hardware) { FactoryBot.create(:hardware, :disks => [ssd_disk_1, ssd_disk_2]) } - let(:resource) { FactoryGirl.create(:vm_vmware_cloud, :hardware => hardware, :created_on => month_beginning) } + let(:resource) { FactoryBot.create(:vm_vmware_cloud, :hardware => hardware, :created_on => month_beginning) } - let(:storage_chargeback_rate) { FactoryGirl.create(:chargeback_rate, :detail_params => detail_params, :rate_type => "Storage") } + let(:storage_chargeback_rate) { FactoryBot.create(:chargeback_rate, :detail_params => detail_params, :rate_type => "Storage") } - let(:parent_classification) { FactoryGirl.create(:classification) } - let(:classification) { FactoryGirl.create(:classification, :parent_id => parent_classification.id) } + let(:parent_classification) { FactoryBot.create(:classification) } + let(:classification) { FactoryBot.create(:classification, :parent_id => parent_classification.id) } let(:rate_assignment_options) { {:cb_rate => storage_chargeback_rate, :object => MiqEnterprise.first } } let(:options) { base_options.merge(:interval => 'daily', :tag => nil, :entity_id => resource.id, :include_metrics => false) } @@ -389,9 +389,9 @@ def pluck_rollup(metric_rollup_records) let(:finish_time) { report_run_time - 14.hours } before do - @tenant = FactoryGirl.create(:tenant) - @tenant_child = FactoryGirl.create(:tenant, :parent => @tenant) - @vm_tenant = FactoryGirl.create(:vm_vmware, :tenant_id => @tenant_child.id, + @tenant = FactoryBot.create(:tenant) + @tenant_child = FactoryBot.create(:tenant, :parent => @tenant) + @vm_tenant = FactoryBot.create(:vm_vmware, :tenant_id => @tenant_child.id, :name => "test_vm_tenant", :created_on => month_beginning) add_metric_rollups_for(@vm_tenant, start_time...finish_time, 1.hour, metric_rollup_params) @@ -448,24 +448,24 @@ def pluck_rollup(metric_rollup_records) # \__Tenant 5 # let(:tenant_1) { Tenant.root_tenant } - let(:vm_1_1) { FactoryGirl.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_1, :miq_group => nil) } - let(:vm_2_1) { FactoryGirl.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_1, :miq_group => nil) } + let(:vm_1_1) { FactoryBot.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_1, :miq_group => nil) } + let(:vm_2_1) { FactoryBot.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_1, :miq_group => nil) } - let(:tenant_2) { FactoryGirl.create(:tenant, :name => 'Tenant 2', :parent => tenant_1) } - let(:vm_1_2) { FactoryGirl.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_2, :miq_group => nil) } - let(:vm_2_2) { FactoryGirl.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_2, :miq_group => nil) } + let(:tenant_2) { FactoryBot.create(:tenant, :name => 'Tenant 2', :parent => tenant_1) } + let(:vm_1_2) { FactoryBot.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_2, :miq_group => nil) } + let(:vm_2_2) { FactoryBot.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_2, :miq_group => nil) } - let(:tenant_3) { FactoryGirl.create(:tenant, :name => 'Tenant 3', :parent => tenant_1) } - let(:vm_1_3) { FactoryGirl.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_3, :miq_group => nil) } - let(:vm_2_3) { FactoryGirl.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_3, :miq_group => nil) } + let(:tenant_3) { FactoryBot.create(:tenant, :name => 'Tenant 3', :parent => tenant_1) } + let(:vm_1_3) { FactoryBot.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_3, :miq_group => nil) } + let(:vm_2_3) { FactoryBot.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_3, :miq_group => nil) } - let(:tenant_4) { FactoryGirl.create(:tenant, :name => 'Tenant 4', :divisible => false, :parent => tenant_3) } - let(:vm_1_4) { FactoryGirl.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_4, :miq_group => nil) } - let(:vm_2_4) { FactoryGirl.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_4, :miq_group => nil) } + let(:tenant_4) { FactoryBot.create(:tenant, :name => 'Tenant 4', :divisible => false, :parent => tenant_3) } + let(:vm_1_4) { FactoryBot.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_4, :miq_group => nil) } + let(:vm_2_4) { FactoryBot.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_4, :miq_group => nil) } - let(:tenant_5) { FactoryGirl.create(:tenant, :name => 'Tenant 5', :divisible => false, :parent => tenant_3) } - let(:vm_1_5) { FactoryGirl.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_5, :miq_group => nil) } - let(:vm_2_5) { FactoryGirl.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_5, :miq_group => nil) } + let(:tenant_5) { FactoryBot.create(:tenant, :name => 'Tenant 5', :divisible => false, :parent => tenant_3) } + let(:vm_1_5) { FactoryBot.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_5, :miq_group => nil) } + let(:vm_2_5) { FactoryBot.create(:vm_vmware, :created_on => month_beginning, :tenant => tenant_5, :miq_group => nil) } subject { ChargebackVm.build_results_for_report_ChargebackVm(options).first } @@ -700,7 +700,7 @@ def result_row_by(chargeback_result, date) context "chargeback rate contains rate unrelated to chargeback vm" do let!(:chargeback_rate) do - FactoryGirl.create(:chargeback_rate, :detail_params => detail_params.merge(:chargeback_rate_detail_cpu_cores_allocated => {:tiers => [count_hourly_variable_tier_rate]})) + FactoryBot.create(:chargeback_rate, :detail_params => detail_params.merge(:chargeback_rate_detail_cpu_cores_allocated => {:tiers => [count_hourly_variable_tier_rate]})) end it "skips unrelated columns and calculate related columns" do @@ -818,7 +818,7 @@ def result_row_by(chargeback_result, date) end context "by owner" do - let(:user) { FactoryGirl.create(:user, :name => 'Test VM Owner', :userid => 'test_user') } + let(:user) { FactoryBot.create(:user, :name => 'Test VM Owner', :userid => 'test_user') } let(:options) { {:interval_size => 4, :owner => user.userid, :ext_options => {:tz => 'Eastern Time (US & Canada)'} } } before do @vm1.update_attribute(:evm_owner, user) @@ -836,11 +836,11 @@ def result_row_by(chargeback_result, date) end describe "#get_rates" do - let(:chargeback_rate) { FactoryGirl.create(:chargeback_rate, :rate_type => "Compute") } + let(:chargeback_rate) { FactoryBot.create(:chargeback_rate, :rate_type => "Compute") } let(:chargeback_vm) { ChargebackVm.new } let(:rate_assignment_options) { {:cb_rate => chargeback_rate, :object => Tenant.root_tenant} } let(:metric_rollup) do - FactoryGirl.create(:metric_rollup_vm_hr, :timestamp => report_run_time - 1.day - 17.hours, + FactoryBot.create(:metric_rollup_vm_hr, :timestamp => report_run_time - 1.day - 17.hours, :tag_names => "environment/prod", :parent_host_id => @host1.id, :parent_ems_cluster_id => @ems_cluster.id, :parent_ems_id => ems.id, :parent_storage_id => @storage.id, @@ -860,20 +860,20 @@ def result_row_by(chargeback_result, date) end context "selecting based on tagged cloud volumes" do - let!(:cloud_volume_sdd) { FactoryGirl.create(:cloud_volume_openstack, :volume_type => 'sdd') } + let!(:cloud_volume_sdd) { FactoryBot.create(:cloud_volume_openstack, :volume_type => 'sdd') } let(:ssd_size) { 1_234 } - let(:ssd_disk) { FactoryGirl.create(:disk, :size => ssd_size, :backing => cloud_volume_sdd) } - let(:hardware) { FactoryGirl.create(:hardware, :disks => [ssd_disk]) } + let(:ssd_disk) { FactoryBot.create(:disk, :size => ssd_size, :backing => cloud_volume_sdd) } + let(:hardware) { FactoryBot.create(:hardware, :disks => [ssd_disk]) } - let(:resource) { FactoryGirl.create(:vm_vmware_cloud, :hardware => hardware, :created_on => month_beginning) } + let(:resource) { FactoryBot.create(:vm_vmware_cloud, :hardware => hardware, :created_on => month_beginning) } let(:consumption) { Chargeback::ConsumptionWithoutRollups.new(resource, nil, nil) } - let(:storage_chargeback_rate) { FactoryGirl.create(:chargeback_rate, :rate_type => "Storage") } + let(:storage_chargeback_rate) { FactoryBot.create(:chargeback_rate, :rate_type => "Storage") } - let(:parent_classification) { FactoryGirl.create(:classification) } - let(:classification) { FactoryGirl.create(:classification, :parent_id => parent_classification.id) } + let(:parent_classification) { FactoryBot.create(:classification) } + let(:classification) { FactoryBot.create(:classification, :parent_id => parent_classification.id) } let(:rate_assignment_options) { {:cb_rate => storage_chargeback_rate, :tag => [classification, "storage"]} } @@ -903,7 +903,7 @@ def result_row_by(chargeback_result, date) let(:report_options) { Chargeback::ReportOptions.new } let(:timestamp_key) { 'Fri, 13 May 2016 10:40:00 UTC +00:00' } let(:beginning_of_day) { timestamp_key.in_time_zone.beginning_of_day } - let(:metric_rollup) { FactoryGirl.create(:metric_rollup_vm_hr, :timestamp => timestamp_key, :resource => @vm1) } + let(:metric_rollup) { FactoryBot.create(:metric_rollup_vm_hr, :timestamp => timestamp_key, :resource => @vm1) } let(:consumption) { Chargeback::ConsumptionWithRollups.new(pluck_rollup([metric_rollup]), nil, nil) } subject { described_class.report_row_key(consumption) } before do @@ -929,7 +929,7 @@ def result_row_by(chargeback_result, date) context 'with parent ems' do let(:metric_rollup) do - FactoryGirl.create(:metric_rollup_vm_hr, :tag_names => 'environment/prod', + FactoryBot.create(:metric_rollup_vm_hr, :tag_names => 'environment/prod', :parent_host_id => @host1.id, :parent_ems_cluster_id => @ems_cluster.id, :parent_ems_id => ems.id, :parent_storage_id => @storage.id, :resource => @vm1, :resource_name => @vm1.name) @@ -942,7 +942,7 @@ def result_row_by(chargeback_result, date) context 'when parent ems is missing' do let(:metric_rollup) do - FactoryGirl.create(:metric_rollup_vm_hr, :tag_names => 'environment/prod', + FactoryBot.create(:metric_rollup_vm_hr, :tag_names => 'environment/prod', :parent_host_id => @host1.id, :parent_ems_cluster_id => @ems_cluster.id, :parent_storage_id => @storage.id, :resource => @vm1, :resource_name => @vm1.name) @@ -963,13 +963,13 @@ def result_row_by(chargeback_result, date) base_options end - let(:vm) { FactoryGirl.create(:vm_vmware, :evm_owner => admin, :name => "vm_1", :created_on => month_beginning) } + let(:vm) { FactoryBot.create(:vm_vmware, :evm_owner => admin, :name => "vm_1", :created_on => month_beginning) } - let(:parent_classification_1) { FactoryGirl.create(:classification, :name => 'department') } - let(:classification_1_1) { FactoryGirl.create(:classification, :name => 'financial', :parent_id => parent_classification_1.id) } + let(:parent_classification_1) { FactoryBot.create(:classification, :name => 'department') } + let(:classification_1_1) { FactoryBot.create(:classification, :name => 'financial', :parent_id => parent_classification_1.id) } - let(:parent_classification_2) { FactoryGirl.create(:classification, :name => 'enviroment') } - let(:classification_2_1) { FactoryGirl.create(:classification, :name => 'test', :parent_id => parent_classification_2.id) } + let(:parent_classification_2) { FactoryBot.create(:classification, :name => 'enviroment') } + let(:classification_2_1) { FactoryBot.create(:classification, :name => 'test', :parent_id => parent_classification_2.id) } let(:hourly_rate_2) { 0.05 } let(:count_hourly_rate_2) { 10.00 } @@ -993,8 +993,8 @@ def result_row_by(chargeback_result, date) } end - let(:chargeback_rate_1) { FactoryGirl.create(:chargeback_rate, :rate_type => "Compute", :detail_params => detail_params) } - let(:chargeback_rate_2) { FactoryGirl.create(:chargeback_rate, :rate_type => "Compute", :detail_params => detail_params_2) } + let(:chargeback_rate_1) { FactoryBot.create(:chargeback_rate, :rate_type => "Compute", :detail_params => detail_params) } + let(:chargeback_rate_2) { FactoryBot.create(:chargeback_rate, :rate_type => "Compute", :detail_params => detail_params_2) } let(:rates) do [ @@ -1126,19 +1126,19 @@ def result_row_by(chargeback_result, date) end context 'more rates have been selected' do - let(:storage_chargeback_rate_1) { FactoryGirl.create(:chargeback_rate, :rate_type => "Storage") } - let(:storage_chargeback_rate_2) { FactoryGirl.create(:chargeback_rate, :rate_type => "Storage") } + let(:storage_chargeback_rate_1) { FactoryBot.create(:chargeback_rate, :rate_type => "Storage") } + let(:storage_chargeback_rate_2) { FactoryBot.create(:chargeback_rate, :rate_type => "Storage") } let(:chargeback_vm) { Chargeback::RatesCache.new(Chargeback::ReportOptions.new_from_h(base_options)) } - let(:parent_classification) { FactoryGirl.create(:classification) } - let(:classification_1) { FactoryGirl.create(:classification, :parent_id => parent_classification.id) } - let(:classification_2) { FactoryGirl.create(:classification, :parent_id => parent_classification.id) } + let(:parent_classification) { FactoryBot.create(:classification) } + let(:classification_1) { FactoryBot.create(:classification, :parent_id => parent_classification.id) } + let(:classification_2) { FactoryBot.create(:classification, :parent_id => parent_classification.id) } let(:rate_assignment_options_1) { {:cb_rate => storage_chargeback_rate_1, :tag => [classification_1, "Storage"]} } let(:rate_assignment_options_2) { {:cb_rate => storage_chargeback_rate_2, :tag => [classification_2, "Storage"]} } let(:metric_rollup) do - FactoryGirl.create(:metric_rollup_vm_hr, :timestamp => report_run_time - 1.day - 17.hours, + FactoryBot.create(:metric_rollup_vm_hr, :timestamp => report_run_time - 1.day - 17.hours, :parent_host_id => @host1.id, :parent_ems_cluster_id => @ems_cluster.id, :parent_ems_id => ems.id, :parent_storage_id => @storage.id, :resource => @vm) @@ -1147,7 +1147,7 @@ def result_row_by(chargeback_result, date) before do @storage.tag_with([classification_1.tag.name, classification_2.tag.name], :ns => '*') ChargebackRate.set_assignments(:storage, [rate_assignment_options_1, rate_assignment_options_2]) - @vm = FactoryGirl.create(:vm_vmware, :name => "test_vm_1", :evm_owner => admin, :ems_ref => "ems_ref", :created_on => month_beginning) + @vm = FactoryBot.create(:vm_vmware, :name => "test_vm_1", :evm_owner => admin, :ems_ref => "ems_ref", :created_on => month_beginning) end it "return only one chargeback rate according to tag name of Vm" do @@ -1176,8 +1176,8 @@ def result_row_by(chargeback_result, date) context "with global and remote regions" do let(:options_tenant) { base_options.merge(:interval => 'monthly', :tenant_id => tenant_1.id).tap { |t| t.delete(:tag) } } - let(:vm_global) { FactoryGirl.create(:vm_vmware) } - let!(:region_1) { FactoryGirl.create(:miq_region) } + let(:vm_global) { FactoryBot.create(:vm_vmware) } + let!(:region_1) { FactoryBot.create(:miq_region) } def region_id_for(klass, region) klass.id_in_region(klass.count + 1_000_000, region) @@ -1202,17 +1202,17 @@ def find_result_by_vm_name_and_region(chargeback_result, vm_name, region) # T1(vm_1, vm_2) -> # T2(vm_1, vm_2) # T3(vm_1, vm_2) - let!(:tenant_1) { FactoryGirl.create(:tenant, :parent => Tenant.root_tenant, :name => tenant_name_1, :description => tenant_name_1) } - let(:vm_1_t_1) { FactoryGirl.create(:vm_vmware, :tenant => tenant_1, :name => vm_name_1) } - let(:vm_2_t_1) { FactoryGirl.create(:vm_vmware, :tenant => tenant_1) } + let!(:tenant_1) { FactoryBot.create(:tenant, :parent => Tenant.root_tenant, :name => tenant_name_1, :description => tenant_name_1) } + let(:vm_1_t_1) { FactoryBot.create(:vm_vmware, :tenant => tenant_1, :name => vm_name_1) } + let(:vm_2_t_1) { FactoryBot.create(:vm_vmware, :tenant => tenant_1) } - let(:tenant_2) { FactoryGirl.create(:tenant, :name => tenant_name_2, :parent => tenant_1, :description => tenant_name_2) } - let(:vm_1_t_2) { FactoryGirl.create(:vm_vmware, :tenant => tenant_2) } - let(:vm_2_t_2) { FactoryGirl.create(:vm_vmware, :tenant => tenant_2) } + let(:tenant_2) { FactoryBot.create(:tenant, :name => tenant_name_2, :parent => tenant_1, :description => tenant_name_2) } + let(:vm_1_t_2) { FactoryBot.create(:vm_vmware, :tenant => tenant_2) } + let(:vm_2_t_2) { FactoryBot.create(:vm_vmware, :tenant => tenant_2) } - let(:tenant_3) { FactoryGirl.create(:tenant, :name => tenant_name_3, :parent => tenant_1, :description => tenant_name_3) } - let(:vm_1_t_3) { FactoryGirl.create(:vm_vmware, :tenant => tenant_3) } - let(:vm_2_t_3) { FactoryGirl.create(:vm_vmware, :tenant => tenant_3) } + let(:tenant_3) { FactoryBot.create(:tenant, :name => tenant_name_3, :parent => tenant_1, :description => tenant_name_3) } + let(:vm_1_t_3) { FactoryBot.create(:vm_vmware, :tenant => tenant_3) } + let(:vm_2_t_3) { FactoryBot.create(:vm_vmware, :tenant => tenant_3) } # BUILD tenants and VMs structure for region_1 # @@ -1221,23 +1221,23 @@ def find_result_by_vm_name_and_region(chargeback_result, vm_name, region) # T3(vm_1, vm_2) # let!(:root_tenant_region_1) do - tenant = FactoryGirl.create(:tenant, :id => region_id_for(Tenant, region_1.region)) + tenant = FactoryBot.create(:tenant, :id => region_id_for(Tenant, region_1.region)) tenant.parent = nil tenant.save(:validate => false) # skip validate to set parent = nil tenant end - let!(:tenant_1_region_1) { FactoryGirl.create(:tenant, :id => region_id_for(Tenant, region_1.region), :name => tenant_name_1, :parent => root_tenant_region_1, :description => tenant_name_1) } - let(:vm_1_region_1_t_1) { FactoryGirl.create(:vm_vmware, :id => region_id_for(Vm, region_1.region), :tenant => tenant_2_region_1, :name => vm_name_1) } - let(:vm_2_region_1_t_1) { FactoryGirl.create(:vm_vmware, :id => region_id_for(Vm, region_1.region), :tenant => tenant_2_region_1) } + let!(:tenant_1_region_1) { FactoryBot.create(:tenant, :id => region_id_for(Tenant, region_1.region), :name => tenant_name_1, :parent => root_tenant_region_1, :description => tenant_name_1) } + let(:vm_1_region_1_t_1) { FactoryBot.create(:vm_vmware, :id => region_id_for(Vm, region_1.region), :tenant => tenant_2_region_1, :name => vm_name_1) } + let(:vm_2_region_1_t_1) { FactoryBot.create(:vm_vmware, :id => region_id_for(Vm, region_1.region), :tenant => tenant_2_region_1) } - let!(:tenant_2_region_1) { FactoryGirl.create(:tenant, :id => region_id_for(Tenant, region_1.region), :name => tenant_name_2, :parent => tenant_1_region_1, :description => tenant_name_2) } - let(:vm_1_region_1_t_2) { FactoryGirl.create(:vm_vmware, :id => region_id_for(Vm, region_1.region), :tenant => tenant_2_region_1) } - let(:vm_2_region_1_t_2) { FactoryGirl.create(:vm_vmware, :id => region_id_for(Vm, region_1.region), :tenant => tenant_2_region_1) } + let!(:tenant_2_region_1) { FactoryBot.create(:tenant, :id => region_id_for(Tenant, region_1.region), :name => tenant_name_2, :parent => tenant_1_region_1, :description => tenant_name_2) } + let(:vm_1_region_1_t_2) { FactoryBot.create(:vm_vmware, :id => region_id_for(Vm, region_1.region), :tenant => tenant_2_region_1) } + let(:vm_2_region_1_t_2) { FactoryBot.create(:vm_vmware, :id => region_id_for(Vm, region_1.region), :tenant => tenant_2_region_1) } - let!(:tenant_3_region_1) { FactoryGirl.create(:tenant, :id => region_id_for(Tenant, region_1.region), :name => tenant_name_3, :parent => tenant_1_region_1, :description => tenant_name_3) } - let(:vm_1_region_1_t_3) { FactoryGirl.create(:vm_vmware, :id => region_id_for(Vm, region_1.region), :tenant => tenant_3_region_1) } - let(:vm_2_region_1_t_3) { FactoryGirl.create(:vm_vmware, :id => region_id_for(Vm, region_1.region), :tenant => tenant_3_region_1) } + let!(:tenant_3_region_1) { FactoryBot.create(:tenant, :id => region_id_for(Tenant, region_1.region), :name => tenant_name_3, :parent => tenant_1_region_1, :description => tenant_name_3) } + let(:vm_1_region_1_t_3) { FactoryBot.create(:vm_vmware, :id => region_id_for(Vm, region_1.region), :tenant => tenant_3_region_1) } + let(:vm_2_region_1_t_3) { FactoryBot.create(:vm_vmware, :id => region_id_for(Vm, region_1.region), :tenant => tenant_3_region_1) } before do # default region @@ -1302,10 +1302,10 @@ def find_result_by_vm_name_and_region(chargeback_result, vm_name, region) let(:disk_b) { disk_gb * 1024**3 } let(:hardware) do - FactoryGirl.create(:hardware, + FactoryBot.create(:hardware, :cpu_total_cores => cores, :memory_mb => mem_mb, - :disks => [FactoryGirl.create(:disk, :size => disk_b)]) + :disks => [FactoryBot.create(:disk, :size => disk_b)]) end let(:fixed_cost) { hourly_rate * 24 } @@ -1315,7 +1315,7 @@ def find_result_by_vm_name_and_region(chargeback_result, vm_name, region) context 'for SCVMM (hyper-v)' do let!(:vm1) do - vm = FactoryGirl.create(:vm_microsoft, :hardware => hardware, :created_on => report_run_time - 1.day) + vm = FactoryBot.create(:vm_microsoft, :hardware => hardware, :created_on => report_run_time - 1.day) vm.tag_with(@tag.name, :ns => '*') vm end @@ -1343,7 +1343,7 @@ def find_result_by_vm_name_and_region(chargeback_result, vm_name, region) context 'for any virtual machine' do let!(:vm1) do - vm = FactoryGirl.create(:vm_vmware, :hardware => hardware, :created_on => report_run_time - 1.day) + vm = FactoryBot.create(:vm_vmware, :hardware => hardware, :created_on => report_run_time - 1.day) vm.tag_with(@tag.name, :ns => '*') vm end diff --git a/spec/models/classification_spec.rb b/spec/models/classification_spec.rb index 818fbef1412..cf6e93c2c45 100644 --- a/spec/models/classification_spec.rb +++ b/spec/models/classification_spec.rb @@ -1,10 +1,10 @@ describe Classification do context ".hash_all_by_type_and_name" do it "with entries duped across categories should return both entries" do - clergy = FactoryGirl.create(:classification, :name => "clergy", :single_value => 1) - clergy_bishop = FactoryGirl.create(:classification_tag, :name => "bishop", :parent => clergy) - chess = FactoryGirl.create(:classification, :name => "chess", :single_value => 1) - chess_bishop = FactoryGirl.create(:classification_tag, :name => "bishop", :parent => chess) + clergy = FactoryBot.create(:classification, :name => "clergy", :single_value => 1) + clergy_bishop = FactoryBot.create(:classification_tag, :name => "bishop", :parent => clergy) + chess = FactoryBot.create(:classification, :name => "chess", :single_value => 1) + chess_bishop = FactoryBot.create(:classification_tag, :name => "bishop", :parent => chess) expect(Classification.hash_all_by_type_and_name).to include( "clergy" => { @@ -20,45 +20,45 @@ end context "enforce_policy" do - let(:tag) { FactoryGirl.build(:classification_tag, :parent => FactoryGirl.build(:classification)) } + let(:tag) { FactoryBot.build(:classification_tag, :parent => FactoryBot.build(:classification)) } it "enforce_policy on sub-classed vm" do allow(MiqEvent).to receive(:raise_evm_event).and_return(true) - vm = FactoryGirl.build(:vm_vmware, :name => "VM1") + vm = FactoryBot.build(:vm_vmware, :name => "VM1") tag.enforce_policy(vm, "fake_event") end it "enforce_policy on sub-classed host" do allow(MiqEvent).to receive(:raise_evm_event).and_return(true) - host = FactoryGirl.build(:host_vmware_esx) + host = FactoryBot.build(:host_vmware_esx) tag.enforce_policy(host, "fake_event") end end context "with hierarchy" do - let(:host1) { FactoryGirl.create(:host, :name => "HOST1") } - let(:host2) { FactoryGirl.create(:host, :name => "HOST2") } + let(:host1) { FactoryBot.create(:host, :name => "HOST1") } + let(:host2) { FactoryBot.create(:host, :name => "HOST2") } let(:host3) do - FactoryGirl.create(:host, :name => "HOST3").tap do |host| + FactoryBot.create(:host, :name => "HOST3").tap do |host| Classification.find_by_name("test_category").entries.each { |ent| ent.assign_entry_to(host) } end end - let(:sti_inst) { FactoryGirl.create(:template_vmware) } + let(:sti_inst) { FactoryBot.create(:template_vmware) } before do - parent = FactoryGirl.create(:classification, :name => "test_category") - FactoryGirl.create(:classification_tag, :name => "test_entry", :parent => parent) - FactoryGirl.create(:classification_tag, :name => "another_test_entry", :parent => parent) + parent = FactoryBot.create(:classification, :name => "test_category") + FactoryBot.create(:classification_tag, :name => "test_entry", :parent => parent) + FactoryBot.create(:classification_tag, :name => "another_test_entry", :parent => parent) - parent = FactoryGirl.create(:classification, :name => "test_single_value_category", :single_value => 1) - FactoryGirl.create(:classification_tag, :name => "single_entry_1", :parent => parent) - FactoryGirl.create(:classification_tag, :name => "single_entry_2", :parent => parent) + parent = FactoryBot.create(:classification, :name => "test_single_value_category", :single_value => 1) + FactoryBot.create(:classification_tag, :name => "single_entry_1", :parent => parent) + FactoryBot.create(:classification_tag, :name => "single_entry_2", :parent => parent) - parent = FactoryGirl.create(:classification, :name => "test_multi_value_category", :single_value => 0) - FactoryGirl.create(:classification_tag, :name => "multi_entry_1", :parent => parent) - FactoryGirl.create(:classification_tag, :name => "multi_entry_2", :parent => parent) + parent = FactoryBot.create(:classification, :name => "test_multi_value_category", :single_value => 0) + FactoryBot.create(:classification_tag, :name => "multi_entry_1", :parent => parent) + FactoryBot.create(:classification_tag, :name => "multi_entry_2", :parent => parent) end context "#destroy" do @@ -122,7 +122,7 @@ it "should test add entry" do cat = Classification.find_by_name("test_category") - ent = FactoryGirl.create(:classification_tag, :name => "test_add_entry", :parent => cat) + ent = FactoryBot.create(:classification_tag, :name => "test_add_entry", :parent => cat) expect(ent).to be_valid expect(cat.id.to_i).to eq(ent.parent_id) @@ -146,7 +146,7 @@ it "should test create duplicate category" do expect do - FactoryGirl.create(:classification, :name => "test_category") + FactoryBot.create(:classification, :name => "test_category") end.to raise_error(ActiveRecord::RecordInvalid) end @@ -160,11 +160,11 @@ it "should test add duplicate entry" do cat = Classification.find_by_name("test_category") - ent = FactoryGirl.create(:classification_tag, :name => "test_add_dup_entry", :parent => cat) + ent = FactoryBot.create(:classification_tag, :name => "test_add_dup_entry", :parent => cat) expect(ent).to be_valid expect do - FactoryGirl.create(:classification_tag, :name => "test_add_dup_entry", :parent => cat) + FactoryBot.create(:classification_tag, :name => "test_add_dup_entry", :parent => cat) end.to raise_error(ActiveRecord::RecordInvalid) end @@ -455,7 +455,7 @@ end it "does not re-seed existing categories" do - category = FactoryGirl.create(:classification_cost_center, + category = FactoryBot.create(:classification_cost_center, :description => "user defined", :example_text => "user defined", :show => false, @@ -475,11 +475,11 @@ let(:other_region_id) { other_region * Classification.rails_sequence_factor + 1 } before do - @local = FactoryGirl.create(:classification, :name => "test_category1") - FactoryGirl.create(:classification, :name => "test_category3") + @local = FactoryBot.create(:classification, :name => "test_category1") + FactoryBot.create(:classification, :name => "test_category3") - FactoryGirl.create(:tag, :name => "/managed/test_category2", :id => other_region_id) - @remote = FactoryGirl.create(:classification, :name => "test_category2", :id => other_region_id) + FactoryBot.create(:tag, :name => "/managed/test_category2", :id => other_region_id) + @remote = FactoryBot.create(:classification, :name => "test_category2", :id => other_region_id) end it "created classification in other region" do @@ -518,10 +518,10 @@ let(:other_region_id) { other_region * Classification.rails_sequence_factor + 1 } before do - @local = FactoryGirl.create(:classification, :name => "test_category1") - FactoryGirl.create(:tag, :name => Classification.name2tag("test_category2"), :id => other_region_id) - @remote = FactoryGirl.create(:classification, :name => "test_category2", :id => other_region_id) - FactoryGirl.create(:classification, :name => "test_category3") + @local = FactoryBot.create(:classification, :name => "test_category1") + FactoryBot.create(:tag, :name => Classification.name2tag("test_category2"), :id => other_region_id) + @remote = FactoryBot.create(:classification, :name => "test_category2", :id => other_region_id) + FactoryBot.create(:classification, :name => "test_category3") end it "finds in region" do diff --git a/spec/models/cloud_service_spec.rb b/spec/models/cloud_service_spec.rb index 4587e6c8a65..502afa19ddb 100644 --- a/spec/models/cloud_service_spec.rb +++ b/spec/models/cloud_service_spec.rb @@ -1,6 +1,6 @@ RSpec.describe CloudService, :type => :model do let(:cloud_service) do - FactoryGirl.create(:cloud_service).tap do |cs| + FactoryBot.create(:cloud_service).tap do |cs| allow(cs).to receive(:fog_service).and_return(fog_service) end end diff --git a/spec/models/cloud_tenant_spec.rb b/spec/models/cloud_tenant_spec.rb index dd681da1d9a..b54ba710c8d 100644 --- a/spec/models/cloud_tenant_spec.rb +++ b/spec/models/cloud_tenant_spec.rb @@ -1,22 +1,22 @@ describe CloudTenant do it "#all_cloud_networks" do - ems = FactoryGirl.create(:ems_openstack) - tenant1 = FactoryGirl.create(:cloud_tenant, :ext_management_system => ems) - tenant2 = FactoryGirl.create(:cloud_tenant, :ext_management_system => ems) - net1 = FactoryGirl.create(:cloud_network, :ext_management_system => ems.network_manager, :shared => true) - net2 = FactoryGirl.create(:cloud_network, :ext_management_system => ems.network_manager, :cloud_tenant => tenant1) - _net3 = FactoryGirl.create(:cloud_network, :ext_management_system => ems.network_manager, :cloud_tenant => tenant2) + ems = FactoryBot.create(:ems_openstack) + tenant1 = FactoryBot.create(:cloud_tenant, :ext_management_system => ems) + tenant2 = FactoryBot.create(:cloud_tenant, :ext_management_system => ems) + net1 = FactoryBot.create(:cloud_network, :ext_management_system => ems.network_manager, :shared => true) + net2 = FactoryBot.create(:cloud_network, :ext_management_system => ems.network_manager, :cloud_tenant => tenant1) + _net3 = FactoryBot.create(:cloud_network, :ext_management_system => ems.network_manager, :cloud_tenant => tenant2) expect(tenant1.all_cloud_networks).to match_array([net1, net2]) end describe '#total_vms' do - let(:ems) { FactoryGirl.create(:ems_openstack) } - let(:vm1) { FactoryGirl.create(:vm_openstack, :ext_management_system => ems) } - let(:vm2) { FactoryGirl.create(:vm_openstack, :ext_management_system => nil) } + let(:ems) { FactoryBot.create(:ems_openstack) } + let(:vm1) { FactoryBot.create(:vm_openstack, :ext_management_system => ems) } + let(:vm2) { FactoryBot.create(:vm_openstack, :ext_management_system => nil) } let(:vms) { [vm1, vm2] } - let(:template) { FactoryGirl.create(:miq_template) } - let(:cloud_tenant) { FactoryGirl.create(:cloud_tenant, :ext_management_system => ems, :vms => vms, :miq_templates => [template]) } + let(:template) { FactoryBot.create(:miq_template) } + let(:cloud_tenant) { FactoryBot.create(:cloud_tenant, :ext_management_system => ems, :vms => vms, :miq_templates => [template]) } it 'counts only vms' do cloud_tenant.reload diff --git a/spec/models/cloud_volume_spec.rb b/spec/models/cloud_volume_spec.rb index d3ff5b74f1c..e5736b94895 100644 --- a/spec/models/cloud_volume_spec.rb +++ b/spec/models/cloud_volume_spec.rb @@ -1,8 +1,8 @@ describe CloudVolume do it ".available" do - disk = FactoryGirl.create(:disk) - FactoryGirl.create(:cloud_volume, :attachments => [disk]) - cv2 = FactoryGirl.create(:cloud_volume) + disk = FactoryBot.create(:disk) + FactoryBot.create(:cloud_volume, :attachments => [disk]) + cv2 = FactoryBot.create(:cloud_volume) expect(described_class.available).to eq([cv2]) end diff --git a/spec/models/compliance_spec.rb b/spec/models/compliance_spec.rb index 48760cc0a06..89725af6847 100644 --- a/spec/models/compliance_spec.rb +++ b/spec/models/compliance_spec.rb @@ -1,13 +1,13 @@ describe Compliance do context "A small virtual infrastructure" do - let(:ems_vmware) { FactoryGirl.create(:ems_vmware, :zone => zone) } - let(:host1) { FactoryGirl.create(:host, :ext_management_system => ems_vmware) } - let(:host2) { FactoryGirl.create(:host) } - let(:vm1) { FactoryGirl.create(:vm_vmware, :host => host1, :ext_management_system => ems_vmware) } - let(:zone) { FactoryGirl.build(:zone) } + let(:ems_vmware) { FactoryBot.create(:ems_vmware, :zone => zone) } + let(:host1) { FactoryBot.create(:host, :ext_management_system => ems_vmware) } + let(:host2) { FactoryBot.create(:host) } + let(:vm1) { FactoryBot.create(:vm_vmware, :host => host1, :ext_management_system => ems_vmware) } + let(:zone) { FactoryBot.build(:zone) } - let(:ems_kubernetes_container) { FactoryGirl.create(:ems_kubernetes, :zone => zone) } - let(:container_image) { FactoryGirl.create(:container_image, :ext_management_system => ems_kubernetes_container) } + let(:ems_kubernetes_container) { FactoryBot.create(:ems_kubernetes, :zone => zone) } + let(:container_image) { FactoryBot.create(:container_image, :ext_management_system => ems_kubernetes_container) } before { allow(MiqServer).to receive(:my_zone).and_return(zone) } @@ -92,20 +92,20 @@ context ".check_compliance" do shared_examples ".check_compliance" do - let(:policy) { FactoryGirl.create(:miq_policy, :mode => 'compliance', :towhat => 'Vm', :active => true) } - let(:policy_set) { FactoryGirl.create(:miq_policy_set) } - let(:template) { FactoryGirl.create(:template_vmware, :host => host1, :ext_management_system => ems_vmware) } - let(:action) { FactoryGirl.create(:miq_action, :name => 'compliance_failed', :action_type => 'default') } + let(:policy) { FactoryBot.create(:miq_policy, :mode => 'compliance', :towhat => 'Vm', :active => true) } + let(:policy_set) { FactoryBot.create(:miq_policy_set) } + let(:template) { FactoryBot.create(:template_vmware, :host => host1, :ext_management_system => ems_vmware) } + let(:action) { FactoryBot.create(:miq_action, :name => 'compliance_failed', :action_type => 'default') } let(:content) do - FactoryGirl.create( + FactoryBot.create( :miq_policy_content, :qualifier => 'failure', :failure_sequence => 1, :failure_synchronous => true ) end let(:event_definition) { MiqEventDefinition.find_by(:name => "vm_compliance_check") } before do - policy.sync_events([FactoryGirl.create(:miq_event_definition, :name => "vm_compliance_check")]) - policy.conditions << FactoryGirl.create(:condition, :expression => MiqExpression.new("IS NOT EMPTY" => {"field" => "Vm-id"})) + policy.sync_events([FactoryBot.create(:miq_event_definition, :name => "vm_compliance_check")]) + policy.conditions << FactoryBot.create(:condition, :expression => MiqExpression.new("IS NOT EMPTY" => {"field" => "Vm-id"})) content.miq_event_definition = event_definition content.miq_action = action policy.miq_policy_contents << content @@ -120,7 +120,7 @@ end it "non-compliant" do - policy.conditions << FactoryGirl.create(:condition, :expression => MiqExpression.new(">=" => {"field" => "Vm-num_cpu", "value" => "2"})) + policy.conditions << FactoryBot.create(:condition, :expression => MiqExpression.new(">=" => {"field" => "Vm-num_cpu", "value" => "2"})) expect(MiqEvent).to receive(:raise_evm_event_queue).with(subject, "vm_compliance_failed") expect(Compliance.check_compliance(subject)).to be_falsey @@ -140,17 +140,17 @@ context "no condition" do let(:policy) do - FactoryGirl.create(:miq_policy, + FactoryBot.create(:miq_policy, :mode => 'compliance', :towhat => 'Vm', :expression => MiqExpression.new("=" => {"field" => "Vm-retired", "value" => "true"}), :active => true) end - let(:policy_set) { FactoryGirl.create(:miq_policy_set) } + let(:policy_set) { FactoryBot.create(:miq_policy_set) } let(:event_definition) { MiqEventDefinition.find_by(:name => "vm_compliance_check") } before do - policy.sync_events([FactoryGirl.create(:miq_event_definition, :name => "vm_compliance_check")]) + policy.sync_events([FactoryBot.create(:miq_event_definition, :name => "vm_compliance_check")]) policy_set.add_member(policy) ems_vmware.add_policy(policy_set) end diff --git a/spec/models/condition_spec.rb b/spec/models/condition_spec.rb index 09dd035f448..1238fde4c3e 100644 --- a/spec/models/condition_spec.rb +++ b/spec/models/condition_spec.rb @@ -1,12 +1,12 @@ describe Condition do describe ".subst" do context "evaluation of virtual custom attributes from left and right side" do - let(:custom_attribute_1) { FactoryGirl.create(:custom_attribute, :name => "attr_1", :value => 20) } - let(:custom_attribute_2) { FactoryGirl.create(:custom_attribute, :name => "attr_2", :value => 30) } + let(:custom_attribute_1) { FactoryBot.create(:custom_attribute, :name => "attr_1", :value => 20) } + let(:custom_attribute_2) { FactoryBot.create(:custom_attribute, :name => "attr_2", :value => 30) } let(:name_of_custom_attribute_1) { "VmOrTemplate-#{CustomAttributeMixin::CUSTOM_ATTRIBUTES_PREFIX}attr_1" } let(:name_of_custom_attribute_2) { "VmOrTemplate-#{CustomAttributeMixin::CUSTOM_ATTRIBUTES_PREFIX}attr_2" } let!(:vm) do - FactoryGirl.create(:vm, :memory_reserve => 10, :custom_attributes => [custom_attribute_1, custom_attribute_2]) + FactoryBot.create(:vm, :memory_reserve => 10, :custom_attributes => [custom_attribute_1, custom_attribute_2]) end before do @@ -37,20 +37,20 @@ end context "expression with " do - let(:cluster) { FactoryGirl.create(:ems_cluster) } - let(:host1) { FactoryGirl.create(:host, :ems_cluster => cluster) } - let(:host2) { FactoryGirl.create(:host, :ems_cluster => cluster) } + let(:cluster) { FactoryBot.create(:ems_cluster) } + let(:host1) { FactoryBot.create(:host, :ems_cluster => cluster) } + let(:host2) { FactoryBot.create(:host, :ems_cluster => cluster) } before do - @rp1 = FactoryGirl.create(:resource_pool) - @rp2 = FactoryGirl.create(:resource_pool) + @rp1 = FactoryBot.create(:resource_pool) + @rp2 = FactoryBot.create(:resource_pool) cluster.with_relationship_type("ems_metadata") { cluster.add_child @rp1 } @rp1.with_relationship_type("ems_metadata") { @rp1.add_child @rp2 } - @vm1 = FactoryGirl.create(:vm_vmware, :host => host1, :ems_cluster => cluster) + @vm1 = FactoryBot.create(:vm_vmware, :host => host1, :ems_cluster => cluster) @vm1.with_relationship_type("ems_metadata") { @vm1.parent = @rp1 } - @vm2 = FactoryGirl.create(:vm_vmware, :host => host2, :ems_cluster => cluster) + @vm2 = FactoryBot.create(:vm_vmware, :host => host2, :ems_cluster => cluster) @vm2.with_relationship_type("ems_metadata") { @vm2.parent = @rp2 } end @@ -96,10 +96,10 @@ end context "expression with " do - let(:vm) { FactoryGirl.create(:vm_vmware, :registry_items => [reg_num, @reg_string]) } - let(:reg_num) { FactoryGirl.create(:registry_item, :name => "HKLM\\SOFTWARE\\WindowsFirewall : EnableFirewall", :data => 0) } + let(:vm) { FactoryBot.create(:vm_vmware, :registry_items => [reg_num, @reg_string]) } + let(:reg_num) { FactoryBot.create(:registry_item, :name => "HKLM\\SOFTWARE\\WindowsFirewall : EnableFirewall", :data => 0) } before do - @reg_string = FactoryGirl.create(:registry_item, :name => "HKLM\\SOFTWARE\\Microsoft\\Ole : EnableDCOM", :data => 'y') + @reg_string = FactoryBot.create(:registry_item, :name => "HKLM\\SOFTWARE\\Microsoft\\Ole : EnableDCOM", :data => 'y') end it "string type registry key data is single quoted" do @@ -114,8 +114,8 @@ end it "does not change the scope for taggings when passed a Tag" do - tag = FactoryGirl.create(:tag, :name => "/managed/foo") - vm = FactoryGirl.create(:vm_vmware) + tag = FactoryBot.create(:tag, :name => "/managed/foo") + vm = FactoryBot.create(:vm_vmware) expr = "/virtual/name == \"/managed/foo\"" described_class.subst(expr, tag) @@ -137,7 +137,7 @@ end describe ".subst_matches?" do - let(:vm1) { FactoryGirl.build(:vm_vmware, :host => FactoryGirl.build(:host, :name => "XXX")) } + let(:vm1) { FactoryBot.build(:vm_vmware, :host => FactoryBot.build(:host, :name => "XXX")) } it "detects match" do expr = "/virtual/host/name == 'XXX' \ diff --git a/spec/models/configured_system_spec.rb b/spec/models/configured_system_spec.rb index fee684c9815..367165a11f0 100644 --- a/spec/models/configured_system_spec.rb +++ b/spec/models/configured_system_spec.rb @@ -1,9 +1,9 @@ describe ConfiguredSystem do it "#counterparts" do - vm = FactoryGirl.create(:vm) - cs1 = FactoryGirl.create(:configured_system, :counterpart => vm) - cs2 = FactoryGirl.create(:configured_system, :counterpart => vm) - cs3 = FactoryGirl.create(:configured_system, :counterpart => vm) + vm = FactoryBot.create(:vm) + cs1 = FactoryBot.create(:configured_system, :counterpart => vm) + cs2 = FactoryBot.create(:configured_system, :counterpart => vm) + cs3 = FactoryBot.create(:configured_system, :counterpart => vm) expect(cs1.counterparts).to match_array([vm, cs2, cs3]) end diff --git a/spec/models/container/purging_spec.rb b/spec/models/container/purging_spec.rb index 9a1e7991ce5..133a1bf46ab 100644 --- a/spec/models/container/purging_spec.rb +++ b/spec/models/container/purging_spec.rb @@ -24,9 +24,9 @@ let(:deleted_date) { 6.months.ago } before do - @old_container = FactoryGirl.create(:container, :deleted_on => deleted_date - 1.day) - @purge_date_container = FactoryGirl.create(:container, :deleted_on => deleted_date) - @new_container = FactoryGirl.create(:container, :deleted_on => deleted_date + 1.day) + @old_container = FactoryBot.create(:container, :deleted_on => deleted_date - 1.day) + @purge_date_container = FactoryBot.create(:container, :deleted_on => deleted_date) + @new_container = FactoryBot.create(:container, :deleted_on => deleted_date + 1.day) end def assert_unpurged_ids(unpurged_ids) diff --git a/spec/models/container_deployment_spec.rb b/spec/models/container_deployment_spec.rb index e69488511f2..db9ef70d22e 100644 --- a/spec/models/container_deployment_spec.rb +++ b/spec/models/container_deployment_spec.rb @@ -1,23 +1,23 @@ describe ContainerDeployment do before do - @container_deployment = FactoryGirl.create(:container_deployment, + @container_deployment = FactoryBot.create(:container_deployment, :method_type => "non_managed", :version => "v2", :kind => "openshift-enterprise") @container_deployment.create_needed_tags - hardware = FactoryGirl.create(:hardware) + hardware = FactoryBot.create(:hardware) hardware.ipaddresses << "10.0.0.1" hardware.ipaddresses << "37.142.68.50" - @container_deployment_node_with_vm_ip = FactoryGirl.create(:container_deployment_node, - :vm => FactoryGirl.create(:vm_vmware, + @container_deployment_node_with_vm_ip = FactoryBot.create(:container_deployment_node, + :vm => FactoryBot.create(:vm_vmware, :hardware => hardware)) - hardware = FactoryGirl.create(:hardware) + hardware = FactoryBot.create(:hardware) hardware.ipaddresses << "37.142.68.51" - @container_deployment_node_with_vm_hostname = FactoryGirl.create(:container_deployment_node, - :vm => FactoryGirl.create(:vm_vmware, + @container_deployment_node_with_vm_hostname = FactoryBot.create(:container_deployment_node, + :vm => FactoryBot.create(:vm_vmware, :hardware => hardware)) - @container_deployment_node_without_vm = FactoryGirl.create(:container_deployment_node, + @container_deployment_node_without_vm = FactoryBot.create(:container_deployment_node, :address => "10.0.0.2") @container_deployment_node_with_vm_ip.tag_add("node") @@ -82,8 +82,8 @@ allow(ServerRole).to receive(:seed_data).and_return(@csv) ServerRole.seed _, _, @zone = EvmSpecHelper.create_guid_miq_server_zone - ems = FactoryGirl.create(:ext_management_system, :zone => @zone) - @node = FactoryGirl.create(:container_node, :name => "n", :ext_management_system => ems) + ems = FactoryBot.create(:ext_management_system, :zone => @zone) + @node = FactoryBot.create(:container_node, :name => "n", :ext_management_system => ems) end it "is direct when no role" do @@ -91,7 +91,7 @@ end it "uses hostname label when present" do - label = FactoryGirl.build(:custom_attribute, + label = FactoryBot.build(:custom_attribute, :name => "kubernetes.io/hostname", :value => "a1.custom.domain", :section => "labels") @@ -100,7 +100,7 @@ end it "uses proxied url when cockpit role is active" do - server = FactoryGirl.create(:miq_server, :ipaddress => "10.0.0.1", :has_active_cockpit_ws => true, :zone => @zone) + server = FactoryBot.create(:miq_server, :ipaddress => "10.0.0.1", :has_active_cockpit_ws => true, :zone => @zone) server.assign_role('cockpit_ws', 1) server.activate_roles('cockpit_ws') expect(@node.cockpit_url).to eq(URI.parse("https://10.0.0.1/cws/=n")) @@ -134,7 +134,7 @@ @container_deployment.authentications.destroy_all end it "parse allow all correctly" do - authentication = FactoryGirl.create(:authentication_allow_all) + authentication = FactoryBot.create(:authentication_allow_all) @container_deployment.authentications << authentication expect(@container_deployment.identity_ansible_config_format).to eq('name' => "example_name", 'login' => "true", @@ -143,7 +143,7 @@ end it "parse github correctly" do - authentication = FactoryGirl.create(:authentication_github) + authentication = FactoryBot.create(:authentication_github) @container_deployment.authentications << authentication expect(@container_deployment.identity_ansible_config_format).to eq("name" => "example_name", "login" => "true", @@ -155,7 +155,7 @@ end it "parse google correctly" do - authentication = FactoryGirl.create(:authentication_google) + authentication = FactoryBot.create(:authentication_google) @container_deployment.authentications << authentication expect(@container_deployment.identity_ansible_config_format).to eq("name" => "example_name", "login" => "true", @@ -167,7 +167,7 @@ end it "parse htpasswd correctly" do - authentication = FactoryGirl.create(:authentication_htpasswd) + authentication = FactoryBot.create(:authentication_htpasswd) @container_deployment.authentications << authentication expect(@container_deployment.identity_ansible_config_format).to eq("name" => "example_name", "login" => "true", @@ -177,7 +177,7 @@ end it "parse ldap correctly" do - authentication = FactoryGirl.create(:authentication_ldap) + authentication = FactoryBot.create(:authentication_ldap) @container_deployment.authentications << authentication expect(@container_deployment.identity_ansible_config_format).to eq("name" => "example_name", "login" => "true", "challenge" => "true", @@ -194,7 +194,7 @@ end it "parse openID correctly" do - authentication = FactoryGirl.create(:authentication_open_id) + authentication = FactoryBot.create(:authentication_open_id) @container_deployment.authentications << authentication expect(@container_deployment.identity_ansible_config_format).to eq("name" => "example_name", "login" => "true", @@ -210,7 +210,7 @@ end it "parse request header correctly" do - authentication = FactoryGirl.create(:authentication_request_header) + authentication = FactoryBot.create(:authentication_request_header) @container_deployment.authentications << authentication expect(@container_deployment.identity_ansible_config_format).to eq("name" => "example_name", "login" => "true", diff --git a/spec/models/container_group/purging_spec.rb b/spec/models/container_group/purging_spec.rb index c0711c46894..817c3b110a9 100644 --- a/spec/models/container_group/purging_spec.rb +++ b/spec/models/container_group/purging_spec.rb @@ -24,9 +24,9 @@ let(:deleted_date) { 6.months.ago } before do - @old_container_group = FactoryGirl.create(:container_group, :deleted_on => deleted_date - 1.day) - @purge_date_container_group = FactoryGirl.create(:container_group, :deleted_on => deleted_date) - @new_container_group = FactoryGirl.create(:container_group, :deleted_on => deleted_date + 1.day) + @old_container_group = FactoryBot.create(:container_group, :deleted_on => deleted_date - 1.day) + @purge_date_container_group = FactoryBot.create(:container_group, :deleted_on => deleted_date) + @new_container_group = FactoryBot.create(:container_group, :deleted_on => deleted_date + 1.day) end def assert_unpurged_ids(unpurged_ids) diff --git a/spec/models/container_group_spec.rb b/spec/models/container_group_spec.rb index a9830c07058..cb4bcc42f82 100644 --- a/spec/models/container_group_spec.rb +++ b/spec/models/container_group_spec.rb @@ -1,22 +1,22 @@ describe ContainerGroup do it "has container volumes and pods" do - pvc = FactoryGirl.create( + pvc = FactoryBot.create( :persistent_volume_claim, :name => "test_claim" ) - group = FactoryGirl.create( + group = FactoryBot.create( :container_group, :name => "group", ) - ems = FactoryGirl.create( + ems = FactoryBot.create( :ems_kubernetes, :id => group.id, :name => "ems" ) - FactoryGirl.create( + FactoryBot.create( :container_volume, :name => "container_volume", :type => 'ContainerVolume', @@ -24,14 +24,14 @@ :persistent_volume_claim => pvc ) - FactoryGirl.create( + FactoryBot.create( :persistent_volume, :name => "persistent_volume0", :parent => ems, :persistent_volume_claim => pvc ) - FactoryGirl.create( + FactoryBot.create( :persistent_volume, :name => "persistent_volume1", :parent => ems, diff --git a/spec/models/container_image/container_image_spec.rb b/spec/models/container_image/container_image_spec.rb index 6fc7a45a3b1..bd2ca26f305 100644 --- a/spec/models/container_image/container_image_spec.rb +++ b/spec/models/container_image/container_image_spec.rb @@ -1,13 +1,13 @@ describe ContainerImage do it "counts containers" do - group = FactoryGirl.create( + group = FactoryBot.create( :container_group, :name => "group", - :container_node => FactoryGirl.create(:container_node, :name => "node") + :container_node => FactoryBot.create(:container_node, :name => "node") ) - expect(FactoryGirl.create( + expect(FactoryBot.create( :container_image, - :containers => FactoryGirl.create_list(:container, 2, :container_group => group) + :containers => FactoryBot.create_list(:container, 2, :container_group => group) ).total_containers).to eq(2) end end diff --git a/spec/models/container_image/purging_spec.rb b/spec/models/container_image/purging_spec.rb index 9999328ecf2..7a3ee4e70ca 100644 --- a/spec/models/container_image/purging_spec.rb +++ b/spec/models/container_image/purging_spec.rb @@ -24,9 +24,9 @@ let(:deleted_date) { 6.months.ago } before do - @old_container_image = FactoryGirl.create(:container_image, :deleted_on => deleted_date - 1.day) - @purge_date_container_image = FactoryGirl.create(:container_image, :deleted_on => deleted_date) - @new_container_image = FactoryGirl.create(:container_image, :deleted_on => deleted_date + 1.day) + @old_container_image = FactoryBot.create(:container_image, :deleted_on => deleted_date - 1.day) + @purge_date_container_image = FactoryBot.create(:container_image, :deleted_on => deleted_date) + @new_container_image = FactoryBot.create(:container_image, :deleted_on => deleted_date + 1.day) end def assert_unpurged_ids(unpurged_ids) diff --git a/spec/models/container_image_spec.rb b/spec/models/container_image_spec.rb index 7e0c0bcb5e6..51cb5414c3d 100644 --- a/spec/models/container_image_spec.rb +++ b/spec/models/container_image_spec.rb @@ -24,21 +24,21 @@ end it "#docker_id" do - image = FactoryGirl.create(:container_image, :image_ref => "docker://id") + image = FactoryBot.create(:container_image, :image_ref => "docker://id") expect(image.docker_id).to eq("id") - image = FactoryGirl.create(:container_image, :image_ref => "docker-pullable://repo/name@id") + image = FactoryBot.create(:container_image, :image_ref => "docker-pullable://repo/name@id") expect(image.docker_id).to eq("repo/name@id") - image = FactoryGirl.create(:container_image, :image_ref => "rocket://id") + image = FactoryBot.create(:container_image, :image_ref => "rocket://id") expect(image.docker_id).to eq(nil) end it "#operating_system=" do - image = FactoryGirl.create(:container_image) + image = FactoryBot.create(:container_image) expect(image.computer_system).to be_nil - image.operating_system = FactoryGirl.create(:operating_system) + image.operating_system = FactoryBot.create(:operating_system) expect(image.computer_system).not_to be_nil expect(image.operating_system).to eq(image.computer_system.operating_system) end diff --git a/spec/models/container_label_tag_mapping_spec.rb b/spec/models/container_label_tag_mapping_spec.rb index 521c0b86c06..c976e843d31 100644 --- a/spec/models/container_label_tag_mapping_spec.rb +++ b/spec/models/container_label_tag_mapping_spec.rb @@ -1,5 +1,5 @@ describe ContainerLabelTagMapping do - let(:cat_classification) { FactoryGirl.create(:classification, :read_only => true, :name => 'kubernetes:1') } + let(:cat_classification) { FactoryBot.create(:classification, :read_only => true, :name => 'kubernetes:1') } let(:cat_tag) { cat_classification.tag } let(:tag1) { cat_classification.add_entry(:name => 'value_1', :description => 'value-1').tag } let(:tag2) { cat_classification.add_entry(:name => 'something_else', :description => 'Another tag').tag } @@ -8,14 +8,14 @@ cat_classification.add_entry(:name => 'my_empty', :description => 'Custom description for empty value').tag end let(:user_tag1) do - FactoryGirl.create(:classification_cost_center_with_tags).entries.first.tag + FactoryBot.create(:classification_cost_center_with_tags).entries.first.tag end let(:user_tag2) do # What's worse, users can create categories with same name structure - but they won't be read_only: - cat = FactoryGirl.create(:classification, :name => 'kubernetes::user_could_enter_this') + cat = FactoryBot.create(:classification, :name => 'kubernetes::user_could_enter_this') cat.add_entry(:name => 'hello', :description => 'Hello').tag end - let(:ems) { FactoryGirl.build(:ext_management_system) } + let(:ems) { FactoryBot.build(:ext_management_system) } def labels(kv) kv.map do |name, value| @@ -43,8 +43,8 @@ def map_to_tags(mapper, model_name, labels_kv) context "with 2 mappings for same label" do before do - FactoryGirl.create(:container_label_tag_mapping, :only_nodes, :label_value => 'value-1', :tag => tag1) - FactoryGirl.create(:container_label_tag_mapping, :only_nodes, :label_value => 'value-1', :tag => tag2) + FactoryBot.create(:container_label_tag_mapping, :only_nodes, :label_value => 'value-1', :tag => tag1) + FactoryBot.create(:container_label_tag_mapping, :only_nodes, :label_value => 'value-1', :tag => tag2) end it "map_labels returns 2 tags" do @@ -55,9 +55,9 @@ def map_to_tags(mapper, model_name, labels_kv) context "with any-value and specific-value mappings" do before do - FactoryGirl.create(:container_label_tag_mapping, :tag => cat_tag) - FactoryGirl.create(:container_label_tag_mapping, :label_value => 'value-1', :tag => tag1) - FactoryGirl.create(:container_label_tag_mapping, :label_value => 'value-1', :tag => tag2) + FactoryBot.create(:container_label_tag_mapping, :tag => cat_tag) + FactoryBot.create(:container_label_tag_mapping, :label_value => 'value-1', :tag => tag1) + FactoryBot.create(:container_label_tag_mapping, :label_value => 'value-1', :tag => tag2) end it "prefers specific-value" do @@ -96,7 +96,7 @@ def map_to_tags(mapper, model_name, labels_kv) it "handles names that differ only by case" do # Kubernetes names are case-sensitive # (but the optional domain prefix must be lowercase). - FactoryGirl.create(:container_label_tag_mapping, + FactoryBot.create(:container_label_tag_mapping, :label_name => 'Name_Case', :label_value => 'value', :tag => tag2) tags = map_to_tags(new_mapper, 'ContainerNode', 'name_case' => 'value') tags2 = map_to_tags(new_mapper, 'ContainerNode', 'Name_Case' => 'value', 'naME_caSE' => 'value') @@ -152,8 +152,8 @@ def map_to_tags(mapper, model_name, labels_kv) context "with 2 any-value mappings onto same category" do before do - FactoryGirl.create(:container_label_tag_mapping, :label_name => 'name1', :tag => cat_tag) - FactoryGirl.create(:container_label_tag_mapping, :label_name => 'name2', :tag => cat_tag) + FactoryBot.create(:container_label_tag_mapping, :label_name => 'name1', :tag => cat_tag) + FactoryBot.create(:container_label_tag_mapping, :label_name => 'name2', :tag => cat_tag) end it "maps same new value in both into 1 new tag" do @@ -165,15 +165,15 @@ def map_to_tags(mapper, model_name, labels_kv) context "given a label with empty value" do it "any-value mapping is ignored" do - FactoryGirl.create(:container_label_tag_mapping, :tag => cat_tag) + FactoryBot.create(:container_label_tag_mapping, :tag => cat_tag) expect(map_to_tags(new_mapper, 'ContainerNode', 'name' => '')).to be_empty end it "honors specific mapping for the empty value" do - FactoryGirl.create(:container_label_tag_mapping, :label_value => '', :tag => empty_tag_under_cat) + FactoryBot.create(:container_label_tag_mapping, :label_value => '', :tag => empty_tag_under_cat) expect(map_to_tags(new_mapper, 'ContainerNode', 'name' => '')).to contain_exactly(empty_tag_under_cat) # same with both any-value and specific-value mappings - FactoryGirl.create(:container_label_tag_mapping, :tag => cat_tag) + FactoryBot.create(:container_label_tag_mapping, :tag => cat_tag) expect(map_to_tags(new_mapper, 'ContainerNode', 'name' => '')).to contain_exactly(empty_tag_under_cat) end end @@ -184,8 +184,8 @@ def map_to_tags(mapper, model_name, labels_kv) context "with any-type and specific-type mappings" do before do - FactoryGirl.create(:container_label_tag_mapping, :only_nodes, :label_value => 'value', :tag => tag1) - FactoryGirl.create(:container_label_tag_mapping, :label_value => 'value', :tag => tag2) + FactoryBot.create(:container_label_tag_mapping, :only_nodes, :label_value => 'value', :tag => tag1) + FactoryBot.create(:container_label_tag_mapping, :label_value => 'value', :tag => tag2) end it "applies both independently" do @@ -199,8 +199,8 @@ def map_to_tags(mapper, model_name, labels_kv) context "any-type specific-value vs specific-type any-value" do before do - FactoryGirl.create(:container_label_tag_mapping, :only_nodes, :tag => cat_tag) - FactoryGirl.create(:container_label_tag_mapping, :label_value => 'value', :tag => tag2) + FactoryBot.create(:container_label_tag_mapping, :only_nodes, :tag => cat_tag) + FactoryBot.create(:container_label_tag_mapping, :label_value => 'value', :tag => tag2) end it "resolves them independently" do @@ -211,7 +211,7 @@ def map_to_tags(mapper, model_name, labels_kv) end describe ".retag_entity" do - let(:node) { FactoryGirl.create(:container_node) } + let(:node) { FactoryBot.create(:container_node) } def ref_to_tag(tag) instance_double(InventoryRefresh::InventoryObject, :id => tag.id) @@ -219,7 +219,7 @@ def ref_to_tag(tag) before do # For tag1, tag2 to be controlled by the mapping, though current implementation doesn't care. - FactoryGirl.create(:container_label_tag_mapping, :tag => cat_tag) + FactoryBot.create(:container_label_tag_mapping, :tag => cat_tag) tag1 tag2 @@ -242,7 +242,7 @@ def ref_to_tag(tag) end it "preserves user tags" do - user_tag = FactoryGirl.create(:tag, :name => '/managed/mycat/mytag') + user_tag = FactoryBot.create(:tag, :name => '/managed/mycat/mytag') expect(Tag.controlled_by_mapping).to contain_exactly(tag1, tag2, tag3) node.tags = [tag1, user_tag1, user_tag2, tag2] expect(node.tags.controlled_by_mapping).to contain_exactly(tag1, tag2) @@ -255,9 +255,9 @@ def ref_to_tag(tag) # What happens with tags no mapping points to? it "considers appropriately named tags as mapping-controlled" do - cat = FactoryGirl.create(:classification, :read_only => true, :name => 'kubernetes:foo') + cat = FactoryBot.create(:classification, :read_only => true, :name => 'kubernetes:foo') k_tag = cat.add_entry(:name => 'unrelated', :description => 'Unrelated tag').tag - cat = FactoryGirl.create(:classification, :read_only => true, :name => 'amazon:river') + cat = FactoryBot.create(:classification, :read_only => true, :name => 'amazon:river') a_tag = cat.add_entry(:name => 'jungle', :description => 'Rainforest').tag expect(Tag.controlled_by_mapping).not_to include(user_tag1, user_tag2) diff --git a/spec/models/container_node/purging_spec.rb b/spec/models/container_node/purging_spec.rb index f76bc984182..8126582e92b 100644 --- a/spec/models/container_node/purging_spec.rb +++ b/spec/models/container_node/purging_spec.rb @@ -24,9 +24,9 @@ let(:deleted_date) { 6.months.ago } before do - @old_container_node = FactoryGirl.create(:container_node, :deleted_on => deleted_date - 1.day) - @purge_date_container_node = FactoryGirl.create(:container_node, :deleted_on => deleted_date) - @new_container_node = FactoryGirl.create(:container_node, :deleted_on => deleted_date + 1.day) + @old_container_node = FactoryBot.create(:container_node, :deleted_on => deleted_date - 1.day) + @purge_date_container_node = FactoryBot.create(:container_node, :deleted_on => deleted_date) + @new_container_node = FactoryBot.create(:container_node, :deleted_on => deleted_date + 1.day) end def assert_unpurged_ids(unpurged_ids) diff --git a/spec/models/container_project/purging_spec.rb b/spec/models/container_project/purging_spec.rb index ef0129dbc8c..fbde5280a1c 100644 --- a/spec/models/container_project/purging_spec.rb +++ b/spec/models/container_project/purging_spec.rb @@ -24,9 +24,9 @@ let(:deleted_date) { 6.months.ago } before do - @old_container_project = FactoryGirl.create(:container_project, :deleted_on => deleted_date - 1.day) - @purge_date_container_project = FactoryGirl.create(:container_project, :deleted_on => deleted_date) - @new_container_project = FactoryGirl.create(:container_project, :deleted_on => deleted_date + 1.day) + @old_container_project = FactoryBot.create(:container_project, :deleted_on => deleted_date - 1.day) + @purge_date_container_project = FactoryBot.create(:container_project, :deleted_on => deleted_date) + @new_container_project = FactoryBot.create(:container_project, :deleted_on => deleted_date + 1.day) end def assert_unpurged_ids(unpurged_ids) diff --git a/spec/models/container_quota/purging_spec.rb b/spec/models/container_quota/purging_spec.rb index 5b1ea79ee42..f00797a84ff 100644 --- a/spec/models/container_quota/purging_spec.rb +++ b/spec/models/container_quota/purging_spec.rb @@ -24,18 +24,18 @@ let(:deleted_date) { 6.months.ago } before do - @old_quota = FactoryGirl.create(:container_quota, :deleted_on => deleted_date - 1.day) - @old_quota_scope = FactoryGirl.create(:container_quota_scope, :container_quota => @old_quota) - @old_quota_old_item = FactoryGirl.create(:container_quota_item, :container_quota => @old_quota, + @old_quota = FactoryBot.create(:container_quota, :deleted_on => deleted_date - 1.day) + @old_quota_scope = FactoryBot.create(:container_quota_scope, :container_quota => @old_quota) + @old_quota_old_item = FactoryBot.create(:container_quota_item, :container_quota => @old_quota, :deleted_on => deleted_date - 1.day) - @old_quota_active_item = FactoryGirl.create(:container_quota_item, :container_quota => @old_quota, + @old_quota_active_item = FactoryBot.create(:container_quota_item, :container_quota => @old_quota, :deleted_on => nil) - @purge_date_quota = FactoryGirl.create(:container_quota, :deleted_on => deleted_date) + @purge_date_quota = FactoryBot.create(:container_quota, :deleted_on => deleted_date) - @new_quota = FactoryGirl.create(:container_quota, :deleted_on => deleted_date + 1.day) - @new_quota_scope = FactoryGirl.create(:container_quota_scope, :container_quota => @new_quota) - @new_quota_old_item = FactoryGirl.create(:container_quota_item, :container_quota => @new_quota, + @new_quota = FactoryBot.create(:container_quota, :deleted_on => deleted_date + 1.day) + @new_quota_scope = FactoryBot.create(:container_quota_scope, :container_quota => @new_quota) + @new_quota_old_item = FactoryBot.create(:container_quota_item, :container_quota => @new_quota, :deleted_on => deleted_date - 1.day) end diff --git a/spec/models/container_quota_item/purging_spec.rb b/spec/models/container_quota_item/purging_spec.rb index 18b7d26d9b1..c389de70995 100644 --- a/spec/models/container_quota_item/purging_spec.rb +++ b/spec/models/container_quota_item/purging_spec.rb @@ -24,25 +24,25 @@ let(:deleted_date) { 6.months.ago } before do - @old_quota = FactoryGirl.create(:container_quota, :deleted_on => deleted_date - 1.day) - @old_quota_scope = FactoryGirl.create(:container_quota_scope, :container_quota => @old_quota) - @old_quota_old_item = FactoryGirl.create(:container_quota_item, :container_quota => @old_quota, + @old_quota = FactoryBot.create(:container_quota, :deleted_on => deleted_date - 1.day) + @old_quota_scope = FactoryBot.create(:container_quota_scope, :container_quota => @old_quota) + @old_quota_old_item = FactoryBot.create(:container_quota_item, :container_quota => @old_quota, :deleted_on => deleted_date - 1.day) - @old_quota_purge_date_item = FactoryGirl.create(:container_quota_item, :container_quota => @old_quota, + @old_quota_purge_date_item = FactoryBot.create(:container_quota_item, :container_quota => @old_quota, :deleted_on => deleted_date) - @old_quota_new_item = FactoryGirl.create(:container_quota_item, :container_quota => @old_quota, + @old_quota_new_item = FactoryBot.create(:container_quota_item, :container_quota => @old_quota, :deleted_on => deleted_date + 1.day) # Quota items may get archived as result of quota edits, while parent quota remains active. - @active_quota = FactoryGirl.create(:container_quota, :deleted_on => nil) - @active_quota_scope = FactoryGirl.create(:container_quota_scope, :container_quota => @active_quota) - @active_quota_old_item = FactoryGirl.create(:container_quota_item, :container_quota => @active_quota, + @active_quota = FactoryBot.create(:container_quota, :deleted_on => nil) + @active_quota_scope = FactoryBot.create(:container_quota_scope, :container_quota => @active_quota) + @active_quota_old_item = FactoryBot.create(:container_quota_item, :container_quota => @active_quota, :deleted_on => deleted_date - 1.day) - @active_quota_purge_date_item = FactoryGirl.create(:container_quota_item, :container_quota => @active_quota, + @active_quota_purge_date_item = FactoryBot.create(:container_quota_item, :container_quota => @active_quota, :deleted_on => deleted_date) - @active_quota_new_item = FactoryGirl.create(:container_quota_item, :container_quota => @active_quota, + @active_quota_new_item = FactoryBot.create(:container_quota_item, :container_quota => @active_quota, :deleted_on => deleted_date + 1.day) - @active_quota_active_item = FactoryGirl.create(:container_quota_item, :container_quota => @active_quota, + @active_quota_active_item = FactoryBot.create(:container_quota_item, :container_quota => @active_quota, :deleted_on => nil) end diff --git a/spec/models/conversion_host/configurations_spec.rb b/spec/models/conversion_host/configurations_spec.rb index 7f5f925ff5a..e566fe1c64c 100644 --- a/spec/models/conversion_host/configurations_spec.rb +++ b/spec/models/conversion_host/configurations_spec.rb @@ -1,5 +1,5 @@ describe ConversionHost do - let(:conversion_host) { FactoryGirl.create(:conversion_host, :resource => vm) } + let(:conversion_host) { FactoryBot.create(:conversion_host, :resource => vm) } let(:params) do { :name => 'transformer', @@ -9,7 +9,7 @@ end context "processing configuration requests" do - let(:vm) { FactoryGirl.create(:vm) } + let(:vm) { FactoryBot.create(:vm) } before(:each) do allow(ConversionHost).to receive(:new).and_return(conversion_host) end @@ -64,8 +64,8 @@ end context "queuing configuration requests" do - let(:ext_management_system) { FactoryGirl.create(:ext_management_system) } - let(:vm) { FactoryGirl.create(:vm, :ext_management_system => ext_management_system) } + let(:ext_management_system) { FactoryBot.create(:ext_management_system) } + let(:vm) { FactoryBot.create(:vm, :ext_management_system => ext_management_system) } let(:expected_task_action) { "Configuring a conversion_host: operation=#{op} resource=(type: #{vm.class.name} id:#{vm.id})" } context ".enable_queue" do diff --git a/spec/models/conversion_host_spec.rb b/spec/models/conversion_host_spec.rb index 34501c47444..c9c9d4bf43a 100644 --- a/spec/models/conversion_host_spec.rb +++ b/spec/models/conversion_host_spec.rb @@ -1,16 +1,16 @@ require "MiqSshUtil" describe ConversionHost do - let(:apst) { FactoryGirl.create(:service_template_ansible_playbook) } + let(:apst) { FactoryBot.create(:service_template_ansible_playbook) } context "provider independent methods" do - let(:host) { FactoryGirl.create(:host) } - let(:vm) { FactoryGirl.create(:vm) } - let(:conversion_host_1) { FactoryGirl.create(:conversion_host, :resource => host, :address => '10.0.0.1') } - let(:conversion_host_2) { FactoryGirl.create(:conversion_host, :resource => vm, :address => '10.0.1.1') } - let(:task_1) { FactoryGirl.create(:service_template_transformation_plan_task, :state => 'active', :conversion_host => conversion_host_1) } - let(:task_2) { FactoryGirl.create(:service_template_transformation_plan_task, :conversion_host => conversion_host_1) } - let(:task_3) { FactoryGirl.create(:service_template_transformation_plan_task, :state => 'active', :conversion_host => conversion_host_2) } + let(:host) { FactoryBot.create(:host) } + let(:vm) { FactoryBot.create(:vm_or_template) } + let(:conversion_host_1) { FactoryBot.create(:conversion_host, :resource => host) } + let(:conversion_host_2) { FactoryBot.create(:conversion_host, :resource => vm) } + let(:task_1) { FactoryBot.create(:service_template_transformation_plan_task, :state => 'active', :conversion_host => conversion_host_1) } + let(:task_2) { FactoryBot.create(:service_template_transformation_plan_task, :conversion_host => conversion_host_1) } + let(:task_3) { FactoryBot.create(:service_template_transformation_plan_task, :state => 'active', :conversion_host => conversion_host_2) } before do allow(conversion_host_1).to receive(:active_tasks).and_return([task_1]) @@ -140,9 +140,9 @@ end context "resource provider is rhevm" do - let(:ems) { FactoryGirl.create(:ems_redhat, :zone => FactoryGirl.create(:zone)) } - let(:host) { FactoryGirl.create(:host_redhat, :ext_management_system => ems) } - let(:conversion_host) { FactoryGirl.create(:conversion_host, :resource => host, :vddk_transport_supported => true) } + let(:ems) { FactoryBot.create(:ems_redhat, :zone => FactoryBot.create(:zone)) } + let(:host) { FactoryBot.create(:host_redhat, :ext_management_system => ems) } + let(:conversion_host) { FactoryBot.create(:conversion_host, :resource => host, :vddk_transport_supported => true) } context "host userid is nil" do before { allow(host).to receive(:authentication_userid).and_return(nil) } @@ -165,16 +165,16 @@ end context "resource provider is openstack" do - let(:ems) { FactoryGirl.create(:ems_openstack, :zone => FactoryGirl.create(:zone)) } - let(:vm) { FactoryGirl.create(:vm_openstack, :ext_management_system => ems) } - let(:conversion_host) { FactoryGirl.create(:conversion_host, :resource => vm, :vddk_transport_supported => true) } + let(:ems) { FactoryBot.create(:ems_openstack, :zone => FactoryBot.create(:zone)) } + let(:vm) { FactoryBot.create(:vm_openstack, :ext_management_system => ems) } + let(:conversion_host) { FactoryBot.create(:conversion_host, :resource => vm, :vddk_transport_supported => true) } context "ems authentications is empty" do it { expect(conversion_host.check_ssh_connection).to be(false) } end context "ems authentications contains ssh_auth" do - let(:ssh_auth) { FactoryGirl.create(:authentication_ssh_keypair, :resource => ems) } + let(:ssh_auth) { FactoryBot.create(:authentication_ssh_keypair, :resource => ems) } before do allow(ems).to receive(:authentications).and_return(ssh_auth) diff --git a/spec/models/custom_attribute_spec.rb b/spec/models/custom_attribute_spec.rb index 0f6da3d0e81..3ab91e58a06 100644 --- a/spec/models/custom_attribute_spec.rb +++ b/spec/models/custom_attribute_spec.rb @@ -1,7 +1,7 @@ describe CustomAttribute do - let(:string_custom_attribute) { FactoryGirl.build(:custom_attribute, :name => "foo", :value => "string", :resource_type => 'ExtManagementSystem') } - let(:time_custom_attribute) { FactoryGirl.build(:custom_attribute, :name => "bar", :value => DateTime.current, :resource_type => 'ExtManagementSystem') } - let(:int_custom_attribute) { FactoryGirl.build(:custom_attribute, :name => "foobar", :value => 5, :resource_type => 'ExtManagementSystem') } + let(:string_custom_attribute) { FactoryBot.build(:custom_attribute, :name => "foo", :value => "string", :resource_type => 'ExtManagementSystem') } + let(:time_custom_attribute) { FactoryBot.build(:custom_attribute, :name => "bar", :value => DateTime.current, :resource_type => 'ExtManagementSystem') } + let(:int_custom_attribute) { FactoryBot.build(:custom_attribute, :name => "foobar", :value => 5, :resource_type => 'ExtManagementSystem') } it "returns the value type of String custom attributes" do expect(string_custom_attribute.value_type).to eq(:string) diff --git a/spec/models/custom_button_event_spec.rb b/spec/models/custom_button_event_spec.rb index 20402d31f7b..f2a59ef51d3 100644 --- a/spec/models/custom_button_event_spec.rb +++ b/spec/models/custom_button_event_spec.rb @@ -1,8 +1,8 @@ describe CustomButtonEvent do - let(:custom_button) { FactoryGirl.create(:custom_button, :applies_to_class => "Vm", :name => "Test Button") } + let(:custom_button) { FactoryBot.create(:custom_button, :applies_to_class => "Vm", :name => "Test Button") } let(:ae_entry_point) { "/SYSTEM/PROCESS/Request" } let(:cb_event) do - FactoryGirl.create(:custom_button_event, + FactoryBot.create(:custom_button_event, :full_data => { :automate_entry_point => ae_entry_point, :button_id => custom_button.id, diff --git a/spec/models/custom_button_set_spec.rb b/spec/models/custom_button_set_spec.rb index 678e0f36771..8a9a0e8a1e6 100644 --- a/spec/models/custom_button_set_spec.rb +++ b/spec/models/custom_button_set_spec.rb @@ -2,15 +2,15 @@ context "find_all_by_class_name" do it "should return all Service and ServiceTemplate buttons only, when ServiceTemplate class is passed in" do set_data = {:applies_to_class => "Service", :group_index => 2} - button_set1 = FactoryGirl.create(:custom_button_set, :name => "set1", :set_data => set_data) + button_set1 = FactoryBot.create(:custom_button_set, :name => "set1", :set_data => set_data) button_set1.save! set_data = {:applies_to_class => "ServiceTemplate", :applies_to_id => 1, :group_index => 1} - button_set2 = FactoryGirl.create(:custom_button_set, :name => "set2", :set_data => set_data) + button_set2 = FactoryBot.create(:custom_button_set, :name => "set2", :set_data => set_data) button_set2.save! set_data = {:applies_to_class => "Vm", :group_index => 3} - button_set3 = FactoryGirl.create(:custom_button_set, :name => "set3", :set_data => set_data) + button_set3 = FactoryBot.create(:custom_button_set, :name => "set3", :set_data => set_data) button_set3.save! button_sets = CustomButtonSet.find_all_by_class_name("ServiceTemplate", 1) @@ -22,12 +22,12 @@ end describe '.filter_with_visibility_expression' do - let(:vm_1) { FactoryGirl.create(:vm_vmware, :name => 'vm_1') } - let(:custom_button_1) { FactoryGirl.create(:custom_button, :applies_to => vm_1) } + let(:vm_1) { FactoryBot.create(:vm_vmware, :name => 'vm_1') } + let(:custom_button_1) { FactoryBot.create(:custom_button, :applies_to => vm_1) } let(:miq_expression) { MiqExpression.new('EQUAL' => {'field' => 'Vm-name', 'value' => "vm_1"}) } - let(:custom_button_2) { FactoryGirl.create(:custom_button, :applies_to => vm_1, :visibility_expression => miq_expression) } + let(:custom_button_2) { FactoryBot.create(:custom_button, :applies_to => vm_1, :visibility_expression => miq_expression) } let(:set_data) { {:applies_to_class => "Vm", :button_order => [custom_button_1.id, custom_button_2.id]} } - let(:custom_button_set) { FactoryGirl.create(:custom_button_set, :name => "set_1", :set_data => set_data) } + let(:custom_button_set) { FactoryBot.create(:custom_button_set, :name => "set_1", :set_data => set_data) } before do [custom_button_1, custom_button_2].each { |x| custom_button_set.add_member(x) } @@ -43,11 +43,11 @@ context 'when any visibility_expression is evaluated to false and any to true' do let(:miq_expression_false) { MiqExpression.new('EQUAL' => {'field' => 'Vm-name', 'value' => "vm_2"}) } - let(:custom_button_1) { FactoryGirl.create(:custom_button, :applies_to => vm_1, :visibility_expression => miq_expression_false) } - let(:custom_button_3) { FactoryGirl.create(:custom_button, :applies_to => vm_1, :visibility_expression => miq_expression) } - let(:custom_button_4) { FactoryGirl.create(:custom_button, :applies_to => vm_1, :visibility_expression => miq_expression) } + let(:custom_button_1) { FactoryBot.create(:custom_button, :applies_to => vm_1, :visibility_expression => miq_expression_false) } + let(:custom_button_3) { FactoryBot.create(:custom_button, :applies_to => vm_1, :visibility_expression => miq_expression) } + let(:custom_button_4) { FactoryBot.create(:custom_button, :applies_to => vm_1, :visibility_expression => miq_expression) } let(:set_data) { {:applies_to_class => "Vm", :button_order => [custom_button_4.id, custom_button_2.id, custom_button_1.id, custom_button_3.id]} } - let(:custom_button_set) { FactoryGirl.create(:custom_button_set, :name => "set_1", :set_data => set_data) } + let(:custom_button_set) { FactoryBot.create(:custom_button_set, :name => "set_1", :set_data => set_data) } before do [custom_button_3, custom_button_4].each { |x| custom_button_set.add_member(x) } @@ -68,10 +68,10 @@ end it "#deep_copy" do - service_template1 = FactoryGirl.create(:service_template) - service_template2 = FactoryGirl.create(:service_template) - custom_button = FactoryGirl.create(:custom_button, :applies_to => service_template1) - custom_button_set = FactoryGirl.create(:custom_button_set) + service_template1 = FactoryBot.create(:service_template) + service_template2 = FactoryBot.create(:service_template) + custom_button = FactoryBot.create(:custom_button, :applies_to => service_template1) + custom_button_set = FactoryBot.create(:custom_button_set) custom_button_set.add_member(custom_button) custom_button_set.deep_copy(:owner => service_template2) diff --git a/spec/models/custom_button_spec.rb b/spec/models/custom_button_spec.rb index 2fb11ed7cfe..c898541497a 100644 --- a/spec/models/custom_button_spec.rb +++ b/spec/models/custom_button_spec.rb @@ -1,9 +1,9 @@ describe CustomButton do describe '.with_array_order' do context 'order by array' do - let!(:custom_button_1) { FactoryGirl.create(:custom_button, :name => 'AAA', :applies_to_id => 100, :applies_to_class => Vm) } - let!(:custom_button_2) { FactoryGirl.create(:custom_button, :name => 'BBB', :applies_to_id => 200, :applies_to_class => Vm) } - let!(:custom_button_3) { FactoryGirl.create(:custom_button, :name => 'CCC', :applies_to_id => 300, :applies_to_class => Vm) } + let!(:custom_button_1) { FactoryBot.create(:custom_button, :name => 'AAA', :applies_to_id => 100, :applies_to_class => Vm) } + let!(:custom_button_2) { FactoryBot.create(:custom_button, :name => 'BBB', :applies_to_id => 200, :applies_to_class => Vm) } + let!(:custom_button_3) { FactoryBot.create(:custom_button, :name => 'CCC', :applies_to_id => 300, :applies_to_class => Vm) } context 'by bigint column' do it 'orders by memory_shares column' do @@ -22,9 +22,9 @@ context "with no buttons" do describe '#evaluate_enablement_expression_for' do let(:miq_expression) { MiqExpression.new('EQUAL' => {'field' => 'Vm-name', 'value' => 'vm_1'}) } - let(:vm) { FactoryGirl.create(:vm_vmware, :name => 'vm_1') } + let(:vm) { FactoryBot.create(:vm_vmware, :name => 'vm_1') } let(:custom_button) do - FactoryGirl.create(:custom_button, :applies_to => vm.class, :name => "foo", :description => "foo foo") + FactoryBot.create(:custom_button, :applies_to => vm.class, :name => "foo", :description => "foo foo") end it 'evaluates enablement expression when expression is not set' do @@ -64,7 +64,7 @@ @ae_uri = MiqAeEngine.create_automation_object(@ae_name, @ae_attributes) @userid = "guest" uri_path, uri_attributes, uri_message = CustomButton.parse_uri(@ae_uri) - @button = FactoryGirl.create(:custom_button, + @button = FactoryBot.create(:custom_button, :name => @button_name, :description => @button_text, :applies_to_class => @button_class, @@ -91,8 +91,8 @@ context "when invoking for a particular VM" do before do - @vm = FactoryGirl.create(:vm_vmware) - @user2 = FactoryGirl.create(:user_with_group) + @vm = FactoryBot.create(:vm_vmware) + @user2 = FactoryBot.create(:user_with_group) EvmSpecHelper.local_miq_server(:is_master => true, :zone => Zone.seed) end @@ -121,19 +121,19 @@ end it ".buttons_for" do - vm = FactoryGirl.create(:vm_vmware) - vm_other = FactoryGirl.create(:vm_vmware) - button1all = FactoryGirl.create(:custom_button, + vm = FactoryBot.create(:vm_vmware) + vm_other = FactoryBot.create(:vm_vmware) + button1all = FactoryBot.create(:custom_button, :applies_to => vm.class, :name => "foo", :description => "foo foo") - button1vm = FactoryGirl.create(:custom_button, + button1vm = FactoryBot.create(:custom_button, :applies_to => vm, :name => "bar", :description => "bar bar") - button2vm = FactoryGirl.create(:custom_button, + button2vm = FactoryBot.create(:custom_button, :applies_to => vm, :name => "foo", :description => "foo foo") @@ -145,8 +145,8 @@ end it "#save" do - ra = FactoryGirl.create(:resource_action, :ae_namespace => 'SYSTEM', :ae_class => 'PROCESS', :ae_message => 'create') - button = FactoryGirl.create(:custom_button, :name => "My test button", :applies_to => Vm, :resource_action => ra) + ra = FactoryBot.create(:resource_action, :ae_namespace => 'SYSTEM', :ae_class => 'PROCESS', :ae_message => 'create') + button = FactoryBot.create(:custom_button, :name => "My test button", :applies_to => Vm, :resource_action => ra) button.save ra.ae_message = "new message" @@ -157,12 +157,12 @@ context "validates uniqueness" do before do - @vm = FactoryGirl.create(:vm_vmware) + @vm = FactoryBot.create(:vm_vmware) @default_name = @default_description = "boom" end it "applies_to_class" do - button_for_all_vms = FactoryGirl.create(:custom_button, + button_for_all_vms = FactoryBot.create(:custom_button, :applies_to_class => 'Vm', :name => @default_name, :description => @default_description) @@ -200,9 +200,9 @@ end it "applies_to_instance" do - vm_other = FactoryGirl.create(:vm_vmware) + vm_other = FactoryBot.create(:vm_vmware) - button_for_single_vm = FactoryGirl.create(:custom_button, + button_for_single_vm = FactoryBot.create(:custom_button, :applies_to => @vm, :name => @default_name, :description => @default_description) @@ -306,19 +306,19 @@ end it "#copy" do - service_template1 = FactoryGirl.create(:service_template) - service_template2 = FactoryGirl.create(:service_template) - button = FactoryGirl.create(:custom_button, :applies_to => service_template1) + service_template1 = FactoryBot.create(:service_template) + service_template2 = FactoryBot.create(:service_template) + button = FactoryBot.create(:custom_button, :applies_to => service_template1) expect { button.copy(:applies_to => service_template2) }.to change { CustomButton.count }.by(1) end describe "publish custom button event" do - let(:vm) { FactoryGirl.create(:vm_vmware) } - let(:vm2) { FactoryGirl.create(:vm_vmware) } - let(:vm3) { FactoryGirl.create(:vm_vmware) } - let(:user) { FactoryGirl.create(:user_with_group) } - let(:resource_action) { FactoryGirl.create(:resource_action, :ae_namespace => 'SYSTEM', :ae_class => 'PROCESS', :ae_instance => 'Request') } - let(:custom_button) { FactoryGirl.create(:custom_button, :applies_to => vm.class, :resource_action => resource_action) } + let(:vm) { FactoryBot.create(:vm_vmware) } + let(:vm2) { FactoryBot.create(:vm_vmware) } + let(:vm3) { FactoryBot.create(:vm_vmware) } + let(:user) { FactoryBot.create(:user_with_group) } + let(:resource_action) { FactoryBot.create(:resource_action, :ae_namespace => 'SYSTEM', :ae_class => 'PROCESS', :ae_instance => 'Request') } + let(:custom_button) { FactoryBot.create(:custom_button, :applies_to => vm.class, :resource_action => resource_action) } before do EvmSpecHelper.local_miq_server(:is_master => true, :zone => Zone.seed) diff --git a/spec/models/customization_template_spec.rb b/spec/models/customization_template_spec.rb index 60654a73f7d..9fa4febf8dd 100644 --- a/spec/models/customization_template_spec.rb +++ b/spec/models/customization_template_spec.rb @@ -1,14 +1,14 @@ describe CustomizationTemplate do context "unique name validation" do it "doesn't allow same name, same pxe_image_type in same region" do - pit = FactoryGirl.create(:pxe_image_type) - FactoryGirl.create(:customization_template, :name => "fred", :pxe_image_type => pit) - expect { FactoryGirl.create(:customization_template, :name => "fred", :pxe_image_type => pit) }.to raise_error(ActiveRecord::RecordInvalid) + pit = FactoryBot.create(:pxe_image_type) + FactoryBot.create(:customization_template, :name => "fred", :pxe_image_type => pit) + expect { FactoryBot.create(:customization_template, :name => "fred", :pxe_image_type => pit) }.to raise_error(ActiveRecord::RecordInvalid) end it "allows same name, different pxe_image_type in same region" do - FactoryGirl.create(:customization_template, :name => "fred", :pxe_image_type => FactoryGirl.create(:pxe_image_type)) - FactoryGirl.create(:customization_template, :name => "fred", :pxe_image_type => FactoryGirl.create(:pxe_image_type)) + FactoryBot.create(:customization_template, :name => "fred", :pxe_image_type => FactoryBot.create(:pxe_image_type)) + FactoryBot.create(:customization_template, :name => "fred", :pxe_image_type => FactoryBot.create(:pxe_image_type)) first, second = described_class.all expect(first.name).to eq(second.name) @@ -17,9 +17,9 @@ end it "allows different name, same pxe_image_type in same region" do - pit = FactoryGirl.create(:pxe_image_type) - FactoryGirl.create(:customization_template, :name => "fred", :pxe_image_type => pit) - FactoryGirl.create(:customization_template, :name => "nick", :pxe_image_type => pit) + pit = FactoryBot.create(:pxe_image_type) + FactoryBot.create(:customization_template, :name => "fred", :pxe_image_type => pit) + FactoryBot.create(:customization_template, :name => "nick", :pxe_image_type => pit) expect(described_class.count).to eq(2) first, second = described_class.all @@ -41,12 +41,12 @@ end it "allows same name, different pxe_image_types in different regions" do - pit = FactoryGirl.create(:pxe_image_type) - template = FactoryGirl.create(:customization_template, :name => "nick", :pxe_image_type => pit) + pit = FactoryBot.create(:pxe_image_type) + template = FactoryBot.create(:customization_template, :name => "nick", :pxe_image_type => pit) other_template_id = ApplicationRecord.id_in_region(template.id, MiqRegion.my_region_number + 1) other_pit_id = ApplicationRecord.id_in_region(pit.id, MiqRegion.my_region_number + 1) - other_pit = FactoryGirl.create(:pxe_image_type, :id => other_pit_id) - FactoryGirl.create(:customization_template, :name => "nick", :pxe_image_type => other_pit, :id => other_template_id) + other_pit = FactoryBot.create(:pxe_image_type, :id => other_pit_id) + FactoryBot.create(:customization_template, :name => "nick", :pxe_image_type => other_pit, :id => other_template_id) first, second = described_class.all expect(first.name).to eq(second.name) diff --git a/spec/models/database_backup_spec.rb b/spec/models/database_backup_spec.rb index a950dbe9379..3e2bfd8ef92 100644 --- a/spec/models/database_backup_spec.rb +++ b/spec/models/database_backup_spec.rb @@ -1,20 +1,20 @@ describe DatabaseBackup do context "region" do - let!(:region) { FactoryGirl.create(:miq_region, :region => 3) } + let!(:region) { FactoryBot.create(:miq_region, :region => 3) } before do allow(described_class).to receive_messages(:my_region_number => region.region) end it "should set region_name based on my_region_number if database backup has a region" do - backup = FactoryGirl.create(:database_backup) + backup = FactoryBot.create(:database_backup) expect(backup.region_name).to eq("region_#{region.region}") end it "should set region_name to region_0 if region is unknown" do # my_region_number => 0 if REGION file is missing or empty allow(described_class).to receive_messages(:my_region_number => 0) - backup = FactoryGirl.create(:database_backup) + backup = FactoryBot.create(:database_backup) expect(backup.region_name).to eq("region_0") end @@ -29,17 +29,17 @@ @name = "adhoc schedule" @sanitized_name = "adhoc_schedule" - @schedule = FactoryGirl.create(:miq_schedule, :name => @name) + @schedule = FactoryBot.create(:miq_schedule, :name => @name) end it "should set schedule_name to schedule_unknown if database backup was not passed a valid schedule id" do - backup = FactoryGirl.create(:database_backup) + backup = FactoryBot.create(:database_backup) backup.instance_variable_set(:@schedule, nil) expect(backup.schedule_name).to eq("schedule_unknown") end it "should set schedule_name to a sanitized version of the schedule's name if database backup was passed a valid schedule id" do - backup = FactoryGirl.create(:database_backup) + backup = FactoryBot.create(:database_backup) backup.instance_variable_set(:@sch, @schedule) expect(backup.schedule_name).to eq(@sanitized_name) end diff --git a/spec/models/dialog/container_template_service_dialog_spec.rb b/spec/models/dialog/container_template_service_dialog_spec.rb index 271b40925d3..7b6c74ed77f 100644 --- a/spec/models/dialog/container_template_service_dialog_spec.rb +++ b/spec/models/dialog/container_template_service_dialog_spec.rb @@ -1,11 +1,11 @@ describe Dialog::ContainerTemplateServiceDialog do describe "#create_dialog" do - let(:container_template) { FactoryGirl.create(:container_template) } + let(:container_template) { FactoryBot.create(:container_template) } let(:params) { [] } before do - params << FactoryGirl.create(:container_template_parameter, :name => "name_1", :value => "value_1", :required => true) - params << FactoryGirl.create(:container_template_parameter, :name => "name_2", :value => "value_2") - params << FactoryGirl.create(:container_template_parameter, :name => "name_3", :value => "value_3", :required => true, :generate => "expression") + params << FactoryBot.create(:container_template_parameter, :name => "name_1", :value => "value_1", :required => true) + params << FactoryBot.create(:container_template_parameter, :name => "name_2", :value => "value_2") + params << FactoryBot.create(:container_template_parameter, :name => "name_3", :value => "value_3", :required => true, :generate => "expression") end it "creates a dialog for a container template with parameters" do diff --git a/spec/models/dialog/orchestration_template_service_dialog_spec.rb b/spec/models/dialog/orchestration_template_service_dialog_spec.rb index 4ab5aeef958..0ba8657472f 100644 --- a/spec/models/dialog/orchestration_template_service_dialog_spec.rb +++ b/spec/models/dialog/orchestration_template_service_dialog_spec.rb @@ -1,6 +1,6 @@ describe Dialog::OrchestrationTemplateServiceDialog do let(:orchestration_template) do - FactoryGirl.create(:orchestration_template).tap do |template| + FactoryBot.create(:orchestration_template).tap do |template| allow(template).to receive(:parameter_groups).and_return(param_groups) allow(template).to receive(:tabs).and_return(tabs) if tabs.count > 0 end diff --git a/spec/models/dialog_field_date_time_control_spec.rb b/spec/models/dialog_field_date_time_control_spec.rb index 7d9420bd086..467e5142c4c 100644 --- a/spec/models/dialog_field_date_time_control_spec.rb +++ b/spec/models/dialog_field_date_time_control_spec.rb @@ -1,7 +1,7 @@ describe DialogFieldDateTimeControl do context "legacy tests" do let!(:user) do - User.current_user = FactoryGirl.create(:user) + User.current_user = FactoryBot.create(:user) end context "with UTC timezone" do diff --git a/spec/models/dialog_field_drop_down_list_spec.rb b/spec/models/dialog_field_drop_down_list_spec.rb index da6368197aa..c10f21d8d13 100644 --- a/spec/models/dialog_field_drop_down_list_spec.rb +++ b/spec/models/dialog_field_drop_down_list_spec.rb @@ -3,7 +3,7 @@ let(:data_type) { "string" } let(:sort_by) { :description } let(:sort_order) { :ascending } - let(:df) { FactoryGirl.create(:dialog_field_sorted_item, :label => 'drop_down_list', :name => 'drop_down_list', :data_type => data_type, :sort_by => sort_by, :sort_order => sort_order) } + let(:df) { FactoryBot.create(:dialog_field_sorted_item, :label => 'drop_down_list', :name => 'drop_down_list', :data_type => data_type, :sort_by => sort_by, :sort_order => sort_order) } describe "#sort_by" do it "allows setters and getters" do @@ -386,7 +386,7 @@ end context "dialog field dropdown without options hash" do - let(:df) { FactoryGirl.create(:dialog_field_drop_down_list, :name => 'test drop down') } + let(:df) { FactoryBot.create(:dialog_field_drop_down_list, :name => 'test drop down') } describe "#force_multi_value" do context "when force_multi_value is present" do @@ -421,7 +421,7 @@ end context "dialog field dropdown with options hash" do - let(:df) { FactoryGirl.create(:dialog_field_drop_down_list, :name => 'test drop down', :options => {:force_multi_value => true}) } + let(:df) { FactoryBot.create(:dialog_field_drop_down_list, :name => 'test drop down', :options => {:force_multi_value => true}) } it "#force_multi_value" do expect(df.force_multi_value).to be_truthy end diff --git a/spec/models/dialog_field_serializer_spec.rb b/spec/models/dialog_field_serializer_spec.rb index 394ead51d0e..16dbc597ec0 100644 --- a/spec/models/dialog_field_serializer_spec.rb +++ b/spec/models/dialog_field_serializer_spec.rb @@ -123,7 +123,7 @@ end context 'with associations' do - let(:dialog_field_responders) { [FactoryGirl.build(:dialog_field_text_box)] } + let(:dialog_field_responders) { [FactoryBot.build(:dialog_field_text_box)] } it 'serializes the dialog_field with all attributes and non_empty associations' do expect(dialog_field_serializer.serialize(dialog_field, dialog_field_responders)) diff --git a/spec/models/dialog_field_spec.rb b/spec/models/dialog_field_spec.rb index 019ed443b12..a45d8b670d4 100644 --- a/spec/models/dialog_field_spec.rb +++ b/spec/models/dialog_field_spec.rb @@ -1,18 +1,18 @@ describe DialogField do context "legacy tests" do - let(:df) { FactoryGirl.create(:dialog_field) } + let(:df) { FactoryBot.create(:dialog_field) } it "sets default value for required attribute" do expect(df.required).to eq(false) expect(df.visible).to eq(true) end it "fields named 'action' or 'controller' are invalid" do - action_field = FactoryGirl.build(:dialog_field, :name => 'action') + action_field = FactoryBot.build(:dialog_field, :name => 'action') expect(action_field).not_to be_valid - controller_field = FactoryGirl.build(:dialog_field, :name => 'controller') + controller_field = FactoryBot.build(:dialog_field, :name => 'controller') expect(controller_field).not_to be_valid - foo_field = FactoryGirl.build(:dialog_field, :name => 'foo') + foo_field = FactoryBot.build(:dialog_field, :name => 'foo') expect(foo_field).to be_valid end diff --git a/spec/models/dialog_field_tag_control_spec.rb b/spec/models/dialog_field_tag_control_spec.rb index d89444da6a2..73df6fbd8cf 100644 --- a/spec/models/dialog_field_tag_control_spec.rb +++ b/spec/models/dialog_field_tag_control_spec.rb @@ -4,12 +4,12 @@ def add_entry(cat, options) # Inherit from parent classification options.merge!(:read_only => cat.read_only, :syntax => cat.syntax, :single_value => cat.single_value, :ns => cat.ns) options.merge!(:parent_id => cat.id) # Ugly way to set up a child - FactoryGirl.create(:classification, options) + FactoryBot.create(:classification, options) end context "dialog field tag control without options hash" do before do - @df = FactoryGirl.create(:dialog_field_tag_control, :label => 'test tag category', :name => 'test tag category') + @df = FactoryBot.create(:dialog_field_tag_control, :label => 'test tag category', :name => 'test tag category') end it "#category=" do @@ -63,7 +63,7 @@ def add_entry(cat, options) context "dialog field tag control with with options hash and category" do before do - @df = FactoryGirl.create(:dialog_field_tag_control, :label => 'test tag category', :name => 'test tag category', + @df = FactoryBot.create(:dialog_field_tag_control, :label => 'test tag category', :name => 'test tag category', :options => {:force_single_value => true, :category_id => 1, :category_name => 'category', :category_description => 'description'} ) end @@ -87,8 +87,8 @@ def add_entry(cat, options) context "dialog field with tag control hash and tag categories" do before do - @cat = FactoryGirl.create(:classification, :description => "Auto Approve - Max CPU", :name => "prov_max_cpu", :single_value => 1) - @df = FactoryGirl.create(:dialog_field_tag_control, :label => 'test tag category', :name => 'test tag category', + @cat = FactoryBot.create(:classification, :description => "Auto Approve - Max CPU", :name => "prov_max_cpu", :single_value => 1) + @df = FactoryBot.create(:dialog_field_tag_control, :label => 'test tag category', :name => 'test tag category', :options => {:category_id => @cat.id, :category_name => 'category', :category_description => 'description'} ) end @@ -96,8 +96,8 @@ def add_entry(cat, options) it "#single_value?" do expect(@df.single_value?).to be_truthy - cat = FactoryGirl.create(:classification, :description => "Auto Approve - Max Memory", :name => "prov_max_memory", :single_value => 0) - df = FactoryGirl.create(:dialog_field_tag_control, :label => 'test tag category', :name => 'test tag category', + cat = FactoryBot.create(:classification, :description => "Auto Approve - Max Memory", :name => "prov_max_memory", :single_value => 0) + df = FactoryBot.create(:dialog_field_tag_control, :label => 'test tag category', :name => 'test tag category', :options => {:category_id => cat.id, :category_name => 'category', :category_description => 'description'} ) @@ -107,12 +107,12 @@ def add_entry(cat, options) context "dialog field tag control and Classification seeded" do before do - cat = FactoryGirl.create(:classification, :description => "Environment", :name => "environment", :single_value => true, :parent_id => 0) + cat = FactoryBot.create(:classification, :description => "Environment", :name => "environment", :single_value => true, :parent_id => 0) add_entry(cat, :name => "dev", :description => "Development") add_entry(cat, :name => "test", :description => "Test") add_entry(cat, :name => "prod", :description => "Production") - cat = FactoryGirl.create(:classification, :description => "Department", :name => "department", :single_value => false, :parent_id => 0) + cat = FactoryBot.create(:classification, :description => "Department", :name => "department", :single_value => false, :parent_id => 0) add_entry(cat, :name => "accounting", :description => "Accounting") add_entry(cat, :name => "engineering", :description => "Engineering") add_entry(cat, :name => "marketing", :description => "Marketing") @@ -128,7 +128,7 @@ def add_entry(cat, options) context "with dialog field tag control without options hash" do before do - @df = FactoryGirl.create(:dialog_field_tag_control, :label => 'test tag', :name => 'test tag', :options => {:force_single_select => true}) + @df = FactoryBot.create(:dialog_field_tag_control, :label => 'test tag', :name => 'test tag', :options => {:force_single_select => true}) end it "automate_output_value with an empty value" do diff --git a/spec/models/dialog_field_text_box_spec.rb b/spec/models/dialog_field_text_box_spec.rb index 6c66d3780b0..87a4d36b1f4 100644 --- a/spec/models/dialog_field_text_box_spec.rb +++ b/spec/models/dialog_field_text_box_spec.rb @@ -70,7 +70,7 @@ end context "dialog field text box without options hash" do - let(:df) { FactoryGirl.build(:dialog_field_text_box, :label => 'test field', :name => 'test field') } + let(:df) { FactoryBot.build(:dialog_field_text_box, :label => 'test field', :name => 'test field') } it "#protected?" do expect(df).not_to be_protected @@ -83,7 +83,7 @@ end context "dialog field text box without protected field" do - let(:df) { FactoryGirl.build(:dialog_field_text_box, :label => 'test field', :name => 'test field', :options => {:protected => false}) } + let(:df) { FactoryBot.build(:dialog_field_text_box, :label => 'test field', :name => 'test field', :options => {:protected => false}) } it "#protected?" do expect(df).not_to be_protected @@ -95,7 +95,7 @@ end context "dialog field text box with protected field" do - let(:df) { FactoryGirl.build(:dialog_field_text_box, :label => 'test field', :name => 'test field', :options => {:protected => true}) } + let(:df) { FactoryBot.build(:dialog_field_text_box, :label => 'test field', :name => 'test field', :options => {:protected => true}) } it "#protected?" do expect(df).to be_protected @@ -121,7 +121,7 @@ end context "validation" do - let(:df) { FactoryGirl.build(:dialog_field_text_box, :label => 'test field', :name => 'test field') } + let(:df) { FactoryBot.build(:dialog_field_text_box, :label => 'test field', :name => 'test field') } describe "#validate_field_data" do let(:dt) { double('DialogTab', :label => 'tab') } diff --git a/spec/models/dialog_group_spec.rb b/spec/models/dialog_group_spec.rb index 4a1afab4885..49bf961cf3e 100644 --- a/spec/models/dialog_group_spec.rb +++ b/spec/models/dialog_group_spec.rb @@ -1,5 +1,5 @@ describe DialogGroup do - let(:dialog_group) { FactoryGirl.build(:dialog_group, :label => 'group') } + let(:dialog_group) { FactoryBot.build(:dialog_group, :label => 'group') } context "#validate_children" do it "fails without element" do expect { dialog_group.save! } @@ -7,7 +7,7 @@ end it "validates with at least one element" do - dialog_group.dialog_fields << FactoryGirl.create(:dialog_field, :label => 'field 1', :name => 'field1') + dialog_group.dialog_fields << FactoryBot.create(:dialog_field, :label => 'field 1', :name => 'field1') expect_any_instance_of(DialogField).to receive(:valid?) expect(dialog_group.errors.full_messages).to be_empty dialog_group.validate_children @@ -22,9 +22,9 @@ end describe '#update_dialog_fields' do - let(:dialog_fields) { FactoryGirl.create_list(:dialog_field, 2) } - let(:dialog_group) { FactoryGirl.create(:dialog_group, :dialog_fields => dialog_fields) } - let(:resource_action) { FactoryGirl.create(:resource_action) } + let(:dialog_fields) { FactoryBot.create_list(:dialog_field, 2) } + let(:dialog_group) { FactoryBot.create(:dialog_group, :dialog_fields => dialog_fields) } + let(:resource_action) { FactoryBot.create(:resource_action) } context 'a collection of dialog fields containing two objects with ids and one without an id' do let(:updated_fields) do diff --git a/spec/models/dialog_spec.rb b/spec/models/dialog_spec.rb index 27e1372883c..850dd1e5e99 100644 --- a/spec/models/dialog_spec.rb +++ b/spec/models/dialog_spec.rb @@ -61,35 +61,35 @@ describe "#content" do it "returns the serialized content" do - dialog = FactoryGirl.create(:dialog, :description => "foo", :label => "bar") + dialog = FactoryBot.create(:dialog, :description => "foo", :label => "bar") expect(dialog.content).to match([hash_including("description" => "foo", "label" => "bar")]) end end context "validate label uniqueness" do it "with same label" do - dialog = FactoryGirl.create(:dialog) + dialog = FactoryBot.create(:dialog) - expect { FactoryGirl.create(:dialog, :name => dialog.name) } + expect { FactoryBot.create(:dialog, :name => dialog.name) } .to raise_error(ActiveRecord::RecordInvalid, /Name is not unique within region/) end it "with different labels" do - FactoryGirl.create(:dialog) + FactoryBot.create(:dialog) - expect { FactoryGirl.create(:dialog) }.to_not raise_error + expect { FactoryBot.create(:dialog) }.to_not raise_error end end context "#destroy" do it "destroy without resource_action association" do - expect(FactoryGirl.create(:dialog).destroy).to be_truthy + expect(FactoryBot.create(:dialog).destroy).to be_truthy expect(Dialog.count).to eq(0) end it "destroy with resource_action association" do - dialog = FactoryGirl.create(:dialog) - FactoryGirl.create(:resource_action, :action => "Provision", :dialog => dialog, :resource_type => Dialog, :resource_id => dialog.id) + dialog = FactoryBot.create(:dialog) + FactoryBot.create(:resource_action, :action => "Provision", :dialog => dialog, :resource_type => Dialog, :resource_id => dialog.id) expect { dialog.destroy } .to raise_error(RuntimeError, "Dialog cannot be deleted because it is connected to other components: [\"Dialog:#{dialog.id} - #{dialog.name}\"]") expect(Dialog.count).to eq(1) @@ -98,10 +98,10 @@ describe "dialog structures" do before do - @dialog = FactoryGirl.build(:dialog, :label => 'dialog') - @dialog_tab = FactoryGirl.create(:dialog_tab, :label => 'tab') - @dialog_group = FactoryGirl.create(:dialog_group, :label => 'group') - @dialog_field = FactoryGirl.create(:dialog_field, :label => 'field 1', :name => 'field_1') + @dialog = FactoryBot.build(:dialog, :label => 'dialog') + @dialog_tab = FactoryBot.create(:dialog_tab, :label => 'tab') + @dialog_group = FactoryBot.create(:dialog_group, :label => 'group') + @dialog_field = FactoryBot.create(:dialog_field, :label => 'field 1', :name => 'field_1') end it "dialogs contain tabs" do @@ -122,26 +122,26 @@ end it "add controls" do - text_box = FactoryGirl.create(:dialog_field_text_box, :label => 'text box', :name => 'text_box') + text_box = FactoryBot.create(:dialog_field_text_box, :label => 'text box', :name => 'text_box') @dialog_group.dialog_fields << text_box expect(@dialog_group.dialog_fields.size).to eq(1) - tags = FactoryGirl.create(:dialog_field_tag_control, :label => 'tags', :name => 'tags') + tags = FactoryBot.create(:dialog_field_tag_control, :label => 'tags', :name => 'tags') @dialog_group.dialog_fields << tags @dialog_group.reload expect(@dialog_group.dialog_fields.size).to eq(2) - button = FactoryGirl.create(:dialog_field_button, :label => 'button', :name => 'button') + button = FactoryBot.create(:dialog_field_button, :label => 'button', :name => 'button') @dialog_group.dialog_fields << button @dialog_group.reload expect(@dialog_group.dialog_fields.size).to eq(3) - check_box = FactoryGirl.create(:dialog_field_text_box, :label => 'check box', :name => "check_box") + check_box = FactoryBot.create(:dialog_field_text_box, :label => 'check box', :name => "check_box") @dialog_group.dialog_fields << check_box @dialog_group.reload expect(@dialog_group.dialog_fields.size).to eq(4) - drop_down_list = FactoryGirl.create(:dialog_field_drop_down_list, :label => 'drop down list', :name => "drop_down_1") + drop_down_list = FactoryBot.create(:dialog_field_drop_down_list, :label => 'drop down list', :name => "drop_down_1") @dialog_group.dialog_fields << drop_down_list @dialog_group.reload expect(@dialog_group.dialog_fields.size).to eq(5) @@ -150,10 +150,10 @@ context "#remove_all_resources" do before do - @dialog = FactoryGirl.create(:dialog, :label => 'dialog') - @dialog_tab = FactoryGirl.create(:dialog_tab, :label => 'tab') - @dialog_group = FactoryGirl.create(:dialog_group, :label => 'group') - @dialog_field = FactoryGirl.create(:dialog_field, :label => 'field 1', :name => "field_1") + @dialog = FactoryBot.create(:dialog, :label => 'dialog') + @dialog_tab = FactoryBot.create(:dialog_tab, :label => 'tab') + @dialog_group = FactoryBot.create(:dialog_group, :label => 'group') + @dialog_field = FactoryBot.create(:dialog_field, :label => 'field 1', :name => "field_1") end it "dialogs contain tabs" do @@ -180,10 +180,10 @@ context "remove resources" do before do - @dialog = FactoryGirl.create(:dialog, :label => 'dialog') - @dialog_tab = FactoryGirl.create(:dialog_tab, :label => 'tab') - @dialog_group = FactoryGirl.create(:dialog_group, :label => 'group') - @dialog_group_field = FactoryGirl.create(:dialog_field, :label => 'group field', :name => "group field") + @dialog = FactoryBot.create(:dialog, :label => 'dialog') + @dialog_tab = FactoryBot.create(:dialog_tab, :label => 'tab') + @dialog_group = FactoryBot.create(:dialog_group, :label => 'group') + @dialog_group_field = FactoryBot.create(:dialog_field, :label => 'group field', :name => "group field") @dialog.dialog_tabs << @dialog_tab @dialog_tab.dialog_groups << @dialog_group @@ -225,11 +225,11 @@ context "#each_field" do before do - @dialog = FactoryGirl.create(:dialog, :label => 'dialog') - @dialog_tab = FactoryGirl.create(:dialog_tab, :label => 'tab') - @dialog_group = FactoryGirl.create(:dialog_group, :label => 'group') - @dialog_field = FactoryGirl.create(:dialog_field, :label => 'field 1', :name => "field_1") - @dialog_field2 = FactoryGirl.create(:dialog_field, :label => 'field 2', :name => "field_2") + @dialog = FactoryBot.create(:dialog, :label => 'dialog') + @dialog_tab = FactoryBot.create(:dialog_tab, :label => 'tab') + @dialog_group = FactoryBot.create(:dialog_group, :label => 'group') + @dialog_field = FactoryBot.create(:dialog_field, :label => 'field 1', :name => "field_1") + @dialog_field2 = FactoryBot.create(:dialog_field, :label => 'field 2', :name => "field_2") @dialog.dialog_tabs << @dialog_tab @dialog_tab.dialog_groups << @dialog_group @@ -261,10 +261,10 @@ end describe '#update_tabs' do - let(:dialog_field) { FactoryGirl.create_list(:dialog_field, 1, :label => 'field') } - let(:dialog_group) { FactoryGirl.create_list(:dialog_group, 1, :label => 'group', :dialog_fields => dialog_field) } - let(:dialog_tab) { FactoryGirl.create_list(:dialog_tab, 1, :label => 'tab', :dialog_groups => dialog_group) } - let(:dialog) { FactoryGirl.create(:dialog, :label => 'dialog', :dialog_tabs => dialog_tab) } + let(:dialog_field) { FactoryBot.create_list(:dialog_field, 1, :label => 'field') } + let(:dialog_group) { FactoryBot.create_list(:dialog_group, 1, :label => 'group', :dialog_fields => dialog_field) } + let(:dialog_tab) { FactoryBot.create_list(:dialog_tab, 1, :label => 'tab', :dialog_groups => dialog_group) } + let(:dialog) { FactoryBot.create(:dialog, :label => 'dialog', :dialog_tabs => dialog_tab) } let(:updated_content) do [ @@ -335,7 +335,7 @@ end before do - dialog.dialog_tabs << FactoryGirl.create(:dialog_tab) + dialog.dialog_tabs << FactoryBot.create(:dialog_tab) end it 'deletes the removed dialog_tab' do @@ -348,16 +348,16 @@ context "#dialog_fields" do before do - @dialog = FactoryGirl.create(:dialog, :label => 'dialog') - @dialog_tab = FactoryGirl.create(:dialog_tab, :label => 'tab') - @dialog_group = FactoryGirl.create(:dialog_group, :label => 'group') - @dialog_field = FactoryGirl.create(:dialog_field, :label => 'field 1', :name => "field_1") - @dialog_field2 = FactoryGirl.create(:dialog_field, :label => 'field 2', :name => "field_2") + @dialog = FactoryBot.create(:dialog, :label => 'dialog') + @dialog_tab = FactoryBot.create(:dialog_tab, :label => 'tab') + @dialog_group = FactoryBot.create(:dialog_group, :label => 'group') + @dialog_field = FactoryBot.create(:dialog_field, :label => 'field 1', :name => "field_1") + @dialog_field2 = FactoryBot.create(:dialog_field, :label => 'field 2', :name => "field_2") @dialog.dialog_tabs << @dialog_tab - @dialog.dialog_tabs << FactoryGirl.create(:dialog_tab, :label => 'tab2') + @dialog.dialog_tabs << FactoryBot.create(:dialog_tab, :label => 'tab2') @dialog_tab.dialog_groups << @dialog_group - @dialog_tab.dialog_groups << FactoryGirl.create(:dialog_group, :label => 'group2') + @dialog_tab.dialog_groups << FactoryBot.create(:dialog_group, :label => 'group2') @dialog_group.dialog_fields << @dialog_field @dialog_group.dialog_fields << @dialog_field2 @@ -380,7 +380,7 @@ end context "validate children before save" do - let(:dialog) { FactoryGirl.build(:dialog, :label => 'dialog') } + let(:dialog) { FactoryBot.build(:dialog, :label => 'dialog') } it "fails without tab" do expect { dialog.save! }.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Dialog #{dialog.label} must have at least one Tab") @@ -388,27 +388,27 @@ context "unique field names" do before do - dialog.dialog_tabs << FactoryGirl.create(:dialog_tab, :label => 'tab') - dialog.dialog_tabs.first.dialog_groups << FactoryGirl.create(:dialog_group, :label => 'group') - dialog.dialog_tabs.first.dialog_groups.first.dialog_fields << FactoryGirl.create(:dialog_field, :label => 'field 1', :name => 'field1') + dialog.dialog_tabs << FactoryBot.create(:dialog_tab, :label => 'tab') + dialog.dialog_tabs.first.dialog_groups << FactoryBot.create(:dialog_group, :label => 'group') + dialog.dialog_tabs.first.dialog_groups.first.dialog_fields << FactoryBot.create(:dialog_field, :label => 'field 1', :name => 'field1') end it "fails with two identical field names on different groups" do - dialog.dialog_tabs.first.dialog_groups << FactoryGirl.create(:dialog_group, :label => 'group2') - dialog.dialog_tabs.first.dialog_groups.last.dialog_fields << FactoryGirl.create(:dialog_field, :label => 'field 3', :name => 'field1') + dialog.dialog_tabs.first.dialog_groups << FactoryBot.create(:dialog_group, :label => 'group2') + dialog.dialog_tabs.first.dialog_groups.last.dialog_fields << FactoryBot.create(:dialog_field, :label => 'field 3', :name => 'field1') expect { dialog.save! } .to raise_error(ActiveRecord::RecordInvalid, /Dialog field name cannot be duplicated on a dialog: field1/) end it "fails with two identical field names on same group" do - dialog.dialog_tabs.first.dialog_groups.first.dialog_fields << FactoryGirl.create(:dialog_field, :label => 'field 3', :name => 'field1') + dialog.dialog_tabs.first.dialog_groups.first.dialog_fields << FactoryBot.create(:dialog_field, :label => 'field 3', :name => 'field1') expect { dialog.save! } .to raise_error(ActiveRecord::RecordInvalid, /Dialog field name cannot be duplicated on a dialog: field1/) end end it "validates with tab" do - dialog.dialog_tabs << FactoryGirl.create(:dialog_tab, :label => 'tab') + dialog.dialog_tabs << FactoryBot.create(:dialog_tab, :label => 'tab') expect_any_instance_of(DialogTab).to receive(:valid?) expect(dialog.errors.full_messages).to be_empty dialog.validate_children @@ -417,7 +417,7 @@ describe "#deep_copy" do let(:dialog_service) { Dialog::OrchestrationTemplateServiceDialog.new } - let(:template) { FactoryGirl.create(:orchestration_template).tap { |t| allow(t).to receive(:parameter_groups).and_return([]) } } + let(:template) { FactoryBot.create(:orchestration_template).tap { |t| allow(t).to receive(:parameter_groups).and_return([]) } } let(:dialog) { dialog_service.create_dialog('test', template) } it "clones the dialog and all containing components" do diff --git a/spec/models/dialog_tab_spec.rb b/spec/models/dialog_tab_spec.rb index 7660640b122..889a18ac2f3 100644 --- a/spec/models/dialog_tab_spec.rb +++ b/spec/models/dialog_tab_spec.rb @@ -1,5 +1,5 @@ describe DialogTab do - let(:dialog_tab) { FactoryGirl.build(:dialog_tab, :label => 'tab') } + let(:dialog_tab) { FactoryBot.build(:dialog_tab, :label => 'tab') } context "#validate_children" do it "fails without box" do expect { dialog_tab.save! } @@ -7,7 +7,7 @@ end it "validates with box" do - dialog_tab.dialog_groups << FactoryGirl.create(:dialog_group, :label => 'box') + dialog_tab.dialog_groups << FactoryBot.create(:dialog_group, :label => 'box') expect_any_instance_of(DialogGroup).to receive(:valid?) expect(dialog_tab.errors.full_messages).to be_empty dialog_tab.validate_children @@ -21,15 +21,15 @@ end it "returns [] when empty dialog_group " do - dialog_tab.dialog_groups << FactoryGirl.build(:dialog_group) + dialog_tab.dialog_groups << FactoryBot.build(:dialog_group) expect(dialog_tab.dialog_fields).to be_empty end end describe '#update_dialog_groups' do - let(:dialog_fields) { FactoryGirl.create_list(:dialog_field, 2) } - let(:dialog_groups) { FactoryGirl.create_list(:dialog_group, 2) } - let(:dialog_tab) { FactoryGirl.create(:dialog_tab, :dialog_groups => dialog_groups) } + let(:dialog_fields) { FactoryBot.create_list(:dialog_field, 2) } + let(:dialog_groups) { FactoryBot.create_list(:dialog_group, 2) } + let(:dialog_tab) { FactoryBot.create(:dialog_tab, :dialog_groups => dialog_groups) } before do dialog_groups.each_with_index { |group, index| group.dialog_fields << dialog_fields[index] } diff --git a/spec/models/disk_spec.rb b/spec/models/disk_spec.rb index 839f8b0b591..e9f0ea6a2f3 100644 --- a/spec/models/disk_spec.rb +++ b/spec/models/disk_spec.rb @@ -3,7 +3,7 @@ describe ".used_disk_storage" do context "with nothing" do - let(:disk) { FactoryGirl.build(:disk) } + let(:disk) { FactoryBot.build(:disk) } it "calculates in ruby" do expect(disk.used_disk_storage).to eq(0) @@ -16,7 +16,7 @@ end context "with size" do - let(:disk) { FactoryGirl.build(:disk, :size => 1024) } + let(:disk) { FactoryBot.build(:disk, :size => 1024) } it "calculates in ruby" do expect(disk.used_disk_storage).to eq(1024) @@ -29,7 +29,7 @@ end context "with size_on_disk" do - let(:disk) { FactoryGirl.build(:disk, :size_on_disk => 1024, :size => 10240) } + let(:disk) { FactoryBot.build(:disk, :size_on_disk => 1024, :size => 10240) } it "calculates in ruby" do expect(disk.used_disk_storage).to eq(1024) diff --git a/spec/models/drift_state/purging_spec.rb b/spec/models/drift_state/purging_spec.rb index 53b6226a7d9..58531bddb57 100644 --- a/spec/models/drift_state/purging_spec.rb +++ b/spec/models/drift_state/purging_spec.rb @@ -13,16 +13,16 @@ stub_settings(@vmdb_config) @rr1 = [ - FactoryGirl.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => 1, :timestamp => (6.months + 1.days).to_i.seconds.ago.utc), - FactoryGirl.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => 1, :timestamp => (6.months - 1.days).to_i.seconds.ago.utc) + FactoryBot.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => 1, :timestamp => (6.months + 1.days).to_i.seconds.ago.utc), + FactoryBot.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => 1, :timestamp => (6.months - 1.days).to_i.seconds.ago.utc) ] @rr2 = [ - FactoryGirl.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => 2, :timestamp => (6.months + 2.days).to_i.seconds.ago.utc), - FactoryGirl.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => 2, :timestamp => (6.months + 1.days).to_i.seconds.ago.utc), - FactoryGirl.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => 2, :timestamp => (6.months - 1.days).to_i.seconds.ago.utc) + FactoryBot.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => 2, :timestamp => (6.months + 2.days).to_i.seconds.ago.utc), + FactoryBot.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => 2, :timestamp => (6.months + 1.days).to_i.seconds.ago.utc), + FactoryBot.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => 2, :timestamp => (6.months - 1.days).to_i.seconds.ago.utc) ] @rr_orphaned = [ - FactoryGirl.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => nil, :timestamp => (6.months - 1.days).to_i.seconds.ago.utc) + FactoryBot.create(:drift_state, :resource_type => 'VmOrTemplate', :resource_id => nil, :timestamp => (6.months - 1.days).to_i.seconds.ago.utc) ] end diff --git a/spec/models/dynamic_dialog_field_value_processor_spec.rb b/spec/models/dynamic_dialog_field_value_processor_spec.rb index a44e2d482e3..37e69529ddc 100644 --- a/spec/models/dynamic_dialog_field_value_processor_spec.rb +++ b/spec/models/dynamic_dialog_field_value_processor_spec.rb @@ -1,5 +1,5 @@ describe DynamicDialogFieldValueProcessor do - let(:user) { FactoryGirl.create(:user_with_group) } + let(:user) { FactoryBot.create(:user_with_group) } let(:dynamic_dialog_field_value_processor) { described_class.new } describe "#values_from_automate" do diff --git a/spec/models/embedded_ansible_worker/runner_spec.rb b/spec/models/embedded_ansible_worker/runner_spec.rb index 9be17a20709..632c7664a89 100644 --- a/spec/models/embedded_ansible_worker/runner_spec.rb +++ b/spec/models/embedded_ansible_worker/runner_spec.rb @@ -11,7 +11,7 @@ s } let(:worker_guid) { SecureRandom.uuid } - let(:worker) { FactoryGirl.create(:embedded_ansible_worker, :guid => worker_guid, :miq_server_id => miq_server.id) } + let(:worker) { FactoryBot.create(:embedded_ansible_worker, :guid => worker_guid, :miq_server_id => miq_server.id) } let(:runner) { worker allow_any_instance_of(described_class).to receive(:worker_initialization) @@ -61,7 +61,7 @@ .with(instance_of(ManageIQ::Providers::EmbeddedAnsible::Provider), api_connection) runner.update_embedded_ansible_provider - new_zone = FactoryGirl.create(:zone) + new_zone = FactoryBot.create(:zone) miq_server.update(:hostname => "boringserver", :zone => new_zone) runner.update_embedded_ansible_provider @@ -110,7 +110,7 @@ end context "with a provider" do - let!(:provider) { FactoryGirl.create(:provider_embedded_ansible, :with_authentication) } + let!(:provider) { FactoryBot.create(:provider_embedded_ansible, :with_authentication) } it "runs an authentication check if embedded ansible is alive and the credentials are not valid" do auth = provider.authentications.first @@ -143,7 +143,7 @@ it "updates provider zone if appliance zone changed" do allow(embedded_ansible_instance).to receive(:alive?).and_return(true) - miq_server.update(:zone => FactoryGirl.create(:zone)) + miq_server.update(:zone => FactoryBot.create(:zone)) runner.do_work expect(provider.reload.zone).to eq(miq_server.zone) @@ -165,7 +165,7 @@ runner.do_work original_zone = miq_server.zone - miq_server.update(:zone => FactoryGirl.create(:zone)) + miq_server.update(:zone => FactoryBot.create(:zone)) # zone was just checked, doesn't do anything yet runner.do_work @@ -187,7 +187,7 @@ before do ServerRole.seed NotificationType.seed - FactoryGirl.create(:user_admin) + FactoryBot.create(:user_admin) end it "creates a notification to inform the user that the service has started" do diff --git a/spec/models/embedded_ansible_worker_spec.rb b/spec/models/embedded_ansible_worker_spec.rb index 80ec0bac3d2..92780abc6ea 100644 --- a/spec/models/embedded_ansible_worker_spec.rb +++ b/spec/models/embedded_ansible_worker_spec.rb @@ -1,8 +1,8 @@ describe EmbeddedAnsibleWorker do - subject { FactoryGirl.create(:embedded_ansible_worker) } + subject { FactoryBot.create(:embedded_ansible_worker) } context "ObjectManagement concern" do - let(:provider) { FactoryGirl.create(:provider_embedded_ansible) } + let(:provider) { FactoryBot.create(:provider_embedded_ansible) } let(:api_connection) { double("AnsibleAPIConnection", :api => tower_api) } let(:tower_api) do methods = { diff --git a/spec/models/ems_cluster/capacity_planning_spec.rb b/spec/models/ems_cluster/capacity_planning_spec.rb index e9c972cf780..55104053c0e 100644 --- a/spec/models/ems_cluster/capacity_planning_spec.rb +++ b/spec/models/ems_cluster/capacity_planning_spec.rb @@ -1,6 +1,6 @@ describe EmsCluster::CapacityPlanning do before do - @cluster = FactoryGirl.create(:ems_cluster) + @cluster = FactoryBot.create(:ems_cluster) end it "virtual columns" do @@ -209,9 +209,9 @@ it "#capacity_failover_host_resources_with_failover_hosts" do hosts = [ - FactoryGirl.create(:host, :hardware => FactoryGirl.create(:hardware, :cpu_total_cores => 4), :failover => true), - FactoryGirl.create(:host, :hardware => FactoryGirl.create(:hardware, :cpu_total_cores => 2), :failover => true), - FactoryGirl.create(:host, :hardware => FactoryGirl.create(:hardware, :cpu_total_cores => 1), :failover => false) + FactoryBot.create(:host, :hardware => FactoryBot.create(:hardware, :cpu_total_cores => 4), :failover => true), + FactoryBot.create(:host, :hardware => FactoryBot.create(:hardware, :cpu_total_cores => 2), :failover => true), + FactoryBot.create(:host, :hardware => FactoryBot.create(:hardware, :cpu_total_cores => 1), :failover => false) ] @cluster.hosts << hosts expect(@cluster.capacity_failover_host_resources_with_failover_hosts(1, :vcpu)).to eq(6.0) @@ -219,8 +219,8 @@ it "#capacity_failover_host_resources_without_failover_hosts" do hosts = [ - FactoryGirl.create(:host, :hardware => FactoryGirl.create(:hardware, :cpu_total_cores => 4), :failover => false), - FactoryGirl.create(:host, :hardware => FactoryGirl.create(:hardware, :cpu_total_cores => 2), :failover => false) + FactoryBot.create(:host, :hardware => FactoryBot.create(:hardware, :cpu_total_cores => 4), :failover => false), + FactoryBot.create(:host, :hardware => FactoryBot.create(:hardware, :cpu_total_cores => 2), :failover => false) ] @cluster.hosts << hosts expect(@cluster.capacity_failover_host_resources_without_failover_hosts(1, :vcpu)).to eq(3.0) diff --git a/spec/models/ems_cluster_spec.rb b/spec/models/ems_cluster_spec.rb index 9a42ccc7185..ebb8e46259f 100644 --- a/spec/models/ems_cluster_spec.rb +++ b/spec/models/ems_cluster_spec.rb @@ -1,22 +1,22 @@ describe EmsCluster do context("VMware") do before do - @cluster = FactoryGirl.create(:ems_cluster) - @host1 = FactoryGirl.create(:host, :ems_cluster => @cluster) - @host2 = FactoryGirl.create(:host, :ems_cluster => @cluster) - @rp1 = FactoryGirl.create(:resource_pool) - @rp2 = FactoryGirl.create(:resource_pool) + @cluster = FactoryBot.create(:ems_cluster) + @host1 = FactoryBot.create(:host, :ems_cluster => @cluster) + @host2 = FactoryBot.create(:host, :ems_cluster => @cluster) + @rp1 = FactoryBot.create(:resource_pool) + @rp2 = FactoryBot.create(:resource_pool) @cluster.with_relationship_type("ems_metadata") { @cluster.add_child @rp1 } @rp1.with_relationship_type("ems_metadata") { @rp1.add_child @rp2 } - @vm1 = FactoryGirl.create(:vm_vmware, :host => @host1, :ems_cluster => @cluster) + @vm1 = FactoryBot.create(:vm_vmware, :host => @host1, :ems_cluster => @cluster) @vm1.with_relationship_type("ems_metadata") { @vm1.parent = @rp1 } - @template1 = FactoryGirl.create(:template_vmware, :host => @host1, :ems_cluster => @cluster) + @template1 = FactoryBot.create(:template_vmware, :host => @host1, :ems_cluster => @cluster) - @vm2 = FactoryGirl.create(:vm_vmware, :host => @host2, :ems_cluster => @cluster) + @vm2 = FactoryBot.create(:vm_vmware, :host => @host2, :ems_cluster => @cluster) @vm2.with_relationship_type("ems_metadata") { @vm2.parent = @rp2 } - @template2 = FactoryGirl.create(:template_vmware, :host => @host2, :ems_cluster => @cluster) + @template2 = FactoryBot.create(:template_vmware, :host => @host2, :ems_cluster => @cluster) end it('#vms_and_templates') { expect(@cluster.vms_and_templates).to match_array [@vm1, @vm2, @template1, @template2] } @@ -61,23 +61,23 @@ context("RedHat") do before do - @cluster = FactoryGirl.create(:ems_cluster) - @host1 = FactoryGirl.create(:host, :ems_cluster => @cluster) - @host2 = FactoryGirl.create(:host, :ems_cluster => @cluster) - @rp1 = FactoryGirl.create(:resource_pool) - @rp2 = FactoryGirl.create(:resource_pool) + @cluster = FactoryBot.create(:ems_cluster) + @host1 = FactoryBot.create(:host, :ems_cluster => @cluster) + @host2 = FactoryBot.create(:host, :ems_cluster => @cluster) + @rp1 = FactoryBot.create(:resource_pool) + @rp2 = FactoryBot.create(:resource_pool) @cluster.with_relationship_type("ems_metadata") { @cluster.add_child @rp1 } @rp1.with_relationship_type("ems_metadata") { @rp1.add_child @rp2 } - @vm1 = FactoryGirl.create(:vm_redhat, :host => @host1, :ems_cluster => @cluster) + @vm1 = FactoryBot.create(:vm_redhat, :host => @host1, :ems_cluster => @cluster) @vm1.with_relationship_type("ems_metadata") { @vm1.parent = @rp1 } - @vm2 = FactoryGirl.create(:vm_redhat, :host => @host2, :ems_cluster => @cluster) + @vm2 = FactoryBot.create(:vm_redhat, :host => @host2, :ems_cluster => @cluster) @vm2.with_relationship_type("ems_metadata") { @vm2.parent = @rp2 } - @template1 = FactoryGirl.create(:template_redhat, :ems_cluster => @cluster) - @template2 = FactoryGirl.create(:template_redhat, :ems_cluster => @cluster) + @template1 = FactoryBot.create(:template_redhat, :ems_cluster => @cluster) + @template2 = FactoryBot.create(:template_redhat, :ems_cluster => @cluster) end it('#vms_and_templates') { expect(@cluster.vms_and_templates).to match_array [@vm1, @vm2, @template1, @template2] } @@ -116,7 +116,7 @@ it "#save_drift_state" do # TODO: Beef up with more data - cluster = FactoryGirl.create(:ems_cluster) + cluster = FactoryBot.create(:ems_cluster) cluster.save_drift_state expect(cluster.drift_states.size).to eq(1) @@ -140,11 +140,11 @@ context("#perf_capture_enabled_host_ids=") do before do - @miq_region = FactoryGirl.create(:miq_region, :region => 1) + @miq_region = FactoryBot.create(:miq_region, :region => 1) allow(MiqRegion).to receive(:my_region).and_return(@miq_region) - @cluster = FactoryGirl.create(:ems_cluster) - @host1 = FactoryGirl.create(:host, :ems_cluster => @cluster) - @host2 = FactoryGirl.create(:host, :ems_cluster => @cluster) + @cluster = FactoryBot.create(:ems_cluster) + @host1 = FactoryBot.create(:host, :ems_cluster => @cluster) + @host2 = FactoryBot.create(:host, :ems_cluster => @cluster) end it "Initially Performance capture for cluster and its hosts should not be set" do @@ -178,26 +178,26 @@ context "#node_types" do before do - @ems1 = FactoryGirl.create(:ems_vmware) - @ems2 = FactoryGirl.create(:ems_openstack_infra) + @ems1 = FactoryBot.create(:ems_vmware) + @ems2 = FactoryBot.create(:ems_openstack_infra) end it "returns :mixed_clusters when there are both openstack & non-openstack clusters in db" do - FactoryGirl.create(:ems_cluster, :ems_id => @ems1.id) - FactoryGirl.create(:ems_cluster, :ems_id => @ems2.id) + FactoryBot.create(:ems_cluster, :ems_id => @ems1.id) + FactoryBot.create(:ems_cluster, :ems_id => @ems2.id) result = EmsCluster.node_types expect(result).to eq(:mixed_clusters) end it "returns :openstack when there are only openstack clusters in db" do - FactoryGirl.create(:ems_cluster, :ems_id => @ems2.id) + FactoryBot.create(:ems_cluster, :ems_id => @ems2.id) result = EmsCluster.node_types expect(result).to eq(:openstack) end it "returns :non_openstack when there are non-openstack clusters in db" do - FactoryGirl.create(:ems_cluster, :ems_id => @ems1.id) + FactoryBot.create(:ems_cluster, :ems_id => @ems1.id) result = EmsCluster.node_types expect(result).to eq(:non_openstack) end @@ -205,31 +205,31 @@ context "#openstack_cluster?" do it "returns true for openstack cluster" do - ems = FactoryGirl.create(:ems_openstack_infra) - cluster = FactoryGirl.create(:ems_cluster, :ems_id => ems.id) + ems = FactoryBot.create(:ems_openstack_infra) + cluster = FactoryBot.create(:ems_cluster, :ems_id => ems.id) result = cluster.openstack_cluster? expect(result).to be_truthy end it "returns false for non-openstack cluster" do - ems = FactoryGirl.create(:ems_vmware) - cluster = FactoryGirl.create(:ems_cluster, :ems_id => ems.id) + ems = FactoryBot.create(:ems_vmware) + cluster = FactoryBot.create(:ems_cluster, :ems_id => ems.id) result = cluster.openstack_cluster? expect(result).to be_falsey end end context "#tenant_identity" do - let(:admin) { FactoryGirl.create(:user_with_group, :userid => "admin") } - let(:tenant) { FactoryGirl.create(:tenant) } - let(:ems) { FactoryGirl.create(:ext_management_system, :tenant => tenant) } + let(:admin) { FactoryBot.create(:user_with_group, :userid => "admin") } + let(:tenant) { FactoryBot.create(:tenant) } + let(:ems) { FactoryBot.create(:ext_management_system, :tenant => tenant) } before { admin } subject { @cluster.tenant_identity } it "has tenant from provider" do - @cluster = FactoryGirl.create(:ems_cluster, :ems_id => ems.id) + @cluster = FactoryBot.create(:ems_cluster, :ems_id => ems.id) expect(subject).to eq(admin) expect(subject.current_group).to eq(ems.tenant.default_miq_group) @@ -237,7 +237,7 @@ end it "without a provider, has tenant from root tenant" do - @cluster = FactoryGirl.create(:ems_cluster) + @cluster = FactoryBot.create(:ems_cluster) expect(subject).to eq(admin) expect(subject.current_group).to eq(Tenant.root_tenant.default_miq_group) @@ -247,8 +247,8 @@ context "#upgrade_cluster" do before do - @ems = FactoryGirl.create(:ems_redhat_with_authentication_with_ca, :skip_validate) - @cluster = FactoryGirl.create(:ems_cluster, :ems_id => @ems.id) + @ems = FactoryBot.create(:ems_redhat_with_authentication_with_ca, :skip_validate) + @cluster = FactoryBot.create(:ems_cluster, :ems_id => @ems.id) my_server = double("my_server", :guid => "guid1") allow(MiqServer).to receive(:my_server).and_return(my_server) end @@ -273,8 +273,8 @@ context "non rhv" do before do - @ems = FactoryGirl.create(:ext_management_system) - @cluster = FactoryGirl.create(:ems_cluster, :ems_id => @ems.id) + @ems = FactoryBot.create(:ext_management_system) + @cluster = FactoryBot.create(:ems_cluster, :ems_id => @ems.id) end it 'does not support upgrade_cluster' do diff --git a/spec/models/ems_event_spec.rb b/spec/models/ems_event_spec.rb index 0863924d931..da100f1aa50 100644 --- a/spec/models/ems_event_spec.rb +++ b/spec/models/ems_event_spec.rb @@ -1,10 +1,10 @@ describe EmsEvent do context "model" do - let(:ems1) { FactoryGirl.create(:ems_kubernetes) } - let(:ems2) { FactoryGirl.create(:ems_kubernetes) } + let(:ems1) { FactoryBot.create(:ems_kubernetes) } + let(:ems2) { FactoryBot.create(:ems_kubernetes) } it "Find ems events and generated events for ext management systems" do - generated_event = FactoryGirl.create(:ems_event, :ext_management_system => ems1, :generating_ems => ems2) + generated_event = FactoryBot.create(:ems_event, :ext_management_system => ems1, :generating_ems => ems2) expect(ems1.ems_events).to match_array([generated_event]) expect(ems2.generated_events).to match_array([generated_event]) end @@ -12,13 +12,13 @@ context "container events" do let(:ems_ref) { "test_ems_ref" } - let(:ems) { FactoryGirl.create(:ems_kubernetes) } + let(:ems) { FactoryBot.create(:ems_kubernetes) } let(:event_hash) { { :ems_ref => "event-ref", :ems_id => ems.id, :event_type => "STUFF_HAPPENED" } } - let(:container_project) { FactoryGirl.create(:container_project, :ext_management_system => ems) } + let(:container_project) { FactoryBot.create(:container_project, :ext_management_system => ems) } context "on node" do let(:node_event_hash) { event_hash.merge(:container_node_ems_ref => ems_ref) } - let!(:container_node) { FactoryGirl.create(:container_node, :ext_management_system => ems, :name => "Test Node", :ems_ref => ems_ref) } + let!(:container_node) { FactoryBot.create(:container_node, :ext_management_system => ems, :name => "Test Node", :ems_ref => ems_ref) } it "process_container_entities_in_event! links node id to event" do EmsEvent.process_container_entities_in_event!(node_event_hash) @@ -38,7 +38,7 @@ context "on pod" do let(:pod_event_hash) { event_hash.merge(:container_group_ems_ref => ems_ref) } - let!(:container_group) { FactoryGirl.create(:container_group, :ext_management_system => ems, :container_project => container_project, :name => "Test Group", :ems_ref => ems_ref) } + let!(:container_group) { FactoryBot.create(:container_group, :ext_management_system => ems, :container_project => container_project, :name => "Test Group", :ems_ref => ems_ref) } it "process_container_entities_in_event! links pod id to event" do EmsEvent.process_container_entities_in_event!(pod_event_hash) @@ -53,7 +53,7 @@ context "on replicator" do let(:repl_event_hash) { event_hash.merge(:container_replicator_ems_ref => ems_ref) } - let!(:container_replicator) { FactoryGirl.create(:container_replicator, :ext_management_system => ems, :container_project => container_project, :name => "Test Replicator", :ems_ref => ems_ref) } + let!(:container_replicator) { FactoryBot.create(:container_replicator, :ext_management_system => ems, :container_project => container_project, :name => "Test Replicator", :ems_ref => ems_ref) } it "process_container_entities_in_event! links replicator id to event" do EmsEvent.process_container_entities_in_event!(repl_event_hash) @@ -68,11 +68,11 @@ end context "with availability zones" do - let(:vm) { FactoryGirl.create(:vm_openstack, :ems_ref => "vm1") } + let(:vm) { FactoryBot.create(:vm_openstack, :ems_ref => "vm1") } before do - @zone = FactoryGirl.create(:small_environment) + @zone = FactoryBot.create(:small_environment) @ems = @zone.ext_management_systems.first - @availability_zone = FactoryGirl.create(:availability_zone_openstack, :ems_ref => "az1") + @availability_zone = FactoryBot.create(:availability_zone_openstack, :ems_ref => "az1") end context ".process_availability_zone_in_event!" do @@ -111,7 +111,7 @@ end context ".add_queue" do - let(:ems) { FactoryGirl.create(:ems_kubernetes) } + let(:ems) { FactoryBot.create(:ems_kubernetes) } let(:event_hash) do { :ems_ref => "event-ref", @@ -221,9 +221,9 @@ end context ".add" do - let(:ems) { FactoryGirl.create(:ext_management_system) } + let(:ems) { FactoryBot.create(:ext_management_system) } context "with a VM" do - let(:vm) { FactoryGirl.create(:vm, :uid_ems => '3ace5197-3d6a-4cb3-aeb2-e8348e428775', :ems_ref => 'vm-123') } + let(:vm) { FactoryBot.create(:vm, :uid_ems => '3ace5197-3d6a-4cb3-aeb2-e8348e428775', :ems_ref => 'vm-123') } let(:event) do { :ems_id => ems.id, diff --git a/spec/models/ems_folder_spec.rb b/spec/models/ems_folder_spec.rb index 7b550051825..fe4a4accdb7 100644 --- a/spec/models/ems_folder_spec.rb +++ b/spec/models/ems_folder_spec.rb @@ -1,18 +1,18 @@ describe EmsFolder do context "with folder tree" do before do - @root = FactoryGirl.create(:ems_folder, :name => "root") + @root = FactoryBot.create(:ems_folder, :name => "root") - @dc = FactoryGirl.create(:ems_folder, :name => "dc") + @dc = FactoryBot.create(:ems_folder, :name => "dc") @dc.parent = @root - @sib1 = FactoryGirl.create(:ems_folder, :name => "sib1") + @sib1 = FactoryBot.create(:ems_folder, :name => "sib1") @sib1.parent = @dc - @sib2 = FactoryGirl.create(:ems_folder, :name => "sib2") + @sib2 = FactoryBot.create(:ems_folder, :name => "sib2") @sib2.parent = @dc - @leaf = FactoryGirl.create(:ems_folder, :name => "leaf") + @leaf = FactoryBot.create(:ems_folder, :name => "leaf") @leaf.parent = @sib2 end diff --git a/spec/models/ems_refresh/link_inventory_spec.rb b/spec/models/ems_refresh/link_inventory_spec.rb index 3d7a854a778..87705ef6768 100644 --- a/spec/models/ems_refresh/link_inventory_spec.rb +++ b/spec/models/ems_refresh/link_inventory_spec.rb @@ -2,11 +2,11 @@ context ".link_ems_inventory" do let!(:ems) do _, _, zone = EvmSpecHelper.local_guid_miq_server_zone - FactoryGirl.create(:ems_vmware, :zone => zone).tap do |e| + FactoryBot.create(:ems_vmware, :zone => zone).tap do |e| build_vmware_folder_structure!(e) folder = e.ems_folders.find_by(:name => "blue1") - folder.add_child(FactoryGirl.create(:vm_vmware, :name => "vm1", :ems_id => e.id)) - folder.add_child(FactoryGirl.create(:vm_vmware, :name => "vm2", :ems_id => e.id)) + folder.add_child(FactoryBot.create(:vm_vmware, :name => "vm1", :ems_id => e.id)) + folder.add_child(FactoryBot.create(:vm_vmware, :name => "vm2", :ems_id => e.id)) end end let(:folder1) { ems.ems_folders.find_by(:name => "blue1") } diff --git a/spec/models/ems_refresh/metadata_relats_spec.rb b/spec/models/ems_refresh/metadata_relats_spec.rb index 88be2869d05..c758cb56bab 100644 --- a/spec/models/ems_refresh/metadata_relats_spec.rb +++ b/spec/models/ems_refresh/metadata_relats_spec.rb @@ -1,17 +1,17 @@ describe EmsRefresh::MetadataRelats do context ".vmdb_relats" do before do - @zone = FactoryGirl.create(:zone) - @ems = FactoryGirl.create(:ems_vmware, :zone => @zone) + @zone = FactoryBot.create(:zone) + @ems = FactoryBot.create(:ems_vmware, :zone => @zone) - @cluster = FactoryGirl.create(:ems_cluster, :ext_management_system => @ems) - @host = FactoryGirl.create(:host, :ext_management_system => @ems, :ems_cluster => @cluster) - @vm = FactoryGirl.create(:vm_vmware, :ext_management_system => @ems, :ems_cluster => @cluster, :host => @host) - @template = FactoryGirl.create(:template_vmware, :ext_management_system => @ems) - @rp = FactoryGirl.create(:resource_pool, :ext_management_system => @ems) - @host_folder = FactoryGirl.create(:vmware_folder_host, :ext_management_system => @ems) - @vm_folder_1 = FactoryGirl.create(:vmware_folder_vm, :ext_management_system => @ems, :name => "folder1") - @vm_folder_2 = FactoryGirl.create(:vmware_folder_vm, :ext_management_system => @ems, :name => "folder2") + @cluster = FactoryBot.create(:ems_cluster, :ext_management_system => @ems) + @host = FactoryBot.create(:host, :ext_management_system => @ems, :ems_cluster => @cluster) + @vm = FactoryBot.create(:vm_vmware, :ext_management_system => @ems, :ems_cluster => @cluster, :host => @host) + @template = FactoryBot.create(:template_vmware, :ext_management_system => @ems) + @rp = FactoryBot.create(:resource_pool, :ext_management_system => @ems) + @host_folder = FactoryBot.create(:vmware_folder_host, :ext_management_system => @ems) + @vm_folder_1 = FactoryBot.create(:vmware_folder_vm, :ext_management_system => @ems, :name => "folder1") + @vm_folder_2 = FactoryBot.create(:vmware_folder_vm, :ext_management_system => @ems, :name => "folder2") @host_folder.add_cluster(@cluster) @cluster.add_resource_pool(@rp) @@ -45,7 +45,7 @@ context "with an invalid relats tree" do before do - @rp2 = FactoryGirl.create(:resource_pool, :ext_management_system => @ems) + @rp2 = FactoryBot.create(:resource_pool, :ext_management_system => @ems) @host.set_child(@rp2) @host_folder.add_host(@host) diff --git a/spec/models/ems_refresh/save_inventory/save_tags_inventory_spec.rb b/spec/models/ems_refresh/save_inventory/save_tags_inventory_spec.rb index 8ed4a4e17a2..f71dc3db8c4 100644 --- a/spec/models/ems_refresh/save_inventory/save_tags_inventory_spec.rb +++ b/spec/models/ems_refresh/save_inventory/save_tags_inventory_spec.rb @@ -3,7 +3,7 @@ context "save_tags_inventory" do # @return [Tag] a tag in a category linked to a mapping. def mapped_tag(category_name, tag_name) - mapping = FactoryGirl.create(:tag_mapping_with_category, + mapping = FactoryBot.create(:tag_mapping_with_category, :category_name => category_name, :category_description => category_name) category = mapping.tag.classification @@ -12,11 +12,11 @@ def mapped_tag(category_name, tag_name) end before do - @zone = FactoryGirl.create(:zone) - @ems = FactoryGirl.create(:ems_amazon, :zone => @zone) + @zone = FactoryBot.create(:zone) + @ems = FactoryBot.create(:ems_amazon, :zone => @zone) - @vm = FactoryGirl.create(:vm, :ext_management_system => @ems) - @node = FactoryGirl.create(:container_node, :ext_management_system => @ems) + @vm = FactoryBot.create(:vm, :ext_management_system => @ems) + @node = FactoryBot.create(:container_node, :ext_management_system => @ems) @tag1 = mapped_tag('amazon:vm:owner', 'alice') @tag2 = mapped_tag('kubernetes:container_node:stuff', 'jabberwocky') diff --git a/spec/models/ems_refresh/save_inventory_infra_spec.rb b/spec/models/ems_refresh/save_inventory_infra_spec.rb index 6b31ab10d51..aa0ecd46c79 100644 --- a/spec/models/ems_refresh/save_inventory_infra_spec.rb +++ b/spec/models/ems_refresh/save_inventory_infra_spec.rb @@ -11,32 +11,32 @@ def _log context ".find_host" do it "with ems_ref" do - FactoryGirl.create(:host, :ems_ref => "some_ems_ref") + FactoryBot.create(:host, :ems_ref => "some_ems_ref") expect(refresher.find_host({:ems_ref => "some_ems_ref"}, nil)).to be_kind_of(Host) end it "with ems_ref and ems_id" do - FactoryGirl.create(:host, :ems_ref => "some_ems_ref") - host_with_ems_id = FactoryGirl.create(:host, :ems_ref => "some_ems_ref_2", :ems_id => 1) + FactoryBot.create(:host, :ems_ref => "some_ems_ref") + host_with_ems_id = FactoryBot.create(:host, :ems_ref => "some_ems_ref_2", :ems_id => 1) expect(refresher.find_host({:ems_ref => "some_ems_ref_2", :name => "name"}, nil)).to be_nil expect(refresher.find_host({:ems_ref => "some_ems_ref_2", :name => "name"}, 1)).to eq(host_with_ems_id) end it "with hostname and ipaddress" do - FactoryGirl.create(:host, :ems_ref => "some_ems_ref", :hostname => "my.hostname", :ipaddress => "192.168.1.1") - expected_host = FactoryGirl.create(:host, :ems_ref => "some_ems_ref", :hostname => "my.hostname", :ipaddress => "192.168.1.2") + FactoryBot.create(:host, :ems_ref => "some_ems_ref", :hostname => "my.hostname", :ipaddress => "192.168.1.1") + expected_host = FactoryBot.create(:host, :ems_ref => "some_ems_ref", :hostname => "my.hostname", :ipaddress => "192.168.1.2") expect(refresher.find_host(expected_host.slice(:hostname, :ipaddress), nil)).to eq(expected_host) end end context ".look_up_host" do - let(:host_3_part_hostname) { FactoryGirl.create(:host_vmware, :hostname => "test1.example.com", :ipaddress => "192.168.1.1") } - let(:host_4_part_hostname) { FactoryGirl.create(:host_vmware, :hostname => "test2.dummy.example.com", :ipaddress => "192.168.1.2") } - let(:host_duplicate_hostname) { FactoryGirl.create(:host_vmware, :hostname => "test2.example.com", :ipaddress => "192.168.1.3", :ems_ref => "host-1", :ems_id => 1) } - let(:host_no_ems_id) { FactoryGirl.create(:host_vmware, :hostname => "test2.example.com", :ipaddress => "192.168.1.4", :ems_ref => "host-2") } + let(:host_3_part_hostname) { FactoryBot.create(:host_vmware, :hostname => "test1.example.com", :ipaddress => "192.168.1.1") } + let(:host_4_part_hostname) { FactoryBot.create(:host_vmware, :hostname => "test2.dummy.example.com", :ipaddress => "192.168.1.2") } + let(:host_duplicate_hostname) { FactoryBot.create(:host_vmware, :hostname => "test2.example.com", :ipaddress => "192.168.1.3", :ems_ref => "host-1", :ems_id => 1) } + let(:host_no_ems_id) { FactoryBot.create(:host_vmware, :hostname => "test2.example.com", :ipaddress => "192.168.1.4", :ems_ref => "host-2") } before do host_3_part_hostname host_4_part_hostname @@ -111,8 +111,8 @@ def _log context ".save_hosts_inventory" do before do - @zone = FactoryGirl.create(:zone) - @ems = FactoryGirl.create(:ems_vmware, :zone => @zone) + @zone = FactoryBot.create(:zone) + @ems = FactoryBot.create(:ems_vmware, :zone => @zone) end it "should handle >10 hosts with duplicate hostnames" do diff --git a/spec/models/ems_refresh/save_inventory_spec.rb b/spec/models/ems_refresh/save_inventory_spec.rb index 117c84c4557..28e162930e3 100644 --- a/spec/models/ems_refresh/save_inventory_spec.rb +++ b/spec/models/ems_refresh/save_inventory_spec.rb @@ -1,32 +1,32 @@ describe EmsRefresh::SaveInventory do context "save_vms_inventory handling duplicate uids" do before do - @zone = FactoryGirl.create(:zone) - @ems = FactoryGirl.create(:ems_vmware, :zone => @zone) + @zone = FactoryBot.create(:zone) + @ems = FactoryBot.create(:ems_vmware, :zone => @zone) end context "check save_ems_inventory_no_disconnect" do before do - @zone = FactoryGirl.create(:zone) - @ems = FactoryGirl.create(:ems_redhat, :zone => @zone) - FactoryGirl.create(:resource_pool, + @zone = FactoryBot.create(:zone) + @ems = FactoryBot.create(:ems_redhat, :zone => @zone) + FactoryBot.create(:resource_pool, :ext_management_system => @ems, :name => "Default for Cluster Default", :uid_ems => "5a09acd2-025c-0118-0172-00000000006d_respool") - FactoryGirl.create(:ems_folder, + FactoryBot.create(:ems_folder, :ext_management_system => @ems, :uid_ems => "5a09acd2-00e1-02d4-0257-000000000180_host", :name => "host") - FactoryGirl.create(:ems_folder, + FactoryBot.create(:ems_folder, :ext_management_system => @ems, :uid_ems => "5a09acd2-00e1-02d4-0257-000000000180_vm", :name => "vm") - FactoryGirl.create(:datacenter, + FactoryBot.create(:datacenter, :ems_ref => "/api/datacenters/5a09acd2-00e1-02d4-0257-000000000180", :ext_management_system => @ems, :name => "Default", :uid_ems => "5a09acd2-00e1-02d4-0257-000000000180") - FactoryGirl.create(:ems_cluster, + FactoryBot.create(:ems_cluster, :ems_ref => "/api/clusters/5a09acd2-025c-0118-0172-00000000006d", :uid_ems => "5a09acd2-025c-0118-0172-00000000006d", :ext_management_system => @ems, @@ -104,8 +104,8 @@ context "with no dups in the database" do before do - @vm1 = FactoryGirl.create(:vm_with_ref, :ext_management_system => @ems) - @vm2 = FactoryGirl.create(:vm_with_ref, :ext_management_system => @ems) + @vm1 = FactoryBot.create(:vm_with_ref, :ext_management_system => @ems) + @vm2 = FactoryBot.create(:vm_with_ref, :ext_management_system => @ems) end it "should handle no dups in the raw data" do @@ -152,8 +152,8 @@ context "with dups in the database" do before do @uid = SecureRandom.uuid - @vm1 = FactoryGirl.create(:vm_with_ref, :ext_management_system => @ems, :uid_ems => @uid) - @vm2 = FactoryGirl.create(:vm_with_ref, :ext_management_system => @ems, :uid_ems => @uid) + @vm1 = FactoryBot.create(:vm_with_ref, :ext_management_system => @ems, :uid_ems => @uid) + @vm2 = FactoryBot.create(:vm_with_ref, :ext_management_system => @ems, :uid_ems => @uid) end it "should handle no dups in the raw data" do @@ -200,8 +200,8 @@ context "with disconnected dups in the database" do before do @uid = SecureRandom.uuid - @vm1 = FactoryGirl.create(:vm_with_ref, :ext_management_system => nil, :uid_ems => @uid) - @vm2 = FactoryGirl.create(:vm_with_ref, :ext_management_system => @ems, :uid_ems => @uid) + @vm1 = FactoryBot.create(:vm_with_ref, :ext_management_system => nil, :uid_ems => @uid) + @vm2 = FactoryBot.create(:vm_with_ref, :ext_management_system => @ems, :uid_ems => @uid) end it "should handle no dups in the raw data" do @@ -248,10 +248,10 @@ context "with non-dup on a different EMS in the database" do before do - @ems2 = FactoryGirl.create(:ems_vmware) + @ems2 = FactoryBot.create(:ems_vmware) @uid = SecureRandom.uuid - @vm1 = FactoryGirl.create(:vm_with_ref, :ext_management_system => @ems2, :uid_ems => @uid) - @vm2 = FactoryGirl.build(:vm_with_ref, :ext_management_system => @ems, :uid_ems => @uid) + @vm1 = FactoryBot.create(:vm_with_ref, :ext_management_system => @ems2, :uid_ems => @uid) + @vm2 = FactoryBot.build(:vm_with_ref, :ext_management_system => @ems, :uid_ems => @uid) end it "should handle new dup in the raw_data" do @@ -275,8 +275,8 @@ context "with disconnected non-dup in the database" do before do @uid = SecureRandom.uuid - @vm1 = FactoryGirl.create(:vm_with_ref, :ext_management_system => nil, :uid_ems => @uid) - @vm2 = FactoryGirl.build(:vm_with_ref, :ext_management_system => @ems, :uid_ems => @uid) + @vm1 = FactoryBot.create(:vm_with_ref, :ext_management_system => nil, :uid_ems => @uid) + @vm2 = FactoryBot.build(:vm_with_ref, :ext_management_system => @ems, :uid_ems => @uid) end it "should handle new dup in the raw_data" do @@ -294,8 +294,8 @@ context "with no dups in the database, but with nil ems_refs (after upgrade)" do before do - @vm1 = FactoryGirl.create(:vm_with_ref, :ext_management_system => @ems) - @vm2 = FactoryGirl.create(:vm_with_ref, :ext_management_system => @ems) + @vm1 = FactoryBot.create(:vm_with_ref, :ext_management_system => @ems) + @vm2 = FactoryBot.create(:vm_with_ref, :ext_management_system => @ems) @ems_ref1 = @vm1.ems_ref_obj @ems_ref2 = @vm2.ems_ref_obj diff --git a/spec/models/ems_refresh_spec.rb b/spec/models/ems_refresh_spec.rb index 3796fabb8a9..dfdf589de22 100644 --- a/spec/models/ems_refresh_spec.rb +++ b/spec/models/ems_refresh_spec.rb @@ -4,7 +4,7 @@ context ".queue_refresh" do before do _guid, _server, zone = EvmSpecHelper.create_guid_miq_server_zone - @ems = FactoryGirl.create(:ems_vmware, :zone => zone) + @ems = FactoryBot.create(:ems_vmware, :zone => zone) end it "with Ems" do @@ -24,25 +24,25 @@ end it "with Host" do - target = FactoryGirl.create(:host_vmware, :ext_management_system => @ems) + target = FactoryBot.create(:host_vmware, :ext_management_system => @ems) queue_refresh_and_assert_queue_item(target, [target]) end it "with Vm" do - target = FactoryGirl.create(:vm_vmware, :ext_management_system => @ems) + target = FactoryBot.create(:vm_vmware, :ext_management_system => @ems) queue_refresh_and_assert_queue_item(target, [target]) end it "with Storage" do allow_any_instance_of(Storage).to receive_messages(:ext_management_systems => [@ems]) - target = FactoryGirl.create(:storage_vmware) + target = FactoryBot.create(:storage_vmware) queue_refresh_and_assert_queue_item(target, [target]) end it "with Vm and an item already on the queue" do target = @ems queue_refresh_and_assert_queue_item(target, [target]) - target2 = FactoryGirl.create(:vm_vmware, :ext_management_system => @ems) + target2 = FactoryBot.create(:vm_vmware, :ext_management_system => @ems) queue_refresh_and_assert_queue_item(target2, [target, target2]) end @@ -58,7 +58,7 @@ context "stopping targets unbounded growth" do before do _guid, _server, zone = EvmSpecHelper.create_guid_miq_server_zone - @ems = FactoryGirl.create(:ems_vmware, :zone => zone) + @ems = FactoryBot.create(:ems_vmware, :zone => zone) end let(:targets) do @@ -79,8 +79,8 @@ targets end - let(:vm_target) { FactoryGirl.create(:vm_vmware, :ext_management_system => @ems) } - let(:host_target) { FactoryGirl.create(:host_vmware, :ext_management_system => @ems) } + let(:vm_target) { FactoryBot.create(:vm_vmware, :ext_management_system => @ems) } + let(:host_target) { FactoryBot.create(:host_vmware, :ext_management_system => @ems) } it "doesn't call uniq on targets if size is <= 1000" do described_class.queue_refresh(targets) @@ -99,7 +99,7 @@ it "uniques targets if queuing breaches size 1000" do # We need different Vm, since targets are uniqued before queueing - described_class.queue_refresh(targets << FactoryGirl.create(:vm_vmware, :ext_management_system => @ems)) + described_class.queue_refresh(targets << FactoryBot.create(:vm_vmware, :ext_management_system => @ems)) expect(MiqQueue.last.data.size).to eq(5) end @@ -108,13 +108,13 @@ context ".queue_refresh_task" do before do _guid, _server, zone = EvmSpecHelper.create_guid_miq_server_zone - @ems = FactoryGirl.create(:ems_vmware, :zone => zone) - @ems2 = FactoryGirl.create(:ems_vmware, :zone => zone) + @ems = FactoryBot.create(:ems_vmware, :zone => zone) + @ems2 = FactoryBot.create(:ems_vmware, :zone => zone) end context "with a refresh already on the queue" do let(:target1) { @ems } - let(:target2) { FactoryGirl.create(:vm_vmware, :ext_management_system => @ems) } + let(:target2) { FactoryBot.create(:vm_vmware, :ext_management_system => @ems) } it "only creates one task" do described_class.queue_refresh_task(target1) @@ -142,8 +142,8 @@ end context "with Vms on different EMSs" do - let(:vm1) { FactoryGirl.create(:vm_vmware, :ext_management_system => @ems) } - let(:vm2) { FactoryGirl.create(:vm_vmware, :ext_management_system => @ems2) } + let(:vm1) { FactoryBot.create(:vm_vmware, :ext_management_system => @ems) } + let(:vm2) { FactoryBot.create(:vm_vmware, :ext_management_system => @ems2) } it "returns a task for each EMS" do task_ids = described_class.queue_refresh_task([vm1, vm2]) expect(task_ids.length).to eq(2) @@ -151,8 +151,8 @@ end context "task name" do - let(:vm1) { FactoryGirl.create(:vm_vmware, :ext_management_system => @ems) } - let(:vm2) { FactoryGirl.create(:vm_vmware, :ext_management_system => @ems) } + let(:vm1) { FactoryBot.create(:vm_vmware, :ext_management_system => @ems) } + let(:vm2) { FactoryBot.create(:vm_vmware, :ext_management_system => @ems) } it "uses targets' short classnames to compose task name" do task_ids = described_class.queue_refresh_task([vm1, vm2]) task_name = MiqTask.find(task_ids.first).name @@ -163,7 +163,7 @@ describe ".create_refresh_task" do it "create refresh task and trancates task name to 255 symbols" do - vm = FactoryGirl.create(:vm_vmware, :name => "vm_vmware1", :ext_management_system => @ems) + vm = FactoryBot.create(:vm_vmware, :name => "vm_vmware1", :ext_management_system => @ems) targets = Array.new(500) { [vm.class.name, vm.id] } task_name = described_class.send(:create_refresh_task, @ems, targets).name expect(task_name.include?(@ems.name)).to eq true @@ -188,8 +188,8 @@ def assert_queue_item(expected_targets) context ".get_target_objects" do it "array of class/ids pairs" do - ems1 = FactoryGirl.create(:ems_vmware, :name => "ems_vmware1") - ems2 = FactoryGirl.create(:ems_redhat, :name => "ems_redhat1") + ems1 = FactoryBot.create(:ems_vmware, :name => "ems_vmware1") + ems2 = FactoryBot.create(:ems_redhat, :name => "ems_redhat1") pairs = [ [ems1.class, ems1.id], [ems2.class, ems2.id] @@ -199,8 +199,8 @@ def assert_queue_item(expected_targets) end it "array of class/hash pairs for InventoryRefresh::Target objects" do - ems1 = FactoryGirl.create(:ems_vmware, :name => "ems_vmware1") - ems2 = FactoryGirl.create(:ems_redhat, :name => "ems_redhat1") + ems1 = FactoryBot.create(:ems_vmware, :name => "ems_vmware1") + ems2 = FactoryBot.create(:ems_redhat, :name => "ems_redhat1") target1 = InventoryRefresh::Target.load(:manager_id => ems1.id, :association => :vms, @@ -227,9 +227,9 @@ def assert_queue_item(expected_targets) context ".refresh" do it "accepts VMs" do - ems = FactoryGirl.create(:ems_vmware, :name => "ems_vmware1") - vm1 = FactoryGirl.create(:vm_vmware, :name => "vm_vmware1", :ext_management_system => ems) - vm2 = FactoryGirl.create(:vm_vmware, :name => "vm_vmware2", :ext_management_system => ems) + ems = FactoryBot.create(:ems_vmware, :name => "ems_vmware1") + vm1 = FactoryBot.create(:vm_vmware, :name => "vm_vmware1", :ext_management_system => ems) + vm2 = FactoryBot.create(:vm_vmware, :name => "vm_vmware2", :ext_management_system => ems) expect(ManageIQ::Providers::Vmware::InfraManager::Refresher).to receive(:refresh) do |args| # Refresh code doesn't care about args order so neither does the test # TODO: use array_including in rspec 3 @@ -243,9 +243,9 @@ def assert_queue_item(expected_targets) end it "ignores an EMS-less (archived) VM" do - ems = FactoryGirl.create(:ems_vmware, :name => "ems_vmware1") - vm1 = FactoryGirl.create(:vm_vmware, :name => "vm_vmware1", :ext_management_system => ems) - vm2 = FactoryGirl.create(:vm_vmware, :name => "vm_vmware2", :ext_management_system => nil) + ems = FactoryBot.create(:ems_vmware, :name => "ems_vmware1") + vm1 = FactoryBot.create(:vm_vmware, :name => "vm_vmware1", :ext_management_system => ems) + vm2 = FactoryBot.create(:vm_vmware, :name => "vm_vmware2", :ext_management_system => nil) expect(ManageIQ::Providers::Vmware::InfraManager::Refresher).to receive(:refresh).with([vm1]) EmsRefresh.refresh([ [vm1.class, vm1.id], @@ -257,7 +257,7 @@ def assert_queue_item(expected_targets) context '.refresh_new_target' do let(:ems) do _, _, zone = EvmSpecHelper.create_guid_miq_server_zone - FactoryGirl.create(:ems_vmware, :zone => zone) + FactoryBot.create(:ems_vmware, :zone => zone) end context 'targeting a new vm' do @@ -285,7 +285,7 @@ def assert_queue_item(expected_targets) end context 'on an existing host' do - let(:host) { FactoryGirl.create(:host_with_ref, :ext_management_system => ems) } + let(:host) { FactoryBot.create(:host_with_ref, :ext_management_system => ems) } it 'links the new vm to the existing host' do target_hash = { @@ -308,7 +308,7 @@ def assert_queue_item(expected_targets) end context 'targeting an existing vm' do - let(:vm) { FactoryGirl.create(:vm_with_ref, :ext_management_system => ems) } + let(:vm) { FactoryBot.create(:vm_with_ref, :ext_management_system => ems) } it "doesn't try to create a new record" do vm_hash = { @@ -328,7 +328,7 @@ def assert_queue_item(expected_targets) end context 'targeting an archived vm' do - let(:vm) { FactoryGirl.create(:vm_with_ref, :ems_id => nil) } + let(:vm) { FactoryBot.create(:vm_with_ref, :ems_id => nil) } it 'adopts the existing vm' do vm_hash = { @@ -351,8 +351,8 @@ def assert_queue_item(expected_targets) end describe '.queue_merge' do - let(:ems) { FactoryGirl.create(:ems_vmware, :name => "ems_vmware1") } - let(:vm) { FactoryGirl.create(:vm_vmware, :name => "vm_vmware1", :ext_management_system => ems) } + let(:ems) { FactoryBot.create(:ems_vmware, :name => "ems_vmware1") } + let(:vm) { FactoryBot.create(:vm_vmware, :name => "vm_vmware1", :ext_management_system => ems) } it 'sends the command to queue' do EmsRefresh.queue_merge([vm], ems) @@ -361,7 +361,7 @@ def assert_queue_item(expected_targets) context "task creation" do before do - @miq_task = FactoryGirl.create(:miq_task) + @miq_task = FactoryBot.create(:miq_task) allow(EmsRefresh).to receive(:create_refresh_task).and_return(@miq_task) end diff --git a/spec/models/endpoint_spec.rb b/spec/models/endpoint_spec.rb index 90cae1df37c..a30c07ce70a 100644 --- a/spec/models/endpoint_spec.rb +++ b/spec/models/endpoint_spec.rb @@ -1,5 +1,5 @@ describe Endpoint do - let(:endpoint) { FactoryGirl.build(:endpoint) } + let(:endpoint) { FactoryBot.build(:endpoint) } describe "#verify_ssl" do context "when non set" do diff --git a/spec/models/entitlement_spec.rb b/spec/models/entitlement_spec.rb index 64ca67cfebd..964ce998fe7 100644 --- a/spec/models/entitlement_spec.rb +++ b/spec/models/entitlement_spec.rb @@ -1,20 +1,20 @@ describe Entitlement do describe "validation" do it "can have a managed filter if it doesn't have a filter expression" do - entitlement = FactoryGirl.build(:entitlement) + entitlement = FactoryBot.build(:entitlement) entitlement.set_managed_filters([["/managed/environment/test"]]) expect(entitlement).to be_valid end it "can have a filter expression if it doesn't have a managed filter" do - entitlement = FactoryGirl.build(:entitlement) + entitlement = FactoryBot.build(:entitlement) expression = MiqExpression.new("=" => {"tag" => "managed-environment", "value" => "test"}) entitlement.filter_expression = expression expect(entitlement).to be_valid end it "cannot have both managed filters and a filter expression" do - entitlement = FactoryGirl.build(:entitlement) + entitlement = FactoryBot.build(:entitlement) expression = MiqExpression.new("=" => {"tag" => "managed-environment", "value" => "test"}) entitlement.filter_expression = expression entitlement.set_managed_filters([["/managed/environment/test"]]) @@ -22,7 +22,7 @@ end it "can have a filter expression and a belongs_to filter" do - entitlement = FactoryGirl.build(:entitlement) + entitlement = FactoryBot.build(:entitlement) expression = MiqExpression.new("=" => {"tag" => "managed-environment", "value" => "test"}) entitlement.filter_expression = expression entitlement.set_belongsto_filters([["/belongsto/ExtManagementSystem/ems1"]]) @@ -31,8 +31,8 @@ end describe "::remove_tag_from_all_managed_filters" do - let!(:entitlement1) { FactoryGirl.create(:entitlement) } - let!(:entitlement2) { FactoryGirl.create(:entitlement) } + let!(:entitlement1) { FactoryBot.create(:entitlement) } + let!(:entitlement2) { FactoryBot.create(:entitlement) } before do entitlement1.set_managed_filters([["/managed/prov_max_memory/test", "/managed/prov_max_memory/1024"], diff --git a/spec/models/event_stream/purging_spec.rb b/spec/models/event_stream/purging_spec.rb index c7c3a4949eb..b574b76ac82 100644 --- a/spec/models/event_stream/purging_spec.rb +++ b/spec/models/event_stream/purging_spec.rb @@ -38,9 +38,9 @@ let(:purge_date) { 2.weeks.ago } before do - @old_event = FactoryGirl.create(:ems_event, :timestamp => purge_date - 1.day) - @purge_date_event = FactoryGirl.create(:ems_event, :timestamp => purge_date) - @new_event = FactoryGirl.create(:ems_event, :timestamp => purge_date + 1.day) + @old_event = FactoryBot.create(:ems_event, :timestamp => purge_date - 1.day) + @purge_date_event = FactoryBot.create(:ems_event, :timestamp => purge_date) + @new_event = FactoryBot.create(:ems_event, :timestamp => purge_date + 1.day) end def assert_unpurged_ids(unpurged_ids) diff --git a/spec/models/ext_management_system_spec.rb b/spec/models/ext_management_system_spec.rb index 7fe0fbe5b25..e1ace56d7fb 100644 --- a/spec/models/ext_management_system_spec.rb +++ b/spec/models/ext_management_system_spec.rb @@ -87,28 +87,28 @@ context "#ipaddress / #ipaddress=" do it "will delegate to the default endpoint" do - ems = FactoryGirl.build(:ems_vmware, :ipaddress => "1.2.3.4") + ems = FactoryBot.build(:ems_vmware, :ipaddress => "1.2.3.4") expect(ems.default_endpoint.ipaddress).to eq "1.2.3.4" end it "with nil" do - ems = FactoryGirl.build(:ems_vmware, :ipaddress => nil) + ems = FactoryBot.build(:ems_vmware, :ipaddress => nil) expect(ems.default_endpoint.ipaddress).to be_nil end end it "#total_storages" do - storage1 = FactoryGirl.create(:storage) - storage2 = FactoryGirl.create(:storage) + storage1 = FactoryBot.create(:storage) + storage2 = FactoryBot.create(:storage) - ems = FactoryGirl.create(:ems_vmware) - FactoryGirl.create( + ems = FactoryBot.create(:ems_vmware) + FactoryBot.create( :host_vmware, :storages => [storage1, storage2], :ext_management_system => ems ) - FactoryGirl.create( + FactoryBot.create( :host_vmware, :storages => [storage2], :ext_management_system => ems @@ -119,35 +119,35 @@ context "#hostname / #hostname=" do it "will delegate to the default endpoint" do - ems = FactoryGirl.build(:ems_vmware, :hostname => "example.org") + ems = FactoryBot.build(:ems_vmware, :hostname => "example.org") expect(ems.default_endpoint.hostname).to eq "example.org" end it "with nil" do - ems = FactoryGirl.build(:ems_vmware, :hostname => nil) + ems = FactoryBot.build(:ems_vmware, :hostname => nil) expect(ems.default_endpoint.hostname).to be_nil end end context "#port, #port=" do it "will delegate to the default endpoint" do - ems = FactoryGirl.build(:ems_vmware, :port => 1234) + ems = FactoryBot.build(:ems_vmware, :port => 1234) expect(ems.default_endpoint.port).to eq 1234 end it "will delegate a string to the default endpoint" do - ems = FactoryGirl.build(:ems_vmware, :port => "1234") + ems = FactoryBot.build(:ems_vmware, :port => "1234") expect(ems.default_endpoint.port).to eq 1234 end it "with nil" do - ems = FactoryGirl.build(:ems_vmware, :port => nil) + ems = FactoryBot.build(:ems_vmware, :port => nil) expect(ems.default_endpoint.port).to be_nil end end context "with multiple endpoints" do - let(:ems) { FactoryGirl.build(:ems_openstack, :hostname => "example.org") } + let(:ems) { FactoryBot.build(:ems_openstack, :hostname => "example.org") } before { ems.add_connection_configuration_by_role(:endpoint => {:role => "amqp", :hostname => "amqp.example.org"}) } it "will contain seperate ampq endpoint" do @@ -163,7 +163,7 @@ context "with multiple endpoints using connection_configurations" do let(:ems) do - FactoryGirl.build(:ems_openstack, + FactoryBot.build(:ems_openstack, :hostname => "example.org", :connection_configurations => [{:endpoint => {:role => "amqp", :hostname => "amqp.example.org"}}]) @@ -182,7 +182,7 @@ context "with multiple endpoints using connection_configurations (string keys)" do let(:ems) do - FactoryGirl.build(:ems_openstack, + FactoryBot.build(:ems_openstack, "hostname" => "example.org", "connection_configurations" => [{"endpoint" => {"role" => "amqp", "hostname" => "amqp.example.org"}}]) @@ -201,7 +201,7 @@ context "with multiple endpoints using explicit authtype" do let(:ems) do - FactoryGirl.build(:ems_openshift, + FactoryBot.build(:ems_openshift, :connection_configurations => [{:endpoint => {:role => "default", :hostname => "openshift.example.org"}, :authentication => {:role => "bearer", @@ -222,7 +222,7 @@ context "with multiple endpoints using implicit default authtype" do let(:ems) do - FactoryGirl.build(:ems_openshift, + FactoryBot.build(:ems_openshift, :connection_configurations => [{:endpoint => {:role => "default", :hostname => "openshift.example.org"}, :authentication => {:auth_key => "SomeSecret"}}, @@ -241,8 +241,8 @@ context "with two small envs" do before do - @zone1 = FactoryGirl.create(:small_environment) - @zone2 = FactoryGirl.create(:small_environment) + @zone1 = FactoryBot.create(:small_environment) + @zone2 = FactoryBot.create(:small_environment) end it "refresh_all_ems_timer will refresh for all emses in zone1" do @@ -262,18 +262,18 @@ context "with virtual totals" do before do - @ems = FactoryGirl.create(:ems_vmware) + @ems = FactoryBot.create(:ems_vmware) 2.times do - FactoryGirl.create(:vm_vmware, + FactoryBot.create(:vm_vmware, :ext_management_system => @ems, - :hardware => FactoryGirl.create(:hardware, + :hardware => FactoryBot.create(:hardware, :cpu1x2, :ram1GB)) end 2.times do - FactoryGirl.create(:host, + FactoryBot.create(:host, :ext_management_system => @ems, - :hardware => FactoryGirl.create(:hardware, + :hardware => FactoryBot.create(:hardware, :cpu2x2, :ram1GB)) end @@ -338,25 +338,25 @@ end it "#total_vms_and_templates" do - FactoryGirl.create(:template_vmware, :ext_management_system => @ems) + FactoryBot.create(:template_vmware, :ext_management_system => @ems) expect(@ems.total_vms_and_templates).to eq(3) end it "#total_miq_templates" do - FactoryGirl.create(:template_vmware, :ext_management_system => @ems) + FactoryBot.create(:template_vmware, :ext_management_system => @ems) expect(@ems.total_miq_templates).to eq(1) end end describe "#total_clusters" do it "knows it has none" do - ems = FactoryGirl.create(:ems_vmware) + ems = FactoryBot.create(:ems_vmware) expect(ems.total_clusters).to eq(0) end it "knows it has one" do - ems = FactoryGirl.create(:ems_vmware) - FactoryGirl.create(:ems_cluster, :ext_management_system => ems) + ems = FactoryBot.create(:ems_vmware) + FactoryBot.create(:ems_cluster, :ext_management_system => ems) expect(ems.total_clusters).to eq(1) end end @@ -365,47 +365,47 @@ context "across tenants" do before do tenant1 = Tenant.seed - @tenant2 = FactoryGirl.create(:tenant, :parent => tenant1) - @ems = FactoryGirl.create(:ems_vmware, :tenant => tenant1) + @tenant2 = FactoryBot.create(:tenant, :parent => tenant1) + @ems = FactoryBot.create(:ems_vmware, :tenant => tenant1) end it "allowing duplicate name" do expect do - FactoryGirl.create(:ems_vmware, :name => @ems.name, :tenant => @tenant2) + FactoryBot.create(:ems_vmware, :name => @ems.name, :tenant => @tenant2) end.to_not raise_error end it "not allowing duplicate hostname for same type provider" do expect do - FactoryGirl.create(:ems_vmware, :hostname => @ems.hostname, :tenant => @tenant2) + FactoryBot.create(:ems_vmware, :hostname => @ems.hostname, :tenant => @tenant2) end.to raise_error(ActiveRecord::RecordInvalid) end it "allowing duplicate hostname for different type providers" do - FactoryGirl.create(:ems_microsoft, :hostname => @ems.hostname, :tenant => @tenant2) + FactoryBot.create(:ems_microsoft, :hostname => @ems.hostname, :tenant => @tenant2) expect(ExtManagementSystem.count).to eq(2) end end end context "#tenant" do - let(:tenant) { FactoryGirl.create(:tenant) } + let(:tenant) { FactoryBot.create(:tenant) } it "has a tenant" do - ems = FactoryGirl.create(:ext_management_system, :tenant => tenant) + ems = FactoryBot.create(:ext_management_system, :tenant => tenant) expect(tenant.ext_management_systems).to include(ems) end end context "destroy" do it "destroys an ems with no active workers" do - ems = FactoryGirl.create(:ext_management_system) + ems = FactoryBot.create(:ext_management_system) ems.destroy expect(ExtManagementSystem.count).to eq(0) end it "destroys an ems with active workers" do - ems = FactoryGirl.create(:ext_management_system) - worker = FactoryGirl.create(:miq_ems_refresh_worker, :queue_name => ems.queue_name, :status => "started") + ems = FactoryBot.create(:ext_management_system) + worker = FactoryBot.create(:miq_ems_refresh_worker, :queue_name => ems.queue_name, :status => "started") ems.destroy expect(ExtManagementSystem.count).to eq(0) expect(worker.class.exists?(worker.id)).to be_falsy @@ -413,8 +413,8 @@ end context ".destroy_queue" do - let(:ems) { FactoryGirl.create(:ext_management_system, :zone => zone) } - let(:ems2) { FactoryGirl.create(:ext_management_system, :zone => zone) } + let(:ems) { FactoryBot.create(:ext_management_system, :zone => zone) } + let(:ems2) { FactoryBot.create(:ext_management_system, :zone => zone) } let(:server) { EvmSpecHelper.local_miq_server } let(:zone) { server.zone } @@ -427,7 +427,7 @@ end context "#destroy_queue" do - let(:ems) { FactoryGirl.create(:ext_management_system, :zone => zone) } + let(:ems) { FactoryBot.create(:ext_management_system, :zone => zone) } let(:server) { EvmSpecHelper.local_miq_server } let(:zone) { server.zone } @@ -454,7 +454,7 @@ end it "destroys the ems when active worker exists" do - FactoryGirl.create(:miq_ems_refresh_worker, :queue_name => ems.queue_name, :status => "started", :miq_server => server) + FactoryBot.create(:miq_ems_refresh_worker, :queue_name => ems.queue_name, :status => "started", :miq_server => server) ems.destroy_queue expect(MiqQueue.count).to eq(1) @@ -474,7 +474,7 @@ def deliver_queue_message(queue_message = MiqQueue.order(:id).first) context "virtual column :supports_block_storage" do it "returns true if block storage is supported" do - ems = FactoryGirl.create(:ext_management_system) + ems = FactoryBot.create(:ext_management_system) allow(ems).to receive(:supports_block_storage).and_return(true) expect(ems.supports_block_storage).to eq(true) end @@ -482,7 +482,7 @@ def deliver_queue_message(queue_message = MiqQueue.order(:id).first) context "virtual column :supports_cloud_object_store_container_create" do it "returns true if cloud_object_store_container_create is supported" do - ems = FactoryGirl.create(:ext_management_system) + ems = FactoryBot.create(:ext_management_system) allow(ems).to receive(:supports_cloud_object_store_container_create).and_return(true) expect(ems.supports_cloud_object_store_container_create).to eq(true) end @@ -499,10 +499,10 @@ def deliver_queue_message(queue_message = MiqQueue.order(:id).first) describe ".inventory_status" do it "works with infra providers" do - ems = FactoryGirl.create(:ems_infra) - host = FactoryGirl.create(:host, :ext_management_system => ems) - FactoryGirl.create(:vm_infra, :ext_management_system => ems, :host => host) - FactoryGirl.create(:vm_infra, :ext_management_system => ems, :host => host) + ems = FactoryBot.create(:ems_infra) + host = FactoryBot.create(:host, :ext_management_system => ems) + FactoryBot.create(:vm_infra, :ext_management_system => ems, :host => host) + FactoryBot.create(:vm_infra, :ext_management_system => ems, :host => host) result = ExtManagementSystem.inventory_status expect(result.size).to eq(2) @@ -511,9 +511,9 @@ def deliver_queue_message(queue_message = MiqQueue.order(:id).first) end it "works with container providers" do - ems = FactoryGirl.create(:ems_container) - FactoryGirl.create(:container, :ems_id => ems.id) - FactoryGirl.create(:container, :ems_id => ems.id) + ems = FactoryBot.create(:ems_container) + FactoryBot.create(:container, :ems_id => ems.id) + FactoryBot.create(:container, :ems_id => ems.id) result = ExtManagementSystem.inventory_status expect(result.size).to eq(2) expect(result[0]).to eq(%w(region zone kind ems containers)) diff --git a/spec/models/filesystem_spec.rb b/spec/models/filesystem_spec.rb index b1b8b0cd2f7..f5f640c57d6 100644 --- a/spec/models/filesystem_spec.rb +++ b/spec/models/filesystem_spec.rb @@ -25,34 +25,34 @@ context "#contents_displayable?" do it "filesystem with missing name is not displayable" do - filesystem = FactoryGirl.create(:filesystem_openstack_conf, :contents => filesystem_conf_file_ascii) + filesystem = FactoryBot.create(:filesystem_openstack_conf, :contents => filesystem_conf_file_ascii) allow(filesystem).to receive(:name).and_return(nil) expect(filesystem.contents_displayable?).to be_falsey end it "filesystem content bigger than 20k characters is not displayable" do - filesystem = FactoryGirl.create(:filesystem_openstack_conf, :contents => filesystem_conf_file_ascii) + filesystem = FactoryBot.create(:filesystem_openstack_conf, :contents => filesystem_conf_file_ascii) allow(filesystem).to receive(:size).and_return(40_000) expect(filesystem.contents_displayable?).to be_falsey end it "non MIME .conf ascii file is displayable" do - filesystem = FactoryGirl.create(:filesystem_openstack_conf, :contents => filesystem_conf_file_ascii) + filesystem = FactoryBot.create(:filesystem_openstack_conf, :contents => filesystem_conf_file_ascii) expect(filesystem.contents_displayable?).to be_truthy end it "non MIME .conf file, with non ascii characters is not displayable" do - filesystem = FactoryGirl.create(:filesystem_openstack_conf, :contents => filesystem_conf_file_non_ascii) + filesystem = FactoryBot.create(:filesystem_openstack_conf, :contents => filesystem_conf_file_non_ascii) filesystem.name = "DOES NOT EXIST" expect(filesystem.contents_displayable?).to be_falsey end it "non MIME .conf file, without content is not displayable" do - filesystem = FactoryGirl.create(:filesystem_openstack_conf, :contents => filesystem_conf_file_ascii) + filesystem = FactoryBot.create(:filesystem_openstack_conf, :contents => filesystem_conf_file_ascii) filesystem.name = "DOES NOT EXIST" allow(filesystem).to receive(:has_contents?).and_return(false) @@ -60,13 +60,13 @@ end it "MIME .exe binary file is not displayable" do - filesystem = FactoryGirl.create(:filesystem_binary_file) + filesystem = FactoryBot.create(:filesystem_binary_file) expect(filesystem.contents_displayable?).to be_falsey end it "MIME .txt non binary file is displayable" do - filesystem = FactoryGirl.create(:filesystem_txt_file) + filesystem = FactoryBot.create(:filesystem_txt_file) expect(filesystem.contents_displayable?).to be_truthy end @@ -74,17 +74,17 @@ context "#displayable_contents" do it "returns utf-8 encoded content for utf-16 little endian data" do - filesystem = FactoryGirl.create(:filesystem_txt_file, :contents => filesystem_file_utf16_little_endian) + filesystem = FactoryBot.create(:filesystem_txt_file, :contents => filesystem_file_utf16_little_endian) expect(filesystem.displayable_contents).to eq("\r\n") end it "returns utf-8 encoded content for utf-16 big endian data" do - filesystem = FactoryGirl.create(:filesystem_txt_file, :contents => filesystem_file_utf16_big_endian) + filesystem = FactoryBot.create(:filesystem_txt_file, :contents => filesystem_file_utf16_big_endian) expect(filesystem.displayable_contents).to eq("\r\n") end it "returns original blob for binary data" do - filesystem = FactoryGirl.create(:filesystem_binary_file) + filesystem = FactoryBot.create(:filesystem_binary_file) expect(filesystem.displayable_contents).to eq(filesystem.contents) end end diff --git a/spec/models/firewall_rule_spec.rb b/spec/models/firewall_rule_spec.rb index f20d5ff20a6..e40aeaee602 100644 --- a/spec/models/firewall_rule_spec.rb +++ b/spec/models/firewall_rule_spec.rb @@ -1,16 +1,16 @@ describe FirewallRule do - let(:firewall_rule) { FactoryGirl.create(:firewall_rule) } + let(:firewall_rule) { FactoryBot.create(:firewall_rule) } context "#operating_system" do it "with an OperatingSystem" do - os = FactoryGirl.create(:operating_system) + os = FactoryBot.create(:operating_system) firewall_rule.update_attributes(:resource_type => "OperatingSystem", :resource_id => os.id) expect(firewall_rule.operating_system).to eq(os) end it "with a non-OperatingSystem" do - sg = FactoryGirl.create(:security_group) + sg = FactoryBot.create(:security_group) firewall_rule.update_attributes(:resource_type => "SecurityGroup", :resource_id => sg.id) expect(firewall_rule.operating_system).to be_nil @@ -19,7 +19,7 @@ context "#operating_system=" do it "with an OperatingSystem" do - os = FactoryGirl.create(:operating_system) + os = FactoryBot.create(:operating_system) firewall_rule.operating_system = os @@ -30,7 +30,7 @@ end it "with a non-OperatingSystem" do - sg = FactoryGirl.create(:security_group) + sg = FactoryBot.create(:security_group) expect { firewall_rule.operating_system = sg }.to raise_error(ArgumentError) end diff --git a/spec/models/flavor_spec.rb b/spec/models/flavor_spec.rb index 3dedfbe2b98..8d0ea467309 100644 --- a/spec/models/flavor_spec.rb +++ b/spec/models/flavor_spec.rb @@ -1,5 +1,5 @@ describe Flavor do - let(:ems) { FactoryGirl.create(:ems_openstack) } + let(:ems) { FactoryBot.create(:ems_openstack) } context 'when calling raw_create_flavor methods' do it 'raises NotImplementedError' do diff --git a/spec/models/generic_object_definition_spec.rb b/spec/models/generic_object_definition_spec.rb index 77da9626991..0db9ab514d6 100644 --- a/spec/models/generic_object_definition_spec.rb +++ b/spec/models/generic_object_definition_spec.rb @@ -1,6 +1,6 @@ describe GenericObjectDefinition do let(:definition) do - FactoryGirl.create( + FactoryBot.create( :generic_object_definition, :name => "test_definition", :properties => { @@ -81,7 +81,7 @@ describe '#destroy' do let(:generic_object) do - FactoryGirl.build(:generic_object, :generic_object_definition => definition, :name => 'test') + FactoryBot.build(:generic_object, :generic_object_definition => definition, :name => 'test') end it 'raises an error if the definition is in use' do @@ -101,7 +101,7 @@ describe '#add_property_attribute' do let(:definition) do - FactoryGirl.create(:generic_object_definition, + FactoryBot.create(:generic_object_definition, :name => 'test', :properties => { :attributes => {:status => "string"}}) end @@ -128,7 +128,7 @@ describe '#delete_property_attribute' do let(:definition) do - FactoryGirl.create(:generic_object_definition, + FactoryBot.create(:generic_object_definition, :name => 'test', :properties => { :attributes => {:status => "string"}}) end @@ -152,7 +152,7 @@ describe '#add_property_method' do let(:definition) do - FactoryGirl.create(:generic_object_definition, + FactoryBot.create(:generic_object_definition, :name => 'test', :properties => { :methods => %w(method1) }) end @@ -170,7 +170,7 @@ describe '#delete_property_method' do let(:definition) do - FactoryGirl.create(:generic_object_definition, + FactoryBot.create(:generic_object_definition, :name => 'test', :properties => { :methods => %w(method1) }) end @@ -188,7 +188,7 @@ describe '#add_property_association' do let(:definition) do - FactoryGirl.create(:generic_object_definition, + FactoryBot.create(:generic_object_definition, :name => 'test', :properties => { :associations => { :vms => 'Vm' } }) end @@ -220,7 +220,7 @@ describe '#delete_property_association' do let(:definition) do - FactoryGirl.create(:generic_object_definition, + FactoryBot.create(:generic_object_definition, :name => 'test', :properties => {:associations => {:vms => 'Vm'}}) end @@ -236,8 +236,8 @@ end it 'deletes the association from associated generic objects' do - vm = FactoryGirl.create(:vm) - go = FactoryGirl.create(:generic_object, :name => 'test', :generic_object_definition => definition) + vm = FactoryBot.create(:vm) + go = FactoryBot.create(:generic_object, :name => 'test', :generic_object_definition => definition) go.add_to_property_association('vms', vm) expect(go.vms.size).to eq(1) @@ -281,7 +281,7 @@ it 'finds by associations' do vm = [] - 3.times { vm << FactoryGirl.create(:vm_vmware) } + 3.times { vm << FactoryBot.create(:vm_vmware) } definition.add_property_association(:vms, 'vm') @g1.vms = [vm[0], vm[1], vm[2]] @@ -295,24 +295,24 @@ describe "#custom_actions" do it "returns the custom actions in a hash grouped by buttons and button groups" do - FactoryGirl.create(:custom_button, :name => "generic_no_group", :applies_to_class => "GenericObject") - generic_group = FactoryGirl.create(:custom_button, :name => "generic_group", :applies_to_class => "GenericObject") - generic_group_set = FactoryGirl.create(:custom_button_set, :name => "generic_group_set") + FactoryBot.create(:custom_button, :name => "generic_no_group", :applies_to_class => "GenericObject") + generic_group = FactoryBot.create(:custom_button, :name => "generic_group", :applies_to_class => "GenericObject") + generic_group_set = FactoryBot.create(:custom_button_set, :name => "generic_group_set") generic_group_set.add_member(generic_group) - FactoryGirl.create( + FactoryBot.create( :custom_button, :name => "assigned_no_group", :applies_to_class => "GenericObjectDefinition", :applies_to_id => definition.id ) - assigned_group = FactoryGirl.create( + assigned_group = FactoryBot.create( :custom_button, :name => "assigned_group", :applies_to_class => "GenericObjectDefinition", :applies_to_id => definition.id ) - assigned_group_set = FactoryGirl.create(:custom_button_set, :name => "assigned_group_set") + assigned_group_set = FactoryBot.create(:custom_button_set, :name => "assigned_group_set") assigned_group_set.add_member(assigned_group) definition.update(:custom_button_sets => [assigned_group_set]) @@ -336,7 +336,7 @@ end context "expression evaluation" do - let(:generic) { FactoryGirl.build(:generic_object, :generic_object_definition => definition, :name => 'hello') } + let(:generic) { FactoryBot.build(:generic_object, :generic_object_definition => definition, :name => 'hello') } let(:true_expression_on_definition) do MiqExpression.new("=" => {"field" => "GenericObjectDefinition-name", "value" => "test_definition"}) end @@ -351,20 +351,20 @@ end before do - FactoryGirl.create(:custom_button, + FactoryBot.create(:custom_button, :name => "visible button on Generic Object", :applies_to_class => "GenericObject", :visibility_expression => true_expression_on_generic) - FactoryGirl.create(:custom_button, + FactoryBot.create(:custom_button, :name => "hidden button on Generic Object", :applies_to_class => "GenericObject", :visibility_expression => false_expression_on_generic) - FactoryGirl.create(:custom_button, + FactoryBot.create(:custom_button, :name => "visible button on Generic Object Definition", :applies_to_class => "GenericObjectDefinition", :applies_to_id => definition.id, :visibility_expression => true_expression_on_definition) - FactoryGirl.create(:custom_button, + FactoryBot.create(:custom_button, :name => "hidden button on Generic Object Definition", :applies_to_class => "GenericObjectDefinition", :applies_to_id => definition.id, diff --git a/spec/models/generic_object_spec.rb b/spec/models/generic_object_spec.rb index 268b7bac932..03291da9f72 100644 --- a/spec/models/generic_object_spec.rb +++ b/spec/models/generic_object_spec.rb @@ -4,11 +4,11 @@ let(:server_name) { "test_server" } let(:data_read) { 345.67 } let(:s_time) { Time.now.utc } - let(:vm1) { FactoryGirl.create(:vm_vmware) } - let(:user) { FactoryGirl.create(:user_with_group) } + let(:vm1) { FactoryBot.create(:vm_vmware) } + let(:user) { FactoryBot.create(:user_with_group) } let(:definition) do - FactoryGirl.create( + FactoryBot.create( :generic_object_definition, :name => "test_definition", :properties => { @@ -26,7 +26,7 @@ end let(:go) do - FactoryGirl.create( + FactoryBot.create( :generic_object, :generic_object_definition => definition, :name => go_object_name, @@ -104,7 +104,7 @@ end context "without generic_object_definition" do - let(:empty_go) { FactoryGirl.build(:generic_object) } + let(:empty_go) { FactoryBot.build(:generic_object) } it "raises an error when set a property attribute" do expect { empty_go.max_number = max_number }.to raise_error(NoMethodError) @@ -121,9 +121,9 @@ end describe 'property associations' do - let(:vm2) { FactoryGirl.create(:vm_vmware) } + let(:vm2) { FactoryBot.create(:vm_vmware) } let(:go_assoc) do - FactoryGirl.create( + FactoryBot.create( :generic_object, :generic_object_definition => definition, :name => 'go_assoc', @@ -144,7 +144,7 @@ end it 'skips invalid object when saving to DB' do - go_assoc.vms = [vm1, vm2, FactoryGirl.create(:host)] + go_assoc.vms = [vm1, vm2, FactoryBot.create(:host)] go_assoc.save! expect(go_assoc.reload.vms.count).to eq(2) @@ -162,7 +162,7 @@ end it 'method returns all associations' do - host = FactoryGirl.create(:host) + host = FactoryBot.create(:host) go_assoc.hosts = [host] result = go_assoc.property_associations @@ -253,7 +253,7 @@ end it 'an association' do - vm2 = FactoryGirl.create(:vm_vmware) + vm2 = FactoryBot.create(:vm_vmware) go.vms = [vm1, vm2] expect(go.delete_property("vms")).to match_array([vm1, vm2]) expect(go.vms).to be_empty @@ -269,7 +269,7 @@ end describe '#add_to_property_association' do - let(:new_vm) { FactoryGirl.create(:vm_vmware) } + let(:new_vm) { FactoryBot.create(:vm_vmware) } subject { go.add_to_property_association("vms", vm1) } it 'adds objects into association' do @@ -289,7 +289,7 @@ end it 'does not add object from differnt class' do - go.add_to_property_association("vms", FactoryGirl.create(:host)) + go.add_to_property_association("vms", FactoryBot.create(:host)) expect(go.vms.count).to eq(0) end @@ -301,7 +301,7 @@ describe '#delete_from_property_association' do before { go.add_to_property_association("vms", [vm1]) } - let(:new_vm) { FactoryGirl.create(:vm_vmware) } + let(:new_vm) { FactoryBot.create(:vm_vmware) } it 'deletes objects from association' do result = go.delete_from_property_association(:vms, [vm1]) @@ -317,7 +317,7 @@ end it 'does not delete object from differnt class' do - result = go.delete_from_property_association(:vms, [FactoryGirl.create(:host)]) + result = go.delete_from_property_association(:vms, [FactoryBot.create(:host)]) expect(go.vms).to match_array([vm1]) expect(result).to be_nil end @@ -328,7 +328,7 @@ end describe '#add_to_service' do - let(:service) { FactoryGirl.create(:service) } + let(:service) { FactoryBot.create(:service) } it 'associates the generic object to the service' do go.add_to_service(service) @@ -336,14 +336,14 @@ end it 'can associate to multiple services' do - go.add_to_service(FactoryGirl.create(:service)) + go.add_to_service(FactoryBot.create(:service)) go.add_to_service(service) expect(service.reload.generic_objects).to include(go) end end describe '#remove_from_service' do - let(:service) { FactoryGirl.create(:service) } + let(:service) { FactoryBot.create(:service) } it 'removes the generic object from the service' do go.add_to_service(service) @@ -378,7 +378,7 @@ end describe '#custom_button_events' do - let(:cb_event) { FactoryGirl.create(:custom_button_event, :target => go) } + let(:cb_event) { FactoryBot.create(:custom_button_event, :target => go) } it 'returns list of custom button events' do expect(go.custom_button_events).to match_array([cb_event]) diff --git a/spec/models/git_repository_spec.rb b/spec/models/git_repository_spec.rb index c8c5f0c41a3..eef3ab2dfdd 100644 --- a/spec/models/git_repository_spec.rb +++ b/spec/models/git_repository_spec.rb @@ -1,18 +1,18 @@ describe GitRepository do it "no url" do - expect { FactoryGirl.create(:git_repository) }.to raise_error(ActiveRecord::RecordInvalid) + expect { FactoryBot.create(:git_repository) }.to raise_error(ActiveRecord::RecordInvalid) end it "invalid url" do - expect { FactoryGirl.create(:git_repository, :url => "abc") }.to raise_error(ActiveRecord::RecordInvalid) + expect { FactoryBot.create(:git_repository, :url => "abc") }.to raise_error(ActiveRecord::RecordInvalid) end it "invalid url, no path" do - expect { FactoryGirl.create(:git_repository, :url => "http://example.com") }.to raise_error(ActiveRecord::RecordInvalid) + expect { FactoryBot.create(:git_repository, :url => "http://example.com") }.to raise_error(ActiveRecord::RecordInvalid) end it "default dirname" do - repo = FactoryGirl.create(:git_repository, + repo = FactoryBot.create(:git_repository, :url => "http://www.example.com/repos/manageiq") expect(repo.directory_name).to eq(File.join(MiqAeDatastore::GIT_REPO_DIRECTORY, 'repos/manageiq')) end @@ -34,7 +34,7 @@ 't2' => {:time => Time.now.utc + 5, :message => "T2", :commit_sha => "123456"} } end - let(:repo) { FactoryGirl.create(:git_repository, :url => git_url, :verify_ssl => verify_ssl) } + let(:repo) { FactoryBot.create(:git_repository, :url => git_url, :verify_ssl => verify_ssl) } let(:userid) { 'user' } let(:password) { 'password' } @@ -171,7 +171,7 @@ end repo.refresh - repo.git_branches << FactoryGirl.create(:git_branch, :name => 'DUMMY') + repo.git_branches << FactoryBot.create(:git_branch, :name => 'DUMMY') expect(repo.git_branches.collect(&:name)).to match_array(branch_list + ['DUMMY']) repo.refresh expect(repo.git_branches.collect(&:name)).to match_array(branch_list) @@ -190,7 +190,7 @@ end repo.refresh - repo.git_tags << FactoryGirl.create(:git_tag, :name => 'DUMMY') + repo.git_tags << FactoryBot.create(:git_tag, :name => 'DUMMY') expect(repo.git_tags.collect(&:name)).to match_array(tag_list + ['DUMMY']) repo.refresh expect(repo.git_tags.collect(&:name)).to match_array(tag_list) diff --git a/spec/models/guest_device_spec.rb b/spec/models/guest_device_spec.rb index 4f852d93980..284523dbd76 100644 --- a/spec/models/guest_device_spec.rb +++ b/spec/models/guest_device_spec.rb @@ -1,12 +1,12 @@ describe GuestDevice do - let!(:vm_gd) { FactoryGirl.create(:guest_device_nic) } - let!(:vm) { FactoryGirl.create(:vm_vmware, :hardware => FactoryGirl.create(:hardware, :guest_devices => [vm_gd])) } + let!(:vm_gd) { FactoryBot.create(:guest_device_nic) } + let!(:vm) { FactoryBot.create(:vm_vmware, :hardware => FactoryBot.create(:hardware, :guest_devices => [vm_gd])) } - let!(:template_gd) { FactoryGirl.create(:guest_device_nic) } - let!(:template) { FactoryGirl.create(:template_vmware, :hardware => FactoryGirl.create(:hardware, :guest_devices => [template_gd])) } + let!(:template_gd) { FactoryBot.create(:guest_device_nic) } + let!(:template) { FactoryBot.create(:template_vmware, :hardware => FactoryBot.create(:hardware, :guest_devices => [template_gd])) } - let!(:host_gd) { FactoryGirl.create(:guest_device_nic) } - let!(:host) { FactoryGirl.create(:host, :hardware => FactoryGirl.create(:hardware, :guest_devices => [host_gd])) } + let!(:host_gd) { FactoryBot.create(:guest_device_nic) } + let!(:host) { FactoryBot.create(:host, :hardware => FactoryBot.create(:hardware, :guest_devices => [host_gd])) } it "#vm_or_template" do expect(vm_gd.vm_or_template).to eq(vm) diff --git a/spec/models/hardware_spec.rb b/spec/models/hardware_spec.rb index 377e2043453..a4a6c273b54 100644 --- a/spec/models/hardware_spec.rb +++ b/spec/models/hardware_spec.rb @@ -1,8 +1,8 @@ describe Hardware do include Spec::Support::ArelHelper - let(:vm) { FactoryGirl.create(:vm_vmware, :hardware => FactoryGirl.create(:hardware)) } - let(:template) { FactoryGirl.create(:template_vmware, :hardware => FactoryGirl.create(:hardware)) } - let(:host) { FactoryGirl.create(:host, :hardware => FactoryGirl.create(:hardware)) } + let(:vm) { FactoryBot.create(:vm_vmware, :hardware => FactoryBot.create(:hardware)) } + let(:template) { FactoryBot.create(:template_vmware, :hardware => FactoryBot.create(:hardware)) } + let(:host) { FactoryBot.create(:host, :hardware => FactoryBot.create(:hardware)) } it "#vm_or_template" do expect(vm.hardware.vm_or_template).to eq(vm) @@ -30,7 +30,7 @@ describe ".aggregate_cpu_speed" do context "with empty hardware" do - let(:hardware) { FactoryGirl.build(:hardware) } + let(:hardware) { FactoryBot.build(:hardware) } it "bails ruby calculation" do expect(hardware.aggregate_cpu_speed).to be_nil end @@ -42,7 +42,7 @@ end context "with values" do - let(:hardware) { FactoryGirl.build(:hardware, :cpu_total_cores => 4, :cpu_speed => 1000) } + let(:hardware) { FactoryBot.build(:hardware, :cpu_total_cores => 4, :cpu_speed => 1000) } it "calculates in ruby" do expect(hardware.aggregate_cpu_speed).to eq(4000) @@ -57,7 +57,7 @@ describe ".v_pct_free_disk_space" do context "with empty hardware" do - let(:hardware) { FactoryGirl.build(:hardware) } + let(:hardware) { FactoryBot.build(:hardware) } it "bails ruby calculation" do expect(hardware.v_pct_free_disk_space).to be_nil expect(hardware.v_pct_used_disk_space).to be_nil @@ -71,7 +71,7 @@ end context "with values" do - let(:hardware) { FactoryGirl.build(:hardware, :disk_free_space => 20, :disk_capacity => 100) } + let(:hardware) { FactoryBot.build(:hardware, :disk_free_space => 20, :disk_capacity => 100) } it "calculates in ruby" do expect(hardware.v_pct_free_disk_space).to eq(20.0) @@ -86,7 +86,7 @@ end context "with 0 disk free " do - let(:hardware) { FactoryGirl.build(:hardware, :disk_free_space => 0, :disk_capacity => 100) } + let(:hardware) { FactoryBot.build(:hardware, :disk_free_space => 0, :disk_capacity => 100) } it "calculates in ruby" do expect(hardware.v_pct_free_disk_space).to eq(0.0) @@ -101,7 +101,7 @@ end context "with null disk capacity" do - let(:hardware) { FactoryGirl.build(:hardware, :disk_free_space => 20, :disk_capacity => nil) } + let(:hardware) { FactoryBot.build(:hardware, :disk_free_space => 20, :disk_capacity => nil) } it "calculates in ruby" do expect(hardware.v_pct_free_disk_space).to eq(nil) @@ -117,7 +117,7 @@ end describe ".allocated_disk_storage" do - let(:hardware) { FactoryGirl.create(:hardware) } + let(:hardware) { FactoryBot.create(:hardware) } context "with no disks" do it "bails ruby calculation" do @@ -132,9 +132,9 @@ context "with disks" do before do - FactoryGirl.create(:disk, :size_on_disk => 1024, :size => 10240, :hardware => hardware) - FactoryGirl.create(:disk, :size => 1024, :hardware => hardware) - FactoryGirl.create(:disk, :hardware => hardware) + FactoryBot.create(:disk, :size_on_disk => 1024, :size => 10240, :hardware => hardware) + FactoryBot.create(:disk, :size => 1024, :hardware => hardware) + FactoryBot.create(:disk, :hardware => hardware) end it "calculates in ruby" do @@ -149,7 +149,7 @@ end describe ".used_disk_storage" do - let(:hardware) { FactoryGirl.create(:hardware) } + let(:hardware) { FactoryBot.create(:hardware) } context "with no disks" do it "bails ruby calculation" do @@ -164,9 +164,9 @@ context "with disks" do before do - FactoryGirl.create(:disk, :size_on_disk => 1024, :size => 10240, :hardware => hardware) - FactoryGirl.create(:disk, :size => 1024, :hardware => hardware) - FactoryGirl.create(:disk, :hardware => hardware) + FactoryBot.create(:disk, :size_on_disk => 1024, :size => 10240, :hardware => hardware) + FactoryBot.create(:disk, :size => 1024, :hardware => hardware) + FactoryBot.create(:disk, :hardware => hardware) end it "calculates in ruby" do @@ -182,25 +182,25 @@ describe ".ram_size_in_bytes" do it "handles nil" do - hardware = FactoryGirl.build(:hardware) + hardware = FactoryBot.build(:hardware) expect(hardware.ram_size_in_bytes).to eq(0) end it "works in ruby" do - hardware = FactoryGirl.build(:hardware, :memory_mb => 5) + hardware = FactoryBot.build(:hardware, :memory_mb => 5) expect(hardware.ram_size_in_bytes).to eq(5.megabytes) end it "works in sql" do - FactoryGirl.create(:hardware, :memory_mb => 5) + FactoryBot.create(:hardware, :memory_mb => 5) expect(virtual_column_sql_value(Hardware, "ram_size_in_bytes")).to eq(5.megabytes) end it "does not raise error if return value bigger than PostgreSQL's integer type" do - FactoryGirl.create(:hardware, :memory_mb => 131_015) + FactoryBot.create(:hardware, :memory_mb => 131_015) expect { virtual_column_sql_value(Hardware, "ram_size_in_bytes") }.to_not raise_error end end @@ -208,7 +208,7 @@ # this is disks + ram_size_in_bytes # so we end up with 4 different senarios describe "#provisioned_storage" do - let(:hardware) { FactoryGirl.create(:hardware) } + let(:hardware) { FactoryBot.create(:hardware) } context "with no disks AND no memory" do it "calculates in ruby" do @@ -223,9 +223,9 @@ context "with disks AND no memory" do before do - FactoryGirl.create(:disk, :size_on_disk => 1024, :size => 10_240, :hardware => hardware) - FactoryGirl.create(:disk, :size => 1024, :hardware => hardware) - FactoryGirl.create(:disk, :hardware => hardware) + FactoryBot.create(:disk, :size_on_disk => 1024, :size => 10_240, :hardware => hardware) + FactoryBot.create(:disk, :size => 1024, :hardware => hardware) + FactoryBot.create(:disk, :hardware => hardware) end it "calculates in ruby" do @@ -239,7 +239,7 @@ end context "with no disks and memory" do - let(:hardware) { FactoryGirl.create(:hardware, :memory_mb => 5) } + let(:hardware) { FactoryBot.create(:hardware, :memory_mb => 5) } it "works in ruby" do expect(hardware.provisioned_storage).to eq(5.megabytes) @@ -252,11 +252,11 @@ end context "with disks and memory" do - let(:hardware) { FactoryGirl.create(:hardware, :memory_mb => 5) } + let(:hardware) { FactoryBot.create(:hardware, :memory_mb => 5) } before do - FactoryGirl.create(:disk, :size_on_disk => 1024, :size => 10_240, :hardware => hardware) - FactoryGirl.create(:disk, :size => 1024, :hardware => hardware) - FactoryGirl.create(:disk, :hardware => hardware) + FactoryBot.create(:disk, :size_on_disk => 1024, :size => 10_240, :hardware => hardware) + FactoryBot.create(:disk, :size => 1024, :hardware => hardware) + FactoryBot.create(:disk, :hardware => hardware) end it "works in ruby" do diff --git a/spec/models/host_spec.rb b/spec/models/host_spec.rb index 333dd82a45e..17a5a723244 100644 --- a/spec/models/host_spec.rb +++ b/spec/models/host_spec.rb @@ -1,36 +1,36 @@ describe Host do it "groups and users joins" do - user1 = FactoryGirl.create(:account_user) - user2 = FactoryGirl.create(:account_user) - group = FactoryGirl.create(:account_group) - host1 = FactoryGirl.create(:host_vmware, :users => [user1], :groups => [group]) - host2 = FactoryGirl.create(:host_vmware, :users => [user2]) + user1 = FactoryBot.create(:account_user) + user2 = FactoryBot.create(:account_user) + group = FactoryBot.create(:account_group) + host1 = FactoryBot.create(:host_vmware, :users => [user1], :groups => [group]) + host2 = FactoryBot.create(:host_vmware, :users => [user2]) expect(described_class.joins(:users)).to match_array([host1, host2]) expect(described_class.joins(:groups)).to eq [host1] expect(described_class.joins(:users, :groups)).to eq [host1] end it "directories and files joins" do - file1 = FactoryGirl.create(:filesystem, :rsc_type => "file") - file2 = FactoryGirl.create(:filesystem, :rsc_type => "file") - dir = FactoryGirl.create(:filesystem, :rsc_type => "dir") - host1 = FactoryGirl.create(:host_vmware, :files => [file1], :directories => [dir]) - host2 = FactoryGirl.create(:host_vmware, :files => [file2]) + file1 = FactoryBot.create(:filesystem, :rsc_type => "file") + file2 = FactoryBot.create(:filesystem, :rsc_type => "file") + dir = FactoryBot.create(:filesystem, :rsc_type => "dir") + host1 = FactoryBot.create(:host_vmware, :files => [file1], :directories => [dir]) + host2 = FactoryBot.create(:host_vmware, :files => [file2]) expect(described_class.joins(:files)).to match_array([host1, host2]) expect(described_class.joins(:directories)).to eq [host1] expect(described_class.joins(:files, :directories)).to eq [host1] end it "#ems_custom_attributes" do - ems_attr = FactoryGirl.create(:custom_attribute, :source => 'VC') - other_attr = FactoryGirl.create(:custom_attribute, :source => 'NOTVC') - host = FactoryGirl.create(:host_vmware, :custom_attributes => [ems_attr, other_attr]) + ems_attr = FactoryBot.create(:custom_attribute, :source => 'VC') + other_attr = FactoryBot.create(:custom_attribute, :source => 'NOTVC') + host = FactoryBot.create(:host_vmware, :custom_attributes => [ems_attr, other_attr]) expect(host.ems_custom_attributes).to eq [ems_attr] end it "#save_drift_state" do # TODO: Beef up with more data - host = FactoryGirl.create(:host_vmware) + host = FactoryBot.create(:host_vmware) host.save_drift_state expect(host.drift_states.size).to eq(1) @@ -60,13 +60,13 @@ it "emits cluster policy event when the cluster changes" do # New host added to a cluster - cluster1 = FactoryGirl.create(:ems_cluster) - host = FactoryGirl.build(:host_vmware, :ems_cluster => cluster1) + cluster1 = FactoryBot.create(:ems_cluster) + host = FactoryBot.build(:host_vmware, :ems_cluster => cluster1) expect(MiqEvent).to receive(:raise_evm_event).with(host, "host_add_to_cluster", anything) host.save # Existing host changes clusters - cluster2 = FactoryGirl.create(:ems_cluster) + cluster2 = FactoryBot.create(:ems_cluster) host.ems_cluster = cluster2 expect(MiqEvent).to receive(:raise_evm_event).with(host, "host_remove_from_cluster", hash_including(:ems_cluster => cluster1)) expect(MiqEvent).to receive(:raise_evm_event).with(host, "host_add_to_cluster", hash_including(:ems_cluster => cluster2)) @@ -79,7 +79,7 @@ end context "#scannable_status" do - let(:host) { FactoryGirl.build(:host_vmware) } + let(:host) { FactoryBot.build(:host_vmware) } subject { host.scannable_status } before do allow_any_instance_of(Authentication).to receive(:after_authentication_changed) @@ -118,8 +118,8 @@ before do EvmSpecHelper.create_guid_miq_server_zone - @ems = FactoryGirl.create(:ext_management_system, :tenant => FactoryGirl.create(:tenant)) - @host = FactoryGirl.create(:host, :ems_id => @ems.id) + @ems = FactoryBot.create(:ext_management_system, :tenant => FactoryBot.create(:tenant)) + @host = FactoryBot.create(:host, :ems_id => @ems.id) end context "#start" do @@ -127,9 +127,9 @@ allow_any_instance_of(described_class).to receive_messages(:validate_start => {}) allow_any_instance_of(described_class).to receive_messages(:validate_ipmi => {:available => true, :message => nil}) allow_any_instance_of(described_class).to receive_messages(:run_ipmi_command => "off") - FactoryGirl.create(:miq_event_definition, :name => :request_host_start) + FactoryBot.create(:miq_event_definition, :name => :request_host_start) # admin user is needed to process Events - FactoryGirl.create(:user_with_group, :userid => "admin", :name => "Administrator") + FactoryBot.create(:user_with_group, :userid => "admin", :name => "Administrator") end it "policy passes" do @@ -178,15 +178,15 @@ end context "quick statistics retrieval" do - subject { FactoryGirl.build(:host) } + subject { FactoryBot.build(:host) } it("#current_memory_usage") { expect(subject.current_memory_usage).to be_kind_of(Integer) } it("#current_cpu_usage") { expect(subject.current_cpu_usage).to be_kind_of(Integer) } end context "#vmm_vendor_display" do - it("known vendor") { expect(FactoryGirl.build(:host_vmware_esx).vmm_vendor_display).to eq("VMware") } - it("nil vendor") { expect(FactoryGirl.build(:host, :vmm_vendor => nil).vmm_vendor_display).to eq("Unknown") } + it("known vendor") { expect(FactoryBot.build(:host_vmware_esx).vmm_vendor_display).to eq("VMware") } + it("nil vendor") { expect(FactoryBot.build(:host, :vmm_vendor => nil).vmm_vendor_display).to eq("Unknown") } end it ".host_discovery_types" do @@ -202,7 +202,7 @@ EvmSpecHelper.local_miq_server @password = "v2:{/OViaBJ0Ug+RSW9n7EFGqw==}" - @host = FactoryGirl.create(:host_vmware_esx) + @host = FactoryBot.create(:host_vmware_esx) @data = {:default => {:userid => "root", :password => @password}} @options = {:save => false} end @@ -271,13 +271,13 @@ end context "#get_ports" do - let(:os) { FactoryGirl.create(:operating_system) } - subject { FactoryGirl.create(:host, :operating_system => os) } + let(:os) { FactoryBot.create(:operating_system) } + subject { FactoryBot.create(:host, :operating_system => os) } before do - FactoryGirl.create(:firewall_rule, :host_protocol => 'udp', :direction => "in", :enabled => true, :port => 1001, :resource => os) - FactoryGirl.create(:firewall_rule, :host_protocol => 'udp', :direction => "out", :enabled => true, :port => 1002, :resource => os) - FactoryGirl.create(:firewall_rule, :host_protocol => 'tcp', :direction => "in", :enabled => true, :port => 1003, :resource => os) + FactoryBot.create(:firewall_rule, :host_protocol => 'udp', :direction => "in", :enabled => true, :port => 1001, :resource => os) + FactoryBot.create(:firewall_rule, :host_protocol => 'udp', :direction => "out", :enabled => true, :port => 1002, :resource => os) + FactoryBot.create(:firewall_rule, :host_protocol => 'tcp', :direction => "in", :enabled => true, :port => 1003, :resource => os) end it("#enabled_udp_outbound_ports") { expect(subject.enabled_udp_outbound_ports).to match_array([1002]) } @@ -286,30 +286,30 @@ context ".node_types" do it "returns :mixed_hosts when there are both openstack & non-openstack hosts in db" do - FactoryGirl.create(:host_openstack_infra, :ext_management_system => FactoryGirl.create(:ems_openstack_infra)) - FactoryGirl.create(:host_vmware_esx, :ext_management_system => FactoryGirl.create(:ems_vmware)) + FactoryBot.create(:host_openstack_infra, :ext_management_system => FactoryBot.create(:ems_openstack_infra)) + FactoryBot.create(:host_vmware_esx, :ext_management_system => FactoryBot.create(:ems_vmware)) expect(Host.node_types).to eq(:mixed_hosts) end it "returns :openstack when there are only openstack hosts in db" do - FactoryGirl.create(:host_openstack_infra, :ext_management_system => FactoryGirl.create(:ems_openstack_infra)) + FactoryBot.create(:host_openstack_infra, :ext_management_system => FactoryBot.create(:ems_openstack_infra)) expect(Host.node_types).to eq(:openstack) end it "returns :non_openstack when there are non-openstack hosts in db" do - FactoryGirl.create(:host_vmware_esx, :ext_management_system => FactoryGirl.create(:ems_vmware)) + FactoryBot.create(:host_vmware_esx, :ext_management_system => FactoryBot.create(:ems_vmware)) expect(Host.node_types).to eq(:non_openstack) end end context "#openstack_host?" do - it("false") { expect(FactoryGirl.build(:host).openstack_host?).to be false } + it("false") { expect(FactoryBot.build(:host).openstack_host?).to be false } it "true" do - expect(FactoryGirl.build(:host_openstack_infra, :ext_management_system => FactoryGirl.create(:ems_openstack_infra))).to be_openstack_host + expect(FactoryBot.build(:host_openstack_infra, :ext_management_system => FactoryBot.create(:ems_openstack_infra))).to be_openstack_host end end @@ -326,15 +326,15 @@ def assert_remote_credentials_validated end context "#tenant_identity" do - let(:admin) { FactoryGirl.create(:user_with_group, :userid => "admin") } - let(:tenant) { FactoryGirl.create(:tenant) } - let(:ems) { FactoryGirl.create(:ext_management_system, :tenant => tenant) } + let(:admin) { FactoryBot.create(:user_with_group, :userid => "admin") } + let(:tenant) { FactoryBot.create(:tenant) } + let(:ems) { FactoryBot.create(:ext_management_system, :tenant => tenant) } before { admin } subject { @host.tenant_identity } it "has tenant from provider" do - @host = FactoryGirl.create(:host, :ext_management_system => ems) + @host = FactoryBot.create(:host, :ext_management_system => ems) expect(subject).to eq(admin) expect(subject.current_group).to eq(ems.tenant.default_miq_group) @@ -342,7 +342,7 @@ def assert_remote_credentials_validated end it "without a provider, has tenant from root tenant" do - @host = FactoryGirl.create(:host) + @host = FactoryBot.create(:host) expect(subject).to eq(admin) expect(subject.current_group).to eq(Tenant.root_tenant.default_miq_group) @@ -351,11 +351,11 @@ def assert_remote_credentials_validated end describe "#disconnect_ems" do - let(:ems) { FactoryGirl.build(:ext_management_system) } + let(:ems) { FactoryBot.build(:ext_management_system) } let(:host) do - FactoryGirl.build(:host, + FactoryBot.build(:host, :ext_management_system => ems, - :ems_cluster => FactoryGirl.build(:ems_cluster)) + :ems_cluster => FactoryBot.build(:ems_cluster)) end it "clears ems and cluster" do host.disconnect_ems(ems) @@ -364,7 +364,7 @@ def assert_remote_credentials_validated end it "doesnt clear the wrong ems" do - host.disconnect_ems(FactoryGirl.build(:ext_management_system)) + host.disconnect_ems(FactoryBot.build(:ext_management_system)) expect(host.ext_management_system).not_to be_nil expect(host.ems_cluster).not_to be_nil end @@ -372,16 +372,16 @@ def assert_remote_credentials_validated describe "#v_total_storages" do it "counts" do - host = FactoryGirl.create(:host) - host.storages.create(FactoryGirl.attributes_for(:storage)) + host = FactoryBot.create(:host) + host.storages.create(FactoryBot.attributes_for(:storage)) expect(host.v_total_storages).to eq(1) end end describe "#v_total_vms" do it "counts" do - host = FactoryGirl.create(:host) - FactoryGirl.create(:vm, :host => host) + host = FactoryBot.create(:host) + FactoryBot.create(:vm, :host => host) expect(host.v_total_vms).to eq(1) expect(Host.attribute_supported_by_sql?(:v_total_vms)).to be true end @@ -389,8 +389,8 @@ def assert_remote_credentials_validated describe "#v_total_miq_templates" do it "counts" do - host = FactoryGirl.create(:host) - FactoryGirl.create(:template, :host => host) + host = FactoryBot.create(:host) + FactoryBot.create(:template, :host => host) expect(host.v_total_miq_templates).to eq(1) expect(Host.attribute_supported_by_sql?(:v_total_miq_templates)).to be true end @@ -398,49 +398,49 @@ def assert_remote_credentials_validated describe "#v_annotation" do it "handles nil" do - h = FactoryGirl.build(:host) + h = FactoryBot.build(:host) expect(h.v_annotation).to be_nil end it "delegates" do - h = FactoryGirl.build(:host, :hardware => FactoryGirl.build(:hardware, :annotation => "the annotation")) + h = FactoryBot.build(:host, :hardware => FactoryBot.build(:hardware, :annotation => "the annotation")) expect(h.v_annotation).to eq("the annotation") end end describe "#v_owning_cluster" do it "handles nil" do - h = FactoryGirl.build(:host) + h = FactoryBot.build(:host) expect(h.v_owning_cluster).to eq("") end it "delegates" do - h = FactoryGirl.build(:host, :ems_cluster => FactoryGirl.build(:ems_cluster, :name => "the cluster")) + h = FactoryBot.build(:host, :ems_cluster => FactoryBot.build(:ems_cluster, :name => "the cluster")) expect(h.v_owning_cluster).to eq("the cluster") end end describe "#ram_size" do it "handles nil" do - h = FactoryGirl.build(:host) + h = FactoryBot.build(:host) expect(h.ram_size).to eq(0) end it "delegates" do - h = FactoryGirl.build(:host, :hardware => FactoryGirl.build(:hardware, :memory_mb => 100)) + h = FactoryBot.build(:host, :hardware => FactoryBot.build(:hardware, :memory_mb => 100)) expect(h.ram_size).to eq(100) end end describe "#cpu_total_cores", "#total_vcpus" do it "handles nil" do - h = FactoryGirl.build(:host) + h = FactoryBot.build(:host) expect(h.cpu_total_cores).to eq(0) expect(h.total_vcpus).to eq(0) end it "delegates" do - h = FactoryGirl.build(:host, :hardware => FactoryGirl.build(:hardware, :cpu_total_cores => 4)) + h = FactoryBot.build(:host, :hardware => FactoryBot.build(:hardware, :cpu_total_cores => 4)) expect(h.cpu_total_cores).to eq(4) expect(h.total_vcpus).to eq(4) end @@ -448,46 +448,46 @@ def assert_remote_credentials_validated describe "#num_cpu" do it "handles nil" do - h = FactoryGirl.build(:host) + h = FactoryBot.build(:host) expect(h.num_cpu).to eq(0) end it "delegates" do - h = FactoryGirl.build(:host, :hardware => FactoryGirl.build(:hardware, :cpu_sockets => 3)) + h = FactoryBot.build(:host, :hardware => FactoryBot.build(:hardware, :cpu_sockets => 3)) expect(h.num_cpu).to eq(3) end end describe "#cpu_cores_per_socket" do it "handles nil" do - h = FactoryGirl.build(:host) + h = FactoryBot.build(:host) expect(h.cpu_cores_per_socket).to eq(0) end it "delegates" do - h = FactoryGirl.build(:host, :hardware => FactoryGirl.build(:hardware, :cpu_cores_per_socket => 4)) + h = FactoryBot.build(:host, :hardware => FactoryBot.build(:hardware, :cpu_cores_per_socket => 4)) expect(h.cpu_cores_per_socket).to eq(4) end end context "supported features" do it "does not support refresh_network_interfaces" do - host = FactoryGirl.build(:host) + host = FactoryBot.build(:host) expect(host.supports_refresh_network_interfaces?).to be_falsey end end describe "#authentication_check_role" do it "returns smartstate" do - host = FactoryGirl.build(:host) + host = FactoryBot.build(:host) expect(host.authentication_check_role).to eq('smartstate') end end describe "#validate_power_state" do let(:host) do - FactoryGirl.create(:host_vmware_esx, - :ext_management_system => FactoryGirl.create(:ems_vmware), + FactoryBot.create(:host_vmware_esx, + :ext_management_system => FactoryBot.create(:ems_vmware), :vmm_vendor => 'vmware') end @@ -510,8 +510,8 @@ def assert_remote_credentials_validated context "vmotion validation methods" do let(:host) do - FactoryGirl.create(:host_vmware_esx, - :ext_management_system => FactoryGirl.create(:ems_vmware), + FactoryBot.create(:host_vmware_esx, + :ext_management_system => FactoryBot.create(:ems_vmware), :vmm_vendor => 'vmware') end @@ -538,7 +538,7 @@ def assert_remote_credentials_validated subject { host.validate_ipmi } context "host does not have ipmi address" do - let(:host) { FactoryGirl.create(:host) } + let(:host) { FactoryBot.create(:host) } it "returns available false" do expect(subject).to eq(:available => false, :message => "The Host is not configured for IPMI") @@ -546,7 +546,7 @@ def assert_remote_credentials_validated end context "host has ipmi address" do - let(:host) { FactoryGirl.create(:host, :ipmi_address => "127.0.0.1") } + let(:host) { FactoryBot.create(:host, :ipmi_address => "127.0.0.1") } before do EvmSpecHelper.local_miq_server end @@ -574,13 +574,13 @@ def assert_remote_credentials_validated end context "ipmi validation methods" do - let(:host_with_ipmi) { FactoryGirl.create(:host_with_ipmi) } + let(:host_with_ipmi) { FactoryBot.create(:host_with_ipmi) } before do EvmSpecHelper.local_miq_server end describe "#validate_start" do - let(:host_off) { FactoryGirl.create(:host_with_ipmi, :power_state => 'off') } + let(:host_off) { FactoryBot.create(:host_with_ipmi, :power_state => 'off') } it "returns available true" do expect(host_off.validate_start).to eq(:available => true, :message => nil) @@ -601,8 +601,8 @@ def assert_remote_credentials_validated end describe ".clustered" do - let(:host_with_cluster) { FactoryGirl.create(:host, :ems_cluster => FactoryGirl.create(:ems_cluster)) } - let(:host) { FactoryGirl.create(:host) } + let(:host_with_cluster) { FactoryBot.create(:host, :ems_cluster => FactoryBot.create(:ems_cluster)) } + let(:host) { FactoryBot.create(:host) } it "detects clustered hosts" do host_with_cluster @@ -613,8 +613,8 @@ def assert_remote_credentials_validated end describe ".non_clustered" do - let(:host_with_cluster) { FactoryGirl.create(:host, :ems_cluster => FactoryGirl.create(:ems_cluster)) } - let(:host) { FactoryGirl.create(:host) } + let(:host_with_cluster) { FactoryBot.create(:host, :ems_cluster => FactoryBot.create(:ems_cluster)) } + let(:host) { FactoryBot.create(:host) } it "detects non_clustered hosts" do host_with_cluster @@ -627,10 +627,10 @@ def assert_remote_credentials_validated describe "#scan" do before do EvmSpecHelper.create_guid_miq_server_zone - @host = FactoryGirl.create(:host_vmware) - FactoryGirl.create(:miq_event_definition, :name => :request_host_scan) + @host = FactoryBot.create(:host_vmware) + FactoryBot.create(:miq_event_definition, :name => :request_host_scan) # admin user is needed to process Events - User.super_admin || FactoryGirl.create(:user_with_group, :userid => "admin") + User.super_admin || FactoryBot.create(:user_with_group, :userid => "admin") end it "policy passes" do @@ -681,17 +681,17 @@ def assert_remote_credentials_validated it "true with address and credentials but not including mac_addr" do EvmSpecHelper.local_miq_server # because of the authentication change - expect(FactoryGirl.create(:host_with_ipmi).ipmi_config_valid?).to eq(true) + expect(FactoryBot.create(:host_with_ipmi).ipmi_config_valid?).to eq(true) end it "false with address, credentials and include_mac_addr with blank address" do EvmSpecHelper.local_miq_server # because of the authentication change - expect(FactoryGirl.create(:host_with_ipmi, :mac_address => nil).ipmi_config_valid?(true)).to eq(false) + expect(FactoryBot.create(:host_with_ipmi, :mac_address => nil).ipmi_config_valid?(true)).to eq(false) end it "true with address, credentials and include_mac_addr with blank address" do EvmSpecHelper.local_miq_server # because of the authentication change - expect(FactoryGirl.create(:host_with_ipmi).ipmi_config_valid?(true)).to eq(true) + expect(FactoryBot.create(:host_with_ipmi).ipmi_config_valid?(true)).to eq(true) end end end diff --git a/spec/models/iso_datastore_spec.rb b/spec/models/iso_datastore_spec.rb index 7679255e845..c657b029c08 100644 --- a/spec/models/iso_datastore_spec.rb +++ b/spec/models/iso_datastore_spec.rb @@ -1,12 +1,12 @@ describe IsoDatastore do - let(:ems) { FactoryGirl.create(:ems_redhat) } - let(:iso_datastore) { FactoryGirl.create(:iso_datastore, :ext_management_system => ems) } + let(:ems) { FactoryBot.create(:ems_redhat) } + let(:iso_datastore) { FactoryBot.create(:iso_datastore, :ext_management_system => ems) } describe "#advertised_images" do subject(:advertised_images) { iso_datastore.advertised_images } context "ems is not rhv" do - let(:ems) { FactoryGirl.create(:ems_vmware) } + let(:ems) { FactoryBot.create(:ems_vmware) } it "returns empty array" do expect(advertised_images).to eq([]) end diff --git a/spec/models/job_proxy_dispatcher_embedded_scan_spec.rb b/spec/models/job_proxy_dispatcher_embedded_scan_spec.rb index 744484febb3..2a35cbf223a 100644 --- a/spec/models/job_proxy_dispatcher_embedded_scan_spec.rb +++ b/spec/models/job_proxy_dispatcher_embedded_scan_spec.rb @@ -39,11 +39,11 @@ def assert_at_most_x_scan_jobs_per_y_resource(x_scans, y_resource) end context "With a zone, server, ems, hosts, vmware vms" do - let(:zone) { FactoryGirl.create(:zone) } + let(:zone) { FactoryBot.create(:zone) } before do server = EvmSpecHelper.local_miq_server(:is_master => true, :name => "test_server_main_server", :zone => zone) (NUM_OF_SERVERS - 1).times do |i| - FactoryGirl.create(:miq_server, :zone => server.zone, :name => "test_server_#{i}") + FactoryBot.create(:miq_server, :zone => server.zone, :name => "test_server_#{i}") end # TODO: We should be able to set values so we don't need to stub behavior diff --git a/spec/models/job_proxy_dispatcher_get_eligible_proxies_for_job_spec.rb b/spec/models/job_proxy_dispatcher_get_eligible_proxies_for_job_spec.rb index 7d80b4376e7..37194f93cdb 100644 --- a/spec/models/job_proxy_dispatcher_get_eligible_proxies_for_job_spec.rb +++ b/spec/models/job_proxy_dispatcher_get_eligible_proxies_for_job_spec.rb @@ -4,7 +4,7 @@ context "with two servers on same zone, vix disk enabled for all, " do before do @server1 = EvmSpecHelper.local_miq_server - @server2 = FactoryGirl.create(:miq_server, :zone => @server1.zone) + @server2 = FactoryBot.create(:miq_server, :zone => @server1.zone) allow_any_instance_of(MiqServer).to receive_messages(:is_vix_disk? => true) # Support old style class methods or new instance style diff --git a/spec/models/job_proxy_dispatcher_spec.rb b/spec/models/job_proxy_dispatcher_spec.rb index 04fa68a3b1a..3f1bca7e4b5 100644 --- a/spec/models/job_proxy_dispatcher_spec.rb +++ b/spec/models/job_proxy_dispatcher_spec.rb @@ -7,7 +7,7 @@ NUM_SERVERS = 3 NUM_STORAGES = 3 - let(:zone) { FactoryGirl.create(:zone) } + let(:zone) { FactoryBot.create(:zone) } let(:dispatcher) do JobProxyDispatcher.new.tap do |dispatcher| dispatcher.instance_variable_set(:@zone, zone.name) @@ -21,7 +21,7 @@ context "With a default zone, server, with hosts with a miq_proxy, vmware vms on storages" do before do (NUM_SERVERS - 1).times do |i| - FactoryGirl.create(:miq_server, :zone => @server.zone, :name => "test_server_#{i}") + FactoryBot.create(:miq_server, :zone => @server.zone, :name => "test_server_#{i}") end # TODO: We should be able to set values so we don't need to stub behavior @@ -166,7 +166,7 @@ let (:container_image_classes) { ContainerImage.descendants.collect(&:name).append('ContainerImage') } before do @jobs = (@vms + @repo_vms).collect(&:raw_scan) - User.current_user = FactoryGirl.create(:user) + User.current_user = FactoryBot.create(:user) @jobs += @container_images.map { |img| img.ext_management_system.raw_scan_job_create(img.class, img.id) } end diff --git a/spec/models/job_proxy_dispatcher_vm_miq_server_proxies_spec.rb b/spec/models/job_proxy_dispatcher_vm_miq_server_proxies_spec.rb index d7b3a1abcff..002ee51246f 100644 --- a/spec/models/job_proxy_dispatcher_vm_miq_server_proxies_spec.rb +++ b/spec/models/job_proxy_dispatcher_vm_miq_server_proxies_spec.rb @@ -2,10 +2,10 @@ include Spec::Support::JobProxyDispatcherHelper context "with two servers on same zone, vix disk enabled for all, " do - let(:zone) { FactoryGirl.create(:zone) } + let(:zone) { FactoryBot.create(:zone) } before do @server1 = EvmSpecHelper.local_miq_server(:zone => zone) - @server2 = FactoryGirl.create(:miq_server, :zone => zone) + @server2 = FactoryBot.create(:miq_server, :zone => zone) allow_any_instance_of(MiqServer).to receive_messages(:is_vix_disk? => true) end @@ -48,7 +48,7 @@ context "with only a server in a different zone than the vm, " do before do - @vms_zone = FactoryGirl.create(:zone, :description => "Zone 1", :name => "zone1") + @vms_zone = FactoryBot.create(:zone, :description => "Zone 1", :name => "zone1") @server2.zone = @vms_zone @server2.save allow(@vm).to receive_messages(:my_zone => @vms_zone.name) diff --git a/spec/models/job_proxy_dispatcher_vm_proxies4job_spec.rb b/spec/models/job_proxy_dispatcher_vm_proxies4job_spec.rb index 235c8a94c9c..b43f55235c1 100644 --- a/spec/models/job_proxy_dispatcher_vm_proxies4job_spec.rb +++ b/spec/models/job_proxy_dispatcher_vm_proxies4job_spec.rb @@ -4,7 +4,7 @@ context "with two servers on same zone, vix disk enabled for all, " do before do @server1 = EvmSpecHelper.local_miq_server(:is_master => true) - @server2 = FactoryGirl.create(:miq_server, :zone => @server1.zone) + @server2 = FactoryBot.create(:miq_server, :zone => @server1.zone) allow_any_instance_of(MiqServer).to receive_messages(:is_vix_disk? => true) end diff --git a/spec/models/job_proxy_dispatcher_vm_storage2hosts_spec.rb b/spec/models/job_proxy_dispatcher_vm_storage2hosts_spec.rb index 76b89d94066..891f58e226a 100644 --- a/spec/models/job_proxy_dispatcher_vm_storage2hosts_spec.rb +++ b/spec/models/job_proxy_dispatcher_vm_storage2hosts_spec.rb @@ -4,7 +4,7 @@ context "with two servers on same zone, vix disk enabled for all, " do before do @server1 = EvmSpecHelper.local_miq_server(:is_master => true) - @server2 = FactoryGirl.create(:miq_server, :zone => @server1.zone) + @server2 = FactoryBot.create(:miq_server, :zone => @server1.zone) allow_any_instance_of(MiqServer).to receive_messages(:is_vix_disk? => true) end diff --git a/spec/models/job_proxy_dispatcher_vm_storage2proxies_spec.rb b/spec/models/job_proxy_dispatcher_vm_storage2proxies_spec.rb index c58f0d4be68..824bc79010d 100644 --- a/spec/models/job_proxy_dispatcher_vm_storage2proxies_spec.rb +++ b/spec/models/job_proxy_dispatcher_vm_storage2proxies_spec.rb @@ -4,7 +4,7 @@ context "two vix disk enabled servers," do before do @server1 = EvmSpecHelper.local_miq_server(:is_master => true) - @server2 = FactoryGirl.create(:miq_server, :zone => @server1.zone) + @server2 = FactoryBot.create(:miq_server, :zone => @server1.zone) allow_any_instance_of(MiqServer).to receive_messages(:is_vix_disk? => true) end @@ -51,7 +51,7 @@ context "'smartproxy' server and roles deactivated" do before do - FactoryGirl.create(:server_role, :name => "smartproxy", :max_concurrent => 0) + FactoryBot.create(:server_role, :name => "smartproxy", :max_concurrent => 0) @server1.deactivate_all_roles @server1.role = 'smartproxy' @@ -85,7 +85,7 @@ before do allow_any_instance_of(ManageIQ::Providers::Vmware::InfraManager).to receive_messages(:missing_credentials? => true) allow(@vm).to receive_messages(:template? => true) - @ems1 = FactoryGirl.create(:ems_vmware, :name => "Ems1") + @ems1 = FactoryBot.create(:ems_vmware, :name => "Ems1") @vm.ext_management_system = @ems1 @vm.save end diff --git a/spec/models/job_spec.rb b/spec/models/job_spec.rb index 55e117bb5f7..0a297883966 100644 --- a/spec/models/job_spec.rb +++ b/spec/models/job_spec.rb @@ -2,17 +2,17 @@ context "With a single scan job," do before do @server1 = EvmSpecHelper.local_miq_server(:is_master => true) - @server2 = FactoryGirl.create(:miq_server, :zone => @server1.zone) + @server2 = FactoryBot.create(:miq_server, :zone => @server1.zone) @miq_server = EvmSpecHelper.local_miq_server(:is_master => true) @zone = @miq_server.zone - @ems = FactoryGirl.create(:ems_vmware, :zone => @zone, :name => "Test EMS") - @host = FactoryGirl.create(:host) + @ems = FactoryBot.create(:ems_vmware, :zone => @zone, :name => "Test EMS") + @host = FactoryBot.create(:host) - @worker = FactoryGirl.create(:miq_worker, :miq_server_id => @miq_server.id) + @worker = FactoryBot.create(:miq_worker, :miq_server_id => @miq_server.id) @schedule_worker_settings = MiqScheduleWorker.worker_settings - @vm = FactoryGirl.create(:vm_vmware, :ems_id => @ems.id, :host_id => @host.id) + @vm = FactoryBot.create(:vm_vmware, :ems_id => @ems.id, :host_id => @host.id) @job = @vm.raw_scan end @@ -121,15 +121,15 @@ scan_type = nil build = '12345' description = "Snapshot for scan job: #{@job.guid}, EVM Server build: #{build} #{scan_type} Server Time: #{Time.now.utc.iso8601}" - @snapshot = FactoryGirl.create(:snapshot, :vm_or_template_id => @vm.id, :name => 'EvmSnapshot', :description => description) + @snapshot = FactoryBot.create(:snapshot, :vm_or_template_id => @vm.id, :name => 'EvmSnapshot', :description => description) - @zone2 = FactoryGirl.create(:zone) - @ems2 = FactoryGirl.create(:ems_vmware, :zone => @zone2, :name => "Test EMS 2") - @vm2 = FactoryGirl.create(:vm_vmware, :ems_id => @ems2.id) + @zone2 = FactoryBot.create(:zone) + @ems2 = FactoryBot.create(:ems_vmware, :zone => @zone2, :name => "Test EMS 2") + @vm2 = FactoryBot.create(:vm_vmware, :ems_id => @ems2.id) @job2 = @vm2.raw_scan @job2.zone = @zone2.name description = "Snapshot for scan job: #{@job2.guid}, EVM Server build: #{build} #{scan_type} Server Time: #{Time.now.utc.iso8601}" - @snapshot2 = FactoryGirl.create(:snapshot, :vm_or_template_id => @vm2.id, :name => 'EvmSnapshot', :description => description) + @snapshot2 = FactoryBot.create(:snapshot, :vm_or_template_id => @vm2.id, :name => 'EvmSnapshot', :description => description) end it "should create proper AR relationships" do @@ -247,12 +247,12 @@ context "where scan jobs exist for both vms and container images" do before do - User.current_user = FactoryGirl.create(:user) - @ems_k8s = FactoryGirl.create( + User.current_user = FactoryBot.create(:user) + @ems_k8s = FactoryBot.create( :ems_kubernetes, :hostname => "test.com", :zone => @zone, :port => 8443, :authentications => [AuthToken.new(:name => "test", :type => 'AuthToken', :auth_key => "a secret")] ) - @image = FactoryGirl.create( + @image = FactoryBot.create( :container_image, :ext_management_system => @ems_k8s, :name => 'test', :image_ref => "docker://3629a651e6c11d7435937bdf41da11cf87863c03f2587fa788cf5cbfe8a11b9a" ) diff --git a/spec/models/lan_spec.rb b/spec/models/lan_spec.rb index bbd1c749740..c117678b100 100644 --- a/spec/models/lan_spec.rb +++ b/spec/models/lan_spec.rb @@ -1,7 +1,7 @@ describe Lan do - let(:lan) { FactoryGirl.create(:lan) } - let!(:vm) { FactoryGirl.create(:vm_vmware, :hardware => FactoryGirl.create(:hardware, :guest_devices => [FactoryGirl.create(:guest_device_nic, :lan => lan)])) } - let!(:template) { FactoryGirl.create(:template_vmware, :hardware => FactoryGirl.create(:hardware, :guest_devices => [FactoryGirl.create(:guest_device_nic, :lan => lan)])) } + let(:lan) { FactoryBot.create(:lan) } + let!(:vm) { FactoryBot.create(:vm_vmware, :hardware => FactoryBot.create(:hardware, :guest_devices => [FactoryBot.create(:guest_device_nic, :lan => lan)])) } + let!(:template) { FactoryBot.create(:template_vmware, :hardware => FactoryBot.create(:hardware, :guest_devices => [FactoryBot.create(:guest_device_nic, :lan => lan)])) } it "#vms_and_templates" do expect(lan.vms_and_templates).to match_array [vm, template] diff --git a/spec/models/log_collection_spec.rb b/spec/models/log_collection_spec.rb index 02785a96be4..b1fcda90081 100644 --- a/spec/models/log_collection_spec.rb +++ b/spec/models/log_collection_spec.rb @@ -5,9 +5,9 @@ context "active log_collection" do before do - @log_file = FactoryGirl.create(:log_file, :state => "collecting") + @log_file = FactoryBot.create(:log_file, :state => "collecting") @miq_server.log_files << @log_file - @task = FactoryGirl.create(:miq_task, + @task = FactoryBot.create(:miq_task, :miq_server_id => @miq_server.id, :name => "Zipped log retrieval for #{@miq_server.name}" ) @@ -41,8 +41,8 @@ context "with a log file instance" do before do - @log_file = FactoryGirl.create(:log_file, :resource => @miq_server) - @region = FactoryGirl.create(:miq_region) + @log_file = FactoryBot.create(:log_file, :resource => @miq_server) + @region = FactoryBot.create(:miq_region) @timestamp = "2010" @fname = "/test.zip" allow_any_instance_of(LogFile).to receive(:format_log_time).and_return(@timestamp) @@ -133,7 +133,7 @@ context "Log Collection #synchronize_logs" do before do - depot = FactoryGirl.create(:file_depot) + depot = FactoryBot.create(:file_depot) @zone.update_attributes(:log_file_depot_id => depot.id) end diff --git a/spec/models/manageiq/providers/cloud_manager/auth_key_pair_spec.rb b/spec/models/manageiq/providers/cloud_manager/auth_key_pair_spec.rb index acafcf3b241..996ef93c381 100644 --- a/spec/models/manageiq/providers/cloud_manager/auth_key_pair_spec.rb +++ b/spec/models/manageiq/providers/cloud_manager/auth_key_pair_spec.rb @@ -1,5 +1,5 @@ describe ManageIQ::Providers::CloudManager::AuthKeyPair do - let(:ems) { FactoryGirl.create(:ems_cloud) } + let(:ems) { FactoryBot.create(:ems_cloud) } context 'create and delete actions' do it "has methods" do diff --git a/spec/models/manageiq/providers/cloud_manager/configuration_spec.rb b/spec/models/manageiq/providers/cloud_manager/configuration_spec.rb index 9df1e477138..819cd81c2ac 100644 --- a/spec/models/manageiq/providers/cloud_manager/configuration_spec.rb +++ b/spec/models/manageiq/providers/cloud_manager/configuration_spec.rb @@ -1,6 +1,6 @@ describe ManageIQ::Providers::CloudManager::Provision::Configuration do it "#userdata_payload is clear text" do - template = FactoryGirl.build(:customization_template, :script => "#cloud-init") + template = FactoryBot.build(:customization_template, :script => "#cloud-init") provision = ManageIQ::Providers::CloudManager::Provision.new allow(provision).to receive(:customization_template).and_return(template) allow(provision).to receive(:post_install_callback_url).and_return("") diff --git a/spec/models/manageiq/providers/cloud_manager/orchestration_stack_spec.rb b/spec/models/manageiq/providers/cloud_manager/orchestration_stack_spec.rb index 34f944b91ca..5f18d7c4791 100644 --- a/spec/models/manageiq/providers/cloud_manager/orchestration_stack_spec.rb +++ b/spec/models/manageiq/providers/cloud_manager/orchestration_stack_spec.rb @@ -1,41 +1,41 @@ describe ManageIQ::Providers::CloudManager::OrchestrationStack do let!(:root_stack) do - FactoryGirl.create(:orchestration_stack_cloud).tap do |stack| - FactoryGirl.create(:vm_cloud, :orchestration_stack => stack) - FactoryGirl.create(:cloud_network, :orchestration_stack => stack) - FactoryGirl.create(:security_group, :orchestration_stack => stack) + FactoryBot.create(:orchestration_stack_cloud).tap do |stack| + FactoryBot.create(:vm_cloud, :orchestration_stack => stack) + FactoryBot.create(:cloud_network, :orchestration_stack => stack) + FactoryBot.create(:security_group, :orchestration_stack => stack) end end let!(:child_stack) do - FactoryGirl.create(:orchestration_stack_cloud, :parent => root_stack).tap do |stack| - FactoryGirl.create(:vm_cloud, :orchestration_stack => stack) - FactoryGirl.create(:cloud_network, :orchestration_stack => stack) - FactoryGirl.create(:security_group, :orchestration_stack => stack) + FactoryBot.create(:orchestration_stack_cloud, :parent => root_stack).tap do |stack| + FactoryBot.create(:vm_cloud, :orchestration_stack => stack) + FactoryBot.create(:cloud_network, :orchestration_stack => stack) + FactoryBot.create(:security_group, :orchestration_stack => stack) end end describe 'set_tenant_from_group' do before { Tenant.seed } - let(:tenant1) { FactoryGirl.create(:tenant) } - let(:tenant2) { FactoryGirl.create(:tenant) } - let(:group1) { FactoryGirl.create(:miq_group, :tenant => tenant1) } - let(:group2) { FactoryGirl.create(:miq_group, :tenant => tenant2) } + let(:tenant1) { FactoryBot.create(:tenant) } + let(:tenant2) { FactoryBot.create(:tenant) } + let(:group1) { FactoryBot.create(:miq_group, :tenant => tenant1) } + let(:group2) { FactoryBot.create(:miq_group, :tenant => tenant2) } it "assigns the tenant from the group" do - expect(FactoryGirl.create(:orchestration_stack, :miq_group => group1).tenant).to eq(tenant1) + expect(FactoryBot.create(:orchestration_stack, :miq_group => group1).tenant).to eq(tenant1) end it "assigns the tenant from the group_id" do - expect(FactoryGirl.create(:orchestration_stack, :miq_group_id => group1.id).tenant).to eq(tenant1) + expect(FactoryBot.create(:orchestration_stack, :miq_group_id => group1.id).tenant).to eq(tenant1) end it "assigns the tenant from the group over the tenant" do - expect(FactoryGirl.create(:orchestration_stack, :miq_group => group1, :tenant_id => tenant2).tenant).to eq(tenant1) + expect(FactoryBot.create(:orchestration_stack, :miq_group => group1, :tenant_id => tenant2).tenant).to eq(tenant1) end it "changes the tenant after changing the group" do - stack = FactoryGirl.create(:orchestration_stack, :miq_group => group1) + stack = FactoryBot.create(:orchestration_stack, :miq_group => group1) stack.update_attributes(:miq_group_id => group2.id) expect(stack.tenant).to eq(tenant2) end @@ -62,8 +62,8 @@ end describe '#service and #direct_service' do - let(:root_service) { FactoryGirl.create(:service) } - let(:child_service) { FactoryGirl.create(:service, :parent => root_service) } + let(:root_service) { FactoryBot.create(:service) } + let(:child_service) { FactoryBot.create(:service, :parent => root_service) } before { child_service.add_resource!(root_stack) } it 'finds the service for the stack' do diff --git a/spec/models/manageiq/providers/cloud_manager/provision_spec.rb b/spec/models/manageiq/providers/cloud_manager/provision_spec.rb index 0be7a946923..daecb392270 100644 --- a/spec/models/manageiq/providers/cloud_manager/provision_spec.rb +++ b/spec/models/manageiq/providers/cloud_manager/provision_spec.rb @@ -1,8 +1,8 @@ describe ManageIQ::Providers::CloudManager::Provision do context "Cloning" do - let(:provider) { FactoryGirl.create(:ems_cloud) } - let(:template) { FactoryGirl.create(:template_cloud, :ext_management_system => provider) } - let(:vm) { FactoryGirl.create(:vm_cloud, :ext_management_system => provider, :ems_ref => "vm_1") } + let(:provider) { FactoryBot.create(:ems_cloud) } + let(:template) { FactoryBot.create(:template_cloud, :ext_management_system => provider) } + let(:vm) { FactoryBot.create(:vm_cloud, :ext_management_system => provider, :ems_ref => "vm_1") } before do subject.source = template diff --git a/spec/models/manageiq/providers/cloud_manager/provision_workflow_spec.rb b/spec/models/manageiq/providers/cloud_manager/provision_workflow_spec.rb index 57fb7d70d6c..e3140889c34 100644 --- a/spec/models/manageiq/providers/cloud_manager/provision_workflow_spec.rb +++ b/spec/models/manageiq/providers/cloud_manager/provision_workflow_spec.rb @@ -1,13 +1,13 @@ describe ManageIQ::Providers::CloudManager::ProvisionWorkflow do include Spec::Support::WorkflowHelper - let(:admin) { FactoryGirl.create(:user_with_group) } - let(:ems) { FactoryGirl.create(:ems_cloud) } - let(:network_manager) { FactoryGirl.create(:ems_network, :parent_ems_id => ems.id) } - let(:template) { FactoryGirl.create(:miq_template, :name => "template", :ext_management_system => ems) } + let(:admin) { FactoryBot.create(:user_with_group) } + let(:ems) { FactoryBot.create(:ems_cloud) } + let(:network_manager) { FactoryBot.create(:ems_network, :parent_ems_id => ems.id) } + let(:template) { FactoryBot.create(:miq_template, :name => "template", :ext_management_system => ems) } - let(:cloud_init_template) { FactoryGirl.create(:customization_template_cloud_init) } - let(:sysprep_template) { FactoryGirl.create(:customization_template_sysprep) } + let(:cloud_init_template) { FactoryBot.create(:customization_template_cloud_init) } + let(:sysprep_template) { FactoryBot.create(:customization_template_sysprep) } let(:workflow) do stub_dialog @@ -79,7 +79,7 @@ context "with valid relationships" do it "#allowed_availability_zones" do - az = FactoryGirl.create(:availability_zone) + az = FactoryBot.create(:availability_zone) ems.availability_zones << az expect(workflow.allowed_availability_zones).to be_empty end @@ -94,7 +94,7 @@ context "without applied tags" do context "availability_zones" do it "#get_targets_for_ems" do - az = FactoryGirl.create(:availability_zone) + az = FactoryBot.create(:availability_zone) ems.availability_zones << az filtered = workflow.send(:get_targets_for_ems, ems, :cloud_filter, AvailabilityZone, 'availability_zones') @@ -111,7 +111,7 @@ context "floating_ips" do it "#get_targets_for_source" do - fip1 = FactoryGirl.create(:floating_ip, :cloud_network_only => true, + fip1 = FactoryBot.create(:floating_ip, :cloud_network_only => true, :ext_management_system => ems.network_manager) filtered = workflow.send(:get_targets_for_source, ems, :cloud_filter, FloatingIp, 'floating_ips.available') @@ -123,21 +123,21 @@ context "with applied tags" do before do - FactoryGirl.create(:classification_cost_center_with_tags) + FactoryBot.create(:classification_cost_center_with_tags) admin.current_group.entitlement = Entitlement.create!(:filters => {'managed' => [['/managed/cc/001']], 'belongsto' => []}) 2.times do |i| kp = ManageIQ::Providers::CloudManager::AuthKeyPair.create(:name => "auth_#{i}") ems.key_pairs << kp end - 2.times { FactoryGirl.create(:availability_zone, :ems_id => ems.id) } + 2.times { FactoryBot.create(:availability_zone, :ems_id => ems.id) } 2.times do - FactoryGirl.create(:security_group, :name => "sgb_1", + FactoryBot.create(:security_group, :name => "sgb_1", :ext_management_system => ems.network_manager) end - ems.flavors << FactoryGirl.create(:flavor, :name => "t1.micro", :supports_32_bit => true, + ems.flavors << FactoryBot.create(:flavor, :name => "t1.micro", :supports_32_bit => true, :supports_64_bit => true) - ems.flavors << FactoryGirl.create(:flavor, :name => "m1.large", :supports_32_bit => false, + ems.flavors << FactoryBot.create(:flavor, :name => "m1.large", :supports_32_bit => false, :supports_64_bit => true) tagged_key_pair = ems.key_pairs.first tagged_zone = ems.availability_zones.first @@ -172,21 +172,21 @@ context "with VPC relationships" do before do - @az1 = FactoryGirl.create(:availability_zone, :ext_management_system => ems) - @az2 = FactoryGirl.create(:availability_zone, :ext_management_system => ems) - @az3 = FactoryGirl.create(:availability_zone, :ext_management_system => ems) + @az1 = FactoryBot.create(:availability_zone, :ext_management_system => ems) + @az2 = FactoryBot.create(:availability_zone, :ext_management_system => ems) + @az3 = FactoryBot.create(:availability_zone, :ext_management_system => ems) - @cn1 = FactoryGirl.create(:cloud_network, :ext_management_system => ems.network_manager, :cidr => "10.0.0./8") + @cn1 = FactoryBot.create(:cloud_network, :ext_management_system => ems.network_manager, :cidr => "10.0.0./8") - @cs1 = FactoryGirl.create(:cloud_subnet, :cloud_network => @cn1, + @cs1 = FactoryBot.create(:cloud_subnet, :cloud_network => @cn1, :availability_zone => @az1, :ext_management_system => ems.network_manager) - @cs2 = FactoryGirl.create(:cloud_subnet, :cloud_network => @cn1, + @cs2 = FactoryBot.create(:cloud_subnet, :cloud_network => @cn1, :availability_zone => @az2, :ext_management_system => ems.network_manager) - @ip1 = FactoryGirl.create(:floating_ip, :cloud_network_only => true, + @ip1 = FactoryBot.create(:floating_ip, :cloud_network_only => true, :ext_management_system => ems.network_manager) - @ip2 = FactoryGirl.create(:floating_ip, :cloud_network_only => false, + @ip2 = FactoryBot.create(:floating_ip, :cloud_network_only => false, :ext_management_system => ems.network_manager) end diff --git a/spec/models/manageiq/providers/cloud_manager/template_spec.rb b/spec/models/manageiq/providers/cloud_manager/template_spec.rb index 414c254e55c..462de911602 100644 --- a/spec/models/manageiq/providers/cloud_manager/template_spec.rb +++ b/spec/models/manageiq/providers/cloud_manager/template_spec.rb @@ -19,11 +19,11 @@ end describe "miq_group" do - let(:user) { FactoryGirl.create(:user, :userid => 'user', :miq_groups => [tenant_group]) } - let(:tenant) { FactoryGirl.build(:tenant, :parent => default_tenant) } - let(:tenant_users) { FactoryGirl.create(:miq_user_role, :name => "tenant-users") } - let(:tenant_group) { FactoryGirl.create(:miq_group, :miq_user_role => tenant_users, :tenant => tenant) } - let(:cloud_template_1) { FactoryGirl.create(:class => "TemplateCloud") } + let(:user) { FactoryBot.create(:user, :userid => 'user', :miq_groups => [tenant_group]) } + let(:tenant) { FactoryBot.build(:tenant, :parent => default_tenant) } + let(:tenant_users) { FactoryBot.create(:miq_user_role, :name => "tenant-users") } + let(:tenant_group) { FactoryBot.create(:miq_group, :miq_user_role => tenant_users, :tenant => tenant) } + let(:cloud_template_1) { FactoryBot.create(:class => "TemplateCloud") } it "finds correct tenant id clause when tenant doesn't have source_id" do User.current_user = user diff --git a/spec/models/manageiq/providers/cloud_manager/vm_or_template_spec.rb b/spec/models/manageiq/providers/cloud_manager/vm_or_template_spec.rb index 7a681b702d3..b7d938a083d 100644 --- a/spec/models/manageiq/providers/cloud_manager/vm_or_template_spec.rb +++ b/spec/models/manageiq/providers/cloud_manager/vm_or_template_spec.rb @@ -1,10 +1,10 @@ describe ManageIQ::Providers::CloudManager::VmOrTemplate do describe "#all" do it "scopes" do - vm = FactoryGirl.create(:vm_openstack) - t = FactoryGirl.create(:template_openstack) - FactoryGirl.create(:vm_vmware) - FactoryGirl.create(:template_vmware) + vm = FactoryBot.create(:vm_openstack) + t = FactoryBot.create(:template_openstack) + FactoryBot.create(:vm_vmware) + FactoryBot.create(:template_vmware) expect(described_class.all).to match_array([vm, t]) end @@ -12,15 +12,15 @@ describe "#all_archived" do it "scopes" do - ems = FactoryGirl.create(:ems_openstack) - vm = FactoryGirl.create(:vm_openstack) - t = FactoryGirl.create(:template_openstack) + ems = FactoryBot.create(:ems_openstack) + vm = FactoryBot.create(:vm_openstack) + t = FactoryBot.create(:template_openstack) # non archived - FactoryGirl.create(:vm_openstack, :ext_management_system => ems) - FactoryGirl.create(:template_openstack, :ext_management_system => ems) + FactoryBot.create(:vm_openstack, :ext_management_system => ems) + FactoryBot.create(:template_openstack, :ext_management_system => ems) # non cloud - FactoryGirl.create(:vm_vmware) - FactoryGirl.create(:template_vmware) + FactoryBot.create(:vm_vmware) + FactoryBot.create(:template_vmware) expect(described_class.archived).to match_array([vm, t]) end diff --git a/spec/models/manageiq/providers/cloud_manager/vm_spec.rb b/spec/models/manageiq/providers/cloud_manager/vm_spec.rb index d18d80ee4ae..82168f6b64a 100644 --- a/spec/models/manageiq/providers/cloud_manager/vm_spec.rb +++ b/spec/models/manageiq/providers/cloud_manager/vm_spec.rb @@ -1,8 +1,8 @@ describe VmCloud do - subject { FactoryGirl.create(:vm_cloud) } + subject { FactoryBot.create(:vm_cloud) } context "relationships" do - let(:resource_group) { FactoryGirl.create(:resource_group) } + let(:resource_group) { FactoryBot.create(:resource_group) } before { subject.resource_group = resource_group } it "has one resource group" do @@ -20,8 +20,8 @@ end describe "#service and #direct_service" do - let(:service_root) { FactoryGirl.create(:service) } - let(:service) { FactoryGirl.create(:service, :parent => service_root) } + let(:service_root) { FactoryBot.create(:service) } + let(:service) { FactoryBot.create(:service, :parent => service_root) } context "provisioned through a vm provisioning service" do before { service.add_resource!(subject) } @@ -34,7 +34,7 @@ context "provisioned through an orchestration provisioning service" do before do - stack = FactoryGirl.create(:orchestration_stack, :direct_vms => [subject]) + stack = FactoryBot.create(:orchestration_stack, :direct_vms => [subject]) service.add_resource!(stack) end diff --git a/spec/models/manageiq/providers/cloud_manager_spec.rb b/spec/models/manageiq/providers/cloud_manager_spec.rb index 472996c5dd0..f28b67fe485 100644 --- a/spec/models/manageiq/providers/cloud_manager_spec.rb +++ b/spec/models/manageiq/providers/cloud_manager_spec.rb @@ -27,8 +27,8 @@ end context "OpenStack CloudTenant Mapping" do - let(:ems_cloud) { FactoryGirl.create(:ems_openstack_with_authentication, :tenant_mapping_enabled => true) } - let(:ems_infra) { FactoryGirl.create(:ext_management_system) } + let(:ems_cloud) { FactoryBot.create(:ems_openstack_with_authentication, :tenant_mapping_enabled => true) } + let(:ems_infra) { FactoryBot.create(:ext_management_system) } describe "#supports_cloud_tenant_mapping" do it "supports tenant mapping if the provider has CloudTenant relation and mapping is enabled" do @@ -52,9 +52,9 @@ end context "provider is not created under root tenant" do - let(:tenant) { FactoryGirl.build(:tenant, :parent => default_tenant) } + let(:tenant) { FactoryBot.build(:tenant, :parent => default_tenant) } let(:ems_cloud_without_root_tenant) do - FactoryGirl.create(:ems_openstack, :tenant => tenant, :tenant_mapping_enabled => true) + FactoryBot.create(:ems_openstack, :tenant => tenant, :tenant_mapping_enabled => true) end it "creates provider's tenant under tenant of provider" do @@ -116,26 +116,26 @@ ems_cloud.reload end - let(:vm_1) { FactoryGirl.create(:vm_openstack) } - let(:vm_2) { FactoryGirl.create(:vm_openstack) } - let(:vm_3) { FactoryGirl.create(:vm_openstack) } - let(:vm_4) { FactoryGirl.create(:vm_openstack) } + let(:vm_1) { FactoryBot.create(:vm_openstack) } + let(:vm_2) { FactoryBot.create(:vm_openstack) } + let(:vm_3) { FactoryBot.create(:vm_openstack) } + let(:vm_4) { FactoryBot.create(:vm_openstack) } let!(:ct_1) do - FactoryGirl.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud) + FactoryBot.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud) end let!(:ct_2) do - FactoryGirl.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :parent => ct_1, + FactoryBot.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :parent => ct_1, :vms_and_templates => [vm_1, vm_2]) end let!(:ct_3) do - FactoryGirl.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :parent => ct_2) + FactoryBot.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :parent => ct_2) end let!(:ct_4) do - FactoryGirl.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :parent => ct_2, + FactoryBot.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :parent => ct_2, :vms_and_templates => [vm_3, vm_4]) end @@ -203,10 +203,10 @@ def expect_created_tenant_tree expect(Tenant.first.name).to eq("My Company") end - let(:vm_5) { FactoryGirl.create(:vm_openstack) } + let(:vm_5) { FactoryBot.create(:vm_openstack) } let(:ct_5) do - FactoryGirl.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :parent => ct_4, + FactoryBot.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :parent => ct_4, :vms_and_templates => [vm_5]) end @@ -291,8 +291,8 @@ def expect_created_tenant_tree end context "provider's user is changed between two synchronizations" do - let!(:vm_1) { FactoryGirl.create(:vm_openstack) } - let!(:vm_2) { FactoryGirl.create(:vm_openstack) } + let!(:vm_1) { FactoryBot.create(:vm_openstack) } + let!(:vm_2) { FactoryBot.create(:vm_openstack) } let(:ct_name_1) { "c_t_1" } let(:ct_name_2) { "c_t_2" } let(:ct_name_3) { "c_t_3" } @@ -303,7 +303,7 @@ def tenant_from_cloud_tenant_by(vm) end let(:ct_3) do - FactoryGirl.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :name => ct_name_3) + FactoryBot.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :name => ct_name_3) end before do @@ -385,9 +385,9 @@ def tenant_from_cloud_tenant_by(vm) # -> t_3 (new_ct_3's) -> t_1(new_ct_1's) # -> t_2 (new_ct_2's) ###### - let(:ct_1_new) { FactoryGirl.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :parent => ct_3_new, :name => ct_name_1) } - let(:ct_2_new) { FactoryGirl.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :name => ct_name_2) } - let(:ct_3_new) { FactoryGirl.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :name => ct_name_3) } + let(:ct_1_new) { FactoryBot.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :parent => ct_3_new, :name => ct_name_1) } + let(:ct_2_new) { FactoryBot.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :name => ct_name_2) } + let(:ct_3_new) { FactoryBot.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :name => ct_name_3) } it "creates tenant tree from cloud tenants with correct source_tenant relations" do expect(CloudTenant.count).to eq(3) @@ -473,9 +473,9 @@ def tenant_from_cloud_tenant_by(vm) # -> t_2(old - moved out) # -> t_3(old - moved out) ###### - let(:ct_1_new) { FactoryGirl.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :parent => ct_3_new, :name => ct_name_1 + "X") } - let(:ct_2_new) { FactoryGirl.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :name => ct_name_2 + "X") } - let(:ct_3_new) { FactoryGirl.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :name => ct_name_3 + "X") } + let(:ct_1_new) { FactoryBot.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :parent => ct_3_new, :name => ct_name_1 + "X") } + let(:ct_2_new) { FactoryBot.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :name => ct_name_2 + "X") } + let(:ct_3_new) { FactoryBot.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :name => ct_name_3 + "X") } it "creates tenant tree from cloud tenants with correct source_tenant relations" do expect(CloudTenant.count).to eq(3) @@ -577,7 +577,7 @@ def tenant_from_cloud_tenant_by(vm) # -> t_2(old - moved out) # -> t_3(old - moved out) ###### - let(:ct_1_new) { FactoryGirl.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :name => ct_name_1) } + let(:ct_1_new) { FactoryBot.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :name => ct_name_1) } it "creates tenant tree from cloud tenants with correct source_tenant relations" do expect(CloudTenant.count).to eq(3) @@ -655,12 +655,12 @@ def tenant_from_cloud_tenant_by(vm) # -> t_1(old - moved out) # -> t_2(old - moved out) ###### - let(:ct_1_new) { FactoryGirl.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :parent => ct_3_new, :name => ct_name_1 + "X") } - let(:ct_2_new) { FactoryGirl.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :name => ct_name_2 + "X") } - let(:ct_3_new) { FactoryGirl.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :name => ct_name_3) } + let(:ct_1_new) { FactoryBot.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :parent => ct_3_new, :name => ct_name_1 + "X") } + let(:ct_2_new) { FactoryBot.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :name => ct_name_2 + "X") } + let(:ct_3_new) { FactoryBot.create(:cloud_tenant_openstack, :ext_management_system => ems_cloud, :name => ct_name_3) } let(:ct_name_4) { "ct_name_4" } let(:vm_4) do - vm = FactoryGirl.create(:vm_openstack) + vm = FactoryBot.create(:vm_openstack) vm.cloud_tenant.update_attributes!(:parent => ct_1_new, :ext_management_system => ems_cloud, :name => ct_name_4) vm end diff --git a/spec/models/manageiq/providers/container_manager/orchestration_stack_spec.rb b/spec/models/manageiq/providers/container_manager/orchestration_stack_spec.rb index bffced763a2..6eb36ca915e 100644 --- a/spec/models/manageiq/providers/container_manager/orchestration_stack_spec.rb +++ b/spec/models/manageiq/providers/container_manager/orchestration_stack_spec.rb @@ -1,5 +1,5 @@ describe ManageIQ::Providers::ContainerManager::OrchestrationStack do - let(:stack) { FactoryGirl.create(:orchestration_stack_container) } + let(:stack) { FactoryBot.create(:orchestration_stack_container) } describe '#retire_now' do it 'retires the orchestration stack' do diff --git a/spec/models/manageiq/providers/embedded_ansible/automation_manager/configuration_script_source_spec.rb b/spec/models/manageiq/providers/embedded_ansible/automation_manager/configuration_script_source_spec.rb index 02dd72925f9..f11f495d9b9 100644 --- a/spec/models/manageiq/providers/embedded_ansible/automation_manager/configuration_script_source_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/automation_manager/configuration_script_source_spec.rb @@ -1,6 +1,6 @@ describe ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScriptSource do let(:manager) do - FactoryGirl.create(:provider_embedded_ansible, :with_authentication, :default_organization => 1).managers.first + FactoryBot.create(:provider_embedded_ansible, :with_authentication, :default_organization => 1).managers.first end before do EvmSpecHelper.assign_embedded_ansible_role diff --git a/spec/models/manageiq/providers/embedded_ansible/automation_manager/configuration_script_spec.rb b/spec/models/manageiq/providers/embedded_ansible/automation_manager/configuration_script_spec.rb index 054e93236c6..3a74e52a0ee 100644 --- a/spec/models/manageiq/providers/embedded_ansible/automation_manager/configuration_script_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/automation_manager/configuration_script_spec.rb @@ -1,7 +1,7 @@ describe ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ConfigurationScript do - let(:provider_with_authentication) { FactoryGirl.create(:provider_embedded_ansible, :with_authentication) } + let(:provider_with_authentication) { FactoryBot.create(:provider_embedded_ansible, :with_authentication) } let(:manager_with_authentication) { provider_with_authentication.managers.first } - let(:manager_with_configuration_scripts) { FactoryGirl.create(:embedded_automation_manager_ansible, :provider, :configuration_script) } + let(:manager_with_configuration_scripts) { FactoryBot.create(:embedded_automation_manager_ansible, :provider, :configuration_script) } before do EvmSpecHelper.assign_embedded_ansible_role diff --git a/spec/models/manageiq/providers/embedded_ansible/automation_manager/credential_spec.rb b/spec/models/manageiq/providers/embedded_ansible/automation_manager/credential_spec.rb index 8e07f709b4e..b9d135c0a8f 100644 --- a/spec/models/manageiq/providers/embedded_ansible/automation_manager/credential_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/automation_manager/credential_spec.rb @@ -1,6 +1,6 @@ describe ManageIQ::Providers::EmbeddedAnsible::AutomationManager::ScmCredential do let(:manager) do - FactoryGirl.create(:provider_embedded_ansible, :with_authentication, :default_organization => 1).managers.first + FactoryBot.create(:provider_embedded_ansible, :with_authentication, :default_organization => 1).managers.first end before do diff --git a/spec/models/manageiq/providers/embedded_ansible/automation_manager/job_spec.rb b/spec/models/manageiq/providers/embedded_ansible/automation_manager/job_spec.rb index 02c85f7266c..28c12fb3ae8 100644 --- a/spec/models/manageiq/providers/embedded_ansible/automation_manager/job_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/automation_manager/job_spec.rb @@ -1,5 +1,5 @@ describe ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Job do - let(:job) { FactoryGirl.create(:embedded_ansible_job) } + let(:job) { FactoryBot.create(:embedded_ansible_job) } before do region = MiqRegion.seed diff --git a/spec/models/manageiq/providers/embedded_ansible/automation_manager/playbook_runner_spec.rb b/spec/models/manageiq/providers/embedded_ansible/automation_manager/playbook_runner_spec.rb index e4434146f09..f444423ae29 100644 --- a/spec/models/manageiq/providers/embedded_ansible/automation_manager/playbook_runner_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/automation_manager/playbook_runner_spec.rb @@ -1,6 +1,6 @@ describe ManageIQ::Providers::EmbeddedAnsible::AutomationManager::PlaybookRunner do - let(:manager) { FactoryGirl.create(:embedded_automation_manager_ansible) } - let(:playbook) { FactoryGirl.create(:embedded_playbook, :manager => manager) } + let(:manager) { FactoryBot.create(:embedded_automation_manager_ansible) } + let(:playbook) { FactoryBot.create(:embedded_playbook, :manager => manager) } subject { ManageIQ::Providers::EmbeddedAnsible::AutomationManager::PlaybookRunner.create_job(options.merge(:playbook_id => playbook.id)) } describe '#start' do diff --git a/spec/models/manageiq/providers/embedded_ansible/automation_manager/playbook_spec.rb b/spec/models/manageiq/providers/embedded_ansible/automation_manager/playbook_spec.rb index 70f0908aa1c..e26f8625a6c 100644 --- a/spec/models/manageiq/providers/embedded_ansible/automation_manager/playbook_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/automation_manager/playbook_spec.rb @@ -1,8 +1,8 @@ describe ManageIQ::Providers::EmbeddedAnsible::AutomationManager::Playbook do - let(:manager) { FactoryGirl.create(:embedded_automation_manager_ansible) } - let(:auth_one) { FactoryGirl.create(:embedded_ansible_credential, :manager_ref => '6') } - let(:auth_two) { FactoryGirl.create(:embedded_ansible_credential, :manager_ref => '8') } - subject { FactoryGirl.create(:embedded_playbook, :manager => manager) } + let(:manager) { FactoryBot.create(:embedded_automation_manager_ansible) } + let(:auth_one) { FactoryBot.create(:embedded_ansible_credential, :manager_ref => '6') } + let(:auth_two) { FactoryBot.create(:embedded_ansible_credential, :manager_ref => '8') } + subject { FactoryBot.create(:embedded_playbook, :manager => manager) } describe '#run' do it 'delegates request to playbook runner' do diff --git a/spec/models/manageiq/providers/embedded_ansible/automation_manager_spec.rb b/spec/models/manageiq/providers/embedded_ansible/automation_manager_spec.rb index a6655f734d8..c17438080ca 100644 --- a/spec/models/manageiq/providers/embedded_ansible/automation_manager_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/automation_manager_spec.rb @@ -2,7 +2,7 @@ it_behaves_like 'ansible automation_manager' context 'catalog types' do - let(:ems) { FactoryGirl.create(:embedded_automation_manager) } + let(:ems) { FactoryBot.create(:embedded_automation_manager) } it "#supported_catalog_types" do expect(ems.supported_catalog_types).to eq(%w(generic_ansible_playbook)) diff --git a/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb b/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb index 4a66a4abd97..2f86ddbc51c 100644 --- a/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb +++ b/spec/models/manageiq/providers/embedded_ansible/provider_spec.rb @@ -1,7 +1,7 @@ describe ManageIQ::Providers::EmbeddedAnsible::Provider do - subject { FactoryGirl.create(:provider_embedded_ansible) } + subject { FactoryBot.create(:provider_embedded_ansible) } - let(:miq_server) { FactoryGirl.create(:miq_server) } + let(:miq_server) { FactoryBot.create(:miq_server) } before do EvmSpecHelper.assign_embedded_ansible_role(miq_server) diff --git a/spec/models/manageiq/providers/ems_refresh_workflow_spec.rb b/spec/models/manageiq/providers/ems_refresh_workflow_spec.rb index 4624eab7fa6..d9207089b51 100644 --- a/spec/models/manageiq/providers/ems_refresh_workflow_spec.rb +++ b/spec/models/manageiq/providers/ems_refresh_workflow_spec.rb @@ -101,7 +101,7 @@ context "refresh" do before do - vm = FactoryGirl.create(:vm) + vm = FactoryBot.create(:vm) options = { :target_id => vm.id, @@ -113,7 +113,7 @@ end it 'sets the refresh_task_ids in the context' do - refresh_task = FactoryGirl.create(:miq_task) + refresh_task = FactoryBot.create(:miq_task) expect(EmsRefresh).to receive(:queue_refresh_task).and_return([refresh_task.id]) expect(@job).to receive(:queue_signal).with(:poll_refresh) @@ -140,7 +140,7 @@ end it 'with a refresh task that is still running' do - refresh_task = FactoryGirl.create(:miq_task) + refresh_task = FactoryBot.create(:miq_task) @job.context[:refresh_task_ids] = [refresh_task.id] expect(@job).to receive(:queue_signal).with(:poll_refresh, anything) @@ -149,7 +149,7 @@ end it 'with a refresh task that failed' do - refresh_task = FactoryGirl.create(:miq_task, :status => MiqTask::STATUS_ERROR) + refresh_task = FactoryBot.create(:miq_task, :status => MiqTask::STATUS_ERROR) @job.context[:refresh_task_ids] = [refresh_task.id] expect(@job).to receive(:queue_signal).with(:post_refresh) @@ -161,7 +161,7 @@ end it 'with a refresh task that finished' do - refresh_task = FactoryGirl.create(:miq_task, :state => MiqTask::STATE_FINISHED) + refresh_task = FactoryBot.create(:miq_task, :state => MiqTask::STATE_FINISHED) @job.context[:refresh_task_ids] = [refresh_task.id] expect(@job).to receive(:queue_signal).with(:post_refresh) diff --git a/spec/models/manageiq/providers/infra_manager/template_spec.rb b/spec/models/manageiq/providers/infra_manager/template_spec.rb index 3e14dc9adf0..4627f24b7d0 100644 --- a/spec/models/manageiq/providers/infra_manager/template_spec.rb +++ b/spec/models/manageiq/providers/infra_manager/template_spec.rb @@ -9,7 +9,7 @@ end it "with a host relationship" do - subject.host = FactoryGirl.build(:host) + subject.host = FactoryBot.build(:host) expect(subject).to receive(:reconnect_events) expect(subject).to receive(:classify_with_parent_folder_path) diff --git a/spec/models/manageiq/providers/infra_manager/vm_or_template_spec.rb b/spec/models/manageiq/providers/infra_manager/vm_or_template_spec.rb index 97327c6274c..1253a5f24f8 100644 --- a/spec/models/manageiq/providers/infra_manager/vm_or_template_spec.rb +++ b/spec/models/manageiq/providers/infra_manager/vm_or_template_spec.rb @@ -1,10 +1,10 @@ describe ManageIQ::Providers::InfraManager::VmOrTemplate do describe "#all" do it "scopes" do - vm = FactoryGirl.create(:vm_vmware) - t = FactoryGirl.create(:template_vmware) - FactoryGirl.create(:vm_openstack) - FactoryGirl.create(:template_openstack) + vm = FactoryBot.create(:vm_vmware) + t = FactoryBot.create(:template_vmware) + FactoryBot.create(:vm_openstack) + FactoryBot.create(:template_openstack) expect(described_class.all).to match_array([vm, t]) end @@ -12,15 +12,15 @@ describe "#all_archived" do it "scopes" do - ems = FactoryGirl.create(:ems_vmware) - vm = FactoryGirl.create(:vm_vmware) - t = FactoryGirl.create(:template_vmware) + ems = FactoryBot.create(:ems_vmware) + vm = FactoryBot.create(:vm_vmware) + t = FactoryBot.create(:template_vmware) # non archived - FactoryGirl.create(:vm_vmware, :ext_management_system => ems) - FactoryGirl.create(:template_vmware, :ext_management_system => ems) + FactoryBot.create(:vm_vmware, :ext_management_system => ems) + FactoryBot.create(:template_vmware, :ext_management_system => ems) # non infra - FactoryGirl.create(:vm_openstack) - FactoryGirl.create(:template_openstack) + FactoryBot.create(:vm_openstack) + FactoryBot.create(:template_openstack) expect(described_class.archived).to match_array([vm, t]) end diff --git a/spec/models/manageiq/providers/infra_manager/vm_spec.rb b/spec/models/manageiq/providers/infra_manager/vm_spec.rb index 7f7e49f1202..694e4af4497 100644 --- a/spec/models/manageiq/providers/infra_manager/vm_spec.rb +++ b/spec/models/manageiq/providers/infra_manager/vm_spec.rb @@ -9,7 +9,7 @@ end it "with a host relationship" do - subject.host = FactoryGirl.build(:host) + subject.host = FactoryBot.build(:host) expect(subject).to receive(:reconnect_events) expect(subject).to receive(:classify_with_parent_folder_path) diff --git a/spec/models/manageiq/providers/inventory/persister/builder_spec.rb b/spec/models/manageiq/providers/inventory/persister/builder_spec.rb index 17b3d641516..2b2ac764dfc 100644 --- a/spec/models/manageiq/providers/inventory/persister/builder_spec.rb +++ b/spec/models/manageiq/providers/inventory/persister/builder_spec.rb @@ -3,10 +3,10 @@ describe ManageIQ::Providers::Inventory::Persister::Builder do before :each do - @zone = FactoryGirl.create(:zone) - @ems = FactoryGirl.create(:ems_cloud, + @zone = FactoryBot.create(:zone) + @ems = FactoryBot.create(:ems_cloud, :zone => @zone, - :network_manager => FactoryGirl.create(:ems_network, :zone => @zone)) + :network_manager => FactoryBot.create(:ems_network, :zone => @zone)) @persister = create_persister end diff --git a/spec/models/manageiq/providers/inventory/persister/finders_spec.rb b/spec/models/manageiq/providers/inventory/persister/finders_spec.rb index 2508666baf2..ffaff178994 100644 --- a/spec/models/manageiq/providers/inventory/persister/finders_spec.rb +++ b/spec/models/manageiq/providers/inventory/persister/finders_spec.rb @@ -11,10 +11,10 @@ ###################################################################################################################### # before do - @zone = FactoryGirl.create(:zone) - @ems = FactoryGirl.create(:ems_cloud, + @zone = FactoryBot.create(:zone) + @ems = FactoryBot.create(:ems_cloud, :zone => @zone, - :network_manager => FactoryGirl.create(:ems_network, :zone => @zone)) + :network_manager => FactoryBot.create(:ems_network, :zone => @zone)) allow(@ems.class).to receive(:ems_type).and_return(:mock) allow(Settings.ems_refresh).to receive(:mock).and_return({}) diff --git a/spec/models/manageiq/providers/inventory/persister/helpers/spec_mocked_data.rb b/spec/models/manageiq/providers/inventory/persister/helpers/spec_mocked_data.rb index bd34a3ac09b..c268762ec7f 100644 --- a/spec/models/manageiq/providers/inventory/persister/helpers/spec_mocked_data.rb +++ b/spec/models/manageiq/providers/inventory/persister/helpers/spec_mocked_data.rb @@ -1,28 +1,28 @@ module SpecMockedData def initialize_mocked_records - @flavor1 = FactoryGirl.create(:flavor, flavor_data(1).merge(:ext_management_system => @ems)) - @flavor2 = FactoryGirl.create(:flavor, flavor_data(2).merge(:ext_management_system => @ems)) - @flavor3 = FactoryGirl.create(:flavor, flavor_data(3).merge(:ext_management_system => @ems)) + @flavor1 = FactoryBot.create(:flavor, flavor_data(1).merge(:ext_management_system => @ems)) + @flavor2 = FactoryBot.create(:flavor, flavor_data(2).merge(:ext_management_system => @ems)) + @flavor3 = FactoryBot.create(:flavor, flavor_data(3).merge(:ext_management_system => @ems)) - @image1 = FactoryGirl.create(:miq_template, image_data(1).merge(:ext_management_system => @ems)) - @image2 = FactoryGirl.create(:miq_template, image_data(2).merge(:ext_management_system => @ems)) - @image3 = FactoryGirl.create(:miq_template, image_data(3).merge(:ext_management_system => @ems)) + @image1 = FactoryBot.create(:miq_template, image_data(1).merge(:ext_management_system => @ems)) + @image2 = FactoryBot.create(:miq_template, image_data(2).merge(:ext_management_system => @ems)) + @image3 = FactoryBot.create(:miq_template, image_data(3).merge(:ext_management_system => @ems)) - @image_hardware1 = FactoryGirl.create( + @image_hardware1 = FactoryBot.create( :hardware, image_hardware_data(1).merge( :guest_os => "linux_generic_1", :vm_or_template => @image1 ) ) - @image_hardware2 = FactoryGirl.create( + @image_hardware2 = FactoryBot.create( :hardware, image_hardware_data(2).merge( :guest_os => "linux_generic_2", :vm_or_template => @image2 ) ) - @image_hardware3 = FactoryGirl.create( + @image_hardware3 = FactoryBot.create( :hardware, image_hardware_data(3).merge( :guest_os => "linux_generic_3", @@ -30,12 +30,12 @@ def initialize_mocked_records ) ) - @key_pair1 = FactoryGirl.create(:auth_key_pair_cloud, key_pair_data(1).merge(:resource => @ems)) - @key_pair12 = FactoryGirl.create(:auth_key_pair_cloud, key_pair_data(12).merge(:resource => @ems)) - @key_pair2 = FactoryGirl.create(:auth_key_pair_cloud, key_pair_data(2).merge(:resource => @ems)) - @key_pair3 = FactoryGirl.create(:auth_key_pair_cloud, key_pair_data(3).merge(:resource => @ems)) + @key_pair1 = FactoryBot.create(:auth_key_pair_cloud, key_pair_data(1).merge(:resource => @ems)) + @key_pair12 = FactoryBot.create(:auth_key_pair_cloud, key_pair_data(12).merge(:resource => @ems)) + @key_pair2 = FactoryBot.create(:auth_key_pair_cloud, key_pair_data(2).merge(:resource => @ems)) + @key_pair3 = FactoryBot.create(:auth_key_pair_cloud, key_pair_data(3).merge(:resource => @ems)) - @vm1 = FactoryGirl.create( + @vm1 = FactoryBot.create( :vm_cloud, vm_data(1).merge( :flavor => @flavor_1, @@ -45,7 +45,7 @@ def initialize_mocked_records :ext_management_system => @ems, ) ) - @vm12 = FactoryGirl.create( + @vm12 = FactoryBot.create( :vm_cloud, vm_data(12).merge( :flavor => @flavor1, @@ -55,7 +55,7 @@ def initialize_mocked_records :ext_management_system => @ems, ) ) - @vm2 = FactoryGirl.create( + @vm2 = FactoryBot.create( :vm_cloud, vm_data(2).merge( :flavor => @flavor2, @@ -65,7 +65,7 @@ def initialize_mocked_records :ext_management_system => @ems, ) ) - @vm4 = FactoryGirl.create( + @vm4 = FactoryBot.create( :vm_cloud, vm_data(4).merge( :location => 'default_value_unknown', @@ -73,21 +73,21 @@ def initialize_mocked_records ) ) - @hardware1 = FactoryGirl.create( + @hardware1 = FactoryBot.create( :hardware, hardware_data(1).merge( :guest_os => @image1.hardware.guest_os, :vm_or_template => @vm1 ) ) - @hardware12 = FactoryGirl.create( + @hardware12 = FactoryBot.create( :hardware, hardware_data(12).merge( :guest_os => @image1.hardware.guest_os, :vm_or_template => @vm12 ) ) - @hardware2 = FactoryGirl.create( + @hardware2 = FactoryBot.create( :hardware, hardware_data(2).merge( :guest_os => @image2.hardware.guest_os, @@ -95,128 +95,128 @@ def initialize_mocked_records ) ) - @disk1 = FactoryGirl.create( + @disk1 = FactoryBot.create( :disk, disk_data(1).merge( :hardware => @hardware1, ) ) - @disk12 = FactoryGirl.create( + @disk12 = FactoryBot.create( :disk, disk_data(12).merge( :hardware => @hardware12, ) ) - @disk13 = FactoryGirl.create( + @disk13 = FactoryBot.create( :disk, disk_data(13).merge( :hardware => @hardware12, ) ) - @disk2 = FactoryGirl.create( + @disk2 = FactoryBot.create( :disk, disk_data(2).merge( :hardware => @hardware2, ) ) - @public_network1 = FactoryGirl.create( + @public_network1 = FactoryBot.create( :network, public_network_data(1).merge( :hardware => @hardware1, ) ) - @public_network12 = FactoryGirl.create( + @public_network12 = FactoryBot.create( :network, public_network_data(12).merge( :hardware => @hardware12, ) ) - @public_network13 = FactoryGirl.create( + @public_network13 = FactoryBot.create( :network, public_network_data(13).merge( :hardware => @hardware12, :description => "public_2" ) ) - @public_network2 = FactoryGirl.create( + @public_network2 = FactoryBot.create( :network, public_network_data(2).merge( :hardware => @hardware2, ) ) - @network_port1 = FactoryGirl.create( + @network_port1 = FactoryBot.create( :network_port, network_port_data(1).merge( :device => @vm1 ) ) - @network_port12 = FactoryGirl.create( + @network_port12 = FactoryBot.create( :network_port, network_port_data(12).merge( :device => @vm1 ) ) - @network_port2 = FactoryGirl.create( + @network_port2 = FactoryBot.create( :network_port, network_port_data(2).merge( :device => @vm2 ) ) - @network_port4 = FactoryGirl.create( + @network_port4 = FactoryBot.create( :network_port, network_port_data(4).merge( :device => @vm4 ) ) - @orchestration_stack_0_1 = FactoryGirl.create( + @orchestration_stack_0_1 = FactoryBot.create( :orchestration_stack, orchestration_stack_data("0_1").merge( :parent => nil ) ) - @orchestration_stack_1_11 = FactoryGirl.create( + @orchestration_stack_1_11 = FactoryBot.create( :orchestration_stack, orchestration_stack_data("1_11").merge( :parent => @orchestration_stack_0_1 ) ) - @orchestration_stack_1_12 = FactoryGirl.create( + @orchestration_stack_1_12 = FactoryBot.create( :orchestration_stack, orchestration_stack_data("1_12").merge( :parent => @orchestration_stack_0_1 ) ) - @orchestration_stack_resource_1_11_1 = FactoryGirl.create( + @orchestration_stack_resource_1_11_1 = FactoryBot.create( :orchestration_stack_resource, orchestration_stack_resource_data("1_11_1").merge( :stack => @orchestration_stack_1_11 ) ) - @orchestration_stack_resource_1_11_2 = FactoryGirl.create( + @orchestration_stack_resource_1_11_2 = FactoryBot.create( :orchestration_stack_resource, orchestration_stack_resource_data("1_11_2").merge( :stack => @orchestration_stack_1_11 ) ) - @orchestration_stack_resource_1_12_1 = FactoryGirl.create( + @orchestration_stack_resource_1_12_1 = FactoryBot.create( :orchestration_stack_resource, orchestration_stack_resource_data("1_12_1").merge( :stack => @orchestration_stack_1_12 ) ) - @orchestration_stack_resource_1_12_2 = FactoryGirl.create( + @orchestration_stack_resource_1_12_2 = FactoryBot.create( :orchestration_stack_resource, orchestration_stack_resource_data("1_12_2").merge( :stack => @orchestration_stack_1_12 diff --git a/spec/models/manageiq/providers/inventory/persister/local_db_finders_spec.rb b/spec/models/manageiq/providers/inventory/persister/local_db_finders_spec.rb index 7a014cea17f..81d50090d74 100644 --- a/spec/models/manageiq/providers/inventory/persister/local_db_finders_spec.rb +++ b/spec/models/manageiq/providers/inventory/persister/local_db_finders_spec.rb @@ -14,10 +14,10 @@ ###################################################################################################################### # before do - @zone = FactoryGirl.create(:zone) - @ems = FactoryGirl.create(:ems_cloud, + @zone = FactoryBot.create(:zone) + @ems = FactoryBot.create(:ems_cloud, :zone => @zone, - :network_manager => FactoryGirl.create(:ems_network, :zone => @zone)) + :network_manager => FactoryBot.create(:ems_network, :zone => @zone)) allow(@ems.class).to receive(:ems_type).and_return(:mock) allow(Settings.ems_refresh).to receive(:mock).and_return({}) diff --git a/spec/models/manageiq/providers/inventory/persister/serializing_spec.rb b/spec/models/manageiq/providers/inventory/persister/serializing_spec.rb index e0ee3a7873c..b8e9ad0df67 100644 --- a/spec/models/manageiq/providers/inventory/persister/serializing_spec.rb +++ b/spec/models/manageiq/providers/inventory/persister/serializing_spec.rb @@ -11,10 +11,10 @@ ###################################################################################################################### # before do - @zone = FactoryGirl.create(:zone) - @ems = FactoryGirl.create(:ems_cloud, + @zone = FactoryBot.create(:zone) + @ems = FactoryBot.create(:ems_cloud, :zone => @zone, - :network_manager => FactoryGirl.create(:ems_network, :zone => @zone)) + :network_manager => FactoryBot.create(:ems_network, :zone => @zone)) allow(@ems.class).to receive(:ems_type).and_return(:mock) allow(Settings.ems_refresh).to receive(:mock).and_return({}) @@ -60,8 +60,8 @@ def populate_test_data(persister) # Add some data into the DB - FactoryGirl.create(:vm, vm_data(20)) - FactoryGirl.create(:vm, vm_data(21)) + FactoryBot.create(:vm, vm_data(20)) + FactoryBot.create(:vm, vm_data(21)) @image_data_1 = image_data(1) @image_hardware_data_1 = image_hardware_data(1).merge( diff --git a/spec/models/manageiq/providers/native_operation_workflow_spec.rb b/spec/models/manageiq/providers/native_operation_workflow_spec.rb index 2c31f014db2..d0faae4726f 100644 --- a/spec/models/manageiq/providers/native_operation_workflow_spec.rb +++ b/spec/models/manageiq/providers/native_operation_workflow_spec.rb @@ -1,7 +1,7 @@ describe ManageIQ::Providers::NativeOperationWorkflow do context "post_refresh" do before do - vm = FactoryGirl.create(:vm) + vm = FactoryBot.create(:vm) options = { :target_id => vm.id, diff --git a/spec/models/manageiq/providers/physical_infra_manager/physical_infra_manager_spec.rb b/spec/models/manageiq/providers/physical_infra_manager/physical_infra_manager_spec.rb index 2c2e7c16200..a6508b9520c 100644 --- a/spec/models/manageiq/providers/physical_infra_manager/physical_infra_manager_spec.rb +++ b/spec/models/manageiq/providers/physical_infra_manager/physical_infra_manager_spec.rb @@ -4,8 +4,8 @@ end it 'will count physical servers' do - ps = FactoryGirl.create(:physical_server) - pim = FactoryGirl.create(:ems_physical_infra, + ps = FactoryBot.create(:physical_server) + pim = FactoryBot.create(:ems_physical_infra, :name => "LXCA", :hostname => "0.0.0.0") @@ -14,9 +14,9 @@ end it 'will count hosts' do - ps = FactoryGirl.create(:physical_server) - host = FactoryGirl.create(:host) - pim = FactoryGirl.create(:ems_physical_infra, + ps = FactoryBot.create(:physical_server) + host = FactoryBot.create(:host) + pim = FactoryBot.create(:ems_physical_infra, :name => "LXCA", :hostname => "0.0.0.0") @@ -26,10 +26,10 @@ end it 'will count vms' do - ps = FactoryGirl.create(:physical_server) - host = FactoryGirl.create(:host) - vm = FactoryGirl.create(:vm) - pim = FactoryGirl.create(:ems_physical_infra, + ps = FactoryBot.create(:physical_server) + host = FactoryBot.create(:host) + vm = FactoryBot.create(:vm) + pim = FactoryBot.create(:ems_physical_infra, :name => "LXCA", :hostname => "0.0.0.0") @@ -40,21 +40,21 @@ end it 'will check supports_console returns false' do - ps = FactoryGirl.create(:ems_physical_infra, + ps = FactoryBot.create(:ems_physical_infra, :name => "LXCA", :hostname => "0.0.0.0") expect(ps.supports_console?).to be(false) end it 'will return false if console is not supported' do - ps = FactoryGirl.create(:ems_physical_infra, + ps = FactoryBot.create(:ems_physical_infra, :name => "LXCA", :hostname => "0.0.0.0") expect(ps.console_supported?).to be(false) end it 'will raise exception for cnosle url if console is not supported' do - ps = FactoryGirl.create(:ems_physical_infra, + ps = FactoryBot.create(:ems_physical_infra, :name => "LXCA", :hostname => "0.0.0.0") expect { ps.console_url }.to raise_error(MiqException::Error) diff --git a/spec/models/message_timeout_handling_spec.rb b/spec/models/message_timeout_handling_spec.rb index 21eb59426e2..7d301c5eb32 100644 --- a/spec/models/message_timeout_handling_spec.rb +++ b/spec/models/message_timeout_handling_spec.rb @@ -3,11 +3,11 @@ @guid = SecureRandom.uuid allow(MiqServer).to receive(:my_guid).and_return(@guid) - @zone = FactoryGirl.create(:zone) - @miq_server = FactoryGirl.create(:miq_server, :guid => @guid, :zone => @zone) + @zone = FactoryBot.create(:zone) + @miq_server = FactoryBot.create(:miq_server, :guid => @guid, :zone => @zone) allow(MiqServer).to receive(:my_server).and_return(@miq_server) - @worker = FactoryGirl.create(:vmware_refresh_worker, :miq_server_id => @miq_server.id) + @worker = FactoryBot.create(:vmware_refresh_worker, :miq_server_id => @miq_server.id) end context "A Worker Handling a Message with a timeout of 3600 seconds" do diff --git a/spec/models/metering_container_image_spec.rb b/spec/models/metering_container_image_spec.rb index d24679b7d02..8618fac48c0 100644 --- a/spec/models/metering_container_image_spec.rb +++ b/spec/models/metering_container_image_spec.rb @@ -10,7 +10,7 @@ let(:month_beginning) { ts.beginning_of_month.utc } let(:month_end) { ts.end_of_month.utc } let(:hours_in_month) { Time.days_in_month(month_beginning.month, month_beginning.year) * 24 } - let(:ems) { FactoryGirl.create(:ems_openshift) } + let(:ems) { FactoryBot.create(:ems_openshift) } let(:metric_rollup_params) { {:parent_ems_id => ems.id, :tag_names => ""} } before do @@ -22,13 +22,13 @@ MiqEnterprise.seed EvmSpecHelper.create_guid_miq_server_zone - @node = FactoryGirl.create(:container_node, :name => "node") - @image = FactoryGirl.create(:container_image, :ext_management_system => ems) - @label = FactoryGirl.build(:custom_attribute, :name => "version/1.2/_label-1", :value => "test/1.0.0 rc_2", :section => 'docker_labels') - @project = FactoryGirl.create(:container_project, :name => "my project", :ext_management_system => ems) - @group = FactoryGirl.create(:container_group, :ext_management_system => ems, :container_project => @project, + @node = FactoryBot.create(:container_node, :name => "node") + @image = FactoryBot.create(:container_image, :ext_management_system => ems) + @label = FactoryBot.build(:custom_attribute, :name => "version/1.2/_label-1", :value => "test/1.0.0 rc_2", :section => 'docker_labels') + @project = FactoryBot.create(:container_project, :name => "my project", :ext_management_system => ems) + @group = FactoryBot.create(:container_group, :ext_management_system => ems, :container_project => @project, :container_node => @node) - @container = FactoryGirl.create(:kubernetes_container, :container_group => @group, :container_image => @image, + @container = FactoryBot.create(:kubernetes_container, :container_group => @group, :container_image => @image, :limit_memory_bytes => 1.megabytes, :limit_cpu_cores => 1.0) Timecop.travel(report_run_time) @@ -45,7 +45,7 @@ add_metric_rollups_for(@container, month_beginning...month_end, 12.hours, metric_rollup_params) Range.new(month_beginning, month_end, true).step_value(12.hours).each do |time| - @container.vim_performance_states << FactoryGirl.create(:vim_performance_state, :timestamp => time, :image_tag_names => "environment/prod") + @container.vim_performance_states << FactoryBot.create(:vim_performance_state, :timestamp => time, :image_tag_names => "environment/prod") end end diff --git a/spec/models/metering_container_project_spec.rb b/spec/models/metering_container_project_spec.rb index 4825d1c8a36..8df99c1c3b4 100644 --- a/spec/models/metering_container_project_spec.rb +++ b/spec/models/metering_container_project_spec.rb @@ -1,7 +1,7 @@ describe MeteringContainerProject do include Spec::Support::ChargebackHelper - let(:admin) { FactoryGirl.create(:user_admin) } + let(:admin) { FactoryBot.create(:user_admin) } let(:base_options) do {:interval_size => 2, :end_interval_offset => 0, @@ -19,12 +19,12 @@ let(:month_beginning) { ts.beginning_of_month.utc } let(:month_end) { ts.end_of_month.utc } let(:count_of_metric_rollup) { MetricRollup.where(:timestamp => month_beginning...month_end).count } - let(:ems) { FactoryGirl.create(:ems_vmware) } - let(:project) { FactoryGirl.create(:container_project, :name => "my project", :ext_management_system => ems, :created_on => month_beginning) } - let(:hardware) { FactoryGirl.create(:hardware, :memory_mb => 8124, :cpu_total_cores => 1, :cpu_speed => 9576) } - let(:host) { FactoryGirl.create(:host, :storages => [storage], :hardware => hardware, :vms => [vm]) } - let(:storage) { FactoryGirl.create(:storage_target_vmware) } - let(:ems_cluster) { FactoryGirl.create(:ems_cluster, :ext_management_system => ems, :hosts => [host]) } + let(:ems) { FactoryBot.create(:ems_vmware) } + let(:project) { FactoryBot.create(:container_project, :name => "my project", :ext_management_system => ems, :created_on => month_beginning) } + let(:hardware) { FactoryBot.create(:hardware, :memory_mb => 8124, :cpu_total_cores => 1, :cpu_speed => 9576) } + let(:host) { FactoryBot.create(:host, :storages => [storage], :hardware => hardware, :vms => [vm]) } + let(:storage) { FactoryBot.create(:storage_target_vmware) } + let(:ems_cluster) { FactoryBot.create(:ems_cluster, :ext_management_system => ems, :hosts => [host]) } before do MiqRegion.seed diff --git a/spec/models/metering_vm_spec.rb b/spec/models/metering_vm_spec.rb index dd09697a480..e5b7db00bb2 100644 --- a/spec/models/metering_vm_spec.rb +++ b/spec/models/metering_vm_spec.rb @@ -1,7 +1,7 @@ describe MeteringVm do include Spec::Support::ChargebackHelper - let(:admin) { FactoryGirl.create(:user_admin) } + let(:admin) { FactoryBot.create(:user_admin) } let(:base_options) do {:interval_size => 2, :end_interval_offset => 0, @@ -25,12 +25,12 @@ let(:month_end) { ts.end_of_month.utc } let(:hours_in_month) { Time.days_in_month(month_beginning.month, month_beginning.year) * 24 } let(:count_of_metric_rollup) { MetricRollup.where(:timestamp => month_beginning...month_end).count } - let(:ems) { FactoryGirl.create(:ems_vmware) } - let(:vm) { FactoryGirl.create(:vm_vmware, :name => "test_vm", :evm_owner => admin, :ems_ref => "ems_ref", :created_on => month_beginning) } - let(:hardware) { FactoryGirl.create(:hardware, :memory_mb => 8124, :cpu_total_cores => 1, :cpu_speed => 9576) } - let(:host) { FactoryGirl.create(:host, :storages => [storage], :hardware => hardware, :vms => [vm]) } - let(:storage) { FactoryGirl.create(:storage_target_vmware) } - let(:ems_cluster) { FactoryGirl.create(:ems_cluster, :ext_management_system => ems, :hosts => [host]) } + let(:ems) { FactoryBot.create(:ems_vmware) } + let(:vm) { FactoryBot.create(:vm_vmware, :name => "test_vm", :evm_owner => admin, :ems_ref => "ems_ref", :created_on => month_beginning) } + let(:hardware) { FactoryBot.create(:hardware, :memory_mb => 8124, :cpu_total_cores => 1, :cpu_speed => 9576) } + let(:host) { FactoryBot.create(:host, :storages => [storage], :hardware => hardware, :vms => [vm]) } + let(:storage) { FactoryBot.create(:storage_target_vmware) } + let(:ems_cluster) { FactoryBot.create(:ems_cluster, :ext_management_system => ems, :hosts => [host]) } before do MiqRegion.seed @@ -62,21 +62,21 @@ let(:metering_used_hours) { 24 } let(:hardware) do - FactoryGirl.create(:hardware, + FactoryBot.create(:hardware, :cpu_total_cores => cores, :memory_mb => mem_mb, - :disks => [FactoryGirl.create(:disk, :size => disk_b)]) + :disks => [FactoryBot.create(:disk, :size => disk_b)]) end context 'for SCVMM (hyper-v)' do before do - cat = FactoryGirl.create(:classification, :description => "Environment", :name => "environment", :single_value => true, :show => true) - FactoryGirl.create(:classification, :name => "prod", :description => "Production", :parent_id => cat.id) + cat = FactoryBot.create(:classification, :description => "Environment", :name => "environment", :single_value => true, :show => true) + FactoryBot.create(:classification, :name => "prod", :description => "Production", :parent_id => cat.id) @tag = Tag.find_by(:name => "/managed/environment/prod") end let!(:vm1) do - vm = FactoryGirl.create(:vm_microsoft, :hardware => hardware, :created_on => report_run_time - 1.day) + vm = FactoryBot.create(:vm_microsoft, :hardware => hardware, :created_on => report_run_time - 1.day) vm.tag_with(@tag.name, :ns => '*') vm end diff --git a/spec/models/metric/capture_spec.rb b/spec/models/metric/capture_spec.rb index 59844611f0e..eda5acf3deb 100644 --- a/spec/models/metric/capture_spec.rb +++ b/spec/models/metric/capture_spec.rb @@ -1,6 +1,6 @@ describe Metric::Capture do describe ".alert_capture_threshold" do - let(:target) { FactoryGirl.build(:host_vmware) } + let(:target) { FactoryBot.build(:host_vmware) } it "parses fixed num" do stub_performance_settings(:capture_threshold_with_alerts => {:host => 4}) @@ -26,7 +26,7 @@ end describe ".standard_capture_threshold" do - let(:host) { FactoryGirl.build(:host_vmware) } + let(:host) { FactoryBot.build(:host_vmware) } it "parses fixed num" do stub_performance_settings(:capture_threshold => {:host => 4}) @@ -53,9 +53,9 @@ context ".perf_capture_health_check" do let(:miq_server) { EvmSpecHelper.local_miq_server } - let(:ems) { FactoryGirl.create(:ems_vmware, :zone => miq_server.zone) } - let(:vm) { FactoryGirl.create(:vm_perf, :ext_management_system => ems) } - let(:vm2) { FactoryGirl.create(:vm_perf, :ext_management_system => ems) } + let(:ems) { FactoryBot.create(:ems_vmware, :zone => miq_server.zone) } + let(:vm) { FactoryBot.create(:vm_perf, :ext_management_system => ems) } + let(:vm2) { FactoryBot.create(:vm_perf, :ext_management_system => ems) } it "should queue up realtime capture for vm" do vm.perf_capture_realtime_now @@ -77,7 +77,7 @@ ) end - let(:target) { FactoryGirl.build(:host_vmware) } + let(:target) { FactoryBot.build(:host_vmware) } context "with a host with alerts" do before do diff --git a/spec/models/metric/ci_mixin/capture_spec.rb b/spec/models/metric/ci_mixin/capture_spec.rb index 2234c979dc8..773d70d34a7 100644 --- a/spec/models/metric/ci_mixin/capture_spec.rb +++ b/spec/models/metric/ci_mixin/capture_spec.rb @@ -8,8 +8,8 @@ :list_meters => OpenstackApiResult.new((mock_meter_list.list_meters("resource_counters") + mock_meter_list.list_meters("metadata_counters")))) end - let(:ems_openstack) { FactoryGirl.create(:ems_openstack, :zone => zone) } - let(:vm) { FactoryGirl.create(:vm_perf_openstack, :ext_management_system => ems_openstack) } + let(:ems_openstack) { FactoryBot.create(:ems_openstack, :zone => zone) } + let(:vm) { FactoryBot.create(:vm_perf_openstack, :ext_management_system => ems_openstack) } # TODO: Don't hack this log stuff. This is difficult right now as some assertions # below are actually emitted by the provider. Not worth fixing right now. @@ -358,7 +358,7 @@ def verify_perf_capture_queue(last_perf_capture_on, total_queue_items) it "links supplied miq_task with queued item which allow to initialize MiqTask#started_on attribute" do MiqQueue.delete_all - task = FactoryGirl.create(:miq_task) + task = FactoryBot.create(:miq_task) vm.perf_capture_queue("realtime", :task_id => task.id) expect(MiqQueue.first.miq_task_id).to eq task.id end @@ -418,13 +418,13 @@ def verify_perf_capture_queue_historical(last_perf_capture_on, total_queue_items context "handles archived container entities" do it "get the correct queue name and zone from archived container entities" do - ems = FactoryGirl.create(:ems_openshift, :name => 'OpenShiftProvider') - group = FactoryGirl.create(:container_group, :name => "group", :ext_management_system => ems) - container = FactoryGirl.create(:container, + ems = FactoryBot.create(:ems_openshift, :name => 'OpenShiftProvider') + group = FactoryBot.create(:container_group, :name => "group", :ext_management_system => ems) + container = FactoryBot.create(:container, :name => "container", :container_group => group, :ext_management_system => ems) - project = FactoryGirl.create(:container_project, + project = FactoryBot.create(:container_project, :name => "project", :ext_management_system => ems) container.disconnect_inv diff --git a/spec/models/metric/ci_mixin_spec.rb b/spec/models/metric/ci_mixin_spec.rb index 0c9f01837e8..738e78156ba 100644 --- a/spec/models/metric/ci_mixin_spec.rb +++ b/spec/models/metric/ci_mixin_spec.rb @@ -1,6 +1,6 @@ describe Metric::CiMixin do context "with a Vm" do - let(:vm) { FactoryGirl.create(:vm_vmware) } + let(:vm) { FactoryBot.create(:vm_vmware) } context "#has_perf_data?" do it "without data" do @@ -8,7 +8,7 @@ end it "with data" do - FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => Time.now.utc) + FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => Time.now.utc) expect(vm.has_perf_data?).to be_truthy end end @@ -19,9 +19,9 @@ end it "with data" do - FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => 10.minutes.ago.utc) - FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => 5.minutes.ago.utc) - last = FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => Time.now.utc) + FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => 10.minutes.ago.utc) + FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => 5.minutes.ago.utc) + last = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => Time.now.utc) expect(vm.last_capture).to be_within(0.1).of last.timestamp end end @@ -32,9 +32,9 @@ end it "with data" do - first = FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => 10.minutes.ago.utc) - FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => 5.minutes.ago.utc) - FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => Time.now.utc) + first = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => 10.minutes.ago.utc) + FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => 5.minutes.ago.utc) + FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => Time.now.utc) expect(vm.first_capture).to be_within(0.1).of first.timestamp end end @@ -45,7 +45,7 @@ end it "with one record" do - first = FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => Time.now.utc) + first = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => Time.now.utc) actual = vm.first_and_last_capture expect(actual.length).to eq(2) expect(actual[0]).to be_within(0.1).of first.timestamp @@ -53,9 +53,9 @@ end it "with multiple records" do - first = FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => 10.minutes.ago.utc) - FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => 5.minutes.ago.utc) - last = FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => Time.now.utc) + first = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => 10.minutes.ago.utc) + FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => 5.minutes.ago.utc) + last = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :timestamp => Time.now.utc) actual = vm.first_and_last_capture expect(actual.length).to eq(2) expect(actual[0]).to be_within(0.1).of first.timestamp @@ -66,8 +66,8 @@ context "#supports_capture?" do context "with a VM" do - let(:unsupported_vm) { FactoryGirl.create(:vm_microsoft) } - let(:supported_vm) { FactoryGirl.create(:vm_vmware) } + let(:unsupported_vm) { FactoryBot.create(:vm_microsoft) } + let(:supported_vm) { FactoryBot.create(:vm_vmware) } it "correctly checks capture support" do expect(unsupported_vm.supports_capture?).to be_falsy @@ -76,8 +76,8 @@ end context "with a Host" do - let(:unsupported_host) { FactoryGirl.create(:host_microsoft) } - let(:supported_host) { FactoryGirl.create(:vm_vmware) } + let(:unsupported_host) { FactoryBot.create(:host_microsoft) } + let(:supported_host) { FactoryBot.create(:vm_vmware) } it "correctly checks capture support" do expect(unsupported_host.supports_capture?).to be_falsy diff --git a/spec/models/metric/common_spec.rb b/spec/models/metric/common_spec.rb index 3d7cef0a708..eab3921df61 100644 --- a/spec/models/metric/common_spec.rb +++ b/spec/models/metric/common_spec.rb @@ -1,7 +1,7 @@ describe Metric::Common do - let(:host) { FactoryGirl.create(:host) } + let(:host) { FactoryBot.create(:host) } let(:metric) do - FactoryGirl.create(:metric_rollup_host_hr, + FactoryBot.create(:metric_rollup_host_hr, :resource => host, :timestamp => Time.now.next_week(:sunday).utc ) @@ -16,7 +16,7 @@ context "#apply_time_profile" do it "with all days and hours selected it should return true" do - profile = FactoryGirl.create(:time_profile, + profile = FactoryBot.create(:time_profile, :description => "foo", :profile => {:tz => "New Delhi", :days => TimeProfile::ALL_DAYS, @@ -27,7 +27,7 @@ end it "with specific days and hours selected it should return false" do - profile = FactoryGirl.create(:time_profile, + profile = FactoryBot.create(:time_profile, :description => "foo", :profile => {:tz => "New Delhi", :days => [1], @@ -38,12 +38,12 @@ end it "returns true if time profile were used for aggregation (and rollup record refer to it)" do - profile = FactoryGirl.create(:time_profile, + profile = FactoryBot.create(:time_profile, :description => "foo", :profile => {:tz => "New Delhi", :days => [1], :hours => [1]}) - profile_aggr = FactoryGirl.create(:time_profile, + profile_aggr = FactoryBot.create(:time_profile, :description => "used_for_daily_aggregation", :profile => {:tz => "UTC", :days => (2..4), @@ -76,28 +76,28 @@ describe ".for_time_range" do it "returns nothing for nil dates" do - FactoryGirl.create(:metric, :timestamp => 5.days.ago) + FactoryBot.create(:metric, :timestamp => 5.days.ago) expect(Metric.for_time_range(nil, nil)).to be_empty end it "returns a single date' worth" do timestamp = 5.days.ago - good = FactoryGirl.create(:metric, :timestamp => timestamp) - FactoryGirl.create(:metric, :timestamp => 4.days.ago) - FactoryGirl.create(:metric, :timestamp => 6.days.ago) + good = FactoryBot.create(:metric, :timestamp => timestamp) + FactoryBot.create(:metric, :timestamp => 4.days.ago) + FactoryBot.create(:metric, :timestamp => 6.days.ago) expect(Metric.for_time_range(timestamp, timestamp)).to eq([good]) end it "returns open ended date" do - FactoryGirl.create(:metric, :timestamp => 30.days.ago) - good = FactoryGirl.create(:metric, :timestamp => 5.days.ago) + FactoryBot.create(:metric, :timestamp => 30.days.ago) + good = FactoryBot.create(:metric, :timestamp => 5.days.ago) expect(Metric.for_time_range(10.days.ago, nil)).to eq([good]) end it "returns range" do - FactoryGirl.create(:metric, :timestamp => 30.days.ago) - good = FactoryGirl.create(:metric, :timestamp => 5.days.ago) - FactoryGirl.create(:metric, :timestamp => 1.day.ago) + FactoryBot.create(:metric, :timestamp => 30.days.ago) + good = FactoryBot.create(:metric, :timestamp => 5.days.ago) + FactoryBot.create(:metric, :timestamp => 1.day.ago) expect(Metric.for_time_range(10.days.ago, 3.days.ago)).to eq([good]) end end diff --git a/spec/models/metric/helper_spec.rb b/spec/models/metric/helper_spec.rb index 1ad8843cbfc..ca93bea9575 100644 --- a/spec/models/metric/helper_spec.rb +++ b/spec/models/metric/helper_spec.rb @@ -4,22 +4,22 @@ end describe ".remove_duplicate_timestamps" do - let(:host) { FactoryGirl.create(:host) } + let(:host) { FactoryBot.create(:host) } let(:metric_rollup_1) do - FactoryGirl.create(:metric_rollup, + FactoryBot.create(:metric_rollup, :resource => host, :timestamp => Time.zone.parse("2016-01-12T00:00:00.00000000")) end # duplicate of metric_rollup_1 let(:metric_rollup_2) do - FactoryGirl.create(:metric_rollup, + FactoryBot.create(:metric_rollup, :resource => host, :timestamp => Time.zone.parse("2016-01-12T00:00:00.00000000")) end let(:metric_rollup_3) do - FactoryGirl.create(:metric_rollup, + FactoryBot.create(:metric_rollup, :resource => host, :timestamp => Time.zone.parse("2016-01-12T01:00:00.00000000")) end @@ -51,7 +51,7 @@ end let(:ems_event) do - FactoryGirl.create(:ems_event, :timestamp => Time.zone.parse("2016-01-12T01:00:00.00000000")) + FactoryBot.create(:ems_event, :timestamp => Time.zone.parse("2016-01-12T01:00:00.00000000")) end it "returns origin set of records, some input records are not MetricRollup and Metric" do diff --git a/spec/models/metric/processing_spec.rb b/spec/models/metric/processing_spec.rb index d84c92cd704..fa5727fe25b 100644 --- a/spec/models/metric/processing_spec.rb +++ b/spec/models/metric/processing_spec.rb @@ -1,8 +1,8 @@ describe Metric::Processing do context "#add_missing_intervals" do let(:time_now) { Time.current } - let(:last_perf) { FactoryGirl.create(:metric_rollup_vm_hr, :timestamp => time_now) } - let(:perf) { FactoryGirl.create(:metric_rollup_vm_hr, :timestamp => time_now + 10_800) } + let(:last_perf) { FactoryBot.create(:metric_rollup_vm_hr, :timestamp => time_now) } + let(:perf) { FactoryBot.create(:metric_rollup_vm_hr, :timestamp => time_now + 10_800) } context "#extrapolate" do it "fills all hourly intervals" do perf.save && last_perf.save @@ -29,11 +29,11 @@ context ".process_derived_columns" do context "services" do - let(:vm_amazon_a) { FactoryGirl.create(:vm_amazon) } - let(:vm_amazon_b) { FactoryGirl.create(:vm_amazon, :powered_off) } - let(:service) { FactoryGirl.create(:service) } - let(:metric_a) { FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm_amazon_a) } - let(:metric_b) { FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm_amazon_b) } + let(:vm_amazon_a) { FactoryBot.create(:vm_amazon) } + let(:vm_amazon_b) { FactoryBot.create(:vm_amazon, :powered_off) } + let(:service) { FactoryBot.create(:service) } + let(:metric_a) { FactoryBot.create(:metric_rollup_vm_hr, :resource => vm_amazon_a) } + let(:metric_b) { FactoryBot.create(:metric_rollup_vm_hr, :resource => vm_amazon_b) } before do service.add_resource(vm_amazon_a) @@ -51,11 +51,11 @@ end context "on :derived_host_sockets" do - let(:hardware) { FactoryGirl.create(:hardware, :cpu_sockets => 2) } - let(:host) { FactoryGirl.create(:host, :hardware => hardware) } + let(:hardware) { FactoryBot.create(:hardware, :cpu_sockets => 2) } + let(:host) { FactoryBot.create(:host, :hardware => hardware) } it "adds the derived host sockets" do - m = FactoryGirl.create(:metric_rollup_vm_hr, :resource => host) + m = FactoryBot.create(:metric_rollup_vm_hr, :resource => host) derived_columns = described_class.process_derived_columns(host, m.attributes.symbolize_keys) @@ -64,10 +64,10 @@ end context "on :derived_vm_numvcpus" do - let(:vm) { FactoryGirl.create(:vm_vmware, :hardware => FactoryGirl.create(:hardware, :cpu_total_cores => 8)) } + let(:vm) { FactoryBot.create(:vm_vmware, :hardware => FactoryBot.create(:hardware, :cpu_total_cores => 8)) } it "with all usage values" do - m = FactoryGirl.create(:metric_rollup_vm_hr, + m = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :cpu_usage_rate_average => 50.0, :cpu_usagemhz_rate_average => 1_500.0, @@ -79,7 +79,7 @@ end it "with only cpu_usage_rate_average usage value" do - m = FactoryGirl.create(:metric_rollup_vm_hr, + m = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :cpu_usage_rate_average => 50.0, ) @@ -90,7 +90,7 @@ end it "with only cpu_usagemhz_rate_average usage value" do - m = FactoryGirl.create(:metric_rollup_vm_hr, + m = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :cpu_usagemhz_rate_average => 1_500.0, ) @@ -101,7 +101,7 @@ end it "without usage values" do - m = FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm) + m = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm) derived_columns = described_class.process_derived_columns(vm, m.attributes.symbolize_keys) @@ -109,8 +109,8 @@ end it "without hardware" do - vm = FactoryGirl.create(:vm_vmware) - m = FactoryGirl.create(:metric_rollup_vm_hr, + vm = FactoryBot.create(:vm_vmware) + m = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :cpu_usage_rate_average => 50.0, :cpu_usagemhz_rate_average => 1_500.0 @@ -124,8 +124,8 @@ context "on :derived_cpu_available" do let(:vm) do - FactoryGirl.create(:vm_vmware, :hardware => - FactoryGirl.create(:hardware, + FactoryBot.create(:vm_vmware, :hardware => + FactoryBot.create(:hardware, :cpu_total_cores => 8, :cpu_sockets => 4, :cpu_cores_per_socket => 2, @@ -135,7 +135,7 @@ end it "with all usage values" do - m = FactoryGirl.create(:metric_rollup_vm_hr, + m = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :cpu_usage_rate_average => 50.0, :cpu_usagemhz_rate_average => 1_500.0, @@ -147,7 +147,7 @@ end it "with only cpu_usage_rate_average usage value" do - m = FactoryGirl.create(:metric_rollup_vm_hr, + m = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :cpu_usage_rate_average => 50.0, ) @@ -158,7 +158,7 @@ end it "with only cpu_usagemhz_rate_average usage value" do - m = FactoryGirl.create(:metric_rollup_vm_hr, + m = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :cpu_usagemhz_rate_average => 1_500.0, ) @@ -169,7 +169,7 @@ end it "without usage values" do - m = FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm) + m = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm) derived_columns = described_class.process_derived_columns(vm, m.attributes.symbolize_keys) @@ -177,8 +177,8 @@ end it "without hardware" do - vm = FactoryGirl.create(:vm_vmware) - m = FactoryGirl.create(:metric_rollup_vm_hr, + vm = FactoryBot.create(:vm_vmware) + m = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :cpu_usage_rate_average => 50.0, :cpu_usagemhz_rate_average => 1_500.0 @@ -192,15 +192,15 @@ context "on :derived_memory_available" do let(:vm) do - FactoryGirl.create(:vm_vmware, :hardware => - FactoryGirl.create(:hardware, + FactoryBot.create(:vm_vmware, :hardware => + FactoryBot.create(:hardware, :memory_mb => 4_096 ) ) end it "with usage values" do - m = FactoryGirl.create(:metric_rollup_vm_hr, + m = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :mem_usage_absolute_average => 50.0, ) @@ -211,7 +211,7 @@ end it "without usage values" do - m = FactoryGirl.create(:metric_rollup_vm_hr, :resource => vm) + m = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm) derived_columns = described_class.process_derived_columns(vm, m.attributes.symbolize_keys) @@ -219,8 +219,8 @@ end it "without hardware" do - vm = FactoryGirl.create(:vm_vmware) - m = FactoryGirl.create(:metric_rollup_vm_hr, + vm = FactoryBot.create(:vm_vmware) + m = FactoryBot.create(:metric_rollup_vm_hr, :resource => vm, :mem_usage_absolute_average => 50.0, ) diff --git a/spec/models/metric/purging_spec.rb b/spec/models/metric/purging_spec.rb index 0019d22c4f4..26b9a445a09 100644 --- a/spec/models/metric/purging_spec.rb +++ b/spec/models/metric/purging_spec.rb @@ -40,18 +40,18 @@ end context "with data" do - let(:vm1) { FactoryGirl.create(:vm_vmware) } - let(:vm2) { FactoryGirl.create(:vm_vmware) } + let(:vm1) { FactoryBot.create(:vm_vmware) } + let(:vm2) { FactoryBot.create(:vm_vmware) } before do @metrics1 = [ - FactoryGirl.create(:metric_rollup_vm_hr, :resource_id => vm1.id, :timestamp => (6.months + 1.days).ago.utc), - FactoryGirl.create(:metric_rollup_vm_hr, :resource_id => vm1.id, :timestamp => (6.months - 1.days).ago.utc) + FactoryBot.create(:metric_rollup_vm_hr, :resource_id => vm1.id, :timestamp => (6.months + 1.days).ago.utc), + FactoryBot.create(:metric_rollup_vm_hr, :resource_id => vm1.id, :timestamp => (6.months - 1.days).ago.utc) ] @metrics2 = [ - FactoryGirl.create(:metric_rollup_vm_hr, :resource_id => vm2.id, :timestamp => (6.months + 2.days).ago.utc), - FactoryGirl.create(:metric_rollup_vm_hr, :resource_id => vm2.id, :timestamp => (6.months + 1.days).ago.utc), - FactoryGirl.create(:metric_rollup_vm_hr, :resource_id => vm2.id, :timestamp => (6.months - 1.days).ago.utc) + FactoryBot.create(:metric_rollup_vm_hr, :resource_id => vm2.id, :timestamp => (6.months + 2.days).ago.utc), + FactoryBot.create(:metric_rollup_vm_hr, :resource_id => vm2.id, :timestamp => (6.months + 1.days).ago.utc), + FactoryBot.create(:metric_rollup_vm_hr, :resource_id => vm2.id, :timestamp => (6.months - 1.days).ago.utc) ] end @@ -85,12 +85,12 @@ context "#purge_realtime" do before { EvmSpecHelper.create_guid_miq_server_zone } - let(:vm1) { FactoryGirl.create(:vm_vmware) } + let(:vm1) { FactoryBot.create(:vm_vmware) } it "deletes mid day" do Timecop.freeze('2018-02-01T09:12:00Z') do (0..16).each do |hours| - FactoryGirl.create(:metric_vm_rt, :resource_id => vm1.id, :timestamp => (hours.hours.ago + 1.minute)) + FactoryBot.create(:metric_vm_rt, :resource_id => vm1.id, :timestamp => (hours.hours.ago + 1.minute)) end expect(Metric.count).to eq(17) # keep metric for 05:13 - 09:13 @@ -104,7 +104,7 @@ it "deletes just after midnight" do Timecop.freeze('2018-02-01T02:12:00Z') do (0..16).each do |hours| - FactoryGirl.create(:metric_vm_rt, :resource_id => vm1.id, :timestamp => (hours.hours.ago + 1.minute)) + FactoryBot.create(:metric_vm_rt, :resource_id => vm1.id, :timestamp => (hours.hours.ago + 1.minute)) end expect(Metric.count).to eq(17) # keep metric for 22:13 - 02:13 @@ -119,7 +119,7 @@ Timecop.freeze('2018-01-01T02:12:00Z') do (0..16).each do |hours| - FactoryGirl.create(:metric_vm_rt, :resource_id => vm1.id, :timestamp => (hours.hours.ago + 1.minute)) + FactoryBot.create(:metric_vm_rt, :resource_id => vm1.id, :timestamp => (hours.hours.ago + 1.minute)) end expect(Metric.count).to eq(17) # keep metric for 22:13 - 02:13 @@ -134,7 +134,7 @@ Timecop.freeze('2017-03-12T08:12:00Z') do # 2:00am+05 EST is time of change # this is overkill. since we prune every 21 minutes, there will only be ~1 table with data (0..16).each do |hours| - FactoryGirl.create(:metric_vm_rt, :resource_id => vm1.id, :timestamp => (hours.hours.ago + 1.minute)) + FactoryBot.create(:metric_vm_rt, :resource_id => vm1.id, :timestamp => (hours.hours.ago + 1.minute)) end expect(Metric.count).to eq(17) # keep metric for 04:13 - 08:13 @@ -149,7 +149,7 @@ Timecop.freeze('2017-11-05T08:12:00Z') do # 2:00am+05 EST is time of change # this is overkill. since we prune every 21 minutes, there will only be ~1 table with data (0..16).each do |hours| - FactoryGirl.create(:metric_vm_rt, :resource_id => vm1.id, :timestamp => (hours.hours.ago + 1.minute)) + FactoryBot.create(:metric_vm_rt, :resource_id => vm1.id, :timestamp => (hours.hours.ago + 1.minute)) end expect(Metric.count).to eq(17) # keep metric for 04:13 - 08:13 @@ -175,7 +175,7 @@ it "deletes just after midnight" do Timecop.freeze('2018-02-01T02:12:00Z') do (0..23).each do |hours| - FactoryGirl.create(:metric_vm_rt, :resource_id => vm1.id, :timestamp => (hours.hours.ago + 1.minute)) + FactoryBot.create(:metric_vm_rt, :resource_id => vm1.id, :timestamp => (hours.hours.ago + 1.minute)) end expect(Metric.count).to eq(24) # keep metric for 18:13 - 02:13 diff --git a/spec/models/metric/statistic_spec.rb b/spec/models/metric/statistic_spec.rb index 0d602dccb36..ef8a12d591d 100644 --- a/spec/models/metric/statistic_spec.rb +++ b/spec/models/metric/statistic_spec.rb @@ -1,29 +1,29 @@ describe Metric::Statistic do context ".calculate_stat_columns" do let(:ems_openshift) do - FactoryGirl.create(:ems_openshift, :hostname => 't', :port => 8443, :name => 't') + FactoryBot.create(:ems_openshift, :hostname => 't', :port => 8443, :name => 't') end let(:project) do - FactoryGirl.create(:container_project, :name => "project") + FactoryBot.create(:container_project, :name => "project") end hour = Time.parse(Metric::Helper.nearest_hourly_timestamp(Time.now)).utc - let(:c1) { FactoryGirl.create(:container_group, :ems_created_on => hour - 10.minutes) } - let(:c2) { FactoryGirl.create(:container_group, :ems_created_on => hour - 50.minutes) } - let(:c3) { FactoryGirl.create(:container_group, :ems_created_on => hour - 120.minutes) } - let(:c4) { FactoryGirl.create(:container_group, :ems_created_on => hour + 1.minute) } + let(:c1) { FactoryBot.create(:container_group, :ems_created_on => hour - 10.minutes) } + let(:c2) { FactoryBot.create(:container_group, :ems_created_on => hour - 50.minutes) } + let(:c3) { FactoryBot.create(:container_group, :ems_created_on => hour - 120.minutes) } + let(:c4) { FactoryBot.create(:container_group, :ems_created_on => hour + 1.minute) } - let(:c5) { FactoryGirl.create(:container_group, :deleted_on => hour - 10.minutes) } - let(:c6) { FactoryGirl.create(:container_group, :deleted_on => hour - 50.minutes) } - let(:c7) { FactoryGirl.create(:container_group, :deleted_on => hour - 120.minutes) } - let(:c8) { FactoryGirl.create(:container_group, :deleted_on => hour + 1.minute) } + let(:c5) { FactoryBot.create(:container_group, :deleted_on => hour - 10.minutes) } + let(:c6) { FactoryBot.create(:container_group, :deleted_on => hour - 50.minutes) } + let(:c7) { FactoryBot.create(:container_group, :deleted_on => hour - 120.minutes) } + let(:c8) { FactoryBot.create(:container_group, :deleted_on => hour + 1.minute) } - let(:c9) { FactoryGirl.create(:container_image, :registered_on => hour - 10.minutes) } - let(:c10) { FactoryGirl.create(:container_image, :registered_on => hour - 50.minutes) } - let(:c11) { FactoryGirl.create(:container_image, :registered_on => hour - 120.minutes) } - let(:c12) { FactoryGirl.create(:container_image, :registered_on => hour + 1.minute) } + let(:c9) { FactoryBot.create(:container_image, :registered_on => hour - 10.minutes) } + let(:c10) { FactoryBot.create(:container_image, :registered_on => hour - 50.minutes) } + let(:c11) { FactoryBot.create(:container_image, :registered_on => hour - 120.minutes) } + let(:c12) { FactoryBot.create(:container_image, :registered_on => hour + 1.minute) } it "count created container groups in a provider" do ems_openshift.container_groups << [c1, c2, c3, c4, c5, c6, c7, c8] diff --git a/spec/models/metric_rollup/chargeback_helper_spec.rb b/spec/models/metric_rollup/chargeback_helper_spec.rb index 1c3a48d942c..76ca7097392 100644 --- a/spec/models/metric_rollup/chargeback_helper_spec.rb +++ b/spec/models/metric_rollup/chargeback_helper_spec.rb @@ -1,6 +1,6 @@ describe MetricRollup do describe '#parents_determining_rate' do - let(:ems) { FactoryGirl.build(:ems_vmware) } + let(:ems) { FactoryBot.build(:ems_vmware) } before do MiqRegion.seed @@ -8,11 +8,11 @@ end context 'VmOrTemplate' do - let(:ems_cluster) { FactoryGirl.build(:ems_cluster, :ext_management_system => ems) } - let(:storage) { FactoryGirl.build(:storage_target_vmware) } - let(:host) { FactoryGirl.build(:host) } + let(:ems_cluster) { FactoryBot.build(:ems_cluster, :ext_management_system => ems) } + let(:storage) { FactoryBot.build(:storage_target_vmware) } + let(:host) { FactoryBot.build(:host) } let(:vm) do - FactoryGirl.create(:vm_vmware, :name => 'test_vm', :ems_ref => 'ems_ref', + FactoryBot.create(:vm_vmware, :name => 'test_vm', :ems_ref => 'ems_ref', :ems_cluster => ems_cluster, :storage => storage, :host => host, :ext_management_system => ems ) @@ -22,7 +22,7 @@ context 'metric_rollup record with parents not nil' do let(:metric_rollup) do - FactoryGirl.build(:metric_rollup_vm_hr, + FactoryBot.build(:metric_rollup_vm_hr, :resource => vm, :parent_host => host, :parent_ems_cluster => ems_cluster, @@ -45,7 +45,7 @@ end context 'metric_rollup record with parents nil' do - let(:metric_rollup) { FactoryGirl.build(:metric_rollup_vm_hr, :resource => vm) } + let(:metric_rollup) { FactoryBot.build(:metric_rollup_vm_hr, :resource => vm) } let(:parents_from_vm) do [ vm.host, diff --git a/spec/models/metric_rollup_spec.rb b/spec/models/metric_rollup_spec.rb index bc564fd4a07..4882281272c 100644 --- a/spec/models/metric_rollup_spec.rb +++ b/spec/models/metric_rollup_spec.rb @@ -20,8 +20,8 @@ context ".rollups_in_range" do before do - @current = FactoryGirl.create_list(:metric_rollup_vm_hr, 2) - @past = FactoryGirl.create_list(:metric_rollup_vm_hr, 2, :timestamp => Time.now.utc - 5.days) + @current = FactoryBot.create_list(:metric_rollup_vm_hr, 2) + @past = FactoryBot.create_list(:metric_rollup_vm_hr, 2, :timestamp => Time.now.utc - 5.days) end it "returns rollups from the correct range" do diff --git a/spec/models/metric_spec.rb b/spec/models/metric_spec.rb index 86323bd6057..bad70a44b83 100644 --- a/spec/models/metric_spec.rb +++ b/spec/models/metric_spec.rb @@ -7,23 +7,23 @@ context "as vmware" do before do - @ems_vmware = FactoryGirl.create(:ems_vmware, :zone => @zone) + @ems_vmware = FactoryBot.create(:ems_vmware, :zone => @zone) end context "with enabled and disabled targets" do before do storages = [] - 2.times { storages << FactoryGirl.create(:storage_target_vmware) } + 2.times { storages << FactoryBot.create(:storage_target_vmware) } @vmware_clusters = [] 2.times do - cluster = FactoryGirl.create(:cluster_target) + cluster = FactoryBot.create(:cluster_target) @vmware_clusters << cluster @ems_vmware.ems_clusters << cluster end 6.times do |n| - host = FactoryGirl.create(:host_target_vmware, :ext_management_system => @ems_vmware) + host = FactoryBot.create(:host_target_vmware, :ext_management_system => @ems_vmware) @ems_vmware.hosts << host @vmware_clusters[n / 2].hosts << host if n < 4 @@ -239,7 +239,7 @@ context "with a vm" do before do - @vm = FactoryGirl.create(:vm_perf, :ext_management_system => @ems_vmware) + @vm = FactoryBot.create(:vm_perf, :ext_management_system => @ems_vmware) end context "queueing up realtime rollups to parent" do @@ -284,7 +284,7 @@ end context "services" do - let(:service) { FactoryGirl.create(:service) } + let(:service) { FactoryBot.create(:service) } before do service.add_resource(@vm) @@ -302,16 +302,16 @@ context "with a small environment and time_profile" do before do - @vm1 = FactoryGirl.create(:vm_vmware) - @vm2 = FactoryGirl.create(:vm_vmware, :hardware => FactoryGirl.create(:hardware, :cpu1x2, :memory_mb => 4096)) - @host1 = FactoryGirl.create(:host, :hardware => FactoryGirl.create(:hardware, :memory_mb => 8124, :cpu_total_cores => 1, :cpu_speed => 9576), :vms => [@vm1]) - @host2 = FactoryGirl.create(:host, :hardware => FactoryGirl.create(:hardware, :memory_mb => 8124, :cpu_total_cores => 1, :cpu_speed => 9576)) + @vm1 = FactoryBot.create(:vm_vmware) + @vm2 = FactoryBot.create(:vm_vmware, :hardware => FactoryBot.create(:hardware, :cpu1x2, :memory_mb => 4096)) + @host1 = FactoryBot.create(:host, :hardware => FactoryBot.create(:hardware, :memory_mb => 8124, :cpu_total_cores => 1, :cpu_speed => 9576), :vms => [@vm1]) + @host2 = FactoryBot.create(:host, :hardware => FactoryBot.create(:hardware, :memory_mb => 8124, :cpu_total_cores => 1, :cpu_speed => 9576)) - @ems_cluster = FactoryGirl.create(:ems_cluster, :ext_management_system => @ems_vmware) + @ems_cluster = FactoryBot.create(:ems_cluster, :ext_management_system => @ems_vmware) @ems_cluster.hosts << @host1 @ems_cluster.hosts << @host2 - @time_profile = FactoryGirl.create(:time_profile_utc) + @time_profile = FactoryBot.create(:time_profile_utc) MiqQueue.delete_all end @@ -328,7 +328,7 @@ "2010-04-14T22:52:30Z", 100.0, ] cases.each_slice(2) do |t, v| - @vm1.metrics << FactoryGirl.create(:metric_vm_rt, + @vm1.metrics << FactoryBot.create(:metric_vm_rt, :timestamp => t, :cpu_usage_rate_average => v, :cpu_ready_delta_summation => v * 1000, # Multiply by a factor of 1000 to maake it more realistic and enable testing virtual col v_pct_cpu_ready_delta_summation @@ -382,7 +382,7 @@ "2010-04-15T21:00:00Z", 100.0, ] cases.each_slice(2) do |t, v| - @vm1.metric_rollups << FactoryGirl.create(:metric_rollup_vm_hr, + @vm1.metric_rollups << FactoryBot.create(:metric_rollup_vm_hr, :timestamp => t, :cpu_usage_rate_average => v, :cpu_ready_delta_summation => v * 10000, @@ -403,7 +403,7 @@ end it "should find multiple resource types" do - @host1.metric_rollups << FactoryGirl.create(:metric_rollup_host_hr, + @host1.metric_rollups << FactoryBot.create(:metric_rollup_host_hr, :resource => @host1, :timestamp => "2010-04-14T22:00:00Z") metrics = Metric::Finders.find_all_by_day([@vm1, @host1], "2010-04-14T00:00:00Z", 'hourly', @time_profile) @@ -461,7 +461,7 @@ context "with Vm daily performances" do before do - @perf = FactoryGirl.create(:metric_rollup_vm_daily, + @perf = FactoryBot.create(:metric_rollup_vm_daily, :timestamp => "2010-04-14T00:00:00Z", :time_profile => @time_profile ) @@ -500,7 +500,7 @@ "2010-04-14T22:52:40Z", 100.0, ] cases.each_slice(2) do |t, v| - @host1.metrics << FactoryGirl.create(:metric_host_rt, + @host1.metrics << FactoryBot.create(:metric_host_rt, :timestamp => t, :cpu_usage_rate_average => v, :cpu_usagemhz_rate_average => v, @@ -518,7 +518,7 @@ "2010-04-14T22:52:40Z", 200.0, ] cases.each_slice(2) do |t, v| - @host2.metrics << FactoryGirl.create(:metric_host_rt, + @host2.metrics << FactoryBot.create(:metric_host_rt, :timestamp => t, :cpu_usage_rate_average => v, :cpu_usagemhz_rate_average => v, @@ -649,7 +649,7 @@ ] cases.each_slice(3) do |t, cpu, mem| [@vm1, @vm2].each do |vm| - vm.metric_rollups << FactoryGirl.create(:metric_rollup_vm_daily, + vm.metric_rollups << FactoryBot.create(:metric_rollup_vm_daily, :timestamp => t, :cpu_usage_rate_average => cpu, :mem_usage_absolute_average => mem, @@ -702,12 +702,12 @@ context "with a full rollup chain and time profile" do before do - @host = FactoryGirl.create(:host, :ext_management_system => @ems_vmware) - @vm = FactoryGirl.create(:vm_vmware, :ext_management_system => @ems_vmware, :host => @host) - @ems_cluster = FactoryGirl.create(:ems_cluster, :ext_management_system => @ems_vmware) + @host = FactoryBot.create(:host, :ext_management_system => @ems_vmware) + @vm = FactoryBot.create(:vm_vmware, :ext_management_system => @ems_vmware, :host => @host) + @ems_cluster = FactoryBot.create(:ems_cluster, :ext_management_system => @ems_vmware) @ems_cluster.hosts << @host - @time_profile = FactoryGirl.create(:time_profile_utc) + @time_profile = FactoryBot.create(:time_profile_utc) MiqQueue.delete_all end @@ -978,8 +978,8 @@ context "with a cluster" do context "maintains_value_for_duration?" do it "should handle the only event right before the starting on time (FB15770)" do - @ems_cluster = FactoryGirl.create(:ems_cluster, :ext_management_system => @ems_vmware) - @ems_cluster.metric_rollups << FactoryGirl.create(:metric_rollup_vm_hr, + @ems_cluster = FactoryBot.create(:ems_cluster, :ext_management_system => @ems_vmware) + @ems_cluster.metric_rollups << FactoryBot.create(:metric_rollup_vm_hr, :timestamp => Time.parse("2011-08-12T20:33:12Z") ) @@ -1000,20 +1000,20 @@ context "as openstack" do before do - @ems_openstack = FactoryGirl.create(:ems_openstack, :zone => @zone) + @ems_openstack = FactoryBot.create(:ems_openstack, :zone => @zone) end context "with enabled and disabled targets" do before do - @availability_zone = FactoryGirl.create(:availability_zone_target) + @availability_zone = FactoryBot.create(:availability_zone_target) @ems_openstack.availability_zones << @availability_zone @vms_in_az = [] - 2.times { @vms_in_az << FactoryGirl.create(:vm_openstack, :ems_id => @ems_openstack.id) } + 2.times { @vms_in_az << FactoryBot.create(:vm_openstack, :ems_id => @ems_openstack.id) } @availability_zone.vms = @vms_in_az - @availability_zone.vms.push(FactoryGirl.create(:vm_openstack, :ems_id => nil)) + @availability_zone.vms.push(FactoryBot.create(:vm_openstack, :ems_id => nil)) @vms_not_in_az = [] - 3.times { @vms_not_in_az << FactoryGirl.create(:vm_openstack, :ems_id => @ems_openstack.id) } + 3.times { @vms_not_in_az << FactoryBot.create(:vm_openstack, :ems_id => @ems_openstack.id) } MiqQueue.delete_all end @@ -1043,7 +1043,7 @@ context "with a vm" do before do - @vm = FactoryGirl.create(:vm_perf_openstack, :ext_management_system => @ems_openstack) + @vm = FactoryBot.create(:vm_perf_openstack, :ext_management_system => @ems_openstack) end context "queueing up realtime rollups to parent" do @@ -1074,10 +1074,10 @@ context "with a full rollup chain and time profile" do before do - @availability_zone = FactoryGirl.create(:availability_zone, :ext_management_system => @ems_openstack) - @vm = FactoryGirl.create(:vm_openstack, :ext_management_system => @ems_openstack, :availability_zone => @availability_zone) + @availability_zone = FactoryBot.create(:availability_zone, :ext_management_system => @ems_openstack) + @vm = FactoryBot.create(:vm_openstack, :ext_management_system => @ems_openstack, :availability_zone => @availability_zone) - @time_profile = FactoryGirl.create(:time_profile_utc) + @time_profile = FactoryBot.create(:time_profile_utc) MiqQueue.delete_all end @@ -1133,15 +1133,15 @@ context "as kubernetes" do before do - @ems_kubernetes = FactoryGirl.create(:ems_kubernetes, :zone => @zone) + @ems_kubernetes = FactoryBot.create(:ems_kubernetes, :zone => @zone) - @node_a = FactoryGirl.create(:container_node, :ext_management_system => @ems_kubernetes) - @node_a.computer_system.hardware = FactoryGirl.create(:hardware, :cpu_total_cores => 2) + @node_a = FactoryBot.create(:container_node, :ext_management_system => @ems_kubernetes) + @node_a.computer_system.hardware = FactoryBot.create(:hardware, :cpu_total_cores => 2) - @node_b = FactoryGirl.create(:container_node, :ext_management_system => @ems_kubernetes) - @node_b.computer_system.hardware = FactoryGirl.create(:hardware, :cpu_total_cores => 8) + @node_b = FactoryBot.create(:container_node, :ext_management_system => @ems_kubernetes) + @node_b.computer_system.hardware = FactoryBot.create(:hardware, :cpu_total_cores => 8) - @node_a.metric_rollups << FactoryGirl.create( + @node_a.metric_rollups << FactoryBot.create( :metric_rollup, :timestamp => ROLLUP_CHAIN_TIMESTAMP, :cpu_usage_rate_average => 50.0, @@ -1150,7 +1150,7 @@ :parent_ems_id => @ems_kubernetes.id ) - @node_b.metric_rollups << FactoryGirl.create( + @node_b.metric_rollups << FactoryBot.create( :metric_rollup, :timestamp => ROLLUP_CHAIN_TIMESTAMP, :cpu_usage_rate_average => 75.0, diff --git a/spec/models/miq_action_spec.rb b/spec/models/miq_action_spec.rb index fd330dbfde8..a6e0c75934a 100644 --- a/spec/models/miq_action_spec.rb +++ b/spec/models/miq_action_spec.rb @@ -13,11 +13,11 @@ context "#action_custom_automation" do before do - tenant = FactoryGirl.create(:tenant) - group = FactoryGirl.create(:miq_group, :tenant => tenant) - @user = FactoryGirl.create(:user, :userid => "test", :miq_groups => [group]) - @vm = FactoryGirl.create(:vm_vmware, :evm_owner => @user, :miq_group => group) - FactoryGirl.create(:miq_action, :name => "custom_automation") + tenant = FactoryBot.create(:tenant) + group = FactoryBot.create(:miq_group, :tenant => tenant) + @user = FactoryBot.create(:user, :userid => "test", :miq_groups => [group]) + @vm = FactoryBot.create(:vm_vmware, :evm_owner => @user, :miq_group => group) + FactoryBot.create(:miq_action, :name => "custom_automation") @action = MiqAction.find_by(:name => "custom_automation") expect(@action).not_to be_nil @action.options = {:ae_request => "test_custom_automation"} @@ -55,7 +55,7 @@ end it "passes source event to automate if set" do - ems_event = FactoryGirl.create(:ems_event, :event_type => "CloneVM_Task") + ems_event = FactoryBot.create(:ems_event, :event_type => "CloneVM_Task") args = {:attrs => {:request => "test_custom_automation", "EventStream::event_stream" => ems_event.id}} expect(MiqAeEngine).to receive(:deliver).with(hash_including(args)).once @@ -65,20 +65,20 @@ context "#action_evm_event" do it "for Vm" do - ems = FactoryGirl.create(:ems_vmware) - host = FactoryGirl.create(:host_vmware) - vm = FactoryGirl.create(:vm_vmware, :host => host, :ext_management_system => ems) - action = FactoryGirl.create(:miq_action) - res = action.action_evm_event(action, vm, :policy => FactoryGirl.create(:miq_policy)) + ems = FactoryBot.create(:ems_vmware) + host = FactoryBot.create(:host_vmware) + vm = FactoryBot.create(:vm_vmware, :host => host, :ext_management_system => ems) + action = FactoryBot.create(:miq_action) + res = action.action_evm_event(action, vm, :policy => FactoryBot.create(:miq_policy)) expect(res).to be_kind_of(MiqEvent) expect(res.target).to eq(vm) end it "for Datastore" do - storage = FactoryGirl.create(:storage) - action = FactoryGirl.create(:miq_action) - result = action.action_evm_event(action, storage, :policy => FactoryGirl.create(:miq_policy)) + storage = FactoryBot.create(:storage) + action = FactoryBot.create(:miq_action) + result = action.action_evm_event(action, storage, :policy => FactoryBot.create(:miq_policy)) expect(result).to be_kind_of(MiqEvent) expect(result.target).to eq(storage) @@ -87,11 +87,11 @@ context "#raise_automation_event" do before do - @vm = FactoryGirl.create(:vm_vmware) + @vm = FactoryBot.create(:vm_vmware) allow(@vm).to receive(:my_zone).and_return("vm_zone") - FactoryGirl.create(:miq_event_definition, :name => "raise_automation_event") - FactoryGirl.create(:miq_event_definition, :name => "vm_start") - FactoryGirl.create(:miq_action, :name => "raise_automation_event") + FactoryBot.create(:miq_event_definition, :name => "raise_automation_event") + FactoryBot.create(:miq_event_definition, :name => "vm_start") + FactoryBot.create(:miq_action, :name => "raise_automation_event") @action = MiqAction.find_by(:name => "raise_automation_event") expect(@action).not_to be_nil @event = MiqEventDefinition.find_by(:name => "vm_start") @@ -134,10 +134,10 @@ context "#action_ems_refresh" do before do - FactoryGirl.create(:miq_action, :name => "ems_refresh") + FactoryBot.create(:miq_action, :name => "ems_refresh") @action = MiqAction.find_by(:name => "ems_refresh") expect(@action).not_to be_nil - @zone1 = FactoryGirl.create(:small_environment) + @zone1 = FactoryBot.create(:small_environment) @vm = @zone1.vms.first end @@ -156,10 +156,10 @@ context "#action_vm_retire" do before do - @vm = FactoryGirl.create(:vm_vmware) + @vm = FactoryBot.create(:vm_vmware) allow(@vm).to receive(:my_zone).and_return("vm_zone") - @event = FactoryGirl.create(:miq_event_definition, :name => "assigned_company_tag") - @action = FactoryGirl.create(:miq_action, :name => "vm_retire") + @event = FactoryBot.create(:miq_event_definition, :name => "assigned_company_tag") + @action = FactoryBot.create(:miq_action, :name => "vm_retire") end it "synchronous" do @@ -178,7 +178,7 @@ it "asynchronous" do input = {:synchronous => false} - zone = FactoryGirl.create(:zone) + zone = FactoryBot.create(:zone) allow(@vm).to receive_messages(:my_zone => zone.name) Timecop.freeze do @@ -196,11 +196,11 @@ end context "#action_container_image_analyze" do - let(:container_image) { FactoryGirl.create(:container_image) } - let(:container_image_registry) { FactoryGirl.create(:container_image_registry) } - let(:event) { FactoryGirl.create(:miq_event_definition, :name => "whatever") } - let(:event_loop) { FactoryGirl.create(:miq_event_definition, :name => "request_containerimage_scan") } - let(:action) { FactoryGirl.create(:miq_action, :name => "container_image_analyze") } + let(:container_image) { FactoryBot.create(:container_image) } + let(:container_image_registry) { FactoryBot.create(:container_image_registry) } + let(:event) { FactoryBot.create(:miq_event_definition, :name => "whatever") } + let(:event_loop) { FactoryBot.create(:miq_event_definition, :name => "request_containerimage_scan") } + let(:action) { FactoryBot.create(:miq_action, :name => "container_image_analyze") } it "scans container images" do expect(container_image).to receive(:scan).once @@ -219,9 +219,9 @@ end context "#action_container_image_annotate_scan_results" do - let(:container_image) { FactoryGirl.create(:container_image) } - let(:event) { FactoryGirl.create(:miq_event_definition, :name => "whatever") } - let(:action) { FactoryGirl.create(:miq_action, :name => "container_image_annotate_deny_execution") } + let(:container_image) { FactoryBot.create(:container_image) } + let(:event) { FactoryBot.create(:miq_event_definition, :name => "whatever") } + let(:action) { FactoryBot.create(:miq_action, :name => "container_image_annotate_deny_execution") } it "will not annotate if the method is unavailable" do expect(MiqQueue).to receive(:put).exactly(0).times @@ -470,21 +470,21 @@ def stub_csv(data) end context 'run_ansible_playbook' do - let(:tenant) { FactoryGirl.create(:tenant) } - let(:group) { FactoryGirl.create(:miq_group, :tenant => tenant) } - let(:user) { FactoryGirl.create(:user, :userid => "test", :miq_groups => [group]) } - let(:vm) { FactoryGirl.create(:vm_vmware, :evm_owner => user, :miq_group => group, :hardware => hardware) } - let(:action) { FactoryGirl.create(:miq_action, :name => "run_ansible_playbook", :options => action_options) } - let(:stap) { FactoryGirl.create(:service_template_ansible_playbook) } + let(:tenant) { FactoryBot.create(:tenant) } + let(:group) { FactoryBot.create(:miq_group, :tenant => tenant) } + let(:user) { FactoryBot.create(:user, :userid => "test", :miq_groups => [group]) } + let(:vm) { FactoryBot.create(:vm_vmware, :evm_owner => user, :miq_group => group, :hardware => hardware) } + let(:action) { FactoryBot.create(:miq_action, :name => "run_ansible_playbook", :options => action_options) } + let(:stap) { FactoryBot.create(:service_template_ansible_playbook) } let(:ip1) { "1.1.1.94" } let(:ip2) { "1.1.1.96" } let(:event_name) { "Fred" } let(:miq_event_def) do - FactoryGirl.create(:miq_event_definition, :name => event_name) + FactoryBot.create(:miq_event_definition, :name => event_name) end let(:hardware) do - FactoryGirl.create(:hardware).tap do |h| + FactoryBot.create(:hardware).tap do |h| h.ipaddresses << ip1 h.ipaddresses << ip2 end diff --git a/spec/models/miq_ae_class_spec.rb b/spec/models/miq_ae_class_spec.rb index 6443cbb5287..15c466b1f72 100644 --- a/spec/models/miq_ae_class_spec.rb +++ b/spec/models/miq_ae_class_spec.rb @@ -38,7 +38,7 @@ end before do - @user = FactoryGirl.create(:user_with_group) + @user = FactoryBot.create(:user_with_group) end it "should not create class without namespace" do @@ -65,14 +65,14 @@ end it "should return editable as false if the parent namespace is not editable" do - n1 = FactoryGirl.create(:miq_ae_system_domain, :tenant => @user.current_tenant) - c1 = FactoryGirl.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") + n1 = FactoryBot.create(:miq_ae_system_domain, :tenant => @user.current_tenant) + c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") expect(c1.editable?(@user)).to be_falsey end it "should return editable as true if the parent namespace is editable" do - n1 = FactoryGirl.create(:miq_ae_domain, :tenant => @user.current_tenant) - c1 = FactoryGirl.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") + n1 = FactoryBot.create(:miq_ae_domain, :tenant => @user.current_tenant) + c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") expect(c1.editable?(@user)).to be_truthy end @@ -83,7 +83,7 @@ def set_priority(name, value) end before do - @user = FactoryGirl.create(:user_with_group, 'name' => 'Fred') + @user = FactoryBot.create(:user_with_group, 'name' => 'Fred') model_data_dir = Rails.root.join("spec/models/miq_ae_class/data") EvmSpecHelper.import_yaml_model(File.join(model_data_dir, 'domain1'), "DOMAIN1") EvmSpecHelper.import_yaml_model(File.join(model_data_dir, 'domain2'), "DOMAIN2") @@ -177,13 +177,13 @@ def set_priority(name, value) context "#copy" do before do - @d1 = FactoryGirl.create(:miq_ae_namespace, :name => "domain1", :parent_id => nil, :priority => 1) - @ns1 = FactoryGirl.create(:miq_ae_namespace, :name => "ns1", :parent_id => @d1.id) - @cls1 = FactoryGirl.create(:miq_ae_class, :name => "cls1", :namespace_id => @ns1.id) - @cls2 = FactoryGirl.create(:miq_ae_class, :name => "cls2", :namespace_id => @ns1.id) + @d1 = FactoryBot.create(:miq_ae_namespace, :name => "domain1", :parent_id => nil, :priority => 1) + @ns1 = FactoryBot.create(:miq_ae_namespace, :name => "ns1", :parent_id => @d1.id) + @cls1 = FactoryBot.create(:miq_ae_class, :name => "cls1", :namespace_id => @ns1.id) + @cls2 = FactoryBot.create(:miq_ae_class, :name => "cls2", :namespace_id => @ns1.id) - @d2 = FactoryGirl.create(:miq_ae_domain, :name => "domain2", :priority => 2) - @ns2 = FactoryGirl.create(:miq_ae_namespace, :name => "ns2", :parent_id => @d2.id) + @d2 = FactoryBot.create(:miq_ae_domain, :name => "domain2", :priority => 2) + @ns2 = FactoryBot.create(:miq_ae_namespace, :name => "ns2", :parent_id => @d2.id) end it "copies classes under specified namespace" do @@ -293,8 +293,8 @@ def set_priority(name, value) context "state_machine_class tests" do before do - n1 = FactoryGirl.create(:miq_ae_system_domain, :name => 'ns1', :priority => 10) - @c1 = FactoryGirl.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") + n1 = FactoryBot.create(:miq_ae_system_domain, :name => 'ns1', :priority => 10) + @c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") end it "class with only state field" do diff --git a/spec/models/miq_ae_field_spec.rb b/spec/models/miq_ae_field_spec.rb index dbdf619ab1b..bf49831dfa5 100644 --- a/spec/models/miq_ae_field_spec.rb +++ b/spec/models/miq_ae_field_spec.rb @@ -42,7 +42,7 @@ context "legacy tests" do before do @c1 = MiqAeClass.create(:namespace => "TEST", :name => "fields_test") - @user = FactoryGirl.create(:user_with_group) + @user = FactoryBot.create(:user_with_group) end it "should enforce necessary parameters upon create" do @@ -159,16 +159,16 @@ end it "should return editable as false if the parent namespace/class is not editable" do - n1 = FactoryGirl.create(:miq_ae_system_domain, :tenant => User.current_tenant) - c1 = FactoryGirl.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") - f1 = FactoryGirl.create(:miq_ae_field, :class_id => c1.id, :name => "foo_field") + n1 = FactoryBot.create(:miq_ae_system_domain, :tenant => User.current_tenant) + c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") + f1 = FactoryBot.create(:miq_ae_field, :class_id => c1.id, :name => "foo_field") expect(f1.editable?(@user)).to be_falsey end it "should return editable as true if the parent namespace/class is editable" do - n1 = FactoryGirl.create(:miq_ae_domain, :tenant => @user.current_tenant) - c1 = FactoryGirl.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") - f1 = FactoryGirl.create(:miq_ae_field, :class_id => c1.id, :name => "foo_field") + n1 = FactoryBot.create(:miq_ae_domain, :tenant => @user.current_tenant) + c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") + f1 = FactoryBot.create(:miq_ae_field, :class_id => c1.id, :name => "foo_field") expect(f1.editable?(@user)).to be_truthy end end diff --git a/spec/models/miq_ae_instance_spec.rb b/spec/models/miq_ae_instance_spec.rb index fd1d2e44df9..9f1a547dfbf 100644 --- a/spec/models/miq_ae_instance_spec.rb +++ b/spec/models/miq_ae_instance_spec.rb @@ -1,7 +1,7 @@ describe MiqAeInstance do context "legacy tests" do before do - @user = FactoryGirl.create(:user_with_group) + @user = FactoryBot.create(:user_with_group) @c1 = MiqAeClass.create(:namespace => "TEST", :name => "instance_test") @fname1 = "field1" @f1 = @c1.ae_fields.create(:name => @fname1) @@ -141,19 +141,19 @@ end it "should return editable as false if the parent namespace/class is not editable" do - d1 = FactoryGirl.create(:miq_ae_system_domain, :tenant => User.current_tenant) - n1 = FactoryGirl.create(:miq_ae_namespace, :parent_id => d1.id) - c1 = FactoryGirl.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") - i1 = FactoryGirl.create(:miq_ae_instance, :class_id => c1.id, :name => "foo_instance") + d1 = FactoryBot.create(:miq_ae_system_domain, :tenant => User.current_tenant) + n1 = FactoryBot.create(:miq_ae_namespace, :parent_id => d1.id) + c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") + i1 = FactoryBot.create(:miq_ae_instance, :class_id => c1.id, :name => "foo_instance") expect(i1.editable?(@user)).to be_falsey end it "should return editable as true if the parent namespace/class is editable" do User.current_user = @user - d1 = FactoryGirl.create(:miq_ae_domain, :tenant => User.current_tenant) - n1 = FactoryGirl.create(:miq_ae_namespace, :parent_id => d1.id) - c1 = FactoryGirl.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") - i1 = FactoryGirl.create(:miq_ae_instance, :class_id => c1.id, :name => "foo_instance") + d1 = FactoryBot.create(:miq_ae_domain, :tenant => User.current_tenant) + n1 = FactoryBot.create(:miq_ae_namespace, :parent_id => d1.id) + c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") + i1 = FactoryBot.create(:miq_ae_instance, :class_id => c1.id, :name => "foo_instance") expect(i1.editable?(@user)).to be_truthy end end @@ -197,14 +197,14 @@ context "#copy" do before do - @d1 = FactoryGirl.create(:miq_ae_namespace, :name => "domain1", :parent_id => nil, :priority => 1) - @ns1 = FactoryGirl.create(:miq_ae_namespace, :name => "ns1", :parent_id => @d1.id) - @cls1 = FactoryGirl.create(:miq_ae_class, :name => "cls1", :namespace_id => @ns1.id) - @i1 = FactoryGirl.create(:miq_ae_instance, :class_id => @cls1.id, :name => "foo_instance1") - @i2 = FactoryGirl.create(:miq_ae_instance, :class_id => @cls1.id, :name => "foo_instance2") + @d1 = FactoryBot.create(:miq_ae_namespace, :name => "domain1", :parent_id => nil, :priority => 1) + @ns1 = FactoryBot.create(:miq_ae_namespace, :name => "ns1", :parent_id => @d1.id) + @cls1 = FactoryBot.create(:miq_ae_class, :name => "cls1", :namespace_id => @ns1.id) + @i1 = FactoryBot.create(:miq_ae_instance, :class_id => @cls1.id, :name => "foo_instance1") + @i2 = FactoryBot.create(:miq_ae_instance, :class_id => @cls1.id, :name => "foo_instance2") - @d2 = FactoryGirl.create(:miq_ae_domain, :name => "domain2", :priority => 2) - @ns2 = FactoryGirl.create(:miq_ae_namespace, :name => "ns2", :parent_id => @d2.id) + @d2 = FactoryBot.create(:miq_ae_domain, :name => "domain2", :priority => 2) + @ns2 = FactoryBot.create(:miq_ae_namespace, :name => "ns2", :parent_id => @d2.id) end it "copies instances under specified namespace" do @@ -244,9 +244,9 @@ end it "#domain" do - n1 = FactoryGirl.create(:miq_ae_system_domain, :name => 'dom1') - c1 = FactoryGirl.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") - i1 = FactoryGirl.create(:miq_ae_instance, :class_id => c1.id, :name => "foo_instance") + n1 = FactoryBot.create(:miq_ae_system_domain, :name => 'dom1') + c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") + i1 = FactoryBot.create(:miq_ae_instance, :class_id => c1.id, :name => "foo_instance") expect(i1.domain.name).to eql('dom1') end end diff --git a/spec/models/miq_ae_method_spec.rb b/spec/models/miq_ae_method_spec.rb index e2ed475ced0..3c326e13958 100644 --- a/spec/models/miq_ae_method_spec.rb +++ b/spec/models/miq_ae_method_spec.rb @@ -1,9 +1,9 @@ describe MiqAeMethod do - let(:user) { FactoryGirl.create(:user_with_group) } + let(:user) { FactoryBot.create(:user_with_group) } it "should return editable as false if the parent namespace/class is not editable" do - n1 = FactoryGirl.create(:miq_ae_system_domain, :tenant => user.current_tenant) - c1 = FactoryGirl.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") - f1 = FactoryGirl.create(:miq_ae_method, + n1 = FactoryBot.create(:miq_ae_system_domain, :tenant => user.current_tenant) + c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") + f1 = FactoryBot.create(:miq_ae_method, :class_id => c1.id, :name => "foo_method", :scope => "instance", @@ -13,9 +13,9 @@ end it "should return editable as true if the parent namespace/class is editable" do - n1 = FactoryGirl.create(:miq_ae_domain, :tenant => user.current_tenant) - c1 = FactoryGirl.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") - f1 = FactoryGirl.create(:miq_ae_method, + n1 = FactoryBot.create(:miq_ae_domain, :tenant => user.current_tenant) + c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") + f1 = FactoryBot.create(:miq_ae_method, :class_id => c1.id, :name => "foo_method", :scope => "instance", @@ -25,14 +25,14 @@ end context "#copy" do - let(:d2) { FactoryGirl.create(:miq_ae_domain, :name => "domain2", :priority => 2) } - let(:ns1) { FactoryGirl.create(:miq_ae_namespace, :name => "ns1", :parent_id => @d1.id) } - let(:m1) { FactoryGirl.create(:miq_ae_method, :class_id => @cls1.id, :name => "foo_method1", :scope => "instance", :language => "ruby", :location => "inline") } - let(:m2) { FactoryGirl.create(:miq_ae_method, :class_id => @cls1.id, :name => "foo_method2", :scope => "instance", :language => "ruby", :location => "inline") } + let(:d2) { FactoryBot.create(:miq_ae_domain, :name => "domain2", :priority => 2) } + let(:ns1) { FactoryBot.create(:miq_ae_namespace, :name => "ns1", :parent_id => @d1.id) } + let(:m1) { FactoryBot.create(:miq_ae_method, :class_id => @cls1.id, :name => "foo_method1", :scope => "instance", :language => "ruby", :location => "inline") } + let(:m2) { FactoryBot.create(:miq_ae_method, :class_id => @cls1.id, :name => "foo_method2", :scope => "instance", :language => "ruby", :location => "inline") } before do - @d1 = FactoryGirl.create(:miq_ae_namespace, :name => "domain1", :parent_id => nil, :priority => 1) - @cls1 = FactoryGirl.create(:miq_ae_class, :name => "cls1", :namespace_id => ns1.id) - @ns2 = FactoryGirl.create(:miq_ae_namespace, :name => "ns2", :parent_id => d2.id) + @d1 = FactoryBot.create(:miq_ae_namespace, :name => "domain1", :parent_id => nil, :priority => 1) + @cls1 = FactoryBot.create(:miq_ae_class, :name => "cls1", :namespace_id => ns1.id) + @ns2 = FactoryBot.create(:miq_ae_namespace, :name => "ns2", :parent_id => d2.id) end it "copies instances under specified namespace" do @@ -102,10 +102,10 @@ end it "#domain" do - d1 = FactoryGirl.create(:miq_ae_system_domain, :name => 'dom1', :priority => 10) - n1 = FactoryGirl.create(:miq_ae_namespace, :name => 'ns1', :parent_id => d1.id) - c1 = FactoryGirl.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") - m1 = FactoryGirl.create(:miq_ae_method, + d1 = FactoryBot.create(:miq_ae_system_domain, :name => 'dom1', :priority => 10) + n1 = FactoryBot.create(:miq_ae_namespace, :name => 'ns1', :parent_id => d1.id) + c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") + m1 = FactoryBot.create(:miq_ae_method, :class_id => c1.id, :name => "foo_method", :scope => "instance", @@ -115,10 +115,10 @@ end it "#to_export_yaml" do - d1 = FactoryGirl.create(:miq_ae_system_domain, :name => 'dom1', :priority => 10) - n1 = FactoryGirl.create(:miq_ae_namespace, :name => 'ns1', :parent_id => d1.id) - c1 = FactoryGirl.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") - m1 = FactoryGirl.create(:miq_ae_method, + d1 = FactoryBot.create(:miq_ae_system_domain, :name => 'dom1', :priority => 10) + n1 = FactoryBot.create(:miq_ae_namespace, :name => 'ns1', :parent_id => d1.id) + c1 = FactoryBot.create(:miq_ae_class, :namespace_id => n1.id, :name => "foo") + m1 = FactoryBot.create(:miq_ae_method, :class_id => c1.id, :name => "foo_method", :scope => "instance", diff --git a/spec/models/miq_ae_namespace_spec.rb b/spec/models/miq_ae_namespace_spec.rb index a9e97c26159..06a0b5def32 100644 --- a/spec/models/miq_ae_namespace_spec.rb +++ b/spec/models/miq_ae_namespace_spec.rb @@ -33,18 +33,18 @@ end context "with a duplicite names" do - let(:domain) { FactoryGirl.create(:miq_ae_domain) } - let(:ns1) { FactoryGirl.create(:miq_ae_namespace, :name => 'ns1', :parent_id => domain.id) } + let(:domain) { FactoryBot.create(:miq_ae_domain) } + let(:ns1) { FactoryBot.create(:miq_ae_namespace, :name => 'ns1', :parent_id => domain.id) } before do - FactoryGirl.create(:miq_ae_namespace, :name => 'namespace', :parent_id => ns1.id) + FactoryBot.create(:miq_ae_namespace, :name => 'namespace', :parent_id => ns1.id) end it "with a distinct path is allowed" do # domain/ns1/namespace # domain/ns2/namespace - ns2 = FactoryGirl.create(:miq_ae_namespace, :name => 'ns2', :parent_id => domain.id) - dup_namespace = FactoryGirl.create(:miq_ae_namespace, :name => 'namespace', :parent_id => ns2.id) + ns2 = FactoryBot.create(:miq_ae_namespace, :name => 'ns2', :parent_id => domain.id) + dup_namespace = FactoryBot.create(:miq_ae_namespace, :name => 'namespace', :parent_id => ns2.id) expect(ns2.valid?).to be_truthy expect(dup_namespace.valid?).to be_truthy @@ -54,14 +54,14 @@ # domain/ns1/namespace # domain/ns1/NAMESPACE expect do - FactoryGirl.create(:miq_ae_namespace, :name => 'NAMESPACE', :parent_id => ns1.id) + FactoryBot.create(:miq_ae_namespace, :name => 'NAMESPACE', :parent_id => ns1.id) end.to raise_error("Validation failed: MiqAeNamespace: Name has already been taken") end end end before do - @user = FactoryGirl.create(:user_with_group) + @user = FactoryBot.create(:user_with_group) end it "should find or create namespaces by fqname" do @@ -89,7 +89,7 @@ end it "should return editable as false if the parent has the system property set to true" do - n1 = FactoryGirl.create(:miq_ae_system_domain, :tenant => @user.current_tenant) + n1 = FactoryBot.create(:miq_ae_system_domain, :tenant => @user.current_tenant) expect(n1.editable?(@user)).to be_falsey n2 = MiqAeNamespace.create!(:name => 'ns2', :parent_id => n1.id) @@ -99,12 +99,12 @@ end it "should return editable as true if the namespace doesn't have the system property defined" do - n1 = FactoryGirl.create(:miq_ae_domain, :tenant => @user.current_tenant) + n1 = FactoryBot.create(:miq_ae_domain, :tenant => @user.current_tenant) expect(n1.editable?(@user)).to be_truthy end it "should raise exception if user is nil" do - n1 = FactoryGirl.create(:miq_ae_domain, :tenant => @user.current_tenant) + n1 = FactoryBot.create(:miq_ae_domain, :tenant => @user.current_tenant) expect { n1.editable?(nil) }.to raise_error(ArgumentError) end diff --git a/spec/models/miq_alert_eval_internal_spec.rb b/spec/models/miq_alert_eval_internal_spec.rb index 35563bdb1ef..81714e20082 100644 --- a/spec/models/miq_alert_eval_internal_spec.rb +++ b/spec/models/miq_alert_eval_internal_spec.rb @@ -1,16 +1,16 @@ describe "MiqAlert Evaluation Internal" do context "With VM as a target," do before do - @vm = FactoryGirl.create(:vm_vmware) + @vm = FactoryBot.create(:vm_vmware) end context "evaluating an event threshold alert" do before do @events = [] - @events << FactoryGirl.create(:ems_event, :vm_or_template_id => @vm.id, :event_type => "MigrateVM_Task_Complete", :timestamp => Time.now.utc) - @events << FactoryGirl.create(:ems_event, :vm_or_template_id => @vm.id, :event_type => "MigrateVM_Task_Complete", :timestamp => 1.day.ago.utc) - @events << FactoryGirl.create(:ems_event, :vm_or_template_id => @vm.id, :event_type => "MigrateVM_Task_Complete", :timestamp => 2.days.ago.utc) - @events << FactoryGirl.create(:ems_event, :vm_or_template_id => @vm.id, :event_type => "MigrateVM_Task_Complete", :timestamp => 3.days.ago.utc) + @events << FactoryBot.create(:ems_event, :vm_or_template_id => @vm.id, :event_type => "MigrateVM_Task_Complete", :timestamp => Time.now.utc) + @events << FactoryBot.create(:ems_event, :vm_or_template_id => @vm.id, :event_type => "MigrateVM_Task_Complete", :timestamp => 1.day.ago.utc) + @events << FactoryBot.create(:ems_event, :vm_or_template_id => @vm.id, :event_type => "MigrateVM_Task_Complete", :timestamp => 2.days.ago.utc) + @events << FactoryBot.create(:ems_event, :vm_or_template_id => @vm.id, :event_type => "MigrateVM_Task_Complete", :timestamp => 3.days.ago.utc) expression = { :eval_method => "event_threshold", @@ -19,8 +19,8 @@ :event_types => ["MigrateVM_Task_Complete"], :freq_threshold => 3, :time_threshold => 3.days}} - @alert = FactoryGirl.create(:miq_alert_vm, :expression => expression) - @alert_prof = FactoryGirl.create(:miq_alert_set_vm) + @alert = FactoryBot.create(:miq_alert_vm, :expression => expression) + @alert_prof = FactoryBot.create(:miq_alert_set_vm) @alert_prof.add_member(@alert) @alert_prof.assign_to_objects(@vm) end @@ -35,7 +35,7 @@ before do t = 2.minutes.ago.utc 6.times do |i| - FactoryGirl.create(:metric_vm_rt, :resource_id => @vm.id, :timestamp => t, :mem_vmmemctl_absolute_average => (250 + (i * 10))) + FactoryBot.create(:metric_vm_rt, :resource_id => @vm.id, :timestamp => t, :mem_vmmemctl_absolute_average => (250 + (i * 10))) t += 20.seconds end @@ -49,8 +49,8 @@ :rt_time_threshold => 60, :trend_direction => 'none', :debug_trace => 'false'}} - @alert = FactoryGirl.create(:miq_alert_vm, :expression => expression) - @alert_prof = FactoryGirl.create(:miq_alert_set_vm) + @alert = FactoryBot.create(:miq_alert_vm, :expression => expression) + @alert_prof = FactoryBot.create(:miq_alert_set_vm) @alert_prof.add_member(@alert) @alert_prof.assign_to_objects(@vm) end @@ -70,8 +70,8 @@ :options => { :operator => "Changed", :hdw_attr => :cpu_affinity}} - @alert = FactoryGirl.create(:miq_alert_vm, :expression => expression) - @alert_prof = FactoryGirl.create(:miq_alert_set_vm) + @alert = FactoryBot.create(:miq_alert_vm, :expression => expression) + @alert_prof = FactoryBot.create(:miq_alert_set_vm) @alert_prof.add_member(@alert) @alert_prof.assign_to_objects(@vm) end @@ -91,8 +91,8 @@ :options => { :operator => "Decreased", :hdw_attr => "memory_mb"}} - @alert = FactoryGirl.create(:miq_alert_vm, :expression => expression) - @alert_prof = FactoryGirl.create(:miq_alert_set_vm) + @alert = FactoryBot.create(:miq_alert_vm, :expression => expression) + @alert_prof = FactoryBot.create(:miq_alert_set_vm) @alert_prof.add_member(@alert) @alert_prof.assign_to_objects(@vm) end @@ -118,8 +118,8 @@ :event_log_event_id => "12345", :time_threshold => 86400, :event_log_level => "fatal"}} - @alert = FactoryGirl.create(:miq_alert_vm, :expression => expression) - @alert_prof = FactoryGirl.create(:miq_alert_set_vm) + @alert = FactoryBot.create(:miq_alert_vm, :expression => expression) + @alert_prof = FactoryBot.create(:miq_alert_set_vm) @alert_prof.add_member(@alert) @alert_prof.assign_to_objects(@vm) end @@ -140,8 +140,8 @@ :ems_alarm_name => "GT VM CPU Usage", :ems_alarm_mor => "alarm-7" }} - @alert = FactoryGirl.create(:miq_alert_vm, :expression => expression) - @alert_prof = FactoryGirl.create(:miq_alert_set_vm) + @alert = FactoryBot.create(:miq_alert_vm, :expression => expression) + @alert_prof = FactoryBot.create(:miq_alert_set_vm) @alert_prof.add_member(@alert) @alert_prof.assign_to_objects(@vm) end @@ -155,7 +155,7 @@ context "With Host as a target," do before do - @host = FactoryGirl.create(:host) + @host = FactoryBot.create(:host) end context "evaluating a hostd log threshold alert" do @@ -171,8 +171,8 @@ :event_log_message_filter_value => "exceeds soft limit", :time_threshold => 86400, :event_log_level => "warn"}} - @alert = FactoryGirl.create(:miq_alert_vm, :expression => expression) - @alert_prof = FactoryGirl.create(:miq_alert_set_host) + @alert = FactoryBot.create(:miq_alert_vm, :expression => expression) + @alert_prof = FactoryBot.create(:miq_alert_set_host) @alert_prof.add_member(@alert) @alert_prof.assign_to_objects(@host) end @@ -186,14 +186,14 @@ context "With MiqServer as a target," do before do - @server = FactoryGirl.create(:miq_server, :zone => FactoryGirl.create(:zone)) + @server = FactoryBot.create(:miq_server, :zone => FactoryBot.create(:zone)) end context "evaluating an alert with no expression" do before do expression = {:eval_method => "nothing"} - @alert = FactoryGirl.create(:miq_alert_vm, :expression => expression) - @alert_prof = FactoryGirl.create(:miq_alert_set, :mode => @server.class.name) + @alert = FactoryBot.create(:miq_alert_vm, :expression => expression) + @alert_prof = FactoryBot.create(:miq_alert_set, :mode => @server.class.name) @alert_prof.add_member(@alert) @alert_prof.assign_to_objects(@server) end diff --git a/spec/models/miq_alert_spec.rb b/spec/models/miq_alert_spec.rb index 6a315ee0dbe..e49eb40261a 100644 --- a/spec/models/miq_alert_spec.rb +++ b/spec/models/miq_alert_spec.rb @@ -2,15 +2,15 @@ context "With single server with a single generic worker with the notifier role," do before do @miq_server = EvmSpecHelper.local_miq_server(:role => 'notifier') - @worker = FactoryGirl.create(:miq_worker, :miq_server_id => @miq_server.id) - @vm = FactoryGirl.create(:vm_vmware) + @worker = FactoryBot.create(:miq_worker, :miq_server_id => @miq_server.id) + @vm = FactoryBot.create(:vm_vmware) MiqAlert.seed @events_to_alerts = MiqAlert.all.inject([]) do |arr, a| next(arr) if a.responds_to_events.nil? next(arr) unless a.db == "Vm" - ap = FactoryGirl.create(:miq_alert_set_vm, :alerts => [a]) + ap = FactoryBot.create(:miq_alert_set_vm, :alerts => [a]) ap.assign_to_objects(@vm) events = a.responds_to_events.split(",") @@ -110,12 +110,12 @@ it "should update the existing status on susesquent evaluations" do @alert.evaluate( [@vm.class.base_class.name, @vm.id], - :ems_event => FactoryGirl.create(:ems_event) + :ems_event => FactoryBot.create(:ems_event) ) Timecop.travel 10.minutes do @alert.evaluate( [@vm.class.base_class.name, @vm.id], - :ems_event => FactoryGirl.create(:ems_event) + :ems_event => FactoryBot.create(:ems_event) ) statuses = @alert.miq_alert_statuses.where(:resource_type => @vm.class.base_class.name, :resource_id => @vm.id) expect(statuses.length).to eq(1) @@ -125,12 +125,12 @@ it "should update the existing status if event has the same ems_ref" do @alert.evaluate( [@vm.class.base_class.name, @vm.id], - :ems_event => FactoryGirl.create(:ems_event, :ems_ref => 'same') + :ems_event => FactoryBot.create(:ems_event, :ems_ref => 'same') ) Timecop.travel 10.minutes do @alert.evaluate( [@vm.class.base_class.name, @vm.id], - :ems_event => FactoryGirl.create(:ems_event, :ems_ref => 'same') + :ems_event => FactoryBot.create(:ems_event, :ems_ref => 'same') ) statuses = @alert.miq_alert_statuses.where(:resource_type => @vm.class.base_class.name, :resource_id => @vm.id) expect(statuses.length).to eq(1) @@ -140,12 +140,12 @@ it "should create a new status if event has a different ems_ref" do @alert.evaluate( [@vm.class.base_class.name, @vm.id], - :ems_event => FactoryGirl.create(:ems_event, :ems_ref => 'same') + :ems_event => FactoryBot.create(:ems_event, :ems_ref => 'same') ) Timecop.travel 10.minutes do @alert.evaluate( [@vm.class.base_class.name, @vm.id], - :ems_event => FactoryGirl.create(:ems_event, :ems_ref => 'different') + :ems_event => FactoryBot.create(:ems_event, :ems_ref => 'different') ) statuses = @alert.miq_alert_statuses.where(:resource_type => @vm.class.base_class.name, :resource_id => @vm.id) expect(statuses.length).to eq(2) @@ -159,7 +159,7 @@ it "miq_alert_status.description = miq_alert.description event if overriden by ems_event.description" do @alert.evaluate( [@vm.class.base_class.name, @vm.id], - :ems_event => FactoryGirl.create(:ems_event, :message => "oh no!") + :ems_event => FactoryBot.create(:ems_event, :message => "oh no!") ) mas = @alert.miq_alert_statuses.where(:resource_type => @vm.class.base_class.name, :resource_id => @vm.id).first expect(mas.description).to eq("VM Unregistered") @@ -168,7 +168,7 @@ it "miq_alert_status.description = ems_event.message if present and datawarehouse_alert" do @alert.evaluate( [@vm.class.base_class.name, @vm.id], - :ems_event => FactoryGirl.create(:ems_event, :message => "oh no!", :event_type => "datawarehouse_alert") + :ems_event => FactoryBot.create(:ems_event, :message => "oh no!", :event_type => "datawarehouse_alert") ) mas = @alert.miq_alert_statuses.where(:resource_type => @vm.class.base_class.name, :resource_id => @vm.id).first expect(mas.description).to eq("oh no!") @@ -177,7 +177,7 @@ it "miq_alert_status.severity = ems_event.full_data.severity if present" do @alert.evaluate( [@vm.class.base_class.name, @vm.id], - :ems_event => FactoryGirl.create(:ems_event, :full_data => {:severity => 'warning'}) + :ems_event => FactoryBot.create(:ems_event, :full_data => {:severity => 'warning'}) ) mas = @alert.miq_alert_statuses.where(:resource_type => @vm.class.base_class.name, :resource_id => @vm.id).first expect(mas.severity).to eq('warning') @@ -187,7 +187,7 @@ @alert.severity = "error" @alert.evaluate( [@vm.class.base_class.name, @vm.id], - :ems_event => FactoryGirl.create(:ems_event, :full_data => {}) + :ems_event => FactoryBot.create(:ems_event, :full_data => {}) ) mas = @alert.miq_alert_statuses.where(:resource_type => @vm.class.base_class.name, :resource_id => @vm.id).first expect(mas.severity).to eq('error') @@ -197,7 +197,7 @@ @alert.severity = "error" @alert.evaluate( [@vm.class.base_class.name, @vm.id], - :ems_event => FactoryGirl.create(:ems_event, :full_data => {:severity => 'info'}) + :ems_event => FactoryBot.create(:ems_event, :full_data => {:severity => 'info'}) ) mas = @alert.miq_alert_statuses.where(:resource_type => @vm.class.base_class.name, :resource_id => @vm.id).first expect(mas.severity).to eq('info') @@ -213,7 +213,7 @@ expect do @alert.evaluate( [@vm.class.base_class.name, @vm.id], - :ems_event => FactoryGirl.create(:ems_event, :full_data => {:severity => 'undefined'}) + :ems_event => FactoryBot.create(:ems_event, :full_data => {:severity => 'undefined'}) ) end.to raise_error(ActiveRecord::RecordInvalid) end @@ -221,7 +221,7 @@ it "miq_alert_status.url = ems_event.full_data.url if present" do @alert.evaluate( [@vm.class.base_class.name, @vm.id], - :ems_event => FactoryGirl.create( + :ems_event => FactoryBot.create( :ems_event, :full_data => {:url => 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'} ) @@ -322,16 +322,16 @@ describe ".assigned_to_target" do it "gets assignment by tagged VM" do - cat = FactoryGirl.create(:classification, :description => "Environment", :name => "environment", :single_value => true, :parent_id => 0) - FactoryGirl.create(:classification, :name => "prod", :description => "Production", :parent_id => cat.id) + cat = FactoryBot.create(:classification, :description => "Environment", :name => "environment", :single_value => true, :parent_id => 0) + FactoryBot.create(:classification, :name => "prod", :description => "Production", :parent_id => cat.id) - @vm = FactoryGirl.create(:vm_vmware) + @vm = FactoryBot.create(:vm_vmware) @mode = @vm.class.base_model.name @c = Classification.where(:description => "Production").first @c.assign_entry_to(@vm) - @alert = FactoryGirl.create(:miq_alert_vm) - @ap = FactoryGirl.create(:miq_alert_set_vm, :alerts =>[@alert]) + @alert = FactoryBot.create(:miq_alert_vm) + @ap = FactoryBot.create(:miq_alert_set_vm, :alerts =>[@alert]) @ap.assign_to_tags([@c.id], @mode) expect(MiqAlert.assigned_to_target(@vm)).to eq([@alert]) @@ -344,24 +344,24 @@ end let(:vm_alert_set) do - alert = FactoryGirl.create(:miq_alert_vm, :responds_to_events => "xxx|vm_perf_complete|zzz") - FactoryGirl.create(:miq_alert_set_vm, :alerts => [alert]) + alert = FactoryBot.create(:miq_alert_vm, :responds_to_events => "xxx|vm_perf_complete|zzz") + FactoryBot.create(:miq_alert_set_vm, :alerts => [alert]) end let(:host_alert_set) do - alert = FactoryGirl.create(:miq_alert_host, :responds_to_events => "xxx|host_perf_complete|zzz") - FactoryGirl.create(:miq_alert_set_host, :alerts => [alert]) + alert = FactoryBot.create(:miq_alert_host, :responds_to_events => "xxx|host_perf_complete|zzz") + FactoryBot.create(:miq_alert_set_host, :alerts => [alert]) end it "detects true with a VM assigned to a realtime C&U alert" do - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) vm_alert_set.assign_to_objects(vm) expect(MiqAlert.target_needs_realtime_capture?(vm)).to be_truthy end it "detects false with a VM NOT assigned to a realtime C&U alert" do - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) expect(MiqAlert.target_needs_realtime_capture?(vm)).to be_falsey end @@ -369,36 +369,36 @@ it "detects true with a VM's ems assigned to a realtime C&U alert" do allow_any_instance_of(MiqAlert).to receive_messages(:validate => true) - ems = FactoryGirl.create(:ems_vmware) - vm = FactoryGirl.create(:vm_vmware, :ext_management_system => ems) + ems = FactoryBot.create(:ems_vmware) + vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems) vm_alert_set.assign_to_objects(ems) expect(MiqAlert.target_needs_realtime_capture?(vm)).to be_truthy end it "detects true with a Host assigned to a realtime C&U alert" do - host = FactoryGirl.create(:host) + host = FactoryBot.create(:host) host_alert_set.assign_to_objects(host) expect(MiqAlert.target_needs_realtime_capture?(host)).to be_truthy end it "detects true with a Host's cluster assigned to a realtime C&U alert" do - cluster = FactoryGirl.create(:ems_cluster) - host = FactoryGirl.create(:host, :ems_cluster => cluster) + cluster = FactoryBot.create(:ems_cluster) + host = FactoryBot.create(:host, :ems_cluster => cluster) host_alert_set.assign_to_objects(cluster) expect(MiqAlert.target_needs_realtime_capture?(host)).to be_truthy end it "detects false with a Host NOT assigned to a realtime C&U alert" do - host = FactoryGirl.create(:host) + host = FactoryBot.create(:host) expect(MiqAlert.target_needs_realtime_capture?(host)).to be_falsey end it "detects true with a VM assigned to a v4-style realtime C&U alert" do - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) # V4 code is actually the same here -- assign_to_objects -- but # this forces the namespace to use actual model class name # rather than base_class @@ -408,7 +408,7 @@ end it "detects true with a Host assigned to a v4-style realtime C&U alert" do - host = FactoryGirl.create(:host) + host = FactoryBot.create(:host) # V4 code is actually the same here -- assign_to_objects -- but # this forces the namespace to use actual model class name # rather than base_class @@ -418,14 +418,14 @@ end let(:classification) do - env = FactoryGirl.create(:classification, :name => "env", :single_value => 1) - FactoryGirl.create(:classification_tag, :name => "good", :parent => env) + env = FactoryBot.create(:classification, :name => "env", :single_value => 1) + FactoryBot.create(:classification_tag, :name => "good", :parent => env) end let(:tag) { classification.tag } it "detects with a shared tag on a Vm" do - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) vm.tag_add(tag.name, :ns => "") vm.reload # reload ensures the tag is set @@ -436,8 +436,8 @@ end it "doesnt detects with a shared tag assigned to a Vm's ems" do - ems = FactoryGirl.create(:ems_vmware) - vm = FactoryGirl.create(:vm_vmware, :ext_management_system => ems) + ems = FactoryBot.create(:ems_vmware) + vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems) ems.tag_add(tag.name, :ns => "") ems.reload # reload ensures the tag is set @@ -452,11 +452,11 @@ before do allow_any_instance_of(MiqAlert).to receive_messages(:validate => true) @miq_server = EvmSpecHelper.local_miq_server - @ems = FactoryGirl.create(:ems_vmware, :zone => @miq_server.zone) - @ems_other = FactoryGirl.create(:ems_vmware, :zone => FactoryGirl.create(:zone, :name => 'other')) - @ems_kub = FactoryGirl.create(:ems_kubernetes, :zone => @miq_server.zone) - @alert = FactoryGirl.create(:miq_alert, :responds_to_events => "_hourly_timer_") - @alert_prof = FactoryGirl.create(:miq_alert_set, :alerts => [@alert]) + @ems = FactoryBot.create(:ems_vmware, :zone => @miq_server.zone) + @ems_other = FactoryBot.create(:ems_vmware, :zone => FactoryBot.create(:zone, :name => 'other')) + @ems_kub = FactoryBot.create(:ems_kubernetes, :zone => @miq_server.zone) + @alert = FactoryBot.create(:miq_alert, :responds_to_events => "_hourly_timer_") + @alert_prof = FactoryBot.create(:miq_alert_set, :alerts => [@alert]) end it "evaluates for ext_management_system" do @@ -470,9 +470,9 @@ end it "evaluates for vm" do - vm_in_zone = FactoryGirl.create(:vm_vmware, :ext_management_system => @ems) - vm_in_other = FactoryGirl.create(:vm_vmware, :ext_management_system => @ems_other) - vm_no_ems = FactoryGirl.create(:vm_vmware) + vm_in_zone = FactoryBot.create(:vm_vmware, :ext_management_system => @ems) + vm_in_other = FactoryBot.create(:vm_vmware, :ext_management_system => @ems_other) + vm_no_ems = FactoryBot.create(:vm_vmware) @alert.update_attributes(:db => "Vm") @alert_prof.mode = vm_in_zone.class.base_model.name @alert_prof.assign_to_objects(vm_in_zone.id, "Vm") @@ -484,16 +484,16 @@ end it "evaluates for storage" do - storage_in_zone = FactoryGirl.create(:storage_vmware) - FactoryGirl.create(:host, :ext_management_system => @ems, :storages => [storage_in_zone]) + storage_in_zone = FactoryBot.create(:storage_vmware) + FactoryBot.create(:host, :ext_management_system => @ems, :storages => [storage_in_zone]) - storage_in_another = FactoryGirl.create(:storage_vmware) - FactoryGirl.create(:host, :ext_management_system => @ems_other, :storages => [storage_in_another]) + storage_in_another = FactoryBot.create(:storage_vmware) + FactoryBot.create(:host, :ext_management_system => @ems_other, :storages => [storage_in_another]) - storage_in_host_no_ems = FactoryGirl.create(:storage_vmware) - FactoryGirl.create(:host, :storages => [storage_in_host_no_ems]) + storage_in_host_no_ems = FactoryBot.create(:storage_vmware) + FactoryBot.create(:host, :storages => [storage_in_host_no_ems]) - storage_no_ems = FactoryGirl.create(:storage_vmware) + storage_no_ems = FactoryBot.create(:storage_vmware) @alert.update_attributes(:db => "Storage") @alert_prof.mode = storage_in_zone.class.base_model.name @@ -508,7 +508,7 @@ it "evaluates for container entities" do [:container_node, :container_group, :container_replicator, :container].each do |entity| - container_entity_in_zone = FactoryGirl.create(entity, :ext_management_system => @ems_kub) + container_entity_in_zone = FactoryBot.create(entity, :ext_management_system => @ems_kub) @alert.update_attributes(:db => entity.to_s.camelize) @alert_prof.mode = container_entity_in_zone.class.base_model.name @alert_prof.assign_to_objects(container_entity_in_zone.id, entity.to_s.camelize) @@ -521,14 +521,14 @@ describe 'Mangement Event' do before do @miq_server = EvmSpecHelper.local_miq_server - @vm = FactoryGirl.create(:vm_vmware) - @alert = FactoryGirl.create( + @vm = FactoryBot.create(:vm_vmware) + @alert = FactoryBot.create( :miq_alert_vm, :options => {:notifications => {:automate => {:event_name => 'test_event_alert'}}}, :expression => {:eval_method => "nothing", :mode => "internal", :options => {}}, :responds_to_events => "request_vm_poweroff" ) - @alert_prof = FactoryGirl.create(:miq_alert_set_vm, :alerts => [@alert]) + @alert_prof = FactoryBot.create(:miq_alert_set_vm, :alerts => [@alert]) @alert_prof.assign_to_objects(@vm) end @@ -562,7 +562,7 @@ describe '.validate_automate_expressions' do it 'Does not allow creation of dwh_generic miq_alerts with delay_next_evaluation > 0 ' do expect do - FactoryGirl.create( + FactoryBot.create( :miq_alert, :options => {:notifications => {:delay_next_evaluation => 600, :evm_event => {}}}, :expression => {:eval_method => "dwh_generic"} diff --git a/spec/models/miq_alert_status_action_spec.rb b/spec/models/miq_alert_status_action_spec.rb index 1929fbac68a..5f7871f7ce0 100644 --- a/spec/models/miq_alert_status_action_spec.rb +++ b/spec/models/miq_alert_status_action_spec.rb @@ -1,53 +1,53 @@ describe MiqAlertStatusAction do - let(:alert) { FactoryGirl.create(:miq_alert_status) } - let(:user) { FactoryGirl.create(:user) } - let(:user2) { FactoryGirl.create(:user, :name => 'user2') } + let(:alert) { FactoryBot.create(:miq_alert_status) } + let(:user) { FactoryBot.create(:user) } + let(:user2) { FactoryBot.create(:user, :name => 'user2') } describe "Validation" do it "forbids unknown operations" do expect do - FactoryGirl.create(:miq_alert_status_action, :action_type => 'churn', :user => user, + FactoryBot.create(:miq_alert_status_action, :action_type => 'churn', :user => user, :miq_alert_status => alert) end.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: MiqAlertStatusAction: Action type must be accepted") end it "must be linked to a user" do expect do - FactoryGirl.create(:miq_alert_status_action, :action_type => 'unassign', :user => nil, + FactoryBot.create(:miq_alert_status_action, :action_type => 'unassign', :user => nil, :miq_alert_status => alert) end.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: MiqAlertStatusAction: User can't be blank") end it "must have a comment if the action_type is comment" do expect do - FactoryGirl.create(:miq_alert_status_action, :action_type => 'comment', :user => user, :comment => nil, + FactoryBot.create(:miq_alert_status_action, :action_type => 'comment', :user => user, :comment => nil, :miq_alert_status => alert) end.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: MiqAlertStatusAction: Comment can't be blank") end it "can have a comment if the action_type isn't comment" do expect do - FactoryGirl.create(:miq_alert_status_action, :action_type => 'unassign', :user => user, :comment => 'Nope.', + FactoryBot.create(:miq_alert_status_action, :action_type => 'unassign', :user => user, :comment => 'Nope.', :miq_alert_status => alert) end.to_not raise_error end it "cannot have an assignee if the action_type is not assign" do expect do - FactoryGirl.create(:miq_alert_status_action, :action_type => 'unassign', :user => user, :assignee => user, + FactoryBot.create(:miq_alert_status_action, :action_type => 'unassign', :user => user, :assignee => user, :miq_alert_status => alert) end.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: MiqAlertStatusAction: Assignee must be blank") end it "must have an assignee if the action_type is assign" do expect do - FactoryGirl.create(:miq_alert_status_action, :action_type => 'assign', :user => user, :assignee => nil, + FactoryBot.create(:miq_alert_status_action, :action_type => 'assign', :user => user, :assignee => nil, :miq_alert_status => alert) end.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: MiqAlertStatusAction: Assignee can't be blank") end it "should allow the currently assigned user to acknoledge the alert" do - FactoryGirl.create( + FactoryBot.create( :miq_alert_status_action, :action_type => 'assign', :assignee => user, @@ -55,7 +55,7 @@ :miq_alert_status => alert ) expect do - FactoryGirl.create( + FactoryBot.create( :miq_alert_status_action, :action_type => 'acknowledge', :user => user, @@ -65,7 +65,7 @@ end it "should not allow a user not assigned to acknoledge the alert" do - FactoryGirl.create( + FactoryBot.create( :miq_alert_status_action, :action_type => 'assign', :assignee => user, @@ -73,7 +73,7 @@ :miq_alert_status => alert ) expect do - FactoryGirl.create( + FactoryBot.create( :miq_alert_status_action, :action_type => 'acknowledge', :user => user2, diff --git a/spec/models/miq_alert_status_spec.rb b/spec/models/miq_alert_status_spec.rb index 88ba25345c6..5ef22aa8400 100644 --- a/spec/models/miq_alert_status_spec.rb +++ b/spec/models/miq_alert_status_spec.rb @@ -1,27 +1,27 @@ describe MiqAlertStatus do - let(:ems) { FactoryGirl.create(:ems_vmware, :name => 'ems') } - let(:alert) { FactoryGirl.create(:miq_alert_status) } - let(:user1) { FactoryGirl.create(:user, :name => 'user1') } - let(:user2) { FactoryGirl.create(:user, :name => 'user2') } + let(:ems) { FactoryBot.create(:ems_vmware, :name => 'ems') } + let(:alert) { FactoryBot.create(:miq_alert_status) } + let(:user1) { FactoryBot.create(:user, :name => 'user1') } + let(:user2) { FactoryBot.create(:user, :name => 'user2') } let(:acknowledgement_action) do - FactoryGirl.create(:miq_alert_status_action, :action_type => 'acknowledge', :user => user1, + FactoryBot.create(:miq_alert_status_action, :action_type => 'acknowledge', :user => user1, :miq_alert_status => alert) end let(:assignment_action) do - FactoryGirl.create(:miq_alert_status_action, :action_type => 'assign', :user => user1, :assignee => user1, + FactoryBot.create(:miq_alert_status_action, :action_type => 'assign', :user => user1, :assignee => user1, :miq_alert_status => alert) end let(:hide_action) do - FactoryGirl.create(:miq_alert_status_action, :action_type => 'hide', :user => user1, :miq_alert_status => alert) + FactoryBot.create(:miq_alert_status_action, :action_type => 'hide', :user => user1, :miq_alert_status => alert) end let(:show_action) do - FactoryGirl.create(:miq_alert_status_action, :action_type => 'show', :user => user1, :miq_alert_status => alert) + FactoryBot.create(:miq_alert_status_action, :action_type => 'show', :user => user1, :miq_alert_status => alert) end describe "Validation" do it "should reject unexpected severities" do expect do - FactoryGirl.create(:miq_alert_status, :severity => 'awesome') + FactoryBot.create(:miq_alert_status, :severity => 'awesome') end.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: MiqAlertStatus: Severity must be accepted") end end @@ -49,7 +49,7 @@ alert.miq_alert_status_actions << acknowledgement_action end Timecop.travel 2.minutes do - FactoryGirl.create( + FactoryBot.create( :miq_alert_status_action, :action_type => 'unacknowledge', :user => user1, @@ -66,7 +66,7 @@ alert.miq_alert_status_actions << acknowledgement_action end Timecop.travel 2.minutes do - alert.miq_alert_status_actions << FactoryGirl.create( + alert.miq_alert_status_actions << FactoryBot.create( :miq_alert_status_action, :action_type => 'assign', :user => user1, @@ -89,7 +89,7 @@ alert.miq_alert_status_actions = [assignment_action] expect(alert.assignee).to eq(user1) Timecop.travel 1.minute do - FactoryGirl.create( + FactoryBot.create( :miq_alert_status_action, :action_type => 'assign', :user => user1, @@ -100,7 +100,7 @@ alert.reload expect(alert.assignee).to eq(user2) Timecop.travel 2.minutes do - FactoryGirl.create( + FactoryBot.create( :miq_alert_status_action, :action_type => 'unassign', :user => user1, diff --git a/spec/models/miq_approval_spec.rb b/spec/models/miq_approval_spec.rb index 0cf8fc3121d..3f04ebb7a1c 100644 --- a/spec/models/miq_approval_spec.rb +++ b/spec/models/miq_approval_spec.rb @@ -1,7 +1,7 @@ describe MiqApproval do it "#approver= also sets approver_name" do - approval = FactoryGirl.build(:miq_approval) - user = FactoryGirl.create(:user) + approval = FactoryBot.build(:miq_approval) + user = FactoryBot.create(:user) expect(approval.approver_name).to be_nil @@ -14,16 +14,16 @@ context "#approve" do it "works" do - user = FactoryGirl.create(:user, :name => 'Fred Flintstone', :userid => 'fred') - approver = FactoryGirl.create(:user, :name => 'Wilma Flintstone', :userid => 'approver') + user = FactoryBot.create(:user, :name => 'Fred Flintstone', :userid => 'fred') + approver = FactoryBot.create(:user, :name => 'Wilma Flintstone', :userid => 'approver') - approval = FactoryGirl.create(:miq_approval) + approval = FactoryBot.create(:miq_approval) reason = "Why Not?" allow(approval).to receive(:authorized?).and_return(false) expect { approval.approve(approver, reason) }.to raise_error("not authorized") - miq_request = FactoryGirl.create(:vm_migrate_request, :requester => user) + miq_request = FactoryBot.create(:vm_migrate_request, :requester => user) approval.miq_request = miq_request allow(approval).to receive(:authorized?).and_return(true) Timecop.freeze do @@ -38,35 +38,35 @@ end it "with an approver's own request" do - vm_template = FactoryGirl.create(:template_vmware) - user = FactoryGirl.create(:user_miq_request_approver) - request = FactoryGirl.create(:miq_provision_request, :provision_type => 'template', :state => 'pending', :status => 'Ok', :src_vm_id => vm_template.id, :requester => user) - approval = FactoryGirl.create(:miq_approval, :miq_request => request) + vm_template = FactoryBot.create(:template_vmware) + user = FactoryBot.create(:user_miq_request_approver) + request = FactoryBot.create(:miq_provision_request, :provision_type => 'template', :state => 'pending', :status => 'Ok', :src_vm_id => vm_template.id, :requester => user) + approval = FactoryBot.create(:miq_approval, :miq_request => request) expect { approval.approve(user, 'Why Not') }.to_not raise_error end it "with an approver's object'" do - vm_template = FactoryGirl.create(:template_vmware) - user = FactoryGirl.create(:user_miq_request_approver) - request = FactoryGirl.create(:miq_provision_request, :provision_type => 'template', :state => 'pending', :status => 'Ok', :src_vm_id => vm_template.id, :requester => user) - approval = FactoryGirl.create(:miq_approval, :miq_request => request) + vm_template = FactoryBot.create(:template_vmware) + user = FactoryBot.create(:user_miq_request_approver) + request = FactoryBot.create(:miq_provision_request, :provision_type => 'template', :state => 'pending', :status => 'Ok', :src_vm_id => vm_template.id, :requester => user) + approval = FactoryBot.create(:miq_approval, :miq_request => request) expect { approval.approve(user, 'Why Not') }.to_not raise_error end end it "#deny" do - user = FactoryGirl.create(:user, :name => 'Fred Flintstone', :userid => 'fred') - approver = FactoryGirl.create(:user, :name => 'Wilma Flintstone', :userid => 'approver') + user = FactoryBot.create(:user, :name => 'Fred Flintstone', :userid => 'fred') + approver = FactoryBot.create(:user, :name => 'Wilma Flintstone', :userid => 'approver') - approval = FactoryGirl.create(:miq_approval) + approval = FactoryBot.create(:miq_approval) reason = "Why Not?" allow(approval).to receive(:authorized?).and_return(false) expect { approval.deny(approver, reason) }.to raise_error("not authorized") - miq_request = FactoryGirl.create(:vm_migrate_request, :requester => user) + miq_request = FactoryBot.create(:vm_migrate_request, :requester => user) approval.miq_request = miq_request allow(approval).to receive(:authorized?).and_return(true) Timecop.freeze do @@ -81,10 +81,10 @@ end context "#authorized?" do - let(:approval) { FactoryGirl.create(:miq_approval) } - let(:user) { FactoryGirl.create(:user, :userid => "user1") } - let(:user2) { FactoryGirl.create(:user, :userid => "user2") } - let(:approver) { FactoryGirl.create(:user_miq_request_approver) } + let(:approval) { FactoryBot.create(:miq_approval) } + let(:user) { FactoryBot.create(:user, :userid => "user1") } + let(:user2) { FactoryBot.create(:user, :userid => "user2") } + let(:approver) { FactoryBot.create(:user_miq_request_approver) } it "with nil" do expect(approval.authorized?(nil)).to be_falsey diff --git a/spec/models/miq_bulk_import_spec.rb b/spec/models/miq_bulk_import_spec.rb index 38403cfc064..281239dd55a 100644 --- a/spec/models/miq_bulk_import_spec.rb +++ b/spec/models/miq_bulk_import_spec.rb @@ -13,8 +13,8 @@ it ".upload" do @file = StringIO.new("name,owner\nJD-C-T4.0.1.44,Joe\nJD-C-T4.0.1.43,Jerry") - FactoryGirl.create(:vm_vmware, :name => "JD-C-T4.0.1.44") - FactoryGirl.create(:template_vmware, :name => "JD-C-T4.0.1.43") + FactoryBot.create(:vm_vmware, :name => "JD-C-T4.0.1.44") + FactoryBot.create(:template_vmware, :name => "JD-C-T4.0.1.43") ati = AssetTagImport.upload('VmOrTemplate', @file) expect(ati.stats[:good]).to eq(2) @@ -22,8 +22,8 @@ it "#apply" do @file = StringIO.new("name,owner\nJD-C-T4.0.1.44,Joe\nJD-C-T4.0.1.43,Jerry") - vm = FactoryGirl.create(:vm_vmware, :name => "JD-C-T4.0.1.44") - template = FactoryGirl.create(:template_vmware, :name => "JD-C-T4.0.1.43") + vm = FactoryBot.create(:vm_vmware, :name => "JD-C-T4.0.1.44") + template = FactoryBot.create(:template_vmware, :name => "JD-C-T4.0.1.43") ati = AssetTagImport.upload('VmOrTemplate', @file) ati.apply @@ -50,7 +50,7 @@ end it ".upload with no category" do - FactoryGirl.create(:vm_vmware, :name => "JD-C-T4.0.1.44") + FactoryBot.create(:vm_vmware, :name => "JD-C-T4.0.1.44") ci = ClassificationImport.upload(@file) expect(ci.stats[:bad]).to eq(1) expect(ci.stats[:good]).to eq(0) @@ -59,10 +59,10 @@ it ".upload" do @file = StringIO.new("name,category,entry\nJD-C-T4.0.1.44,Environment,Test\nJD-C-T4.0.1.43,Environment,Test") - category = FactoryGirl.create(:classification, :name => 'environment', :description => 'Environment') - FactoryGirl.create(:classification, :parent_id => category.id, :name => 'test', :description => 'Test') - FactoryGirl.create(:vm_vmware, :name => "JD-C-T4.0.1.44") - FactoryGirl.create(:template_vmware, :name => "JD-C-T4.0.1.43") + category = FactoryBot.create(:classification, :name => 'environment', :description => 'Environment') + FactoryBot.create(:classification, :parent_id => category.id, :name => 'test', :description => 'Test') + FactoryBot.create(:vm_vmware, :name => "JD-C-T4.0.1.44") + FactoryBot.create(:template_vmware, :name => "JD-C-T4.0.1.43") ci = ClassificationImport.upload(@file) expect(ci.stats[:bad]).to eq(0) expect(ci.stats[:good]).to eq(2) @@ -71,10 +71,10 @@ it "#apply" do @file = StringIO.new("name,category,entry\nJD-C-T4.0.1.44,Environment,Test\nJD-C-T4.0.1.43,Environment,Test") - category = FactoryGirl.create(:classification, :name => 'environment', :description => 'Environment') - FactoryGirl.create(:classification, :parent_id => category.id, :name => 'test', :description => 'Test') - vm = FactoryGirl.create(:vm_vmware, :name => "JD-C-T4.0.1.44") - template = FactoryGirl.create(:template_vmware, :name => "JD-C-T4.0.1.43") + category = FactoryBot.create(:classification, :name => 'environment', :description => 'Environment') + FactoryBot.create(:classification, :parent_id => category.id, :name => 'test', :description => 'Test') + vm = FactoryBot.create(:vm_vmware, :name => "JD-C-T4.0.1.44") + template = FactoryBot.create(:template_vmware, :name => "JD-C-T4.0.1.43") ci = ClassificationImport.upload(@file) ci.apply diff --git a/spec/models/miq_cockpit_ws_worker/authenticator_spec.rb b/spec/models/miq_cockpit_ws_worker/authenticator_spec.rb index ca2cb5af8d3..bac73be9e00 100644 --- a/spec/models/miq_cockpit_ws_worker/authenticator_spec.rb +++ b/spec/models/miq_cockpit_ws_worker/authenticator_spec.rb @@ -2,7 +2,7 @@ describe '#authenticate_for_host' do before do @auth = MiqCockpitWsWorker::Authenticator - @user = FactoryGirl.create(:user, :userid => "admin") + @user = FactoryBot.create(:user, :userid => "admin") @token = Api::UserTokenService.new.generate_token(@user.userid, 'api') end @@ -14,11 +14,11 @@ context "when host is" do before do - @hardware = FactoryGirl.create(:hardware) - @vm = FactoryGirl.create(:vm_openstack, :hardware => @hardware) - @hardware.networks << FactoryGirl.create(:network, :ipaddress => "10.0.0.1", :hostname => "vm-host1") - @hardware.networks << FactoryGirl.create(:network, :ipaddress => "10.0.0.2", :hostname => "vm-host2") - @container_deployment = FactoryGirl.create(:container_deployment, + @hardware = FactoryBot.create(:hardware) + @vm = FactoryBot.create(:vm_openstack, :hardware => @hardware) + @hardware.networks << FactoryBot.create(:network, :ipaddress => "10.0.0.1", :hostname => "vm-host1") + @hardware.networks << FactoryBot.create(:network, :ipaddress => "10.0.0.2", :hostname => "vm-host2") + @container_deployment = FactoryBot.create(:container_deployment, :method_type => "non_managed", :version => "v2", :kind => "openshift-enterprise") @@ -53,7 +53,7 @@ end it "a known vm with a key pair returns that host with auth" do - pair = FactoryGirl.create(:auth_key_pair_cloud, + pair = FactoryBot.create(:auth_key_pair_cloud, :userid => "vm", :auth_key => @vmkey, :public_key => "public_key", @@ -62,12 +62,12 @@ end it "a container node name returns known vm with no auth" do - FactoryGirl.create(:container_node, :name => "kube-node.name") + FactoryBot.create(:container_node, :name => "kube-node.name") expect(@auth.authenticate_for_host(@token, "kube-node.name")).to eq(@found) end it "a container deployment node address uses container deploy auth" do - FactoryGirl.create(:container_deployment_node, + FactoryBot.create(:container_deployment_node, :address => "cd-node.address", :container_deployment => @container_deployment) @@ -92,7 +92,7 @@ "public_key" => "public_key", "type" => "AuthPrivateKey") - FactoryGirl.create(:container_deployment_node, + FactoryBot.create(:container_deployment_node, :vm => @vm, :container_deployment => @container_deployment) diff --git a/spec/models/miq_compare_spec.rb b/spec/models/miq_compare_spec.rb index ce7406b76bf..eec138042ec 100644 --- a/spec/models/miq_compare_spec.rb +++ b/spec/models/miq_compare_spec.rb @@ -1,8 +1,8 @@ describe MiqCompare do context "Marshal.dump and Marshal.load" do it "with Vms" do - vm1 = FactoryGirl.create(:vm_vmware) - vm2 = FactoryGirl.create(:vm_vmware) + vm1 = FactoryBot.create(:vm_vmware) + vm2 = FactoryBot.create(:vm_vmware) MiqReport.seed_report("vms", "compare") @@ -15,8 +15,8 @@ end it "with Hosts" do - host1 = FactoryGirl.create(:host_vmware) - host2 = FactoryGirl.create(:host_vmware) + host1 = FactoryBot.create(:host_vmware) + host2 = FactoryBot.create(:host_vmware) MiqRegion.seed MiqReport.seed_report("hosts", "compare") diff --git a/spec/models/miq_database_spec.rb b/spec/models/miq_database_spec.rb index 6a479c444f2..0bb50b71999 100644 --- a/spec/models/miq_database_spec.rb +++ b/spec/models/miq_database_spec.rb @@ -9,7 +9,7 @@ let(:db) { described_class.seed } let!(:region) do - FactoryGirl.create(:miq_region, :region => ApplicationRecord.my_region_number) + FactoryBot.create(:miq_region, :region => ApplicationRecord.my_region_number) end context ".registration_default_value_for_update_repo_name" do @@ -72,7 +72,7 @@ context "existing record" do it "will seed nil values" do - FactoryGirl.build(:miq_database, + FactoryBot.build(:miq_database, :csrf_secret_token => nil, :session_secret_token => nil ).save(:validate => false) @@ -83,7 +83,7 @@ end it "will not change existing values" do - FactoryGirl.create(:miq_database, + FactoryBot.create(:miq_database, :csrf_secret_token => "abc", :session_secret_token => "def" ) @@ -114,7 +114,7 @@ MiqDatabase.seed EvmSpecHelper.create_guid_miq_server_zone - expect(MiqTask).to receive(:wait_for_taskid).and_return(FactoryGirl.create(:miq_task, :state => "Finished")) + expect(MiqTask).to receive(:wait_for_taskid).and_return(FactoryBot.create(:miq_task, :state => "Finished")) MiqDatabase.first.verify_credentials(:registration) end @@ -122,12 +122,12 @@ context "#registration_organization_name" do it "returns registration_organization when registration_organization_display_name is not available" do - db = FactoryGirl.create(:miq_database, :registration_organization => "foo") + db = FactoryBot.create(:miq_database, :registration_organization => "foo") expect(db.registration_organization_name).to eq("foo") end it "returns registration_organization_display_name when available" do - db = FactoryGirl.create(:miq_database, + db = FactoryBot.create(:miq_database, :registration_organization => "foo", :registration_organization_display_name => "FOO") expect(db.registration_organization_name).to eq("FOO") diff --git a/spec/models/miq_enterprise_spec.rb b/spec/models/miq_enterprise_spec.rb index 538c113bf7b..3a048f39a3e 100644 --- a/spec/models/miq_enterprise_spec.rb +++ b/spec/models/miq_enterprise_spec.rb @@ -1,7 +1,7 @@ describe MiqEnterprise do include_examples ".seed called multiple times" - let(:enterprise) { FactoryGirl.create(:miq_enterprise) } + let(:enterprise) { FactoryBot.create(:miq_enterprise) } context "with all existing records" do it "#miq_regions" do @@ -11,19 +11,19 @@ end it "#ext_management_systems" do - ems = [FactoryGirl.create(:ems_vmware), FactoryGirl.create(:ems_vmware)] + ems = [FactoryBot.create(:ems_vmware), FactoryBot.create(:ems_vmware)] expect(enterprise.ext_management_systems).to match_array(ems) end it "#storages" do - storage = FactoryGirl.create(:storage) + storage = FactoryBot.create(:storage) expect(enterprise.storages).to eq([storage]) end it "#policy_events" do - policy_events = [FactoryGirl.create(:policy_event), FactoryGirl.create(:policy_event)] + policy_events = [FactoryBot.create(:policy_event), FactoryBot.create(:policy_event)] expect(enterprise.policy_events).to match_array(policy_events) end @@ -31,41 +31,41 @@ context "with some existing records" do before do - @ems = FactoryGirl.create(:ems_vmware) + @ems = FactoryBot.create(:ems_vmware) end it "#vms_and_templates" do - vm_1 = FactoryGirl.create(:vm_vmware, :ext_management_system => @ems) - FactoryGirl.create(:vm_vmware) + vm_1 = FactoryBot.create(:vm_vmware, :ext_management_system => @ems) + FactoryBot.create(:vm_vmware) - template_1 = FactoryGirl.create(:template_vmware, :ext_management_system => @ems) - FactoryGirl.create(:template_vmware) + template_1 = FactoryBot.create(:template_vmware, :ext_management_system => @ems) + FactoryBot.create(:template_vmware) expect(enterprise.vms_and_templates).to match_array([vm_1, template_1]) end it "#vms" do - vm = [FactoryGirl.create(:vm_vmware, :ext_management_system => @ems), - FactoryGirl.create(:vm_vmware, :ext_management_system => @ems)] + vm = [FactoryBot.create(:vm_vmware, :ext_management_system => @ems), + FactoryBot.create(:vm_vmware, :ext_management_system => @ems)] - FactoryGirl.create(:vm_vmware) + FactoryBot.create(:vm_vmware) expect(enterprise.vms).to match_array(vm) end it "#miq_templates" do - template = FactoryGirl.create(:template_redhat, :ext_management_system => @ems) + template = FactoryBot.create(:template_redhat, :ext_management_system => @ems) - FactoryGirl.create(:template_redhat) + FactoryBot.create(:template_redhat) expect(enterprise.miq_templates).to eq([template]) end it "#hosts" do - hosts = [FactoryGirl.create(:host_vmware, :ext_management_system => @ems), - FactoryGirl.create(:host_vmware, :ext_management_system => @ems)] + hosts = [FactoryBot.create(:host_vmware, :ext_management_system => @ems), + FactoryBot.create(:host_vmware, :ext_management_system => @ems)] - FactoryGirl.create(:host_vmware) + FactoryBot.create(:host_vmware) expect(enterprise.hosts).to match_array(hosts) end diff --git a/spec/models/miq_event_definition_spec.rb b/spec/models/miq_event_definition_spec.rb index a0a40533924..8fe3bef8653 100644 --- a/spec/models/miq_event_definition_spec.rb +++ b/spec/models/miq_event_definition_spec.rb @@ -61,14 +61,14 @@ def create_set!(name) it "returns event set type" do set_type = 'set_testing' set = MiqEventDefinitionSet.create(:name => set_type, :description => "Set testing") - event = FactoryGirl.create(:miq_event_definition, :name => "vm_start") + event = FactoryBot.create(:miq_event_definition, :name => "vm_start") set.add_member(event) expect(event.etype.name).to eq(set_type) end it "returns nil when not belong to any event set" do - event = FactoryGirl.create(:miq_event_definition, :name => "test_event") + event = FactoryBot.create(:miq_event_definition, :name => "test_event") expect(event.etype).to be_nil end end @@ -78,13 +78,13 @@ def create_set!(name) before do com_set = MiqEventDefinitionSet.create(:name => "compliance", :description => "Compliance Events") - FactoryGirl.create(:miq_event_definition, + FactoryBot.create(:miq_event_definition, :name => "host_compliance_check", :event_type => "Default").tap { |e| com_set.add_member(e) } end it 'has all default control policy events with set type' do - event = FactoryGirl.create(:miq_event_definition, :name => "some_event", :event_type => "Default") + event = FactoryBot.create(:miq_event_definition, :name => "some_event", :event_type => "Default") set = MiqEventDefinitionSet.create(:name => "evm_operations", :description => "EVM Events") set.add_member(event) @@ -96,7 +96,7 @@ def create_set!(name) end it 'has not the events without a set type' do - event = FactoryGirl.create(:miq_event_definition, :name => "test_event", :event_type => "Default") + event = FactoryBot.create(:miq_event_definition, :name => "test_event", :event_type => "Default") expect(subject.include?(event)).to be false end end diff --git a/spec/models/miq_event_spec.rb b/spec/models/miq_event_spec.rb index 1bbe63c31f4..ef69caad595 100644 --- a/spec/models/miq_event_spec.rb +++ b/spec/models/miq_event_spec.rb @@ -2,7 +2,7 @@ context "seeded" do context ".raise_evm_job_event" do it "vm" do - obj = FactoryGirl.create(:vm_redhat) + obj = FactoryBot.create(:vm_redhat) expect(MiqEvent).to receive(:raise_evm_event) do |target, raw_event, _inputs| target == obj && raw_event == "vm_scan_complete" end @@ -10,7 +10,7 @@ end it "container_image" do - obj = FactoryGirl.create(:container_image) + obj = FactoryBot.create(:container_image) expect(MiqEvent).to receive(:raise_evm_event) do |target, raw_event, _inputs| target == obj && raw_event == "container_image_scan_complete" end @@ -22,7 +22,7 @@ end it "host" do - obj = FactoryGirl.create(:host_vmware) + obj = FactoryBot.create(:host_vmware) expect(MiqEvent).to receive(:raise_evm_event) do |target, raw_event, _inputs| target == obj && raw_event == "host_scan_complete" end @@ -30,7 +30,7 @@ end it "physical_server" do - obj = FactoryGirl.create(:physical_server) + obj = FactoryBot.create(:physical_server) expect(MiqEvent).to receive(:raise_evm_event) do |target, raw_event, _inputs| target == obj && raw_event == "physical_server_shutdown" end @@ -39,10 +39,10 @@ end it "will recognize known events" do - FactoryGirl.create(:miq_event_definition, :name => "host_connect") + FactoryBot.create(:miq_event_definition, :name => "host_connect") expect(MiqEvent.normalize_event("host_connect")).not_to eq("unknown") - FactoryGirl.create(:miq_event_definition, :name => "evm_server_start") + FactoryBot.create(:miq_event_definition, :name => "evm_server_start") expect(MiqEvent.normalize_event("evm_server_start")).not_to eq("unknown") end @@ -53,17 +53,17 @@ context ".event_name_for_target" do it "vm" do - expect(MiqEvent.event_name_for_target(FactoryGirl.build(:vm_redhat), "perf_complete")).to eq("vm_perf_complete") + expect(MiqEvent.event_name_for_target(FactoryBot.build(:vm_redhat), "perf_complete")).to eq("vm_perf_complete") end it "host" do - expect(MiqEvent.event_name_for_target(FactoryGirl.build(:host_redhat), "perf_complete")).to eq("host_perf_complete") + expect(MiqEvent.event_name_for_target(FactoryBot.build(:host_redhat), "perf_complete")).to eq("host_perf_complete") end end context ".raise_evm_event" do before do - @cluster = FactoryGirl.create(:ems_cluster) + @cluster = FactoryBot.create(:ems_cluster) @miq_server = EvmSpecHelper.local_miq_server @zone = @miq_server.zone end @@ -80,20 +80,20 @@ it "will raise the event to automate given target directly" do event = 'evm_server_start' - FactoryGirl.create(:miq_event_definition, :name => event) + FactoryBot.create(:miq_event_definition, :name => event) expect(MiqAeEvent).to receive(:raise_evm_event) MiqEvent.raise_evm_event(@miq_server, event) end it "will raise the event to automate given target type and id" do event = 'evm_server_start' - FactoryGirl.create(:miq_event_definition, :name => event) + FactoryBot.create(:miq_event_definition, :name => event) expect(MiqAeEvent).to receive(:raise_evm_event) MiqEvent.raise_evm_event([:MiqServer, @miq_server.id], event) end it "will raise undefined event for classes that do not support policy" do - service = FactoryGirl.create(:service) + service = FactoryBot.create(:service) expect(MiqAeEvent).to receive(:raise_evm_event) MiqEvent.raise_evm_event(service, "request_service_retire") end @@ -104,10 +104,10 @@ end it "will create miq_event object with username" do - user = FactoryGirl.create(:user_with_group, :userid => "test") - vm = FactoryGirl.create(:vm_vmware) + user = FactoryBot.create(:user_with_group, :userid => "test") + vm = FactoryBot.create(:vm_vmware) event = 'request_vm_start' - FactoryGirl.create(:miq_event_definition, :name => event) + FactoryBot.create(:miq_event_definition, :name => event) User.with_user(user) do event_obj = MiqEvent.raise_evm_event(vm, event) @@ -120,15 +120,15 @@ context "#process_evm_event" do before do - @cluster = FactoryGirl.create(:ems_cluster) - @zone = FactoryGirl.create(:zone, :name => "test") - @miq_server = FactoryGirl.create(:miq_server, :guid => @guid, :zone => @zone) + @cluster = FactoryBot.create(:ems_cluster) + @zone = FactoryBot.create(:zone, :name => "test") + @miq_server = FactoryBot.create(:miq_server, :guid => @guid, :zone => @zone) end it "will do policy, alerts, and children events for supported policy target" do event = 'vm_start' - FactoryGirl.create(:miq_event_definition, :name => event) - FactoryGirl.create(:miq_event, :event_type => event, :target => @cluster) + FactoryBot.create(:miq_event_definition, :name => event) + FactoryBot.create(:miq_event, :event_type => event, :target => @cluster) inputs = {:type => @cluster.class.name, :triggering_type => event, :triggering_data => nil} expect(MiqPolicy).to receive(:enforce_policy).with(@cluster, event, inputs) expect(MiqAlert).to receive(:evaluate_alerts).with(@cluster, event, inputs) @@ -140,16 +140,16 @@ it "will not raise to automate for supported policy target" do raw_event = "evm_server_start" - FactoryGirl.create(:miq_event_definition, :name => raw_event) - FactoryGirl.create(:miq_event, :event_type => raw_event, :target => @miq_server) + FactoryBot.create(:miq_event_definition, :name => raw_event) + FactoryBot.create(:miq_event, :event_type => raw_event, :target => @miq_server) expect(MiqAeEvent).to receive(:raise_evm_event).never MiqEvent.first.process_evm_event end it "will do nothing for unsupported policy target" do - FactoryGirl.create(:miq_event_definition, :name => "some_event") - FactoryGirl.create(:miq_event, :event_type => "some_event", :target => @zone) + FactoryBot.create(:miq_event_definition, :name => "some_event") + FactoryBot.create(:miq_event, :event_type => "some_event", :target => @zone) expect(MiqPolicy).to receive(:enforce_policy).never expect(MiqAlert).to receive(:evaluate_alerts).never @@ -159,9 +159,9 @@ it "will do policy for provider events" do event = 'ems_auth_changed' - ems = FactoryGirl.create(:ext_management_system) - FactoryGirl.create(:miq_event_definition, :name => event) - FactoryGirl.create(:miq_event, :event_type => event, :target => ems) + ems = FactoryBot.create(:ext_management_system) + FactoryBot.create(:miq_event_definition, :name => event) + FactoryBot.create(:miq_event, :event_type => event, :target => ems) inputs = {:type => ems.class.name, :triggering_type => event, :triggering_data => nil} expect(MiqPolicy).to receive(:enforce_policy).with(ems, event, inputs) @@ -170,13 +170,13 @@ it"will pass EmsEvent to policy if set" do event = 'vm_clone_start' - vm = FactoryGirl.create(:vm_vmware) - ems_event = FactoryGirl.create( + vm = FactoryBot.create(:vm_vmware) + ems_event = FactoryBot.create( :ems_event, :event_type => "CloneVM_Task", :full_data => { "info" => {"task" => "task-5324"}}) - FactoryGirl.create(:miq_event_definition, :name => event) - FactoryGirl.create( + FactoryBot.create(:miq_event_definition, :name => event) + FactoryBot.create( :miq_event, :event_type => event, :target => vm, @@ -199,8 +199,8 @@ context ".raise_event_for_children" do it "uses base_model to build event name" do - host = FactoryGirl.create(:host_vmware_esx) - vm = FactoryGirl.create(:vm_vmware, :host => host) + host = FactoryBot.create(:host_vmware_esx) + vm = FactoryBot.create(:vm_vmware, :host => host) expect(MiqEvent).to receive(:raise_evm_event_queue) do |target, child_event, _inputs| target == vm && child_event == "assigned_company_tag_parent_host" end diff --git a/spec/models/miq_filter_spec.rb b/spec/models/miq_filter_spec.rb index 081cce1e03e..3eecc0574a1 100644 --- a/spec/models/miq_filter_spec.rb +++ b/spec/models/miq_filter_spec.rb @@ -1,13 +1,13 @@ describe MiqFilter do - let(:ems) { FactoryGirl.create(:ems_vmware, :name => 'ems') } - let(:datacenter) { FactoryGirl.create(:ems_folder, :name => "Datacenters").tap { |dc| dc.parent = ems } } - let(:mtc) { FactoryGirl.create(:datacenter, :name => "MTC").tap { |mtc| mtc.parent = datacenter } } + let(:ems) { FactoryBot.create(:ems_vmware, :name => 'ems') } + let(:datacenter) { FactoryBot.create(:ems_folder, :name => "Datacenters").tap { |dc| dc.parent = ems } } + let(:mtc) { FactoryBot.create(:datacenter, :name => "MTC").tap { |mtc| mtc.parent = datacenter } } let(:ems_folder_path) { "/belongsto/ExtManagementSystem|#{ems.name}" } let(:mtc_folder_path) { "#{ems_folder_path}/EmsFolder|#{datacenter.name}/EmsFolder|#{mtc.name}" } - let(:host_folder) { FactoryGirl.create(:ems_folder, :name => "host").tap { |hf| hf.parent = mtc } } - let(:host_1) { FactoryGirl.create(:host_vmware, :name => "Host_1", :ext_management_system => ems).tap { |h| h.parent = host_folder } } - let(:host_2) { FactoryGirl.create(:host_vmware, :name => "Host_2", :ext_management_system => ems).tap { |h| h.parent = host_folder } } - let(:host_3) { FactoryGirl.create(:host_vmware, :name => "Host_3") } + let(:host_folder) { FactoryBot.create(:ems_folder, :name => "host").tap { |hf| hf.parent = mtc } } + let(:host_1) { FactoryBot.create(:host_vmware, :name => "Host_1", :ext_management_system => ems).tap { |h| h.parent = host_folder } } + let(:host_2) { FactoryBot.create(:host_vmware, :name => "Host_2", :ext_management_system => ems).tap { |h| h.parent = host_folder } } + let(:host_3) { FactoryBot.create(:host_vmware, :name => "Host_3") } let(:mtc_folder_path_with_host_folder) { "#{mtc_folder_path}/EmsFolder|host" } let(:mtc_folder_path_with_host_1) { "#{mtc_folder_path_with_host_folder}/Host|#{host_1.name}" } diff --git a/spec/models/miq_group_spec.rb b/spec/models/miq_group_spec.rb index bafea857f80..840e6921ffd 100644 --- a/spec/models/miq_group_spec.rb +++ b/spec/models/miq_group_spec.rb @@ -2,7 +2,7 @@ include Spec::Support::ArelHelper describe "#settings" do - subject { FactoryGirl.create(:miq_group) } + subject { FactoryBot.create(:miq_group) } it "returns a HashWithIndifferentAccess" do subject.settings = {:a => 1} @@ -17,7 +17,7 @@ end context "as a Super Administrator" do - subject { FactoryGirl.create(:miq_group, :group_type => "system", :role => "super_administrator") } + subject { FactoryBot.create(:miq_group, :group_type => "system", :role => "super_administrator") } before do subject.entitlement.set_managed_filters([['some managed filter']]) @@ -146,38 +146,38 @@ end context "Testing active VM aggregation" do - let(:miq_group) { FactoryGirl.create(:miq_group, :description => "test group") } + let(:miq_group) { FactoryBot.create(:miq_group, :description => "test group") } let(:ram_size) { 1024 } let(:disk_size) { 1_000_000 } let(:num_cpu) { 2 } - let(:ems) { FactoryGirl.create(:ems_vmware, :name => "test_vcenter") } - let(:storage) { FactoryGirl.create(:storage, :name => "test_storage_nfs", :store_type => "NFS") } + let(:ems) { FactoryBot.create(:ems_vmware, :name => "test_vcenter") } + let(:storage) { FactoryBot.create(:storage, :name => "test_storage_nfs", :store_type => "NFS") } before do - @hw1 = FactoryGirl.create(:hardware, :cpu_total_cores => num_cpu, :memory_mb => ram_size) - @hw2 = FactoryGirl.create(:hardware, :cpu_total_cores => num_cpu, :memory_mb => ram_size) - @hw3 = FactoryGirl.create(:hardware, :cpu_total_cores => num_cpu, :memory_mb => ram_size) - @hw4 = FactoryGirl.create(:hardware, :cpu_total_cores => num_cpu, :memory_mb => ram_size) - @disk1 = FactoryGirl.create(:disk, :device_type => "disk", :size => disk_size, :hardware_id => @hw1.id) - @disk2 = FactoryGirl.create(:disk, :device_type => "disk", :size => disk_size, :hardware_id => @hw2.id) - @disk3 = FactoryGirl.create(:disk, :device_type => "disk", :size => disk_size, :hardware_id => @hw3.id) - @disk3 = FactoryGirl.create(:disk, :device_type => "disk", :size => disk_size, :hardware_id => @hw4.id) - - @active_vm = FactoryGirl.create(:vm_vmware, + @hw1 = FactoryBot.create(:hardware, :cpu_total_cores => num_cpu, :memory_mb => ram_size) + @hw2 = FactoryBot.create(:hardware, :cpu_total_cores => num_cpu, :memory_mb => ram_size) + @hw3 = FactoryBot.create(:hardware, :cpu_total_cores => num_cpu, :memory_mb => ram_size) + @hw4 = FactoryBot.create(:hardware, :cpu_total_cores => num_cpu, :memory_mb => ram_size) + @disk1 = FactoryBot.create(:disk, :device_type => "disk", :size => disk_size, :hardware_id => @hw1.id) + @disk2 = FactoryBot.create(:disk, :device_type => "disk", :size => disk_size, :hardware_id => @hw2.id) + @disk3 = FactoryBot.create(:disk, :device_type => "disk", :size => disk_size, :hardware_id => @hw3.id) + @disk3 = FactoryBot.create(:disk, :device_type => "disk", :size => disk_size, :hardware_id => @hw4.id) + + @active_vm = FactoryBot.create(:vm_vmware, :name => "Active VM", :miq_group_id => miq_group.id, :ems_id => ems.id, :storage_id => storage.id, :hardware => @hw1) - @archived_vm = FactoryGirl.create(:vm_vmware, + @archived_vm = FactoryBot.create(:vm_vmware, :name => "Archived VM", :miq_group_id => miq_group.id, :hardware => @hw2) - @orphaned_vm = FactoryGirl.create(:vm_vmware, + @orphaned_vm = FactoryBot.create(:vm_vmware, :name => "Orphaned VM", :miq_group_id => miq_group.id, :storage_id => storage.id, :hardware => @hw3) - @retired_vm = FactoryGirl.create(:vm_vmware, + @retired_vm = FactoryBot.create(:vm_vmware, :name => "Retired VM", :miq_group_id => miq_group.id, :retired => true, @@ -211,8 +211,8 @@ end it "when the virtual column is nil" do - hw = FactoryGirl.create(:hardware, :cpu_sockets => num_cpu, :memory_mb => ram_size) - FactoryGirl.create(:vm_vmware, + hw = FactoryBot.create(:hardware, :cpu_sockets => num_cpu, :memory_mb => ram_size) + FactoryBot.create(:vm_vmware, :name => "VM with no disk", :miq_group_id => miq_group.id, :ems_id => ems.id, @@ -223,40 +223,40 @@ end describe "#destroy" do - let(:group) { FactoryGirl.create(:miq_group) } + let(:group) { FactoryBot.create(:miq_group) } it "can succeed" do expect { group.destroy }.not_to raise_error end it "fails if referenced by user#current_group" do - FactoryGirl.create(:user, :miq_groups => [group]) + FactoryBot.create(:user, :miq_groups => [group]) expect { expect { group.destroy }.to raise_error(RuntimeError, /The group has users assigned that do not belong to any other group/) }.to_not change { MiqGroup.count } end it "succeeds if referenced by multiple user#miq_groups" do - group2 = FactoryGirl.create(:miq_group) - FactoryGirl.create(:user, :miq_groups => [group, group2], :current_group => group2) + group2 = FactoryBot.create(:miq_group) + FactoryBot.create(:user, :miq_groups => [group, group2], :current_group => group2) expect { group.destroy }.not_to raise_error end it "fails if trying to delete the current user's group" do - group2 = FactoryGirl.create(:miq_group) - user = FactoryGirl.create(:user, :miq_groups => [group, group2], :current_group => group) + group2 = FactoryBot.create(:miq_group) + user = FactoryBot.create(:user, :miq_groups => [group, group2], :current_group => group) User.current_user = user expect { expect { group.destroy }.to raise_error(RuntimeError, /The login group cannot be deleted/) }.to_not change { MiqGroup.count } end it "fails if one user in the group does not belong to any other group" do - group2 = FactoryGirl.create(:miq_group) - FactoryGirl.create(:user, :miq_groups => [group, group2], :current_group => group2) - FactoryGirl.create(:user, :miq_groups => [group], :current_group => group) + group2 = FactoryBot.create(:miq_group) + FactoryBot.create(:user, :miq_groups => [group, group2], :current_group => group2) + FactoryBot.create(:user, :miq_groups => [group], :current_group => group) expect { expect { group.destroy }.to raise_error(RuntimeError, /The group has users assigned that do not belong to any other group/) }.to_not change { MiqGroup.count } end it "fails if referenced by a tenant#default_miq_group" do - expect { FactoryGirl.create(:tenant).default_miq_group.reload.destroy } + expect { FactoryBot.create(:tenant).default_miq_group.reload.destroy } .to raise_error(RuntimeError, /A tenant default group can not be deleted/) end end @@ -284,9 +284,9 @@ let!(:tenant) { Tenant.seed } let!(:group_with_no_entitlement) { tenant.default_miq_group } let!(:group_with_existing_entitlement) do - FactoryGirl.create(:miq_group, + FactoryBot.create(:miq_group, :tenant_type, - :entitlement => FactoryGirl.create(:entitlement, :miq_user_role => nil)) + :entitlement => FactoryBot.create(:entitlement, :miq_user_role => nil)) end let(:default_tenant_role) { MiqUserRole.default_tenant_role } @@ -311,27 +311,27 @@ end context "#ordered_widget_sets" do - let(:group) { FactoryGirl.create(:miq_group) } + let(:group) { FactoryBot.create(:miq_group) } it "uses dashboard_order if present" do - ws1 = FactoryGirl.create(:miq_widget_set, :name => 'A1', :owner => group) - FactoryGirl.create(:miq_widget_set, :name => 'C3', :owner => group) - ws3 = FactoryGirl.create(:miq_widget_set, :name => 'B2', :owner => group) + ws1 = FactoryBot.create(:miq_widget_set, :name => 'A1', :owner => group) + FactoryBot.create(:miq_widget_set, :name => 'C3', :owner => group) + ws3 = FactoryBot.create(:miq_widget_set, :name => 'B2', :owner => group) group.update_attributes(:settings => {:dashboard_order => [ws3.id.to_s, ws1.id.to_s]}) expect(group.ordered_widget_sets).to eq([ws3, ws1]) end it "uses all owned widgets" do - ws1 = FactoryGirl.create(:miq_widget_set, :name => 'A1', :owner => group) - ws2 = FactoryGirl.create(:miq_widget_set, :name => 'C3', :owner => group) - ws3 = FactoryGirl.create(:miq_widget_set, :name => 'B2', :owner => group) + ws1 = FactoryBot.create(:miq_widget_set, :name => 'A1', :owner => group) + ws2 = FactoryBot.create(:miq_widget_set, :name => 'C3', :owner => group) + ws3 = FactoryBot.create(:miq_widget_set, :name => 'B2', :owner => group) expect(group.ordered_widget_sets).to eq([ws1, ws3, ws2]) end it "works when settings use strings" do - ws1 = FactoryGirl.create(:miq_widget_set, :name => 'A1', :owner => group) - _ws2 = FactoryGirl.create(:miq_widget_set, :name => 'C3', :owner => group) - ws3 = FactoryGirl.create(:miq_widget_set, :name => 'B2', :owner => group) + ws1 = FactoryBot.create(:miq_widget_set, :name => 'A1', :owner => group) + _ws2 = FactoryBot.create(:miq_widget_set, :name => 'C3', :owner => group) + ws3 = FactoryBot.create(:miq_widget_set, :name => 'B2', :owner => group) group.update_attributes(:settings => {"dashboard_order" => [ws3.id.to_s, ws1.id.to_s]}) expect(group.ordered_widget_sets).to eq([ws3, ws1]) @@ -340,10 +340,10 @@ context ".sort_by_desc" do it "sorts by description" do - tenant = FactoryGirl.create(:tenant) - gc = FactoryGirl.create(:miq_group, :description => 'C', :tenant => tenant) - ga = FactoryGirl.create(:miq_group, :description => 'a', :tenant => tenant) - gb = FactoryGirl.create(:miq_group, :description => 'B', :tenant => tenant) + tenant = FactoryBot.create(:tenant) + gc = FactoryBot.create(:miq_group, :description => 'C', :tenant => tenant) + ga = FactoryBot.create(:miq_group, :description => 'a', :tenant => tenant) + gb = FactoryBot.create(:miq_group, :description => 'B', :tenant => tenant) expect(tenant.miq_groups.sort_by_desc).to eq([ga, gb, gc, tenant.default_miq_group]) end @@ -351,26 +351,26 @@ describe "#read_only" do it "is not read_only for regular groups" do - expect(FactoryGirl.create(:miq_group)).not_to be_read_only + expect(FactoryBot.create(:miq_group)).not_to be_read_only end it "is read_only for system groups" do - expect(FactoryGirl.create(:miq_group, :system_type)).to be_read_only + expect(FactoryBot.create(:miq_group, :system_type)).to be_read_only end it "is read_only for tenant groups" do - expect(FactoryGirl.create(:tenant).default_miq_group).to be_read_only + expect(FactoryBot.create(:tenant).default_miq_group).to be_read_only end end describe "#self_service" do it "detects role" do - role = FactoryGirl.create( + role = FactoryBot.create( :miq_user_role, :role => "self_service", :settings => {:restrictions => {:vms => :user_or_group}} ) - group = FactoryGirl.create(:miq_group, + group = FactoryBot.create(:miq_group, :description => "MiqGroup-self_service", :miq_user_role => role ) @@ -378,42 +378,42 @@ end it "detects non-role" do - group = FactoryGirl.create(:miq_group, :role => "abc") + group = FactoryBot.create(:miq_group, :role => "abc") expect(group).not_to be_self_service end end describe "#system_group?" do it "is not system_group for regular groups" do - expect(FactoryGirl.create(:miq_group)).not_to be_system_group + expect(FactoryBot.create(:miq_group)).not_to be_system_group end it "is system_group for system groups" do - expect(FactoryGirl.create(:miq_group, :system_type)).to be_system_group + expect(FactoryBot.create(:miq_group, :system_type)).to be_system_group end end describe "#tenant_group" do it "is not tenant_group for regular groups" do - expect(FactoryGirl.create(:miq_group)).not_to be_tenant_group + expect(FactoryBot.create(:miq_group)).not_to be_tenant_group end it "is tenant_group for tenant groups" do - expect(FactoryGirl.create(:tenant).default_miq_group).to be_tenant_group + expect(FactoryBot.create(:tenant).default_miq_group).to be_tenant_group end end describe "#tenant=" do it "changes for non default groups" do - tenant = FactoryGirl.create(:tenant) - g = FactoryGirl.create(:miq_group) + tenant = FactoryBot.create(:tenant) + g = FactoryBot.create(:miq_group) g.update_attributes(:tenant => tenant) expect(g.tenant).to eq(tenant) end it "fails for default groups" do - tenant = FactoryGirl.create(:tenant) - g = FactoryGirl.create(:tenant).default_miq_group + tenant = FactoryBot.create(:tenant) + g = FactoryBot.create(:tenant).default_miq_group expect { g.update_attributes!(:tenant => tenant) } .to raise_error(ActiveRecord::RecordInvalid, /Tenant cant change the tenant of a default group/) end @@ -421,8 +421,8 @@ describe '.tenant_groups' do it "brings back only tenant_groups" do - tg = FactoryGirl.create(:tenant).default_miq_group - g = FactoryGirl.create(:miq_group) + tg = FactoryBot.create(:tenant).default_miq_group + g = FactoryBot.create(:miq_group) expect(MiqGroup.tenant_groups).to include(tg) expect(MiqGroup.tenant_groups).not_to include(g) @@ -431,8 +431,8 @@ describe '.non_tenant_groups' do it "brings back only non_tenant_groups" do - tg = FactoryGirl.create(:tenant).default_miq_group - g = FactoryGirl.create(:miq_group) + tg = FactoryBot.create(:tenant).default_miq_group + g = FactoryBot.create(:miq_group) expect(MiqGroup.non_tenant_groups).not_to include(tg) expect(MiqGroup.non_tenant_groups).to include(g) @@ -447,13 +447,13 @@ it "detects existing groups" do expect(MiqGroup.next_sequence).to be < 999 # sanity check - FactoryGirl.create(:miq_group, :sequence => 999) + FactoryBot.create(:miq_group, :sequence => 999) expect(MiqGroup.next_sequence).to eq(1000) end it "handles nil sequences" do MiqGroup.delete_all - g = FactoryGirl.create(:miq_group) + g = FactoryBot.create(:miq_group) g.update_attribute(:sequence, nil) expect(MiqGroup.next_sequence).to eq(1) @@ -471,9 +471,9 @@ it "builds a sequence based upon select criteria" do expect(MiqGroup.next_sequence).to be < 999 # sanity check - FactoryGirl.create(:miq_group, :description => "want 1", :sequence => 999) - FactoryGirl.create(:miq_group, :description => "want 2", :sequence => 1000) - FactoryGirl.create(:miq_group, :description => "dont want", :sequence => 1009) + FactoryBot.create(:miq_group, :description => "want 1", :sequence => 999) + FactoryBot.create(:miq_group, :description => "want 2", :sequence => 1000) + FactoryBot.create(:miq_group, :description => "dont want", :sequence => 1009) expect(MiqGroup.where("description like 'want%'").next_sequence).to eq(1001) end @@ -481,66 +481,66 @@ describe "#user_count" do it "counts none" do - group = FactoryGirl.create(:miq_group) + group = FactoryBot.create(:miq_group) expect(group.user_count).to eq(0) end it "counts some" do - group = FactoryGirl.create(:miq_group) - FactoryGirl.create_list(:user, 2, :miq_groups =>[group]) + group = FactoryBot.create(:miq_group) + FactoryBot.create_list(:user, 2, :miq_groups =>[group]) expect(group.user_count).to eq(2) end end describe "#single_group_users?" do it "returns false if all users in the group belong to an additional group" do - testgroup1 = FactoryGirl.create(:miq_group) - testgroup2 = FactoryGirl.create(:miq_group) - testgroup3 = FactoryGirl.create(:miq_group) - FactoryGirl.create(:user, :miq_groups => [testgroup1, testgroup2]) - FactoryGirl.create(:user, :miq_groups => [testgroup1, testgroup3]) + testgroup1 = FactoryBot.create(:miq_group) + testgroup2 = FactoryBot.create(:miq_group) + testgroup3 = FactoryBot.create(:miq_group) + FactoryBot.create(:user, :miq_groups => [testgroup1, testgroup2]) + FactoryBot.create(:user, :miq_groups => [testgroup1, testgroup3]) expect(testgroup1.single_group_users?).to eq(false) end it "returns false if the group has no users" do - testgroup1 = FactoryGirl.create(:miq_group) + testgroup1 = FactoryBot.create(:miq_group) expect(testgroup1.single_group_users?).to eq(false) end it "returns true if all users in a group do not belong to any other group" do - testgroup1 = FactoryGirl.create(:miq_group) - FactoryGirl.create(:user, :miq_groups => [testgroup1]) - FactoryGirl.create(:user, :miq_groups => [testgroup1]) + testgroup1 = FactoryBot.create(:miq_group) + FactoryBot.create(:user, :miq_groups => [testgroup1]) + FactoryBot.create(:user, :miq_groups => [testgroup1]) expect(testgroup1.single_group_users?).to eq(true) end it "returns true if any user in a group does not belong to another group" do - testgroup1 = FactoryGirl.create(:miq_group) - testgroup2 = FactoryGirl.create(:miq_group) - FactoryGirl.create(:user, :miq_groups => [testgroup1]) - FactoryGirl.create(:user, :miq_groups => [testgroup1, testgroup2]) + testgroup1 = FactoryBot.create(:miq_group) + testgroup2 = FactoryBot.create(:miq_group) + FactoryBot.create(:user, :miq_groups => [testgroup1]) + FactoryBot.create(:user, :miq_groups => [testgroup1, testgroup2]) expect(testgroup1.single_group_users?).to eq(true) end end describe "#reset_current_group_for_users" do it "changes the current_group for users that have the deleted group as the current_group" do - testgroup1 = FactoryGirl.create(:miq_group) - testgroup2 = FactoryGirl.create(:miq_group) - testgroup3 = FactoryGirl.create(:miq_group) - user1 = FactoryGirl.create(:user, :miq_groups => [testgroup1, testgroup2], :current_group => testgroup2) - user2 = FactoryGirl.create(:user, :miq_groups => [testgroup1, testgroup3], :current_group => testgroup3) + testgroup1 = FactoryBot.create(:miq_group) + testgroup2 = FactoryBot.create(:miq_group) + testgroup3 = FactoryBot.create(:miq_group) + user1 = FactoryBot.create(:user, :miq_groups => [testgroup1, testgroup2], :current_group => testgroup2) + user2 = FactoryBot.create(:user, :miq_groups => [testgroup1, testgroup3], :current_group => testgroup3) expect { testgroup2.destroy }.not_to raise_error expect(User.find_by(:id => user1.id).current_group.id).to eq(testgroup1.id) expect(User.find_by(:id => user2.id).current_group.id).to eq(testgroup3.id) end it "should not be called if the user does not have the deleted group as the current_group" do - testgroup1 = FactoryGirl.create(:miq_group) - testgroup2 = FactoryGirl.create(:miq_group) - testgroup3 = FactoryGirl.create(:miq_group) - user1 = FactoryGirl.create(:user, :miq_groups => [testgroup1, testgroup2], :current_group => testgroup2) - user2 = FactoryGirl.create(:user, :miq_groups => [testgroup3], :current_group => testgroup3) + testgroup1 = FactoryBot.create(:miq_group) + testgroup2 = FactoryBot.create(:miq_group) + testgroup3 = FactoryBot.create(:miq_group) + user1 = FactoryBot.create(:user, :miq_groups => [testgroup1, testgroup2], :current_group => testgroup2) + user2 = FactoryBot.create(:user, :miq_groups => [testgroup3], :current_group => testgroup3) expect { testgroup1.destroy }.not_to raise_error expect(User.find_by(:id => user1).current_group.id).to eq(testgroup2.id) expect(User.find_by(:id => user2).current_group.id).to eq(testgroup3.id) @@ -572,7 +572,7 @@ end describe "#miq_user_role_name" do - let(:group) { FactoryGirl.build(:miq_group, :role => "the_role") } + let(:group) { FactoryBot.build(:miq_group, :role => "the_role") } it "calculates in ruby" do expect(group.miq_user_role_name).to eq("EvmRole-the_role") @@ -586,12 +586,12 @@ describe "#regional_groups" do let(:other_id) { ApplicationRecord.id_in_region(1, ApplicationRecord.my_region_number + 1) } - let(:group) { FactoryGirl.create(:miq_group) } - let!(:regional_group) { FactoryGirl.create(:miq_group, :description => group.description.upcase, :id => other_id) } + let(:group) { FactoryBot.create(:miq_group) } + let!(:regional_group) { FactoryBot.create(:miq_group, :description => group.description.upcase, :id => other_id) } it "finds regional groups" do - FactoryGirl.create(:miq_group) # ensure these doen't come back - FactoryGirl.create(:miq_group, :id => other_id + 1) + FactoryBot.create(:miq_group) # ensure these doen't come back + FactoryBot.create(:miq_group, :id => other_id + 1) expect(group.regional_groups).to match_array([group, regional_group]) end @@ -599,9 +599,9 @@ describe ".with_roles_excluding" do it "handles multiple columns" do - a = FactoryGirl.create(:miq_group, :features => "good") - FactoryGirl.create(:miq_group, :features => %w(good everything)) - FactoryGirl.create(:miq_group, :features => "everything") + a = FactoryBot.create(:miq_group, :features => "good") + FactoryBot.create(:miq_group, :features => %w(good everything)) + FactoryBot.create(:miq_group, :features => "everything") expect(MiqGroup.select(:id, :description).with_roles_excluding("everything")).to match_array([a]) end diff --git a/spec/models/miq_policy_content_spec.rb b/spec/models/miq_policy_content_spec.rb index 87754fe9563..228aad7e5a8 100644 --- a/spec/models/miq_policy_content_spec.rb +++ b/spec/models/miq_policy_content_spec.rb @@ -1,7 +1,7 @@ describe MiqPolicyContent do context 'Empty content' do describe '#export_to_array' do - subject { FactoryGirl.create(:miq_policy_content).export_to_array } + subject { FactoryBot.create(:miq_policy_content).export_to_array } it { is_expected.to match_array(['MiqPolicyContent'=>{}]) } end end diff --git a/spec/models/miq_policy_spec.rb b/spec/models/miq_policy_spec.rb index 73c7f9eb4d2..bca5e801aa3 100644 --- a/spec/models/miq_policy_spec.rb +++ b/spec/models/miq_policy_spec.rb @@ -6,12 +6,12 @@ # calling conditions. before do - @ps = FactoryGirl.create(:miq_policy_set, :name => "ps") - @p = FactoryGirl.create(:miq_policy) + @ps = FactoryBot.create(:miq_policy_set, :name => "ps") + @p = FactoryBot.create(:miq_policy) @ps.add_member(@p) - @ps2 = FactoryGirl.create(:miq_policy_set, :name => "ps2") - @p2 = FactoryGirl.create(:miq_policy) + @ps2 = FactoryBot.create(:miq_policy_set, :name => "ps2") + @p2 = FactoryBot.create(:miq_policy) end it "should return the correct conditions" do @@ -21,7 +21,7 @@ end context "#description=" do - subject { FactoryGirl.create(:miq_policy, :description => @description) } + subject { FactoryBot.create(:miq_policy, :description => @description) } it "should keep the description < 255" do @description = "a" * 30 @@ -41,12 +41,12 @@ end context "instance methods" do - let(:event) { FactoryGirl.create(:miq_event_definition) } - let(:action) { FactoryGirl.create(:miq_action) } + let(:event) { FactoryBot.create(:miq_event_definition) } + let(:action) { FactoryBot.create(:miq_action) } let(:policy) do - cond = FactoryGirl.create(:condition) - FactoryGirl.create(:miq_policy, :conditions => [cond]).tap do |p| + cond = FactoryBot.create(:condition) + FactoryBot.create(:miq_policy, :conditions => [cond]).tap do |p| p.replace_actions_for_event(event, [[action, {:qualifier => :success}]]) end end @@ -59,7 +59,7 @@ describe '#miq_event_definitions' do before do - policy.miq_policy_contents.push(FactoryGirl.create(:miq_policy_content)) + policy.miq_policy_contents.push(FactoryBot.create(:miq_policy_content)) end it 'lists event definition' do @@ -68,7 +68,7 @@ end describe "#sync_events, #add_event, #delete_event" do - let(:new_events) { [FactoryGirl.create(:miq_event_definition), FactoryGirl.create(:miq_event_definition)] } + let(:new_events) { [FactoryBot.create(:miq_event_definition), FactoryBot.create(:miq_event_definition)] } it 'synchronizes with new list of events' do policy.sync_events(new_events) @@ -78,8 +78,8 @@ end describe "#actions #actions_for_event, #replace_actions_for_event" do - let(:new_action) { FactoryGirl.create(:miq_action) } - let(:another_event) { FactoryGirl.create(:miq_event_definition) } + let(:new_action) { FactoryBot.create(:miq_action) } + let(:another_event) { FactoryBot.create(:miq_event_definition) } it "lists all actions for the policy" do policy.replace_actions_for_event(another_event, [[new_action, {:qualifier => :success}]]) @@ -112,9 +112,9 @@ end describe "#applies_to?" do - let(:target_vm) { FactoryGirl.create(:vm_amazon) } - let(:target_template) { FactoryGirl.create(:template_infra) } - let(:target_host) { FactoryGirl.create(:host) } + let(:target_vm) { FactoryBot.create(:vm_amazon) } + let(:target_template) { FactoryBot.create(:template_infra) } + let(:target_host) { FactoryBot.create(:host) } it "applies to target with matched type" do expect(policy.applies_to?(target_vm)).to be_truthy @@ -141,17 +141,17 @@ end context "class methods" do - let(:events) { [FactoryGirl.create(:miq_event_definition), FactoryGirl.create(:miq_event_definition)] } - let(:actions) { [FactoryGirl.create(:miq_action), FactoryGirl.create(:miq_action)] } - let(:conds) { [FactoryGirl.create(:condition), FactoryGirl.create(:condition)] } - let(:target) { FactoryGirl.create(:vm) } + let(:events) { [FactoryBot.create(:miq_event_definition), FactoryBot.create(:miq_event_definition)] } + let(:actions) { [FactoryBot.create(:miq_action), FactoryBot.create(:miq_action)] } + let(:conds) { [FactoryBot.create(:condition), FactoryBot.create(:condition)] } + let(:target) { FactoryBot.create(:vm) } let(:policies) do [ - FactoryGirl.create(:miq_policy, :conditions => [conds[0]], :active => true, :mode => 'control').tap do |p| + FactoryBot.create(:miq_policy, :conditions => [conds[0]], :active => true, :mode => 'control').tap do |p| p.replace_actions_for_event(events[0], [[actions[0], {:qualifier => :success}], [actions[1], {:qualifier => :failure}]]) end, - FactoryGirl.create(:miq_policy, :conditions => [conds[1]], :active => false).tap do |p| + FactoryBot.create(:miq_policy, :conditions => [conds[1]], :active => false).tap do |p| p.replace_actions_for_event(events[1], [[actions[1], {:qualifier => :success}]]) end ] @@ -159,8 +159,8 @@ let(:profiles) do [ - FactoryGirl.create(:miq_policy_set, :name => "ps3").tap { |pf| pf.add_member(policies[0]) }, - FactoryGirl.create(:miq_policy_set, :name => "ps4").tap { |pf| pf.add_member(policies[1]) }, + FactoryBot.create(:miq_policy_set, :name => "ps3").tap { |pf| pf.add_member(policies[0]) }, + FactoryBot.create(:miq_policy_set, :name => "ps4").tap { |pf| pf.add_member(policies[1]) }, ] end @@ -168,12 +168,12 @@ describe ".resolve" do it "resolves all policies" do - results = described_class.resolve(FactoryGirl.create(:vm)) + results = described_class.resolve(FactoryBot.create(:vm)) expect(results.size).to eq(2) end it "resolves policies by event" do - results = described_class.resolve(FactoryGirl.create(:vm), policies.collect(&:name), events[1]) + results = described_class.resolve(FactoryBot.create(:vm), policies.collect(&:name), events[1]) expect(results.size).to eq(1) result = results[0] expect(result).to include( @@ -233,7 +233,7 @@ describe ".eval_condition" do it "returns 'allow' when condition is met" do - vm = FactoryGirl.create(:vm_vmware, :hardware => FactoryGirl.create(:hardware, :cpu_sockets => 2)) + vm = FactoryBot.create(:vm_vmware, :hardware => FactoryBot.create(:hardware, :cpu_sockets => 2)) result = described_class.send(:eval_condition, conds[0], vm) expect(result).to eq('allow') @@ -260,12 +260,12 @@ describe "(Built-in) Prevent Retired Instance from Starting policy" do before do - FactoryGirl.create(:miq_event_definition, :name => "vm_resume") - FactoryGirl.create(:miq_action, :name => "vm_suspend", :action_type => 'default') + FactoryBot.create(:miq_event_definition, :name => "vm_resume") + FactoryBot.create(:miq_action, :name => "vm_suspend", :action_type => 'default') MiqPolicy.class_variable_set(:@@built_in_policies, nil) - @vm = FactoryGirl.create(:vm_openstack, - :ext_management_system => FactoryGirl.create(:ems_openstack, - :zone => FactoryGirl.create(:zone))) + @vm = FactoryBot.create(:vm_openstack, + :ext_management_system => FactoryBot.create(:ems_openstack, + :zone => FactoryBot.create(:zone))) end subject { MiqPolicy.enforce_policy(@vm, "vm_resume", {}) } @@ -310,11 +310,11 @@ context '.validates' do it 'validates towhat' do - expect(FactoryGirl.build(:miq_policy, :towhat => "Host")).to be_valid + expect(FactoryBot.build(:miq_policy, :towhat => "Host")).to be_valid end it 'reports invalid towhat' do - expect(FactoryGirl.build(:miq_policy, :towhat => "BobsYourUncle")).not_to be_valid + expect(FactoryBot.build(:miq_policy, :towhat => "BobsYourUncle")).not_to be_valid end end end diff --git a/spec/models/miq_product_feature_spec.rb b/spec/models/miq_product_feature_spec.rb index 5937b234eea..814ee93f317 100644 --- a/spec/models/miq_product_feature_spec.rb +++ b/spec/models/miq_product_feature_spec.rb @@ -88,9 +88,9 @@ def traverse_product_features(product_feature, &block) end it "existing records" do - deleted = FactoryGirl.create(:miq_product_feature, :identifier => "xxx") - changed = FactoryGirl.create(:miq_product_feature, :identifier => "dialog_new_editor", :name => "XXX") - unchanged = FactoryGirl.create(:miq_product_feature_everything) + deleted = FactoryBot.create(:miq_product_feature, :identifier => "xxx") + changed = FactoryBot.create(:miq_product_feature, :identifier => "dialog_new_editor", :name => "XXX") + unchanged = FactoryBot.create(:miq_product_feature_everything) unchanged_orig_updated_at = unchanged.updated_at MiqProductFeature.seed_features(feature_path) @@ -148,7 +148,7 @@ def traverse_product_features(product_feature, &block) Tenant.default_tenant end - let!(:tenant) { FactoryGirl.create(:tenant, :parent => root_tenant) } + let!(:tenant) { FactoryBot.create(:tenant, :parent => root_tenant) } before do MiqProductFeature.seed_features(feature_path) @@ -313,11 +313,11 @@ def traverse_product_features(product_feature, &block) # 2 3 # 4 5 it "populates parent and children" do - f1 = FactoryGirl.create(:miq_product_feature, :identifier => "f1", :name => "F1n") - FactoryGirl.create(:miq_product_feature, :identifier => "f2", :name => "F2n", :parent_id => f1.id) - f3 = FactoryGirl.create(:miq_product_feature, :identifier => "f3", :name => "F3n", :parent_id => f1.id) - FactoryGirl.create(:miq_product_feature, :identifier => "f4", :name => "F4n", :parent_id => f3.id) - FactoryGirl.create(:miq_product_feature, :identifier => "f5", :name => "F5n", :parent_id => f3.id) + f1 = FactoryBot.create(:miq_product_feature, :identifier => "f1", :name => "F1n") + FactoryBot.create(:miq_product_feature, :identifier => "f2", :name => "F2n", :parent_id => f1.id) + f3 = FactoryBot.create(:miq_product_feature, :identifier => "f3", :name => "F3n", :parent_id => f1.id) + FactoryBot.create(:miq_product_feature, :identifier => "f4", :name => "F4n", :parent_id => f3.id) + FactoryBot.create(:miq_product_feature, :identifier => "f5", :name => "F5n", :parent_id => f3.id) expect { MiqProductFeature.features }.to match_query_limit_of(1) expect { MiqProductFeature.features }.to match_query_limit_of(0) @@ -334,12 +334,12 @@ def traverse_product_features(product_feature, &block) end describe "feature object cache" do - let!(:f0) { FactoryGirl.create(:miq_product_feature, :identifier => "everything", :name => "F0n") } - let!(:f1) { FactoryGirl.create(:miq_product_feature, :identifier => "f1", :name => "F1n", :parent_id => f0.id) } - let!(:f2) { FactoryGirl.create(:miq_product_feature, :identifier => "f2", :name => "F2n", :parent_id => f1.id) } - let!(:f3) { FactoryGirl.create(:miq_product_feature, :identifier => "f3", :name => "F3n", :parent_id => f1.id) } - let!(:f4) { FactoryGirl.create(:miq_product_feature, :identifier => "f4", :name => "F4n", :parent_id => f3.id) } - let!(:f5) { FactoryGirl.create(:miq_product_feature, :identifier => "f5", :name => "F5n", :parent_id => f3.id) } + let!(:f0) { FactoryBot.create(:miq_product_feature, :identifier => "everything", :name => "F0n") } + let!(:f1) { FactoryBot.create(:miq_product_feature, :identifier => "f1", :name => "F1n", :parent_id => f0.id) } + let!(:f2) { FactoryBot.create(:miq_product_feature, :identifier => "f2", :name => "F2n", :parent_id => f1.id) } + let!(:f3) { FactoryBot.create(:miq_product_feature, :identifier => "f3", :name => "F3n", :parent_id => f1.id) } + let!(:f4) { FactoryBot.create(:miq_product_feature, :identifier => "f4", :name => "F4n", :parent_id => f3.id) } + let!(:f5) { FactoryBot.create(:miq_product_feature, :identifier => "f5", :name => "F5n", :parent_id => f3.id) } it "memoizes hash to prevent extra db queries" do expect { MiqProductFeature.obj_features }.to match_query_limit_of(1) diff --git a/spec/models/miq_provision/post_install_callback_spec.rb b/spec/models/miq_provision/post_install_callback_spec.rb index aca60dd40b2..f14bc2b3e48 100644 --- a/spec/models/miq_provision/post_install_callback_spec.rb +++ b/spec/models/miq_provision/post_install_callback_spec.rb @@ -18,7 +18,7 @@ def _log end end - let(:destination) { FactoryGirl.build(:vm) } + let(:destination) { FactoryBot.build(:vm) } ALLOWED_PHASES = [:poll_destination_powered_off_in_provider, :poll_destination_powered_off_in_vmdb].freeze BLOCKED_PHASES = [ diff --git a/spec/models/miq_provision/state_machine_spec.rb b/spec/models/miq_provision/state_machine_spec.rb index 51ce44177d0..79d125da991 100644 --- a/spec/models/miq_provision/state_machine_spec.rb +++ b/spec/models/miq_provision/state_machine_spec.rb @@ -1,14 +1,14 @@ describe MiqProvision do context "::StateMachine" do - let(:req_user) { FactoryGirl.create(:user_with_group) } - let(:ems) { FactoryGirl.create(:ems_openstack_with_authentication) } - let(:flavor) { FactoryGirl.create(:flavor_openstack, :ems_ref => 24) } + let(:req_user) { FactoryBot.create(:user_with_group) } + let(:ems) { FactoryBot.create(:ems_openstack_with_authentication) } + let(:flavor) { FactoryBot.create(:flavor_openstack, :ems_ref => 24) } let(:options) { {:src_vm_id => template.id, :vm_target_name => "test_vm_1"} } - let(:template) { FactoryGirl.create(:template_openstack, :ext_management_system => ems, :ems_ref => SecureRandom.uuid) } - let(:vm) { FactoryGirl.create(:vm_openstack, :ext_management_system => ems) } + let(:template) { FactoryBot.create(:template_openstack, :ext_management_system => ems, :ems_ref => SecureRandom.uuid) } + let(:vm) { FactoryBot.create(:vm_openstack, :ext_management_system => ems) } let(:task) do - FactoryGirl.create(:miq_provision_openstack, + FactoryBot.create(:miq_provision_openstack, :source => template, :destination => vm, :state => 'pending', @@ -74,7 +74,7 @@ end context "#post_create_destination" do - let(:user) { FactoryGirl.create(:user_with_email_and_group) } + let(:user) { FactoryBot.create(:user_with_email_and_group) } it "sets description" do options[:vm_description] = description = "foo bar" @@ -89,8 +89,8 @@ end it "sets ownership" do - group_owner = FactoryGirl.create(:miq_group, :description => "desired") - group_current = FactoryGirl.create(:miq_group, :description => "current") + group_owner = FactoryBot.create(:miq_group, :description => "desired") + group_current = FactoryBot.create(:miq_group, :description => "current") user.update_attributes!(:miq_groups => [group_owner, group_current], :current_group => group_current) options[:owner_email] = user.email options[:owner_group] = group_owner.description diff --git a/spec/models/miq_provision_request_spec.rb b/spec/models/miq_provision_request_spec.rb index 152d2bdf328..882a3684e6c 100644 --- a/spec/models/miq_provision_request_spec.rb +++ b/spec/models/miq_provision_request_spec.rb @@ -1,26 +1,26 @@ describe MiqProvisionRequest do context "#request_task_class_from" do it "retrieves the provision class when the vm has EMS" do - ems = FactoryGirl.create(:ems_vmware) - vm = FactoryGirl.create(:vm_vmware, :ext_management_system => ems) + ems = FactoryBot.create(:ems_vmware) + vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems) expect(described_class.request_task_class_from('options' => {:src_vm_id => vm.id})).to eq ManageIQ::Providers::Vmware::InfraManager::Provision expect(described_class.request_task_class_from('options' => {:src_vm_id => vm.id, :provision_type => "pxe"})).to eq ManageIQ::Providers::Vmware::InfraManager::ProvisionViaPxe - ems = FactoryGirl.create(:ems_redhat) - vm = FactoryGirl.create(:vm_redhat, :ext_management_system => ems) + ems = FactoryBot.create(:ems_redhat) + vm = FactoryBot.create(:vm_redhat, :ext_management_system => ems) expect(described_class.request_task_class_from('options' => {:src_vm_id => vm.id})).to eq ManageIQ::Providers::Redhat::InfraManager::Provision - ems = FactoryGirl.create(:ems_openstack) - vm = FactoryGirl.create(:vm_openstack, :ext_management_system => ems) + ems = FactoryBot.create(:ems_openstack) + vm = FactoryBot.create(:vm_openstack, :ext_management_system => ems) expect(described_class.request_task_class_from('options' => {:src_vm_id => vm.id})).to eq ManageIQ::Providers::Openstack::CloudManager::Provision - ems = FactoryGirl.create(:ems_amazon) - vm = FactoryGirl.create(:vm_amazon, :ext_management_system => ems) + ems = FactoryBot.create(:ems_amazon) + vm = FactoryBot.create(:vm_amazon, :ext_management_system => ems) expect(described_class.request_task_class_from('options' => {:src_vm_id => vm.id})).to eq ManageIQ::Providers::Amazon::CloudManager::Provision end it "fails to retrieve the provision class when the vm has no EMS" do - vm = FactoryGirl.create(:vm_redhat) + vm = FactoryBot.create(:vm_redhat) expect { described_class.request_task_class_from('options' => {:src_vm_id => vm.id}) }.to raise_error(MiqException::MiqProvisionError) end @@ -31,32 +31,32 @@ context "A new provision request," do before { allow_any_instance_of(User).to receive(:role).and_return("admin") } - let(:approver) { FactoryGirl.create(:user_miq_request_approver) } - let(:user) { FactoryGirl.create(:user) } - let(:ems) { FactoryGirl.create(:ems_vmware) } - let(:vm) { FactoryGirl.create(:vm_vmware, :name => "vm1", :location => "abc/def.vmx") } - let(:vm_template) { FactoryGirl.create(:template_vmware, :name => "template1", :ext_management_system => ems) } + let(:approver) { FactoryBot.create(:user_miq_request_approver) } + let(:user) { FactoryBot.create(:user) } + let(:ems) { FactoryBot.create(:ems_vmware) } + let(:vm) { FactoryBot.create(:vm_vmware, :name => "vm1", :location => "abc/def.vmx") } + let(:vm_template) { FactoryBot.create(:template_vmware, :name => "template1", :ext_management_system => ems) } it "should not be created without requester being specified" do - expect { FactoryGirl.create(:miq_provision_request, :requester => nil) }.to raise_error(ActiveRecord::RecordInvalid) + expect { FactoryBot.create(:miq_provision_request, :requester => nil) }.to raise_error(ActiveRecord::RecordInvalid) end it "should not be created with a valid userid but no vm being specified" do - expect { FactoryGirl.create(:miq_provision_request, :requester => user, :source => nil) }.to raise_error(ActiveRecord::RecordInvalid) + expect { FactoryBot.create(:miq_provision_request, :requester => user, :source => nil) }.to raise_error(ActiveRecord::RecordInvalid) end it "should be created from either a VM or Template" do - expect { FactoryGirl.create(:miq_provision_request, :requester => user, :src_vm_id => vm_template.id) }.not_to raise_error - expect { FactoryGirl.create(:miq_provision_request, :requester => user, :src_vm_id => vm.id) }.not_to raise_error + expect { FactoryBot.create(:miq_provision_request, :requester => user, :src_vm_id => vm_template.id) }.not_to raise_error + expect { FactoryBot.create(:miq_provision_request, :requester => user, :src_vm_id => vm.id) }.not_to raise_error end it "should not be created with a valid userid but invalid vm being specified" do - expect { FactoryGirl.create(:miq_provision_request, :requester => user, :src_vm_id => 42) }.to raise_error(ActiveRecord::RecordInvalid) + expect { FactoryBot.create(:miq_provision_request, :requester => user, :src_vm_id => 42) }.to raise_error(ActiveRecord::RecordInvalid) end context "with a valid userid and source vm," do before do - @pr = FactoryGirl.create(:miq_provision_request, :requester => user, :src_vm_id => vm_template.id, :options => {:owner_email => 'tester@miq.com'}) + @pr = FactoryBot.create(:miq_provision_request, :requester => user, :src_vm_id => vm_template.id, :options => {:owner_email => 'tester@miq.com'}) @request = @pr.miq_request end @@ -129,7 +129,7 @@ it "should return stats from quota methods" do prov_options = {:number_of_vms => [2, '2'], :owner_email => 'tester@miq.com', :vm_memory => [1024, '1024'], :number_of_cpus => [2, '2']} - @pr2 = FactoryGirl.create(:miq_provision_request, :requester => user, :src_vm_id => vm_template.id, :options => prov_options) + @pr2 = FactoryBot.create(:miq_provision_request, :requester => user, :src_vm_id => vm_template.id, :options => prov_options) stats = @pr.check_quota(:requests_by_owner) expect(stats).to be_kind_of(Hash) @@ -143,7 +143,7 @@ context "for cloud and infra providers," do def create_request(user, vm_template, prov_options) - FactoryGirl.create(:miq_provision_request, :requester => user, + FactoryBot.create(:miq_provision_request, :requester => user, :description => "request", :tenant => user.current_tenant, :source => vm_template, @@ -156,13 +156,13 @@ def create_request(user, vm_template, prov_options) end let(:create_requests) do - ems = FactoryGirl.create(:ems_vmware) - vmware_tenant = FactoryGirl.create(:tenant) - group = FactoryGirl.create(:miq_group, :tenant => vmware_tenant) - @vmware_user1 = FactoryGirl.create(:user_with_email, :miq_groups => [group]) - @vmware_user2 = FactoryGirl.create(:user_with_email, :miq_groups => [group]) - hardware = FactoryGirl.create(:hardware, :cpu1x2, :memory_mb => 512) - @vmware_template = FactoryGirl.create(:template_vmware, + ems = FactoryBot.create(:ems_vmware) + vmware_tenant = FactoryBot.create(:tenant) + group = FactoryBot.create(:miq_group, :tenant => vmware_tenant) + @vmware_user1 = FactoryBot.create(:user_with_email, :miq_groups => [group]) + @vmware_user2 = FactoryBot.create(:user_with_email, :miq_groups => [group]) + hardware = FactoryBot.create(:hardware, :cpu1x2, :memory_mb => 512) + @vmware_template = FactoryBot.create(:template_vmware, :ext_management_system => ems, :hardware => hardware) prov_options = {:number_of_vms => [2, '2'], :vm_memory => [1024, '1024'], :number_of_cpus => [2, '2']} @@ -170,14 +170,14 @@ def create_request(user, vm_template, prov_options) 2.times { create_request(@vmware_user2, @vmware_template, prov_options) } - ems = FactoryGirl.create(:ems_google_with_authentication, - :availability_zones => [FactoryGirl.create(:availability_zone_google)]) - google_tenant = FactoryGirl.create(:tenant) - group = FactoryGirl.create(:miq_group, :tenant => google_tenant) - @google_user1 = FactoryGirl.create(:user_with_email, :miq_groups => [group]) - @google_user2 = FactoryGirl.create(:user_with_email, :miq_groups => [group]) - @google_template = FactoryGirl.create(:template_google, :ext_management_system => ems) - flavor = FactoryGirl.create(:flavor_google, :ems_id => ems.id, + ems = FactoryBot.create(:ems_google_with_authentication, + :availability_zones => [FactoryBot.create(:availability_zone_google)]) + google_tenant = FactoryBot.create(:tenant) + group = FactoryBot.create(:miq_group, :tenant => google_tenant) + @google_user1 = FactoryBot.create(:user_with_email, :miq_groups => [group]) + @google_user2 = FactoryBot.create(:user_with_email, :miq_groups => [group]) + @google_template = FactoryBot.create(:template_google, :ext_management_system => ems) + flavor = FactoryBot.create(:flavor_google, :ems_id => ems.id, :cpus => 4, :cpu_cores => 1, :memory => 1024) prov_options = {:number_of_vms => 1, :src_vm_id => vm_template.id, :boot_disk_size => ["10.GB", "10 GB"], :placement_auto => [true, 1], :instance_type => [flavor.id, flavor.name]} @@ -268,7 +268,7 @@ def create_request(user, vm_template, prov_options) end context "when processing tags" do - before { FactoryGirl.create(:classification_department_with_tags) } + before { FactoryBot.create(:classification_department_with_tags) } it "should add and delete tags from a request" do expect(@pr.get_tags.length).to eq(0) diff --git a/spec/models/miq_provision_request_template_spec.rb b/spec/models/miq_provision_request_template_spec.rb index 5a5527e6752..f5d2593c43a 100644 --- a/spec/models/miq_provision_request_template_spec.rb +++ b/spec/models/miq_provision_request_template_spec.rb @@ -1,42 +1,42 @@ describe MiqProvisionRequestTemplate do - let(:user) { FactoryGirl.create(:user) } + let(:user) { FactoryBot.create(:user) } let(:template) do - FactoryGirl.create(:template_vmware, - :ext_management_system => FactoryGirl.create(:ems_vmware_with_authentication)) + FactoryBot.create(:template_vmware, + :ext_management_system => FactoryBot.create(:ems_vmware_with_authentication)) end - let(:parent_svc) { FactoryGirl.create(:service, :guid => SecureRandom.uuid, :options => {:dialog => {}}) } + let(:parent_svc) { FactoryBot.create(:service, :guid => SecureRandom.uuid, :options => {:dialog => {}}) } let(:bundle_parent_svc) do - FactoryGirl.create(:service, :guid => SecureRandom.uuid, :options => {:dialog => {}}) + FactoryBot.create(:service, :guid => SecureRandom.uuid, :options => {:dialog => {}}) end let(:service_resource) do - FactoryGirl.create(:service_resource, + FactoryBot.create(:service_resource, :resource_type => 'MiqRequest', :resource_id => service_template_request.id) end let(:service_template) do - FactoryGirl.create(:service_template) + FactoryBot.create(:service_template) end let(:bundle_service_template) do - FactoryGirl.create(:service_template) + FactoryBot.create(:service_template) end let(:service_template_resource) do - FactoryGirl.create(:service_resource, + FactoryBot.create(:service_resource, :resource_type => 'ServiceTemplate', :resource_id => service_template.id) end let(:bundle_service_template_resource) do - FactoryGirl.create(:service_resource, + FactoryBot.create(:service_resource, :resource_type => 'ServiceTemplate', :resource_id => bundle_service_template.id) end - let(:service_template_request) { FactoryGirl.create(:service_template_provision_request, :requester => user) } + let(:service_template_request) { FactoryBot.create(:service_template_provision_request, :requester => user) } let(:service_task) do - FactoryGirl.create(:service_template_provision_task, + FactoryBot.create(:service_template_provision_task, :miq_request => service_template_request, :options => {:service_resource_id => service_resource.id}) end let(:parent_service_task) do - FactoryGirl.create(:service_template_provision_task, + FactoryBot.create(:service_template_provision_task, :status => 'Ok', :state => 'pending', :request_type => 'clone_to_service', @@ -44,7 +44,7 @@ :options => {:service_resource_id => service_template_resource.id}) end let(:bundle_service_task) do - FactoryGirl.create(:service_template_provision_task, + FactoryBot.create(:service_template_provision_task, :status => 'Ok', :state => 'pending', :request_type => 'clone_to_service', @@ -52,7 +52,7 @@ :options => {:service_resource_id => bundle_service_template_resource.id}) end let(:provision_request_template) do - FactoryGirl.create(:miq_provision_request_template, + FactoryBot.create(:miq_provision_request_template, :requester => user, :src_vm_id => template.id, :options => { @@ -142,7 +142,7 @@ end context "with service_task user" do - let(:user) { FactoryGirl.create(:user_with_email) } + let(:user) { FactoryBot.create(:user_with_email) } it "sets owner in options" do service_task.update_attributes(:userid => user.userid) diff --git a/spec/models/miq_provision_spec.rb b/spec/models/miq_provision_spec.rb index 1ab114fd59b..c7307554a10 100644 --- a/spec/models/miq_provision_spec.rb +++ b/spec/models/miq_provision_spec.rb @@ -2,7 +2,7 @@ context "A new provision request," do before do @os = OperatingSystem.new(:product_name => 'Microsoft Windows') - @admin = FactoryGirl.create(:user_with_group, :role => "admin") + @admin = FactoryBot.create(:user_with_group, :role => "admin") @target_vm_name = 'clone test' @options = { :pass => 1, @@ -17,16 +17,16 @@ context "with VMware infrastructure" do before do - @ems = FactoryGirl.create(:ems_vmware_with_authentication) - @vm_template = FactoryGirl.create(:template_vmware, :name => "template1", :ext_management_system => @ems, :operating_system => @os, :cpu_limit => -1, :cpu_reserve => 0) - @vm = FactoryGirl.create(:vm_vmware, :name => "vm1", :location => "abc/def.vmx") + @ems = FactoryBot.create(:ems_vmware_with_authentication) + @vm_template = FactoryBot.create(:template_vmware, :name => "template1", :ext_management_system => @ems, :operating_system => @os, :cpu_limit => -1, :cpu_reserve => 0) + @vm = FactoryBot.create(:vm_vmware, :name => "vm1", :location => "abc/def.vmx") end context "with a valid userid and source vm," do before do - @pr = FactoryGirl.create(:miq_provision_request, :requester => @admin, :src_vm_id => @vm_template.id) + @pr = FactoryBot.create(:miq_provision_request, :requester => @admin, :src_vm_id => @vm_template.id) @options[:src_vm_id] = [@vm_template.id, @vm_template.name] - @vm_prov = FactoryGirl.create(:miq_provision, :userid => @admin.userid, :miq_request => @pr, :source => @vm_template, :request_type => 'template', :state => 'pending', :status => 'Ok', :options => @options) + @vm_prov = FactoryBot.create(:miq_provision, :userid => @admin.userid, :miq_request => @pr, :source => @vm_template, :request_type => 'template', :state => 'pending', :status => 'Ok', :options => @options) end it "should get values out of an arrays in the options hash" do @@ -110,7 +110,7 @@ it "When task is part of a ServiceTemplateProvisionRequest the description should not update" do request_descripton = "Service Name Test" - service_provision_request = FactoryGirl.create(:service_template_provision_request, :description => request_descripton) + service_provision_request = FactoryBot.create(:service_template_provision_request, :description => request_descripton) @vm_prov.update_attributes(:miq_request_id => service_provision_request.id) expect(service_provision_request).not_to receive(:update_description_from_tasks) @@ -194,7 +194,7 @@ context "#eligible_resources" do it "workflow should be called with placement_auto = false and skip_dialog_load = true" do - prov = FactoryGirl.build(:miq_provision) + prov = FactoryBot.build(:miq_provision) host = double('Host', :id => 1, :name => 'my_host') workflow = double("MiqProvisionWorkflow", :allowed_hosts => [host]) @@ -210,7 +210,7 @@ end describe "#placement_auto" do - let(:miq_provision) { FactoryGirl.build(:miq_provision, :options => {:placement_auto => placement_option}) } + let(:miq_provision) { FactoryBot.build(:miq_provision, :options => {:placement_auto => placement_option}) } context "when option[:placement_auto] is true" do let(:placement_option) { [true, 1] } diff --git a/spec/models/miq_provision_virt_workflow_spec.rb b/spec/models/miq_provision_virt_workflow_spec.rb index 230dfce52a6..06bb54acf35 100644 --- a/spec/models/miq_provision_virt_workflow_spec.rb +++ b/spec/models/miq_provision_virt_workflow_spec.rb @@ -1,10 +1,10 @@ describe MiqProvisionVirtWorkflow do - let(:workflow) { FactoryGirl.create(:miq_provision_virt_workflow) } + let(:workflow) { FactoryBot.create(:miq_provision_virt_workflow) } context "#new" do let(:sdn) { 'SysprepDomainName' } let(:host) { double('Host', :id => 1, :name => 'my_host') } - let(:user) { FactoryGirl.create(:user_with_email) } + let(:user) { FactoryBot.create(:user_with_email) } before do allow(workflow).to receive_messages(:validate => true) @@ -67,11 +67,11 @@ context 'network selection' do before do - @ems = FactoryGirl.create(:ems_vmware) - @host1 = FactoryGirl.create(:host_vmware, :ems_id => @ems.id) - @host2 = FactoryGirl.create(:host_vmware, :ems_id => @ems.id) - @src_vm = FactoryGirl.create(:vm_vmware, :host => @host1, :ems_id => @ems.id) - @other_vm = FactoryGirl.create(:vm_vmware, :host => @host2, :ems_id => @ems.id) + @ems = FactoryBot.create(:ems_vmware) + @host1 = FactoryBot.create(:host_vmware, :ems_id => @ems.id) + @host2 = FactoryBot.create(:host_vmware, :ems_id => @ems.id) + @src_vm = FactoryBot.create(:vm_vmware, :host => @host1, :ems_id => @ems.id) + @other_vm = FactoryBot.create(:vm_vmware, :host => @host2, :ems_id => @ems.id) allow(Rbac).to receive(:search) do |hash| [Array.wrap(hash[:targets])] end @@ -83,16 +83,16 @@ context 'vlans' do before do - s11 = FactoryGirl.create(:switch, :name => "A") - s12 = FactoryGirl.create(:switch, :name => "B") - s13 = FactoryGirl.create(:switch, :name => "C") - s14 = FactoryGirl.create(:switch, :name => "D") + s11 = FactoryBot.create(:switch, :name => "A") + s12 = FactoryBot.create(:switch, :name => "B") + s13 = FactoryBot.create(:switch, :name => "C") + s14 = FactoryBot.create(:switch, :name => "D") @src_vm.host.switches = [s11, s12, s13] @other_vm.host.switches = [s14] - @lan11 = FactoryGirl.create(:lan, :name => "lan_A", :switch_id => s11.id) - @lan12 = FactoryGirl.create(:lan, :name => "lan_B", :switch_id => s12.id) - @lan13 = FactoryGirl.create(:lan, :name => "lan_C", :switch_id => s13.id) - @lan14 = FactoryGirl.create(:lan, :name => "lan_D", :switch_id => s14.id) + @lan11 = FactoryBot.create(:lan, :name => "lan_A", :switch_id => s11.id) + @lan12 = FactoryBot.create(:lan, :name => "lan_B", :switch_id => s12.id) + @lan13 = FactoryBot.create(:lan, :name => "lan_C", :switch_id => s13.id) + @lan14 = FactoryBot.create(:lan, :name => "lan_D", :switch_id => s14.id) end it '#allowed_vlans' do @@ -116,22 +116,22 @@ context '#allowed_hosts_obj' do before do - @ems = FactoryGirl.create(:ems_vmware) - @host1 = FactoryGirl.create(:host_vmware, :ems_id => @ems.id) - @host2 = FactoryGirl.create(:host_vmware, :ems_id => @ems.id) - @src_vm = FactoryGirl.create(:vm_vmware, :ems_id => @ems.id) + @ems = FactoryBot.create(:ems_vmware) + @host1 = FactoryBot.create(:host_vmware, :ems_id => @ems.id) + @host2 = FactoryBot.create(:host_vmware, :ems_id => @ems.id) + @src_vm = FactoryBot.create(:vm_vmware, :ems_id => @ems.id) allow(workflow).to receive(:find_all_ems_of_type).and_return([@host1, @host2]) allow(Rbac).to receive(:search) do |hash| [Array.wrap(hash[:targets])] end workflow.instance_variable_set(:@target_resource, nil) - s1 = FactoryGirl.create(:switch, :name => "A") - s2 = FactoryGirl.create(:switch, :name => "B") + s1 = FactoryBot.create(:switch, :name => "A") + s2 = FactoryBot.create(:switch, :name => "B") @host1.switches = [s1] @host2.switches = [s2] - @lan1 = FactoryGirl.create(:lan, :name => "lan_A", :switch_id => s1.id) - @lan2 = FactoryGirl.create(:lan, :name => "lan_B", :switch_id => s2.id) + @lan1 = FactoryBot.create(:lan, :name => "lan_A", :switch_id => s1.id) + @lan2 = FactoryBot.create(:lan, :name => "lan_B", :switch_id => s2.id) end it 'finds all hosts with no selected network' do @@ -146,9 +146,9 @@ end context "#update_requester_from_parameters" do - let(:user_new) { FactoryGirl.create(:user_with_email) } + let(:user_new) { FactoryBot.create(:user_with_email) } let(:data_new_user) { {:user_name => user_new.name} } - let(:current_user) { FactoryGirl.create(:user_with_email) } + let(:current_user) { FactoryBot.create(:user_with_email) } it "finds and sets a new user if one is passed in" do expect(User).to receive(:lookup_by_identity).and_return(user_new).once @@ -230,7 +230,7 @@ end it "with a provider model defined" do - ems = FactoryGirl.create(:ems_vmware) + ems = FactoryBot.create(:ems_vmware) expect(workflow.class).to receive(:provider_model).once.and_return(ems.class) expect(workflow.allowed_template_condition).to eq(["vms.template = ? AND vms.ems_id in (?)", true, [ems.id]]) @@ -258,9 +258,9 @@ end it "returns a hash struct if a vm or template is found" do - ems = FactoryGirl.create(:ems_vmware) - host1 = FactoryGirl.create(:host_vmware, :ems_id => ems.id) - src_vm = FactoryGirl.create(:vm_vmware, :host => host1, :ems_id => ems.id) + ems = FactoryBot.create(:ems_vmware) + host1 = FactoryBot.create(:host_vmware, :ems_id => ems.id) + src_vm = FactoryBot.create(:vm_vmware, :host => host1, :ems_id => ems.id) allow(workflow).to receive(:source_vm_rbac_filter).and_return([src_vm]) expect(workflow.ws_find_template_or_vm("", "VMWARE", "asdf-adsf", "asdfadfasdf")).to be_a(MiqHashStruct) end @@ -348,9 +348,9 @@ context '#make_request (update)' do let(:template) do - FactoryGirl.create( + FactoryBot.create( :template_vmware, - :ext_management_system => FactoryGirl.create(:ems_vmware_with_authentication) + :ext_management_system => FactoryBot.create(:ems_vmware_with_authentication) ) end let(:values) { {:src_vm_id => [template.id, template.name]} } @@ -372,13 +372,13 @@ ApplicationRecord.region_to_range(remote_region_number).first end - let(:remote_vmware) { FactoryGirl.create(:ems_vmware_with_authentication, :id => external_region_id) } - let(:local_vmware) { FactoryGirl.create(:ems_vmware_with_authentication) } + let(:remote_vmware) { FactoryBot.create(:ems_vmware_with_authentication, :id => external_region_id) } + let(:local_vmware) { FactoryBot.create(:ems_vmware_with_authentication) } it "only returns records from its region" do EvmSpecHelper.local_miq_server # Because there is no default timezone in settings - FactoryGirl.create(:template_vmware, :ext_management_system => remote_vmware, :id => external_region_id) - FactoryGirl.create(:template_vmware, :ext_management_system => local_vmware) + FactoryBot.create(:template_vmware, :ext_management_system => remote_vmware, :id => external_region_id) + FactoryBot.create(:template_vmware, :ext_management_system => local_vmware) expect(MiqTemplate.count).to eq(2) expect(workflow.allowed_templates.count).to eq(1) diff --git a/spec/models/miq_provision_workflow_spec.rb b/spec/models/miq_provision_workflow_spec.rb index 9587b211f0c..50ac5d31fb4 100644 --- a/spec/models/miq_provision_workflow_spec.rb +++ b/spec/models/miq_provision_workflow_spec.rb @@ -1,9 +1,9 @@ silence_warnings { MiqProvisionWorkflow.const_set("DIALOGS_VIA_AUTOMATE", false) } describe MiqProvisionWorkflow do - let(:admin) { FactoryGirl.create(:user_admin) } + let(:admin) { FactoryBot.create(:user_admin) } let(:server) { EvmSpecHelper.local_miq_server } - let(:dialog) { FactoryGirl.create(:miq_dialog_provision) } + let(:dialog) { FactoryBot.create(:miq_dialog_provision) } context "seeded" do context "After setup," do before do @@ -21,24 +21,24 @@ context "With a Valid Template," do before do - @ems = FactoryGirl.create(:ems_vmware, :name => "Test EMS", :zone => server.zone) - @host = FactoryGirl.create(:host, :name => "test_host", :hostname => "test_host", :state => 'on', + @ems = FactoryBot.create(:ems_vmware, :name => "Test EMS", :zone => server.zone) + @host = FactoryBot.create(:host, :name => "test_host", :hostname => "test_host", :state => 'on', :ext_management_system => @ems) - @vm_template = FactoryGirl.create(:template_vmware, :name => "template", :ext_management_system => @ems, + @vm_template = FactoryBot.create(:template_vmware, :name => "template", :ext_management_system => @ems, :host => @host) - @hardware = FactoryGirl.create(:hardware, :vm_or_template => @vm_template, :guest_os => "winxppro", + @hardware = FactoryBot.create(:hardware, :vm_or_template => @vm_template, :guest_os => "winxppro", :memory_mb => 512, :cpu_sockets => 2) - @switch = FactoryGirl.create(:switch, :name => 'vSwitch0', :ports => 32, :hosts => [@host]) - @lan = FactoryGirl.create(:lan, :name => "VM Network", :switch => @switch) - @ethernet = FactoryGirl.create(:guest_device, :hardware => @hardware, :lan => @lan, + @switch = FactoryBot.create(:switch, :name => 'vSwitch0', :ports => 32, :hosts => [@host]) + @lan = FactoryBot.create(:lan, :name => "VM Network", :switch => @switch) + @ethernet = FactoryBot.create(:guest_device, :hardware => @hardware, :lan => @lan, :device_type => 'ethernet', :controller_type => 'ethernet', :address => '00:50:56:ba:10:6b', :present => false, :start_connected => true) end it "should create an MiqRequest when calling from_ws" do - FactoryGirl.create(:classification_cost_center_with_tags) + FactoryBot.create(:classification_cost_center_with_tags) request = ManageIQ::Providers::Vmware::InfraManager::ProvisionWorkflow.from_ws( "1.0", admin, "template", "target", false, "cc|001|environment|test", "") expect(request).to be_a_kind_of(MiqRequest) @@ -47,7 +47,7 @@ end it "should set tags" do - FactoryGirl.create(:classification_cost_center_with_tags) + FactoryBot.create(:classification_cost_center_with_tags) request = ManageIQ::Providers::Vmware::InfraManager::ProvisionWorkflow.from_ws( "1.1", admin, {'name' => 'template'}, {'vm_name' => 'spec_test'}, nil, {'cc' => '001', 'environment' => 'test'}, nil, nil, nil) @@ -105,8 +105,8 @@ end context '.class_for_source' do - let(:provider) { FactoryGirl.create(:ems_amazon) } - let(:template) { FactoryGirl.create(:template_amazon, :name => "template") } + let(:provider) { FactoryBot.create(:ems_amazon) } + let(:template) { FactoryBot.create(:template_amazon, :name => "template") } let(:workflow_class) { provider.class.provision_workflow_class } it 'with valid source' do @@ -115,7 +115,7 @@ end it 'with orphaned source' do - template.storage = FactoryGirl.create(:storage) + template.storage = FactoryBot.create(:storage) expect(template.orphaned?).to be_truthy expect(described_class.class_for_source(template.id)).to eq(workflow_class) diff --git a/spec/models/miq_queue_spec.rb b/spec/models/miq_queue_spec.rb index 8920e8c7dc6..8f0444ad5bb 100644 --- a/spec/models/miq_queue_spec.rb +++ b/spec/models/miq_queue_spec.rb @@ -1,5 +1,5 @@ describe MiqQueue do - specify { expect(FactoryGirl.build(:miq_queue)).to be_valid } + specify { expect(FactoryBot.build(:miq_queue)).to be_valid } context "#deliver" do before do @@ -112,7 +112,7 @@ it "works with MiqQueueRetryLater(deliver_on)" do deliver_on = Time.now.utc + 1.minute allow(Storage).to receive(:foobar).and_raise(MiqException::MiqQueueRetryLater.new(:deliver_on => deliver_on)) - msg = FactoryGirl.build(:miq_queue, :state => MiqQueue::STATE_DEQUEUE, :handler => @miq_server, :class_name => 'Storage', :method_name => 'foobar') + msg = FactoryBot.build(:miq_queue, :state => MiqQueue::STATE_DEQUEUE, :handler => @miq_server, :class_name => 'Storage', :method_name => 'foobar') status, message, result = msg.deliver expect(status).to eq(MiqQueue::STATUS_RETRY) @@ -136,7 +136,7 @@ it "sets last_exception on raised Exception" do ex = StandardError.new("something blewup") allow(MiqServer).to receive(:foobar).and_raise(ex) - msg = FactoryGirl.build(:miq_queue, :state => MiqQueue::STATE_DEQUEUE, :handler => @miq_server, :class_name => 'MiqServer', :method_name => 'foobar') + msg = FactoryBot.build(:miq_queue, :state => MiqQueue::STATE_DEQUEUE, :handler => @miq_server, :class_name => 'MiqServer', :method_name => 'foobar') expect(msg._log).to receive(:error).with(/Error:/) expect(msg._log).to receive(:log_backtrace) status, message, _result = msg.deliver @@ -148,8 +148,8 @@ describe "user_context" do it "sets the User.current_user" do - user = FactoryGirl.create(:user_with_group, :name => 'Freddy Kreuger') - msg = FactoryGirl.create(:miq_queue, :state => MiqQueue::STATE_DEQUEUE, + user = FactoryBot.create(:user_with_group, :name => 'Freddy Kreuger') + msg = FactoryBot.create(:miq_queue, :state => MiqQueue::STATE_DEQUEUE, :handler => @miq_server, :class_name => 'Storage', :method_name => 'foobar', @@ -170,8 +170,8 @@ describe "#check_for_timeout" do it "will destroy a dequeued message when it times out" do - handler = FactoryGirl.create(:miq_ems_refresh_worker) - msg = FactoryGirl.create(:miq_queue, :state => MiqQueue::STATE_DEQUEUE, :handler => handler, :msg_timeout => 1.minute) + handler = FactoryBot.create(:miq_ems_refresh_worker) + msg = FactoryBot.create(:miq_queue, :state => MiqQueue::STATE_DEQUEUE, :handler => handler, :msg_timeout => 1.minute) Timecop.travel(10.minutes) do expect($log).to receive(:warn) @@ -202,7 +202,7 @@ ] message_parms.each do |mparms| - msg = FactoryGirl.create(:miq_queue) + msg = FactoryBot.create(:miq_queue) mparms.each { |k, v| msg.send("#{k}=", v) } expect(MiqQueue.format_short_log_msg(msg)).to eq("Message id: [#{msg.id}]") expect(MiqQueue.format_full_log_msg(msg)).to eq("Message id: [#{msg.id}], #{msg.handler_type} id: [#{msg.handler_id}], Zone: [#{msg.zone}], Role: [#{msg.role}], Server: [#{msg.server_guid}], MiqTask id: [#{msg.miq_task_id}], Ident: [#{msg.queue_name}], Target id: [#{msg.target_id}], Instance id: [#{msg.instance_id}], Task id: [#{msg.task_id}], Command: [#{msg.class_name}.#{msg.method_name}], Timeout: [#{msg.msg_timeout}], Priority: [#{msg.priority}], State: [#{msg.state}], Deliver On: [#{msg.deliver_on}], Data: [#{msg.data.nil? ? "" : "#{msg.data.length} bytes"}], Args: #{msg.args.inspect}") @@ -240,7 +240,7 @@ ] message_parms.each do |mparms| - msg = FactoryGirl.build(:miq_queue, mparms) + msg = FactoryBot.build(:miq_queue, mparms) expect(MiqQueue.format_short_log_msg(msg)).to eq("Message id: [#{msg.id}]") expect(MiqQueue.format_full_log_msg(msg)).to eq("Message id: [#{msg.id}], #{msg.handler_type} id: [#{msg.handler_id}], Zone: [#{msg.zone}], Role: [#{msg.role}], Server: [#{msg.server_guid}], MiqTask id: [#{msg.miq_task_id}], Ident: [#{msg.queue_name}], Target id: [#{msg.target_id}], Instance id: [#{msg.instance_id}], Task id: [#{msg.task_id}], Command: [#{msg.class_name}.#{msg.method_name}], Timeout: [#{msg.msg_timeout}], Priority: [#{msg.priority}], State: [#{msg.state}], Deliver On: [#{msg.deliver_on}], Data: [#{msg.data.nil? ? "" : "#{msg.data.length} bytes"}], Args: #{args_cleaned_password.inspect}") end @@ -286,7 +286,7 @@ _, @miq_server, @zone = EvmSpecHelper.create_guid_miq_server_zone @t1 = Time.parse("Wed Apr 20 00:15:00 UTC 2011") - @msg = FactoryGirl.create(:miq_queue, :zone => @zone.name, :role => "role1", :priority => 20, :created_on => @t1) + @msg = FactoryBot.create(:miq_queue, :zone => @zone.name, :role => "role1", :priority => 20, :created_on => @t1) end it "should requeue a message with new message id" do @@ -339,8 +339,8 @@ before do _, @miq_server, = EvmSpecHelper.create_guid_miq_server_zone - @worker = FactoryGirl.create(:miq_ems_refresh_worker, :miq_server_id => @miq_server.id) - @msg = FactoryGirl.create(:miq_queue, :state => MiqQueue::STATE_DEQUEUE, :task_id => "task123", :handler => @worker) + @worker = FactoryBot.create(:miq_ems_refresh_worker, :miq_server_id => @miq_server.id) + @msg = FactoryBot.create(:miq_queue, :state => MiqQueue::STATE_DEQUEUE, :task_id => "task123", :handler => @worker) end it "should find a message by task id" do @@ -771,7 +771,7 @@ def self.some_method(single_arg) end it "should not unqueue a message from a different zone" do - zone = FactoryGirl.create(:zone) + zone = FactoryBot.create(:zone) MiqQueue.put( :class_name => 'MyClass', :method_name => 'method1', @@ -844,7 +844,7 @@ def self.some_method(single_arg) context "validates that the zone exists in the current region" do it "with a matching region" do - zone = FactoryGirl.create(:zone) + zone = FactoryBot.create(:zone) expect(MiqQueue.create!(:state => "ready", :zone => zone.name)).to be_kind_of(MiqQueue) end diff --git a/spec/models/miq_queue_worker_base/runner_spec.rb b/spec/models/miq_queue_worker_base/runner_spec.rb index b2270402e65..4a8b341936c 100644 --- a/spec/models/miq_queue_worker_base/runner_spec.rb +++ b/spec/models/miq_queue_worker_base/runner_spec.rb @@ -1,7 +1,7 @@ describe MiqQueueWorkerBase::Runner do context "#get_message_via_drb" do let(:server) { EvmSpecHelper.local_miq_server } - let(:worker) { FactoryGirl.create(:miq_generic_worker, :miq_server => server, :pid => 123) } + let(:worker) { FactoryBot.create(:miq_generic_worker, :miq_server => server, :pid => 123) } let(:runner) do allow_any_instance_of(MiqQueueWorkerBase::Runner).to receive(:sync_config) allow_any_instance_of(MiqQueueWorkerBase::Runner).to receive(:set_connection_pool_size) @@ -11,7 +11,7 @@ it "sets message to 'error' and raises for unhandled exceptions" do # simulate what may happen if invalid yaml is deserialized allow_any_instance_of(MiqQueue).to receive(:args).and_raise(ArgumentError) - q1 = FactoryGirl.create(:miq_queue) + q1 = FactoryBot.create(:miq_queue) allow(runner) .to receive(:worker_monitor_drb) .and_return(double(:get_queue_message => [q1.id, q1.lock_version])) diff --git a/spec/models/miq_region_spec.rb b/spec/models/miq_region_spec.rb index 324620be671..38fbc37fafa 100644 --- a/spec/models/miq_region_spec.rb +++ b/spec/models/miq_region_spec.rb @@ -1,5 +1,5 @@ describe MiqRegion do - let(:region) { FactoryGirl.create(:miq_region, :region => ApplicationRecord.my_region_number) } + let(:region) { FactoryBot.create(:miq_region, :region => ApplicationRecord.my_region_number) } # the first id from a region other than ours let(:external_region_id) do remote_region_number = ApplicationRecord.my_region_number + 1 @@ -20,9 +20,9 @@ context "with cloud and infra EMSes" do before do _, _, zone = EvmSpecHelper.create_guid_miq_server_zone - ems_vmware = FactoryGirl.create(:ems_vmware, :zone => zone) - ems_openstack = FactoryGirl.create(:ems_openstack, :zone => zone) - ems_redhat = FactoryGirl.create(:ems_redhat, :zone => zone) + ems_vmware = FactoryBot.create(:ems_vmware, :zone => zone) + ems_openstack = FactoryBot.create(:ems_openstack, :zone => zone) + ems_redhat = FactoryBot.create(:ems_redhat, :zone => zone) @ems_clouds = [ems_openstack] @ems_infras = [ems_redhat, ems_vmware] @@ -63,7 +63,7 @@ end it "raises Exception if db region_id doesn't match my_region_number" do - @db = FactoryGirl.create(:miq_database) + @db = FactoryBot.create(:miq_database) allow(MiqRegion).to receive_messages(:my_region_number => @region_number + 1) expect { MiqRegion.seed }.to raise_error(Exception) end @@ -153,7 +153,7 @@ describe "#api_system_auth_token" do it "generates the token correctly" do user = "admin" - server = FactoryGirl.create(:miq_server, :has_active_webservices => true) + server = FactoryBot.create(:miq_server, :has_active_webservices => true) token = region.api_system_auth_token(user) token_hash = YAML.load(MiqPassword.decrypt(token)) @@ -166,9 +166,9 @@ describe "#vms" do it "brings them back" do - FactoryGirl.create(:vm_vmware, :id => external_region_id) - vm = FactoryGirl.create(:vm_vmware) - FactoryGirl.create(:template_vmware) + FactoryBot.create(:vm_vmware, :id => external_region_id) + vm = FactoryBot.create(:vm_vmware) + FactoryBot.create(:template_vmware) expect(region.vms).to eq([vm]) end @@ -176,9 +176,9 @@ describe "#miq_templates" do it "brings them back" do - FactoryGirl.create(:vm_vmware, :id => external_region_id) - FactoryGirl.create(:vm_vmware) - t = FactoryGirl.create(:template_vmware) + FactoryBot.create(:vm_vmware, :id => external_region_id) + FactoryBot.create(:vm_vmware) + t = FactoryBot.create(:template_vmware) expect(region.miq_templates).to eq([t]) end @@ -186,9 +186,9 @@ describe "#vms_and_templates" do it "brings them back" do - FactoryGirl.create(:vm_vmware, :id => external_region_id) - vm = FactoryGirl.create(:vm_vmware) - t = FactoryGirl.create(:template_vmware) + FactoryBot.create(:vm_vmware, :id => external_region_id) + vm = FactoryBot.create(:vm_vmware) + t = FactoryBot.create(:template_vmware) expect(region.vms_and_templates).to match_array [vm, t] end @@ -201,7 +201,7 @@ let(:ip) { "1.1.1.94" } let(:url) { "https://www.manageiq.org" } let!(:web_server) do - FactoryGirl.create(:miq_server, :has_active_webservices => true, + FactoryBot.create(:miq_server, :has_active_webservices => true, :hostname => hostname, :ipaddress => ip) end @@ -217,7 +217,7 @@ end it "with no recently active servers" do - FactoryGirl.create(:miq_server, :has_active_webservices => true, :hostname => hostname, :last_heartbeat => 11.minutes.ago.utc) + FactoryBot.create(:miq_server, :has_active_webservices => true, :hostname => hostname, :last_heartbeat => 11.minutes.ago.utc) expect(region.remote_ws_url).to be_nil end @@ -230,7 +230,7 @@ let(:ip) { "1.1.1.94" } let(:url) { "http://localhost:3000" } let!(:ui_server) do - FactoryGirl.create(:miq_server, :has_active_userinterface => true, + FactoryBot.create(:miq_server, :has_active_userinterface => true, :hostname => hostname, :ipaddress => ip) end @@ -246,7 +246,7 @@ end it "with no recently active servers" do - FactoryGirl.create(:miq_server, :has_active_userinterface => true, :hostname => hostname, :last_heartbeat => 11.minutes.ago.utc) + FactoryBot.create(:miq_server, :has_active_userinterface => true, :hostname => hostname, :last_heartbeat => 11.minutes.ago.utc) expect(region.remote_ws_url).to be_nil end @@ -254,13 +254,13 @@ describe "#remote_ui_miq_server" do it "with no recently active servers" do - server = FactoryGirl.create(:miq_server, :has_active_userinterface => true, :hostname => "example.com") + server = FactoryBot.create(:miq_server, :has_active_userinterface => true, :hostname => "example.com") expect(region.remote_ui_miq_server).to eq(server) end it "with no recently active servers" do - FactoryGirl.create(:miq_server, :has_active_userinterface => true, :hostname => "example.com", :last_heartbeat => 1.month.ago.utc) + FactoryBot.create(:miq_server, :has_active_userinterface => true, :hostname => "example.com", :last_heartbeat => 1.month.ago.utc) expect(region.remote_ui_miq_server).to be_nil end @@ -268,13 +268,13 @@ describe "#remote_ws_miq_server" do it "with no recently active servers" do - server = FactoryGirl.create(:miq_server, :has_active_webservices => true, :hostname => "example.com") + server = FactoryBot.create(:miq_server, :has_active_webservices => true, :hostname => "example.com") expect(region.remote_ws_miq_server).to eq(server) end it "with no recently active servers" do - FactoryGirl.create(:miq_server, :has_active_webservices => true, :hostname => "example.com", :last_heartbeat => 1.month.ago.utc) + FactoryBot.create(:miq_server, :has_active_webservices => true, :hostname => "example.com", :last_heartbeat => 1.month.ago.utc) expect(region.remote_ws_miq_server).to be_nil end diff --git a/spec/models/miq_report/charting_spec.rb b/spec/models/miq_report/charting_spec.rb index 1e6dbf1220f..3f9c1868605 100644 --- a/spec/models/miq_report/charting_spec.rb +++ b/spec/models/miq_report/charting_spec.rb @@ -2,11 +2,11 @@ before do EvmSpecHelper.local_miq_server - @group = FactoryGirl.create(:miq_group) - @user = FactoryGirl.create(:user, :miq_groups => [@group]) + @group = FactoryBot.create(:miq_group) + @user = FactoryBot.create(:user, :miq_groups => [@group]) 5.times do |i| - vm = FactoryGirl.build(:vm_vmware) + vm = FactoryBot.build(:vm_vmware) vm.evm_owner_id = @user.id if i > 2 vm.miq_group_id = @user.current_group.id if vm.evm_owner_id || (i > 1) vm.save @@ -31,7 +31,7 @@ context 'to_chart' do it "raises an exception for missing sortby or type" do - rpt = FactoryGirl.create(:miq_report) + rpt = FactoryBot.create(:miq_report) # Can't create a graph without a sortby column expect { rpt.to_chart(@report_theme, @show_title, @options) } diff --git a/spec/models/miq_report/formats_spec.rb b/spec/models/miq_report/formats_spec.rb index dd77000d09c..9691fdfe04e 100644 --- a/spec/models/miq_report/formats_spec.rb +++ b/spec/models/miq_report/formats_spec.rb @@ -19,7 +19,7 @@ describe '.default_format_for_path' do context 'for chargebacks' do - let!(:cloud_volume) { FactoryGirl.create(:cloud_volume_openstack) } + let!(:cloud_volume) { FactoryBot.create(:cloud_volume_openstack) } before do ChargebackVm.refresh_dynamic_metric_columns diff --git a/spec/models/miq_report/generator_spec.rb b/spec/models/miq_report/generator_spec.rb index e7e51f6551c..a9b36424439 100644 --- a/spec/models/miq_report/generator_spec.rb +++ b/spec/models/miq_report/generator_spec.rb @@ -1,15 +1,15 @@ describe MiqReport::Generator do before do EvmSpecHelper.local_miq_server - @user = FactoryGirl.create(:user_with_group) - @time_profile_all = FactoryGirl.create(:time_profile_with_rollup, :tz => "UTC") - @host1 = FactoryGirl.create(:host) + @user = FactoryBot.create(:user_with_group) + @time_profile_all = FactoryBot.create(:time_profile_with_rollup, :tz => "UTC") + @host1 = FactoryBot.create(:host) end describe "#generate" do context "Memory Utilization Trends report (daily)" do before do - @miq_report_profile_all = FactoryGirl.create( + @miq_report_profile_all = FactoryBot.create( :miq_report, :db => "VimPerformanceTrend", :order => "Ascending", @@ -27,7 +27,7 @@ it "returns one row for each host" do used_mem_up = [400, 500, 600, 700] - @host2 = FactoryGirl.create(:host) + @host2 = FactoryBot.create(:host) create_rollup(@host1, @time_profile_all, used_mem_up) create_rollup(@host2, @time_profile_all, used_mem_up) @miq_report_profile_all.generate_table(:userid => @user.userid) @@ -67,7 +67,7 @@ def create_rollup(host, profile, used_mem) day_midnight = Time.zone.yesterday.beginning_of_day - used_mem.size.days used_mem.size.times do |i| - host.metric_rollups << FactoryGirl.create(:metric_rollup_host_daily, + host.metric_rollups << FactoryBot.create(:metric_rollup_host_daily, :timestamp => day_midnight + i.day, :time_profile_id => profile.id, :derived_memory_used => used_mem[i], diff --git a/spec/models/miq_report/import_export_spec.rb b/spec/models/miq_report/import_export_spec.rb index 320807039ba..281db581533 100644 --- a/spec/models/miq_report/import_export_spec.rb +++ b/spec/models/miq_report/import_export_spec.rb @@ -1,7 +1,7 @@ describe MiqReport::ImportExport do before do - @user = FactoryGirl.create(:user_admin) - @old_report = FactoryGirl.create(:miq_report, + @user = FactoryBot.create(:user_admin) + @old_report = FactoryBot.create(:miq_report, :name => "Test Report", :rpt_type => "Custom", :tz => "Eastern Time (US & Canada)", @@ -107,7 +107,7 @@ context ".view_yaml_filename" do let(:feature) { MiqProductFeature.find_all_by_identifier("vm_infra_explorer") } - let(:user) { FactoryGirl.create(:user, :features => feature) } + let(:user) { FactoryBot.create(:user, :features => feature) } before do EvmSpecHelper.seed_specific_product_features("vm_infra_explorer", "host_edit") diff --git a/spec/models/miq_report_result/purging_spec.rb b/spec/models/miq_report_result/purging_spec.rb index 9e3e56c2021..5fe296408a7 100644 --- a/spec/models/miq_report_result/purging_spec.rb +++ b/spec/models/miq_report_result/purging_spec.rb @@ -15,16 +15,16 @@ stub_settings(settings) @rr1 = [ - FactoryGirl.create(:miq_report_result, :miq_report_id => 1, :created_on => (6.months + 1.days).to_i.seconds.ago.utc), - FactoryGirl.create(:miq_report_result, :miq_report_id => 1, :created_on => (6.months - 1.days).to_i.seconds.ago.utc) + FactoryBot.create(:miq_report_result, :miq_report_id => 1, :created_on => (6.months + 1.days).to_i.seconds.ago.utc), + FactoryBot.create(:miq_report_result, :miq_report_id => 1, :created_on => (6.months - 1.days).to_i.seconds.ago.utc) ] @rr2 = [ - FactoryGirl.create(:miq_report_result, :miq_report_id => 2, :created_on => (6.months + 2.days).to_i.seconds.ago.utc), - FactoryGirl.create(:miq_report_result, :miq_report_id => 2, :created_on => (6.months + 1.days).to_i.seconds.ago.utc), - FactoryGirl.create(:miq_report_result, :miq_report_id => 2, :created_on => (6.months - 1.days).to_i.seconds.ago.utc) + FactoryBot.create(:miq_report_result, :miq_report_id => 2, :created_on => (6.months + 2.days).to_i.seconds.ago.utc), + FactoryBot.create(:miq_report_result, :miq_report_id => 2, :created_on => (6.months + 1.days).to_i.seconds.ago.utc), + FactoryBot.create(:miq_report_result, :miq_report_id => 2, :created_on => (6.months - 1.days).to_i.seconds.ago.utc) ] @rr_orphaned = [ - FactoryGirl.create(:miq_report_result, :miq_report_id => nil, :created_on => (6.months - 1.days).to_i.seconds.ago.utc) + FactoryBot.create(:miq_report_result, :miq_report_id => nil, :created_on => (6.months - 1.days).to_i.seconds.ago.utc) ] end diff --git a/spec/models/miq_report_result_spec.rb b/spec/models/miq_report_result_spec.rb index cbdb4549c66..43d335f4160 100644 --- a/spec/models/miq_report_result_spec.rb +++ b/spec/models/miq_report_result_spec.rb @@ -2,11 +2,11 @@ before do EvmSpecHelper.local_miq_server - @user1 = FactoryGirl.create(:user_with_group) + @user1 = FactoryBot.create(:user_with_group) end it "#_async_generate_result" do - task = FactoryGirl.create(:miq_task) + task = FactoryBot.create(:miq_task) EvmSpecHelper.local_miq_server report = MiqReport.create( :name => "VMs based on Disk Type", @@ -29,16 +29,16 @@ context "report result created by User 1 with current group 1" do before do - @report_1 = FactoryGirl.create(:miq_report) - group_1 = FactoryGirl.create(:miq_group) - group_2 = FactoryGirl.create(:miq_group) + @report_1 = FactoryBot.create(:miq_report) + group_1 = FactoryBot.create(:miq_group) + group_2 = FactoryBot.create(:miq_group) @user1.miq_groups << group_1 - @report_result1 = FactoryGirl.create(:miq_report_result, :miq_report_id => @report_1.id, :miq_group => group_1) - @report_result2 = FactoryGirl.create(:miq_report_result, :miq_report_id => @report_1.id, :miq_group => group_1) - @report_result_nil_report_id = FactoryGirl.create(:miq_report_result) + @report_result1 = FactoryBot.create(:miq_report_result, :miq_report_id => @report_1.id, :miq_group => group_1) + @report_result2 = FactoryBot.create(:miq_report_result, :miq_report_id => @report_1.id, :miq_group => group_1) + @report_result_nil_report_id = FactoryBot.create(:miq_report_result) - @report_2 = FactoryGirl.create(:miq_report) - @report_result3 = FactoryGirl.create(:miq_report_result, :miq_report_id => @report_2.id, :miq_group => group_2) + @report_2 = FactoryBot.create(:miq_report) + @report_result3 = FactoryBot.create(:miq_report_result, :miq_report_id => @report_2.id, :miq_group => group_2) User.current_user = @user1 end @@ -64,7 +64,7 @@ end it "returns report all results, admin user logged" do - admin_role = FactoryGirl.create(:miq_user_role, :features => MiqProductFeature::REPORT_ADMIN_FEATURE, :read_only => false) + admin_role = FactoryBot.create(:miq_user_role, :features => MiqProductFeature::REPORT_ADMIN_FEATURE, :read_only => false) User.current_user.current_group.miq_user_role = admin_role report_result = MiqReportResult.with_current_user_groups expected_reports = [@report_result1, @report_result2, @report_result3, @report_result_nil_report_id] @@ -76,7 +76,7 @@ context "persisting generated report results" do before do 5.times do |i| - vm = FactoryGirl.build(:vm_vmware) + vm = FactoryBot.build(:vm_vmware) vm.evm_owner_id = @user1.id if i > 2 vm.miq_group_id = @user1.current_group.id if vm.evm_owner_id || (i > 1) vm.save @@ -126,7 +126,7 @@ before do MiqUserRole.seed role = MiqUserRole.find_by(:name => "EvmRole-operator") - @miq_group = FactoryGirl.create(:miq_group, :miq_user_role => role, :description => "Group1") + @miq_group = FactoryBot.create(:miq_group, :miq_user_role => role, :description => "Group1") MiqReport.seed_report(@name_of_report = "Vendor and Guest OS") end @@ -144,7 +144,7 @@ describe "#status" do let(:report_name) { "Vendor and Guest OS" } - let(:task) { FactoryGirl.create(:miq_task) } + let(:task) { FactoryBot.create(:miq_task) } let(:miq_report_result) do MiqReport.seed_report(report_name) report = MiqReport.where(:name => report_name).last @@ -173,7 +173,7 @@ describe "serializing and deserializing report results" do it "can serialize and deserialize an MiqReport" do - report = FactoryGirl.build(:miq_report) + report = FactoryBot.build(:miq_report) report_result = described_class.new report_result.report_results = report @@ -211,11 +211,11 @@ describe ".counts_by_userid" do it "fetches counts" do - u1 = FactoryGirl.create(:user) - u2 = FactoryGirl.create(:user) - FactoryGirl.create(:miq_report_result, :userid => u1.userid) - FactoryGirl.create(:miq_report_result, :userid => u1.userid) - FactoryGirl.create(:miq_report_result, :userid => u2.userid) + u1 = FactoryBot.create(:user) + u2 = FactoryBot.create(:user) + FactoryBot.create(:miq_report_result, :userid => u1.userid) + FactoryBot.create(:miq_report_result, :userid => u1.userid) + FactoryBot.create(:miq_report_result, :userid => u2.userid) expect(MiqReportResult.counts_by_userid).to match_array([ {:userid => u1.userid, :count => 2}, diff --git a/spec/models/miq_report_spec.rb b/spec/models/miq_report_spec.rb index 84ec279e944..bd8314ef5a5 100644 --- a/spec/models/miq_report_spec.rb +++ b/spec/models/miq_report_spec.rb @@ -3,14 +3,14 @@ let(:custom_attributes_field) { custom_attribute_field.to_s.pluralize } before do - @user = FactoryGirl.create(:user_with_group) + @user = FactoryBot.create(:user_with_group) # create custom attributes @key = 'key1' @value = 'value1' - @resource = base_report == "Host" ? FactoryGirl.create(:host) : FactoryGirl.create(:vm_vmware) - FactoryGirl.create(custom_attribute_field, :resource => @resource, :name => @key, :value => @value) + @resource = base_report == "Host" ? FactoryBot.create(:host) : FactoryBot.create(:vm_vmware) + FactoryBot.create(custom_attribute_field, :resource => @resource, :name => @key, :value => @value) end let(:report) do @@ -40,15 +40,15 @@ describe MiqReport do context ".for_user" do - let(:my_user) { FactoryGirl.create(:user_with_group) } - let(:group_in_my_tenant) { FactoryGirl.create(:miq_group, :tenant => my_user.current_tenant) } + let(:my_user) { FactoryBot.create(:user_with_group) } + let(:group_in_my_tenant) { FactoryBot.create(:miq_group, :tenant => my_user.current_tenant) } - let(:other_tenant) { FactoryGirl.create(:tenant) } - let(:group_in_other_tenant) { FactoryGirl.create(:miq_group, :tenant => other_tenant) } + let(:other_tenant) { FactoryBot.create(:tenant) } + let(:group_in_other_tenant) { FactoryBot.create(:miq_group, :tenant => other_tenant) } - let!(:my_report) { FactoryGirl.create(:miq_report, :miq_group => my_user.current_group, :rpt_type => "Custom") } - let!(:report_in_my_tenant) { FactoryGirl.create(:miq_report, :miq_group => group_in_my_tenant, :rpt_type => "Custom") } - let!(:report_in_another_tenant) { FactoryGirl.create(:miq_report, :miq_group => group_in_other_tenant, :rpt_type => "Custom") } + let!(:my_report) { FactoryBot.create(:miq_report, :miq_group => my_user.current_group, :rpt_type => "Custom") } + let!(:report_in_my_tenant) { FactoryBot.create(:miq_report, :miq_group => group_in_my_tenant, :rpt_type => "Custom") } + let!(:report_in_another_tenant) { FactoryBot.create(:miq_report, :miq_group => group_in_other_tenant, :rpt_type => "Custom") } it "returns reports created by me or anyone in a group in my tenant" do User.current_user = my_user @@ -59,14 +59,14 @@ context "report with filtering in Registry" do let(:options) { {:targets_hash => true, :userid => "admin"} } - let(:miq_task) { FactoryGirl.create(:miq_task) } + let(:miq_task) { FactoryBot.create(:miq_task) } before do - @user = FactoryGirl.create(:user_with_group) + @user = FactoryBot.create(:user_with_group) - @registry = FactoryGirl.create(:registry_item, :name => "HKLM\\SOFTWARE\\WindowsFirewall : EnableFirewall", + @registry = FactoryBot.create(:registry_item, :name => "HKLM\\SOFTWARE\\WindowsFirewall : EnableFirewall", :data => 0) - @vm = FactoryGirl.create(:vm_vmware, :registry_items => [@registry]) + @vm = FactoryBot.create(:vm_vmware, :registry_items => [@registry]) EvmSpecHelper.local_miq_server end @@ -101,21 +101,21 @@ let(:custom_column_key_2) { 'manageiq.org' } let(:custom_column_key_3) { 'ATTR_Name_3' } let(:custom_column_value) { 'value1' } - let(:user) { FactoryGirl.create(:user_with_group) } - let(:ems) { FactoryGirl.create(:ems_vmware) } - let!(:vm_1) { FactoryGirl.create(:vm_vmware) } - let!(:vm_2) { FactoryGirl.create(:vm_vmware, :retired => false, :ext_management_system => ems) } + let(:user) { FactoryBot.create(:user_with_group) } + let(:ems) { FactoryBot.create(:ems_vmware) } + let!(:vm_1) { FactoryBot.create(:vm_vmware) } + let!(:vm_2) { FactoryBot.create(:vm_vmware, :retired => false, :ext_management_system => ems) } let(:virtual_column_key_1) { "#{CustomAttributeMixin::CUSTOM_ATTRIBUTES_PREFIX}kubernetes.io/hostname" } let(:virtual_column_key_2) { "#{CustomAttributeMixin::CUSTOM_ATTRIBUTES_PREFIX}manageiq.org" } let(:virtual_column_key_3) { "#{CustomAttributeMixin::CUSTOM_ATTRIBUTES_PREFIX}ATTR_Name_3" } - let(:miq_task) { FactoryGirl.create(:miq_task) } + let(:miq_task) { FactoryBot.create(:miq_task) } subject! do - FactoryGirl.create(:miq_custom_attribute, :resource => vm_1, :name => custom_column_key_1, + FactoryBot.create(:miq_custom_attribute, :resource => vm_1, :name => custom_column_key_1, :value => custom_column_value) - FactoryGirl.create(:miq_custom_attribute, :resource => vm_2, :name => custom_column_key_2, + FactoryBot.create(:miq_custom_attribute, :resource => vm_2, :name => custom_column_key_2, :value => custom_column_value) - FactoryGirl.create(:miq_custom_attribute, :resource => vm_2, :name => custom_column_key_3, + FactoryBot.create(:miq_custom_attribute, :resource => vm_2, :name => custom_column_key_3, :value => custom_column_value) end @@ -151,16 +151,16 @@ end let!(:container_image) do - FactoryGirl.create(:container_image, :name => "test_container_images") + FactoryBot.create(:container_image, :name => "test_container_images") end let!(:custom_attribute_1) do - FactoryGirl.create(:custom_attribute, :resource => container_image, :name => 'CATTR', :value => 'any_value', + FactoryBot.create(:custom_attribute, :resource => container_image, :name => 'CATTR', :value => 'any_value', :section => 'docker_labels') end let!(:custom_attribute_2) do - FactoryGirl.create(:custom_attribute, :resource => container_image, :name => 'CATTR', :value => 'other_value', + FactoryBot.create(:custom_attribute, :resource => container_image, :name => 'CATTR', :value => 'other_value', :section => 'labels') end @@ -271,23 +271,23 @@ end it '.get_expressions_by_model' do - FactoryGirl.create(:miq_report, :conditions => nil) - rep_nil = FactoryGirl.create(:miq_report) + FactoryBot.create(:miq_report, :conditions => nil) + rep_nil = FactoryBot.create(:miq_report) # FIXME: find a way to do this in a factory serialized_nil = "--- !!null \n...\n" ActiveRecord::Base.connection.execute("update miq_reports set conditions='#{serialized_nil}' where id=#{rep_nil.id}") - rep_ok = FactoryGirl.create(:miq_report, :conditions => "SOMETHING") + rep_ok = FactoryBot.create(:miq_report, :conditions => "SOMETHING") reports = MiqReport.get_expressions_by_model('Vm') expect(reports).to eq(rep_ok.name => rep_ok.id) end it "paged_view_search on vmdb_* tables" do # Create EVM tables/indexes and hourly metric data... - table = FactoryGirl.create(:vmdb_table_evm, :name => "accounts") - index = FactoryGirl.create(:vmdb_index, :name => "accounts_pkey", :vmdb_table => table) - FactoryGirl.create(:vmdb_metric, :resource => index, :timestamp => Time.now.utc, :capture_interval_name => 'hourly', :size => 102, :rows => 102, :pages => 102, :wasted_bytes => 102, :percent_bloat => 102) + table = FactoryBot.create(:vmdb_table_evm, :name => "accounts") + index = FactoryBot.create(:vmdb_index, :name => "accounts_pkey", :vmdb_table => table) + FactoryBot.create(:vmdb_metric, :resource => index, :timestamp => Time.now.utc, :capture_interval_name => 'hourly', :size => 102, :rows => 102, :pages => 102, :wasted_bytes => 102, :percent_bloat => 102) report_args = { "db" => "VmdbIndex", @@ -317,20 +317,20 @@ context "#paged_view_search" do it "filters vms in folders" do - host = FactoryGirl.create(:host) - vm1 = FactoryGirl.create(:vm_vmware, :host => host) + host = FactoryBot.create(:host) + vm1 = FactoryBot.create(:vm_vmware, :host => host) allow(vm1).to receive(:archived?).and_return(false) - vm2 = FactoryGirl.create(:vm_vmware, :host => host) + vm2 = FactoryBot.create(:vm_vmware, :host => host) allow(vm2).to receive(:archived?).and_return(false) allow(Vm).to receive(:find_by).and_return(vm1) - root = FactoryGirl.create(:ems_folder, :name => "datacenters") + root = FactoryBot.create(:ems_folder, :name => "datacenters") root.parent = host - usa = FactoryGirl.create(:ems_folder, :name => "usa") + usa = FactoryBot.create(:ems_folder, :name => "usa") usa.parent = root - nyc = FactoryGirl.create(:ems_folder, :name => "nyc") + nyc = FactoryBot.create(:ems_folder, :name => "nyc") nyc.parent = usa vm1.with_relationship_type("ems_metadata") { vm1.parent = usa } @@ -349,8 +349,8 @@ end it "paging with order" do - vm1 = FactoryGirl.create(:vm_vmware) - vm2 = FactoryGirl.create(:vm_vmware) + vm1 = FactoryBot.create(:vm_vmware) + vm2 = FactoryBot.create(:vm_vmware) ids = [vm1.id, vm2.id].sort report = MiqReport.new(:db => "Vm", :sortby => "id", :order => "Descending") @@ -361,8 +361,8 @@ end it "target_ids_for_paging caches results" do - vm = FactoryGirl.create(:vm_vmware) - FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) + FactoryBot.create(:vm_vmware) report = MiqReport.new(:db => "Vm") report.extras = {:target_ids_for_paging => [vm.id], :attrs_for_paging => {}} @@ -372,13 +372,13 @@ end it "VMs under Host with order" do - host1 = FactoryGirl.create(:host) - FactoryGirl.create(:vm_vmware, :host => host1, :name => "a") + host1 = FactoryBot.create(:host) + FactoryBot.create(:vm_vmware, :host => host1, :name => "a") - ems = FactoryGirl.create(:ems_vmware) - host2 = FactoryGirl.create(:host) - vmb = FactoryGirl.create(:vm_vmware, :host => host2, :name => "b", :ext_management_system => ems) - vmc = FactoryGirl.create(:vm_vmware, :host => host2, :name => "c", :ext_management_system => ems) + ems = FactoryBot.create(:ems_vmware) + host2 = FactoryBot.create(:host) + vmb = FactoryBot.create(:vm_vmware, :host => host2, :name => "b", :ext_management_system => ems) + vmc = FactoryBot.create(:vm_vmware, :host => host2, :name => "c", :ext_management_system => ems) report = MiqReport.new(:db => "Vm", :sortby => "name", :order => "Descending") results, = report.paged_view_search( @@ -393,12 +393,12 @@ end it "user managed filters" do - vm1 = FactoryGirl.create(:vm_vmware) + vm1 = FactoryBot.create(:vm_vmware) vm1.tag_with("/managed/environment/prod", :ns => "*") - vm2 = FactoryGirl.create(:vm_vmware) + vm2 = FactoryBot.create(:vm_vmware) vm2.tag_with("/managed/environment/dev", :ns => "*") - user = FactoryGirl.create(:user_with_group) + user = FactoryBot.create(:user_with_group) group = user.current_group allow(User).to receive_messages(:server_timezone => "UTC") group.entitlement = Entitlement.new @@ -420,10 +420,10 @@ end it "sortby, order, user filters, where sort column is in a sub-table" do - user = FactoryGirl.create(:user_with_group) + user = FactoryBot.create(:user_with_group) group = user.current_group - vm1 = FactoryGirl.create(:vm_vmware, :name => "VA", :storage => FactoryGirl.create(:storage, :name => "SA")) - vm2 = FactoryGirl.create(:vm_vmware, :name => "VB", :storage => FactoryGirl.create(:storage, :name => "SB")) + vm1 = FactoryBot.create(:vm_vmware, :name => "VA", :storage => FactoryBot.create(:storage, :name => "SA")) + vm2 = FactoryBot.create(:vm_vmware, :name => "VB", :storage => FactoryBot.create(:storage, :name => "SB")) tag = "/managed/environment/prod" group.entitlement = Entitlement.new group.entitlement.set_managed_filters([[tag]]) @@ -452,8 +452,8 @@ end it "sorting on a virtual column" do - FactoryGirl.create(:vm_vmware, :name => "B", :host => FactoryGirl.create(:host, :name => "A")) - FactoryGirl.create(:vm_vmware, :name => "A", :host => FactoryGirl.create(:host, :name => "B")) + FactoryBot.create(:vm_vmware, :name => "B", :host => FactoryBot.create(:host, :name => "A")) + FactoryBot.create(:vm_vmware, :name => "A", :host => FactoryBot.create(:host, :name => "B")) report = MiqReport.new(:db => "Vm", :sortby => %w(host_name name), :order => "Descending") options = { @@ -467,8 +467,8 @@ end it "expression filtering on a virtual column" do - FactoryGirl.create(:vm_vmware, :name => "VA", :host => FactoryGirl.create(:host, :name => "HA")) - FactoryGirl.create(:vm_vmware, :name => "VB", :host => FactoryGirl.create(:host, :name => "HB")) + FactoryBot.create(:vm_vmware, :name => "VA", :host => FactoryBot.create(:host, :name => "HA")) + FactoryBot.create(:vm_vmware, :name => "VB", :host => FactoryBot.create(:host, :name => "HB")) report = MiqReport.new(:db => "Vm") @@ -486,12 +486,12 @@ end it "expression filtering on a virtual column and user filters" do - user = FactoryGirl.create(:user_with_group) + user = FactoryBot.create(:user_with_group) group = user.current_group - _vm1 = FactoryGirl.create(:vm_vmware, :name => "VA", :host => FactoryGirl.create(:host, :name => "HA")) - vm2 = FactoryGirl.create(:vm_vmware, :name => "VB", :host => FactoryGirl.create(:host, :name => "HB")) - vm3 = FactoryGirl.create(:vm_vmware, :name => "VAA", :host => FactoryGirl.create(:host, :name => "HAA")) + _vm1 = FactoryBot.create(:vm_vmware, :name => "VA", :host => FactoryBot.create(:host, :name => "HA")) + vm2 = FactoryBot.create(:vm_vmware, :name => "VB", :host => FactoryBot.create(:host, :name => "HB")) + vm3 = FactoryBot.create(:vm_vmware, :name => "VAA", :host => FactoryBot.create(:host, :name => "HAA")) tag = "/managed/environment/prod" group.entitlement = Entitlement.new group.entitlement.set_managed_filters([[tag]]) @@ -520,10 +520,10 @@ end it "filtering on a virtual reflection" do - vm1 = FactoryGirl.create(:vm_vmware, :name => "VA") - vm2 = FactoryGirl.create(:vm_vmware, :name => "VB") - rp1 = FactoryGirl.create(:resource_pool, :name => "RPA") - rp2 = FactoryGirl.create(:resource_pool, :name => "RPB") + vm1 = FactoryBot.create(:vm_vmware, :name => "VA") + vm2 = FactoryBot.create(:vm_vmware, :name => "VB") + rp1 = FactoryBot.create(:resource_pool, :name => "RPA") + rp2 = FactoryBot.create(:resource_pool, :name => "RPB") rp1.add_child(vm1) rp2.add_child(vm2) @@ -541,8 +541,8 @@ end it "virtual columns included in cols" do - FactoryGirl.create(:vm_vmware, :host => FactoryGirl.create(:host, :name => "HA", :vmm_product => "ESX")) - FactoryGirl.create(:vm_vmware, :host => FactoryGirl.create(:host, :name => "HB", :vmm_product => "ESX")) + FactoryBot.create(:vm_vmware, :host => FactoryBot.create(:host, :name => "HA", :vmm_product => "ESX")) + FactoryBot.create(:vm_vmware, :host => FactoryBot.create(:host, :name => "HB", :vmm_product => "ESX")) report = MiqReport.new( :name => "VMs", @@ -569,13 +569,13 @@ describe "#generate_table" do it "with has_many through" do - ems = FactoryGirl.create(:ems_vmware_with_authentication) - user = FactoryGirl.create(:user_with_group) + ems = FactoryBot.create(:ems_vmware_with_authentication) + user = FactoryBot.create(:user_with_group) group = user.current_group - template = FactoryGirl.create(:template_vmware, :ext_management_system => ems) - vm = FactoryGirl.create(:vm_vmware, :ext_management_system => ems) - hardware = FactoryGirl.create(:hardware, :vm => vm) - FactoryGirl.create(:disk, :hardware => hardware, :disk_type => "thin") + template = FactoryBot.create(:template_vmware, :ext_management_system => ems) + vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems) + hardware = FactoryBot.create(:hardware, :vm => vm) + FactoryBot.create(:disk, :hardware => hardware, :disk_type => "thin") options = { :vm_name => vm.name, @@ -584,7 +584,7 @@ :src_vm_id => [template.id, template.name] } - provision = FactoryGirl.create( + provision = FactoryBot.create( :miq_provision_vmware, :destination => vm, :source => template, @@ -666,7 +666,7 @@ derived_memory_used_high_over_time_period derived_memory_used_low_over_time_period)}}) end - let(:ems) { FactoryGirl.create(:ems_vmware, :zone => @server.zone) } + let(:ems) { FactoryBot.create(:ems_vmware, :zone => @server.zone) } it "runs report" do report.generate_table(:userid => "admin") @@ -676,7 +676,7 @@ context "Tenant Quota Report" do include Spec::Support::QuotaHelper - let!(:tenant_without_quotas) { FactoryGirl.create(:tenant, :name=>"tenant_without_quotas") } + let!(:tenant_without_quotas) { FactoryBot.create(:tenant, :name=>"tenant_without_quotas") } let(:skip_condition) do YAML.load '--- !ruby/object:MiqExpression @@ -691,13 +691,13 @@ "tenant_quotas.available"] headers = ["Tenant Name", "Quota Name", "Total Quota", "Total Quota", "In Use", "Allocated", "Available"] - FactoryGirl.create(:miq_report, :title => "Tenant Quotas", :order => 'Ascending', :rpt_group => "Custom", + FactoryBot.create(:miq_report, :title => "Tenant Quotas", :order => 'Ascending', :rpt_group => "Custom", :priority => 231, :rpt_type => 'Custom', :db => 'Tenant', :col_order => cols, :template_type => "report", :headers => headers, :conditions => skip_condition, :sortby => ["tenant_quotas.name"]) end - let(:user_admin) { FactoryGirl.create(:user, :role => "super_administrator") } + let(:user_admin) { FactoryBot.create(:user, :role => "super_administrator") } def generate_table_cell(formatted_value) "#{formatted_value}" @@ -719,7 +719,7 @@ def generate_html_row(is_even, tenant_name, formatted_values) setup_model # dummy child tenant - FactoryGirl.create(:tenant, :parent => @tenant) + FactoryBot.create(:tenant, :parent => @tenant) # remove quotas that QuotaHelper already initialized @tenant.tenant_quotas = [] @@ -872,7 +872,7 @@ def generate_html_row(is_even, tenant_name, formatted_values) let(:hourly_variable_tier_rate) { {:variable_rate => hourly_rate.to_s} } let(:detail_params) { {:chargeback_rate_detail_fixed_compute_cost => { :tiers => [hourly_variable_tier_rate] } } } let!(:chargeback_rate) do - FactoryGirl.create(:chargeback_rate, :detail_params => detail_params) + FactoryBot.create(:chargeback_rate, :detail_params => detail_params) end let(:report_params) do { @@ -895,7 +895,7 @@ def generate_html_row(is_even, tenant_name, formatted_values) context "chargeback based on container images" do let(:label_name) { "version" } let(:label_value) { "1.0.0" } - let(:label) { FactoryGirl.build(:custom_attribute, :name => label_name, :value => label_value, :section => 'docker_labels') } + let(:label) { FactoryBot.build(:custom_attribute, :name => label_name, :value => label_value, :section => 'docker_labels') } let(:label_report_column) { "virtual_custom_attribute_#{label_name}" } let(:report) do MiqReport.new( @@ -920,14 +920,14 @@ def generate_html_row(is_even, tenant_name, formatted_values) end it "runs a report with a custom attribute" do - ems = FactoryGirl.create(:ems_openshift) - image = FactoryGirl.create(:container_image, :ext_management_system => ems) + ems = FactoryBot.create(:ems_openshift) + image = FactoryBot.create(:container_image, :ext_management_system => ems) image.docker_labels << label project_name = "my project" - project = FactoryGirl.create(:container_project, :name => project_name, :ext_management_system => ems) - group = FactoryGirl.create(:container_group, :ext_management_system => ems, :container_project => project) - container = FactoryGirl.create(:kubernetes_container, :container_group => group, :container_image => image) - container.metric_rollups << FactoryGirl.create(:metric_rollup_vm_hr, + project = FactoryBot.create(:container_project, :name => project_name, :ext_management_system => ems) + group = FactoryBot.create(:container_group, :ext_management_system => ems, :container_project => project) + container = FactoryBot.create(:kubernetes_container, :container_group => group, :container_image => image) + container.metric_rollups << FactoryBot.create(:metric_rollup_vm_hr, :with_data, :timestamp => 1.day.ago.beginning_of_day, :resource_id => container.id, @@ -945,7 +945,7 @@ def generate_html_row(is_even, tenant_name, formatted_values) context "chargeback based on container projects" do let(:label_name) { "version" } let(:label_value) { "1.0.0" } - let(:label) { FactoryGirl.build(:custom_attribute, :name => label_name, :value => label_value, :section => 'labels') } + let(:label) { FactoryBot.build(:custom_attribute, :name => label_name, :value => label_value, :section => 'labels') } let(:label_report_column) { "virtual_custom_attribute_#{label_name}" } let(:report) do MiqReport.new( @@ -970,11 +970,11 @@ def generate_html_row(is_even, tenant_name, formatted_values) end it "runs a report with a custom attribute" do - ems = FactoryGirl.create(:ems_openshift) + ems = FactoryBot.create(:ems_openshift) project_name = "my project" - project = FactoryGirl.create(:container_project, :name => project_name, :ext_management_system => ems, :created_on => 2.days.ago) + project = FactoryBot.create(:container_project, :name => project_name, :ext_management_system => ems, :created_on => 2.days.ago) project.labels << label - project.metric_rollups << FactoryGirl.create(:metric_rollup_vm_hr, + project.metric_rollups << FactoryBot.create(:metric_rollup_vm_hr, :with_data, :timestamp => 1.day.ago, :resource_id => project.id, @@ -991,7 +991,7 @@ def generate_html_row(is_even, tenant_name, formatted_values) context "chargeback based on vms" do let(:label_name) { "version" } let(:label_value) { "1.0.0" } - let(:label) { FactoryGirl.build(:custom_attribute, :name => label_name, :value => label_value, :section => 'labels') } + let(:label) { FactoryBot.build(:custom_attribute, :name => label_name, :value => label_value, :section => 'labels') } let(:label_report_column) { "virtual_custom_attribute_#{label_name}" } let(:report) do MiqReport.new( @@ -1017,27 +1017,27 @@ def generate_html_row(is_even, tenant_name, formatted_values) end it "runs a report with a custom attribute" do - ems = FactoryGirl.create(:ems_vmware) + ems = FactoryBot.create(:ems_vmware) - cat = FactoryGirl.create(:classification, :description => "Environment", :name => "environment", :single_value => true, :show => true) - c = FactoryGirl.create(:classification, :name => "prod", :description => "Production", :parent_id => cat.id) + cat = FactoryBot.create(:classification, :description => "Environment", :name => "environment", :single_value => true, :show => true) + c = FactoryBot.create(:classification, :name => "prod", :description => "Production", :parent_id => cat.id) tag = Tag.find_by(:name => "/managed/environment/prod") temp = {:cb_rate => chargeback_rate, :tag => [c, "vm"]} ChargebackRate.set_assignments(:compute, [temp]) vm_name = "test_vm" - vm1 = FactoryGirl.create(:vm_vmware, :name => vm_name, :evm_owner => FactoryGirl.create(:user_admin), :ems_ref => "ems_ref", + vm1 = FactoryBot.create(:vm_vmware, :name => vm_name, :evm_owner => FactoryBot.create(:user_admin), :ems_ref => "ems_ref", :created_on => 2.days.ago) vm1.tag_with(tag.name, :ns => '*') vm1.labels << label - host1 = FactoryGirl.create(:host, :hardware => FactoryGirl.create(:hardware, :memory_mb => 8124, :cpu_total_cores => 1, :cpu_speed => 9576), :vms => [vm1]) - storage = FactoryGirl.create(:storage_target_vmware) + host1 = FactoryBot.create(:host, :hardware => FactoryBot.create(:hardware, :memory_mb => 8124, :cpu_total_cores => 1, :cpu_speed => 9576), :vms => [vm1]) + storage = FactoryBot.create(:storage_target_vmware) host1.storages << storage - ems_cluster = FactoryGirl.create(:ems_cluster, :ext_management_system => ems) + ems_cluster = FactoryBot.create(:ems_cluster, :ext_management_system => ems) ems_cluster.hosts << host1 - vm1.metric_rollups << FactoryGirl.create(:metric_rollup_vm_hr, + vm1.metric_rollups << FactoryBot.create(:metric_rollup_vm_hr, :with_data, :timestamp => 1.day.ago, :resource_id => vm1.id, diff --git a/spec/models/miq_request_spec.rb b/spec/models/miq_request_spec.rb index 8fa1aa109ba..4fab5d1275d 100644 --- a/spec/models/miq_request_spec.rb +++ b/spec/models/miq_request_spec.rb @@ -1,6 +1,6 @@ describe MiqRequest do - let(:fred) { FactoryGirl.create(:user_with_group, :name => 'Fred Flintstone', :userid => 'fred', :email => "fred@example.com") } - let(:barney) { FactoryGirl.create(:user_with_group, :name => 'Barney Rubble', :userid => 'barney', :email => "barney@example.com") } + let(:fred) { FactoryBot.create(:user_with_group, :name => 'Fred Flintstone', :userid => 'fred', :email => "fred@example.com") } + let(:barney) { FactoryBot.create(:user_with_group, :name => 'Barney Rubble', :userid => 'barney', :email => "barney@example.com") } context "CONSTANTS" do it "REQUEST_TYPES" do @@ -27,10 +27,10 @@ context "A new request" do let(:event_name) { "hello" } - let(:miq_request) { FactoryGirl.build(:automation_request, :options => {:src_ids => [1]}) } - let(:request) { FactoryGirl.create(:vm_migrate_request, :requester => fred) } - let(:ems) { FactoryGirl.create(:ems_vmware) } - let(:template) { FactoryGirl.create(:template_vmware, :ext_management_system => ems) } + let(:miq_request) { FactoryBot.build(:automation_request, :options => {:src_ids => [1]}) } + let(:request) { FactoryBot.create(:vm_migrate_request, :requester => fred) } + let(:ems) { FactoryBot.create(:ems_vmware) } + let(:template) { FactoryBot.create(:template_vmware, :ext_management_system => ems) } it { expect(request).to be_valid } describe("#request_type_display") { it { expect(request.request_type_display).to eq("VM Migrate") } } @@ -68,7 +68,7 @@ end it "#call_automate_event_queue" do - zone = FactoryGirl.create(:zone) + zone = FactoryBot.create(:zone) allow(MiqServer).to receive(:my_zone).and_return(zone.name) expect(MiqQueue.count).to eq(0) @@ -112,7 +112,7 @@ end context "using Polymorphic Resource" do - let(:provision_request) { FactoryGirl.create(:miq_provision_request, :requester => fred, :src_vm_id => template.id) } + let(:provision_request) { FactoryBot.create(:miq_provision_request, :requester => fred, :src_vm_id => template.id) } it { expect(provision_request.workflow_class).to eq(ManageIQ::Providers::Vmware::InfraManager::ProvisionWorkflow) } @@ -194,8 +194,8 @@ context "with user approvals" do let(:reason) { "Why Not?" } - let(:fred_approval) { FactoryGirl.create(:miq_approval, :approver => fred, :reason => reason, :stamper => barney, :stamped_on => Time.now) } - let(:barney_approval) { FactoryGirl.create(:miq_approval, :approver => barney) } + let(:fred_approval) { FactoryBot.create(:miq_approval, :approver => fred, :reason => reason, :stamper => barney, :stamped_on => Time.now) } + let(:barney_approval) { FactoryBot.create(:miq_approval, :approver => barney) } before { request.miq_approvals = [fred_approval, barney_approval] } @@ -269,9 +269,9 @@ subject { described_class.with_reason_like(pattern).created_recently(days_ago).distinct.count } before do - FactoryGirl.create(:vm_migrate_request, :requester => fred, :created_on => 10.days.ago, :miq_approvals => approvals) - FactoryGirl.create(:vm_migrate_request, :requester => fred, :created_on => 14.days.ago, :miq_approvals => approvals) - FactoryGirl.create(:vm_migrate_request, :requester => fred, :created_on => 3.days.ago, :miq_approvals => approvals) + FactoryBot.create(:vm_migrate_request, :requester => fred, :created_on => 10.days.ago, :miq_approvals => approvals) + FactoryBot.create(:vm_migrate_request, :requester => fred, :created_on => 14.days.ago, :miq_approvals => approvals) + FactoryBot.create(:vm_migrate_request, :requester => fred, :created_on => 3.days.ago, :miq_approvals => approvals) end { @@ -288,7 +288,7 @@ def approvals reason.collect do |r| - FactoryGirl.create(:miq_approval, :approver => fred, :reason => r, :stamper => barney, :stamped_on => Time.now.utc) + FactoryBot.create(:miq_approval, :approver => fred, :reason => r, :stamper => barney, :stamped_on => Time.now.utc) end end end @@ -299,7 +299,7 @@ def approvals allow_any_instance_of(MiqApproval).to receive_messages(:authorized? => true) allow(MiqServer).to receive_messages(:my_zone => "default") - provision_request = FactoryGirl.create(:miq_provision_request, :requester => fred, :src_vm_id => template.id) + provision_request = FactoryBot.create(:miq_provision_request, :requester => fred, :src_vm_id => template.id) provision_request.deny(fred, "Why Not?") @@ -326,7 +326,7 @@ def approvals end context 'Service provisioning' do - let(:request) { FactoryGirl.create(:service_template_provision_request, :approval_state => 'approved', :requester => fred) } + let(:request) { FactoryBot.create(:service_template_provision_request, :approval_state => 'approved', :requester => fred) } let(:role) { 'automate' } context "uses the automate role" do @@ -335,8 +335,8 @@ def approvals end context 'VM provisioning' do - let(:template) { FactoryGirl.create(:template_vmware, :ext_management_system => FactoryGirl.create(:ems_vmware_with_authentication)) } - let(:request) { FactoryGirl.build(:miq_provision_request, :requester => fred, :src_vm_id => template.id).tap(&:valid?) } + let(:template) { FactoryBot.create(:template_vmware, :ext_management_system => FactoryBot.create(:ems_vmware_with_authentication)) } + let(:request) { FactoryBot.build(:miq_provision_request, :requester => fred, :src_vm_id => template.id).tap(&:valid?) } let(:role) { 'ems_operations' } context "uses the ems_operations role" do @@ -354,8 +354,8 @@ def approvals end let(:description) { 'my original information' } - let(:template) { FactoryGirl.create(:template_vmware, :ext_management_system => FactoryGirl.create(:ems_vmware_with_authentication)) } - let(:request) { FactoryGirl.build(:miq_provision_request, :requester => fred, :description => description, :src_vm_id => template.id).tap(&:valid?) } + let(:template) { FactoryBot.create(:template_vmware, :ext_management_system => FactoryBot.create(:ems_vmware_with_authentication)) } + let(:request) { FactoryBot.build(:miq_provision_request, :requester => fred, :description => description, :src_vm_id => template.id).tap(&:valid?) } it 'with 1 task' do request.options[:src_vm_id] = template.id @@ -400,7 +400,7 @@ def approvals it 'non VM provisioning' do description = 'Service Request' - request = FactoryGirl.create(:service_template_provision_request, :description => description, :requester => fred) + request = FactoryBot.create(:service_template_provision_request, :description => description, :requester => fred) request.post_create_request_tasks expect(request.description).to eq(description) end @@ -408,13 +408,13 @@ def approvals context '#workflow' do let(:provision_request) do - FactoryGirl.create(:miq_provision_request, + FactoryBot.create(:miq_provision_request, :requester => fred, :src_vm_id => template.id, :options => {:src_vm_id => template.id}) end - let(:ems) { FactoryGirl.create(:ems_vmware) } - let(:template) { FactoryGirl.create(:template_vmware, :ext_management_system => ems) } + let(:ems) { FactoryBot.create(:ems_vmware) } + let(:template) { FactoryBot.create(:template_vmware, :ext_management_system => ems) } let(:host) { double('Host', :id => 1, :name => 'my_host') } it "calls password_helper when a block is passed in" do @@ -423,11 +423,11 @@ def approvals end it "returns the allowed tags" do - FactoryGirl.create(:miq_dialog, + FactoryBot.create(:miq_dialog, :name => "miq_provision_dialogs", :dialog_type => MiqProvisionWorkflow) - FactoryGirl.create(:classification_department_with_tags) + FactoryBot.create(:classification_department_with_tags) tag = Classification.where(:description => 'Department', :parent_id => 0).includes(:tag).first provision_request.add_tag(tag.name, tag.children.first.name) @@ -438,14 +438,14 @@ def approvals end context '#create_request_task' do - let(:ems) { FactoryGirl.create(:ems_vmware_with_authentication) } - let(:template) { FactoryGirl.create(:template_vmware, :ext_management_system => ems) } + let(:ems) { FactoryBot.create(:ems_vmware_with_authentication) } + let(:template) { FactoryBot.create(:template_vmware, :ext_management_system => ems) } let(:request) do - FactoryGirl.create(:miq_provision_request, :requester => fred, :options => @options, :source => template) + FactoryBot.create(:miq_provision_request, :requester => fred, :options => @options, :source => template) end before do - allow(MiqRegion).to receive(:my_region).and_return(FactoryGirl.create(:miq_region)) + allow(MiqRegion).to receive(:my_region).and_return(FactoryBot.create(:miq_region)) ae_workspace = double("ae_workspace") allow(ae_workspace).to receive(:root).and_return("test_vm") allow(MiqAeEngine).to receive(:resolve_automation_object).and_return(ae_workspace) @@ -495,19 +495,19 @@ def approvals context "#get_user" do let(:root_tenant) { Tenant.seed } - let(:tenant1) { FactoryGirl.create(:tenant, :parent => root_tenant) } - let(:group1) { FactoryGirl.create(:miq_group, :description => 'Group 1', :tenant => root_tenant) } - let(:group2) { FactoryGirl.create(:miq_group, :description => 'Group 2', :tenant => tenant1) } - let(:user) { FactoryGirl.create(:user, :miq_groups => [group1, group2], :current_group => group1) } + let(:tenant1) { FactoryBot.create(:tenant, :parent => root_tenant) } + let(:group1) { FactoryBot.create(:miq_group, :description => 'Group 1', :tenant => root_tenant) } + let(:group2) { FactoryBot.create(:miq_group, :description => 'Group 2', :tenant => tenant1) } + let(:user) { FactoryBot.create(:user, :miq_groups => [group1, group2], :current_group => group1) } it "takes the requester group" do - request = FactoryGirl.create(:miq_provision_request, :requester => user, :options => {:requester_group => group2.description}) + request = FactoryBot.create(:miq_provision_request, :requester => user, :options => {:requester_group => group2.description}) expect(user.current_group).to eq(group1) expect(request.get_user.current_group).to eq(group2) end it "stays with user's current group" do - request = FactoryGirl.create(:miq_provision_request, :requester => user) + request = FactoryBot.create(:miq_provision_request, :requester => user) expect(user.current_group).to eq(group1) expect(request.get_user.current_group).to eq(group1) end @@ -519,7 +519,7 @@ def approvals end let(:request) do - FactoryGirl.create(:miq_provision_request, + FactoryBot.create(:miq_provision_request, :requester => fred, :options => {:a => "1"}) end @@ -553,9 +553,9 @@ def approvals end context "retire request source classes" do - let(:vm_retire_request) { FactoryGirl.create(:vm_retire_request, :requester => fred) } - let(:service_retire_request) { FactoryGirl.create(:service_retire_request, :requester => fred) } - let(:orch_stack_request) { FactoryGirl.create(:orchestration_stack_retire_request, :requester => fred) } + let(:vm_retire_request) { FactoryBot.create(:vm_retire_request, :requester => fred) } + let(:service_retire_request) { FactoryBot.create(:service_retire_request, :requester => fred) } + let(:orch_stack_request) { FactoryBot.create(:orchestration_stack_retire_request, :requester => fred) } it "gets the right source class names" do expect(vm_retire_request.class::SOURCE_CLASS_NAME).to eq('Vm') @@ -566,28 +566,28 @@ def approvals describe ".user_owned" do let(:regional_id) { ApplicationRecord.id_in_region(1, ApplicationRecord.my_region_number + 1) } - let(:user) { FactoryGirl.create(:user) } - let!(:regional_user) { FactoryGirl.create(:user, :userid => user.userid.upcase, :id => regional_id) } - let!(:request) { FactoryGirl.create(:vm_migrate_request, :requester => user) } - let!(:regional_request) { FactoryGirl.create(:vm_migrate_request, :requester => regional_user) } + let(:user) { FactoryBot.create(:user) } + let!(:regional_user) { FactoryBot.create(:user, :userid => user.userid.upcase, :id => regional_id) } + let!(:request) { FactoryBot.create(:vm_migrate_request, :requester => user) } + let!(:regional_request) { FactoryBot.create(:vm_migrate_request, :requester => regional_user) } it "finds request for cross region users" do - FactoryGirl.create(:vm_migrate_request, :requester => FactoryGirl.create(:user)) - FactoryGirl.create(:vm_migrate_request, :requester => FactoryGirl.create(:user), :id => regional_id + 1) + FactoryBot.create(:vm_migrate_request, :requester => FactoryBot.create(:user)) + FactoryBot.create(:vm_migrate_request, :requester => FactoryBot.create(:user), :id => regional_id + 1) expect(MiqRequest.user_owned(regional_user)).to match_array([request, regional_request]) end end describe ".group_owned" do let(:regional_id) { ApplicationRecord.id_in_region(1, ApplicationRecord.my_region_number + 1) } - let(:group) { FactoryGirl.create(:miq_group) } - let(:regional_group) { FactoryGirl.create(:miq_group, :id => regional_id) } - let(:user) { FactoryGirl.create(:user, :miq_groups => [group]) } - let!(:regional_user) { FactoryGirl.create(:user, :userid => user.userid.upcase, :id => regional_id, :miq_groups => [regional_group]) } - let!(:request) { FactoryGirl.create(:vm_migrate_request, :requester => user) } - let!(:regional_request) { FactoryGirl.create(:vm_migrate_request, :requester => regional_user) } + let(:group) { FactoryBot.create(:miq_group) } + let(:regional_group) { FactoryBot.create(:miq_group, :id => regional_id) } + let(:user) { FactoryBot.create(:user, :miq_groups => [group]) } + let!(:regional_user) { FactoryBot.create(:user, :userid => user.userid.upcase, :id => regional_id, :miq_groups => [regional_group]) } + let!(:request) { FactoryBot.create(:vm_migrate_request, :requester => user) } + let!(:regional_request) { FactoryBot.create(:vm_migrate_request, :requester => regional_user) } it "finds request for cross region groups" do - FactoryGirl.create(:vm_migrate_request, :requester => FactoryGirl.create(:user)) - FactoryGirl.create(:vm_migrate_request, :requester => FactoryGirl.create(:user), :id => regional_id + 1) + FactoryBot.create(:vm_migrate_request, :requester => FactoryBot.create(:user)) + FactoryBot.create(:vm_migrate_request, :requester => FactoryBot.create(:user), :id => regional_id + 1) expect(MiqRequest.user_owned(regional_user)).to match_array([request, regional_request]) end end diff --git a/spec/models/miq_request_task/dumping_spec.rb b/spec/models/miq_request_task/dumping_spec.rb index 7ce4342e936..af690f95eab 100644 --- a/spec/models/miq_request_task/dumping_spec.rb +++ b/spec/models/miq_request_task/dumping_spec.rb @@ -1,6 +1,6 @@ describe MiqRequestTask do context "::Dumping" do - let(:task) { FactoryGirl.create(:miq_request_task) } + let(:task) { FactoryBot.create(:miq_request_task) } describe '.dump_obj' do it 'accepts a hash' do diff --git a/spec/models/miq_request_task/post_install_callback_spec.rb b/spec/models/miq_request_task/post_install_callback_spec.rb index aa8136fe7c9..f8451fec584 100644 --- a/spec/models/miq_request_task/post_install_callback_spec.rb +++ b/spec/models/miq_request_task/post_install_callback_spec.rb @@ -1,7 +1,7 @@ describe MiqRequestTask::PostInstallCallback do - let(:miq_request) { FactoryGirl.build(:miq_provision_request, :requester => user) } - let(:task) { FactoryGirl.create(:miq_request_task, :miq_request => miq_request) } - let(:user) { FactoryGirl.build(:user) } + let(:miq_request) { FactoryBot.build(:miq_provision_request, :requester => user) } + let(:task) { FactoryBot.create(:miq_request_task, :miq_request => miq_request) } + let(:user) { FactoryBot.build(:user) } context ".post_install_callback" do it "valid id" do diff --git a/spec/models/miq_request_task/state_machine_spec.rb b/spec/models/miq_request_task/state_machine_spec.rb index 7ab58839811..e3f01396066 100644 --- a/spec/models/miq_request_task/state_machine_spec.rb +++ b/spec/models/miq_request_task/state_machine_spec.rb @@ -2,7 +2,7 @@ context "::StateMachine" do context "#signal" do it "will deal with exceptions" do - task = FactoryGirl.create(:miq_request_task) + task = FactoryBot.create(:miq_request_task) allow(task).to receive_messages(:miq_request => double("MiqRequest").as_null_object) exception = String.xxx rescue $! allow(task).to receive(:some_state).and_raise(exception) diff --git a/spec/models/miq_request_workflow_spec.rb b/spec/models/miq_request_workflow_spec.rb index 797d8798099..36e4403186f 100644 --- a/spec/models/miq_request_workflow_spec.rb +++ b/spec/models/miq_request_workflow_spec.rb @@ -1,9 +1,9 @@ describe MiqRequestWorkflow do - let(:workflow) { FactoryGirl.build(:miq_provision_workflow) } - let(:ems) { FactoryGirl.create(:ext_management_system) } - let(:resource_pool) { FactoryGirl.create(:resource_pool) } - let(:ems_folder) { FactoryGirl.create(:ems_folder) } - let(:datacenter) { FactoryGirl.create(:ems_folder, :type => "Datacenter") } + let(:workflow) { FactoryBot.build(:miq_provision_workflow) } + let(:ems) { FactoryBot.create(:ext_management_system) } + let(:resource_pool) { FactoryBot.create(:resource_pool) } + let(:ems_folder) { FactoryBot.create(:ems_folder) } + let(:datacenter) { FactoryBot.create(:ems_folder, :type => "Datacenter") } context "#validate" do let(:dialog) { workflow.instance_variable_get(:@dialogs) } @@ -218,13 +218,13 @@ end context "#allowed_tags" do - let!(:managed_classification) { FactoryGirl.create(:classification) } - let!(:no_child_classification) { FactoryGirl.create(:classification) } - let!(:read_only_classification) { FactoryGirl.create(:classification, :read_only => true) } - let!(:hidden_classification) { FactoryGirl.create(:classification, :show => false) } - let!(:unmanaged_classification) { FactoryGirl.create(:classification, :ns => "/unmanaged") } - let!(:child_classification_1) { FactoryGirl.create(:classification, :parent => managed_classification) } - let!(:child_classification_2) { FactoryGirl.create(:classification, :parent => unmanaged_classification) } + let!(:managed_classification) { FactoryBot.create(:classification) } + let!(:no_child_classification) { FactoryBot.create(:classification) } + let!(:read_only_classification) { FactoryBot.create(:classification, :read_only => true) } + let!(:hidden_classification) { FactoryBot.create(:classification, :show => false) } + let!(:unmanaged_classification) { FactoryBot.create(:classification, :ns => "/unmanaged") } + let!(:child_classification_1) { FactoryBot.create(:classification, :parent => managed_classification) } + let!(:child_classification_2) { FactoryBot.create(:classification, :parent => unmanaged_classification) } it "includes all managed tags" do allowed_tag_ids = workflow.allowed_tags.map { |c| c[:id] } @@ -241,10 +241,10 @@ end context "'allowed_*' methods" do - let(:cluster) { FactoryGirl.create(:ems_cluster, :ems_id => ems.id) } - let(:ems) { FactoryGirl.create(:ext_management_system) } - let(:resource_pool) { FactoryGirl.create(:resource_pool, :ems_id => ems.id) } - let(:host) { FactoryGirl.create(:host, :ems_id => ems.id) } + let(:cluster) { FactoryBot.create(:ems_cluster, :ems_id => ems.id) } + let(:ems) { FactoryBot.create(:ext_management_system) } + let(:resource_pool) { FactoryBot.create(:resource_pool, :ems_id => ems.id) } + let(:host) { FactoryBot.create(:host, :ems_id => ems.id) } before { allow_any_instance_of(User).to receive(:get_timezone).and_return("UTC") } @@ -259,7 +259,7 @@ end it "with valid sources" do - FactoryGirl.create(:ems_cluster) + FactoryBot.create(:ems_cluster) allow(workflow).to receive(:get_source_and_targets).and_return(:ems => ems) expect(workflow).to receive(:allowed_ci).with(:cluster, [:respool, :host, :folder], [cluster.id]) @@ -279,7 +279,7 @@ end it "with valid sources" do - FactoryGirl.create(:resource_pool) + FactoryBot.create(:resource_pool) allow(workflow).to receive(:get_source_and_targets).and_return(:ems => workflow.ci_to_hash_struct(ems)) expect(workflow).to receive(:allowed_ci).with(:respool, [:cluster, :host, :folder], [resource_pool.id]) @@ -311,17 +311,17 @@ it("with a nil") { expect(workflow.ci_to_hash_struct(nil)).to be_nil } context "with collections" do - let(:ems) { FactoryGirl.create(:ext_management_system) } + let(:ems) { FactoryBot.create(:ext_management_system) } it "an array" do - arr = [FactoryGirl.create(:ems_cluster, :ems_id => ems.id), FactoryGirl.create(:ems_cluster, :ems_id => ems.id)] + arr = [FactoryBot.create(:ems_cluster, :ems_id => ems.id), FactoryBot.create(:ems_cluster, :ems_id => ems.id)] expect(workflow.ci_to_hash_struct(arr).length).to eq(2) end it "an ActiveRecord CollectionProxy" do - FactoryGirl.create(:ems_cluster, :ems_id => ems.id) - FactoryGirl.create(:ems_cluster, :ems_id => ems.id) + FactoryBot.create(:ems_cluster, :ems_id => ems.id) + FactoryBot.create(:ems_cluster, :ems_id => ems.id) expect(ems.clusters).to be_kind_of(ActiveRecord::Associations::CollectionProxy) expect(workflow.ci_to_hash_struct(ems.clusters).length).to eq(2) @@ -329,7 +329,7 @@ end it "with an instance of a class that has a special format" do - hs = workflow.ci_to_hash_struct(FactoryGirl.create(:vm_or_template)) + hs = workflow.ci_to_hash_struct(FactoryBot.create(:vm_or_template)) expect(hs.id).to be_kind_of(Integer) expect(hs.evm_object_class).to eq(:VmOrTemplate) @@ -339,7 +339,7 @@ end it "with a regular class" do - hs = workflow.ci_to_hash_struct(FactoryGirl.create(:configured_system)) + hs = workflow.ci_to_hash_struct(FactoryBot.create(:configured_system)) expect(hs.id).to be_kind_of(Integer) expect(hs.evm_object_class).to eq(:ConfiguredSystem) @@ -349,7 +349,7 @@ context "#ems_folder_to_hash_struct" do it 'contains hidden column' do - hs = workflow.ems_folder_to_hash_struct(FactoryGirl.create(:ems_folder, :name => 'vm', :hidden => true)) + hs = workflow.ems_folder_to_hash_struct(FactoryBot.create(:ems_folder, :name => 'vm', :hidden => true)) expect(hs.id).to be_kind_of(Integer) expect(hs.evm_object_class).to eq(:EmsFolder) @@ -426,7 +426,7 @@ end it "sets owner group" do - owner = FactoryGirl.create(:user_with_email, :miq_groups => [FactoryGirl.create(:miq_group)]) + owner = FactoryBot.create(:user_with_email, :miq_groups => [FactoryBot.create(:miq_group)]) values = {:owner_email => owner.email} request = workflow.make_request(nil, values) expect(request.options[:owner_email]).to eq(owner.email) @@ -439,7 +439,7 @@ workflow.set_request_values(values) end let(:values) { {:owner_email => owner.email} } - let(:owner) { FactoryGirl.create(:user_with_email, :miq_groups => [FactoryGirl.create(:miq_group)]) } + let(:owner) { FactoryBot.create(:user_with_email, :miq_groups => [FactoryBot.create(:miq_group)]) } it 'sets owner_group and requester_group' do expect(values[:owner_group]).to eq(owner.current_group.description) @@ -448,9 +448,9 @@ it 'does not reset owner_group and requester_group on a second run' do old_requester = workflow.requester - new_requester = FactoryGirl.create(:user_with_email, :miq_groups => [FactoryGirl.create(:miq_group)]) + new_requester = FactoryBot.create(:user_with_email, :miq_groups => [FactoryBot.create(:miq_group)]) workflow.requester = new_requester - new_owner = FactoryGirl.create(:user_with_email, :miq_groups => [FactoryGirl.create(:miq_group)]) + new_owner = FactoryBot.create(:user_with_email, :miq_groups => [FactoryBot.create(:miq_group)]) values[:owner_email] = new_owner.email workflow.set_request_values(values) @@ -622,12 +622,12 @@ end context "#storage_to_hash_struct" do - let(:storage) { FactoryGirl.create(:storage) } + let(:storage) { FactoryBot.create(:storage) } it 'filters out storage_clusters not in same ems' do allow(workflow).to receive(:get_source_and_targets).and_return(:ems => MiqHashStruct.new(:id => ems.id)) - storage_cluster1 = FactoryGirl.create(:storage_cluster, :name => 'test_storage_cluster1', :ems_id => ems.id) - storage_cluster2 = FactoryGirl.create(:storage_cluster, :name => 'test_storage_cluster2', :ems_id => ems.id + 1) + storage_cluster1 = FactoryBot.create(:storage_cluster, :name => 'test_storage_cluster1', :ems_id => ems.id) + storage_cluster2 = FactoryBot.create(:storage_cluster, :name => 'test_storage_cluster2', :ems_id => ems.id + 1) storage_cluster1.add_child(storage) storage_cluster2.add_child(storage) clusters = workflow.storage_to_hash_struct(storage).storage_clusters.split(', ') diff --git a/spec/models/miq_schedule_filter_spec.rb b/spec/models/miq_schedule_filter_spec.rb index 28fae24dc8c..0b1fd627551 100644 --- a/spec/models/miq_schedule_filter_spec.rb +++ b/spec/models/miq_schedule_filter_spec.rb @@ -4,36 +4,36 @@ @server1 = EvmSpecHelper.local_miq_server # Vm Scan Schedules - @vm1 = FactoryGirl.create(:vm_vmware, :name => "Test VM 1") - @vm2 = FactoryGirl.create(:vm_vmware, :name => "Test VM 2") - @vm3 = FactoryGirl.create(:vm_vmware, :name => "Test VM 3") - @vm4 = FactoryGirl.create(:vm_vmware, :name => "Special Test VM") + @vm1 = FactoryBot.create(:vm_vmware, :name => "Test VM 1") + @vm2 = FactoryBot.create(:vm_vmware, :name => "Test VM 2") + @vm3 = FactoryBot.create(:vm_vmware, :name => "Test VM 3") + @vm4 = FactoryBot.create(:vm_vmware, :name => "Special Test VM") - @vm_single_schedule = FactoryGirl.create(:miq_schedule, + @vm_single_schedule = FactoryBot.create(:miq_schedule, :resource_type => "Vm", :sched_action => {:method => "vm_scan"}, :filter => MiqExpression.new("=" => {"field" => "Vm-name", "value" => "Special Test VM"}) ) - @vm_all_schedule = FactoryGirl.create(:miq_schedule, + @vm_all_schedule = FactoryBot.create(:miq_schedule, :resource_type => "Vm", :sched_action => {:method => "vm_scan"}, :filter => MiqExpression.new("IS NOT NULL" => {"field" => "Vm-name"}) ) # Schedule froma saved search - @search = FactoryGirl.create(:miq_search, + @search = FactoryBot.create(:miq_search, :db => "Vm", :filter => MiqExpression.new("=" => {"field" => "Vm-name", "value" => "Test VM 2"}) ) - @vm_search_schedule = FactoryGirl.create(:miq_schedule, + @vm_search_schedule = FactoryBot.create(:miq_schedule, :resource_type => "Vm", :sched_action => {:method => "vm_scan"}, :miq_search_id => @search.id ) # DB Baskup Schedule - @db_backup = FactoryGirl.create(:miq_schedule, + @db_backup = FactoryBot.create(:miq_schedule, :resource_type => "DatabaseBackup", :sched_action => {:method => "db_backup"} ) @@ -43,7 +43,7 @@ before do MiqReport.seed_report("Vendor and Guest OS") @report = MiqReport.first - @report_schedule = FactoryGirl.create(:miq_schedule, + @report_schedule = FactoryBot.create(:miq_schedule, :resource_type => "MiqReport", :sched_action => {:method => "run_report"}, :filter => MiqExpression.new("=" => {"field" => "MiqReport-id", "value" => @report.id}) diff --git a/spec/models/miq_schedule_spec.rb b/spec/models/miq_schedule_spec.rb index c146c97388b..42ea322bde5 100644 --- a/spec/models/miq_schedule_spec.rb +++ b/spec/models/miq_schedule_spec.rb @@ -9,7 +9,7 @@ it "hourly schedule" do run_at = {:interval => {:value => "1", :unit => "hourly"}, :start_time => "2012-03-10 01:35:00 Z", :tz => "Central Time (US & Canada)"} - hourly_schedule = FactoryGirl.create(:miq_schedule_validation, :run_at => run_at) + hourly_schedule = FactoryBot.create(:miq_schedule_validation, :run_at => run_at) current = Time.parse("Sat March 10 3:00:00 -0600 2012") # CST Timecop.travel(current) do time = hourly_schedule.next_interval_time @@ -25,7 +25,7 @@ it "hourly schedule, going from CST -> CDT" do run_at = {:interval => {:value => "1", :unit => "hourly"}, :start_time => "2012-03-11 01:35:00 Z", :tz => "Central Time (US & Canada)"} - hourly_schedule = FactoryGirl.create(:miq_schedule_validation, :run_at => run_at) + hourly_schedule = FactoryBot.create(:miq_schedule_validation, :run_at => run_at) current = Time.parse("Sun March 11 3:00:00 -0500 2012") # CDT Timecop.travel(current) do time = hourly_schedule.next_interval_time @@ -40,7 +40,7 @@ it "next_interval_time for start of every month" do start_time = Time.parse("2012-01-01 08:30:00 Z") - start_of_every_month = FactoryGirl.create(:miq_schedule_validation, :run_at => {:start_time => start_time, :interval => {:unit => "monthly", :value => "1"}}) + start_of_every_month = FactoryBot.create(:miq_schedule_validation, :run_at => {:start_time => start_time, :interval => {:unit => "monthly", :value => "1"}}) Timecop.travel(start_of_every_month.run_at[:start_time] - 5.minutes) do time = start_of_every_month.next_interval_time expect(time.month).to eq(start_time.month) @@ -55,7 +55,7 @@ end it "next_interval_time for start of every month for a very old start time" do - start_of_every_month = FactoryGirl.create(:miq_schedule_validation, :run_at => {:start_time => "2005-01-01 08:30:00 Z", :interval => {:unit => "monthly", :value => "1"}}) + start_of_every_month = FactoryBot.create(:miq_schedule_validation, :run_at => {:start_time => "2005-01-01 08:30:00 Z", :interval => {:unit => "monthly", :value => "1"}}) Timecop.travel(Time.parse("2013-01-01 08:31:00 UTC")) do time = start_of_every_month.next_interval_time expect(time.month).to eq(2) @@ -65,7 +65,7 @@ end it "next_interval_time for end of every month" do - end_of_every_month = FactoryGirl.create(:miq_schedule_validation, :run_at => {:start_time => "2012-01-31 08:30:00 Z", :interval => {:unit => "monthly", :value => "1"}}) + end_of_every_month = FactoryBot.create(:miq_schedule_validation, :run_at => {:start_time => "2012-01-31 08:30:00 Z", :interval => {:unit => "monthly", :value => "1"}}) Timecop.travel(end_of_every_month.run_at[:start_time] - 5.minutes) do time = end_of_every_month.next_interval_time expect(time.month).to eq(1) @@ -80,7 +80,7 @@ end it "next_interval_time for end of every month for a very old start time" do - end_of_every_month = FactoryGirl.create(:miq_schedule_validation, :run_at => {:start_time => "2005-01-31 08:30:00 Z", :interval => {:unit => "monthly", :value => "1"}}) + end_of_every_month = FactoryBot.create(:miq_schedule_validation, :run_at => {:start_time => "2005-01-31 08:30:00 Z", :interval => {:unit => "monthly", :value => "1"}}) Timecop.travel(Time.parse("2013-01-31 08:31:00 UTC")) do time = end_of_every_month.next_interval_time expect(time.month).to eq(2) @@ -90,7 +90,7 @@ end it "next_interval_time for the 30th of every month" do - end_of_every_month = FactoryGirl.create(:miq_schedule_validation, :run_at => {:start_time => "2012-01-30 08:30:00 Z", :interval => {:unit => "monthly", :value => "1"}}) + end_of_every_month = FactoryBot.create(:miq_schedule_validation, :run_at => {:start_time => "2012-01-30 08:30:00 Z", :interval => {:unit => "monthly", :value => "1"}}) Timecop.travel(end_of_every_month.run_at[:start_time] - 5.minutes) do time = end_of_every_month.next_interval_time expect(time.month).to eq(1) @@ -105,7 +105,7 @@ end it "next_interval_time for start of every two months" do - start_of_every_two_months = FactoryGirl.create(:miq_schedule_validation, :run_at => {:start_time => "2012-01-01 08:30:00 Z", :interval => {:unit => "monthly", :value => "2"}}) + start_of_every_two_months = FactoryBot.create(:miq_schedule_validation, :run_at => {:start_time => "2012-01-01 08:30:00 Z", :interval => {:unit => "monthly", :value => "2"}}) Timecop.travel(start_of_every_two_months.run_at[:start_time] + 5.minutes) do time = start_of_every_two_months.next_interval_time expect(time.month).to eq(3) @@ -114,7 +114,7 @@ end it "next_interval_time for end of every two months" do - end_of_every_two_months = FactoryGirl.create(:miq_schedule_validation, :run_at => {:start_time => "2012-01-31 08:30:00 Z", :interval => {:unit => "monthly", :value => "2"}}) + end_of_every_two_months = FactoryBot.create(:miq_schedule_validation, :run_at => {:start_time => "2012-01-31 08:30:00 Z", :interval => {:unit => "monthly", :value => "2"}}) Timecop.travel(end_of_every_two_months.run_at[:start_time] + 5.minutes) do time = end_of_every_two_months.next_interval_time expect(time.month).to eq(3) @@ -127,7 +127,7 @@ @valid_schedules = [] @valid_run_ats.each do |run_at| - @valid_schedules << FactoryGirl.create(:miq_schedule_validation, :run_at => run_at) + @valid_schedules << FactoryBot.create(:miq_schedule_validation, :run_at => run_at) end @first = @valid_schedules.first end @@ -481,7 +481,7 @@ @task_id = MiqSchedule.run_adhoc_db_gc(:userid => "admin", :aggressive => true) @gc_message = MiqQueue.where(:class_name => "DatabaseBackup", :method_name => "gc", :role => "database_operations").first - @region = FactoryGirl.create(:miq_region) + @region = FactoryBot.create(:miq_region) allow(MiqRegion).to receive(:my_region).and_return(@region) end @@ -512,7 +512,7 @@ end context "valid action_automation_request" do - let(:admin) { FactoryGirl.create(:user_miq_request_approver) } + let(:admin) { FactoryBot.create(:user_miq_request_approver) } let(:automate_sched) do MiqSchedule.create(:name => "test_method", :resource_type => "AutomationRequest", :userid => admin.userid, :enabled => true, @@ -537,11 +537,11 @@ end context "valid schedules for db_backup" do - let(:file_depot) { FactoryGirl.create(:file_depot_ftp_with_authentication) } + let(:file_depot) { FactoryBot.create(:file_depot_ftp_with_authentication) } before do @valid_schedules = [] @valid_run_ats.each do |run_at| - @valid_schedules << FactoryGirl.create(:miq_schedule_validation, :run_at => run_at, :file_depot => file_depot, :sched_action => {:method => "db_backup"}, :resource_type => "DatabaseBackup") + @valid_schedules << FactoryBot.create(:miq_schedule_validation, :run_at => run_at, :file_depot => file_depot, :sched_action => {:method => "db_backup"}, :resource_type => "DatabaseBackup") end @schedule = @valid_schedules.first end @@ -551,7 +551,7 @@ @task_id = @schedule.run_adhoc_db_backup @backup_message = MiqQueue.where(:class_name => "DatabaseBackup", :method_name => "backup", :role => "database_operations").first - @region = FactoryGirl.create(:miq_region) + @region = FactoryBot.create(:miq_region) allow(MiqRegion).to receive(:my_region).and_return(@region) end @@ -595,7 +595,7 @@ @invoke_actions_message.delivered(status, message, result) @backup_message = MiqQueue.where(:class_name => "DatabaseBackup", :method_name => "backup", :role => "database_operations").first - @region = FactoryGirl.create(:miq_region) + @region = FactoryBot.create(:miq_region) allow(MiqRegion).to receive(:my_region).and_return(@region) end @@ -694,15 +694,15 @@ describe ".updated_since" do it "fetches records" do - FactoryGirl.create(:miq_schedule, :updated_at => 1.year.ago) - s = FactoryGirl.create(:miq_schedule, :updated_at => 1.day.ago) + FactoryBot.create(:miq_schedule, :updated_at => 1.year.ago) + s = FactoryBot.create(:miq_schedule, :updated_at => 1.day.ago) expect(MiqSchedule.updated_since(1.month.ago)).to eq([s]) end end context ".queue_scheduled_work" do it "When action exists" do - schedule = FactoryGirl.create(:miq_schedule, :sched_action => {:method => "scan"}) + schedule = FactoryBot.create(:miq_schedule, :sched_action => {:method => "scan"}) MiqSchedule.queue_scheduled_work(schedule.id, nil, "abc", nil) expect(MiqQueue.first).to have_attributes( @@ -716,7 +716,7 @@ context "no action method" do it "no resource" do - schedule = FactoryGirl.create(:miq_schedule, :sched_action => {:method => "test_method"}) + schedule = FactoryBot.create(:miq_schedule, :sched_action => {:method => "test_method"}) expect($log).to receive(:warn) do |message| expect(message).to include("no such action: [test_method], aborting schedule") @@ -726,14 +726,14 @@ end context "resource exists" do - let(:resource) { FactoryGirl.create(:host) } + let(:resource) { FactoryBot.create(:host) } before do allow(Host).to receive(:find_by).with(:id => resource.id).and_return(resource) end it "and does not respond to the method" do - schedule = FactoryGirl.create(:miq_schedule, :resource => resource, :sched_action => {:method => "test_method"}) + schedule = FactoryBot.create(:miq_schedule, :resource => resource, :sched_action => {:method => "test_method"}) expect($log).to receive(:warn) do |message| expect(message).to include("no such action: [test_method], aborting schedule") @@ -743,7 +743,7 @@ end it "and responds to the method" do - schedule = FactoryGirl.create(:miq_schedule, :resource => resource, :sched_action => {:method => "name"}) + schedule = FactoryBot.create(:miq_schedule, :resource => resource, :sched_action => {:method => "name"}) expect_any_instance_of(Host).to receive("name").once @@ -751,7 +751,7 @@ end it "and responds to the method with arguments" do - schedule = FactoryGirl.create(:miq_schedule, :resource => resource, :sched_action => {:method => "name", :args => ["abc", 123, :a => 1]}) + schedule = FactoryBot.create(:miq_schedule, :resource => resource, :sched_action => {:method => "name", :args => ["abc", 123, :a => 1]}) expect_any_instance_of(Host).to receive("name").once.with("abc", 123, :a => 1) diff --git a/spec/models/miq_schedule_worker/jobs_spec.rb b/spec/models/miq_schedule_worker/jobs_spec.rb index d8aeec2c16f..d67afde2d37 100644 --- a/spec/models/miq_schedule_worker/jobs_spec.rb +++ b/spec/models/miq_schedule_worker/jobs_spec.rb @@ -8,7 +8,7 @@ it "with an EMS" do _, _, zone = EvmSpecHelper.create_guid_miq_server_zone - FactoryGirl.create(:ems_vmware, :zone => zone) + FactoryBot.create(:ems_vmware, :zone => zone) described_class.new.ems_refresh_timer(ManageIQ::Providers::Vmware::InfraManager) expect(MiqQueue.count).to eq(1) diff --git a/spec/models/miq_schedule_worker/runner_spec.rb b/spec/models/miq_schedule_worker/runner_spec.rb index a3e4d2fcf34..2ddbe90adec 100644 --- a/spec/models/miq_schedule_worker/runner_spec.rb +++ b/spec/models/miq_schedule_worker/runner_spec.rb @@ -5,7 +5,7 @@ @zone = @miq_server.zone worker_guid = SecureRandom.uuid - @worker = FactoryGirl.create(:miq_schedule_worker, :guid => worker_guid, :miq_server_id => @miq_server.id) + @worker = FactoryBot.create(:miq_schedule_worker, :guid => worker_guid, :miq_server_id => @miq_server.id) allow_any_instance_of(MiqScheduleWorker::Runner).to receive(:initialize_rufus) allow_any_instance_of(MiqScheduleWorker::Runner).to receive(:sync_config) @@ -22,11 +22,11 @@ allow(@schedule_worker).to receive(:worker_settings).and_return(:job_proxy_dispatcher_stale_message_timeout => @stale_timeout) @zone1 = @zone - @worker1 = FactoryGirl.create(:miq_worker, :status => MiqWorker::STATUS_STOPPED) - @dispatch1 = FactoryGirl.create(:miq_queue, {:zone => @zone1.name, :handler_type => @worker1.class.name, :handler_id => @worker1.id}.merge(@opts)) + @worker1 = FactoryBot.create(:miq_worker, :status => MiqWorker::STATUS_STOPPED) + @dispatch1 = FactoryBot.create(:miq_queue, {:zone => @zone1.name, :handler_type => @worker1.class.name, :handler_id => @worker1.id}.merge(@opts)) - @zone2 = FactoryGirl.create(:zone) - @worker2 = FactoryGirl.create(:miq_worker, :status => MiqWorker::STATUS_STOPPED) + @zone2 = FactoryBot.create(:zone) + @worker2 = FactoryBot.create(:miq_worker, :status => MiqWorker::STATUS_STOPPED) allow(MiqServer).to receive(:my_zone).and_return(@zone1.name) Timecop.travel 5.minutes @@ -39,7 +39,7 @@ it "check_for_dispatch calls check_for_timeout which deletes both dispatches with fixnum" do attrs = {:zone => @zone2.name, :handler_type => @worker2.class.name, :handler_id => @worker2.id} - @dispatch2 = FactoryGirl.create(:miq_queue, attrs.merge(@opts)) + @dispatch2 = FactoryBot.create(:miq_queue, attrs.merge(@opts)) expect(MiqQueue.where(@cond).count).to eq(2) MiqScheduleWorker::Jobs.new.check_for_stuck_dispatch(@stale_timeout.to_i) @@ -49,7 +49,7 @@ it "check_for_dispatch calls check_for_timeout which deletes both dispatches" do attrs = {:zone => @zone2.name, :handler_type => @worker2.class.name, :handler_id => @worker2.id} - @dispatch2 = FactoryGirl.create(:miq_queue, attrs.merge(@opts)) + @dispatch2 = FactoryBot.create(:miq_queue, attrs.merge(@opts)) expect(MiqQueue.where(@cond).count).to eq(2) MiqScheduleWorker::Jobs.new.check_for_stuck_dispatch(@stale_timeout) @@ -72,7 +72,7 @@ end it "check_for_dispatch calls check_for_timeout which deletes for in-active worker" do - @dispatch2 = FactoryGirl.create(:miq_queue, {:zone => @zone2.name, :handler_type => @worker2.class.name, :handler_id => @worker2.id}.merge(@opts)) + @dispatch2 = FactoryBot.create(:miq_queue, {:zone => @zone2.name, :handler_type => @worker2.class.name, :handler_id => @worker2.id}.merge(@opts)) @worker1.update_attribute(:status, MiqWorker::STATUS_STARTED) cond_active = @cond.dup @@ -118,7 +118,7 @@ it "monthly schedule scheduled for 5 years will be unscheduled by tag" do first_at = Time.utc(2011, 1, 1, 8, 30) tag = "miq_schedules_1" - @sch = FactoryGirl.create(:miq_schedule_validation, :run_at => {:start_time => "2011-01-01 08:30:00 Z", :interval => {:unit => "monthly", :value => "1"}}) + @sch = FactoryBot.create(:miq_schedule_validation, :run_at => {:start_time => "2011-01-01 08:30:00 Z", :interval => {:unit => "monthly", :value => "1"}}) @schedule_worker.rufus_add_schedule(:method => :schedule_at, :interval => first_at, :months => 1, :schedule_id => @sch.id, :discard_past => true, :tags => tag) expect(@schedule_worker.queue_length).to eq(0) @@ -129,7 +129,7 @@ it "monthly creates a schedule each month for 5 years" do first_at = Time.utc(2011, 1, 1, 8, 30) - @sch = FactoryGirl.create(:miq_schedule_validation, :run_at => {:start_time => "2011-01-01 08:30:00 Z", :interval => {:unit => "monthly", :value => "1"}}) + @sch = FactoryBot.create(:miq_schedule_validation, :run_at => {:start_time => "2011-01-01 08:30:00 Z", :interval => {:unit => "monthly", :value => "1"}}) Timecop.freeze(first_at - 1.minute) do @schedule_worker.rufus_add_schedule(:method => :schedule_at, :interval => first_at, :months => 1, :schedule_id => @sch.id, :discard_past => true, :tags => "miq_schedules_1") @@ -143,7 +143,7 @@ it "monthly schedule starting Jan 31 will next run Feb 28" do first_at = Time.utc(2011, 1, 31, 8, 30) - @sch = FactoryGirl.create(:miq_schedule_validation, :run_at => {:start_time => "2011-01-31 08:30:00 Z", :interval => {:unit => "monthly", :value => "1"}}) + @sch = FactoryBot.create(:miq_schedule_validation, :run_at => {:start_time => "2011-01-31 08:30:00 Z", :interval => {:unit => "monthly", :value => "1"}}) Timecop.freeze(first_at + 1.minute) do @schedule_worker.rufus_add_schedule(:method => :schedule_at, :interval => first_at, :months => 1, :schedule_id => @sch.id, :discard_past => true, :tags => "miq_schedules_1") @@ -177,8 +177,8 @@ allow(@schedule_worker).to receive(:worker_settings).and_return(Hash.new(5.minutes)) @schedule_worker.instance_variable_set(:@schedules, :scheduler => []) - @sch1 = FactoryGirl.create(:miq_schedule) - @sch2 = FactoryGirl.create(:miq_schedule) + @sch1 = FactoryBot.create(:miq_schedule) + @sch2 = FactoryBot.create(:miq_schedule) end it "should load all user schedules when scheduler role is added" do diff --git a/spec/models/miq_search_spec.rb b/spec/models/miq_search_spec.rb index 831789f520b..0a310b70bb4 100644 --- a/spec/models/miq_search_spec.rb +++ b/spec/models/miq_search_spec.rb @@ -2,9 +2,9 @@ describe '#descriptions' do it "hashes" do srchs = [ - FactoryGirl.create(:miq_search, :description => 'a'), - FactoryGirl.create(:miq_search, :description => 'b'), - FactoryGirl.create(:miq_search, :description => 'c') + FactoryBot.create(:miq_search, :description => 'a'), + FactoryBot.create(:miq_search, :description => 'b'), + FactoryBot.create(:miq_search, :description => 'c') ] expect(MiqSearch.descriptions).to eq( @@ -15,9 +15,9 @@ it "supports scopes" do srchs = [ - FactoryGirl.create(:miq_search, :description => 'a', :db => 'Vm'), - FactoryGirl.create(:miq_search, :description => 'b', :db => 'Vm'), - FactoryGirl.create(:miq_search, :description => 'c', :db => 'Host') + FactoryBot.create(:miq_search, :description => 'a', :db => 'Vm'), + FactoryBot.create(:miq_search, :description => 'b', :db => 'Vm'), + FactoryBot.create(:miq_search, :description => 'c', :db => 'Host') ] expect(MiqSearch.where(:db => 'Vm').descriptions).to eq( @@ -27,14 +27,14 @@ end let(:vm_location_search) do - FactoryGirl.create(:miq_search, + FactoryBot.create(:miq_search, :db => "Vm", :filter => MiqExpression.new("=" => {"field" => "Vm-location", "value" => "good"}) ) end - let(:matched_vms) { FactoryGirl.create_list(:vm_vmware, 2, :location => "good") } - let(:other_vms) { FactoryGirl.create_list(:vm_vmware, 1, :location => "other") } + let(:matched_vms) { FactoryBot.create_list(:vm_vmware, 2, :location => "good") } + let(:other_vms) { FactoryBot.create_list(:vm_vmware, 1, :location => "other") } let(:all_vms) { matched_vms + other_vms } let(:partial_matched_vms) { [matched_vms.first] } let(:partial_vms) { partial_matched_vms + other_vms } @@ -42,7 +42,7 @@ describe "#quick_search?" do let(:qs) { MiqExpression.new("=" => {"field" => "Vm-name", "value" => :user_input}) } it "supports no filter" do - expect(FactoryGirl.build(:miq_search, :filter => nil)).not_to be_quick_search + expect(FactoryBot.build(:miq_search, :filter => nil)).not_to be_quick_search end it "supports a filter" do @@ -50,7 +50,7 @@ end it "supports a quick search" do - expect(FactoryGirl.build(:miq_search, :filter => qs)).to be_quick_search + expect(FactoryBot.build(:miq_search, :filter => qs)).to be_quick_search end end diff --git a/spec/models/miq_server/at_startup_spec.rb b/spec/models/miq_server/at_startup_spec.rb index 02248dc0e36..72c6321a37f 100644 --- a/spec/models/miq_server/at_startup_spec.rb +++ b/spec/models/miq_server/at_startup_spec.rb @@ -6,8 +6,8 @@ context "where worker has a message in dequeue" do it "should cleanup message on startup" do - worker = FactoryGirl.create(:miq_ems_refresh_worker, :miq_server_id => @miq_server.id) - msg = FactoryGirl.create(:miq_queue, :state => MiqQueue::STATE_DEQUEUE, :handler => worker) + worker = FactoryBot.create(:miq_ems_refresh_worker, :miq_server_id => @miq_server.id) + msg = FactoryBot.create(:miq_queue, :state => MiqQueue::STATE_DEQUEUE, :handler => worker) described_class.clean_dequeued_messages @@ -16,8 +16,8 @@ end it "deletes shutdown_and_exit messages" do - worker = FactoryGirl.create(:miq_ems_refresh_worker, :miq_server_id => @miq_server.id) - FactoryGirl.create(:miq_queue, :state => MiqQueue::STATE_DEQUEUE, :handler => worker, + worker = FactoryBot.create(:miq_ems_refresh_worker, :miq_server_id => @miq_server.id) + FactoryBot.create(:miq_queue, :state => MiqQueue::STATE_DEQUEUE, :handler => worker, :method_name => "shutdown_and_exit") described_class.clean_dequeued_messages expect(MiqQueue.count).to eq 0 @@ -26,9 +26,9 @@ context "where worker on other server has a message in dequeue" do it "should not cleanup message on startup" do - other_miq_server = FactoryGirl.create(:miq_server, :zone => @zone) - other_worker = FactoryGirl.create(:miq_ems_refresh_worker, :miq_server_id => other_miq_server.id) - msg = FactoryGirl.create(:miq_queue, :state => MiqQueue::STATE_DEQUEUE, :handler => other_worker) + other_miq_server = FactoryBot.create(:miq_server, :zone => @zone) + other_worker = FactoryBot.create(:miq_ems_refresh_worker, :miq_server_id => other_miq_server.id) + msg = FactoryBot.create(:miq_queue, :state => MiqQueue::STATE_DEQUEUE, :handler => other_worker) described_class.clean_dequeued_messages @@ -39,7 +39,7 @@ context "message in dequeue without a worker" do it "should cleanup message on startup" do - msg = FactoryGirl.create(:miq_queue, :state => MiqQueue::STATE_DEQUEUE) + msg = FactoryBot.create(:miq_queue, :state => MiqQueue::STATE_DEQUEUE) described_class.clean_dequeued_messages @@ -51,8 +51,8 @@ it ".log_not_under_management (private)" do MiqRegion.seed - FactoryGirl.create(:host_vmware) - FactoryGirl.create(:vm_vmware) + FactoryBot.create(:host_vmware) + FactoryBot.create(:vm_vmware) expect($log).to receive(:info).with(/VMs: \[1\], Hosts: \[1\]/) described_class.send(:log_not_under_management, "") end diff --git a/spec/models/miq_server/configuration_management_spec.rb b/spec/models/miq_server/configuration_management_spec.rb index d8664a82921..e41925c4470 100644 --- a/spec/models/miq_server/configuration_management_spec.rb +++ b/spec/models/miq_server/configuration_management_spec.rb @@ -9,7 +9,7 @@ it "with changes in the database" do miq_server.settings_changes = [ - FactoryGirl.create(:settings_change, :key => "/api/token_ttl", :value => "2.minutes") + FactoryBot.create(:settings_change, :key => "/api/token_ttl", :value => "2.minutes") ] Settings.reload! @@ -50,12 +50,12 @@ end context "ConfigurationManagementMixin" do - let(:miq_server) { FactoryGirl.create(:miq_server) } + let(:miq_server) { FactoryBot.create(:miq_server) } describe "#config_activated" do - let(:zone) { FactoryGirl.create(:zone, :name => "My Zone") } + let(:zone) { FactoryBot.create(:zone, :name => "My Zone") } let(:zone_other_region) do other_region_id = ApplicationRecord.id_in_region(1, MiqRegion.my_region_number + 1) - FactoryGirl.create(:zone, :id => other_region_id).tap do |z| + FactoryBot.create(:zone, :id => other_region_id).tap do |z| z.update_column(:name, "My Zone") # Bypass validation for test purposes end end diff --git a/spec/models/miq_server/log_management_spec.rb b/spec/models/miq_server/log_management_spec.rb index b129fe5b95f..fc04f452c7c 100644 --- a/spec/models/miq_server/log_management_spec.rb +++ b/spec/models/miq_server/log_management_spec.rb @@ -78,13 +78,13 @@ def stub_vmdb_util_methods_for_collection_log describe MiqServer do context "LogManagement" do - let(:server_depot) { FactoryGirl.create(:file_depot) } - let(:zone_depot) { FactoryGirl.create(:file_depot) } - let(:miq_task) { FactoryGirl.create(:miq_task) } + let(:server_depot) { FactoryBot.create(:file_depot) } + let(:zone_depot) { FactoryBot.create(:file_depot) } + let(:miq_task) { FactoryBot.create(:miq_task) } before do _, @miq_server, @zone = EvmSpecHelper.create_guid_miq_server_zone - @miq_server2 = FactoryGirl.create(:miq_server, :zone => @zone) + @miq_server2 = FactoryBot.create(:miq_server, :zone => @zone) end context "#pg_data_log_patterns" do @@ -114,14 +114,14 @@ def stub_vmdb_util_methods_for_collection_log end context "post current/historical/models/dialogs" do - let(:task) { FactoryGirl.create(:miq_task) } + let(:task) { FactoryBot.create(:miq_task) } let(:compressed_log_patterns) { [Rails.root.join("log", "evm*.log.gz").to_s] } let(:current_log_patterns) { [Rails.root.join("log", "evm.log").to_s] } let(:compressed_evm_log) { Rails.root.join("evm.log-20180319.gz").to_s } let(:log_start) { Time.zone.parse("2018-05-11 11:33:12 UTC") } let(:log_end) { Time.zone.parse("2018-05-11 15:34:16 UTC") } let(:daily_log) { Rails.root.join("data", "user", "system", "evm_server_daily.zip").to_s } - let(:log_depot) { FactoryGirl.create(:file_depot) } + let(:log_depot) { FactoryBot.create(:file_depot) } let!(:region) { MiqRegion.seed } let(:zone) { @miq_server.zone } before do @@ -134,7 +134,7 @@ def stub_vmdb_util_methods_for_collection_log allow(@miq_server).to receive(:backup_automate_dialogs) allow(@miq_server).to receive(:backup_automate_models) %w(historical_logfile current_logfile).each do |kind| - logfile = FactoryGirl.create(:log_file, :historical => kind == "historical_logfile") + logfile = FactoryBot.create(:log_file, :historical => kind == "historical_logfile") allow(logfile).to receive(:upload) allow(LogFile).to receive(kind).and_return(logfile) end diff --git a/spec/models/miq_server/server_monitor_spec.rb b/spec/models/miq_server/server_monitor_spec.rb index 8f297a0a6ab..80e92dafe18 100644 --- a/spec/models/miq_server/server_monitor_spec.rb +++ b/spec/models/miq_server/server_monitor_spec.rb @@ -234,7 +234,7 @@ @miq_server1.deactivate_all_roles @miq_server1.role = 'event, ems_operations, scheduler, reporting' - @miq_server2 = FactoryGirl.create(:miq_server, :zone => @miq_server1.zone) + @miq_server2 = FactoryBot.create(:miq_server, :zone => @miq_server1.zone) @miq_server2.deactivate_all_roles @miq_server2.role = 'event, ems_operations, scheduler, reporting' end @@ -355,7 +355,7 @@ @roles1.each { |role, priority| @miq_server1.assign_role(role, priority) } @miq_server1.activate_roles("ems_operations", 'reporting') - @miq_server2 = FactoryGirl.create(:miq_server, :is_master => true, :zone => @miq_server1.zone) + @miq_server2 = FactoryBot.create(:miq_server, :is_master => true, :zone => @miq_server1.zone) @miq_server2.deactivate_all_roles @miq_server2.role = 'event, ems_operations, scheduler, reporting' @roles2 = [['ems_operations', 1], ['event', 1], ['scheduler', 1], ['reporting', 1]] @@ -443,12 +443,12 @@ @roles1 = [['ems_operations', 2], ['event', 2], ['ems_inventory', 3], ['ems_metrics_coordinator', 2],] @roles1.each { |role, priority| @miq_server1.assign_role(role, priority) } - @miq_server2 = FactoryGirl.create(:miq_server, :zone => @miq_server1.zone, :name => "Miq2") + @miq_server2 = FactoryBot.create(:miq_server, :zone => @miq_server1.zone, :name => "Miq2") @miq_server2.deactivate_all_roles @roles2 = [['ems_operations', 1], ['event', 1], ['ems_metrics_coordinator', 3], ['ems_inventory', 2],] @roles2.each { |role, priority| @miq_server2.assign_role(role, priority) } - @miq_server3 = FactoryGirl.create(:miq_server, :zone => @miq_server1.zone, :name => "Miq3") + @miq_server3 = FactoryBot.create(:miq_server, :zone => @miq_server1.zone, :name => "Miq3") @miq_server3.deactivate_all_roles @roles3 = [['ems_operations', 2], ['event', 3], ['ems_inventory', 1], ['ems_metrics_coordinator', 1]] @roles3.each { |role, priority| @miq_server3.assign_role(role, priority) } @@ -674,12 +674,12 @@ @miq_server1.role = 'event, ems_operations, ems_inventory' @miq_server1.activate_roles("ems_operations", "ems_inventory") - @miq_server2 = FactoryGirl.create(:miq_server, :is_master => true, :zone => @miq_server1.zone, :name => "Server 2") + @miq_server2 = FactoryBot.create(:miq_server, :is_master => true, :zone => @miq_server1.zone, :name => "Server 2") @miq_server2.deactivate_all_roles @miq_server2.role = 'event, ems_metrics_coordinator, ems_operations' @miq_server2.activate_roles("event", "ems_metrics_coordinator", 'ems_operations') - @miq_server3 = FactoryGirl.create(:miq_server, :zone => @miq_server2.zone, :name => "Server 3") + @miq_server3 = FactoryBot.create(:miq_server, :zone => @miq_server2.zone, :name => "Server 3") @miq_server3.deactivate_all_roles @miq_server3.role = 'ems_metrics_coordinator, ems_inventory, ems_operations' @miq_server3.activate_roles("ems_operations") @@ -787,8 +787,8 @@ context "In 2 Zones," do before do - @zone1 = FactoryGirl.create(:zone) - @zone2 = FactoryGirl.create(:zone, :name => "zone2", :description => "Zone 2") + @zone1 = FactoryBot.create(:zone) + @zone2 = FactoryBot.create(:zone, :name => "zone2", :description => "Zone 2") end context "with 2 Servers across Zones where there is no master" do @@ -796,7 +796,7 @@ @miq_server1 = EvmSpecHelper.local_miq_server(:zone => @zone1, :name => "Server 1") @miq_server1.deactivate_all_roles - @miq_server2 = FactoryGirl.create(:miq_server, :guid => SecureRandom.uuid, :zone => @zone2, :name => "Server 2") + @miq_server2 = FactoryBot.create(:miq_server, :guid => SecureRandom.uuid, :zone => @zone2, :name => "Server 2") @miq_server2.deactivate_all_roles end @@ -831,7 +831,7 @@ @roles1 = [['ems_operations', 1], ['event', 1], ['ems_metrics_coordinator', 2], ['scheduler', 1], ['reporting', 1]] @roles1.each { |role, priority| @miq_server1.assign_role(role, priority) } - @miq_server2 = FactoryGirl.create(:miq_server, :guid => SecureRandom.uuid, :zone => @zone2, :name => "Server 2") + @miq_server2 = FactoryBot.create(:miq_server, :guid => SecureRandom.uuid, :zone => @zone2, :name => "Server 2") @miq_server2.deactivate_all_roles @roles2 = [['ems_operations', 1], ['event', 2], ['ems_metrics_coordinator', 1], ['scheduler', 2], ['reporting', 1]] @roles2.each { |role, priority| @miq_server2.assign_role(role, priority) } diff --git a/spec/models/miq_server/update_management_spec.rb b/spec/models/miq_server/update_management_spec.rb index 4482611a744..87f42ac2383 100644 --- a/spec/models/miq_server/update_management_spec.rb +++ b/spec/models/miq_server/update_management_spec.rb @@ -4,7 +4,7 @@ end let!(:database) do - FactoryGirl.create(:miq_region, :region => ApplicationRecord.my_region_number) + FactoryBot.create(:miq_region, :region => ApplicationRecord.my_region_number) db = MiqDatabase.seed db.update_repo_name = "repo-1 repo-2" db @@ -15,7 +15,7 @@ context "Queue multiple servers" do before do - FactoryGirl.create(:miq_server, :zone => @server.zone) + FactoryBot.create(:miq_server, :zone => @server.zone) end it ".queue_update_registration_status" do diff --git a/spec/models/miq_server/worker_management/heartbeat_spec.rb b/spec/models/miq_server/worker_management/heartbeat_spec.rb index a509f5f116e..4df7b1edf2d 100644 --- a/spec/models/miq_server/worker_management/heartbeat_spec.rb +++ b/spec/models/miq_server/worker_management/heartbeat_spec.rb @@ -2,7 +2,7 @@ context "#validate_heartbeat" do let(:miq_server) { EvmSpecHelper.local_miq_server.tap(&:setup_drb_variables) } let(:pid) { 1234 } - let(:worker) { FactoryGirl.create(:miq_worker, :miq_server_id => miq_server.id, :pid => pid) } + let(:worker) { FactoryBot.create(:miq_worker, :miq_server_id => miq_server.id, :pid => pid) } it "sets initial and subsequent heartbeats" do 2.times do diff --git a/spec/models/miq_server/worker_management/monitor_spec.rb b/spec/models/miq_server/worker_management/monitor_spec.rb index 1c6940b6f9b..09565987532 100644 --- a/spec/models/miq_server/worker_management/monitor_spec.rb +++ b/spec/models/miq_server/worker_management/monitor_spec.rb @@ -2,7 +2,7 @@ context "#check_not_responding" do let(:server) { EvmSpecHelper.local_miq_server } let(:worker) do - FactoryGirl.create(:miq_worker, + FactoryBot.create(:miq_worker, :type => "MiqGenericWorker", :miq_server => server, :pid => 12345, diff --git a/spec/models/miq_server/worker_monitor_spec.rb b/spec/models/miq_server/worker_monitor_spec.rb index a9b089a29f8..3c49668d2fa 100644 --- a/spec/models/miq_server/worker_monitor_spec.rb +++ b/spec/models/miq_server/worker_monitor_spec.rb @@ -11,11 +11,11 @@ context "A worker" do before do - @worker = FactoryGirl.create(:miq_worker, :miq_server_id => @miq_server.id) + @worker = FactoryBot.create(:miq_worker, :miq_server_id => @miq_server.id) end it "MiqServer#clean_worker_records" do - FactoryGirl.create(:miq_worker, :miq_server_id => @miq_server.id) + FactoryBot.create(:miq_worker, :miq_server_id => @miq_server.id) allow(@miq_server).to receive(:worker_delete) @worker.update_attributes(:status => MiqWorker::STATUS_STOPPED) @@ -26,7 +26,7 @@ end it "MiqServer#check_not_responding" do - w2 = FactoryGirl.create(:miq_worker, :miq_server_id => @miq_server.id, :pid => (@worker.pid + 1)) + w2 = FactoryBot.create(:miq_worker, :miq_server_id => @miq_server.id, :pid => (@worker.pid + 1)) allow(@miq_server).to receive(:worker_delete) allow(@miq_server).to receive(:worker_get_monitor_status).with(@worker.pid).and_return(:waiting_for_stop) allow(@miq_server).to receive(:worker_get_monitor_reason).with(@worker.pid).and_return(:not_responding) @@ -43,11 +43,11 @@ describe "#do_system_limit_exceeded" do before do - @worker_to_keep = FactoryGirl.create(:miq_ems_metrics_processor_worker, + @worker_to_keep = FactoryBot.create(:miq_ems_metrics_processor_worker, :miq_server => @miq_server, :memory_usage => 1.gigabytes ) - @worker_to_kill = FactoryGirl.create(:miq_ems_metrics_processor_worker, + @worker_to_kill = FactoryBot.create(:miq_ems_metrics_processor_worker, :miq_server => @miq_server, :memory_usage => 2.gigabytes ) @@ -74,7 +74,7 @@ context "with 1 message" do before do - @message = FactoryGirl.create(:miq_queue, :state => 'dequeue', :handler => @worker) + @message = FactoryBot.create(:miq_queue, :state => 'dequeue', :handler => @worker) end it "should have one in its relationship" do @@ -88,15 +88,15 @@ @messages = [] @actives = [] - m = FactoryGirl.create(:miq_queue, :state => 'ready', :handler => @worker, :msg_timeout => 4.minutes) + m = FactoryBot.create(:miq_queue, :state => 'ready', :handler => @worker, :msg_timeout => 4.minutes) @messages << m @actives << m if m.state == 'dequeue' - m = FactoryGirl.create(:miq_queue, :state => 'dequeue', :handler => @worker, :msg_timeout => 4.minutes) + m = FactoryBot.create(:miq_queue, :state => 'dequeue', :handler => @worker, :msg_timeout => 4.minutes) @messages << m @actives << m if m.state == 'dequeue' - m = FactoryGirl.create(:miq_queue, :state => 'dequeue', :handler => @worker, :msg_timeout => 5.minutes) + m = FactoryBot.create(:miq_queue, :state => 'dequeue', :handler => @worker, :msg_timeout => 5.minutes) @messages << m @actives << m if m.state == 'dequeue' @worker.reload @@ -150,8 +150,8 @@ context "with active messages without worker" do before do @actives = [] - @actives << FactoryGirl.create(:miq_queue, :state => 'dequeue', :msg_timeout => 4.minutes) - @actives << FactoryGirl.create(:miq_queue, :state => 'dequeue', :msg_timeout => 5.minutes) + @actives << FactoryBot.create(:miq_queue, :state => 'dequeue', :msg_timeout => 4.minutes) + @actives << FactoryBot.create(:miq_queue, :state => 'dequeue', :msg_timeout => 5.minutes) end it "should timeout the right active messages" do @@ -169,16 +169,16 @@ context "with expired active messages assigned to workers from multiple" do before do - @miq_server2 = FactoryGirl.create(:miq_server, :zone => @miq_server.zone) - @worker1 = FactoryGirl.create(:miq_worker, :miq_server_id => @miq_server.id) - @worker2 = FactoryGirl.create(:miq_worker, :miq_server_id => @miq_server2.id) + @miq_server2 = FactoryBot.create(:miq_server, :zone => @miq_server.zone) + @worker1 = FactoryBot.create(:miq_worker, :miq_server_id => @miq_server.id) + @worker2 = FactoryBot.create(:miq_worker, :miq_server_id => @miq_server2.id) @actives = [] end it "should timeout messages on my server or servers that are down" do - @actives << FactoryGirl.create(:miq_queue, :state => 'dequeue', :msg_timeout => 4.minutes, :handler => @worker1) - @actives << FactoryGirl.create(:miq_queue, :state => 'dequeue', :msg_timeout => 4.minutes, :handler => @worker2) + @actives << FactoryBot.create(:miq_queue, :state => 'dequeue', :msg_timeout => 4.minutes, :handler => @worker1) + @actives << FactoryBot.create(:miq_queue, :state => 'dequeue', :msg_timeout => 4.minutes, :handler => @worker2) actives = MiqQueue.where(:state => 'dequeue') expect(actives.length).to eq(@actives.length) @@ -204,7 +204,7 @@ context "with vanilla generic worker" do before do - @worker1 = FactoryGirl.create(:miq_worker, :miq_server_id => @miq_server.id, :pid => 42, :type => 'MiqGenericWorker') + @worker1 = FactoryBot.create(:miq_worker, :miq_server_id => @miq_server.id, :pid => 42, :type => 'MiqGenericWorker') allow_any_instance_of(MiqServer).to receive(:get_time_threshold).and_return(2.minutes) allow_any_instance_of(MiqServer).to receive(:get_memory_threshold).and_return(500.megabytes) allow_any_instance_of(MiqServer).to receive(:get_restart_interval).and_return(0.hours) @@ -323,7 +323,7 @@ end context "threshold validation" do - let(:worker) { FactoryGirl.create(:miq_worker, :miq_server_id => server.id, :pid => 42) } + let(:worker) { FactoryBot.create(:miq_worker, :miq_server_id => server.id, :pid => 42) } let(:server) { @miq_server } before do diff --git a/spec/models/miq_server_spec.rb b/spec/models/miq_server_spec.rb index c63d0d3383c..3a772b53ed9 100644 --- a/spec/models/miq_server_spec.rb +++ b/spec/models/miq_server_spec.rb @@ -256,7 +256,7 @@ context "with a worker" do before do - @worker = FactoryGirl.create(:miq_worker, :miq_server_id => @miq_server.id, :pid => Process.pid) + @worker = FactoryBot.create(:miq_worker, :miq_server_id => @miq_server.id, :pid => Process.pid) allow(@miq_server).to receive(:validate_worker).and_return(true) @miq_server.setup_drb_variables @miq_server.worker_add(@worker.pid) @@ -304,8 +304,8 @@ context "with an active messsage and a second server" do before do - @msg = FactoryGirl.create(:miq_queue, :state => 'dequeue') - @miq_server2 = FactoryGirl.create(:miq_server, :is_master => true, :zone => @zone) + @msg = FactoryBot.create(:miq_queue, :state => 'dequeue') + @miq_server2 = FactoryBot.create(:miq_server, :is_master => true, :zone => @zone) end it "will validate the 'started' first server's active message when called on it" do @@ -374,7 +374,7 @@ ['event', 1], ['ems_metrics_coordinator', 1], ['ems_operations', 0] - ].each { |r, max| @server_roles << FactoryGirl.create(:server_role, :name => r, :max_concurrent => max) } + ].each { |r, max| @server_roles << FactoryBot.create(:server_role, :name => r, :max_concurrent => max) } @miq_server.role = @server_roles.collect(&:name).join(',') end @@ -416,9 +416,9 @@ describe ".destroy_linked_events" do it "destroys all events associated with destroyed server" do - FactoryGirl.create(:miq_event, :event_type => "Local TestEvent", :target => @miq_server) - FactoryGirl.create(:miq_event, :event_type => "Remote TestEvent 1", :target => remote_server) - FactoryGirl.create(:miq_event, :event_type => "Remote TestEvent 1", :target => remote_server) + FactoryBot.create(:miq_event, :event_type => "Local TestEvent", :target => @miq_server) + FactoryBot.create(:miq_event, :event_type => "Remote TestEvent 1", :target => remote_server) + FactoryBot.create(:miq_event, :event_type => "Remote TestEvent 1", :target => remote_server) expect(MiqEvent.count).to eq 3 diff --git a/spec/models/miq_task/purging_spec.rb b/spec/models/miq_task/purging_spec.rb index e8a9da3da66..0114a64846e 100644 --- a/spec/models/miq_task/purging_spec.rb +++ b/spec/models/miq_task/purging_spec.rb @@ -4,15 +4,15 @@ before do Timecop.freeze(8.days.ago) do @old_task = Job.create_job("VmScan", :guid => "old").miq_task - FactoryGirl.create(:binary_blob, :name => "old", :resource_type => 'MiqTask', :resource_id => @old_task.id) - FactoryGirl.create(:log_file, :name => "old", :miq_task_id => @old_task.id) + FactoryBot.create(:binary_blob, :name => "old", :resource_type => 'MiqTask', :resource_id => @old_task.id) + FactoryBot.create(:log_file, :name => "old", :miq_task_id => @old_task.id) end Timecop.freeze(6.days.ago) do @new_task = Job.create_job("VmScan", :guid => "recent").miq_task @new_task.state_finished - FactoryGirl.create(:binary_blob, :name => "recent", :resource_type => 'MiqTask', :resource_id => @new_task.id) - FactoryGirl.create(:log_file, :name => "recent", :miq_task_id => @new_task.id) + FactoryBot.create(:binary_blob, :name => "recent", :resource_type => 'MiqTask', :resource_id => @new_task.id) + FactoryBot.create(:log_file, :name => "recent", :miq_task_id => @new_task.id) end end diff --git a/spec/models/miq_task_spec.rb b/spec/models/miq_task_spec.rb index dc38fe42efd..9d672d59da4 100644 --- a/spec/models/miq_task_spec.rb +++ b/spec/models/miq_task_spec.rb @@ -1,6 +1,6 @@ describe MiqTask do context "when I add an MiqTask" do - let(:miq_task) { FactoryGirl.create(:miq_task_plain) } + let(:miq_task) { FactoryBot.create(:miq_task_plain) } it "should initialize properly" do expect(miq_task.state).to eq(MiqTask::STATE_INITIALIZED) @@ -177,7 +177,7 @@ end it "should properly process MiqTask#generic_action_with_callback" do - zone = FactoryGirl.create(:zone) + zone = FactoryBot.create(:zone) allow(MiqServer).to receive(:my_zone).and_return(zone.name) opts = { :action => 'Feed', @@ -207,10 +207,10 @@ end context "when there are multiple MiqTasks" do - let(:miq_task1) { FactoryGirl.create(:miq_task_plain) } - let(:miq_task2) { FactoryGirl.create(:miq_task_plain) } - let(:miq_task3) { FactoryGirl.create(:miq_task_plain) } - let(:zone) { FactoryGirl.create(:zone) } + let(:miq_task1) { FactoryBot.create(:miq_task_plain) } + let(:miq_task2) { FactoryBot.create(:miq_task_plain) } + let(:miq_task3) { FactoryBot.create(:miq_task_plain) } + let(:zone) { FactoryBot.create(:zone) } before do allow(MiqServer).to receive(:my_zone).and_return(zone.name) end @@ -265,7 +265,7 @@ end describe '#results_ready?' do - let(:miq_task) { FactoryGirl.create(:miq_task_plain) } + let(:miq_task) { FactoryBot.create(:miq_task_plain) } it 'returns false when task_results are missing' do expect(miq_task.task_results).to be_blank expect(miq_task.status).to eq(MiqTask::STATUS_OK) @@ -283,7 +283,7 @@ context "before_destroy callback" do it "destroys miq_task record if there is no job associated with it and Task is not active" do - miq_task = FactoryGirl.create(:miq_task_plain) + miq_task = FactoryBot.create(:miq_task_plain) miq_task.update_attributes!(:state => MiqTask::STATE_QUEUED) miq_task.destroy expect(MiqTask.count).to eq 0 @@ -301,7 +301,7 @@ it "doesn't destroy miq_task if task is active" do expect(MiqTask.count).to eq 0 - miq_task = FactoryGirl.create(:miq_task_plain) + miq_task = FactoryBot.create(:miq_task_plain) expect(MiqTask.count).to eq 1 miq_task.update_attributes!(:state => MiqTask::STATE_ACTIVE) MiqTask.first.destroy @@ -331,7 +331,7 @@ context "before save callback" do describe "#started" do - let(:task) { FactoryGirl.create(:miq_task_plain) } + let(:task) { FactoryBot.create(:miq_task_plain) } it "initilizes 'started_on' attribute if task become Active " do expect(task.started_on).to be nil @@ -344,7 +344,7 @@ end describe "#update_status" do - let(:miq_task) { FactoryGirl.create(:miq_task_plain) } + let(:miq_task) { FactoryBot.create(:miq_task_plain) } context "to 'Active' state" do it "sets 'started_on => Time.now.utc' if 'started_on' is nil" do @@ -376,7 +376,7 @@ end describe "#state_active" do - let(:miq_task) { FactoryGirl.create(:miq_task_plain) } + let(:miq_task) { FactoryBot.create(:miq_task_plain) } it "sets 'started_on => Time.now.utc' if 'started_on' is nil" do Timecop.freeze do @@ -407,7 +407,7 @@ end context "task does not linked to job" do - let(:miq_task) { FactoryGirl.create(:miq_task_plain) } + let(:miq_task) { FactoryBot.create(:miq_task_plain) } context "task is active" do before do @@ -486,7 +486,7 @@ describe "#task_results" do it "forces UTF-8 encoding" do - task = FactoryGirl.create( + task = FactoryBot.create( :miq_task, :binary_blob => BinaryBlob.new( :name => "task_results", @@ -501,7 +501,7 @@ describe "#task_results=" do it "forces UTF-8 encoding" do - task = FactoryGirl.create(:miq_task, :task_results => "\xC3\xA4".force_encoding("ASCII-8BIT")) + task = FactoryBot.create(:miq_task, :task_results => "\xC3\xA4".force_encoding("ASCII-8BIT")) expect(task.task_results).to eq("ä") end @@ -511,7 +511,7 @@ def create_test_task(name, status, updated) Timecop.travel(updated) do - FactoryGirl.create(:miq_task_plain).update_attributes(:state => MiqTask::STATE_FINISHED, + FactoryBot.create(:miq_task_plain).update_attributes(:state => MiqTask::STATE_FINISHED, :status => status, :name => name) end diff --git a/spec/models/miq_template_spec.rb b/spec/models/miq_template_spec.rb index b89886f84e3..52dc1640230 100644 --- a/spec/models/miq_template_spec.rb +++ b/spec/models/miq_template_spec.rb @@ -12,7 +12,7 @@ end context "#template=" do - let(:template) { FactoryGirl.create(:template_vmware) } + let(:template) { FactoryBot.create(:template_vmware) } it "true" do template.update_attribute(:template, true) @@ -46,18 +46,18 @@ end it "#supports_provisioning?" do - template = FactoryGirl.create(:template_openstack) - FactoryGirl.create(:ems_openstack, :miq_templates => [template]) + template = FactoryBot.create(:template_openstack) + FactoryBot.create(:ems_openstack, :miq_templates => [template]) expect(template.supports_provisioning?).to be_truthy - template = FactoryGirl.create(:template_openstack) + template = FactoryBot.create(:template_openstack) expect(template.supports_provisioning?).to be_falsey - template = FactoryGirl.create(:template_microsoft) + template = FactoryBot.create(:template_microsoft) expect(template.supports_provisioning?).to be_falsey - template = FactoryGirl.create(:template_microsoft) - FactoryGirl.create(:ems_openstack, :miq_templates => [template]) + template = FactoryBot.create(:template_microsoft) + FactoryBot.create(:ems_openstack, :miq_templates => [template]) expect(template.supports_provisioning?).to be_truthy end end diff --git a/spec/models/miq_ui_worker_spec.rb b/spec/models/miq_ui_worker_spec.rb index 7d5e1ad23dc..e17a33cf780 100644 --- a/spec/models/miq_ui_worker_spec.rb +++ b/spec/models/miq_ui_worker_spec.rb @@ -6,8 +6,8 @@ _guid, server1, @zone = EvmSpecHelper.create_guid_miq_server_zone - @worker1 = FactoryGirl.create(:miq_ui_worker, :miq_server => server1, :uri => "http://0.0.0.0:3000", :status => 'started') - @worker2 = FactoryGirl.create(:miq_ui_worker, :miq_server => server1, :uri => "http://0.0.0.0:3001", :status => 'started') + @worker1 = FactoryBot.create(:miq_ui_worker, :miq_server => server1, :uri => "http://0.0.0.0:3000", :status => 'started') + @worker2 = FactoryBot.create(:miq_ui_worker, :miq_server => server1, :uri => "http://0.0.0.0:3001", :status => 'started') end it "normal case" do @@ -20,7 +20,7 @@ end it "current vs. remote servers" do - server2 = FactoryGirl.create(:miq_server, :zone => @zone) + server2 = FactoryBot.create(:miq_server, :zone => @zone) @worker2.miq_server = server2 @worker2.save expect(MiqUiWorker.all_ports_in_use).to eq([3000]) diff --git a/spec/models/miq_user_role_spec.rb b/spec/models/miq_user_role_spec.rb index 2731851a2b7..5e735a9f8ad 100644 --- a/spec/models/miq_user_role_spec.rb +++ b/spec/models/miq_user_role_spec.rb @@ -18,8 +18,8 @@ it "with existing records" do # administrator is a role that we know is provide with the product # this is not testing administrator privileges - changed = FactoryGirl.create(:miq_user_role, :name => "EvmRole-administrator", :read_only => false) - unchanged = FactoryGirl.create(:miq_user_role, :name => "xxx", :read_only => false) + changed = FactoryBot.create(:miq_user_role, :name => "EvmRole-administrator", :read_only => false) + unchanged = FactoryBot.create(:miq_user_role, :name => "xxx", :read_only => false) unchanged_orig_updated_at = unchanged.updated_at MiqUserRole.seed @@ -57,19 +57,19 @@ )) feature1 = MiqProductFeature.find_all_by_identifier("dashboard_admin") - @role1 = FactoryGirl.create(:miq_user_role, :name => "Role1", :miq_product_features => feature1) - @group1 = FactoryGirl.create(:miq_group, :description => "Group1", :miq_user_role => @role1) - @user1 = FactoryGirl.create(:user, :userid => "user1", :miq_groups => [@group1]) + @role1 = FactoryBot.create(:miq_user_role, :name => "Role1", :miq_product_features => feature1) + @group1 = FactoryBot.create(:miq_group, :description => "Group1", :miq_user_role => @role1) + @user1 = FactoryBot.create(:user, :userid => "user1", :miq_groups => [@group1]) feature2 = MiqProductFeature.find_all_by_identifier("everything") - @role2 = FactoryGirl.create(:miq_user_role, :name => "Role2", :miq_product_features => feature2) - @group2 = FactoryGirl.create(:miq_group, :description => "Group2", :miq_user_role => @role2) - @user2 = FactoryGirl.create(:user, :userid => "user2", :miq_groups => [@group2]) + @role2 = FactoryBot.create(:miq_user_role, :name => "Role2", :miq_product_features => feature2) + @group2 = FactoryBot.create(:miq_group, :description => "Group2", :miq_user_role => @role2) + @user2 = FactoryBot.create(:user, :userid => "user2", :miq_groups => [@group2]) feature3 = MiqProductFeature.find_all_by_identifier(%w(host_show_list host_scan host_edit)) - @role3 = FactoryGirl.create(:miq_user_role, :name => "Role3", :miq_product_features => feature3) - @group3 = FactoryGirl.create(:miq_group, :description => "Group3", :miq_user_role => @role3) - @user3 = FactoryGirl.create(:user, :userid => "user3", :miq_groups => [@group3]) + @role3 = FactoryBot.create(:miq_user_role, :name => "Role3", :miq_product_features => feature3) + @group3 = FactoryBot.create(:miq_group, :description => "Group3", :miq_user_role => @role3) + @user3 = FactoryBot.create(:user, :userid => "user3", :miq_groups => [@group3]) end context "dynamic tenant product features" do @@ -78,19 +78,19 @@ Tenant.default_tenant end - let!(:tenant_1) { FactoryGirl.create(:tenant, :parent => root_tenant) } - let!(:tenant_2) { FactoryGirl.create(:tenant, :parent => root_tenant) } + let!(:tenant_1) { FactoryBot.create(:tenant, :parent => root_tenant) } + let!(:tenant_2) { FactoryBot.create(:tenant, :parent => root_tenant) } let(:feature) { MiqProductFeature.find_all_by_identifier(["dialog_edit_editor_tenant_#{tenant_2.id}", "rbac_tenant_manage_quotas_tenant_#{tenant_2.id}"]) } let(:non_dynamic_feature) { MiqProductFeature.find_all_by_identifier(["dialog_edit_editor", "rbac_tenant_manage_quotas"]) } - let(:role) { FactoryGirl.create(:miq_user_role, :miq_product_features => feature) } - let(:role_no_dynamic) { FactoryGirl.create(:miq_user_role, :miq_product_features => non_dynamic_feature) } - let(:group_tenant_1) { FactoryGirl.create(:miq_group, :miq_user_role => role, :tenant => tenant_1) } - let(:group_tenant_2) { FactoryGirl.create(:miq_group, :miq_user_role => role, :tenant => tenant_2) } - let(:group_3) { FactoryGirl.create(:miq_group, :miq_user_role => role_no_dynamic, :tenant => tenant_2) } - let!(:user_1) { FactoryGirl.create(:user, :userid => "user_1", :miq_groups => [group_tenant_1]) } - let!(:user_2) { FactoryGirl.create(:user, :userid => "user_2", :miq_groups => [group_tenant_2]) } - let!(:user_3) { FactoryGirl.create(:user, :userid => "user_3", :miq_groups => [group_3]) } + let(:role) { FactoryBot.create(:miq_user_role, :miq_product_features => feature) } + let(:role_no_dynamic) { FactoryBot.create(:miq_user_role, :miq_product_features => non_dynamic_feature) } + let(:group_tenant_1) { FactoryBot.create(:miq_group, :miq_user_role => role, :tenant => tenant_1) } + let(:group_tenant_2) { FactoryBot.create(:miq_group, :miq_user_role => role, :tenant => tenant_2) } + let(:group_3) { FactoryBot.create(:miq_group, :miq_user_role => role_no_dynamic, :tenant => tenant_2) } + let!(:user_1) { FactoryBot.create(:user, :userid => "user_1", :miq_groups => [group_tenant_1]) } + let!(:user_2) { FactoryBot.create(:user, :userid => "user_2", :miq_groups => [group_tenant_2]) } + let!(:user_3) { FactoryBot.create(:user, :userid => "user_3", :miq_groups => [group_3]) } it "doesn't authorize user without dynamic product feature" do User.with_user(user_1) do @@ -138,19 +138,19 @@ describe "#allow?" do it "allows everything" do EvmSpecHelper.seed_specific_product_features(%w(everything miq_report)) - user = FactoryGirl.create(:user, :features => "everything") + user = FactoryBot.create(:user, :features => "everything") expect(user.role_allows?(:identifier => "miq_report")).to be_truthy end it "dissallows unentitled" do EvmSpecHelper.seed_specific_product_features(%w(miq_report container_dashboard)) - user = FactoryGirl.create(:user, :features => "container_dashboard") + user = FactoryBot.create(:user, :features => "container_dashboard") expect(user.role_allows?(:identifier => "miq_report")).to be_falsey end it "allows entitled" do EvmSpecHelper.seed_specific_product_features(%w(miq_report)) - user = FactoryGirl.create(:user, :features => "miq_report") + user = FactoryBot.create(:user, :features => "miq_report") expect(user.role_allows?(:identifier => "miq_report")).to be_truthy end @@ -160,13 +160,13 @@ it "disallows hidden child with not-entitled parent" do EvmSpecHelper.seed_specific_product_features(%w(miq_report_view render_report_csv container_dashboard)) - user = FactoryGirl.create(:user, :features => "container_dashboard") + user = FactoryBot.create(:user, :features => "container_dashboard") expect(user.role_allows?(:identifier => "render_report_csv")).to be_falsey end it "allows hidden child with entitled parent" do EvmSpecHelper.seed_specific_product_features(%w(miq_report_view render_report_csv)) - user = FactoryGirl.create(:user, :features => "miq_report_view") + user = FactoryBot.create(:user, :features => "miq_report_view") expect(user.role_allows?(:identifier => "render_report_csv")).to be_truthy end @@ -180,7 +180,7 @@ EvmSpecHelper.seed_specific_product_features( %w(miq_report_widget_admin widget_refresh widget_edit widget_copy container_dashboard) ) - user = FactoryGirl.create(:user, :features => "widget_edit") + user = FactoryBot.create(:user, :features => "widget_edit") expect(user.role_allows?(:identifier => "widget_refresh")).to be_truthy end @@ -188,7 +188,7 @@ EvmSpecHelper.seed_specific_product_features( %w(miq_report_widget_admin widget_refresh widget_edit widget_copy container_dashboard) ) - user = FactoryGirl.create(:user, :features => "container_dashboard") + user = FactoryBot.create(:user, :features => "container_dashboard") expect(user.role_allows?(:identifier => "widget_refresh")).to be_falsey end @@ -199,30 +199,30 @@ EvmSpecHelper.seed_specific_product_features( %w(policy_profile_admin profile_new container_dashboard) ) - user = FactoryGirl.create(:user, :features => "container_dashboard") + user = FactoryBot.create(:user, :features => "container_dashboard") expect(user.role_allows?(:identifier => "profile_new")).to be_truthy end end it "deletes with no group assigned" do - role = FactoryGirl.create(:miq_user_role, :name => "test role") + role = FactoryBot.create(:miq_user_role, :name => "test role") role.destroy expect(MiqUserRole.count).to eq(0) end it "does not delete with group assigned" do - role = FactoryGirl.create(:miq_user_role, :name => "test role") - FactoryGirl.create(:miq_group, :description => "test group", :miq_user_role => role) + role = FactoryBot.create(:miq_user_role, :name => "test role") + FactoryBot.create(:miq_group, :description => "test group", :miq_user_role => role) expect { role.destroy }.to raise_error(ActiveRecord::DeleteRestrictionError) expect(MiqUserRole.count).to eq(1) end - let(:super_admin_role) { FactoryGirl.create(:miq_user_role, :features => MiqProductFeature::SUPER_ADMIN_FEATURE) } - let(:tenant_admin_role) { FactoryGirl.create(:miq_user_role, :features => MiqProductFeature::TENANT_ADMIN_FEATURE) } - let(:report_admin_role) { FactoryGirl.create(:miq_user_role, :features => MiqProductFeature::REPORT_ADMIN_FEATURE) } - let(:request_admin_role) { FactoryGirl.create(:miq_user_role, :features => MiqProductFeature::REQUEST_ADMIN_FEATURE) } - let(:regular_role) { FactoryGirl.create(:miq_user_role) } + let(:super_admin_role) { FactoryBot.create(:miq_user_role, :features => MiqProductFeature::SUPER_ADMIN_FEATURE) } + let(:tenant_admin_role) { FactoryBot.create(:miq_user_role, :features => MiqProductFeature::TENANT_ADMIN_FEATURE) } + let(:report_admin_role) { FactoryBot.create(:miq_user_role, :features => MiqProductFeature::REPORT_ADMIN_FEATURE) } + let(:request_admin_role) { FactoryBot.create(:miq_user_role, :features => MiqProductFeature::REQUEST_ADMIN_FEATURE) } + let(:regular_role) { FactoryBot.create(:miq_user_role) } describe "#super_admin_user?" do it "detects super admin" do @@ -268,7 +268,7 @@ describe "#destroy" do subject { miq_group.entitlement.miq_user_role } - let!(:miq_group) { FactoryGirl.create(:miq_group, :role => "EvmRole-administrator") } + let!(:miq_group) { FactoryBot.create(:miq_group, :role => "EvmRole-administrator") } context "when the role has any entitlements" do it "does not allow the role to be deleted" do @@ -295,22 +295,22 @@ describe "#group_count" do it "counts none in ruby" do - role = FactoryGirl.create(:miq_user_role) + role = FactoryBot.create(:miq_user_role) expect(role.group_count).to eq(0) end it "counts some in ruby" do - role = FactoryGirl.create(:miq_user_role) - FactoryGirl.create_list(:miq_group, 2, :miq_user_role => role) + role = FactoryBot.create(:miq_user_role) + FactoryBot.create_list(:miq_group, 2, :miq_user_role => role) expect(role.group_count).to eq(2) end end describe ".with_roles_excluding" do it "handles multiple columns" do - a = FactoryGirl.create(:miq_user_role, :features => "good") - FactoryGirl.create(:miq_user_role, :features => %w(good everything)) - FactoryGirl.create(:miq_user_role, :features => "everything") + a = FactoryBot.create(:miq_user_role, :features => "good") + FactoryBot.create(:miq_user_role, :features => %w(good everything)) + FactoryBot.create(:miq_user_role, :features => "everything") expect(MiqUserRole.select(:id, :name).with_roles_excluding("everything")).to match_array([a]) end diff --git a/spec/models/miq_widget/chart_content_spec.rb b/spec/models/miq_widget/chart_content_spec.rb index 34f5ac55e9d..3a81149bdda 100644 --- a/spec/models/miq_widget/chart_content_spec.rb +++ b/spec/models/miq_widget/chart_content_spec.rb @@ -7,12 +7,12 @@ MiqReport.seed_report("Vendor and Guest OS") MiqWidget.seed_widget("chart_vendor_and_guest_os") - @role = FactoryGirl.create(:miq_user_role) - @group = FactoryGirl.create(:miq_group, :miq_user_role => @role) - @user = FactoryGirl.create(:user, :miq_groups => [@group]) + @role = FactoryBot.create(:miq_user_role) + @group = FactoryBot.create(:miq_group, :miq_user_role => @role) + @user = FactoryBot.create(:user, :miq_groups => [@group]) 5.times do |i| - vm = FactoryGirl.build(:vm_vmware) + vm = FactoryBot.build(:vm_vmware) vm.evm_owner_id = @user.id if i > 2 vm.miq_group_id = @user.current_group.id if vm.evm_owner_id || (i > 1) vm.save diff --git a/spec/models/miq_widget/import_from_hash_spec.rb b/spec/models/miq_widget/import_from_hash_spec.rb index f602695e60e..deef92f1598 100644 --- a/spec/models/miq_widget/import_from_hash_spec.rb +++ b/spec/models/miq_widget/import_from_hash_spec.rb @@ -1,15 +1,15 @@ describe MiqWidget do context ".import_from_hash" do before do - @user = FactoryGirl.create(:user_admin) - @old_report = FactoryGirl.create(:miq_report, + @user = FactoryBot.create(:user_admin) + @old_report = FactoryBot.create(:miq_report, :name => "Test Report", :rpt_type => "Custom", :tz => "Eastern Time (US & Canada)", :col_order => ["name", "boot_time", "disks_aligned"], :cols => ["name", "boot_time", "disks_aligned"] ) - @old_widget = FactoryGirl.create(:miq_widget, + @old_widget = FactoryBot.create(:miq_widget, :title => "Test Widget", :visibility => {:roles => ["_ALL_"]}, :resource => @old_report diff --git a/spec/models/miq_widget/report_content_spec.rb b/spec/models/miq_widget/report_content_spec.rb index 81cd93e99f9..263a855a301 100644 --- a/spec/models/miq_widget/report_content_spec.rb +++ b/spec/models/miq_widget/report_content_spec.rb @@ -24,9 +24,9 @@ MiqReport.seed_report("Vendor and Guest OS") EvmSpecHelper.create_guid_miq_server_zone - @admin = FactoryGirl.create(:user_admin) + @admin = FactoryBot.create(:user_admin) @admin_group = @admin.current_group - vm_count.times { FactoryGirl.create(:vm_vmware) } + vm_count.times { FactoryBot.create(:vm_vmware) } end it "#generate_one_content_for_user" do @@ -54,18 +54,18 @@ end it "#generate with self service user" do - self_service_role = FactoryGirl.create( + self_service_role = FactoryBot.create( :miq_user_role, :name => "ss_role", :settings => {:restrictions => {:vms => :user_or_group}} ) - self_service_group = FactoryGirl.create( + self_service_group = FactoryBot.create( :miq_group, :description => "EvmGroup-self_service", :miq_user_role => self_service_role ) - user2 = FactoryGirl.create(:user, :miq_groups => [self_service_group]) + user2 = FactoryBot.create(:user, :miq_groups => [self_service_group]) report = widget.generate_report(self_service_group, user2) content = MiqWidget::ReportContent.new(:report => report, :resource => widget.resource, :timezone => "UTC", :widget_options => widget.options) diff --git a/spec/models/miq_widget/rss_content_spec.rb b/spec/models/miq_widget/rss_content_spec.rb index fa8604a2a08..75f6894c045 100644 --- a/spec/models/miq_widget/rss_content_spec.rb +++ b/spec/models/miq_widget/rss_content_spec.rb @@ -61,11 +61,11 @@ EvmSpecHelper.local_miq_server - @admin = FactoryGirl.create(:user_admin) + @admin = FactoryBot.create(:user_admin) @admin_group = @admin.current_group 10.times do |i| - FactoryGirl.create(:vm_vmware, :name => "VmVmware #{i}") + FactoryBot.create(:vm_vmware, :name => "VmVmware #{i}") end MiqWidget.sync_from_hash(YAML.load(' diff --git a/spec/models/miq_widget_set_spec.rb b/spec/models/miq_widget_set_spec.rb index cd95686a283..6a4181a0d00 100644 --- a/spec/models/miq_widget_set_spec.rb +++ b/spec/models/miq_widget_set_spec.rb @@ -1,8 +1,8 @@ describe MiqWidgetSet do let(:group) { user.current_group } - let(:user) { FactoryGirl.create(:user_with_group) } + let(:user) { FactoryBot.create(:user_with_group) } before do - @ws_group = FactoryGirl.create(:miq_widget_set, :name => 'Home', :owner => group) + @ws_group = FactoryBot.create(:miq_widget_set, :name => 'Home', :owner => group) end it "when a group dashboard is deleted" do @@ -22,7 +22,7 @@ context "with a user" do before do - FactoryGirl.create(:miq_widget_set, :name => 'Home', :userid => user.userid, :group_id => group.id) + FactoryBot.create(:miq_widget_set, :name => 'Home', :userid => user.userid, :group_id => group.id) end it "initial state" do @@ -41,13 +41,13 @@ end describe "#where_unique_on" do - let(:group2) { FactoryGirl.create(:miq_group, :description => 'dev group2') } - let(:ws_1) { FactoryGirl.create(:miq_widget_set, :name => 'Home', :userid => user.userid, :group_id => group.id) } + let(:group2) { FactoryBot.create(:miq_group, :description => 'dev group2') } + let(:ws_1) { FactoryBot.create(:miq_widget_set, :name => 'Home', :userid => user.userid, :group_id => group.id) } before do user.miq_groups << group2 ws_1 - FactoryGirl.create(:miq_widget_set, :name => 'Home', :userid => user.userid, :group_id => group2.id) + FactoryBot.create(:miq_widget_set, :name => 'Home', :userid => user.userid, :group_id => group2.id) end it "initial state" do @@ -65,21 +65,21 @@ describe "#with_users" do it "brings back records with users" do - ws_1 = FactoryGirl.create(:miq_widget_set, :name => 'Home', :userid => user.userid, :group_id => group.id) + ws_1 = FactoryBot.create(:miq_widget_set, :name => 'Home', :userid => user.userid, :group_id => group.id) expect(described_class.with_users).to eq([ws_1]) end end context ".find_with_same_order" do it "returns in index order" do - g1 = FactoryGirl.create(:miq_widget_set) - g2 = FactoryGirl.create(:miq_widget_set) + g1 = FactoryBot.create(:miq_widget_set) + g2 = FactoryBot.create(:miq_widget_set) expect(MiqWidgetSet.find_with_same_order([g1.id.to_s, g2.id.to_s])).to eq([g1, g2]) end it "returns in non index order" do - g1 = FactoryGirl.create(:miq_widget_set) - g2 = FactoryGirl.create(:miq_widget_set) + g1 = FactoryBot.create(:miq_widget_set) + g2 = FactoryBot.create(:miq_widget_set) expect(MiqWidgetSet.find_with_same_order([g2.id.to_s, g1.id.to_s])).to eq([g2, g1]) end end diff --git a/spec/models/miq_widget_spec.rb b/spec/models/miq_widget_spec.rb index 5dddeb87159..dbf6e3531f2 100644 --- a/spec/models/miq_widget_spec.rb +++ b/spec/models/miq_widget_spec.rb @@ -13,13 +13,13 @@ MiqReport.seed_report("Vendor and Guest OS") feature1 = MiqProductFeature.find_all_by_identifier("dashboard_admin") - @user1 = FactoryGirl.create(:user, :role => "role1", :features => feature1) + @user1 = FactoryBot.create(:user, :role => "role1", :features => feature1) @group1 = @user1.current_group feature2 = MiqProductFeature.find_all_by_identifier("everything") - @role2 = FactoryGirl.create(:miq_user_role, :name => "Role2", :features => feature2) - @group2 = FactoryGirl.create(:miq_group, :description => "Group2", :miq_user_role => @role2) - @user2 = FactoryGirl.create(:user, :miq_groups => [@group2]) + @role2 = FactoryBot.create(:miq_user_role, :name => "Role2", :features => feature2) + @group2 = FactoryBot.create(:miq_group, :description => "Group2", :miq_user_role => @role2) + @user2 = FactoryBot.create(:user, :miq_groups => [@group2]) @widget_report_vendor_and_guest_os = MiqWidget.sync_from_hash(YAML.load(' description: report_vendor_and_guest_os @@ -91,7 +91,7 @@ end it "ignores the legacy format admin|db_name" do - ws = FactoryGirl.create(:miq_widget_set, :name => "#{@user1.userid}|Home") + ws = FactoryBot.create(:miq_widget_set, :name => "#{@user1.userid}|Home") @widget_report_vendor_and_guest_os.make_memberof(ws) expect(@widget_report_vendor_and_guest_os.grouped_subscribers).to be_kind_of(Hash) expect(@widget_report_vendor_and_guest_os.grouped_subscribers).to be_empty @@ -99,7 +99,7 @@ context 'with subscribers' do before do - ws = FactoryGirl.create(:miq_widget_set, :name => "Home", :userid => @user1.userid, :group_id => @group1.id) + ws = FactoryBot.create(:miq_widget_set, :name => "Home", :userid => @user1.userid, :group_id => @group1.id) @widget_report_vendor_and_guest_os.make_memberof(ws) end @@ -156,17 +156,17 @@ end def add_user(group) - FactoryGirl.create(:user, :miq_groups => [group]) + FactoryBot.create(:user, :miq_groups => [group]) end def add_dashboard_for_user(db_name, userid, group) - FactoryGirl.create(:miq_widget_set, :name => db_name, :userid => userid, :group_id => group) + FactoryBot.create(:miq_widget_set, :name => db_name, :userid => userid, :group_id => group) end end context "#contents_for_user" do it "user owned" do - content = FactoryGirl.create(:miq_widget_content, + content = FactoryBot.create(:miq_widget_content, :miq_widget => @widget_report_vendor_and_guest_os, :user_id => @user1.id, :miq_group_id => @user1.current_group_id, @@ -177,7 +177,7 @@ def add_dashboard_for_user(db_name, userid, group) it "owned by miq_group and in user's timezone" do @user1.settings.store_path(:display, :timezone, "Eastern Time (US & Canada)") - content = FactoryGirl.create(:miq_widget_content, + content = FactoryBot.create(:miq_widget_content, :miq_widget => @widget_report_vendor_and_guest_os, :miq_group_id => @group1.id, :timezone => "Eastern Time (US & Canada)" @@ -187,7 +187,7 @@ def add_dashboard_for_user(db_name, userid, group) it "owned by miq_group and not in user's timezone" do @user1.settings.store_path(:display, :timezone, "Eastern Time (US & Canada)") - FactoryGirl.create(:miq_widget_content, + FactoryBot.create(:miq_widget_content, :miq_widget => @widget_report_vendor_and_guest_os, :miq_group_id => @group1.id, :timezone => "UTC" @@ -196,12 +196,12 @@ def add_dashboard_for_user(db_name, userid, group) end it "both user and miq_group owned" do - FactoryGirl.create(:miq_widget_content, + FactoryBot.create(:miq_widget_content, :miq_widget => @widget_report_vendor_and_guest_os, :miq_group_id => @group1.id, :timezone => "Eastern Time (US & Canada)" ) - content2 = FactoryGirl.create(:miq_widget_content, + content2 = FactoryBot.create(:miq_widget_content, :miq_widget => @widget_report_vendor_and_guest_os, :miq_group_id => @group1.id, :user_id => @user1.id, @@ -232,11 +232,11 @@ def add_dashboard_for_user(db_name, userid, group) before do MiqReport.seed_report("Top CPU Consumers weekly") - role1 = FactoryGirl.create(:miq_user_role, :name => 'EvmRole-support') - group1 = FactoryGirl.create(:miq_group, :description => "EvmGroup-support", :miq_user_role => role1) - user1 = FactoryGirl.create(:user, :miq_groups => [group1]) + role1 = FactoryBot.create(:miq_user_role, :name => 'EvmRole-support') + group1 = FactoryBot.create(:miq_group, :description => "EvmGroup-support", :miq_user_role => role1) + user1 = FactoryBot.create(:user, :miq_groups => [group1]) - @user2 = FactoryGirl.create(:user_admin) + @user2 = FactoryBot.create(:user_admin) @group2 = @user2.current_group attrs = YAML.load(' @@ -265,8 +265,8 @@ def add_dashboard_for_user(db_name, userid, group) read_only: true ') - ws1 = FactoryGirl.create(:miq_widget_set, :name => "default", :userid => user1.userid, :group_id => group1.id) - ws2 = FactoryGirl.create(:miq_widget_set, :name => "default", :userid => @user2.userid, :group_id => @group2.id) + ws1 = FactoryBot.create(:miq_widget_set, :name => "default", :userid => user1.userid, :group_id => group1.id) + ws2 = FactoryBot.create(:miq_widget_set, :name => "default", :userid => @user2.userid, :group_id => @group2.id) @widget = MiqWidget.sync_from_hash(attrs) ws1.add_member(@widget) ws2.add_member(@widget) @@ -404,7 +404,7 @@ def add_dashboard_for_user(db_name, userid, group) expect(task.pct_complete).to eq(100) @widget.visibility[:roles] = "_ALL_" - new_user = FactoryGirl.create(:user, :userid => "test task", :role => "random") + new_user = FactoryBot.create(:user, :userid => "test task", :role => "random") @widget.create_initial_content_for_user(new_user) q = MiqQueue.first @@ -428,9 +428,9 @@ def add_dashboard_for_user(db_name, userid, group) end it "with multiple timezones in one group" do - user_est = FactoryGirl.create(:user, :userid => 'user_est', :miq_groups => [@group2], :settings => {:display => {:timezone => "Eastern Time (US & Canada)"}}) + user_est = FactoryBot.create(:user, :userid => 'user_est', :miq_groups => [@group2], :settings => {:display => {:timezone => "Eastern Time (US & Canada)"}}) expect(user_est.get_timezone).to eq("Eastern Time (US & Canada)") - ws = FactoryGirl.create(:miq_widget_set, :name => "default", :userid => "user_est", :group_id => @group2.id) + ws = FactoryBot.create(:miq_widget_set, :name => "default", :userid => "user_est", :group_id => @group2.id) ws.add_member(@widget) expect_any_instance_of(MiqWidget).to receive(:generate_content).with("MiqGroup", @group2.name, nil, ["Eastern Time (US & Canada)", "UTC"]) @@ -441,9 +441,9 @@ def add_dashboard_for_user(db_name, userid, group) end it "with report_sync" do - user_est = FactoryGirl.create(:user, :userid => 'user_est', :miq_groups => [@group2], :settings => {:display => {:timezone => "Eastern Time (US & Canada)"}}) + user_est = FactoryBot.create(:user, :userid => 'user_est', :miq_groups => [@group2], :settings => {:display => {:timezone => "Eastern Time (US & Canada)"}}) expect(user_est.get_timezone).to eq("Eastern Time (US & Canada)") - ws = FactoryGirl.create(:miq_widget_set, :name => "default", :userid => "user_est", :group_id => @group2.id) + ws = FactoryBot.create(:miq_widget_set, :name => "default", :userid => "user_est", :group_id => @group2.id) ws.add_member(@widget) expect_any_instance_of(MiqWidget).to receive(:generate_content).with("MiqGroup", @group2.name, nil, @@ -463,15 +463,15 @@ def add_dashboard_for_user(db_name, userid, group) it "multiple" do @widget.visibility[:roles] = "_ALL_" - new_group1 = FactoryGirl.create(:miq_group, :role => "operator") - new_ws1 = FactoryGirl.create(:miq_widget_set, + new_group1 = FactoryBot.create(:miq_group, :role => "operator") + new_ws1 = FactoryBot.create(:miq_widget_set, :name => "default", :userid => @user2.userid, :group_id => new_group1.id) new_ws1.add_member(@widget) - new_group2 = FactoryGirl.create(:miq_group, :role => "approver") - new_ws2 = FactoryGirl.create(:miq_widget_set, + new_group2 = FactoryBot.create(:miq_group, :role => "approver") + new_ws2 = FactoryBot.create(:miq_widget_set, :name => "default", :userid => @user2.userid, :group_id => new_group2.id) @@ -486,8 +486,8 @@ def add_dashboard_for_user(db_name, userid, group) it "none" do @widget.visibility[:roles] = "_ALL_" MiqWidgetSet.destroy_all - user = FactoryGirl.create(:user, :userid => 'alone', :miq_groups => [@group2]) - ws = FactoryGirl.create(:miq_widget_set, :name => "default", :userid => user.userid) + user = FactoryBot.create(:user, :userid => 'alone', :miq_groups => [@group2]) + ws = FactoryBot.create(:miq_widget_set, :name => "default", :userid => user.userid) ws.add_member(@widget) expect(@widget).to receive(:generate_content_options).never @@ -576,10 +576,10 @@ def add_dashboard_for_user(db_name, userid, group) context "#create_initial_content_for_user" do before do - self_service_role = FactoryGirl.create(:miq_user_role, :settings => {:restrictions => {:vms => :user}}) - self_service_group = FactoryGirl.create(:miq_group, :miq_user_role => self_service_role) - @user = FactoryGirl.create(:user, :miq_groups => [self_service_group]) - @widget = FactoryGirl.create(:miq_widget) + self_service_role = FactoryBot.create(:miq_user_role, :settings => {:restrictions => {:vms => :user}}) + self_service_group = FactoryBot.create(:miq_group, :miq_user_role => self_service_role) + @user = FactoryBot.create(:user, :miq_groups => [self_service_group]) + @widget = FactoryBot.create(:miq_widget) end it "with single user" do @@ -596,21 +596,21 @@ def add_dashboard_for_user(db_name, userid, group) # tests are written for timezone_matters = true widget.options[:timezone_matters] = true if widget.options - @role = FactoryGirl.create(:miq_user_role) - @group = FactoryGirl.create(:miq_group, :miq_user_role => @role) - @user1 = FactoryGirl.create(:user, + @role = FactoryBot.create(:miq_user_role) + @group = FactoryBot.create(:miq_group, :miq_user_role => @role) + @user1 = FactoryBot.create(:user, :settings => {:display => {:timezone => "Eastern Time (US & Canada)"}}, :miq_groups => [@group]) - @user2 = FactoryGirl.create(:user, + @user2 = FactoryBot.create(:user, :settings => {:display => {:timezone => "Pacific Time (US & Canada)"}}, :miq_groups => [@group]) - @ws1 = FactoryGirl.create(:miq_widget_set, + @ws1 = FactoryBot.create(:miq_widget_set, :name => "HOME", :userid => @user1.userid, :group_id => @group.id ) - @ws2 = FactoryGirl.create(:miq_widget_set, + @ws2 = FactoryBot.create(:miq_widget_set, :name => "HOME", :userid => @user2.userid, :group_id => @group.id @@ -696,8 +696,8 @@ def add_dashboard_for_user(db_name, userid, group) context "for non-current self service group" do before do @role.update_attributes(:settings => {:restrictions => {:vms => :user_or_group}}) - @group2 = FactoryGirl.create(:miq_group, :miq_user_role => @role) - @ws3 = FactoryGirl.create(:miq_widget_set, + @group2 = FactoryBot.create(:miq_group, :miq_user_role => @role) + @ws3 = FactoryBot.create(:miq_widget_set, :name => "HOME", :userid => @user1.userid, :group_id => @group2.id @@ -709,10 +709,10 @@ def add_dashboard_for_user(db_name, userid, group) @winos_pruduct_name = 'Windows 7 Enterprise' 7.times do |i| - vm = FactoryGirl.build(:vm_vmware, + vm = FactoryBot.build(:vm_vmware, :name => "vm_win_#{i}", :vendor => "vmware", - :operating_system => FactoryGirl.create(:operating_system, + :operating_system => FactoryBot.create(:operating_system, :product_name => @winos_pruduct_name, :name => 'my_pc'), ) @@ -722,10 +722,10 @@ def add_dashboard_for_user(db_name, userid, group) @rhos_product_name = 'Red Hat Enterprise Linux 6 (64-bit)' 3.times do |i| - vm = FactoryGirl.build(:vm_redhat, + vm = FactoryBot.build(:vm_redhat, :name => "vm_rh_#{i}", :vendor => "redhat", - :operating_system => FactoryGirl.create(:operating_system, + :operating_system => FactoryBot.create(:operating_system, :product_name => @rhos_product_name, :name => 'my_linux'), ) @@ -772,25 +772,25 @@ def add_dashboard_for_user(db_name, userid, group) describe "#queued_at" do it "is nil when no task" do - widget = FactoryGirl.build(:miq_widget) + widget = FactoryBot.build(:miq_widget) expect(widget.queued_at).to be_nil end it "uses task value" do dt = Time.now.utc - widget = FactoryGirl.build(:miq_widget, :miq_task => FactoryGirl.build(:miq_task, :created_on => dt)) + widget = FactoryBot.build(:miq_widget, :miq_task => FactoryBot.build(:miq_task, :created_on => dt)) expect(widget.queued_at).to eq(dt) end end describe "#status_message" do it "is nil when no task" do - widget = FactoryGirl.build(:miq_widget) + widget = FactoryBot.build(:miq_widget) expect(widget.status_message).to eq("Unknown") end it "uses task value" do - widget = FactoryGirl.build(:miq_widget, :miq_task => FactoryGirl.build(:miq_task, :message => "message")) + widget = FactoryBot.build(:miq_widget, :miq_task => FactoryBot.build(:miq_task, :message => "message")) expect(widget.status_message).to eq("message") end end diff --git a/spec/models/miq_worker/runner_spec.rb b/spec/models/miq_worker/runner_spec.rb index 0ed477ae510..d9e0c3269e3 100644 --- a/spec/models/miq_worker/runner_spec.rb +++ b/spec/models/miq_worker/runner_spec.rb @@ -31,7 +31,7 @@ end it "worker_monitor_drb caches DRbObject" do - @worker_base.instance_variable_set(:@server, FactoryGirl.create(:miq_server, :drb_uri => "druby://127.0.0.1:123456")) + @worker_base.instance_variable_set(:@server, FactoryBot.create(:miq_server, :drb_uri => "druby://127.0.0.1:123456")) require 'drb' allow(DRbObject).to receive(:new).and_return(0, 1) expect(@worker_base.worker_monitor_drb).to eq 0 @@ -58,7 +58,7 @@ @miq_server = EvmSpecHelper.local_miq_server allow(@miq_server).to receive(:active_role).and_return("automate)") - @worker = FactoryGirl.create(:miq_worker, :miq_server_id => @miq_server.id, :type => "MiqGenericWorker") + @worker = FactoryBot.create(:miq_worker, :miq_server_id => @miq_server.id, :type => "MiqGenericWorker") @worker_base = MiqWorker::Runner.new(:guid => @worker.guid) end diff --git a/spec/models/miq_worker_spec.rb b/spec/models/miq_worker_spec.rb index f3e7653638a..8bd33903cd2 100644 --- a/spec/models/miq_worker_spec.rb +++ b/spec/models/miq_worker_spec.rb @@ -16,7 +16,7 @@ def all_workers context ".sync_workers" do it "stops extra workers, returning deleted pids" do expect_any_instance_of(described_class).to receive(:stop) - worker = FactoryGirl.create(:miq_worker, :status => "started") + worker = FactoryBot.create(:miq_worker, :status => "started") worker.class.workers = 0 expect(worker.class.sync_workers).to eq(:adds => [], :deletes => [worker.pid]) end @@ -36,14 +36,14 @@ def check_has_required_role(worker_role_names, expected_result) end before do - active_roles = %w(foo bar).map { |rn| FactoryGirl.create(:server_role, :name => rn) } + active_roles = %w(foo bar).map { |rn| FactoryBot.create(:server_role, :name => rn) } @server = EvmSpecHelper.local_miq_server(:active_roles => active_roles) end context "clean_active_messages" do before do - @worker = FactoryGirl.create(:miq_worker, :miq_server => @server) - @message = FactoryGirl.create(:miq_queue, :handler => @worker, :state => 'dequeue') + @worker = FactoryBot.create(:miq_worker, :miq_server => @server) + @message = FactoryBot.create(:miq_queue, :handler => @worker, :state => 'dequeue') end it "normal" do @@ -229,13 +229,13 @@ def check_has_required_role(worker_role_names, expected_result) before do allow(described_class).to receive(:nice_increment).and_return("+10") - @zone = FactoryGirl.create(:zone) - @server = FactoryGirl.create(:miq_server, :zone => @zone) + @zone = FactoryBot.create(:zone) + @server = FactoryBot.create(:miq_server, :zone => @zone) allow(MiqServer).to receive(:my_server).and_return(@server) - @worker = FactoryGirl.create(:ems_refresh_worker_amazon, :miq_server => @server) + @worker = FactoryBot.create(:ems_refresh_worker_amazon, :miq_server => @server) - @server2 = FactoryGirl.create(:miq_server, :zone => @zone) - @worker2 = FactoryGirl.create(:ems_refresh_worker_amazon, :miq_server => @server2) + @server2 = FactoryBot.create(:miq_server, :zone => @zone) + @worker2 = FactoryBot.create(:ems_refresh_worker_amazon, :miq_server => @server2) end it ".server_scope" do @@ -338,7 +338,7 @@ def check_has_required_role(worker_role_names, expected_result) context "instance" do before do allow(described_class).to receive(:nice_increment).and_return("+10") - @worker = FactoryGirl.create(:miq_worker) + @worker = FactoryBot.create(:miq_worker) end it "#worker_options" do @@ -390,14 +390,14 @@ def check_has_required_role(worker_role_names, expected_result) end it "true if stopping and last heartbeat is within the queue message timeout of an active message" do - @worker.messages << FactoryGirl.create(:miq_queue, :msg_timeout => 60.minutes) + @worker.messages << FactoryBot.create(:miq_queue, :msg_timeout => 60.minutes) @worker.update(:status => described_class::STATUS_STOPPING, :last_heartbeat => 90.minutes.ago) expect(subject).to be_truthy end it "false if stopping and last heartbeat is older than the queue message timeout of the work item" do - @worker.messages << FactoryGirl.create(:miq_queue, :msg_timeout => 60.minutes, :state => "dequeue") + @worker.messages << FactoryBot.create(:miq_queue, :msg_timeout => 60.minutes, :state => "dequeue") @worker.update(:status => described_class::STATUS_STOPPING, :last_heartbeat => 30.minutes.ago) expect(subject).to be_falsey diff --git a/spec/models/mixins/aggregation_mixin_spec.rb b/spec/models/mixins/aggregation_mixin_spec.rb index 3584234e856..6b353f2884e 100644 --- a/spec/models/mixins/aggregation_mixin_spec.rb +++ b/spec/models/mixins/aggregation_mixin_spec.rb @@ -116,16 +116,16 @@ def cluster_2_1_host(hardware_args) hosts = Array.new(2) do - FactoryGirl.create(:host, :hardware => FactoryGirl.create(:hardware, hardware_args)) - end + [FactoryGirl.create(:host, :hardware => FactoryGirl.create(:hardware))] - FactoryGirl.create(:ems_cluster, :hosts => hosts) + FactoryBot.create(:host, :hardware => FactoryBot.create(:hardware, hardware_args)) + end + [FactoryBot.create(:host, :hardware => FactoryBot.create(:hardware))] + FactoryBot.create(:ems_cluster, :hosts => hosts) end def cluster_3_1_vm(hardware_args) vms = Array.new(3) do - FactoryGirl.create(:vm, :hardware => FactoryGirl.create(:hardware, hardware_args)) - end + [FactoryGirl.create(:vm, :hardware => FactoryGirl.create(:hardware))] + FactoryBot.create(:vm, :hardware => FactoryBot.create(:hardware, hardware_args)) + end + [FactoryBot.create(:vm, :hardware => FactoryBot.create(:hardware))] - FactoryGirl.create(:ems_cluster, :vms => vms) + FactoryBot.create(:ems_cluster, :vms => vms) end end diff --git a/spec/models/mixins/assignment_mixin_spec.rb b/spec/models/mixins/assignment_mixin_spec.rb index 496bdd08964..b093d08e3fe 100644 --- a/spec/models/mixins/assignment_mixin_spec.rb +++ b/spec/models/mixins/assignment_mixin_spec.rb @@ -5,10 +5,10 @@ describe '#get_assigned_for_target' do context 'searching for ChargebackRate' do let(:test_class) { ChargebackRate } - let(:vm) { FactoryGirl.create(:vm_openstack) } - let(:hardware) { FactoryGirl.create(:hardware, :vm_or_template_id => vm.id) } - let(:cloud_volume) { FactoryGirl.create(:cloud_volume, :hardwares => [hardware]) } - let(:chargeback_rate) { FactoryGirl.create(:chargeback_rate, :rate_type => 'Storage') } + let(:vm) { FactoryBot.create(:vm_openstack) } + let(:hardware) { FactoryBot.create(:hardware, :vm_or_template_id => vm.id) } + let(:cloud_volume) { FactoryBot.create(:cloud_volume, :hardwares => [hardware]) } + let(:chargeback_rate) { FactoryBot.create(:chargeback_rate, :rate_type => 'Storage') } before do ct1 = ctag("environment", "test1") @@ -30,12 +30,12 @@ it "detects tags on alert_set" do ct1 = ctag("environment", "test") - alert_set = FactoryGirl.create(:miq_alert_set_vm) + alert_set = FactoryBot.create(:miq_alert_set_vm) alert_set.assign_to_tags([ct1], "vm") alert_set.reload # reload ensures the tag is set ct2 = ctag("environment", "staging") - alert_set2 = FactoryGirl.create(:miq_alert_set_vm) + alert_set2 = FactoryBot.create(:miq_alert_set_vm) alert_set2.assign_to_tags([ct2], "vm") alert_set2.reload # reload ensures the tag is set @@ -48,7 +48,7 @@ it "unassigns one tag from alert_set" do ct1 = ctag("environment", "test1") ct2 = ctag("environment", "staging1") - alert_set = FactoryGirl.create(:miq_alert_set_vm) + alert_set = FactoryBot.create(:miq_alert_set_vm) alert_set.assign_to_tags([ct1, ct2], "vm") alert_set.reload # reload ensures the tag is set @@ -61,9 +61,9 @@ end it "unassigns object from alert_set" do - enterprise = FactoryGirl.create(:miq_enterprise) - enterprise2 = FactoryGirl.create(:miq_enterprise) - alert_set = FactoryGirl.create(:miq_alert_set_vm) + enterprise = FactoryBot.create(:miq_enterprise) + enterprise2 = FactoryBot.create(:miq_enterprise) + alert_set = FactoryBot.create(:miq_alert_set_vm) alert_set.assign_to_objects([enterprise, enterprise2]) alert_set.reload @@ -79,10 +79,10 @@ end describe "#get_assigned_tos" do - let(:cc_classification) { FactoryGirl.create(:classification_cost_center) } - let(:classification_tag) { FactoryGirl.create(:classification_tag, :parent => cc_classification) } - let(:vm) { FactoryGirl.create(:vm) } - let(:alert_set) { FactoryGirl.create(:miq_alert_set) } + let(:cc_classification) { FactoryBot.create(:classification_cost_center) } + let(:classification_tag) { FactoryBot.create(:classification_tag, :parent => cc_classification) } + let(:vm) { FactoryBot.create(:vm) } + let(:alert_set) { FactoryBot.create(:miq_alert_set) } before do alert_set.assign_to_objects([vm]) @@ -131,7 +131,7 @@ # @return [ClassificationTag] classification tag. `.tag()` is an available method def ctag(category = "environment", value = "test") env = Classification.find_by_name(category) || - FactoryGirl.create(:classification, :name => category, :single_value => 1) - FactoryGirl.create(:classification_tag, :name => value, :parent => env) + FactoryBot.create(:classification, :name => category, :single_value => 1) + FactoryBot.create(:classification_tag, :name => value, :parent => env) end end diff --git a/spec/models/mixins/authentication_mixin_spec.rb b/spec/models/mixins/authentication_mixin_spec.rb index 3d8cd3e5244..920e03ddee2 100644 --- a/spec/models/mixins/authentication_mixin_spec.rb +++ b/spec/models/mixins/authentication_mixin_spec.rb @@ -1,9 +1,9 @@ describe AuthenticationMixin do include Spec::Support::ArelHelper - let(:host) { FactoryGirl.create(:host) } - let(:invalid_auth) { FactoryGirl.create(:authentication, :resource => host, :status => "Invalid") } - let(:valid_auth) { FactoryGirl.create(:authentication, :resource => host, :status => "Valid") } + let(:host) { FactoryBot.create(:host) } + let(:invalid_auth) { FactoryBot.create(:authentication, :resource => host, :status => "Invalid") } + let(:valid_auth) { FactoryBot.create(:authentication, :resource => host, :status => "Valid") } let(:authentications) { [invalid_auth, valid_auth] } let(:test_class_instance) do @@ -97,13 +97,13 @@ def self.name; "TestClass"; end context "authorization event and check for container providers" do before do - zone = FactoryGirl.create(:zone) + zone = FactoryBot.create(:zone) allow(MiqServer).to receive(:my_zone).and_return(zone.name) end it "should be triggered for kubernetes" do auth = AuthToken.new(:name => "bearer", :auth_key => "valid-token") - FactoryGirl.create(:ems_kubernetes, :authentications => [auth]) + FactoryBot.create(:ems_kubernetes, :authentications => [auth]) expect(MiqQueue.count).to eq(2) expect(MiqQueue.find_by(:method_name => 'raise_evm_event')).not_to be_nil @@ -112,7 +112,7 @@ def self.name; "TestClass"; end it "should be triggered for openshift" do auth = AuthToken.new(:name => "bearer", :auth_key => "valid-token") - FactoryGirl.create(:ems_openshift, :authentications => [auth]) + FactoryBot.create(:ems_openshift, :authentications => [auth]) expect(MiqQueue.count).to eq(2) expect(MiqQueue.find_by(:method_name => 'raise_evm_event')).not_to be_nil @@ -145,7 +145,7 @@ def self.name; "TestClass"; end context "#retry_scheduled_authentication_check" do let(:host) do EvmSpecHelper.local_miq_server - FactoryGirl.create(:host_with_authentication).tap { MiqQueue.destroy_all } + FactoryBot.create(:host_with_authentication).tap { MiqQueue.destroy_all } end it "works" do @@ -177,11 +177,11 @@ def self.name; "TestClass"; end context "with multiple zones, emses, and hosts" do before do @zone1 = @miq_server.zone - @zone2 = FactoryGirl.create(:zone, :name => 'test1') - @ems1 = FactoryGirl.create(:ems_vmware_with_authentication, :zone => @zone1) - @ems2 = FactoryGirl.create(:ems_vmware_with_authentication, :zone => @zone2) - @host1 = FactoryGirl.create(:host_with_authentication, :ext_management_system => @ems1) - @host2 = FactoryGirl.create(:host_with_authentication, :ext_management_system => @ems2) + @zone2 = FactoryBot.create(:zone, :name => 'test1') + @ems1 = FactoryBot.create(:ems_vmware_with_authentication, :zone => @zone1) + @ems2 = FactoryBot.create(:ems_vmware_with_authentication, :zone => @zone2) + @host1 = FactoryBot.create(:host_with_authentication, :ext_management_system => @ems1) + @host2 = FactoryBot.create(:host_with_authentication, :ext_management_system => @ems2) # Destroy any queued auth checks from creating the new CI's with authentications MiqQueue.destroy_all @@ -286,7 +286,7 @@ def self.name; "TestClass"; end end it "returns success with no error message" do - ok_task = FactoryGirl.create(:miq_task, :status => 'Ok') + ok_task = FactoryBot.create(:miq_task, :status => 'Ok') allow(MiqTask).to receive(:generic_action_with_callback).with(task_opts, queue_opts).and_return(1) allow(MiqTask).to receive(:wait_for_taskid).with(1, :timeout => 30).and_return(ok_task) @@ -295,7 +295,7 @@ def self.name; "TestClass"; end it "returns failure with an error message" do message = 'Login failed due to a bad username or password.' - error_task = FactoryGirl.create(:miq_task, :status => 'Error', :message => message) + error_task = FactoryBot.create(:miq_task, :status => 'Error', :message => message) allow(MiqTask).to receive(:generic_action_with_callback).with(task_opts, queue_opts).and_return(1) allow(MiqTask).to receive(:wait_for_taskid).with(1, :timeout => 30).and_return(error_task) @@ -305,9 +305,9 @@ def self.name; "TestClass"; end context "with a host and ems" do before do - @host = FactoryGirl.create(:host_vmware_esx_with_authentication) - @host_no_auth = FactoryGirl.create(:host_vmware_esx) - @ems = FactoryGirl.create(:ems_vmware_with_authentication) + @host = FactoryBot.create(:host_vmware_esx_with_authentication) + @host_no_auth = FactoryBot.create(:host_vmware_esx) + @ems = FactoryBot.create(:ems_vmware_with_authentication) MiqQueue.destroy_all @auth = @ems.authentication_type(:default) @orig_ems_user, @orig_ems_pwd = @ems.auth_user_pwd(:default) @@ -320,88 +320,88 @@ def self.name; "TestClass"; end it "#authentication_status_ok? true if no type, default is Valid and second one is Invalid" do @auth.update_attribute(:status, "Valid") - @ems.authentications << FactoryGirl.build(:authentication, :authtype => :some_type, :status => "Invalid") + @ems.authentications << FactoryBot.build(:authentication, :authtype => :some_type, :status => "Invalid") expect(@ems.authentication_status_ok?).to be_truthy end it "#authentication_status_ok? false if no type, default is Invalid and second one is Valid" do @auth.update_attribute(:status, "Invalid") - @ems.authentications << FactoryGirl.build(:authentication, :authtype => :some_type, :status => "Valid") + @ems.authentications << FactoryBot.build(:authentication, :authtype => :some_type, :status => "Valid") expect(@ems.authentication_status_ok?).to be_falsey end it "#authentication_status_ok? true if type is Valid" do @auth.update_attribute(:status, "Invalid") - @ems.authentications << FactoryGirl.build(:authentication, :authtype => :some_type, :status => "Valid") + @ems.authentications << FactoryBot.build(:authentication, :authtype => :some_type, :status => "Valid") expect(@ems.authentication_status_ok?(:some_type)).to be_truthy end it "#authentication_status_ok? false if type is Invalid" do @auth.update_attribute(:status, "Valid") - @ems.authentications << FactoryGirl.build(:authentication, :authtype => :some_type, :status => "Invalid") + @ems.authentications << FactoryBot.build(:authentication, :authtype => :some_type, :status => "Invalid") expect(@ems.authentication_status_ok?(:some_type)).to be_falsey end it "should return 'Invalid' authentication_status with one valid, one invalid" do highest = "Invalid" @auth.update_attribute(:status, "Valid") - @ems.authentications << FactoryGirl.create(:authentication, :status => highest) + @ems.authentications << FactoryBot.create(:authentication, :status => highest) expect(@ems.authentication_status).to eq(highest) end it "should return 'Invalid' authentication_status with one error, one invalid" do highest = "Invalid" @auth.update_attribute(:status, "Error") - @ems.authentications << FactoryGirl.create(:authentication, :status => highest) + @ems.authentications << FactoryBot.create(:authentication, :status => highest) expect(@ems.authentication_status).to eq(highest) end it "should return 'Invalid' authentication_status with one unreachable, one invalid" do highest = "Invalid" @auth.update_attribute(:status, "Unreachable") - @ems.authentications << FactoryGirl.create(:authentication, :status => highest) + @ems.authentications << FactoryBot.create(:authentication, :status => highest) expect(@ems.authentication_status).to eq(highest) end it "should return 'Invalid' authentication_status with one incomplete, one invalid" do highest = "Invalid" @auth.update_attribute(:status, "Incomplete") - @ems.authentications << FactoryGirl.create(:authentication, :status => highest) + @ems.authentications << FactoryBot.create(:authentication, :status => highest) expect(@ems.authentication_status).to eq(highest) end it "should return 'Error' authentication_status with one incomplete, one error" do highest = "Error" @auth.update_attribute(:status, "Incomplete") - @ems.authentications << FactoryGirl.create(:authentication, :status => highest) + @ems.authentications << FactoryBot.create(:authentication, :status => highest) expect(@ems.authentication_status).to eq(highest) end it "should return 'Error' authentication_status with one valid, one error" do highest = "Error" @auth.update_attribute(:status, "Valid") - @ems.authentications << FactoryGirl.create(:authentication, :status => highest) + @ems.authentications << FactoryBot.create(:authentication, :status => highest) expect(@ems.authentication_status).to eq(highest) end it "should return 'Valid' authentication_status with both valid" do highest = "Valid" @auth.update_attribute(:status, highest) - @ems.authentications << FactoryGirl.create(:authentication, :status => highest) + @ems.authentications << FactoryBot.create(:authentication, :status => highest) expect(@ems.authentication_status).to eq(highest) end it "should return 'Incomplete' authentication_status with one valid, one incomplete" do highest = "Incomplete" @auth.update_attribute(:status, "Valid") - @ems.authentications << FactoryGirl.create(:authentication, :status => highest) + @ems.authentications << FactoryBot.create(:authentication, :status => highest) expect(@ems.authentication_status).to eq(highest) end it "should return 'None' authentication_status with one nil, one nil" do highest = nil @auth.update_attribute(:status, nil) - @ems.authentications << FactoryGirl.create(:authentication, :status => highest) + @ems.authentications << FactoryBot.create(:authentication, :status => highest) expect(@ems.authentication_status).to eq('None') end diff --git a/spec/models/mixins/ci_feature_mixin_spec.rb b/spec/models/mixins/ci_feature_mixin_spec.rb index 30fe3d8a3fa..4a314a01dd9 100644 --- a/spec/models/mixins/ci_feature_mixin_spec.rb +++ b/spec/models/mixins/ci_feature_mixin_spec.rb @@ -1,29 +1,29 @@ describe CiFeatureMixin do - let(:service) { FactoryGirl.create(:service) } + let(:service) { FactoryBot.create(:service) } describe "#retireable?" do it "vm is retireable" do - FactoryGirl.create(:service_resource, :service => service, :resource => FactoryGirl.create(:vm)) + FactoryBot.create(:service_resource, :service => service, :resource => FactoryBot.create(:vm)) expect(service.service_resources.first.resource.retireable?).to eq(true) end it "orchestration stack is retireable" do - FactoryGirl.create(:service_resource, :service => service, :resource => FactoryGirl.create(:orchestration_stack_amazon)) + FactoryBot.create(:service_resource, :service => service, :resource => FactoryBot.create(:orchestration_stack_amazon)) expect(service.service_resources.first.resource.retireable?).to eq(true) end it "job not retireable" do - FactoryGirl.create(:service_resource, :service => service, :resource => FactoryGirl.create(:embedded_ansible_job)) + FactoryBot.create(:service_resource, :service => service, :resource => FactoryBot.create(:embedded_ansible_job)) expect(service.service_resources.first.resource.retireable?).to eq(false) end context "service" do context "with type" do - let(:service1) { FactoryGirl.create(:service_ansible_tower, :type => ServiceAnsibleTower) } + let(:service1) { FactoryBot.create(:service_ansible_tower, :type => ServiceAnsibleTower) } it "is retireable" do - FactoryGirl.create(:service_resource, :service => service, :resource => service1) + FactoryBot.create(:service_resource, :service => service, :resource => service1) expect(service.service_resources.first.resource.retireable?).to eq(true) end @@ -31,7 +31,7 @@ context "without type" do it "is not retireable" do - FactoryGirl.create(:service_resource, :service => service, :resource => FactoryGirl.create(:service)) + FactoryBot.create(:service_resource, :service => service, :resource => FactoryBot.create(:service)) expect(service.service_resources.first.resource.retireable?).to eq(false) end diff --git a/spec/models/mixins/cloud_tenancy_mixin_spec.rb b/spec/models/mixins/cloud_tenancy_mixin_spec.rb index 9026ffe411d..59af90b1c8a 100644 --- a/spec/models/mixins/cloud_tenancy_mixin_spec.rb +++ b/spec/models/mixins/cloud_tenancy_mixin_spec.rb @@ -9,10 +9,10 @@ end describe "miq_group" do - let(:user) { FactoryGirl.create(:user, :userid => 'user', :miq_groups => [tenant_group]) } - let(:tenant) { FactoryGirl.build(:tenant, :parent => default_tenant) } - let(:tenant_users) { FactoryGirl.create(:miq_user_role, :name => "tenant-users") } - let(:tenant_group) { FactoryGirl.create(:miq_group, :miq_user_role => tenant_users, :tenant => tenant) } + let(:user) { FactoryBot.create(:user, :userid => 'user', :miq_groups => [tenant_group]) } + let(:tenant) { FactoryBot.build(:tenant, :parent => default_tenant) } + let(:tenant_users) { FactoryBot.create(:miq_user_role, :name => "tenant-users") } + let(:tenant_group) { FactoryBot.create(:miq_group, :miq_user_role => tenant_users, :tenant => tenant) } it "finds correct tenant id clause for regular tenants" do expect(VmOrTemplate.tenant_id_clause(user)).to eql ["(vms.template = true AND vms.tenant_id IN (?)) OR (vms.template = false AND vms.tenant_id IN (?))", [default_tenant.id, tenant.id], [tenant.id]] diff --git a/spec/models/mixins/cockpit_support_mixin_spec.rb b/spec/models/mixins/cockpit_support_mixin_spec.rb index b129e44a940..96b9a67cb0a 100644 --- a/spec/models/mixins/cockpit_support_mixin_spec.rb +++ b/spec/models/mixins/cockpit_support_mixin_spec.rb @@ -2,7 +2,7 @@ context '#supports_launch_cockpit?' do context 'Container Groups' do before do - @container_group = FactoryGirl.create(:container_group) + @container_group = FactoryBot.create(:container_group) end it 'does not support it if the ready condition is not true' do @@ -30,7 +30,7 @@ context 'VMs' do before do - @vm = FactoryGirl.create(:vm) + @vm = FactoryBot.create(:vm) end it 'does not support it if there are no ipaddresses present' do @@ -60,7 +60,7 @@ context '#supports_cockpit_console?' do context 'Container Groups' do - let(:container_group) { FactoryGirl.create(:container_group) } + let(:container_group) { FactoryBot.create(:container_group) } before do @my_region = double @@ -83,7 +83,7 @@ context 'VMs' do before do @my_region = double - @vm = FactoryGirl.create(:vm) + @vm = FactoryBot.create(:vm) allow(MiqRegion).to receive(:my_region).and_return(@my_region) end diff --git a/spec/models/mixins/compliance_mixin_spec.rb b/spec/models/mixins/compliance_mixin_spec.rb index 1acc26a23b4..80704081230 100644 --- a/spec/models/mixins/compliance_mixin_spec.rb +++ b/spec/models/mixins/compliance_mixin_spec.rb @@ -1,11 +1,11 @@ describe ComplianceMixin do include Spec::Support::ArelHelper - let(:host) { FactoryGirl.create(:host) } + let(:host) { FactoryBot.create(:host) } let(:new_timestamp) { 2.months.ago.change(:usec => 0) } let(:old_timestamp) { 4.months.ago.change(:usec => 0) } - let(:new_compliance) { FactoryGirl.create(:compliance, :resource => host, :timestamp => new_timestamp, :compliant => false) } - let(:old_compliance) { FactoryGirl.create(:compliance, :resource => host, :timestamp => old_timestamp) } + let(:new_compliance) { FactoryBot.create(:compliance, :resource => host, :timestamp => new_timestamp, :compliant => false) } + let(:old_compliance) { FactoryBot.create(:compliance, :resource => host, :timestamp => old_timestamp) } let(:compliances) { [old_compliance, new_compliance] } describe "#last_compliance" do diff --git a/spec/models/mixins/configuration_management_mixin_spec.rb b/spec/models/mixins/configuration_management_mixin_spec.rb index 86cdcf3b945..173382cdcfe 100644 --- a/spec/models/mixins/configuration_management_mixin_spec.rb +++ b/spec/models/mixins/configuration_management_mixin_spec.rb @@ -1,8 +1,8 @@ describe ConfigurationManagementMixin do - let(:miq_server) { FactoryGirl.create(:miq_server, :zone => zone, :status => "started") } - let(:region) { FactoryGirl.create(:miq_region, :region => ApplicationRecord.my_region_number) } + let(:miq_server) { FactoryBot.create(:miq_server, :zone => zone, :status => "started") } + let(:region) { FactoryBot.create(:miq_region, :region => ApplicationRecord.my_region_number) } let(:settings) { {:some_test_setting => {:setting => {:deeper => 1}, :other => 2}} } - let(:zone) { FactoryGirl.create(:zone) } + let(:zone) { FactoryBot.create(:zone) } [:miq_server, :region, :zone].each do |i| context "On a #{i.capitalize}" do @@ -47,8 +47,8 @@ remote_region_number = ApplicationRecord.my_region_number + 1 external_region_id = ApplicationRecord.region_to_range(remote_region_number).first - FactoryGirl.create(:miq_server, :status => "started", :id => external_region_id) - FactoryGirl.create(:miq_server, :status => "stopped") + FactoryBot.create(:miq_server, :status => "started", :id => external_region_id) + FactoryBot.create(:miq_server, :status => "stopped") subject.reload_all_server_settings diff --git a/spec/models/mixins/custom_actions_mixin_spec.rb b/spec/models/mixins/custom_actions_mixin_spec.rb index 3c2e953d00f..2b9ea0f148b 100644 --- a/spec/models/mixins/custom_actions_mixin_spec.rb +++ b/spec/models/mixins/custom_actions_mixin_spec.rb @@ -8,9 +8,9 @@ def self.name; "TestClass"; end end describe '#custom_actions' do - let(:definition) { FactoryGirl.create(:generic_object_definition) } - let(:button) { FactoryGirl.create(:custom_button, :name => "generic_button", :applies_to_class => "GenericObject") } - let(:group) { FactoryGirl.create(:custom_button_set, :name => "generic_button_group") } + let(:definition) { FactoryBot.create(:generic_object_definition) } + let(:button) { FactoryBot.create(:custom_button, :name => "generic_button", :applies_to_class => "GenericObject") } + let(:group) { FactoryBot.create(:custom_button_set, :name => "generic_button_group") } before { group.add_member(button) } @@ -30,10 +30,10 @@ def self.name; "TestClass"; end end context 'with RBAC' do - let(:user) { FactoryGirl.create(:user_admin) } - let(:cloud_tenant) { FactoryGirl.create(:cloud_tenant) } - let!(:custom_button_event_1) { FactoryGirl.create(:custom_button_event, :target => cloud_tenant) } - let!(:custom_button_event_2) { FactoryGirl.create(:custom_button_event, :target => cloud_tenant) } + let(:user) { FactoryBot.create(:user_admin) } + let(:cloud_tenant) { FactoryBot.create(:cloud_tenant) } + let!(:custom_button_event_1) { FactoryBot.create(:custom_button_event, :target => cloud_tenant) } + let!(:custom_button_event_2) { FactoryBot.create(:custom_button_event, :target => cloud_tenant) } before do EvmSpecHelper.create_guid_miq_server_zone @@ -47,7 +47,7 @@ def self.name; "TestClass"; end end context "when user is non-super admin user" do - let(:user) { FactoryGirl.create(:user) } + let(:user) { FactoryBot.create(:user) } it "returns all custom button events" do User.with_user(user) do diff --git a/spec/models/mixins/custom_attribute_mixin_spec.rb b/spec/models/mixins/custom_attribute_mixin_spec.rb index 8cf75ecee30..d350559759d 100644 --- a/spec/models/mixins/custom_attribute_mixin_spec.rb +++ b/spec/models/mixins/custom_attribute_mixin_spec.rb @@ -29,13 +29,13 @@ def self.name; "TestClass"; end end describe '#custom_keys' do - let!(:custom_attribute) { FactoryGirl.create(:custom_attribute, :name => "attr_1", :value => 'value') } + let!(:custom_attribute) { FactoryBot.create(:custom_attribute, :name => "attr_1", :value => 'value') } let!(:custom_attribute_with_section) do - FactoryGirl.create(:custom_attribute, :name => "attr_2", :value => 'value', :section => 'labels') + FactoryBot.create(:custom_attribute, :name => "attr_2", :value => 'value', :section => 'labels') end let!(:vm) do - FactoryGirl.create(:vm_redhat, :custom_attributes => [custom_attribute, custom_attribute_with_section]) + FactoryBot.create(:vm_redhat, :custom_attributes => [custom_attribute, custom_attribute_with_section]) end it 'returns human form of virtual custom attribute with sections' do @@ -70,12 +70,12 @@ def self.name; "TestClass"; end it "#miq_custom_keys" do expect(test_class.new.miq_custom_keys).to eq([]) supported_factories.each do |factory_name| - object = FactoryGirl.create(factory_name) + object = FactoryBot.create(factory_name) expect(object.miq_custom_keys).to eq([]) key = "foo" - FactoryGirl.create(:miq_custom_attribute, + FactoryBot.create(:miq_custom_attribute, :resource_type => object.class.base_class.name, :resource_id => object.id, :name => key, @@ -84,7 +84,7 @@ def self.name; "TestClass"; end expect(object.reload.miq_custom_keys).to eq([key]) key2 = "foobar" - FactoryGirl.create(:miq_custom_attribute, + FactoryBot.create(:miq_custom_attribute, :resource_type => object.class.base_class.name, :resource_id => object.id, :name => key2, @@ -95,7 +95,7 @@ def self.name; "TestClass"; end it "#miq_custom_set" do supported_factories.each do |factory_name| - object = FactoryGirl.create(factory_name) + object = FactoryBot.create(factory_name) key = "foo" value = "bar" @@ -133,14 +133,14 @@ def self.name; "TestClass"; end it "#miq_custom_get" do supported_factories.each do |factory_name| - object = FactoryGirl.create(factory_name) + object = FactoryBot.create(factory_name) key = "foo" value = "bar" expect(object.miq_custom_get(key)).to be_nil - FactoryGirl.create(:miq_custom_attribute, + FactoryBot.create(:miq_custom_attribute, :resource_type => object.class.base_class.name, :resource_id => object.id, :name => key, diff --git a/spec/models/mixins/drift_state_mixin_spec.rb b/spec/models/mixins/drift_state_mixin_spec.rb index 81f845c4b1e..3594807f30b 100644 --- a/spec/models/mixins/drift_state_mixin_spec.rb +++ b/spec/models/mixins/drift_state_mixin_spec.rb @@ -1,12 +1,12 @@ describe DriftStateMixin do include Spec::Support::ArelHelper - let(:host) { FactoryGirl.create(:host) } + let(:host) { FactoryBot.create(:host) } let(:drift_states) do [ - FactoryGirl.create(:drift_state, :resource => host, :timestamp => recent_timestamp, :data => "bogus"), - FactoryGirl.create(:drift_state, :resource => host, :timestamp => old_timestamp, :data => "bogus") + FactoryBot.create(:drift_state, :resource => host, :timestamp => recent_timestamp, :data => "bogus"), + FactoryBot.create(:drift_state, :resource => host, :timestamp => old_timestamp, :data => "bogus") ] end diff --git a/spec/models/mixins/event_mixin_spec.rb b/spec/models/mixins/event_mixin_spec.rb index 0caaa8b7311..0f81d18ff7f 100644 --- a/spec/models/mixins/event_mixin_spec.rb +++ b/spec/models/mixins/event_mixin_spec.rb @@ -13,11 +13,11 @@ def event_where_clause(assoc) before do @ts_1 = 5.days.ago - FactoryGirl.create(:ems_event, :ems_id => 1, :timestamp => @ts_1) + FactoryBot.create(:ems_event, :ems_id => 1, :timestamp => @ts_1) @ts_2 = 4.days.ago - FactoryGirl.create(:ems_event, :ems_id => 1, :timestamp => @ts_2) + FactoryBot.create(:ems_event, :ems_id => 1, :timestamp => @ts_2) @ts_3 = 3.days.ago - FactoryGirl.create(:ems_event, :ems_id => 1, :timestamp => @ts_3) + FactoryBot.create(:ems_event, :ems_id => 1, :timestamp => @ts_3) end it "#first_event" do diff --git a/spec/models/mixins/inter_region_api_method_relay_spec.rb b/spec/models/mixins/inter_region_api_method_relay_spec.rb index 057cf499f17..8da35898da2 100644 --- a/spec/models/mixins/inter_region_api_method_relay_spec.rb +++ b/spec/models/mixins/inter_region_api_method_relay_spec.rb @@ -164,7 +164,7 @@ def expect_api_call(expected_action, expected_args = nil) describe ".api_client_connection_for_region" do let!(:server) { EvmSpecHelper.local_miq_server(:has_active_webservices => true) } - let!(:region) { FactoryGirl.create(:miq_region, :region => region_number) } + let!(:region) { FactoryBot.create(:miq_region, :region => region_number) } let(:region_number) { ApplicationRecord.my_region_number } let(:request_user) { "test_user" } let(:api_connection) { double("ManageIQ::API::Client connection") } diff --git a/spec/models/mixins/miq_provision_mixin_spec.rb b/spec/models/mixins/miq_provision_mixin_spec.rb index 37ac91b4eec..83ac525b32d 100644 --- a/spec/models/mixins/miq_provision_mixin_spec.rb +++ b/spec/models/mixins/miq_provision_mixin_spec.rb @@ -1,8 +1,8 @@ describe MiqProvisionMixin do describe "#get_owner" do - let(:owner) { FactoryGirl.create(:user_with_email) } + let(:owner) { FactoryBot.create(:user_with_email) } let(:options) { {:owner_email => owner.email} } - let(:requester) { FactoryGirl.create(:user_with_email) } + let(:requester) { FactoryBot.create(:user_with_email) } subject do Class.new do include MiqProvisionMixin @@ -53,9 +53,9 @@ def get_option(name) owner.update_attributes(:current_group => my_group, :miq_groups => [my_group, my_alt_group]) end - let(:my_group) { FactoryGirl.create(:miq_group) } - let(:my_alt_group) { FactoryGirl.create(:miq_group, :description => 'yay') } - let(:bad_group) { FactoryGirl.create(:miq_group, :description => 'boo') } + let(:my_group) { FactoryBot.create(:miq_group) } + let(:my_alt_group) { FactoryBot.create(:miq_group, :description => 'yay') } + let(:bad_group) { FactoryBot.create(:miq_group, :description => 'boo') } it "keeps current_group" do expect(subject.get_owner.current_group).to eq(my_group) diff --git a/spec/models/mixins/miq_request_mixin.rb b/spec/models/mixins/miq_request_mixin.rb index e63ace579f7..35e894f49de 100644 --- a/spec/models/mixins/miq_request_mixin.rb +++ b/spec/models/mixins/miq_request_mixin.rb @@ -13,8 +13,8 @@ def initialize let(:test_instance) { test_class.new } it "#get_user only searches users in the current region" do - user = FactoryGirl.create(:user, :userid => "TestUser") - FactoryGirl.create(:user, :userid => "TestUser", :id => ApplicationRecord.id_in_region(1, ApplicationRecord.my_region_number + 1)) + user = FactoryBot.create(:user, :userid => "TestUser") + FactoryBot.create(:user, :userid => "TestUser", :id => ApplicationRecord.id_in_region(1, ApplicationRecord.my_region_number + 1)) test_instance.userid = "TestUser" expect(test_instance.get_user).to eq(user) diff --git a/spec/models/mixins/miq_web_server_worker_mixin_spec.rb b/spec/models/mixins/miq_web_server_worker_mixin_spec.rb index 0b22bde727a..da547e008a4 100644 --- a/spec/models/mixins/miq_web_server_worker_mixin_spec.rb +++ b/spec/models/mixins/miq_web_server_worker_mixin_spec.rb @@ -50,7 +50,7 @@ end it "#rails_server_options" do - w = FactoryGirl.create(:miq_ui_worker, :uri => "http://127.0.0.1:3000") + w = FactoryBot.create(:miq_ui_worker, :uri => "http://127.0.0.1:3000") expect(w.rails_server_options).to include( :Port => 3000, :Host => w.class.binding_address, @@ -72,8 +72,8 @@ def self.binding_address end describe '#rails_application' do - let(:websocket_worker) { FactoryGirl.create(:miq_websocket_worker, :uri => 'http://127.0.0.1:3000') } - let(:ui_worker) { FactoryGirl.create(:miq_ui_worker, :uri => 'http://127.0.0.1:3000') } + let(:websocket_worker) { FactoryBot.create(:miq_websocket_worker, :uri => 'http://127.0.0.1:3000') } + let(:ui_worker) { FactoryBot.create(:miq_ui_worker, :uri => 'http://127.0.0.1:3000') } it 'provides access to the Rack/Rails application' do expect(websocket_worker.rails_application).to be_a_kind_of(WebsocketServer) diff --git a/spec/models/mixins/per_ems_worker_mixin_spec.rb b/spec/models/mixins/per_ems_worker_mixin_spec.rb index 7a30005489d..14bc75a886b 100644 --- a/spec/models/mixins/per_ems_worker_mixin_spec.rb +++ b/spec/models/mixins/per_ems_worker_mixin_spec.rb @@ -1,11 +1,11 @@ describe PerEmsWorkerMixin do before do _guid, server, zone = EvmSpecHelper.create_guid_miq_server_zone - @ems = FactoryGirl.create(:ems_vmware_with_authentication, :zone => zone) + @ems = FactoryBot.create(:ems_vmware_with_authentication, :zone => zone) @ems_queue_name = "ems_#{@ems.id}" # General stubbing for testing any worker (methods called during initialize) - @worker_record = FactoryGirl.create(:miq_ems_refresh_core_worker, :queue_name => "ems_#{@ems.id}", :miq_server => server) + @worker_record = FactoryBot.create(:miq_ems_refresh_core_worker, :queue_name => "ems_#{@ems.id}", :miq_server => server) @worker_class = @worker_record.class end diff --git a/spec/models/mixins/process_tasks_mixin_spec.rb b/spec/models/mixins/process_tasks_mixin_spec.rb index 447da7f921f..cdac520fa4d 100644 --- a/spec/models/mixins/process_tasks_mixin_spec.rb +++ b/spec/models/mixins/process_tasks_mixin_spec.rb @@ -77,7 +77,7 @@ def test_method end before do - FactoryGirl.create(:miq_region, :region => ApplicationRecord.my_region_number) + FactoryBot.create(:miq_region, :region => ApplicationRecord.my_region_number) end context "when the server has an ip address" do diff --git a/spec/models/mixins/purging_mixin_spec.rb b/spec/models/mixins/purging_mixin_spec.rb index 9a6efae4734..585db9134c6 100644 --- a/spec/models/mixins/purging_mixin_spec.rb +++ b/spec/models/mixins/purging_mixin_spec.rb @@ -20,7 +20,7 @@ describe ".purge" do let(:events) do (-2..2).collect do |date_modifier| - FactoryGirl.create(:policy_event, :timestamp => purge_date + date_modifier.days) + FactoryBot.create(:policy_event, :timestamp => purge_date + date_modifier.days) end end let(:all_ids) { events.collect(&:id) } diff --git a/spec/models/mixins/relationship_mixin_spec.rb b/spec/models/mixins/relationship_mixin_spec.rb index f12bc60400c..f0d930a2ae8 100644 --- a/spec/models/mixins/relationship_mixin_spec.rb +++ b/spec/models/mixins/relationship_mixin_spec.rb @@ -7,7 +7,7 @@ let(:vms_rel_tree) { {0 => [{1 => [3, 4]}, {2 => [5, 6, {7 => [8, 9]}]}]} } let(:vms) { build_relationship_tree(vms_rel_tree) } # host with no tree - let(:host) { FactoryGirl.create(:host) } + let(:host) { FactoryBot.create(:host) } describe "#remove_children" do it "handles [nil]" do @@ -58,10 +58,10 @@ # than one associated tree node. context "#set_child on a new parent object" do - before { @parent = FactoryGirl.create(:vm_vmware) } + before { @parent = FactoryBot.create(:vm_vmware) } it "with a second new object will link a new tree node for the parent to a new tree node for the child" do - child = FactoryGirl.create(:vm_vmware) + child = FactoryBot.create(:vm_vmware) @parent.with_relationship_type(test_rel_type) { |v| v.set_child(child) } assert_parent_child_structure(test_rel_type, @@ -102,10 +102,10 @@ end context "#set_parent on a new child object" do - before { @child = FactoryGirl.create(:vm_vmware) } + before { @child = FactoryBot.create(:vm_vmware) } it "with a second new object will link a new tree node for the parent to a new tree node for the child" do - parent = FactoryGirl.create(:vm_vmware) + parent = FactoryBot.create(:vm_vmware) @child.with_relationship_type(test_rel_type) { |v| v.set_parent(parent) } assert_parent_child_structure(test_rel_type, @@ -146,10 +146,10 @@ end context "with a new parent object, #replace_parent" do - before { @parent = FactoryGirl.create(:vm_vmware) } + before { @parent = FactoryBot.create(:vm_vmware) } it "on a second new object will link a new tree node for the parent to a new tree node for the child and be the only parent for the child" do - child = FactoryGirl.create(:vm_vmware) + child = FactoryBot.create(:vm_vmware) child.with_relationship_type(test_rel_type) { |v| v.replace_parent(@parent) } assert_parent_child_structure(test_rel_type, @@ -203,9 +203,9 @@ end describe "#add_parent" do - let(:folder1) { FactoryGirl.create(:ems_folder) } - let(:folder2) { FactoryGirl.create(:ems_folder) } - let(:vm) { FactoryGirl.create(:vm) } + let(:folder1) { FactoryBot.create(:ems_folder) } + let(:folder2) { FactoryBot.create(:ems_folder) } + let(:vm) { FactoryBot.create(:vm) } it "puts an object under another object" do vm.with_relationship_type(test_rel_type) do @@ -233,8 +233,8 @@ end describe "#parent=" do - let(:folder) { FactoryGirl.create(:ems_folder) } - let(:vm) { FactoryGirl.create(:vm) } + let(:folder) { FactoryBot.create(:ems_folder) } + let(:vm) { FactoryBot.create(:vm) } it "puts an object under another object" do vm.with_relationship_type(test_rel_type) do @@ -246,7 +246,7 @@ end it "moves an object that already has a parent under an another object" do - vm.with_relationship_type(test_rel_type) { vm.parent = FactoryGirl.create(:ems_folder) } + vm.with_relationship_type(test_rel_type) { vm.parent = FactoryBot.create(:ems_folder) } vm.reload vm.with_relationship_type(test_rel_type) do @@ -259,7 +259,7 @@ end it "#replace_children" do - new_vms = (0...2).collect { FactoryGirl.create(:vm_vmware) } + new_vms = (0...2).collect { FactoryBot.create(:vm_vmware) } vms[0].with_relationship_type(test_rel_type) do |v| v.replace_children(new_vms) expect(new_vms).to match_array(v.children) @@ -326,9 +326,9 @@ context ".alias_with_relationship_type" do before do - @ws = FactoryGirl.create(:miq_widget_set) - @w1 = FactoryGirl.create(:miq_widget) - @w2 = FactoryGirl.create(:miq_widget) + @ws = FactoryBot.create(:miq_widget_set) + @w1 = FactoryBot.create(:miq_widget) + @w2 = FactoryBot.create(:miq_widget) @ws.add_member(@w1) @ws.add_member(@w2) end @@ -864,8 +864,8 @@ def build_relationship_tree(tree, rel_type = test_rel_type, base_factory = :vm_v # allows easy access while building # can map to the resource to return all the resources created rels = Hash.new do |hash, key| - hash[key] = FactoryGirl.create(:relationship, - :resource => FactoryGirl.create(base_factory), + hash[key] = FactoryBot.create(:relationship, + :resource => FactoryBot.create(base_factory), :relationship => rel_type) end diff --git a/spec/models/mixins/tenancy_mixin_spec.rb b/spec/models/mixins/tenancy_mixin_spec.rb index 250a5520907..d2022575483 100644 --- a/spec/models/mixins/tenancy_mixin_spec.rb +++ b/spec/models/mixins/tenancy_mixin_spec.rb @@ -9,13 +9,13 @@ end describe "miq_group" do - let(:user) { FactoryGirl.create(:user, :userid => 'user', :miq_groups => [tenant_group]) } - let(:tenant) { FactoryGirl.build(:tenant, :parent => default_tenant) } - let(:tenant_users) { FactoryGirl.create(:miq_user_role, :name => "tenant-users") } - let(:tenant_group) { FactoryGirl.create(:miq_group, :miq_user_role => tenant_users, :tenant => tenant) } + let(:user) { FactoryBot.create(:user, :userid => 'user', :miq_groups => [tenant_group]) } + let(:tenant) { FactoryBot.build(:tenant, :parent => default_tenant) } + let(:tenant_users) { FactoryBot.create(:miq_user_role, :name => "tenant-users") } + let(:tenant_group) { FactoryBot.create(:miq_group, :miq_user_role => tenant_users, :tenant => tenant) } it "assigns owning group tenant" do - vm = FactoryGirl.create(:vm_vmware, :miq_group => tenant_group) + vm = FactoryBot.create(:vm_vmware, :miq_group => tenant_group) expect(vm.miq_group).to eql tenant_group expect(vm.tenant).to eql tenant @@ -23,7 +23,7 @@ it "assigns current user tenant" do User.current_user = user - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) expect(vm.miq_group).to eql tenant_group expect(vm.tenant).to eql tenant @@ -31,8 +31,8 @@ it "assigns parent EMS tenant" do tenant.save - ems = FactoryGirl.create(:ems_vmware, :name => 'ems', :tenant => tenant) - vm = FactoryGirl.create(:vm_vmware, :ext_management_system => ems) + ems = FactoryBot.create(:ems_vmware, :name => 'ems', :tenant => tenant) + vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems) expect(vm.miq_group).to eql tenant.default_miq_group expect(vm.tenant).to eql tenant @@ -40,7 +40,7 @@ it "assigns root tenant" do root_tenant - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) expect(vm.miq_group).to eql root_tenant.default_miq_group expect(vm.tenant).to eql root_tenant @@ -50,27 +50,27 @@ root_tenant tenant.save - vm = FactoryGirl.create(:vm_vmware, :tenant => tenant) + vm = FactoryBot.create(:vm_vmware, :tenant => tenant) expect(vm.tenant).to eq(tenant) expect(vm.miq_group).to eq(tenant.default_miq_group) end end describe "assigning tenants without a miq_group" do - let(:tenant) { FactoryGirl.build(:tenant, :parent => default_tenant) } - let(:tenant_users) { FactoryGirl.create(:miq_user_role, :name => "tenant-users") } - let(:tenant_group) { FactoryGirl.create(:miq_group, :miq_user_role => tenant_users, :tenant => tenant) } + let(:tenant) { FactoryBot.build(:tenant, :parent => default_tenant) } + let(:tenant_users) { FactoryBot.create(:miq_user_role, :name => "tenant-users") } + let(:tenant_group) { FactoryBot.create(:miq_group, :miq_user_role => tenant_users, :tenant => tenant) } it "assigns current user tenant" do - User.current_user = FactoryGirl.create(:user, :userid => 'user', :miq_groups => [tenant_group]) - ems = FactoryGirl.create(:ext_management_system) + User.current_user = FactoryBot.create(:user, :userid => 'user', :miq_groups => [tenant_group]) + ems = FactoryBot.create(:ext_management_system) expect(ems.tenant).to eql tenant end it "assigns root tenant" do root_tenant - ems = FactoryGirl.create(:ext_management_system) + ems = FactoryBot.create(:ext_management_system) expect(ems.tenant).to eql root_tenant end diff --git a/spec/models/mixins/tenant_identity_mixin_spec.rb b/spec/models/mixins/tenant_identity_mixin_spec.rb index 4ce69b31fec..5ddf69b80de 100644 --- a/spec/models/mixins/tenant_identity_mixin_spec.rb +++ b/spec/models/mixins/tenant_identity_mixin_spec.rb @@ -1,15 +1,15 @@ describe TenantIdentityMixin do describe '#tenant_identity' do - let(:admin) { FactoryGirl.create(:user_with_group, :userid => "admin") } - let(:tenant) { FactoryGirl.create(:tenant) } - let(:ems) { FactoryGirl.create(:ext_management_system, :tenant => tenant) } + let(:admin) { FactoryBot.create(:user_with_group, :userid => "admin") } + let(:tenant) { FactoryBot.create(:tenant) } + let(:ems) { FactoryBot.create(:ext_management_system, :tenant => tenant) } let(:test_class) { :container_group } subject { @test_instance.tenant_identity } before { admin } it "has tenant from provider" do - @test_instance = FactoryGirl.create(test_class, :ext_management_system => ems) + @test_instance = FactoryBot.create(test_class, :ext_management_system => ems) expect(subject).to eq(admin) expect(subject.current_group).to eq(ems.tenant.default_miq_group) @@ -17,7 +17,7 @@ end it "without a provider, has tenant from root tenant" do - @test_instance = FactoryGirl.create(test_class) + @test_instance = FactoryBot.create(test_class) expect(subject).to eq(admin) expect(subject.current_group).to eq(Tenant.root_tenant.default_miq_group) diff --git a/spec/models/mixins/tenant_quotas_mixin_spec.rb b/spec/models/mixins/tenant_quotas_mixin_spec.rb index 22426518c49..424123a0c48 100644 --- a/spec/models/mixins/tenant_quotas_mixin_spec.rb +++ b/spec/models/mixins/tenant_quotas_mixin_spec.rb @@ -7,18 +7,18 @@ Tenant.root_tenant end - let(:super_admin_role) { FactoryGirl.create(:miq_user_role, :features => MiqProductFeature::SUPER_ADMIN_FEATURE) } - let(:tenant_admin_role) { FactoryGirl.create(:miq_user_role, :features => MiqProductFeature::TENANT_ADMIN_FEATURE) } + let(:super_admin_role) { FactoryBot.create(:miq_user_role, :features => MiqProductFeature::SUPER_ADMIN_FEATURE) } + let(:tenant_admin_role) { FactoryBot.create(:miq_user_role, :features => MiqProductFeature::TENANT_ADMIN_FEATURE) } - let(:tenant_1) { FactoryGirl.create(:tenant, :parent => root_tenant) } - let(:tenant_1_1) { FactoryGirl.create(:tenant, :parent => tenant_1) } - let(:tenant_1_2) { FactoryGirl.create(:tenant, :parent => tenant_1, :divisible => false) } + let(:tenant_1) { FactoryBot.create(:tenant, :parent => root_tenant) } + let(:tenant_1_1) { FactoryBot.create(:tenant, :parent => tenant_1) } + let(:tenant_1_2) { FactoryBot.create(:tenant, :parent => tenant_1, :divisible => false) } - let(:group_tenant_1_tenant_admin) { FactoryGirl.create(:miq_group, :miq_user_role => tenant_admin_role, :tenant => tenant_1) } - let(:user_tenant_1_tenant_admin) { FactoryGirl.create(:user, :miq_groups => [group_tenant_1_tenant_admin]) } + let(:group_tenant_1_tenant_admin) { FactoryBot.create(:miq_group, :miq_user_role => tenant_admin_role, :tenant => tenant_1) } + let(:user_tenant_1_tenant_admin) { FactoryBot.create(:user, :miq_groups => [group_tenant_1_tenant_admin]) } - let(:group_tenant_1_super_admin) { FactoryGirl.create(:miq_group, :miq_user_role => super_admin_role, :tenant => tenant_1) } - let(:user_tenant_1_super_admin) { FactoryGirl.create(:user, :miq_groups => [group_tenant_1_super_admin]) } + let(:group_tenant_1_super_admin) { FactoryBot.create(:miq_group, :miq_user_role => super_admin_role, :tenant => tenant_1) } + let(:user_tenant_1_super_admin) { FactoryBot.create(:user, :miq_groups => [group_tenant_1_super_admin]) } describe "#tenant_quotas_allowed?" do it "allows managing on all tenant quotas when user is super admin" do diff --git a/spec/models/mixins/timezone_mixin_spec.rb b/spec/models/mixins/timezone_mixin_spec.rb index 2979dcb8ef1..c2d3c5e6349 100644 --- a/spec/models/mixins/timezone_mixin_spec.rb +++ b/spec/models/mixins/timezone_mixin_spec.rb @@ -30,7 +30,7 @@ context "with a user" do let!(:user) do - User.current_user = FactoryGirl.create(:user) + User.current_user = FactoryBot.create(:user) end it "#with_current_user_timezone in GMT" do diff --git a/spec/models/mixins/yaml_import_export_mixin_spec.rb b/spec/models/mixins/yaml_import_export_mixin_spec.rb index d6d110b8a38..8e8020ff096 100644 --- a/spec/models/mixins/yaml_import_export_mixin_spec.rb +++ b/spec/models/mixins/yaml_import_export_mixin_spec.rb @@ -2,7 +2,7 @@ let(:test_class) { Class.new { include YAMLImportExportMixin } } before do - @report1 = FactoryGirl.create(:miq_report, :name => "test_report_1") + @report1 = FactoryBot.create(:miq_report, :name => "test_report_1") end context ".export_to_array" do @@ -20,7 +20,7 @@ end it "single valid instance" do - policy = FactoryGirl.create(:miq_policy, :name => "test_policy") + policy = FactoryBot.create(:miq_policy, :name => "test_policy") @list = [@report1.id, policy.id] expect_any_instance_of(MiqPolicy).to receive(:export_to_array).never @@ -29,7 +29,7 @@ end it "multiple valid instances" do - @report2 = FactoryGirl.create(:miq_report, :name => "test_report_2") + @report2 = FactoryBot.create(:miq_report, :name => "test_report_2") @list = [@report1.id, @report2.id] expect(subject.size).to eq(2) diff --git a/spec/models/notification/purging_spec.rb b/spec/models/notification/purging_spec.rb index de0a01ca149..675f4371216 100644 --- a/spec/models/notification/purging_spec.rb +++ b/spec/models/notification/purging_spec.rb @@ -2,21 +2,21 @@ context "::Purging" do describe ".purge_by_date" do it "purges old notifications" do - FactoryGirl.create(:user) - FactoryGirl.create(:user) - type = FactoryGirl.create(:notification_type, :audience => NotificationType::AUDIENCE_GLOBAL) + FactoryBot.create(:user) + FactoryBot.create(:user) + type = FactoryBot.create(:notification_type, :audience => NotificationType::AUDIENCE_GLOBAL) # Notification and recipients that will not be purged - new_notification = FactoryGirl.create(:notification, :notification_type => type) + new_notification = FactoryBot.create(:notification, :notification_type => type) old_notification, semi_old_notification = nil Timecop.freeze(6.days.ago) do - semi_old_notification = FactoryGirl.create(:notification, :notification_type => type) + semi_old_notification = FactoryBot.create(:notification, :notification_type => type) end Timecop.freeze(8.days.ago) do # Notification and recipients that will be purged - old_notification = FactoryGirl.create(:notification, :notification_type => type) + old_notification = FactoryBot.create(:notification, :notification_type => type) end expect(described_class.all).to match_array([new_notification, semi_old_notification, old_notification]) diff --git a/spec/models/notification_spec.rb b/spec/models/notification_spec.rb index 5054e3bbb77..a0b3876aaca 100644 --- a/spec/models/notification_spec.rb +++ b/spec/models/notification_spec.rb @@ -1,8 +1,8 @@ describe Notification, :type => :model do before { allow(User).to receive_messages(:server_timezone => 'UTC') } before { NotificationType.seed } - let(:tenant) { FactoryGirl.create(:tenant) } - let!(:user) { FactoryGirl.create(:user_with_group, :tenant => tenant) } + let(:tenant) { FactoryBot.create(:tenant) } + let!(:user) { FactoryBot.create(:user_with_group, :tenant => tenant) } describe '.of_type' do it "only returns notification of the given type" do @@ -23,7 +23,7 @@ describe '.emit' do context 'successful' do - let(:vm) { FactoryGirl.create(:vm, :tenant => tenant) } + let(:vm) { FactoryBot.create(:vm, :tenant => tenant) } let(:notification_type) { :vm_retired } subject { Notification.create(:type => notification_type, :subject => vm) } @@ -37,7 +37,7 @@ end it 'creates single record in notification_recipients table if recipent user belongs to several groups' do - user.miq_groups << FactoryGirl.create(:miq_group, :tenant => tenant) + user.miq_groups << FactoryBot.create(:miq_group, :tenant => tenant) expect(subject.recipients).to match_array([user]) end @@ -63,11 +63,11 @@ end context 'tenant includes user without access to the subject (vm)' do - let(:limiting_role) { FactoryGirl.create(:miq_user_role, :settings => {:restrictions=>{:vms=>:user}}) } + let(:limiting_role) { FactoryBot.create(:miq_user_role, :settings => {:restrictions=>{:vms=>:user}}) } let(:limited_group) do - FactoryGirl.create(:miq_group, :tenant_type, :tenant => tenant, :miq_user_role => limiting_role) + FactoryBot.create(:miq_group, :tenant_type, :tenant => tenant, :miq_user_role => limiting_role) end - let!(:limited_user) { FactoryGirl.create(:user, :miq_groups => [limited_group]) } + let!(:limited_user) { FactoryBot.create(:user, :miq_groups => [limited_group]) } it 'emits notifications only to those users, who are authorized to see the subject' do expect(subject.recipients).to match_array([user]) @@ -75,13 +75,13 @@ end context 'emiting for MiqRequest' do - let(:friends) { FactoryGirl.create(:miq_group) } - let(:requester) { FactoryGirl.create(:user, :miq_groups => [friends]) } - let!(:peer) { FactoryGirl.create(:user, :miq_groups => [friends]) } - let!(:non_peer) { FactoryGirl.create(:user) } - let(:vm) { FactoryGirl.create(:vm_vmware, :name => 'vm', :location => 'abc/def.vmx') } + let(:friends) { FactoryBot.create(:miq_group) } + let(:requester) { FactoryBot.create(:user, :miq_groups => [friends]) } + let!(:peer) { FactoryBot.create(:user, :miq_groups => [friends]) } + let!(:non_peer) { FactoryBot.create(:user) } + let(:vm) { FactoryBot.create(:vm_vmware, :name => 'vm', :location => 'abc/def.vmx') } let(:request) do - FactoryGirl.create(:miq_provision_request, :requester => requester, :src_vm_id => vm.id, + FactoryBot.create(:miq_provision_request, :requester => requester, :src_vm_id => vm.id, :options => {:owner_email => 'tester@miq.com'}) end subject { Notification.create(:subject => request, :type => 'request_approved') } @@ -92,8 +92,8 @@ end context 'subject does not have tenant' do - let!(:peer) { FactoryGirl.create(:user_with_group, :tenant => tenant) } - let!(:non_peer) { FactoryGirl.create(:user) } + let!(:peer) { FactoryBot.create(:user_with_group, :tenant => tenant) } + let!(:non_peer) { FactoryBot.create(:user) } subject { Notification.create(:initiator => user, :type => 'automate_tenant_info') } @@ -105,7 +105,7 @@ end describe '#to_h' do - let(:notification) { FactoryGirl.create(:notification, :initiator => user, :options => {:extra => 'information'}) } + let(:notification) { FactoryBot.create(:notification, :initiator => user, :options => {:extra => 'information'}) } it 'contains information consumable by UI' do expect(notification.to_h).to include( :level => notification.notification_type.level, @@ -119,8 +119,8 @@ context 'link_to is set' do let(:notification) do - FactoryGirl.create(:notification, :initiator => user, - :notification_type => FactoryGirl.create(:notification_type, :link_to => 'initiator')) + FactoryBot.create(:notification, :initiator => user, + :notification_type => FactoryBot.create(:notification_type, :link_to => 'initiator')) end it 'contains the link to the initiator' do @@ -129,7 +129,7 @@ end context "subject text" do - let(:vm) { FactoryGirl.create(:vm, :tenant => tenant) } + let(:vm) { FactoryBot.create(:vm, :tenant => tenant) } subject { Notification.create(:type => :vm_snapshot_failure, :subject => vm, :options => {:error => "oops", :snapshot_op => "create"}) } it "stuffs subject into options hash in case the subject is destroyed" do @@ -168,7 +168,7 @@ end describe "#seen_by_all_recipients?" do - let(:notification) { FactoryGirl.create(:notification, :initiator => user) } + let(:notification) { FactoryBot.create(:notification, :initiator => user) } it "is false if a user has not seen the notification" do expect(notification.seen_by_all_recipients?).to be_falsey diff --git a/spec/models/notification_type_spec.rb b/spec/models/notification_type_spec.rb index bb084d69151..e9ef9a59c31 100644 --- a/spec/models/notification_type_spec.rb +++ b/spec/models/notification_type_spec.rb @@ -14,32 +14,32 @@ end describe '#subscribers_ids' do - let(:user1) { FactoryGirl.create(:user) } - let(:tenant2) { FactoryGirl.create(:tenant) } - let!(:user2) { FactoryGirl.create(:user_with_group, :tenant => tenant2) } - let(:vm) { FactoryGirl.create(:vm, :tenant => tenant2) } + let(:user1) { FactoryBot.create(:user) } + let(:tenant2) { FactoryBot.create(:tenant) } + let!(:user2) { FactoryBot.create(:user_with_group, :tenant => tenant2) } + let(:vm) { FactoryBot.create(:vm, :tenant => tenant2) } subject { notification.subscriber_ids(vm, user1) } context 'global notification type' do - let(:notification) { FactoryGirl.create(:notification_type, :audience => 'global') } + let(:notification) { FactoryBot.create(:notification_type, :audience => 'global') } it 'returns all the users' do is_expected.to match_array(User.pluck(:id)) end end context 'user specific notification type' do - let(:notification) { FactoryGirl.create(:notification_type, :audience => 'user') } + let(:notification) { FactoryBot.create(:notification_type, :audience => 'user') } it 'returns just the user, who initiated the task' do is_expected.to match_array([user1.id]) end end context 'tenant specific notification type' do - let(:notification) { FactoryGirl.create(:notification_type, :audience => 'tenant') } + let(:notification) { FactoryBot.create(:notification_type, :audience => 'tenant') } it 'returns the users in the tenant same tenant as concerned vm' do is_expected.to match_array([user2.id]) end it "returns single id if user belongs to different group" do - user2.miq_groups << FactoryGirl.create(:miq_group, :tenant => tenant2) + user2.miq_groups << FactoryBot.create(:miq_group, :tenant => tenant2) is_expected.to match_array([user2.id]) end end @@ -47,9 +47,9 @@ describe "#enabled?" do it "detects properly" do - expect(FactoryGirl.build(:notification_type, :audience => NotificationType::AUDIENCE_USER)).to be_enabled - expect(FactoryGirl.build(:notification_type, :audience => NotificationType::AUDIENCE_NONE)).not_to be_enabled - expect(FactoryGirl.build(:notification_type, :audience => NotificationType::AUDIENCE_NONE)).to be_valid + expect(FactoryBot.build(:notification_type, :audience => NotificationType::AUDIENCE_USER)).to be_enabled + expect(FactoryBot.build(:notification_type, :audience => NotificationType::AUDIENCE_NONE)).not_to be_enabled + expect(FactoryBot.build(:notification_type, :audience => NotificationType::AUDIENCE_NONE)).to be_valid end end end diff --git a/spec/models/orchestration_stack/retirement_management_spec.rb b/spec/models/orchestration_stack/retirement_management_spec.rb index e1b0d263a6b..54f0d7b8c3e 100644 --- a/spec/models/orchestration_stack/retirement_management_spec.rb +++ b/spec/models/orchestration_stack/retirement_management_spec.rb @@ -1,11 +1,11 @@ describe "Service Retirement Management" do - let!(:user) { FactoryGirl.create(:user_miq_request_approver, :userid => "admin") } + let!(:user) { FactoryBot.create(:user_miq_request_approver, :userid => "admin") } context "with zone/ems" do before do @miq_server = EvmSpecHelper.local_miq_server @zone = @miq_server.zone - ems = FactoryGirl.create(:ext_management_system, :zone => @zone) - @stack = FactoryGirl.create(:orchestration_stack, :ext_management_system => ems) + ems = FactoryBot.create(:ext_management_system, :zone => @zone) + @stack = FactoryBot.create(:orchestration_stack, :ext_management_system => ems) end it "#retirement_check" do @@ -148,7 +148,7 @@ context "without zone/ems" do it "#raise_retirement_event" do - stack_without_zone = FactoryGirl.create(:orchestration_stack, :ext_management_system => nil) + stack_without_zone = FactoryBot.create(:orchestration_stack, :ext_management_system => nil) event_name = 'foo' event_hash = { :userid => nil, diff --git a/spec/models/orchestration_stack_retire_task_spec.rb b/spec/models/orchestration_stack_retire_task_spec.rb index 5a434a7e850..5393b05c162 100644 --- a/spec/models/orchestration_stack_retire_task_spec.rb +++ b/spec/models/orchestration_stack_retire_task_spec.rb @@ -1,9 +1,9 @@ describe OrchestrationStackRetireTask do - let(:user) { FactoryGirl.create(:user_with_group) } - let(:orchestration_stack) { FactoryGirl.create(:orchestration_stack) } - let(:miq_request) { FactoryGirl.create(:orchestration_stack_retire_request, :requester => user) } - let(:orchestration_stack_retire_task) { FactoryGirl.create(:orchestration_stack_retire_task, :source => orchestration_stack, :miq_request => miq_request, :options => {:src_ids => [orchestration_stack.id] }) } - let(:approver) { FactoryGirl.create(:user_miq_request_approver) } + let(:user) { FactoryBot.create(:user_with_group) } + let(:orchestration_stack) { FactoryBot.create(:orchestration_stack) } + let(:miq_request) { FactoryBot.create(:orchestration_stack_retire_request, :requester => user) } + let(:orchestration_stack_retire_task) { FactoryBot.create(:orchestration_stack_retire_task, :source => orchestration_stack, :miq_request => miq_request, :options => {:src_ids => [orchestration_stack.id] }) } + let(:approver) { FactoryBot.create(:user_miq_request_approver) } it "should initialize properly" do expect(orchestration_stack_retire_task).to have_attributes(:state => "pending", :status => "Ok") diff --git a/spec/models/orchestration_template_spec.rb b/spec/models/orchestration_template_spec.rb index 90750157aa0..46a61d7118a 100644 --- a/spec/models/orchestration_template_spec.rb +++ b/spec/models/orchestration_template_spec.rb @@ -1,7 +1,7 @@ describe OrchestrationTemplate do describe ".find_or_create_by_contents" do context "when the template does not exist" do - let(:query_hash) { FactoryGirl.build(:orchestration_template).as_json.symbolize_keys } + let(:query_hash) { FactoryBot.build(:orchestration_template).as_json.symbolize_keys } it "creates a new template" do expect(OrchestrationTemplate.count).to eq(0) @@ -16,7 +16,7 @@ context "when the template already exists" do before do - @existing_record = FactoryGirl.create(:orchestration_template) + @existing_record = FactoryBot.create(:orchestration_template) # prepare the query with different name and description; it is considered the same template # because the body (:template and :md5) does not change @query_hash = @existing_record.as_json.symbolize_keys.except(:id) @@ -59,8 +59,8 @@ context "when both types of templates, either alone or with deployed stacks, are present" do before do # prepare a mini environment with an orphan template and a template with deployed stacks - @template_alone = FactoryGirl.create(:orchestration_template) - @template_with_stack = FactoryGirl.create(:orchestration_template_with_stacks) + @template_alone = FactoryBot.create(:orchestration_template) + @template_with_stack = FactoryBot.create(:orchestration_template_with_stacks) end describe "#in_use?" do @@ -96,18 +96,18 @@ describe "#eligible_managers" do let!(:miq_server) { EvmSpecHelper.local_miq_server } - let(:user_admin) { FactoryGirl.create(:user_admin) } - let(:tenant) { FactoryGirl.create(:tenant) } - let(:other_tenant) { FactoryGirl.create(:tenant) } - let!(:user) { FactoryGirl.create(:user_with_group, :tenant => tenant) } + let(:user_admin) { FactoryBot.create(:user_admin) } + let(:tenant) { FactoryBot.create(:tenant) } + let(:other_tenant) { FactoryBot.create(:tenant) } + let!(:user) { FactoryBot.create(:user_with_group, :tenant => tenant) } before do allow(OrchestrationTemplate).to receive_messages(:eligible_manager_types => [ManageIQ::Providers::Amazon::CloudManager, ManageIQ::Providers::Openstack::CloudManager]) - @template = FactoryGirl.create(:orchestration_template) - @aws = FactoryGirl.create(:ems_amazon, :tenant => other_tenant) - @openstack = FactoryGirl.create(:ems_openstack, :tenant => tenant) + @template = FactoryBot.create(:orchestration_template) + @aws = FactoryBot.create(:ems_amazon, :tenant => other_tenant) + @openstack = FactoryBot.create(:ems_openstack, :tenant => tenant) end it "lists all eligible managers for a template" do @@ -125,8 +125,8 @@ describe "#validate_content" do before do - @template = FactoryGirl.create(:orchestration_template) - @manager = FactoryGirl.create(:ems_amazon) + @template = FactoryBot.create(:orchestration_template) + @manager = FactoryBot.create(:ems_amazon) allow(@manager).to receive_messages(:orchestration_template_validate => "Validation Message") end @@ -147,7 +147,7 @@ describe "#draft=" do context "when existing record is not a draft" do - let(:existing_template) { FactoryGirl.create(:orchestration_template, :draft => false) } + let(:existing_template) { FactoryBot.create(:orchestration_template, :draft => false) } it "allows duplicated draft record to be added" do dup_template = existing_template.dup @@ -162,7 +162,7 @@ end context "when existing record is a draft" do - let(:existing_template) { FactoryGirl.create(:orchestration_template, :draft => true) } + let(:existing_template) { FactoryBot.create(:orchestration_template, :draft => true) } it "allows duplicated draft record to be added" do dup_template = existing_template.dup @@ -178,7 +178,7 @@ describe ".find_with_content" do it "avoids content comparison but through content hash value comparison" do - existing_template = FactoryGirl.create(:orchestration_template) + existing_template = FactoryBot.create(:orchestration_template) allow(Digest::MD5).to receive(:hexdigest).and_return(existing_template.md5) result = OrchestrationTemplate.find_with_content("#{existing_template.content} content changed") @@ -189,7 +189,7 @@ context "when content has non-universal newlines" do let(:raw_text) { "abc\r\nxyz\r123\nend" } let(:content) { "abc\nxyz\n123\nend\n" } - let(:existing_template) { FactoryGirl.create(:orchestration_template, :content => raw_text) } + let(:existing_template) { FactoryBot.create(:orchestration_template, :content => raw_text) } it "stores content with universal newlines" do expect(existing_template.content).to eq(content) @@ -210,14 +210,14 @@ describe ".save_as_orderable!" do let(:content) { "content of the test template" } let(:existing_orderable_template) do - FactoryGirl.create(:orchestration_template, :content => content, :orderable => true) + FactoryBot.create(:orchestration_template, :content => content, :orderable => true) end let(:existing_discovered_template) do - FactoryGirl.create(:orchestration_template, :content => content, :orderable => false) + FactoryBot.create(:orchestration_template, :content => content, :orderable => false) end context "save new template" do - let(:template) { FactoryGirl.build(:orchestration_template, :content => content) } + let(:template) { FactoryBot.build(:orchestration_template, :content => content) } context "when format validation fails" do it "raises an error showing the failure reason" do @@ -263,7 +263,7 @@ end context "modify and save an existing template" do - let(:template) { FactoryGirl.create(:orchestration_template, :content => "old content") } + let(:template) { FactoryBot.create(:orchestration_template, :content => "old content") } before { template.content = content } @@ -278,7 +278,7 @@ context "when conflicts with existing discovered template" do let!(:stack) do - FactoryGirl.create(:orchestration_stack_cloud, :orchestration_template => existing_discovered_template) + FactoryBot.create(:orchestration_stack_cloud, :orchestration_template => existing_discovered_template) end it "updates the stacks from the discovered template to use the working template" do diff --git a/spec/models/partition_alignment_spec.rb b/spec/models/partition_alignment_spec.rb index cb4ae74ce01..69184f48d65 100644 --- a/spec/models/partition_alignment_spec.rb +++ b/spec/models/partition_alignment_spec.rb @@ -4,83 +4,83 @@ aligned = 64.kilobytes not_aligned = 1 - @vm1 = FactoryGirl.create(:vm_vmware, :name => "VM 1 Aligned", :hardware => FactoryGirl.create(:hardware)) - FactoryGirl.create(:disk, + @vm1 = FactoryBot.create(:vm_vmware, :name => "VM 1 Aligned", :hardware => FactoryBot.create(:hardware)) + FactoryBot.create(:disk, :device_type => "floppy", :hardware_id => @vm1.hardware.id, - :partitions => [FactoryGirl.create(:partition, :start_address => not_aligned)] + :partitions => [FactoryBot.create(:partition, :start_address => not_aligned)] ) - FactoryGirl.create(:disk, + FactoryBot.create(:disk, :device_type => "cdrom-raw", :hardware_id => @vm1.hardware.id, - :partitions => [FactoryGirl.create(:partition, :start_address => not_aligned)] + :partitions => [FactoryBot.create(:partition, :start_address => not_aligned)] ) - FactoryGirl.create(:disk, + FactoryBot.create(:disk, :device_type => "disk", :disk_type => "rdm-raw", :hardware_id => @vm1.hardware.id, - :partitions => [FactoryGirl.create(:partition, :start_address => not_aligned)] + :partitions => [FactoryBot.create(:partition, :start_address => not_aligned)] ) - FactoryGirl.create(:disk, + FactoryBot.create(:disk, :device_type => "disk", :hardware_id => @vm1.hardware.id, - :partitions => [FactoryGirl.create(:partition, :start_address => aligned)] + :partitions => [FactoryBot.create(:partition, :start_address => aligned)] ) - FactoryGirl.create(:disk, + FactoryBot.create(:disk, :device_type => "disk", :hardware_id => @vm1.hardware.id, :partitions => [ - FactoryGirl.create(:partition, :start_address => aligned), - FactoryGirl.create(:partition, :start_address => aligned) + FactoryBot.create(:partition, :start_address => aligned), + FactoryBot.create(:partition, :start_address => aligned) ] ) - @vm2 = FactoryGirl.create(:vm_vmware, :name => "VM 2 Not Aligned", :hardware => FactoryGirl.create(:hardware)) - FactoryGirl.create(:disk, + @vm2 = FactoryBot.create(:vm_vmware, :name => "VM 2 Not Aligned", :hardware => FactoryBot.create(:hardware)) + FactoryBot.create(:disk, :device_type => "floppy", :hardware_id => @vm2.hardware.id, - :partitions => [FactoryGirl.create(:partition, :start_address => not_aligned)] + :partitions => [FactoryBot.create(:partition, :start_address => not_aligned)] ) - FactoryGirl.create(:disk, + FactoryBot.create(:disk, :device_type => "cdrom-raw", :hardware_id => @vm2.hardware.id, - :partitions => [FactoryGirl.create(:partition, :start_address => not_aligned)] + :partitions => [FactoryBot.create(:partition, :start_address => not_aligned)] ) - FactoryGirl.create(:disk, + FactoryBot.create(:disk, :device_type => "disk", :disk_type => "rdm-raw", :hardware_id => @vm2.hardware.id, - :partitions => [FactoryGirl.create(:partition, :start_address => not_aligned)] + :partitions => [FactoryBot.create(:partition, :start_address => not_aligned)] ) - FactoryGirl.create(:disk, + FactoryBot.create(:disk, :device_type => "disk", :hardware_id => @vm2.hardware.id, - :partitions => [FactoryGirl.create(:partition, :start_address => not_aligned)] + :partitions => [FactoryBot.create(:partition, :start_address => not_aligned)] ) - FactoryGirl.create(:disk, + FactoryBot.create(:disk, :device_type => "disk", :hardware_id => @vm2.hardware.id, :partitions => [ - FactoryGirl.create(:partition, :start_address => aligned), - FactoryGirl.create(:partition, :start_address => not_aligned) + FactoryBot.create(:partition, :start_address => aligned), + FactoryBot.create(:partition, :start_address => not_aligned) ] ) - @vm3 = FactoryGirl.create(:vm_vmware, :name => "VM 3 Unknown", :hardware => FactoryGirl.create(:hardware)) + @vm3 = FactoryBot.create(:vm_vmware, :name => "VM 3 Unknown", :hardware => FactoryBot.create(:hardware)) - @vm4 = FactoryGirl.create(:vm_vmware, :name => "VM 4 Unknown", :hardware => FactoryGirl.create(:hardware)) - FactoryGirl.create(:disk, + @vm4 = FactoryBot.create(:vm_vmware, :name => "VM 4 Unknown", :hardware => FactoryBot.create(:hardware)) + FactoryBot.create(:disk, :device_type => "disk", :hardware_id => @vm4.hardware.id ) - @vm5 = FactoryGirl.create(:vm_vmware, :name => "VM 4 Unknown", :hardware => FactoryGirl.create(:hardware)) - FactoryGirl.create(:disk, + @vm5 = FactoryBot.create(:vm_vmware, :name => "VM 4 Unknown", :hardware => FactoryBot.create(:hardware)) + FactoryBot.create(:disk, :device_type => "disk", :hardware_id => @vm5.hardware.id, :partitions => [ - FactoryGirl.create(:partition, :start_address => aligned), - FactoryGirl.create(:partition) + FactoryBot.create(:partition, :start_address => aligned), + FactoryBot.create(:partition) ] ) end diff --git a/spec/models/partition_spec.rb b/spec/models/partition_spec.rb index 2838db5cf99..5e200f6d588 100644 --- a/spec/models/partition_spec.rb +++ b/spec/models/partition_spec.rb @@ -1,6 +1,6 @@ describe Partition do it "#partition_type_name" do - partition = FactoryGirl.create(:partition) + partition = FactoryBot.create(:partition) partition.partition_type = 999 expect(partition.partition_type_name).to eq(Partition::UNKNOWN_PARTITION_TYPE) diff --git a/spec/models/persistent_volume_claim_spec.rb b/spec/models/persistent_volume_claim_spec.rb index b48e8958a08..7d7bd5c5d16 100644 --- a/spec/models/persistent_volume_claim_spec.rb +++ b/spec/models/persistent_volume_claim_spec.rb @@ -3,7 +3,7 @@ let(:storage_size) { 123_456_789 } it "returns value for :storage key in Hash column :capacity" do - persistent_volume = FactoryGirl.create( + persistent_volume = FactoryBot.create( :persistent_volume_claim, :capacity => {:storage => storage_size, :foo => "something"} ) @@ -11,7 +11,7 @@ end it "returns nil if there is no :storage key in Hash column :capacity" do - persistent_volume = FactoryGirl.create( + persistent_volume = FactoryBot.create( :persistent_volume_claim, :capacity => {:foo => "something"} ) diff --git a/spec/models/persistent_volume_spec.rb b/spec/models/persistent_volume_spec.rb index 011821357c2..9923a9d3802 100644 --- a/spec/models/persistent_volume_spec.rb +++ b/spec/models/persistent_volume_spec.rb @@ -1,22 +1,22 @@ describe PersistentVolume do it "has container volumes and pods" do - pvc = FactoryGirl.create( + pvc = FactoryBot.create( :persistent_volume_claim, :name => "test_claim" ) - group = FactoryGirl.create( + group = FactoryBot.create( :container_group, :name => "group", ) - ems = FactoryGirl.create( + ems = FactoryBot.create( :ems_kubernetes, :id => group.id, :name => "ems" ) - FactoryGirl.create( + FactoryBot.create( :container_volume, :name => "container_volume", :type => 'ContainerVolume', @@ -24,7 +24,7 @@ :persistent_volume_claim => pvc ) - persistent_volume = FactoryGirl.create( + persistent_volume = FactoryBot.create( :persistent_volume, :name => "persistent_volume", :parent => ems, @@ -45,7 +45,7 @@ def assert_pv_relationships(persistent_volume) let(:storage_size) { 123_456_789 } it "returns value for :storage key in Hash column :capacity" do - persistent_volume = FactoryGirl.create( + persistent_volume = FactoryBot.create( :persistent_volume, :capacity => {:storage => storage_size, :foo => "something"} ) @@ -53,7 +53,7 @@ def assert_pv_relationships(persistent_volume) end it "returns nil if there is no :storage key in Hash column :capacity" do - persistent_volume = FactoryGirl.create( + persistent_volume = FactoryBot.create( :persistent_volume, :capacity => {:foo => "something"} ) diff --git a/spec/models/pglogical_subscription_spec.rb b/spec/models/pglogical_subscription_spec.rb index d8a47b3da6b..f6ab947d741 100644 --- a/spec/models/pglogical_subscription_spec.rb +++ b/spec/models/pglogical_subscription_spec.rb @@ -53,7 +53,7 @@ let(:pglogical) { double } let!(:remote_region) do - FactoryGirl.create( + FactoryBot.create( :miq_region, :id => ApplicationRecord.id_in_region(remote_region1, 1), :region => remote_region1, diff --git a/spec/models/picture_spec.rb b/spec/models/picture_spec.rb index 9fbc08568f7..40e7fa06e4a 100644 --- a/spec/models/picture_spec.rb +++ b/spec/models/picture_spec.rb @@ -1,5 +1,5 @@ describe Picture do - subject { FactoryGirl.build(:picture) } + subject { FactoryBot.build(:picture) } it "auto-creates needed directory" do expect(File.directory?(described_class.directory)).to be_truthy diff --git a/spec/models/provider_spec.rb b/spec/models/provider_spec.rb index 8214a9e45f7..acdacab7404 100644 --- a/spec/models/provider_spec.rb +++ b/spec/models/provider_spec.rb @@ -46,7 +46,7 @@ end it "works with #update_attributes" do - p = FactoryGirl.build(:provider_ansible_tower) + p = FactoryBot.build(:provider_ansible_tower) p.update_attributes(:verify_ssl => 0) p.update_attributes(:verify_ssl => 1) @@ -55,16 +55,16 @@ end context "#tenant" do - let(:tenant) { FactoryGirl.create(:tenant) } + let(:tenant) { FactoryBot.create(:tenant) } it "has a tenant" do - provider = FactoryGirl.create(:provider, :tenant => tenant) + provider = FactoryBot.create(:provider, :tenant => tenant) expect(tenant.providers).to include(provider) end end context "destroying provider" do let!(:miq_server) { EvmSpecHelper.local_miq_server } - let(:provider) { FactoryGirl.create(:provider) } + let(:provider) { FactoryBot.create(:provider) } context "#destroy_queue" do it "queues destroy" do provider.destroy_queue @@ -77,7 +77,7 @@ context "#destroy" do it "destroys its managers and itself" do - manager = FactoryGirl.create(:ext_management_system) + manager = FactoryBot.create(:ext_management_system) provider.managers = [manager] task = MiqTask.create( :name => "Destroying #{self.class.name} with id: #{provider.id}", diff --git a/spec/models/pxe_image_ipxe_spec.rb b/spec/models/pxe_image_ipxe_spec.rb index 4dfa4ce0bad..eb4fa89c4f5 100644 --- a/spec/models/pxe_image_ipxe_spec.rb +++ b/spec/models/pxe_image_ipxe_spec.rb @@ -1,5 +1,5 @@ describe PxeImageIpxe do - let(:image) { FactoryGirl.create(:pxe_image_ipxe) } + let(:image) { FactoryBot.create(:pxe_image_ipxe) } context "#build_pxe_contents" do it "updates ks and ks_device options" do diff --git a/spec/models/pxe_image_pxelinux_spec.rb b/spec/models/pxe_image_pxelinux_spec.rb index fbe7755e0b1..fcbc833c3c9 100644 --- a/spec/models/pxe_image_pxelinux_spec.rb +++ b/spec/models/pxe_image_pxelinux_spec.rb @@ -1,5 +1,5 @@ describe PxeImagePxelinux do - let(:image) { FactoryGirl.create(:pxe_image_pxelinux) } + let(:image) { FactoryBot.create(:pxe_image_pxelinux) } context "#build_pxe_contents" do it "updates ks and ks_device options" do diff --git a/spec/models/pxe_image_spec.rb b/spec/models/pxe_image_spec.rb index a0e9783a43d..b478f2bbec6 100644 --- a/spec/models/pxe_image_spec.rb +++ b/spec/models/pxe_image_spec.rb @@ -1,5 +1,5 @@ describe PxeImage do - let(:image) { FactoryGirl.create(:pxe_image) } + let(:image) { FactoryBot.create(:pxe_image) } context "#build_pxe_contents" do it "updates ks and ks_device options" do diff --git a/spec/models/pxe_image_type_spec.rb b/spec/models/pxe_image_type_spec.rb index 3cd5d16ed46..a2aab969910 100644 --- a/spec/models/pxe_image_type_spec.rb +++ b/spec/models/pxe_image_type_spec.rb @@ -22,8 +22,8 @@ context "duplicated name" do it "should raise RecordInvalid error" do - FactoryGirl.create(:pxe_image_type, :name => "unique_name") - expect { FactoryGirl.create(:pxe_image_type, :name => "unique_name") }.to raise_error(ActiveRecord::RecordInvalid) + FactoryBot.create(:pxe_image_type, :name => "unique_name") + expect { FactoryBot.create(:pxe_image_type, :name => "unique_name") }.to raise_error(ActiveRecord::RecordInvalid) end end end diff --git a/spec/models/pxe_menu_ipxe_spec.rb b/spec/models/pxe_menu_ipxe_spec.rb index c52bd3c2a93..247b53d311a 100644 --- a/spec/models/pxe_menu_ipxe_spec.rb +++ b/spec/models/pxe_menu_ipxe_spec.rb @@ -88,8 +88,8 @@ context "#synchronize_images" do before do - @pxe_server = FactoryGirl.create(:pxe_server) - @pxe_menu = FactoryGirl.create(:pxe_menu_ipxe, :contents => @contents, :pxe_server => @pxe_server) + @pxe_server = FactoryBot.create(:pxe_server) + @pxe_menu = FactoryBot.create(:pxe_menu_ipxe, :contents => @contents, :pxe_server => @pxe_server) end it "finds correct number of menu items" do diff --git a/spec/models/pxe_menu_pxelinux_spec.rb b/spec/models/pxe_menu_pxelinux_spec.rb index 991d7f6f523..b838daabe5b 100644 --- a/spec/models/pxe_menu_pxelinux_spec.rb +++ b/spec/models/pxe_menu_pxelinux_spec.rb @@ -88,8 +88,8 @@ context "#synchronize_images" do before do - @pxe_server = FactoryGirl.create(:pxe_server) - @pxe_menu = FactoryGirl.create(:pxe_menu_pxelinux, :contents => @contents, :pxe_server => @pxe_server) + @pxe_server = FactoryBot.create(:pxe_server) + @pxe_menu = FactoryBot.create(:pxe_menu_pxelinux, :contents => @contents, :pxe_server => @pxe_server) end it "finds correct number of menu items" do diff --git a/spec/models/pxe_menu_spec.rb b/spec/models/pxe_menu_spec.rb index 2a675c21707..cc8f6b5c47c 100644 --- a/spec/models/pxe_menu_spec.rb +++ b/spec/models/pxe_menu_spec.rb @@ -131,12 +131,12 @@ context "#synchronize" do before do - @pxe_server = FactoryGirl.create(:pxe_server) + @pxe_server = FactoryBot.create(:pxe_server) allow(@pxe_server).to receive_messages(:read_file => @contents_ipxe) end it "on typed menu" do - pxe_menu = FactoryGirl.create(:pxe_menu_ipxe, :pxe_server => @pxe_server) + pxe_menu = FactoryBot.create(:pxe_menu_ipxe, :pxe_server => @pxe_server) pxe_menu.synchronize new_pxe_menu = PxeMenu.find(pxe_menu.id) @@ -145,7 +145,7 @@ end it "on untyped menu" do - pxe_menu = FactoryGirl.create(:pxe_menu, :pxe_server => @pxe_server) + pxe_menu = FactoryBot.create(:pxe_menu, :pxe_server => @pxe_server) pxe_menu.synchronize new_pxe_menu = PxeMenu.find(pxe_menu.id) @@ -154,7 +154,7 @@ end it "on typed menu switching to a different type" do - pxe_menu = FactoryGirl.create(:pxe_menu_pxelinux, :contents => @contents_pxelinux, :pxe_server => @pxe_server) + pxe_menu = FactoryBot.create(:pxe_menu_pxelinux, :contents => @contents_pxelinux, :pxe_server => @pxe_server) pxe_menu.synchronize new_pxe_menu = PxeMenu.find(pxe_menu.id) diff --git a/spec/models/pxe_server_spec.rb b/spec/models/pxe_server_spec.rb index e3ae4bd1378..8a852bf09e8 100644 --- a/spec/models/pxe_server_spec.rb +++ b/spec/models/pxe_server_spec.rb @@ -1,7 +1,7 @@ describe PxeServer do before do EvmSpecHelper.local_miq_server - @pxe_server = FactoryGirl.create(:pxe_server, :uri_prefix => "nfs", :uri => "nfs:///#{@mnt_point}") + @pxe_server = FactoryBot.create(:pxe_server, :uri_prefix => "nfs", :uri => "nfs:///#{@mnt_point}") end context "#sync_images_queue" do @@ -86,9 +86,9 @@ def file_write(file, contents) it "with existing data" do @pxe_server.pxe_images = [ - FactoryGirl.create(:pxe_image_pxelinux, :path => "XXX", :name => "XXX"), - FactoryGirl.create(:pxe_image_pxelinux, :path => "default", :name => "XXX"), - FactoryGirl.create(:pxe_image_pxelinux, :path => "default", :name => "iPXE", :kernel => "XXX"), + FactoryBot.create(:pxe_image_pxelinux, :path => "XXX", :name => "XXX"), + FactoryBot.create(:pxe_image_pxelinux, :path => "default", :name => "XXX"), + FactoryBot.create(:pxe_image_pxelinux, :path => "default", :name => "iPXE", :kernel => "XXX"), ] @pxe_server.sync_images @@ -132,7 +132,7 @@ def file_write(file, contents) image = @pxe_server.pxe_images.find_by(:name => "Ubuntu-10.10-Desktop-i386-LIVE_BOOT") ks_contents = "FOO" - kickstart = FactoryGirl.create(:customization_template_kickstart, :script => ks_contents) + kickstart = FactoryBot.create(:customization_template_kickstart, :script => ks_contents) expected_contents = <<-PXE timeout 0 @@ -218,9 +218,9 @@ def file_write(file, contents) it "with existing images" do @pxe_server.pxe_images = [ - FactoryGirl.create(:pxe_image_ipxe, :path => "XXX", :name => "XXX"), - FactoryGirl.create(:pxe_image_ipxe, :path => "00-50-56-91-79-d5", :name => "XXX"), - FactoryGirl.create(:pxe_image_ipxe, :path => "00-50-56-91-79-d5", :name => "00-50-56-91-79-d5", :kernel => "XXX") + FactoryBot.create(:pxe_image_ipxe, :path => "XXX", :name => "XXX"), + FactoryBot.create(:pxe_image_ipxe, :path => "00-50-56-91-79-d5", :name => "XXX"), + FactoryBot.create(:pxe_image_ipxe, :path => "00-50-56-91-79-d5", :name => "00-50-56-91-79-d5", :kernel => "XXX") ] @pxe_server.sync_images @@ -230,7 +230,7 @@ def file_write(file, contents) context "#create_provisioning_files" do it "without kickstart" do - image = FactoryGirl.create(:pxe_image_ipxe, + image = FactoryBot.create(:pxe_image_ipxe, :pxe_server => @pxe_server, :kernel => "http://192.168.252.60/ipxe/rhel6.2-desktop/vmlinuz", :kernel_options => "ramdisk_size=10000 ksdevice=00:50:56:91:79:d5", @@ -260,7 +260,7 @@ def file_write(file, contents) expected_name = @pxe_server.test_full_path_to("#{@pxe_server.pxe_directory}/#{dashed_mac_address}") expected_ks_name = "#{expected_name}.ks.cfg" - image = FactoryGirl.create(:pxe_image_ipxe, + image = FactoryBot.create(:pxe_image_ipxe, :pxe_server => @pxe_server, :kernel => "http://192.168.252.60/ipxe/rhel6.2-desktop/vmlinuz", :kernel_options => "ramdisk_size=10000 ksdevice=00:50:56:91:79:d5", @@ -268,7 +268,7 @@ def file_write(file, contents) ) ks_contents = "FOO" - kickstart = FactoryGirl.create(:customization_template_kickstart, :script => ks_contents) + kickstart = FactoryBot.create(:customization_template_kickstart, :script => ks_contents) expected_contents = <<-PXE #!ipxe @@ -293,9 +293,9 @@ def file_write(file, contents) context "with pxe images" do before do - pxe_menu = FactoryGirl.create(:pxe_menu, :pxe_server => @pxe_server) - @advertised_image = FactoryGirl.create(:pxe_image, :pxe_server => @pxe_server, :pxe_menu => pxe_menu) - @discovered_image = FactoryGirl.create(:pxe_image, :pxe_server => @pxe_server) + pxe_menu = FactoryBot.create(:pxe_menu, :pxe_server => @pxe_server) + @advertised_image = FactoryBot.create(:pxe_image, :pxe_server => @pxe_server, :pxe_menu => pxe_menu) + @discovered_image = FactoryBot.create(:pxe_image, :pxe_server => @pxe_server) end it "#pxe_images" do diff --git a/spec/models/registration_system_spec.rb b/spec/models/registration_system_spec.rb index 30f2e4fa911..91ed1a7202f 100644 --- a/spec/models/registration_system_spec.rb +++ b/spec/models/registration_system_spec.rb @@ -115,7 +115,7 @@ :registration_http_proxy_username => "my_dummy_username", :registration_http_proxy_password => "my_dummy_password"}.freeze - @miq_region = FactoryGirl.create(:miq_region, :region => 1) + @miq_region = FactoryBot.create(:miq_region, :region => 1) allow(MiqRegion).to receive(:my_region).and_return(@miq_region) end diff --git a/spec/models/relationship_spec.rb b/spec/models/relationship_spec.rb index 96a012c3e20..26f8199fd59 100644 --- a/spec/models/relationship_spec.rb +++ b/spec/models/relationship_spec.rb @@ -1,7 +1,7 @@ describe Relationship do describe "#filtered?" do before do - @rel = FactoryGirl.build(:relationship_vm_vmware) + @rel = FactoryBot.build(:relationship_vm_vmware) end it "with neither" do @@ -29,9 +29,9 @@ end describe ".filter_by_resource_type" do - let(:storages) { FactoryGirl.build_list(:relationship_storage_vmware, 1) } - let(:vms) { FactoryGirl.build_list(:relationship_vm_vmware, 1) } - let(:hosts) { FactoryGirl.build_list(:relationship_host_vmware, 1) } + let(:storages) { FactoryBot.build_list(:relationship_storage_vmware, 1) } + let(:vms) { FactoryBot.build_list(:relationship_vm_vmware, 1) } + let(:hosts) { FactoryBot.build_list(:relationship_host_vmware, 1) } it "includes" do expect(Relationship.filter_by_resource_type(vms + hosts, :of_type => "Host")).to eq(hosts) @@ -104,9 +104,9 @@ end describe ".filtered" do - let(:storages) { FactoryGirl.build_list(:relationship_storage_vmware, 1) } - let(:vms) { FactoryGirl.build_list(:relationship_vm_vmware, 1) } - let(:hosts) { FactoryGirl.build_list(:relationship_host_vmware, 1) } + let(:storages) { FactoryBot.build_list(:relationship_storage_vmware, 1) } + let(:vms) { FactoryBot.build_list(:relationship_vm_vmware, 1) } + let(:hosts) { FactoryBot.build_list(:relationship_host_vmware, 1) } it "scopes" do vms.map(&:save!) diff --git a/spec/models/resource_action_spec.rb b/spec/models/resource_action_spec.rb index 2d6986fca46..a6380a4cd3f 100644 --- a/spec/models/resource_action_spec.rb +++ b/spec/models/resource_action_spec.rb @@ -1,9 +1,9 @@ describe ResourceAction do context "#deliver_to_automate_from_dialog" do - let(:user) { FactoryGirl.create(:user_with_group) } + let(:user) { FactoryBot.create(:user_with_group) } let(:zone_name) { "default" } - let(:ra) { FactoryGirl.create(:resource_action) } - let(:miq_server) { FactoryGirl.create(:miq_server) } + let(:ra) { FactoryBot.create(:resource_action) } + let(:miq_server) { FactoryBot.create(:miq_server) } let(:ae_attributes) { {} } let(:q_args) do { @@ -49,7 +49,7 @@ context 'with target' do it "validates queue entry" do - target = FactoryGirl.create(:vm_vmware) + target = FactoryBot.create(:vm_vmware) q_args[:object_type] = target.class.base_class.name q_args[:object_id] = target.id expect(MiqQueue).to receive(:put).with(q_options).once @@ -60,7 +60,7 @@ context 'with targets' do let(:zone_name) { nil } it "validates queue entry" do - targets = [FactoryGirl.create(:vm_vmware), FactoryGirl.create(:vm_vmware)] + targets = [FactoryBot.create(:vm_vmware), FactoryBot.create(:vm_vmware)] ae_attributes[:target_object_type] = targets.first.class.base_class.name klass = targets.first.id.class ae_attributes['Array::target_object_ids'] = targets.collect { |t| "#{klass}::#{t.id}" }.join(",") @@ -82,7 +82,7 @@ context "uri validation" do let(:ra) do - FactoryGirl.build(:resource_action, + FactoryBot.build(:resource_action, :ae_namespace => "NAMESPACE", :ae_class => "CLASS", :ae_instance => "INSTANCE") diff --git a/spec/models/resource_action_workflow_spec.rb b/spec/models/resource_action_workflow_spec.rb index f81b1afdaff..f2ee3a74eac 100644 --- a/spec/models/resource_action_workflow_spec.rb +++ b/spec/models/resource_action_workflow_spec.rb @@ -1,20 +1,20 @@ describe ResourceActionWorkflow do - let(:admin) { FactoryGirl.create(:user_with_group) } + let(:admin) { FactoryBot.create(:user_with_group) } context "#create" do before do - @dialog = FactoryGirl.create(:dialog, :label => 'dialog') - @dialog_tab = FactoryGirl.create(:dialog_tab, :label => 'tab') - @dialog_group = FactoryGirl.create(:dialog_group, :label => 'group') - @dialog_field = FactoryGirl.create(:dialog_field_text_box, :label => 'field 1', :name => 'field_1') - @dialog_field2 = FactoryGirl.create(:dialog_field_text_box, :label => 'field 2', :name => 'field_2') + @dialog = FactoryBot.create(:dialog, :label => 'dialog') + @dialog_tab = FactoryBot.create(:dialog_tab, :label => 'tab') + @dialog_group = FactoryBot.create(:dialog_group, :label => 'group') + @dialog_field = FactoryBot.create(:dialog_field_text_box, :label => 'field 1', :name => 'field_1') + @dialog_field2 = FactoryBot.create(:dialog_field_text_box, :label => 'field 2', :name => 'field_2') @dialog_tab.dialog_groups << @dialog_group @dialog_group.dialog_fields << @dialog_field @dialog_group.dialog_fields << @dialog_field2 @dialog.dialog_tabs << @dialog_tab - @resource_action = FactoryGirl.create(:resource_action, :action => "Provision", :dialog => @dialog) + @resource_action = FactoryBot.create(:resource_action, :action => "Provision", :dialog => @dialog) end it "new from resource_action" do @@ -68,7 +68,7 @@ let(:data) { {} } context "with request class" do - let(:target) { FactoryGirl.create(:service) } + let(:target) { FactoryBot.create(:service) } it "creates requests" do EvmSpecHelper.local_miq_server @@ -89,7 +89,7 @@ subject { ResourceActionWorkflow.new({}, admin, resource_action, :target => target) } let(:resource_action) { @resource_action } - let(:target) { FactoryGirl.create(:vm_vmware) } + let(:target) { FactoryBot.create(:vm_vmware) } it "calls automate" do EvmSpecHelper.local_miq_server @@ -104,11 +104,11 @@ end context "with custom button request" do - let(:target) { FactoryGirl.build(:service) } + let(:target) { FactoryBot.build(:service) } let(:options) { {} } let(:resource_action) do @resource_action.tap do |ra| - ra.update_attributes(:resource => FactoryGirl.create(:custom_button, :applies_to_class => target.class.name, :options => options)) + ra.update_attributes(:resource => FactoryBot.create(:custom_button, :applies_to_class => target.class.name, :options => options)) end end @@ -138,7 +138,7 @@ let(:data) { {"parameters" => {"field_1" => "new_value"}} } context "with request class" do - let(:target) { FactoryGirl.create(:service) } + let(:target) { FactoryBot.create(:service) } it "creates requests" do EvmSpecHelper.local_miq_server @@ -159,7 +159,7 @@ subject { ResourceActionWorkflow.new({}, admin, resource_action, :target => target) } let(:resource_action) { @resource_action } - let(:target) { FactoryGirl.create(:vm_vmware) } + let(:target) { FactoryBot.create(:vm_vmware) } it "calls automate" do EvmSpecHelper.local_miq_server @@ -174,11 +174,11 @@ end context "with custom button request" do - let(:target) { FactoryGirl.build(:service) } + let(:target) { FactoryBot.build(:service) } let(:options) { {} } let(:resource_action) do @resource_action.tap do |ra| - ra.update_attributes(:resource => FactoryGirl.create(:custom_button, :applies_to_class => target.class.name, :options => options)) + ra.update_attributes(:resource => FactoryBot.create(:custom_button, :applies_to_class => target.class.name, :options => options)) end end diff --git a/spec/models/resource_group_spec.rb b/spec/models/resource_group_spec.rb index 6307dce37d5..7df7c58874e 100644 --- a/spec/models/resource_group_spec.rb +++ b/spec/models/resource_group_spec.rb @@ -1,6 +1,6 @@ describe ResourceGroup do let(:resource_group) do - FactoryGirl.create( + FactoryBot.create( :resource_group, :type => "ResourceGroup", :name => "foo", @@ -24,8 +24,8 @@ context "relationships" do before do - @vm = FactoryGirl.create(:vm_google, :template => false, :resource_group => resource_group) - @template = FactoryGirl.create(:template_google, :template => true, :resource_group => resource_group) + @vm = FactoryBot.create(:vm_google, :template => false, :resource_group => resource_group) + @template = FactoryBot.create(:template_google, :template => true, :resource_group => resource_group) end it "returns the expected results for vms" do diff --git a/spec/models/resource_pool_spec.rb b/spec/models/resource_pool_spec.rb index c03191627d0..81bc99458ce 100644 --- a/spec/models/resource_pool_spec.rb +++ b/spec/models/resource_pool_spec.rb @@ -1,42 +1,42 @@ describe ResourcePool do context "Testing VM count virtual columns" do before do - @rp1 = FactoryGirl.create(:resource_pool, :name => "RP 1") - @rp2 = FactoryGirl.create(:resource_pool, :name => "RP 2") - @rp3 = FactoryGirl.create(:resource_pool, :name => "RP 3") - @rp4 = FactoryGirl.create(:resource_pool, :name => "RP 4") - @rp5 = FactoryGirl.create(:resource_pool, :name => "RP 5") - @rp6 = FactoryGirl.create(:resource_pool, :name => "RP 6") - @rp7 = FactoryGirl.create(:resource_pool, :name => "RP 7") + @rp1 = FactoryBot.create(:resource_pool, :name => "RP 1") + @rp2 = FactoryBot.create(:resource_pool, :name => "RP 2") + @rp3 = FactoryBot.create(:resource_pool, :name => "RP 3") + @rp4 = FactoryBot.create(:resource_pool, :name => "RP 4") + @rp5 = FactoryBot.create(:resource_pool, :name => "RP 5") + @rp6 = FactoryBot.create(:resource_pool, :name => "RP 6") + @rp7 = FactoryBot.create(:resource_pool, :name => "RP 7") @rp2.with_relationship_type("ems_metadata") { @rp2.set_parent @rp1 } @rp5.with_relationship_type("ems_metadata") { @rp5.set_parent @rp4 } @rp6.with_relationship_type("ems_metadata") { @rp6.set_parent @rp5 } 5.times do |_i| - vm = FactoryGirl.create(:vm_vmware, :name => "Test VM Under RP1") + vm = FactoryBot.create(:vm_vmware, :name => "Test VM Under RP1") vm.with_relationship_type("ems_metadata") { vm.set_parent @rp1 } end 10.times do |_i| - vm = FactoryGirl.create(:vm_vmware, :name => "Test VM Under RP2") + vm = FactoryBot.create(:vm_vmware, :name => "Test VM Under RP2") vm.with_relationship_type("ems_metadata") { vm.set_parent @rp2 } end 15.times do |_i| - vm = FactoryGirl.create(:vm_vmware, :name => "Test VM Under RP3") + vm = FactoryBot.create(:vm_vmware, :name => "Test VM Under RP3") vm.with_relationship_type("ems_metadata") { vm.set_parent @rp3 } end 1.times do |_i| - vm = FactoryGirl.create(:vm_vmware, :name => "Test VM Under RP4") + vm = FactoryBot.create(:vm_vmware, :name => "Test VM Under RP4") vm.with_relationship_type("ems_metadata") { vm.set_parent @rp4 } end # @rp5 has no child VMs 2.times do |_i| - vm = FactoryGirl.create(:vm_vmware, :name => "Test VM Under RP6") + vm = FactoryBot.create(:vm_vmware, :name => "Test VM Under RP6") vm.with_relationship_type("ems_metadata") { vm.set_parent @rp6 } end @@ -90,15 +90,15 @@ end context "#tenant_identity" do - let(:admin) { FactoryGirl.create(:user_with_group, :userid => "admin") } - let(:tenant) { FactoryGirl.create(:tenant) } - let(:ems) { FactoryGirl.create(:ext_management_system, :tenant => tenant) } + let(:admin) { FactoryBot.create(:user_with_group, :userid => "admin") } + let(:tenant) { FactoryBot.create(:tenant) } + let(:ems) { FactoryBot.create(:ext_management_system, :tenant => tenant) } before { admin } subject { @rp.tenant_identity } it "has tenant from provider" do - @rp = FactoryGirl.create(:resource_pool, :ems_id => ems.id) + @rp = FactoryBot.create(:resource_pool, :ems_id => ems.id) expect(subject).to eq(admin) expect(subject.current_group).to eq(ems.tenant.default_miq_group) @@ -106,7 +106,7 @@ end it "without a provider, has tenant from root tenant" do - @rp = FactoryGirl.create(:resource_pool) + @rp = FactoryBot.create(:resource_pool) expect(subject).to eq(admin) expect(subject.current_group).to eq(Tenant.root_tenant.default_miq_group) diff --git a/spec/models/retirement_manager_spec.rb b/spec/models/retirement_manager_spec.rb index e698e5386fd..43e82c95ae2 100644 --- a/spec/models/retirement_manager_spec.rb +++ b/spec/models/retirement_manager_spec.rb @@ -2,16 +2,16 @@ describe "#check" do it "with retirement date, runs retirement checks" do _, _, zone = EvmSpecHelper.local_guid_miq_server_zone - ems = FactoryGirl.create(:ems_network, :zone => zone) + ems = FactoryBot.create(:ems_network, :zone => zone) - load_balancer = FactoryGirl.create(:load_balancer, :retires_on => Time.zone.today + 1.day, :ext_management_system => ems) - FactoryGirl.create(:load_balancer, :retired => true) - orchestration_stack = FactoryGirl.create(:orchestration_stack, :retires_on => Time.zone.today + 1.day, :ext_management_system => ems) - FactoryGirl.create(:orchestration_stack, :retired => true) - vm = FactoryGirl.create(:vm, :retires_on => Time.zone.today + 1.day, :ems_id => ems.id) - FactoryGirl.create(:vm, :retired => true) - service = FactoryGirl.create(:service, :retires_on => Time.zone.today + 1.day) - FactoryGirl.create(:service, :retired => true) + load_balancer = FactoryBot.create(:load_balancer, :retires_on => Time.zone.today + 1.day, :ext_management_system => ems) + FactoryBot.create(:load_balancer, :retired => true) + orchestration_stack = FactoryBot.create(:orchestration_stack, :retires_on => Time.zone.today + 1.day, :ext_management_system => ems) + FactoryBot.create(:orchestration_stack, :retired => true) + vm = FactoryBot.create(:vm, :retires_on => Time.zone.today + 1.day, :ems_id => ems.id) + FactoryBot.create(:vm, :retired => true) + service = FactoryBot.create(:service, :retires_on => Time.zone.today + 1.day) + FactoryBot.create(:service, :retired => true) expect(RetirementManager.check).to match_array([load_balancer, orchestration_stack, vm, service]) end diff --git a/spec/models/rss_feed/import_export_spec.rb b/spec/models/rss_feed/import_export_spec.rb index 2d8f45d4ff3..b2a2d414182 100644 --- a/spec/models/rss_feed/import_export_spec.rb +++ b/spec/models/rss_feed/import_export_spec.rb @@ -1,6 +1,6 @@ describe RssFeed::ImportExport do it "#export_to_array" do - expect(FactoryGirl.create(:rss_feed, :title => "Latest things!!!") + expect(FactoryBot.create(:rss_feed, :title => "Latest things!!!") .export_to_array.first["RssFeed"]["title"]).to eq("Latest things!!!") end end diff --git a/spec/models/rss_feed/rss_feed_spec.rb b/spec/models/rss_feed/rss_feed_spec.rb index bcdb7e78a40..8c8e19f3700 100644 --- a/spec/models/rss_feed/rss_feed_spec.rb +++ b/spec/models/rss_feed/rss_feed_spec.rb @@ -10,11 +10,11 @@ RssFeed.sync_from_yml_file("newest_vms") end - let(:owner_tenant) { FactoryGirl.create(:tenant) } - let(:owner_group) { FactoryGirl.create(:miq_group, :tenant => owner_tenant) } - let(:owner_user) { FactoryGirl.create(:user, :miq_groups => [owner_group]) } - let!(:owned_vm) { FactoryGirl.create(:vm_vmware, :tenant => owner_tenant) } - let!(:tenant_root_vm) { FactoryGirl.create(:vm_vmware, :tenant => Tenant.root_tenant) } + let(:owner_tenant) { FactoryBot.create(:tenant) } + let(:owner_group) { FactoryBot.create(:miq_group, :tenant => owner_tenant) } + let(:owner_user) { FactoryBot.create(:user, :miq_groups => [owner_group]) } + let!(:owned_vm) { FactoryBot.create(:vm_vmware, :tenant => owner_tenant) } + let!(:tenant_root_vm) { FactoryBot.create(:vm_vmware, :tenant => Tenant.root_tenant) } let(:rss_feed) { RssFeed.find_by(:name => "newest_vms") } it "#generate 1 vms with owner_tenant tenant in newest_vms rss" do @@ -48,8 +48,8 @@ context "with 2 hosts" do before do - @host1 = FactoryGirl.create(:host, :created_on => Time.utc(2013, 1, 1, 0, 0, 0)) - @host2 = FactoryGirl.create(:host_microsoft, :created_on => @host1.created_on + 1.second) + @host1 = FactoryBot.create(:host, :created_on => Time.utc(2013, 1, 1, 0, 0, 0)) + @host2 = FactoryBot.create(:host_microsoft, :created_on => @host1.created_on + 1.second) end it "#generate 2 hosts in newest_hosts rss" do diff --git a/spec/models/security_group_spec.rb b/spec/models/security_group_spec.rb index 6740d310143..8814361f5f7 100644 --- a/spec/models/security_group_spec.rb +++ b/spec/models/security_group_spec.rb @@ -1,12 +1,12 @@ describe SecurityGroup do before do - provider = FactoryGirl.create(:ems_amazon) - cn = FactoryGirl.create(:cloud_network) - @sg1 = FactoryGirl.create(:security_group, + provider = FactoryBot.create(:ems_amazon) + cn = FactoryBot.create(:cloud_network) + @sg1 = FactoryBot.create(:security_group, :name => "sq_1", :ext_management_system => provider.network_manager, :cloud_network => cn) - @sg2 = FactoryGirl.create(:security_group, + @sg2 = FactoryBot.create(:security_group, :name => "sq_1", :ext_management_system => provider.network_manager) end @@ -17,11 +17,11 @@ describe "#total_vms" do it "counts vms" do - sg = FactoryGirl.create(:security_group) + sg = FactoryBot.create(:security_group) 2.times do - vm = FactoryGirl.create(:vm_amazon) - FactoryGirl.create(:network_port_openstack, + vm = FactoryBot.create(:vm_amazon) + FactoryBot.create(:network_port_openstack, :device => vm, :security_groups => [sg]) end diff --git a/spec/models/server_role_spec.rb b/spec/models/server_role_spec.rb index 5b68cef0214..935c09b5ec0 100644 --- a/spec/models/server_role_spec.rb +++ b/spec/models/server_role_spec.rb @@ -6,11 +6,11 @@ ['event', 1], ['ems_metrics_coordinator', 1], ['ems_operations', 0] - ].each { |r, max| @server_roles << FactoryGirl.create(:server_role, :name => r, :max_concurrent => max) } + ].each { |r, max| @server_roles << FactoryBot.create(:server_role, :name => r, :max_concurrent => max) } end it "validates uniqueness of name" do - expect { FactoryGirl.create(:server_role, :name => @server_roles.first.name, :max_concurrent => @server_roles.first.max_concurrent) }.to raise_error(ActiveRecord::RecordInvalid) + expect { FactoryBot.create(:server_role, :name => @server_roles.first.name, :max_concurrent => @server_roles.first.max_concurrent) }.to raise_error(ActiveRecord::RecordInvalid) end it "should return all names" do diff --git a/spec/models/service/aggregation_spec.rb b/spec/models/service/aggregation_spec.rb index e54f58e2631..a0dfca6b4a5 100644 --- a/spec/models/service/aggregation_spec.rb +++ b/spec/models/service/aggregation_spec.rb @@ -1,6 +1,6 @@ describe Service do it "#aggregate_all_vm_memory_on_disk will not raise when the attribute is nil" do - service = FactoryGirl.create(:service) + service = FactoryBot.create(:service) expect(service).to receive(:has_attribute?).with("aggregate_all_vm_memory_on_disk").and_return(true) expect { service.aggregate_all_vm_memory_on_disk }.not_to raise_error end diff --git a/spec/models/service/dialog_properties/retirement_spec.rb b/spec/models/service/dialog_properties/retirement_spec.rb index a6617e96e33..4344b398bb0 100644 --- a/spec/models/service/dialog_properties/retirement_spec.rb +++ b/spec/models/service/dialog_properties/retirement_spec.rb @@ -85,7 +85,7 @@ context 'when setting retirement warn date' do it 'with retirement_warn_on' do - user = FactoryGirl.create(:user) + user = FactoryBot.create(:user) expect(user).to receive(:with_my_timezone).exactly(3).times.and_yield Timecop.freeze(time) do diff --git a/spec/models/service/linking_workflow_spec.rb b/spec/models/service/linking_workflow_spec.rb index 228796c7d09..245023fdf15 100644 --- a/spec/models/service/linking_workflow_spec.rb +++ b/spec/models/service/linking_workflow_spec.rb @@ -1,6 +1,6 @@ describe Service::LinkingWorkflow do - let(:service) { FactoryGirl.create(:service) } - let(:provider) { FactoryGirl.create(:ems_vmware) } + let(:service) { FactoryBot.create(:service) } + let(:provider) { FactoryBot.create(:ems_vmware) } let(:uid_ems_array) { ["423c9963-378c-813f-1dbd-630e464d59d4", "423cf3e2-e319-3953-993f-fd8513db951d"] } let(:options) do { @@ -34,7 +34,7 @@ end it 'calls post_refresh if all VMs found in DB' do - uid_ems_array.each { |uid| FactoryGirl.create(:vm_vmware, :uid_ems => uid, :ems_id => provider.id) } + uid_ems_array.each { |uid| FactoryBot.create(:vm_vmware, :uid_ems => uid, :ems_id => provider.id) } expect(job).to receive(:signal).with(:post_refresh) subject end @@ -44,7 +44,7 @@ subject { job.post_refresh } it 'links found VMs to service' do - uid_ems_array.each { |uid| FactoryGirl.create(:vm_vmware, :uid_ems => uid, :ems_id => provider.id) } + uid_ems_array.each { |uid| FactoryBot.create(:vm_vmware, :uid_ems => uid, :ems_id => provider.id) } subject expect(service.vms.count).to eq(2) end diff --git a/spec/models/service/resource_linking_spec.rb b/spec/models/service/resource_linking_spec.rb index eb208ade25b..9a5044ee76a 100644 --- a/spec/models/service/resource_linking_spec.rb +++ b/spec/models/service/resource_linking_spec.rb @@ -1,7 +1,7 @@ describe Service do describe '#add_provider_vms' do - let(:service) { FactoryGirl.create(:service, :evm_owner => FactoryGirl.create(:user)) } - let(:provider) { FactoryGirl.create(:ems_vmware) } + let(:service) { FactoryBot.create(:service, :evm_owner => FactoryBot.create(:user)) } + let(:provider) { FactoryBot.create(:ems_vmware) } let(:uid_ems_array) { ["423c9963-378c-813f-1dbd-630e464d59d4", "423cf3e2-e319-3953-993f-fd8513db951d"] } it 'raises an error if uid_ems_array is not passed in' do diff --git a/spec/models/service/retirement_management_spec.rb b/spec/models/service/retirement_management_spec.rb index 3d35dfacc0b..2e62a8ad3b2 100644 --- a/spec/models/service/retirement_management_spec.rb +++ b/spec/models/service/retirement_management_spec.rb @@ -1,10 +1,10 @@ describe "Service Retirement Management" do - let!(:user) { FactoryGirl.create(:user_miq_request_approver, :userid => 'admin') } - let(:service_without_owner) { FactoryGirl.create(:service) } - let(:service3) { FactoryGirl.create(:service) } + let!(:user) { FactoryBot.create(:user_miq_request_approver, :userid => 'admin') } + let(:service_without_owner) { FactoryBot.create(:service) } + let(:service3) { FactoryBot.create(:service) } before do @server = EvmSpecHelper.local_miq_server - @service = FactoryGirl.create(:service, :evm_owner_id => user.id) + @service = FactoryBot.create(:service, :evm_owner_id => user.id) end # shouldn't be running make_retire_request because it's the bimodal not from ui part @@ -118,8 +118,8 @@ end it "#retire_service_resources" do - ems = FactoryGirl.create(:ems_vmware, :zone => @server.zone) - vm = FactoryGirl.create(:vm_vmware, :ems_id => ems.id) + ems = FactoryBot.create(:ems_vmware, :zone => @server.zone) + vm = FactoryBot.create(:vm_vmware, :ems_id => ems.id) @service << vm expect(@service.service_resources.size).to eq(1) expect(@service.service_resources.first.resource).to_not receive(:retire_now) @@ -127,8 +127,8 @@ end it "#retire_service_resources should get service's retirement_requester" do - ems = FactoryGirl.create(:ems_vmware, :zone => @server.zone) - vm = FactoryGirl.create(:vm_vmware, :ems_id => ems.id) + ems = FactoryBot.create(:ems_vmware, :zone => @server.zone) + vm = FactoryBot.create(:vm_vmware, :ems_id => ems.id) userid = 'freddy' @service.update_attributes(:retirement_requester => userid) @service << vm @@ -138,8 +138,8 @@ end it "#retire_service_resources should get service's nil retirement_requester" do - ems = FactoryGirl.create(:ems_vmware, :zone => @server.zone) - vm = FactoryGirl.create(:vm_vmware, :ems_id => ems.id) + ems = FactoryBot.create(:ems_vmware, :zone => @server.zone) + vm = FactoryBot.create(:vm_vmware, :ems_id => ems.id) @service << vm expect(@service.service_resources.size).to eq(1) expect(@service.service_resources.first.resource).to_not receive(:retire_now).with(nil) diff --git a/spec/models/service_ansible_playbook_spec.rb b/spec/models/service_ansible_playbook_spec.rb index df90de7a093..a5c18a5e964 100644 --- a/spec/models/service_ansible_playbook_spec.rb +++ b/spec/models/service_ansible_playbook_spec.rb @@ -1,28 +1,28 @@ describe(ServiceAnsiblePlaybook) do - let(:tower_job) { FactoryGirl.create(:embedded_ansible_job) } - let(:tower_job_temp) { FactoryGirl.create(:ansible_configuration_script) } - let(:basic_service) { FactoryGirl.create(:service_ansible_playbook, :options => config_info_options) } - let(:service) { FactoryGirl.create(:service_ansible_playbook, :options => config_info_options.merge(dialog_options)) } + let(:tower_job) { FactoryBot.create(:embedded_ansible_job) } + let(:tower_job_temp) { FactoryBot.create(:ansible_configuration_script) } + let(:basic_service) { FactoryBot.create(:service_ansible_playbook, :options => config_info_options) } + let(:service) { FactoryBot.create(:service_ansible_playbook, :options => config_info_options.merge(dialog_options)) } let(:action) { ResourceAction::PROVISION } - let(:credential_0) { FactoryGirl.create(:embedded_ansible_credential, :manager_ref => '1') } - let(:credential_1) { FactoryGirl.create(:embedded_ansible_credential, :manager_ref => '2') } - let(:credential_2) { FactoryGirl.create(:embedded_ansible_credential, :manager_ref => '3') } - let(:credential_3) { FactoryGirl.create(:embedded_ansible_credential, :manager_ref => '4') } + let(:credential_0) { FactoryBot.create(:embedded_ansible_credential, :manager_ref => '1') } + let(:credential_1) { FactoryBot.create(:embedded_ansible_credential, :manager_ref => '2') } + let(:credential_2) { FactoryBot.create(:embedded_ansible_credential, :manager_ref => '3') } + let(:credential_3) { FactoryBot.create(:embedded_ansible_credential, :manager_ref => '4') } let(:decrpyted_val) { 'my secret' } let(:encrypted_val) { MiqPassword.encrypt(decrpyted_val) } let(:encrypted_val2) { MiqPassword.encrypt(decrpyted_val + "new") } let(:loaded_service) do - service_template = FactoryGirl.create(:service_template_ansible_playbook) + service_template = FactoryBot.create(:service_template_ansible_playbook) service_template.resource_actions.build(:action => action, :configuration_template => tower_job_temp) service_template.save! - FactoryGirl.create(:service_ansible_playbook, + FactoryBot.create(:service_ansible_playbook, :options => provision_options.merge(config_info_options), :service_template => service_template) end let(:executed_service) do - FactoryGirl.create(:service_ansible_playbook, :options => provision_options).tap do |service| + FactoryBot.create(:service_ansible_playbook, :options => provision_options).tap do |service| regex = /(#{ResourceAction::PROVISION})|(#{ResourceAction::RETIREMENT})/ allow(service).to receive(:job).with(regex).and_return(tower_job) end @@ -143,11 +143,11 @@ describe '#execute' do let(:control_extras) { {'a' => 'A', 'b' => 'B', 'c' => 'C'} } before do - FactoryGirl.create(:miq_region, :region => ApplicationRecord.my_region_number) - miq_request_task = FactoryGirl.create(:miq_request_task, :miq_request => FactoryGirl.create(:service_template_provision_request)) + FactoryBot.create(:miq_region, :region => ApplicationRecord.my_region_number) + miq_request_task = FactoryBot.create(:miq_request_task, :miq_request => FactoryBot.create(:service_template_provision_request)) miq_request_task.update_attributes(:options => {:request_options => {:manageiq_extra_vars => control_extras}}) - loaded_service.update_attributes(:evm_owner => FactoryGirl.create(:user_with_group), - :miq_group => FactoryGirl.create(:miq_group), + loaded_service.update_attributes(:evm_owner => FactoryBot.create(:user_with_group), + :miq_group => FactoryBot.create(:miq_group), :miq_request_task => miq_request_task) end diff --git a/spec/models/service_ansible_tower_spec.rb b/spec/models/service_ansible_tower_spec.rb index af9a010848e..bd14eb2586e 100644 --- a/spec/models/service_ansible_tower_spec.rb +++ b/spec/models/service_ansible_tower_spec.rb @@ -1,7 +1,7 @@ describe ServiceAnsibleTower do - let(:tower) { FactoryGirl.create(:automation_manager_ansible_tower) } - let(:template_by_dialog) { FactoryGirl.create(:ansible_configuration_script, :manager => tower) } - let(:template_by_setter) { FactoryGirl.create(:ansible_configuration_script, :manager => tower) } + let(:tower) { FactoryBot.create(:automation_manager_ansible_tower) } + let(:template_by_dialog) { FactoryBot.create(:ansible_configuration_script, :manager => tower) } + let(:template_by_setter) { FactoryBot.create(:ansible_configuration_script, :manager => tower) } let(:dialog_options) do { @@ -20,9 +20,9 @@ end let(:service) do - FactoryGirl.create(:service_ansible_tower, - :evm_owner => FactoryGirl.create(:user), - :miq_group => FactoryGirl.create(:miq_group)) + FactoryBot.create(:service_ansible_tower, + :evm_owner => FactoryBot.create(:user), + :miq_group => FactoryBot.create(:miq_group)) end let(:service_with_dialog_options) do @@ -63,11 +63,11 @@ describe '#launch_job' do let(:control_extras) { {'a' => 'A', 'b' => 'B', 'c' => 'C'} } before do - FactoryGirl.create(:miq_region, :region => ApplicationRecord.my_region_number) - miq_request_task = FactoryGirl.create(:miq_request_task, :miq_request => FactoryGirl.create(:service_template_provision_request)) + FactoryBot.create(:miq_region, :region => ApplicationRecord.my_region_number) + miq_request_task = FactoryBot.create(:miq_request_task, :miq_request => FactoryBot.create(:service_template_provision_request)) miq_request_task.update_attributes(:options => {:request_options => {:manageiq_extra_vars => control_extras}}) - service.update_attributes(:evm_owner => FactoryGirl.create(:user_with_group), - :miq_group => FactoryGirl.create(:miq_group), + service.update_attributes(:evm_owner => FactoryBot.create(:user_with_group), + :miq_group => FactoryBot.create(:miq_group), :miq_request_task => miq_request_task) end diff --git a/spec/models/service_container_template_spec.rb b/spec/models/service_container_template_spec.rb index e6bef9d81ef..5e817a72de2 100644 --- a/spec/models/service_container_template_spec.rb +++ b/spec/models/service_container_template_spec.rb @@ -6,29 +6,29 @@ end let(:ems) do - FactoryGirl.create(:ems_openshift).tap do |ems| + FactoryBot.create(:ems_openshift).tap do |ems| allow(ems).to receive(:create_project) end end let(:service) do - FactoryGirl.create(:service_container_template, :options => config_info_options.merge(dialog_options)).tap do |svc| + FactoryBot.create(:service_container_template, :options => config_info_options.merge(dialog_options)).tap do |svc| allow(svc).to receive(:container_manager).and_return(ems) end end let(:service_with_new_project) do - FactoryGirl.create(:service_container_template, :options => config_info_options.merge(dialog_options_with_new_project)).tap do |svc| + FactoryBot.create(:service_container_template, :options => config_info_options.merge(dialog_options_with_new_project)).tap do |svc| allow(svc).to receive(:container_manager).and_return(ems) end end let(:loaded_service) do - service_template = FactoryGirl.create(:service_template_container_template).tap do |st| + service_template = FactoryBot.create(:service_template_container_template).tap do |st| allow(st).to receive(:container_manager).and_return(ems) end - FactoryGirl.create(:service_container_template, + FactoryBot.create(:service_container_template, :options => provision_options.merge(config_info_options), :service_template => service_template).tap do |svc| allow(svc).to receive(:container_template).and_return(container_template) @@ -79,16 +79,16 @@ } end - let(:ctp1) { FactoryGirl.create(:container_template_parameter, :name => 'var1', :value => 'p1', :required => true) } - let(:ctp2) { FactoryGirl.create(:container_template_parameter, :name => 'var2', :value => 'p2', :required => true) } - let(:ctp3) { FactoryGirl.create(:container_template_parameter, :name => 'var3', :value => 'p3', :required => false) } + let(:ctp1) { FactoryBot.create(:container_template_parameter, :name => 'var1', :value => 'p1', :required => true) } + let(:ctp2) { FactoryBot.create(:container_template_parameter, :name => 'var2', :value => 'p2', :required => true) } + let(:ctp3) { FactoryBot.create(:container_template_parameter, :name => 'var3', :value => 'p3', :required => false) } let(:container_template) do - FactoryGirl.create(:container_template, :ems_id => ems.id).tap do |ct| + FactoryBot.create(:container_template, :ems_id => ems.id).tap do |ct| ct.container_template_parameters = [ctp1, ctp2, ctp3] end end - let(:created_object) { FactoryGirl.create(:orchestration_stack_resource, :name => 'my-example', :resource_category => 'ContainerRoute') } + let(:created_object) { FactoryBot.create(:orchestration_stack_resource, :name => 'my-example', :resource_category => 'ContainerRoute') } let(:object_hash) { {:apiVersion => "v1", :kind => "Route", :metadata => {:name => "dotnet-example"}} } describe '#preprocess' do diff --git a/spec/models/service_orchestration/provision_tagging_spec.rb b/spec/models/service_orchestration/provision_tagging_spec.rb index 0daf1466755..7afd1c9b6d0 100644 --- a/spec/models/service_orchestration/provision_tagging_spec.rb +++ b/spec/models/service_orchestration/provision_tagging_spec.rb @@ -15,9 +15,9 @@ describe '#apply_provisioning_tags' do before { expect(service).to receive(:assign_vms_owner) } - let(:miq_request_task) { FactoryGirl.create(:service_template_provision_task) } - let(:vm) { FactoryGirl.create(:vm) } - let(:service) { FactoryGirl.build(:service_orchestration, :miq_request_task => miq_request_task) } + let(:miq_request_task) { FactoryBot.create(:service_template_provision_task) } + let(:vm) { FactoryBot.create(:vm) } + let(:service) { FactoryBot.build(:service_orchestration, :miq_request_task => miq_request_task) } let(:dialog_tag_options) do { :dialog => { 'Array::dialog_tag_0_env' => 'Classification::1', @@ -54,8 +54,8 @@ service.add_to_service(parent_service) end - let(:parent_service) { FactoryGirl.create(:service, :name => 'parent_service') } - let(:service) { FactoryGirl.build(:service_orchestration, :miq_request_task => miq_request_task) } + let(:parent_service) { FactoryBot.create(:service, :name => 'parent_service') } + let(:service) { FactoryBot.build(:service_orchestration, :miq_request_task => miq_request_task) } context 'Calls Classification.bulk_reassignment with VM and tag IDs for provision_priority 0' do let(:provision_priority) { 0 } diff --git a/spec/models/service_orchestration_spec.rb b/spec/models/service_orchestration_spec.rb index 4ad40df619a..a78f35057f5 100644 --- a/spec/models/service_orchestration_spec.rb +++ b/spec/models/service_orchestration_spec.rb @@ -1,14 +1,14 @@ describe ServiceOrchestration do - let(:manager_by_setter) { FactoryGirl.create(:ems_amazon) } - let(:template_by_setter) { FactoryGirl.create(:orchestration_template) } - let(:manager_by_dialog) { FactoryGirl.create(:ems_amazon) } - let(:template_by_dialog) { FactoryGirl.create(:orchestration_template) } - let(:manager_in_st) { FactoryGirl.create(:ems_amazon) } - let(:template_in_st) { FactoryGirl.create(:orchestration_template) } - let(:deployed_stack) { FactoryGirl.create(:orchestration_stack_amazon) } + let(:manager_by_setter) { FactoryBot.create(:ems_amazon) } + let(:template_by_setter) { FactoryBot.create(:orchestration_template) } + let(:manager_by_dialog) { FactoryBot.create(:ems_amazon) } + let(:template_by_dialog) { FactoryBot.create(:orchestration_template) } + let(:manager_in_st) { FactoryBot.create(:ems_amazon) } + let(:template_in_st) { FactoryBot.create(:orchestration_template) } + let(:deployed_stack) { FactoryBot.create(:orchestration_stack_amazon) } let(:service_template) do - FactoryGirl.create(:service_template_orchestration, + FactoryBot.create(:service_template_orchestration, :orchestration_manager => manager_in_st, :orchestration_template => template_in_st) end @@ -26,12 +26,12 @@ end let(:service) do - FactoryGirl.create(:service_orchestration, + FactoryBot.create(:service_orchestration, :service_template => service_template, :orchestration_manager => manager_in_st, :orchestration_template => template_in_st, - :evm_owner => FactoryGirl.create(:user), - :miq_group => FactoryGirl.create(:miq_group)) + :evm_owner => FactoryBot.create(:user), + :miq_group => FactoryBot.create(:miq_group)) end let(:service_with_dialog_options) do @@ -66,14 +66,14 @@ end it "service, takes the zone from orchestration_manager" do - ems = FactoryGirl.create(:ems_amazon, :zone => FactoryGirl.create(:zone)) - deployed_stack.direct_vms << FactoryGirl.create(:vm_amazon, :ext_management_system => ems) + ems = FactoryBot.create(:ems_amazon, :zone => FactoryBot.create(:zone)) + deployed_stack.direct_vms << FactoryBot.create(:vm_amazon, :ext_management_system => ems) expect(service_with_deployed_stack.my_zone).to eq(service.orchestration_manager.my_zone) end it "service, takes the zone from VM ext_management_system if no orchestration_manager" do - ems = FactoryGirl.create(:ems_amazon, :zone => FactoryGirl.create(:zone)) - deployed_stack.direct_vms << FactoryGirl.create(:vm_amazon, :ext_management_system => ems) + ems = FactoryBot.create(:ems_amazon, :zone => FactoryBot.create(:zone)) + deployed_stack.direct_vms << FactoryBot.create(:vm_amazon, :ext_management_system => ems) service.orchestration_manager = nil expect(service_with_deployed_stack.my_zone).to eq(service_with_deployed_stack.vms.first.ext_management_system.my_zone) end @@ -179,8 +179,8 @@ describe '#update_orchestration_stack' do let(:reconfigurable_service) do - stack = FactoryGirl.create(:orchestration_stack) - service_template = FactoryGirl.create(:service_template_orchestration) + stack = FactoryBot.create(:orchestration_stack) + service_template = FactoryBot.create(:service_template_orchestration) service_template.orchestration_template = template_by_setter service.service_template = service_template @@ -232,10 +232,10 @@ describe '#all_vms' do it 'returns all vms from a deployed stack' do - vm1 = FactoryGirl.create(:vm_amazon) - vm2 = FactoryGirl.create(:vm_amazon) + vm1 = FactoryBot.create(:vm_amazon) + vm2 = FactoryBot.create(:vm_amazon) - child_stack = FactoryGirl.create(:orchestration_stack_amazon, :parent => deployed_stack) + child_stack = FactoryBot.create(:orchestration_stack_amazon, :parent => deployed_stack) deployed_stack.direct_vms << vm1 child_stack.direct_vms << vm2 @@ -259,11 +259,11 @@ :raw_create_stack).and_return("ems_ref") @resulting_stack = service.deploy_orchestration_stack - service.miq_request_task = FactoryGirl.create(:service_template_provision_task) + service.miq_request_task = FactoryBot.create(:service_template_provision_task) end it 'sets owners for all vms included in the stack' do - vms = [FactoryGirl.create(:vm_amazon), FactoryGirl.create(:vm_amazon)] + vms = [FactoryBot.create(:vm_amazon), FactoryBot.create(:vm_amazon)] @resulting_stack.direct_vms.push(*vms) service.post_provision_configure diff --git a/spec/models/service_order_spec.rb b/spec/models/service_order_spec.rb index 7f4e72d242e..01bc59157ab 100644 --- a/spec/models/service_order_spec.rb +++ b/spec/models/service_order_spec.rb @@ -1,17 +1,17 @@ describe ServiceOrder do def create_request - FactoryGirl.create(:service_template_provision_request, + FactoryBot.create(:service_template_provision_request, :process => false, :requester => admin) end - let(:admin) { FactoryGirl.create(:user_with_group, :userid => "admin") } - let(:user) { FactoryGirl.create(:user_with_group, :tenant => tenant) } + let(:admin) { FactoryBot.create(:user_with_group, :userid => "admin") } + let(:user) { FactoryBot.create(:user_with_group, :tenant => tenant) } let(:request) { create_request } let(:request2) { create_request } let(:request3) { create_request } let(:service_order) do - FactoryGirl.create(:service_order, :state => ServiceOrder::STATE_CART, + FactoryBot.create(:service_order, :state => ServiceOrder::STATE_CART, :user => user, :tenant => tenant) end diff --git a/spec/models/service_reconfigure_task_spec.rb b/spec/models/service_reconfigure_task_spec.rb index c003a687d28..05ea3468cc4 100644 --- a/spec/models/service_reconfigure_task_spec.rb +++ b/spec/models/service_reconfigure_task_spec.rb @@ -1,7 +1,7 @@ describe ServiceReconfigureTask do - let(:user) { FactoryGirl.create(:user_with_group) } - let(:template) { FactoryGirl.create(:service_template, :name => 'Test Template') } - let(:service) { FactoryGirl.create(:service, :name => 'Test Service', :service_template => template) } + let(:user) { FactoryBot.create(:user_with_group) } + let(:template) { FactoryBot.create(:service_template, :name => 'Test Template') } + let(:service) { FactoryBot.create(:service, :name => 'Test Service', :service_template => template) } let(:request) do ServiceReconfigureRequest.create(:requester => user, @@ -60,7 +60,7 @@ context "automation entry point available" do before do - FactoryGirl.create(:resource_action, :action => 'Reconfigure', + FactoryBot.create(:resource_action, :action => 'Reconfigure', :resource => template, :ae_namespace => 'namespace', :ae_class => 'class', diff --git a/spec/models/service_resource_spec.rb b/spec/models/service_resource_spec.rb index 7b4f6ef8bea..3dac6cc6f05 100644 --- a/spec/models/service_resource_spec.rb +++ b/spec/models/service_resource_spec.rb @@ -18,7 +18,7 @@ context "with a service as a resource" do before do - @service = FactoryGirl.create(:service, :name => "Svc_A", :description => "Test Service") + @service = FactoryBot.create(:service, :name => "Svc_A", :description => "Test Service") subject.resource = @service end diff --git a/spec/models/service_retire_task_spec.rb b/spec/models/service_retire_task_spec.rb index 18bceb22ff1..fb52dadf80a 100644 --- a/spec/models/service_retire_task_spec.rb +++ b/spec/models/service_retire_task_spec.rb @@ -1,20 +1,20 @@ describe ServiceRetireTask do - let(:user) { FactoryGirl.create(:user_with_group) } - let(:vm) { FactoryGirl.create(:vm) } - let(:service) { FactoryGirl.create(:service) } - let(:miq_request) { FactoryGirl.create(:service_retire_request, :requester => user) } - let(:service_retire_task) { FactoryGirl.create(:service_retire_task, :source => service, :miq_request => miq_request, :options => {:src_ids => [service.id] }) } + let(:user) { FactoryBot.create(:user_with_group) } + let(:vm) { FactoryBot.create(:vm) } + let(:service) { FactoryBot.create(:service) } + let(:miq_request) { FactoryBot.create(:service_retire_request, :requester => user) } + let(:service_retire_task) { FactoryBot.create(:service_retire_task, :source => service, :miq_request => miq_request, :options => {:src_ids => [service.id] }) } let(:reason) { "Why Not?" } - let(:approver) { FactoryGirl.create(:user_miq_request_approver) } - let(:zone) { FactoryGirl.create(:zone, :name => "fred") } + let(:approver) { FactoryBot.create(:user_miq_request_approver) } + let(:zone) { FactoryBot.create(:zone, :name => "fred") } shared_context "service_bundle" do - let(:zone) { FactoryGirl.create(:small_environment) } - let(:service_c1) { FactoryGirl.create(:service, :service => service) } + let(:zone) { FactoryBot.create(:small_environment) } + let(:service_c1) { FactoryBot.create(:service, :service => service) } before do allow(MiqServer).to receive(:my_server).and_return(zone.miq_servers.first) - @miq_request = FactoryGirl.create(:service_retire_request, :requester => user) + @miq_request = FactoryBot.create(:service_retire_request, :requester => user) @miq_request.approve(approver, reason) end end @@ -58,7 +58,7 @@ end it "creates subtask" do - resource = FactoryGirl.create(:service_resource, :resource_type => "VmOrTemplate", :service_id => service.id, :resource_id => vm.id) + resource = FactoryBot.create(:service_resource, :resource_type => "VmOrTemplate", :service_id => service.id, :resource_id => vm.id) service.service_resources << resource service_retire_task.after_request_task_create @@ -69,8 +69,8 @@ context "bundled service retires all children" do include_context "service_bundle" - let(:vm1) { FactoryGirl.create(:vm_vmware) } - let(:service_c2) { FactoryGirl.create(:service, :service => service_c1) } + let(:vm1) { FactoryBot.create(:vm_vmware) } + let(:service_c2) { FactoryBot.create(:service, :service => service_c1) } before do service_c1 << vm @@ -81,11 +81,11 @@ end it "creates subtask" do - @service_retire_task = FactoryGirl.create(:service_retire_task, :source => service, :miq_request_task_id => nil, :miq_request_id => @miq_request.id, :options => {:src_ids => [service.id] }) - service.service_resources << FactoryGirl.create(:service_resource, :resource_type => "VmOrTemplate", :service_id => service_c1.id, :resource_id => vm.id) - service.service_resources << FactoryGirl.create(:service_resource, :resource_type => "VmOrTemplate", :service_id => service_c1.id, :resource_id => vm1.id) - service.service_resources << FactoryGirl.create(:service_resource, :resource_type => "Service", :service_id => service_c1.id, :resource_id => service_c1.id) - service.service_resources << FactoryGirl.create(:service_resource, :resource_type => "ServiceTemplate", :service_id => service_c1.id, :resource_id => service_c1.id) + @service_retire_task = FactoryBot.create(:service_retire_task, :source => service, :miq_request_task_id => nil, :miq_request_id => @miq_request.id, :options => {:src_ids => [service.id] }) + service.service_resources << FactoryBot.create(:service_resource, :resource_type => "VmOrTemplate", :service_id => service_c1.id, :resource_id => vm.id) + service.service_resources << FactoryBot.create(:service_resource, :resource_type => "VmOrTemplate", :service_id => service_c1.id, :resource_id => vm1.id) + service.service_resources << FactoryBot.create(:service_resource, :resource_type => "Service", :service_id => service_c1.id, :resource_id => service_c1.id) + service.service_resources << FactoryBot.create(:service_resource, :resource_type => "ServiceTemplate", :service_id => service_c1.id, :resource_id => service_c1.id) @service_retire_task.after_request_task_create expect(VmRetireTask.count).to eq(2) @@ -95,8 +95,8 @@ end it "doesn't creates subtask for ServiceTemplates" do - @service_retire_task = FactoryGirl.create(:service_retire_task, :source => service, :miq_request_task_id => nil, :miq_request_id => @miq_request.id, :options => {:src_ids => [service.id] }) - service.service_resources << FactoryGirl.create(:service_resource, :resource_type => "ServiceTemplate", :service_id => service_c1.id, :resource_id => service_c1.id) + @service_retire_task = FactoryBot.create(:service_retire_task, :source => service, :miq_request_task_id => nil, :miq_request_id => @miq_request.id, :options => {:src_ids => [service.id] }) + service.service_resources << FactoryBot.create(:service_resource, :resource_type => "ServiceTemplate", :service_id => service_c1.id, :resource_id => service_c1.id) @service_retire_task.after_request_task_create expect(ServiceRetireTask.count).to eq(1) @@ -104,8 +104,8 @@ end it "doesn't creates subtask for service resources whose resources are nil" do - @service_retire_task = FactoryGirl.create(:service_retire_task, :source => service, :miq_request_task_id => nil, :miq_request_id => @miq_request.id, :options => {:src_ids => [service.id] }) - service.service_resources << FactoryGirl.create(:service_resource, :resource_type => "ServiceTemplate", :service_id => service_c1.id, :resource => nil) + @service_retire_task = FactoryBot.create(:service_retire_task, :source => service, :miq_request_task_id => nil, :miq_request_id => @miq_request.id, :options => {:src_ids => [service.id] }) + service.service_resources << FactoryBot.create(:service_resource, :resource_type => "ServiceTemplate", :service_id => service_c1.id, :resource => nil) @service_retire_task.after_request_task_create expect(ServiceRetireTask.count).to eq(1) diff --git a/spec/models/service_spec.rb b/spec/models/service_spec.rb index 81eff9dfd4d..dfc9f158aa2 100644 --- a/spec/models/service_spec.rb +++ b/spec/models/service_spec.rb @@ -3,7 +3,7 @@ context "service events" do before do - @service = FactoryGirl.create(:service) + @service = FactoryBot.create(:service) end it "raise_request_start_event" do @@ -70,15 +70,15 @@ context "VM associations" do before do - @zone1 = FactoryGirl.create(:small_environment) + @zone1 = FactoryBot.create(:small_environment) allow(MiqServer).to receive(:my_server).and_return(@zone1.miq_servers.first) - @vm = FactoryGirl.create(:vm_vmware) - @vm1 = FactoryGirl.create(:vm_vmware) - @vm2 = FactoryGirl.create(:vm_vmware) + @vm = FactoryBot.create(:vm_vmware) + @vm1 = FactoryBot.create(:vm_vmware) + @vm2 = FactoryBot.create(:vm_vmware) - @service = FactoryGirl.create(:service) - @service_c1 = FactoryGirl.create(:service, :service => @service) - @service_c2 = FactoryGirl.create(:service, :service => @service_c1) + @service = FactoryBot.create(:service) + @service_c1 = FactoryBot.create(:service, :service => @service) + @service_c2 = FactoryBot.create(:service, :service => @service_c1) @service << @vm @service_c1 << @vm1 @service_c2 << @vm1 @@ -233,9 +233,9 @@ context "with a small env" do before do - @zone1 = FactoryGirl.create(:small_environment) + @zone1 = FactoryBot.create(:small_environment) allow(MiqServer).to receive(:my_server).and_return(@zone1.miq_servers.first) - @service = FactoryGirl.create(:service, :name => 'Service 1') + @service = FactoryBot.create(:service, :name => 'Service 1') end it "should create a valid service" do @@ -262,13 +262,13 @@ end it "should allow a service to connect to another service" do - s2 = FactoryGirl.create(:service, :name => 'inner_service') + s2 = FactoryBot.create(:service, :name => 'inner_service') @service << s2 expect(@service.service_resources.size).to eq(1) end it "should allow a service to connect to ansible tower service" do - s2 = FactoryGirl.create(:service_ansible_tower, :name => 'ansible') + s2 = FactoryBot.create(:service_ansible_tower, :name => 'ansible') @service.add_resource(s2) expect(s2.parent).to eq(@service) end @@ -400,7 +400,7 @@ vm = Vm.first @service.save expect(vm.service).not_to be_nil - service2 = FactoryGirl.create(:service) + service2 = FactoryBot.create(:service) expect { service2.add_resource(vm) }.to raise_error(MiqException::Error) expect { service2 << vm }.to raise_error(MiqException::Error) end @@ -420,9 +420,9 @@ context "Chargeback report generation" do before do - @vm = FactoryGirl.create(:vm_vmware) - @vm1 = FactoryGirl.create(:vm_vmware) - @service = FactoryGirl.create(:service) + @vm = FactoryBot.create(:vm_vmware) + @vm1 = FactoryBot.create(:vm_vmware) + @service = FactoryBot.create(:service) @service.name = "Test_Service_1" @service << @vm @service.save @@ -430,7 +430,7 @@ describe ".queue_chargeback_reports" do it "queue request to generate chargeback report for each service" do - @service_c1 = FactoryGirl.create(:service, :service => @service) + @service_c1 = FactoryBot.create(:service, :service => @service) @service_c1.name = "Test_Service_2" @service_c1 << @vm1 @service_c1.save @@ -459,7 +459,7 @@ describe "#generate_chargeback_report" do it "delete existing chargeback report result for service before generating new one" do - FactoryGirl.create(:miq_chargeback_report_result, :name => @service.chargeback_report_name) + FactoryBot.create(:miq_chargeback_report_result, :name => @service.chargeback_report_name) expect(MiqReportResult.count).to eq 1 report = double("MiqReport") @@ -481,7 +481,7 @@ describe "#chargeback_yaml" do it "loads chargeback report template" do - @user = FactoryGirl.create(:user_with_group) + @user = FactoryBot.create(:user_with_group) report_yaml = @service.chargeback_yaml report = MiqReport.new(report_yaml) @@ -515,7 +515,7 @@ end it "returns no children" do - @service = FactoryGirl.create(:service) + @service = FactoryBot.create(:service) expect(@service.children).to be_empty expect(@service.composite?).to be_falsey expect(@service.atomic?).to be_truthy @@ -575,13 +575,13 @@ describe "#parent_service" do it "returns no parent" do - service = FactoryGirl.create(:service) + service = FactoryBot.create(:service) expect(service.parent).to be_nil end it "returns parent" do - service = FactoryGirl.create(:service) - service_c1 = FactoryGirl.create(:service, :service => service) + service = FactoryBot.create(:service) + service_c1 = FactoryBot.create(:service, :service => service) expect(service_c1.parent).to eq(service) expect(service_c1.parent_service).to eq(service) # alias @@ -590,14 +590,14 @@ describe "#has_parent" do it "has no parent" do - service = FactoryGirl.create(:service) + service = FactoryBot.create(:service) expect(service.has_parent).to be_falsey expect(service.has_parent?).to be_falsey # alias end it "has parent" do - service = FactoryGirl.create(:service) - service_c1 = FactoryGirl.create(:service, :service => service) + service = FactoryBot.create(:service) + service_c1 = FactoryBot.create(:service, :service => service) expect(service_c1.has_parent).to be_truthy expect(service_c1.has_parent?).to be_truthy # alias @@ -606,21 +606,21 @@ describe "#root" do it "has root as self" do - service = FactoryGirl.create(:service) + service = FactoryBot.create(:service) expect(service.root).to eq(service) expect(service.root_service).to eq(service) # alias end it "has root as parent" do - service = FactoryGirl.create(:service) - service_c1 = FactoryGirl.create(:service, :service => service) + service = FactoryBot.create(:service) + service_c1 = FactoryBot.create(:service, :service => service) expect(service_c1.root).to eq(service) expect(service_c1.root_service).to eq(service) # alias end end describe "#service_action" do - let(:service) { FactoryGirl.create(:service) } + let(:service) { FactoryBot.create(:service) } let(:service_resource_nil) { double(:service_resource) } let(:service_resource_power) do instance_double("ServiceResource", :start_action => "Power On", @@ -670,7 +670,7 @@ end it "cannot be nil" do - service = FactoryGirl.build(:service, :display => nil) + service = FactoryBot.build(:service, :display => nil) expect(service).not_to be_valid end end @@ -682,14 +682,14 @@ end it "cannot be nil" do - service = FactoryGirl.build(:service, :retired => nil) + service = FactoryBot.build(:service, :retired => nil) expect(service).not_to be_valid end end describe '#orchestration_stacks' do - let(:service) { FactoryGirl.create(:service) } - let(:tower_job) { FactoryGirl.create(:embedded_ansible_job) } + let(:service) { FactoryBot.create(:service) } + let(:tower_job) { FactoryBot.create(:embedded_ansible_job) } before { service.add_resource!(tower_job, :name => ResourceAction::PROVISION) } @@ -699,9 +699,9 @@ end describe '#generic_objects' do - let(:service) { FactoryGirl.create(:service) } - let(:go_def) { FactoryGirl.create(:generic_object_definition, :properties => {:attributes => {:limit => :integer}}) } - let(:generic_object) { FactoryGirl.create(:generic_object, :generic_object_definition => go_def).tap { |g| g.property_attributes = {"limit" => 1} } } + let(:service) { FactoryBot.create(:service) } + let(:go_def) { FactoryBot.create(:generic_object_definition, :properties => {:attributes => {:limit => :integer}}) } + let(:generic_object) { FactoryBot.create(:generic_object, :generic_object_definition => go_def).tap { |g| g.property_attributes = {"limit" => 1} } } before { service.add_resource!(generic_object) } @@ -711,22 +711,22 @@ end describe '#my_zone' do - let(:service) { FactoryGirl.create(:service) } + let(:service) { FactoryBot.create(:service) } it 'returns nil without any resources' do expect(service.my_zone).to be_nil end it 'returns nil zone when VM is archived' do - vm = FactoryGirl.build(:vm_vmware) + vm = FactoryBot.build(:vm_vmware) service.add_resource!(vm) expect(service.my_zone).to be_nil end it 'returns the EMS zone when the VM is connected to a EMS' do - ems = FactoryGirl.create(:ext_management_system, :zone => FactoryGirl.create(:zone)) - vm = FactoryGirl.create(:vm_vmware, :ext_management_system => ems) + ems = FactoryBot.create(:ext_management_system, :zone => FactoryBot.create(:zone)) + vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems) service.add_resource!(vm) @@ -734,10 +734,10 @@ end it 'returns the EMS zone with one VM connected to a EMS and one archived' do - service.add_resource!(FactoryGirl.build(:vm_vmware)) + service.add_resource!(FactoryBot.build(:vm_vmware)) - ems = FactoryGirl.create(:ext_management_system, :zone => FactoryGirl.create(:zone)) - vm = FactoryGirl.create(:vm_vmware, :ext_management_system => ems) + ems = FactoryBot.create(:ext_management_system, :zone => FactoryBot.create(:zone)) + vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems) service.add_resource!(vm) @@ -746,8 +746,8 @@ end describe '#add_to_service' do - let(:service) { FactoryGirl.create(:service) } - let(:child_service) { FactoryGirl.create(:service) } + let(:service) { FactoryBot.create(:service) } + let(:child_service) { FactoryBot.create(:service) } it 'associates a child_service to the service' do expect(child_service.add_to_service(service)).to be_kind_of(ServiceResource) @@ -763,8 +763,8 @@ end describe '#remove_from_service' do - let(:service) { FactoryGirl.create(:service) } - let(:child_service) { FactoryGirl.create(:service) } + let(:service) { FactoryBot.create(:service) } + let(:child_service) { FactoryBot.create(:service) } it 'removes child_service from the service' do child_service.add_to_service(service) @@ -814,17 +814,17 @@ end def create_deep_tree - @service = FactoryGirl.create(:service) - @service_c1 = FactoryGirl.create(:service, :service => @service) - @service_c11 = FactoryGirl.create(:service, :service => @service_c1) - @service_c12 = FactoryGirl.create(:service, :service => @service_c1) - @service_c121 = FactoryGirl.create(:service, :service => @service_c12) - @service_c2 = FactoryGirl.create(:service, :service => @service) + @service = FactoryBot.create(:service) + @service_c1 = FactoryBot.create(:service, :service => @service) + @service_c11 = FactoryBot.create(:service, :service => @service_c1) + @service_c12 = FactoryBot.create(:service, :service => @service_c1) + @service_c121 = FactoryBot.create(:service, :service => @service_c12) + @service_c2 = FactoryBot.create(:service, :service => @service) end context "custom actions" do - let(:service_template) { FactoryGirl.create(:service_template) } - let(:service) { FactoryGirl.create(:service, :service_template => service_template) } + let(:service_template) { FactoryBot.create(:service_template) } + let(:service) { FactoryBot.create(:service, :service_template => service_template) } context "with template" do describe "#custom_actions" do @@ -843,8 +843,8 @@ def create_deep_tree end context "without template" do - let!(:custom_button) { FactoryGirl.create(:custom_button, :applies_to_class => "Service") } - let(:service) { FactoryGirl.create(:service, :service_template_id => -1) } + let!(:custom_button) { FactoryBot.create(:custom_button, :applies_to_class => "Service") } + let(:service) { FactoryBot.create(:service, :service_template_id => -1) } describe "#custom_action_buttons" do it "get list of custom action buttons on services" do diff --git a/spec/models/service_template_ansible_playbook_spec.rb b/spec/models/service_template_ansible_playbook_spec.rb index 0383bf7a8d2..9b94df36db9 100644 --- a/spec/models/service_template_ansible_playbook_spec.rb +++ b/spec/models/service_template_ansible_playbook_spec.rb @@ -1,23 +1,23 @@ describe ServiceTemplateAnsiblePlaybook do - let(:user) { FactoryGirl.create(:user_with_group) } - let(:auth_one) { FactoryGirl.create(:embedded_ansible_credential, :manager_ref => '6') } - let(:auth_two) { FactoryGirl.create(:embedded_ansible_credential, :manager_ref => '10') } - let(:auth_three) { FactoryGirl.create(:embedded_ansible_credential, :manager_ref => '14') } + let(:user) { FactoryBot.create(:user_with_group) } + let(:auth_one) { FactoryBot.create(:embedded_ansible_credential, :manager_ref => '6') } + let(:auth_two) { FactoryBot.create(:embedded_ansible_credential, :manager_ref => '10') } + let(:auth_three) { FactoryBot.create(:embedded_ansible_credential, :manager_ref => '14') } - let(:script_source) { FactoryGirl.create(:configuration_script_source, :manager => ems) } + let(:script_source) { FactoryBot.create(:configuration_script_source, :manager => ems) } - let(:service_template_catalog) { FactoryGirl.create(:service_template_catalog) } - let(:provider) { FactoryGirl.create(:provider_embedded_ansible, :default_inventory => 1) } - let(:ems) { FactoryGirl.create(:automation_manager_ansible_tower, :provider => provider) } + let(:service_template_catalog) { FactoryBot.create(:service_template_catalog) } + let(:provider) { FactoryBot.create(:provider_embedded_ansible, :default_inventory => 1) } + let(:ems) { FactoryBot.create(:automation_manager_ansible_tower, :provider => provider) } let(:playbook) do - FactoryGirl.create(:embedded_playbook, + FactoryBot.create(:embedded_playbook, :configuration_script_source => script_source, :manager => ems) end let(:job_template) do - FactoryGirl.create(:embedded_ansible_configuration_script, + FactoryBot.create(:embedded_ansible_configuration_script, :variables => catalog_item_options.fetch_path(:config_info, :provision, :extra_vars), :manager => ems) end @@ -277,7 +277,7 @@ end describe '#delete_job_templates' do - let(:service) { FactoryGirl.create(:service_ansible_tower) } + let(:service) { FactoryBot.create(:service_ansible_tower) } it 'destroys a job template if there is an associated configuration_template' do service_template = prebuild_service_template(:job_template => false) diff --git a/spec/models/service_template_ansible_tower_spec.rb b/spec/models/service_template_ansible_tower_spec.rb index a243e51d7c1..106f80b53bd 100644 --- a/spec/models/service_template_ansible_tower_spec.rb +++ b/spec/models/service_template_ansible_tower_spec.rb @@ -1,8 +1,8 @@ describe ServiceTemplateAnsibleTower do - let(:ra1) { FactoryGirl.create(:resource_action, :action => 'Provision') } - let(:ra2) { FactoryGirl.create(:resource_action, :action => 'Retirement') } - let(:service_dialog) { FactoryGirl.create(:dialog) } - let(:configuration_script) { FactoryGirl.create(:configuration_script) } + let(:ra1) { FactoryBot.create(:resource_action, :action => 'Provision') } + let(:ra2) { FactoryBot.create(:resource_action, :action => 'Retirement') } + let(:service_dialog) { FactoryBot.create(:dialog) } + let(:configuration_script) { FactoryBot.create(:configuration_script) } let(:catalog_item_options) do { :name => 'Ansible Tower', @@ -54,7 +54,7 @@ end describe '#update_catalog_item' do - let(:new_configuration_script) { FactoryGirl.create(:configuration_script) } + let(:new_configuration_script) { FactoryBot.create(:configuration_script) } let(:updated_catalog_item_options) do { :name => 'Updated Ansible Tower', @@ -112,9 +112,9 @@ describe '#config_info' do it 'returns the correct format' do - job_template = FactoryGirl.create(:configuration_script) - service_template = FactoryGirl.create(:service_template_ansible_tower, :job_template => job_template) - ra = FactoryGirl.create(:resource_action, :action => 'Provision', :fqname => '/a/b/c') + job_template = FactoryBot.create(:configuration_script) + service_template = FactoryBot.create(:service_template_ansible_tower, :job_template => job_template) + ra = FactoryBot.create(:resource_action, :action => 'Provision', :fqname => '/a/b/c') service_template.create_resource_actions(:provision => { :fqname => ra.fqname }) expected_config_info = { @@ -128,9 +128,9 @@ end describe '#my_zone' do - let(:manager) { FactoryGirl.create(:automation_manager_ansible_tower, :provider) } - let(:job_template) { FactoryGirl.create(:configuration_script, :manager => manager) } - let(:service_template) { FactoryGirl.create(:service_template_ansible_tower, :job_template => job_template) } + let(:manager) { FactoryBot.create(:automation_manager_ansible_tower, :provider) } + let(:job_template) { FactoryBot.create(:configuration_script, :manager => manager) } + let(:service_template) { FactoryBot.create(:service_template_ansible_tower, :job_template => job_template) } context "with job template manager" do it "takes the zone from job_template manager" do diff --git a/spec/models/service_template_catalog_spec.rb b/spec/models/service_template_catalog_spec.rb index 5e80f161c97..d41604f8350 100644 --- a/spec/models/service_template_catalog_spec.rb +++ b/spec/models/service_template_catalog_spec.rb @@ -5,17 +5,17 @@ describe "#name" do it "is unique per tenant" do - FactoryGirl.create(:service_template_catalog, :name => "common", :tenant => root_tenant) - expect { FactoryGirl.create(:service_template_catalog, :name => "common", :tenant => root_tenant) } + FactoryBot.create(:service_template_catalog, :name => "common", :tenant => root_tenant) + expect { FactoryBot.create(:service_template_catalog, :name => "common", :tenant => root_tenant) } .to raise_error(ActiveRecord::RecordInvalid, /Name has already been taken/) end it "can be the same across tenants" do - tenant1 = FactoryGirl.create(:tenant, :parent => root_tenant) - tenant2 = FactoryGirl.create(:tenant, :parent => root_tenant) - FactoryGirl.create(:service_template_catalog, :name => "common", :tenant => tenant1) + tenant1 = FactoryBot.create(:tenant, :parent => root_tenant) + tenant2 = FactoryBot.create(:tenant, :parent => root_tenant) + FactoryBot.create(:service_template_catalog, :name => "common", :tenant => tenant1) expect do - FactoryGirl.build(:service_template_catalog, :name => "common", :tenant => tenant2) + FactoryBot.build(:service_template_catalog, :name => "common", :tenant => tenant2) end.not_to raise_error end end diff --git a/spec/models/service_template_container_template_spec.rb b/spec/models/service_template_container_template_spec.rb index 2e8351737f0..f540ab4d75c 100644 --- a/spec/models/service_template_container_template_spec.rb +++ b/spec/models/service_template_container_template_spec.rb @@ -1,9 +1,9 @@ describe ServiceTemplateContainerTemplate do - let(:service_template_catalog) { FactoryGirl.create(:service_template_catalog) } - let(:container_template) { FactoryGirl.create(:container_template, :ems_id => ems.id) } - let(:ems) { FactoryGirl.create(:ems_openshift) } - let(:dialog) { FactoryGirl.create(:dialog) } - let(:dialog2) { FactoryGirl.create(:dialog) } + let(:service_template_catalog) { FactoryBot.create(:service_template_catalog) } + let(:container_template) { FactoryBot.create(:container_template, :ems_id => ems.id) } + let(:ems) { FactoryBot.create(:ems_openshift) } + let(:dialog) { FactoryBot.create(:dialog) } + let(:dialog2) { FactoryBot.create(:dialog) } let(:catalog_item_options) do { diff --git a/spec/models/service_template_orchestration_spec.rb b/spec/models/service_template_orchestration_spec.rb index ab322726369..31e66b5c6a2 100644 --- a/spec/models/service_template_orchestration_spec.rb +++ b/spec/models/service_template_orchestration_spec.rb @@ -1,5 +1,5 @@ describe ServiceTemplateOrchestration do - subject { FactoryGirl.create(:service_template_orchestration) } + subject { FactoryBot.create(:service_template_orchestration) } describe '#create_subtasks' do it 'does not need subtasks' do @@ -8,8 +8,8 @@ end describe "#orchestration_template" do - let(:first_orch_template) { FactoryGirl.create(:orchestration_template) } - let(:second_orch_template) { FactoryGirl.create(:orchestration_template) } + let(:first_orch_template) { FactoryBot.create(:orchestration_template) } + let(:second_orch_template) { FactoryBot.create(:orchestration_template) } it "initially reads a nil orchestration template" do expect(subject.orchestration_template).to be_nil @@ -46,8 +46,8 @@ end describe "#orchestration_manager" do - let(:ems_amazon) { FactoryGirl.create(:ems_amazon) } - let(:ems_openstack) { FactoryGirl.create(:ems_openstack) } + let(:ems_amazon) { FactoryBot.create(:ems_amazon) } + let(:ems_openstack) { FactoryBot.create(:ems_openstack) } it "initially reads a nil orchestration manager" do expect(subject.orchestration_manager).to be_nil @@ -85,7 +85,7 @@ describe "#my_zone" do context "with orchestration manager" do - let(:ems_amazon) { FactoryGirl.create(:ems_amazon) } + let(:ems_amazon) { FactoryBot.create(:ems_amazon) } before { subject.orchestration_manager = ems_amazon } it "takes the zone from orchestration manager" do @@ -101,11 +101,11 @@ end end - let(:ra1) { FactoryGirl.create(:resource_action, :action => 'Provision') } - let(:ra2) { FactoryGirl.create(:resource_action, :action => 'Retirement') } - let(:service_dialog) { FactoryGirl.create(:dialog) } - let(:template) { FactoryGirl.create(:orchestration_template) } - let(:manager) { FactoryGirl.create(:ext_management_system) } + let(:ra1) { FactoryBot.create(:resource_action, :action => 'Provision') } + let(:ra2) { FactoryBot.create(:resource_action, :action => 'Retirement') } + let(:service_dialog) { FactoryBot.create(:dialog) } + let(:template) { FactoryBot.create(:orchestration_template) } + let(:manager) { FactoryBot.create(:ext_management_system) } let(:catalog_item_options) do { :name => 'Orchestration Template', @@ -167,8 +167,8 @@ end describe '#update_catalog_item' do - let(:new_template) { FactoryGirl.create(:orchestration_template) } - let(:new_manager) { FactoryGirl.create(:ext_management_system) } + let(:new_template) { FactoryBot.create(:orchestration_template) } + let(:new_manager) { FactoryBot.create(:ext_management_system) } let(:updated_catalog_item_options) do { :name => 'Updated Orchestration Template', @@ -230,12 +230,12 @@ describe '#config_info' do it 'returns the correct format' do - template = FactoryGirl.create(:orchestration_template) - manager = FactoryGirl.create(:ext_management_system) - service_template = FactoryGirl.create(:service_template_orchestration, + template = FactoryBot.create(:orchestration_template) + manager = FactoryBot.create(:ext_management_system) + service_template = FactoryBot.create(:service_template_orchestration, :orchestration_template => template, :orchestration_manager => manager) - ra = FactoryGirl.create(:resource_action, :action => 'Provision', :fqname => '/a/b/c') + ra = FactoryBot.create(:resource_action, :action => 'Provision', :fqname => '/a/b/c') service_template.create_resource_actions(:provision => { :fqname => ra.fqname }) expected_config_info = { diff --git a/spec/models/service_template_provision_request_quota_spec.rb b/spec/models/service_template_provision_request_quota_spec.rb index 9e42a3bc17c..c068a5d89b7 100644 --- a/spec/models/service_template_provision_request_quota_spec.rb +++ b/spec/models/service_template_provision_request_quota_spec.rb @@ -2,11 +2,11 @@ include Spec::Support::QuotaHelper include Spec::Support::ServiceTemplateHelper - let(:admin) { FactoryGirl.create(:user_admin) } + let(:admin) { FactoryBot.create(:user_admin) } context "quota methods" do context "for cloud and infra providers," do def create_request(user, template, prov_options = {}) - FactoryGirl.create(:service_template_provision_request, :requester => user, + FactoryBot.create(:service_template_provision_request, :requester => user, :description => "request", :tenant_id => user.current_tenant.id, :source_type => "ServiceTemplate", @@ -38,13 +38,13 @@ def create_service_bundle(user, items, options = {}) context "infra," do let(:vmware_requests) do - ems = FactoryGirl.create(:ems_vmware) - group = FactoryGirl.create(:miq_group, :tenant => FactoryGirl.create(:tenant)) - @vmware_user1 = FactoryGirl.create(:user_with_email, :miq_groups => [group]) - @vmware_user2 = FactoryGirl.create(:user_with_email, :miq_groups => [group]) - @vmware_template = FactoryGirl.create(:template_vmware, + ems = FactoryBot.create(:ems_vmware) + group = FactoryBot.create(:miq_group, :tenant => FactoryBot.create(:tenant)) + @vmware_user1 = FactoryBot.create(:user_with_email, :miq_groups => [group]) + @vmware_user2 = FactoryBot.create(:user_with_email, :miq_groups => [group]) + @vmware_template = FactoryBot.create(:template_vmware, :ext_management_system => ems, - :hardware => FactoryGirl.create(:hardware, :cpu1x2, :memory_mb => 512)) + :hardware => FactoryBot.create(:hardware, :cpu1x2, :memory_mb => 512)) @vmware_prov_options = {:number_of_vms => [2, '2'], :vm_memory => [1024, '1024'], :number_of_cpus => [2, '2']} requests = [] @@ -112,14 +112,14 @@ def build_google_service_item end let(:google_requests) do - ems = FactoryGirl.create(:ems_google_with_authentication, - :availability_zones => [FactoryGirl.create(:availability_zone_google)]) - group = FactoryGirl.create(:miq_group, :tenant => FactoryGirl.create(:tenant)) - @google_user1 = FactoryGirl.create(:user_with_email, :miq_groups => [group]) - @google_user2 = FactoryGirl.create(:user_with_email, :miq_groups => [group]) - - @google_template = FactoryGirl.create(:template_google, :ext_management_system => ems) - flavor = FactoryGirl.create(:flavor_google, :ems_id => ems.id, + ems = FactoryBot.create(:ems_google_with_authentication, + :availability_zones => [FactoryBot.create(:availability_zone_google)]) + group = FactoryBot.create(:miq_group, :tenant => FactoryBot.create(:tenant)) + @google_user1 = FactoryBot.create(:user_with_email, :miq_groups => [group]) + @google_user2 = FactoryBot.create(:user_with_email, :miq_groups => [group]) + + @google_template = FactoryBot.create(:template_google, :ext_management_system => ems) + flavor = FactoryBot.create(:flavor_google, :ems_id => ems.id, :cpus => 4, :cpu_cores => 1, :memory => 1024) @google_prov_options = {:number_of_vms => [1, '1'], :src_vm_id => @google_template.id, :boot_disk_size => ["10.GB", "10 GB"], :placement_auto => [true, 1], :instance_type => [flavor.id, flavor.name]} diff --git a/spec/models/service_template_provision_request_spec.rb b/spec/models/service_template_provision_request_spec.rb index fe78d495a5f..924d5e1d9a0 100644 --- a/spec/models/service_template_provision_request_spec.rb +++ b/spec/models/service_template_provision_request_spec.rb @@ -1,13 +1,13 @@ describe ServiceTemplateProvisionRequest do - let(:admin) { FactoryGirl.create(:user_admin) } + let(:admin) { FactoryBot.create(:user_admin) } context "with multiple tasks" do before do - @request = FactoryGirl.create(:service_template_provision_request, :description => 'Service Request', :requester => admin) + @request = FactoryBot.create(:service_template_provision_request, :description => 'Service Request', :requester => admin) - @task_1 = FactoryGirl.create(:service_template_provision_task, :description => 'Task 1', :userid => admin.userid, :miq_request_id => @request.id) - @task_1_1 = FactoryGirl.create(:service_template_provision_task, :description => 'Task 1 - 1', :userid => admin.userid, :miq_request_id => @request.id) - @task_2 = FactoryGirl.create(:service_template_provision_task, :description => 'Task 2', :userid => admin.userid, :miq_request_id => @request.id) - @task_2_1 = FactoryGirl.create(:service_template_provision_task, :description => 'Task 2 - 1', :userid => admin.userid, :miq_request_id => @request.id) + @task_1 = FactoryBot.create(:service_template_provision_task, :description => 'Task 1', :userid => admin.userid, :miq_request_id => @request.id) + @task_1_1 = FactoryBot.create(:service_template_provision_task, :description => 'Task 1 - 1', :userid => admin.userid, :miq_request_id => @request.id) + @task_2 = FactoryBot.create(:service_template_provision_task, :description => 'Task 2', :userid => admin.userid, :miq_request_id => @request.id) + @task_2_1 = FactoryBot.create(:service_template_provision_task, :description => 'Task 2 - 1', :userid => admin.userid, :miq_request_id => @request.id) @task_1.miq_request_tasks << @task_1_1 @task_2.miq_request_tasks << @task_2_1 @@ -109,8 +109,8 @@ end describe "#make_request" do - let(:service_template) { FactoryGirl.create(:service_template, :name => "My Service Template") } - let(:alt_user) { FactoryGirl.create(:user_with_group) } + let(:service_template) { FactoryBot.create(:service_template, :name => "My Service Template") } + let(:alt_user) { FactoryBot.create(:user_with_group) } it "creates and update a request" do EvmSpecHelper.local_miq_server expect(AuditEvent).to receive(:success).with( diff --git a/spec/models/service_template_provision_task_spec.rb b/spec/models/service_template_provision_task_spec.rb index bfb05f946a9..33dd2ad1e44 100644 --- a/spec/models/service_template_provision_task_spec.rb +++ b/spec/models/service_template_provision_task_spec.rb @@ -1,9 +1,9 @@ describe ServiceTemplateProvisionTask do context "with multiple tasks" do before do - @admin = FactoryGirl.create(:user_with_group) + @admin = FactoryBot.create(:user_with_group) - @request = FactoryGirl.create(:service_template_provision_request, + @request = FactoryBot.create(:service_template_provision_request, :description => 'Service Request', :requester => @admin) @task_0 = create_stp('Task 0 (Top)') @@ -33,7 +33,7 @@ def create_stp(description, state = 'pending', prov_index = nil, scaling_max = n else options = {} end - FactoryGirl.create(:service_template_provision_task, + FactoryBot.create(:service_template_provision_task, :description => description, :userid => @admin.userid, :state => state, @@ -42,7 +42,7 @@ def create_stp(description, state = 'pending', prov_index = nil, scaling_max = n end def service_resource_id(index, scaling_max) - FactoryGirl.create(:service_resource, + FactoryBot.create(:service_resource, :provision_index => index, :scaling_min => 1, :scaling_max => scaling_max, @@ -77,12 +77,12 @@ def service_resource_id(index, scaling_max) describe "#deliver_to_automate" do it "delivers to the queue when the state is not active" do - @service = FactoryGirl.create(:service, :name => 'Test Service') + @service = FactoryBot.create(:service, :name => 'Test Service') @task_0.destination = @service @task_0.state = 'pending' - zone = FactoryGirl.create(:zone, :name => "special") - orchestration_manager = FactoryGirl.create(:ext_management_system, :zone => zone) - @task_0.source = FactoryGirl.create(:service_template_orchestration, :orchestration_manager => orchestration_manager) + zone = FactoryBot.create(:zone, :name => "special") + orchestration_manager = FactoryBot.create(:ext_management_system, :zone => zone) + @task_0.source = FactoryBot.create(:service_template_orchestration, :orchestration_manager => orchestration_manager) automate_args = { :object_type => 'ServiceTemplateProvisionTask', :object_id => @task_0.id, @@ -223,7 +223,7 @@ def service_resource_id(index, scaling_max) context "with a service" do before do - @service = FactoryGirl.create(:service, :name => 'Test Service') + @service = FactoryBot.create(:service, :name => 'Test Service') end it "raise provisioned event" do @@ -235,7 +235,7 @@ def service_resource_id(index, scaling_max) end describe "#mark_execution_servers" do - let(:server) { FactoryGirl.create(:miq_server) } + let(:server) { FactoryBot.create(:miq_server) } before { allow(MiqServer).to receive(:my_server).and_return(server) } it "with new server id" do diff --git a/spec/models/service_template_spec.rb b/spec/models/service_template_spec.rb index fa517ea39d7..2ddb4910dec 100644 --- a/spec/models/service_template_spec.rb +++ b/spec/models/service_template_spec.rb @@ -1,29 +1,29 @@ describe ServiceTemplate do include_examples "OwnershipMixin" - let(:service_user) { FactoryGirl.build(:user) } + let(:service_user) { FactoryBot.build(:user) } describe "#custom_actions" do it "returns the custom actions in a hash grouped by buttons and button groups" do - FactoryGirl.create(:custom_button, :name => "generic_no_group", :applies_to_class => "Service") - generic_group = FactoryGirl.create(:custom_button, :name => "generic_group", :applies_to_class => "Service") - generic_group_set = FactoryGirl.create(:custom_button_set, :name => "generic_group_set") + FactoryBot.create(:custom_button, :name => "generic_no_group", :applies_to_class => "Service") + generic_group = FactoryBot.create(:custom_button, :name => "generic_group", :applies_to_class => "Service") + generic_group_set = FactoryBot.create(:custom_button_set, :name => "generic_group_set") generic_group_set.add_member(generic_group) - service_template = FactoryGirl.create(:service_template) - FactoryGirl.create( + service_template = FactoryBot.create(:service_template) + FactoryBot.create( :custom_button, :name => "assigned_no_group", :applies_to_class => "ServiceTemplate", :applies_to_id => service_template.id ) - assigned_group = FactoryGirl.create( + assigned_group = FactoryBot.create( :custom_button, :name => "assigned_group", :applies_to_class => "ServiceTemplate", :applies_to_id => service_template.id ) - assigned_group_set = FactoryGirl.create(:custom_button_set, :name => "assigned_group_set") + assigned_group_set = FactoryBot.create(:custom_button_set, :name => "assigned_group_set") assigned_group_set.add_member(assigned_group) service_template.update(:custom_button_sets => [assigned_group_set]) @@ -47,24 +47,24 @@ end it "does not show hidden buttons" do - service_template = FactoryGirl.create(:service_template) - service = FactoryGirl.create(:service, :name => "foo", :service_template => service_template) + service_template = FactoryBot.create(:service_template) + service = FactoryBot.create(:service, :name => "foo", :service_template => service_template) true_expression = MiqExpression.new("=" => {"field" => "Service-name", "value" => "foo"}) false_expression = MiqExpression.new("=" => {"field" => "Service-name", "value" => "labar"}) - FactoryGirl.create(:custom_button, + FactoryBot.create(:custom_button, :name => "visible button", :applies_to_class => "Service", :visibility_expression => true_expression) - FactoryGirl.create(:custom_button, + FactoryBot.create(:custom_button, :name => "hidden button", :applies_to_class => "Service", :visibility_expression => false_expression) - FactoryGirl.create(:custom_button_set).tap do |group| - group.add_member(FactoryGirl.create(:custom_button, + FactoryBot.create(:custom_button_set).tap do |group| + group.add_member(FactoryBot.create(:custom_button, :name => "visible button in group", :applies_to_class => "Service", :visibility_expression => true_expression)) - group.add_member(FactoryGirl.create(:custom_button, + group.add_member(FactoryBot.create(:custom_button, :name => "hidden button in group", :applies_to_class => "Service", :visibility_expression => false_expression)) @@ -86,8 +86,8 @@ end context "expression evaluation" do - let(:service_template) { FactoryGirl.create(:service_template, :prov_type=> "vmware") } - let(:service) { FactoryGirl.create(:service, :name => "foo", :service_template => service_template) } + let(:service_template) { FactoryBot.create(:service_template, :prov_type=> "vmware") } + let(:service) { FactoryBot.create(:service, :name => "foo", :service_template => service_template) } let(:true_expression_on_template) do MiqExpression.new("=" => {"field" => "ServiceTemplate-prov_type", "value" => "vmware"}) end @@ -102,20 +102,20 @@ end before do - FactoryGirl.create(:custom_button, + FactoryBot.create(:custom_button, :name => "visible button on service", :applies_to_class => "Service", :visibility_expression => true_expression_on_service) - FactoryGirl.create(:custom_button, + FactoryBot.create(:custom_button, :name => "hidden button on service", :applies_to_class => "Service", :visibility_expression => false_expression_on_service) - FactoryGirl.create(:custom_button, + FactoryBot.create(:custom_button, :name => "visible button on template", :applies_to_class => "ServiceTemplate", :applies_to_id => service_template.id, :visibility_expression => true_expression_on_template) - FactoryGirl.create(:custom_button, + FactoryBot.create(:custom_button, :name => "hidden visible button on template", :applies_to_class => "ServiceTemplate", :applies_to_id => service_template.id, @@ -145,24 +145,24 @@ end it "serializes the enablement" do - service_template = FactoryGirl.create(:service_template, :name => "foo") - service = FactoryGirl.create(:service, :name => "bar", :service_template => service_template) + service_template = FactoryBot.create(:service_template, :name => "foo") + service = FactoryBot.create(:service, :name => "bar", :service_template => service_template) true_expression = MiqExpression.new("=" => {"field" => "Service-name", "value" => "bar"}) false_expression = MiqExpression.new("=" => {"field" => "Service-name", "value" => "foo"}) - FactoryGirl.create(:custom_button, + FactoryBot.create(:custom_button, :name => "enabled button", :applies_to_class => "Service", :enablement_expression => true_expression) - FactoryGirl.create(:custom_button, + FactoryBot.create(:custom_button, :name => "disabled button", :applies_to_class => "Service", :enablement_expression => false_expression) - FactoryGirl.create(:custom_button_set).tap do |group| - group.add_member(FactoryGirl.create(:custom_button, + FactoryBot.create(:custom_button_set).tap do |group| + group.add_member(FactoryBot.create(:custom_button, :name => "enabled button in group", :applies_to_class => "Service", :enablement_expression => true_expression)) - group.add_member(FactoryGirl.create(:custom_button, + group.add_member(FactoryBot.create(:custom_button, :name => "disabled button in group", :applies_to_class => "Service", :enablement_expression => false_expression)) @@ -188,26 +188,26 @@ describe "#custom_action_buttons" do it "does not show hidden buttons" do - service_template = FactoryGirl.create(:service_template, :name => "foo") + service_template = FactoryBot.create(:service_template, :name => "foo") true_expression = MiqExpression.new("=" => {"field" => "ServiceTemplate-name", "value" => "foo"}) false_expression = MiqExpression.new("=" => {"field" => "ServiceTemplate-name", "value" => "bar"}) - visible_button = FactoryGirl.create(:custom_button, + visible_button = FactoryBot.create(:custom_button, :applies_to_class => "ServiceTemplate", :applies_to_id => service_template.id, :visibility_expression => true_expression) - _hidden_button = FactoryGirl.create(:custom_button, + _hidden_button = FactoryBot.create(:custom_button, :applies_to_class => "ServiceTemplate", :applies_to_id => service_template.id, :visibility_expression => false_expression) - visible_button_in_group = FactoryGirl.create(:custom_button, + visible_button_in_group = FactoryBot.create(:custom_button, :applies_to_class => "ServiceTemplate", :applies_to_id => service_template.id, :visibility_expression => true_expression) - hidden_button_in_group = FactoryGirl.create(:custom_button, + hidden_button_in_group = FactoryBot.create(:custom_button, :applies_to_class => "ServiceTemplate", :applies_to_id => service_template.id, :visibility_expression => false_expression) - service_template.custom_button_sets << FactoryGirl.create(:custom_button_set).tap do |group| + service_template.custom_button_sets << FactoryBot.create(:custom_button_set).tap do |group| group.add_member(visible_button_in_group) group.add_member(hidden_button_in_group) end @@ -218,7 +218,7 @@ context "#type_display" do before do - @st1 = FactoryGirl.create(:service_template, :name => 'Service Template 1') + @st1 = FactoryBot.create(:service_template, :name => 'Service Template 1') end it "with default service_type" do @@ -249,7 +249,7 @@ context "#atomic?" do before do - @st1 = FactoryGirl.create(:service_template) + @st1 = FactoryBot.create(:service_template) end it "with service_type of unknown" do @@ -270,7 +270,7 @@ context "#composite?" do before do - @st1 = FactoryGirl.create(:service_template) + @st1 = FactoryBot.create(:service_template) end it "with service_type of unknown" do @@ -292,7 +292,7 @@ context "initiator" do shared_examples_for 'initiator example' do |initiator, match| it 'test initiator' do - svc_template = FactoryGirl.create(:service_template, :name => 'Svc A') + svc_template = FactoryBot.create(:service_template, :name => 'Svc A') options = {:dialog => {}} options[:initiator] = initiator if initiator svc_task = instance_double("service_task", :options => options, :get_user => service_user) @@ -313,11 +313,11 @@ context "with multiple services" do before do - @svc_a = FactoryGirl.create(:service_template, :name => 'Svc A') - @svc_b = FactoryGirl.create(:service_template, :name => 'Svc B') - @svc_c = FactoryGirl.create(:service_template, :name => 'Svc C') - @svc_d = FactoryGirl.create(:service_template, :name => 'Svc D') - @svc_e = FactoryGirl.create(:service_template, :name => 'Svc E') + @svc_a = FactoryBot.create(:service_template, :name => 'Svc A') + @svc_b = FactoryBot.create(:service_template, :name => 'Svc B') + @svc_c = FactoryBot.create(:service_template, :name => 'Svc C') + @svc_d = FactoryBot.create(:service_template, :name => 'Svc D') + @svc_e = FactoryBot.create(:service_template, :name => 'Svc E') end it "should return level 1 sub-services" do @@ -357,18 +357,18 @@ describe "#create_service" do let(:service_task) do - FactoryGirl.create(:service_template_provision_task, + FactoryBot.create(:service_template_provision_task, :miq_request => service_template_request, :options => {:service_resource_id => service_resource.id}) end - let(:service_template_request) { FactoryGirl.create(:service_template_provision_request, :requester => user) } + let(:service_template_request) { FactoryBot.create(:service_template_provision_request, :requester => user) } let(:service_resource) do - FactoryGirl.create(:service_resource, + FactoryBot.create(:service_resource, :resource_type => 'MiqRequest', :resource_id => service_template_request.id) end - let(:user) { FactoryGirl.create(:user) } - let(:parent_service) { FactoryGirl.create(:service) } + let(:user) { FactoryBot.create(:user) } + let(:parent_service) { FactoryBot.create(:service) } it "create service sets parent service resource resource id" do @svc_a.create_service(service_task, parent_service) @@ -457,7 +457,7 @@ end it "should allow service template to connect to a service with the same id" do - svc = FactoryGirl.create(:service) + svc = FactoryBot.create(:service) svc.id = @svc_a.id expect { svc << @svc_a }.to_not raise_error end @@ -477,9 +477,9 @@ context "with a small env" do before do - @zone1 = FactoryGirl.create(:small_environment) + @zone1 = FactoryBot.create(:small_environment) allow(MiqServer).to receive(:my_server).and_return(@zone1.miq_servers.first) - @st1 = FactoryGirl.create(:service_template, :name => 'Service Template 1') + @st1 = FactoryBot.create(:service_template, :name => 'Service Template 1') end it "should create a valid service template" do @@ -490,15 +490,15 @@ it "should not set the owner for the service template" do @user = nil - @test_service = FactoryGirl.create(:service, :name => 'test service') + @test_service = FactoryBot.create(:service, :name => 'test service') expect(@test_service.evm_owner).to be_nil @st1.set_ownership(@test_service, @user) expect(@test_service.evm_owner).to be_nil end it "should set the owner and group for the service template" do - @user = FactoryGirl.create(:user_with_group) - @test_service = FactoryGirl.create(:service, :name => 'test service') + @user = FactoryBot.create(:user_with_group) + @test_service = FactoryBot.create(:service, :name => 'test service') expect(@test_service.evm_owner).to be_nil @st1.set_ownership(@test_service, @user) expect(@test_service.evm_owner.name).to eq(@user.name) @@ -507,7 +507,7 @@ end it "should create a composite service template" do - st2 = FactoryGirl.create(:service_template, :name => 'Service Template 2') + st2 = FactoryBot.create(:service_template, :name => 'Service Template 2') @st1.add_resource(st2) expect(@st1.service_resources.size).to eq(1) expect(@st1.composite?).to be_truthy @@ -524,10 +524,10 @@ context "with a VM Provision Request Template" do before do - admin = FactoryGirl.create(:user_admin) + admin = FactoryBot.create(:user_admin) vm_template = Vm.first - ptr = FactoryGirl.create(:miq_provision_request_template, :requester => admin, :src_vm_id => vm_template.id) + ptr = FactoryBot.create(:miq_provision_request_template, :requester => admin, :src_vm_id => vm_template.id) @st1.add_resource(ptr) end @@ -549,11 +549,11 @@ context 'validate template' do before do - @st1 = FactoryGirl.create(:service_template, :name => 'Service Template 1') + @st1 = FactoryBot.create(:service_template, :name => 'Service Template 1') - user = FactoryGirl.create(:user, :name => 'Fred Flintstone', :userid => 'fred') - @vm_template = FactoryGirl.create(:template_vmware, :ext_management_system => FactoryGirl.create(:ems_vmware_with_authentication)) - @ptr = FactoryGirl.create(:miq_provision_request_template, :requester => user, :src_vm_id => @vm_template.id) + user = FactoryBot.create(:user, :name => 'Fred Flintstone', :userid => 'fred') + @vm_template = FactoryBot.create(:template_vmware, :ext_management_system => FactoryBot.create(:ems_vmware_with_authentication)) + @ptr = FactoryBot.create(:miq_provision_request_template, :requester => user, :src_vm_id => @vm_template.id) end context 'atomic' do @@ -600,7 +600,7 @@ context 'composite' do before do @st1.add_resource(@ptr) - @st2 = FactoryGirl.create(:service_template, :name => 'Service Template 2') + @st2 = FactoryBot.create(:service_template, :name => 'Service Template 2') @st2.add_resource(@st1) end @@ -652,16 +652,16 @@ describe "#provision_action" do it "returns the provision action" do - provision_action = FactoryGirl.create(:resource_action, :action => "Provision") - service_template = FactoryGirl.create(:service_template, :resource_actions => [provision_action]) + provision_action = FactoryBot.create(:resource_action, :action => "Provision") + service_template = FactoryBot.create(:service_template, :resource_actions => [provision_action]) expect(service_template.provision_action).to eq(provision_action) end end describe '#config_info' do before do - @user = FactoryGirl.create(:user_with_group) - @ra = FactoryGirl.create(:resource_action, :action => 'Provision', :fqname => '/a/b/c') + @user = FactoryBot.create(:user_with_group) + @ra = FactoryBot.create(:resource_action, :action => 'Provision', :fqname => '/a/b/c') end it 'returns the config_info passed to #create_catalog_item' do @@ -682,9 +682,9 @@ end it 'will build the config_info if not created through #create_catalog_item' do - dialog = FactoryGirl.create(:dialog) - template = FactoryGirl.create(:service_template) - request = FactoryGirl.create(:service_template_provision_request, + dialog = FactoryBot.create(:dialog) + template = FactoryBot.create(:service_template) + request = FactoryBot.create(:service_template_provision_request, :requester => @user, :options => {:foo => 'bar', :baz => nil }) template.create_resource_actions(:provision => { :fqname => @ra.fqname, :dialog_id => dialog.id }) @@ -716,14 +716,14 @@ end end - let(:user) { FactoryGirl.create(:user_with_group) } - let(:ra1) { FactoryGirl.create(:resource_action, :action => 'Provision') } - let(:ra2) { FactoryGirl.create(:resource_action, :action => 'Retirement') } - let(:ems) { FactoryGirl.create(:ems_amazon) } - let(:vm) { FactoryGirl.create(:vm_amazon, :ext_management_system => ems) } - let(:flavor) { FactoryGirl.create(:flavor_amazon) } - let(:request_dialog) { FactoryGirl.create(:miq_dialog_provision) } - let(:service_dialog) { FactoryGirl.create(:dialog) } + let(:user) { FactoryBot.create(:user_with_group) } + let(:ra1) { FactoryBot.create(:resource_action, :action => 'Provision') } + let(:ra2) { FactoryBot.create(:resource_action, :action => 'Retirement') } + let(:ems) { FactoryBot.create(:ems_amazon) } + let(:vm) { FactoryBot.create(:vm_amazon, :ext_management_system => ems) } + let(:flavor) { FactoryBot.create(:flavor_amazon) } + let(:request_dialog) { FactoryBot.create(:miq_dialog_provision) } + let(:service_dialog) { FactoryBot.create(:dialog) } let(:catalog_item_options) do { :name => 'Atomic Service Template', @@ -769,7 +769,7 @@ end describe '#update_catalog_item' do - let(:new_vm) { FactoryGirl.create(:vm_amazon, :ext_management_system => ems) } + let(:new_vm) { FactoryBot.create(:vm_amazon, :ext_management_system => ems) } let(:updated_catalog_item_options) do { :name => 'Updated Template Name', @@ -846,11 +846,11 @@ end context "#order" do - let(:user) { FactoryGirl.create(:user, :userid => "barney") } - let(:resource_action) { FactoryGirl.create(:resource_action, :action => "Provision") } - let(:service_template) { FactoryGirl.create(:service_template, :resource_actions => [resource_action]) } + let(:user) { FactoryBot.create(:user, :userid => "barney") } + let(:resource_action) { FactoryBot.create(:resource_action, :action => "Provision") } + let(:service_template) { FactoryBot.create(:service_template, :resource_actions => [resource_action]) } let(:resource_action_options) { {:target => service_template, :initiator => 'control', :submit_workflow => true} } - let(:miq_request) { FactoryGirl.create(:service_template_provision_request) } + let(:miq_request) { FactoryBot.create(:service_template_provision_request) } let!(:resource_action_workflow) { ResourceActionWorkflow.new({}, user, resource_action, resource_action_options) } before do @@ -1001,7 +1001,7 @@ end it "returns orchestration template and generic" do - FactoryGirl.create(:orchestration_template) + FactoryBot.create(:orchestration_template) expect(ServiceTemplate.catalog_item_types).to match( hash_including('amazon' => { :description => 'Amazon', :display => false }, @@ -1014,7 +1014,7 @@ end context "#archive" do - let(:service_template) { FactoryGirl.create(:service_template, :miq_requests => miq_requests) } + let(:service_template) { FactoryBot.create(:service_template, :miq_requests => miq_requests) } context "with no MiqRequests" do let(:miq_requests) { [] } @@ -1025,7 +1025,7 @@ end context "with no active MiqRequests" do - let(:miq_requests) { [FactoryGirl.create(:service_template_provision_request, :request_state => "finished")] } + let(:miq_requests) { [FactoryBot.create(:service_template_provision_request, :request_state => "finished")] } it "archives the service_template" do service_template.archive expect(service_template.reload.archived?).to be_truthy @@ -1035,8 +1035,8 @@ context "with an active MiqRequest" do let(:miq_requests) do [ - FactoryGirl.create(:service_template_provision_request, :request_state => "finished"), - FactoryGirl.create(:service_template_provision_request, :request_state => "queued"), + FactoryBot.create(:service_template_provision_request, :request_state => "finished"), + FactoryBot.create(:service_template_provision_request, :request_state => "queued"), ] end diff --git a/spec/models/service_template_transformation_plan_request_spec.rb b/spec/models/service_template_transformation_plan_request_spec.rb index f611017466d..262df04adda 100644 --- a/spec/models/service_template_transformation_plan_request_spec.rb +++ b/spec/models/service_template_transformation_plan_request_spec.rb @@ -1,13 +1,13 @@ describe ServiceTemplateTransformationPlanRequest do - let(:vms) { Array.new(3) { FactoryGirl.create(:vm_or_template) } } + let(:vms) { Array.new(3) { FactoryBot.create(:vm_or_template) } } let(:vm_requests) do [ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_FAILED, ServiceResource::STATUS_APPROVED].zip(vms).collect do |status, vm| ServiceResource.new(:resource => vm, :status => status) end end - let(:plan) { FactoryGirl.create(:service_template_transformation_plan, :service_resources => vm_requests) } - let(:request) { FactoryGirl.create(:service_template_transformation_plan_request, :source => plan) } + let(:plan) { FactoryBot.create(:service_template_transformation_plan, :service_resources => vm_requests) } + let(:request) { FactoryBot.create(:service_template_transformation_plan_request, :source => plan) } describe '#requested_task_idx' do it 'selects approved vm requests' do @@ -31,12 +31,12 @@ describe '#validate_conversion_hosts' do context 'no conversion host exists in EMS' do - let(:dst_ems) { FactoryGirl.create(:ext_management_system) } - let(:src_cluster) { FactoryGirl.create(:ems_cluster) } - let(:dst_cluster) { FactoryGirl.create(:ems_cluster, :ext_management_system => dst_ems) } + let(:dst_ems) { FactoryBot.create(:ext_management_system) } + let(:src_cluster) { FactoryBot.create(:ems_cluster) } + let(:dst_cluster) { FactoryBot.create(:ems_cluster, :ext_management_system => dst_ems) } let(:mapping) do - FactoryGirl.create( + FactoryBot.create( :transformation_mapping, :transformation_mapping_items => [TransformationMappingItem.new(:source => src_cluster, :destination => dst_cluster)] ) @@ -57,22 +57,22 @@ end let(:plan) { ServiceTemplateTransformationPlan.create_catalog_item(catalog_item_options) } - let(:request) { FactoryGirl.create(:service_template_transformation_plan_request, :source => plan) } + let(:request) { FactoryBot.create(:service_template_transformation_plan_request, :source => plan) } it 'returns false' do - host = FactoryGirl.create(:host, :ext_management_system => FactoryGirl.create(:ext_management_system, :zone => FactoryGirl.create(:zone))) - conversion_host = FactoryGirl.create(:conversion_host, :resource => host) + host = FactoryBot.create(:host, :ext_management_system => FactoryBot.create(:ext_management_system, :zone => FactoryBot.create(:zone))) + conversion_host = FactoryBot.create(:conversion_host, :resource => host) expect(request.validate_conversion_hosts).to be false end end context 'conversion host exists in EMS and resource is a Host' do - let(:dst_ems) { FactoryGirl.create(:ems_redhat) } - let(:src_cluster) { FactoryGirl.create(:ems_cluster) } - let(:dst_cluster) { FactoryGirl.create(:ems_cluster, :ext_management_system => dst_ems) } + let(:dst_ems) { FactoryBot.create(:ems_redhat) } + let(:src_cluster) { FactoryBot.create(:ems_cluster) } + let(:dst_cluster) { FactoryBot.create(:ems_cluster, :ext_management_system => dst_ems) } let(:mapping) do - FactoryGirl.create( + FactoryBot.create( :transformation_mapping, :transformation_mapping_items => [TransformationMappingItem.new(:source => src_cluster, :destination => dst_cluster)] ) @@ -93,22 +93,22 @@ end let(:plan) { ServiceTemplateTransformationPlan.create_catalog_item(catalog_item_options) } - let(:request) { FactoryGirl.create(:service_template_transformation_plan_request, :source => plan) } + let(:request) { FactoryBot.create(:service_template_transformation_plan_request, :source => plan) } it 'returns true' do - host = FactoryGirl.create(:host, :ext_management_system => dst_ems, :ems_cluster => dst_cluster) - conversion_host = FactoryGirl.create(:conversion_host, :resource => host) + host = FactoryBot.create(:host, :ext_management_system => dst_ems, :ems_cluster => dst_cluster) + conversion_host = FactoryBot.create(:conversion_host, :resource => host) expect(request.validate_conversion_hosts).to be true end end context 'conversion host exists in EMS and resource is a Vm' do - let(:dst_ems) { FactoryGirl.create(:ems_openstack) } - let(:src_cluster) { FactoryGirl.create(:ems_cluster) } - let(:dst_cloud_tenant) { FactoryGirl.create(:cloud_tenant, :ext_management_system => dst_ems) } + let(:dst_ems) { FactoryBot.create(:ems_openstack) } + let(:src_cluster) { FactoryBot.create(:ems_cluster) } + let(:dst_cloud_tenant) { FactoryBot.create(:cloud_tenant, :ext_management_system => dst_ems) } let(:mapping) do - FactoryGirl.create( + FactoryBot.create( :transformation_mapping, :transformation_mapping_items => [TransformationMappingItem.new(:source => src_cluster, :destination => dst_cloud_tenant)] ) @@ -129,11 +129,11 @@ end let(:plan) { ServiceTemplateTransformationPlan.create_catalog_item(catalog_item_options) } - let(:request) { FactoryGirl.create(:service_template_transformation_plan_request, :source => plan) } + let(:request) { FactoryBot.create(:service_template_transformation_plan_request, :source => plan) } it 'returns true' do - vm = FactoryGirl.create(:vm_openstack, :ext_management_system => dst_ems, :cloud_tenant => dst_cloud_tenant) - conversion_host = FactoryGirl.create(:conversion_host, :resource => vm) + vm = FactoryBot.create(:vm_openstack, :ext_management_system => dst_ems, :cloud_tenant => dst_cloud_tenant) + conversion_host = FactoryBot.create(:conversion_host, :resource => vm) expect(request.validate_conversion_hosts).to be true end end diff --git a/spec/models/service_template_transformation_plan_spec.rb b/spec/models/service_template_transformation_plan_spec.rb index 8a85f50496c..8f90cced140 100644 --- a/spec/models/service_template_transformation_plan_spec.rb +++ b/spec/models/service_template_transformation_plan_spec.rb @@ -1,5 +1,5 @@ describe ServiceTemplateTransformationPlan do - subject { FactoryGirl.create(:service_template_transformation_plan) } + subject { FactoryBot.create(:service_template_transformation_plan) } describe '#request_class' do it { expect(subject.request_class).to eq(ServiceTemplateTransformationPlanRequest) } @@ -16,16 +16,16 @@ end end - let(:transformation_mapping) { FactoryGirl.create(:transformation_mapping) } - let(:transformation_mapping2) { FactoryGirl.create(:transformation_mapping) } - let(:apst) { FactoryGirl.create(:service_template_ansible_playbook) } - let(:vm1) { FactoryGirl.create(:vm_or_template) } - let(:vm2) { FactoryGirl.create(:vm_or_template) } - let(:vm3) { FactoryGirl.create(:vm_or_template) } - let(:security_group1) { FactoryGirl.create(:security_group, :name => "default") } - let(:flavor1) { FactoryGirl.create(:flavor, :name => "large") } - let(:security_group2) { FactoryGirl.create(:security_group, :name => "default") } - let(:flavor2) { FactoryGirl.create(:flavor, :name => "medium") } + let(:transformation_mapping) { FactoryBot.create(:transformation_mapping) } + let(:transformation_mapping2) { FactoryBot.create(:transformation_mapping) } + let(:apst) { FactoryBot.create(:service_template_ansible_playbook) } + let(:vm1) { FactoryBot.create(:vm_or_template) } + let(:vm2) { FactoryBot.create(:vm_or_template) } + let(:vm3) { FactoryBot.create(:vm_or_template) } + let(:security_group1) { FactoryBot.create(:security_group, :name => "default") } + let(:flavor1) { FactoryBot.create(:flavor, :name => "large") } + let(:security_group2) { FactoryBot.create(:security_group, :name => "default") } + let(:flavor2) { FactoryBot.create(:flavor, :name => "medium") } let(:catalog_item_options) do { @@ -107,13 +107,13 @@ } end - let(:miq_requests) { [FactoryGirl.create(:service_template_transformation_plan_request, :request_state => "finished")] } - let(:miq_requests_with_in_progress_request) { [FactoryGirl.create(:service_template_transformation_plan_request, :request_state => "active")] } + let(:miq_requests) { [FactoryBot.create(:service_template_transformation_plan_request, :request_state => "finished")] } + let(:miq_requests_with_in_progress_request) { [FactoryBot.create(:service_template_transformation_plan_request, :request_state => "active")] } describe '.public_service_templates' do it 'display public service templates' do - st1 = FactoryGirl.create(:service_template_transformation_plan) - st2 = FactoryGirl.create(:service_template) + st1 = FactoryBot.create(:service_template_transformation_plan) + st2 = FactoryBot.create(:service_template) expect(st1.internal?).to be_truthy expect(st2.internal?).to be_falsey diff --git a/spec/models/service_template_transformation_plan_task_spec.rb b/spec/models/service_template_transformation_plan_task_spec.rb index dabdfb111a1..50332dda776 100644 --- a/spec/models/service_template_transformation_plan_task_spec.rb +++ b/spec/models/service_template_transformation_plan_task_spec.rb @@ -13,16 +13,16 @@ end context 'independent of provider' do - let(:src) { FactoryGirl.create(:ems_cluster) } - let(:dst) { FactoryGirl.create(:ems_cluster) } - let(:host) { FactoryGirl.create(:host, :ext_management_system => FactoryGirl.create(:ext_management_system, :zone => FactoryGirl.create(:zone))) } - let(:vm) { FactoryGirl.create(:vm_or_template) } - let(:vm2) { FactoryGirl.create(:vm_or_template) } - let(:apst) { FactoryGirl.create(:service_template_ansible_playbook) } - let(:conversion_host) { FactoryGirl.create(:conversion_host, :resource => host) } + let(:src) { FactoryBot.create(:ems_cluster) } + let(:dst) { FactoryBot.create(:ems_cluster) } + let(:host) { FactoryBot.create(:host, :ext_management_system => FactoryBot.create(:ext_management_system, :zone => FactoryBot.create(:zone))) } + let(:vm) { FactoryBot.create(:vm_or_template) } + let(:vm2) { FactoryBot.create(:vm_or_template) } + let(:apst) { FactoryBot.create(:service_template_ansible_playbook) } + let(:conversion_host) { FactoryBot.create(:conversion_host, :resource => host) } let(:mapping) do - FactoryGirl.create( + FactoryBot.create( :transformation_mapping, :transformation_mapping_items => [TransformationMappingItem.new(:source => src, :destination => dst)] ) @@ -46,9 +46,9 @@ let(:plan) { ServiceTemplateTransformationPlan.create_catalog_item(catalog_item_options) } - let(:request) { FactoryGirl.create(:service_template_transformation_plan_request, :source => plan) } - let(:task) { FactoryGirl.create(:service_template_transformation_plan_task, :miq_request => request, :request_type => 'transformation_plan', :source => vm) } - let(:task2) { FactoryGirl.create(:service_template_transformation_plan_task, :miq_request => request, :request_type => 'transformation_plan', :source => vm2) } + let(:request) { FactoryBot.create(:service_template_transformation_plan_request, :source => plan) } + let(:task) { FactoryBot.create(:service_template_transformation_plan_task, :miq_request => request, :request_type => 'transformation_plan', :source => vm) } + let(:task2) { FactoryBot.create(:service_template_transformation_plan_task, :miq_request => request, :request_type => 'transformation_plan', :source => vm2) } describe '#resource_action' do it 'has a resource action points to the entry point for transformation' do @@ -208,20 +208,20 @@ end context 'populated request and task' do - let(:src_ems) { FactoryGirl.create(:ext_management_system, :zone => FactoryGirl.create(:zone)) } - let(:src_cluster) { FactoryGirl.create(:ems_cluster, :ext_management_system => src_ems) } - let(:dst_ems) { FactoryGirl.create(:ext_management_system, :zone => FactoryGirl.create(:zone)) } - let(:dst_cluster) { FactoryGirl.create(:ems_cluster, :ext_management_system => dst_ems) } + let(:src_ems) { FactoryBot.create(:ext_management_system, :zone => FactoryBot.create(:zone)) } + let(:src_cluster) { FactoryBot.create(:ems_cluster, :ext_management_system => src_ems) } + let(:dst_ems) { FactoryBot.create(:ext_management_system, :zone => FactoryBot.create(:zone)) } + let(:dst_cluster) { FactoryBot.create(:ems_cluster, :ext_management_system => dst_ems) } - let(:src_vm_1) { FactoryGirl.create(:vm_or_template, :ext_management_system => src_ems, :ems_cluster => src_cluster) } - let(:src_vm_2) { FactoryGirl.create(:vm_or_template, :ext_management_system => src_ems, :ems_cluster => src_cluster) } - let(:apst) { FactoryGirl.create(:service_template_ansible_playbook) } + let(:src_vm_1) { FactoryBot.create(:vm_or_template, :ext_management_system => src_ems, :ems_cluster => src_cluster) } + let(:src_vm_2) { FactoryBot.create(:vm_or_template, :ext_management_system => src_ems, :ems_cluster => src_cluster) } + let(:apst) { FactoryBot.create(:service_template_ansible_playbook) } - let(:dst_flavor) { FactoryGirl.create(:flavor) } - let(:dst_security_group) { FactoryGirl.create(:security_group) } + let(:dst_flavor) { FactoryBot.create(:flavor) } + let(:dst_security_group) { FactoryBot.create(:security_group) } let(:mapping) do - FactoryGirl.create( + FactoryBot.create( :transformation_mapping, :transformation_mapping_items => [TransformationMappingItem.new(:source => src_cluster, :destination => dst_cluster)] ) @@ -244,11 +244,11 @@ end let(:plan) { ServiceTemplateTransformationPlan.create_catalog_item(catalog_item_options) } - let(:request) { FactoryGirl.create(:service_template_transformation_plan_request, :source => plan) } - let(:task_1) { FactoryGirl.create(:service_template_transformation_plan_task, :miq_request => request, :request_type => 'transformation_plan', :source => src_vm_1) } - let(:task_2) { FactoryGirl.create(:service_template_transformation_plan_task, :miq_request => request, :request_type => 'transformation_plan', :source => src_vm_2) } + let(:request) { FactoryBot.create(:service_template_transformation_plan_request, :source => plan) } + let(:task_1) { FactoryBot.create(:service_template_transformation_plan_task, :miq_request => request, :request_type => 'transformation_plan', :source => src_vm_1) } + let(:task_2) { FactoryBot.create(:service_template_transformation_plan_task, :miq_request => request, :request_type => 'transformation_plan', :source => src_vm_2) } - let(:conversion_host) { FactoryGirl.create(:conversion_host, :resource => src_vm_1) } + let(:conversion_host) { FactoryBot.create(:conversion_host, :resource => src_vm_1) } describe '#transformation_destination' do it { expect(task_1.transformation_destination(src_cluster)).to eq(dst_cluster) } @@ -292,24 +292,24 @@ end context 'source is vmwarews' do - let(:src_ems) { FactoryGirl.create(:ems_vmware, :zone => FactoryGirl.create(:zone)) } - let(:src_host) { FactoryGirl.create(:host, :ext_management_system => src_ems, :ipaddress => '10.0.0.1') } - let(:src_storage) { FactoryGirl.create(:storage, :ext_management_system => src_ems) } + let(:src_ems) { FactoryBot.create(:ems_vmware, :zone => FactoryBot.create(:zone)) } + let(:src_host) { FactoryBot.create(:host, :ext_management_system => src_ems, :ipaddress => '10.0.0.1') } + let(:src_storage) { FactoryBot.create(:storage, :ext_management_system => src_ems) } - let(:src_lan_1) { FactoryGirl.create(:lan) } - let(:src_lan_2) { FactoryGirl.create(:lan) } - let(:src_nic_1) { FactoryGirl.create(:guest_device_nic, :lan => src_lan_1) } - let(:src_nic_2) { FactoryGirl.create(:guest_device_nic, :lan => src_lan_2) } + let(:src_lan_1) { FactoryBot.create(:lan) } + let(:src_lan_2) { FactoryBot.create(:lan) } + let(:src_nic_1) { FactoryBot.create(:guest_device_nic, :lan => src_lan_1) } + let(:src_nic_2) { FactoryBot.create(:guest_device_nic, :lan => src_lan_2) } let(:src_disk_1) { instance_double("disk", :device_name => "Hard disk 1", :device_type => "disk", :filename => "[datastore12] test_vm/test_vm.vmdk", :size => 17_179_869_184) } let(:src_disk_2) { instance_double("disk", :device_name => "Hard disk 2", :device_type => "disk", :filename => "[datastore12] test_vm/test_vm-2.vmdk", :size => 17_179_869_184) } - let(:src_hardware) { FactoryGirl.create(:hardware, :nics => [src_nic_1, src_nic_2]) } + let(:src_hardware) { FactoryBot.create(:hardware, :nics => [src_nic_1, src_nic_2]) } - let(:src_vm_1) { FactoryGirl.create(:vm_vmware, :ext_management_system => src_ems, :ems_cluster => src_cluster, :host => src_host, :hardware => src_hardware) } - let(:src_vm_2) { FactoryGirl.create(:vm_vmware, :ext_management_system => src_ems, :ems_cluster => src_cluster, :host => src_host) } + let(:src_vm_1) { FactoryBot.create(:vm_vmware, :ext_management_system => src_ems, :ems_cluster => src_cluster, :host => src_host, :hardware => src_hardware) } + let(:src_vm_2) { FactoryBot.create(:vm_vmware, :ext_management_system => src_ems, :ems_cluster => src_cluster, :host => src_host) } - let(:src_network) { FactoryGirl.create(:network, :ipaddress => '10.0.0.1') } + let(:src_network) { FactoryBot.create(:network, :ipaddress => '10.0.0.1') } # Disks have to be stubbed because there's no factory for Disk class before do @@ -423,14 +423,14 @@ end context 'destination is rhevm' do - let(:dst_ems) { FactoryGirl.create(:ems_redhat, :zone => FactoryGirl.create(:zone)) } - let(:dst_storage) { FactoryGirl.create(:storage) } - let(:dst_lan_1) { FactoryGirl.create(:lan) } - let(:dst_lan_2) { FactoryGirl.create(:lan) } - let(:conversion_host) { FactoryGirl.create(:conversion_host, :resource => FactoryGirl.create(:host, :ext_management_system => dst_ems)) } + let(:dst_ems) { FactoryBot.create(:ems_redhat, :zone => FactoryBot.create(:zone)) } + let(:dst_storage) { FactoryBot.create(:storage) } + let(:dst_lan_1) { FactoryBot.create(:lan) } + let(:dst_lan_2) { FactoryBot.create(:lan) } + let(:conversion_host) { FactoryBot.create(:conversion_host, :resource => FactoryBot.create(:host, :ext_management_system => dst_ems)) } let(:mapping) do - FactoryGirl.create( + FactoryBot.create( :transformation_mapping, :transformation_mapping_items => [ TransformationMappingItem.new(:source => src_cluster, :destination => dst_cluster), @@ -508,18 +508,18 @@ end context 'destination is openstack' do - let(:dst_ems) { FactoryGirl.create(:ems_openstack, :api_version => 'v3', :zone => FactoryGirl.create(:zone)) } - let(:dst_cloud_tenant) { FactoryGirl.create(:cloud_tenant, :name => 'fake tenant', :ext_management_system => dst_ems) } - let(:dst_cloud_volume_type) { FactoryGirl.create(:cloud_volume_type) } - let(:dst_cloud_network_1) { FactoryGirl.create(:cloud_network) } - let(:dst_cloud_network_2) { FactoryGirl.create(:cloud_network) } - let(:dst_flavor) { FactoryGirl.create(:flavor) } - let(:dst_security_group) { FactoryGirl.create(:security_group) } - let(:conversion_host_vm) { FactoryGirl.create(:vm_openstack, :ext_management_system => dst_ems, :cloud_tenant => dst_cloud_tenant) } - let(:conversion_host) { FactoryGirl.create(:conversion_host, :resource => conversion_host_vm) } + let(:dst_ems) { FactoryBot.create(:ems_openstack, :api_version => 'v3', :zone => FactoryBot.create(:zone)) } + let(:dst_cloud_tenant) { FactoryBot.create(:cloud_tenant, :name => 'fake tenant', :ext_management_system => dst_ems) } + let(:dst_cloud_volume_type) { FactoryBot.create(:cloud_volume_type) } + let(:dst_cloud_network_1) { FactoryBot.create(:cloud_network) } + let(:dst_cloud_network_2) { FactoryBot.create(:cloud_network) } + let(:dst_flavor) { FactoryBot.create(:flavor) } + let(:dst_security_group) { FactoryBot.create(:security_group) } + let(:conversion_host_vm) { FactoryBot.create(:vm_openstack, :ext_management_system => dst_ems, :cloud_tenant => dst_cloud_tenant) } + let(:conversion_host) { FactoryBot.create(:conversion_host, :resource => conversion_host_vm) } let(:mapping) do - FactoryGirl.create( + FactoryBot.create( :transformation_mapping, :transformation_mapping_items => [ TransformationMappingItem.new(:source => src_cluster, :destination => dst_cloud_tenant), diff --git a/spec/models/session_spec.rb b/spec/models/session_spec.rb index c5fdbfa04da..8d7c6f47ef9 100644 --- a/spec/models/session_spec.rb +++ b/spec/models/session_spec.rb @@ -1,13 +1,13 @@ describe Session do describe "#raw_data" do it "returns the unmarshaled data" do - session = FactoryGirl.build(:session, :data => "BAh7BjoLdXNlcmlkSSIKYWRtaW4GOgZFVA==\n") + session = FactoryBot.build(:session, :data => "BAh7BjoLdXNlcmlkSSIKYWRtaW4GOgZFVA==\n") expect(session.raw_data).to eq(:userid => "admin") end it "can handle newlines" do - session = FactoryGirl.build( + session = FactoryBot.build( :session, :data => "BAh7CDoIZm9vSSIIYmFyBjoGRVQ6CGJhekkiCHF1eAY7BlQ6CXF1dXhJIglx\ndXV6BjsGVA==\n" ) @@ -18,7 +18,7 @@ describe "#raw_data=" do it "marshals the data" do - session = FactoryGirl.build(:session, :raw_data => {:userid => "admin"}) + session = FactoryBot.build(:session, :raw_data => {:userid => "admin"}) expect(session.data).to eq("BAh7BjoLdXNlcmlkSSIKYWRtaW4GOgZFVA==\n") end @@ -26,13 +26,13 @@ describe ".purge" do it "purges an old session" do - FactoryGirl.create(:session, :updated_at => 1.year.ago, :raw_data => {:userid => "admin"}) + FactoryBot.create(:session, :updated_at => 1.year.ago, :raw_data => {:userid => "admin"}) expect { described_class.purge(0, 1) }.to change { described_class.count }.from(1).to(0) end it "logs out users before destroying stale sessions" do - FactoryGirl.create(:session, :updated_at => 1.year.ago, :raw_data => {:userid => "admin"}) + FactoryBot.create(:session, :updated_at => 1.year.ago, :raw_data => {:userid => "admin"}) user = instance_double(User, :lastlogoff => 2.days.ago, :lastlogon => 1.day.ago) allow(User).to receive(:where).with(:userid => ["admin"]).and_return([user]) @@ -42,7 +42,7 @@ end it "handles a session with bad data" do - FactoryGirl.create(:session, :updated_at => 1.year.ago, :data => "Data that can't be marshaled") + FactoryBot.create(:session, :updated_at => 1.year.ago, :data => "Data that can't be marshaled") expect { described_class.purge(0) }.to change { described_class.count }.from(1).to(0) end @@ -51,13 +51,13 @@ around { |example| Timecop.freeze { example.run } } it "will purge an expired token" do - FactoryGirl.create(:session, :raw_data => {:expires_on => 1.second.ago}) + FactoryBot.create(:session, :raw_data => {:expires_on => 1.second.ago}) expect { described_class.purge(0) }.to change { described_class.count }.from(1).to(0) end it "won't purge an unexpired token" do - FactoryGirl.create(:session, :raw_data => {:expires_on => 1.second.from_now}) + FactoryBot.create(:session, :raw_data => {:expires_on => 1.second.from_now}) expect { described_class.purge(0) }.not_to change { described_class.count } end @@ -65,7 +65,7 @@ describe ".purge_one_batch" do it "purges one batch" do - FactoryGirl.create_list(:session, 2, :updated_at => 1.year.ago, :raw_data => {:userid => "admin"}) + FactoryBot.create_list(:session, 2, :updated_at => 1.year.ago, :raw_data => {:userid => "admin"}) expect do expect(described_class.purge_one_batch(0, 1)).to eq 1 diff --git a/spec/models/storage_file_spec.rb b/spec/models/storage_file_spec.rb index 47a733cf544..522996ac884 100644 --- a/spec/models/storage_file_spec.rb +++ b/spec/models/storage_file_spec.rb @@ -141,8 +141,8 @@ end it "saves to database when update=true" do - file1 = FactoryGirl.create(:storage_file, :name => 'path1/test1.log') - file2 = FactoryGirl.create(:storage_file, :name => 'path2/test2.log', :vm_or_template_id => '1002') + file1 = FactoryBot.create(:storage_file, :name => 'path1/test1.log') + file2 = FactoryBot.create(:storage_file, :name => 'path2/test2.log', :vm_or_template_id => '1002') vm_ids = { "path1" => 5001, "path2" => 5002 @@ -153,7 +153,7 @@ end it "does not save to database when update=false" do - file1 = FactoryGirl.create(:storage_file, :name => 'path1/test1.log') + file1 = FactoryBot.create(:storage_file, :name => 'path1/test1.log') vm_ids = {"path1" => 5001} described_class.link_storage_files_to_vms(file1, vm_ids, false) expect(file1.vm_or_template_id).to eq(5001) diff --git a/spec/models/storage_spec.rb b/spec/models/storage_spec.rb index 516142a19cb..a1f8e033366 100644 --- a/spec/models/storage_spec.rb +++ b/spec/models/storage_spec.rb @@ -1,11 +1,11 @@ describe Storage do describe "#total_unregistered_vms" do - let(:ext_management_system) { FactoryGirl.create(:ext_management_system) } - let(:host) { FactoryGirl.create(:host) } - let(:storage) { FactoryGirl.create(:storage) } - let!(:vm_registered_1) { FactoryGirl.create(:vm, :storage => storage, :ext_management_system => ext_management_system, :host => host) } - let!(:vm_registered_2) { FactoryGirl.create(:vm, :storage => storage, :host => host) } - let!(:vm_unregistered) { FactoryGirl.create(:vm, :storage => storage, :ext_management_system => ext_management_system) } + let(:ext_management_system) { FactoryBot.create(:ext_management_system) } + let(:host) { FactoryBot.create(:host) } + let(:storage) { FactoryBot.create(:storage) } + let!(:vm_registered_1) { FactoryBot.create(:vm, :storage => storage, :ext_management_system => ext_management_system, :host => host) } + let!(:vm_registered_2) { FactoryBot.create(:vm, :storage => storage, :host => host) } + let!(:vm_unregistered) { FactoryBot.create(:vm, :storage => storage, :ext_management_system => ext_management_system) } it 'returns only unregistred vms' do expect(storage.total_unregistered_vms).to eq(1) @@ -38,7 +38,7 @@ end it "#scan_complete?" do - miq_task = FactoryGirl.create(:miq_task) + miq_task = FactoryBot.create(:miq_task) miq_task.context_data = {:targets => [], :complete => [], :pending => {}} miq_task.context_data[:targets] = [123, 456, 789] miq_task.context_data[:complete] = [] @@ -49,14 +49,14 @@ end it "#scan_complete_message" do - miq_task = FactoryGirl.create(:miq_task) + miq_task = FactoryBot.create(:miq_task) miq_task.context_data = {:targets => [], :complete => [], :pending => {}} miq_task.context_data[:targets] = [123, 456, 789] expect(Storage.scan_complete_message(miq_task)).to eq("SmartState Analysis for 3 storages complete") end it "#scan_update_message" do - miq_task = FactoryGirl.create(:miq_task) + miq_task = FactoryBot.create(:miq_task) miq_task.context_data = {:targets => [], :complete => [], :pending => {}} miq_task.context_data[:targets] = [123, 456, 789] miq_task.context_data[:complete] = [123] @@ -69,14 +69,14 @@ @server = EvmSpecHelper.local_miq_server @zone = @server.zone - @zone2 = FactoryGirl.create(:zone, :name => 'Bedrock') - @ems1 = FactoryGirl.create(:ems_vmware_with_valid_authentication, :name => "test_vcenter1", :zone => @zone) - @ems2 = FactoryGirl.create(:ems_vmware_with_authentication, :name => "test_vcenter2", :zone => @zone2) - @storage1 = FactoryGirl.create(:storage, :name => "test_storage_vmfs", :store_type => "VMFS") - @storage2 = FactoryGirl.create(:storage, :name => "test_storage_nfs", :store_type => "NFS") - @storage3 = FactoryGirl.create(:storage, :name => "test_storage_foo", :store_type => "FOO") - @host1 = FactoryGirl.create(:host, :name => "test_host1", :hostname => "test_host1", :state => 'on', :ems_id => @ems1.id, :storages => [@storage1, @storage3]) - @host2 = FactoryGirl.create(:host, :name => "test_host2", :hostname => "test_host2", :state => 'on', :ems_id => @ems2.id, :storages => [@storage2, @storage3]) + @zone2 = FactoryBot.create(:zone, :name => 'Bedrock') + @ems1 = FactoryBot.create(:ems_vmware_with_valid_authentication, :name => "test_vcenter1", :zone => @zone) + @ems2 = FactoryBot.create(:ems_vmware_with_authentication, :name => "test_vcenter2", :zone => @zone2) + @storage1 = FactoryBot.create(:storage, :name => "test_storage_vmfs", :store_type => "VMFS") + @storage2 = FactoryBot.create(:storage, :name => "test_storage_nfs", :store_type => "NFS") + @storage3 = FactoryBot.create(:storage, :name => "test_storage_foo", :store_type => "FOO") + @host1 = FactoryBot.create(:host, :name => "test_host1", :hostname => "test_host1", :state => 'on', :ems_id => @ems1.id, :storages => [@storage1, @storage3]) + @host2 = FactoryBot.create(:host, :name => "test_host2", :hostname => "test_host2", :state => 'on', :ems_id => @ems2.id, :storages => [@storage2, @storage3]) end it "#active_hosts_in_zone" do @@ -104,7 +104,7 @@ scan_collection_timeout = 456 allow(Storage).to receive_messages(:scan_collection_timeout => scan_collection_timeout) - miq_task = FactoryGirl.create(:miq_task) + miq_task = FactoryBot.create(:miq_task) qitem = @storage1.scan_queue_item(miq_task.id) expect(qitem.class_name).to eq(@storage1.class.name) @@ -118,7 +118,7 @@ end it "#scan_storages_unprocessed" do - miq_task = FactoryGirl.create(:miq_task) + miq_task = FactoryBot.create(:miq_task) miq_task.context_data = {:targets => [], :complete => [], :pending => {}} miq_task.context_data[:targets] = [@storage1.id, @storage2.id, @storage3.id] miq_task.context_data[:complete] = [] @@ -139,7 +139,7 @@ end it "#scan_queue_watchdog" do - miq_task = FactoryGirl.create(:miq_task) + miq_task = FactoryBot.create(:miq_task) deliver_on = Time.now.utc + 1.hour allow(Storage).to receive_messages(:scan_watchdog_deliver_on => deliver_on) watchdog = Storage.scan_queue_watchdog(miq_task.id) @@ -159,7 +159,7 @@ context "on a host with authentication status ok" do before do allow_any_instance_of(Authentication).to receive(:after_authentication_changed) - FactoryGirl.create(:authentication, :resource => @host1, :status => "Valid") + FactoryBot.create(:authentication, :resource => @host1, :status => "Valid") end it "#active_hosts_with_authentication_status_ok" do @@ -256,14 +256,14 @@ it "#scan_queue" do bogus_id = @storage1.id - 1 - miq_task = FactoryGirl.create(:miq_task) + miq_task = FactoryBot.create(:miq_task) miq_task.context_data = {:targets => [], :complete => [], :pending => {}} miq_task.context_data[:targets] = [bogus_id, @storage1.id, @storage2.id, @storage3.id] miq_task.context_data[:complete] = [] miq_task.context_data[:pending] = {} miq_task.save! - qitem1 = FactoryGirl.create(:miq_queue) + qitem1 = FactoryBot.create(:miq_queue) allow_any_instance_of(Storage).to receive_messages(:scan_queue_item => qitem1) Storage.scan_queue(miq_task) miq_task.reload @@ -275,7 +275,7 @@ miq_task.context_data[:complete] << @storage1.id miq_task.context_data[:pending].delete(@storage1.id) miq_task.save! - qitem2 = FactoryGirl.create(:miq_queue) + qitem2 = FactoryBot.create(:miq_queue) allow_any_instance_of(Storage).to receive_messages(:scan_queue_item => qitem2) Storage.scan_queue(miq_task) miq_task.reload @@ -298,7 +298,7 @@ it "#scan_watchdog" do max_qitems_per_scan_request = 1 allow(Storage).to receive_messages(:max_qitems_per_scan_request => max_qitems_per_scan_request) - miq_task = FactoryGirl.create(:miq_task) + miq_task = FactoryBot.create(:miq_task) miq_task.context_data = {:targets => [], :complete => [], :pending => {}} miq_task.context_data[:targets] = [@storage1.id, @storage2.id, @storage3.id] miq_task.context_data[:complete] = [] @@ -312,7 +312,7 @@ expect(miq_task.context_data[:complete]).to eq([]) expect(miq_task.context_data[:pending].length).to eq(0) - qitem1 = FactoryGirl.create(:miq_queue) + qitem1 = FactoryBot.create(:miq_queue) miq_task.context_data[:pending][@storage1.id] = qitem1.id miq_task.save! expect(Storage).to receive(:scan_queue_watchdog).with(miq_task.id).once @@ -344,7 +344,7 @@ end it "#scan_complete_callback" do - miq_task = FactoryGirl.create(:miq_task) + miq_task = FactoryBot.create(:miq_task) miq_task.context_data = {:targets => [], :complete => [], :pending => {}} miq_task.context_data[:targets] = [@storage1.id, @storage2.id, @storage3.id] miq_task.context_data[:complete] = [] @@ -414,12 +414,12 @@ context "#is_available? for Smartstate Analysis" do before do - @storage = FactoryGirl.create(:storage) + @storage = FactoryBot.create(:storage) end it "returns true for VMware Storage when queried whether it supports smartstate analysis" do - FactoryGirl.create(:host_vmware, - :ext_management_system => FactoryGirl.create(:ems_vmware_with_valid_authentication), + FactoryBot.create(:host_vmware, + :ext_management_system => FactoryBot.create(:ems_vmware_with_valid_authentication), :storages => [@storage]) expect(@storage.supports_smartstate_analysis?).to eq(true) @@ -432,9 +432,9 @@ describe "#update_vm_perf" do it "will update a vm_perf with an attributes hash keyed with symbols" do - storage = FactoryGirl.create(:storage) - vm = FactoryGirl.create(:vm) - metric_rollup = FactoryGirl.build(:metric_rollup) + storage = FactoryBot.create(:storage) + vm = FactoryBot.create(:vm) + metric_rollup = FactoryBot.build(:metric_rollup) attrs = {:resource_name => "test vm"} storage.update_vm_perf(vm, metric_rollup, attrs) @@ -445,12 +445,12 @@ describe "#count_of_vmdk_disk_files" do it "ignores the correct files" do - FactoryGirl.create(:storage_file, :storage_id => 1, :ext_name => 'vmdk', :base_name => "good-stuff.vmdk") - FactoryGirl.create(:storage_file, :storage_id => 2, :ext_name => 'dat', :base_name => "bad-stuff.dat") - FactoryGirl.create(:storage_file, :storage_id => 3, :ext_name => 'vmdk', :base_name => "bad-flat.vmdk") - FactoryGirl.create(:storage_file, :storage_id => 4, :ext_name => 'vmdk', :base_name => "bad-delta.vmdk") - FactoryGirl.create(:storage_file, :storage_id => 5, :ext_name => 'vmdk', :base_name => "bad-123456.vmdk") - FactoryGirl.create(:storage_file, :storage_id => 6, :ext_name => 'vmdk', :base_name => "good-11.vmdk") + FactoryBot.create(:storage_file, :storage_id => 1, :ext_name => 'vmdk', :base_name => "good-stuff.vmdk") + FactoryBot.create(:storage_file, :storage_id => 2, :ext_name => 'dat', :base_name => "bad-stuff.dat") + FactoryBot.create(:storage_file, :storage_id => 3, :ext_name => 'vmdk', :base_name => "bad-flat.vmdk") + FactoryBot.create(:storage_file, :storage_id => 4, :ext_name => 'vmdk', :base_name => "bad-delta.vmdk") + FactoryBot.create(:storage_file, :storage_id => 5, :ext_name => 'vmdk', :base_name => "bad-123456.vmdk") + FactoryBot.create(:storage_file, :storage_id => 6, :ext_name => 'vmdk', :base_name => "good-11.vmdk") counts = Storage.count_of_vmdk_disk_files expect(counts[1]).to eq(1) @@ -464,12 +464,12 @@ context "#is_available? for Smartstate Analysis" do before do - @storage = FactoryGirl.create(:storage) + @storage = FactoryBot.create(:storage) end it "returns true for VMware Storage when queried whether it supports smartstate analysis" do - FactoryGirl.create(:host_vmware, - :ext_management_system => FactoryGirl.create(:ems_vmware_with_valid_authentication), + FactoryBot.create(:host_vmware, + :ext_management_system => FactoryBot.create(:ems_vmware_with_valid_authentication), :storages => [@storage]) expect(@storage.supports_smartstate_analysis?).to eq(true) end @@ -481,8 +481,8 @@ describe "#smartstate_analysis_count_for_ems_id" do it "returns counts" do EvmSpecHelper.local_miq_server - ems = FactoryGirl.create(:ems_vmware) - storage = FactoryGirl.create(:storage) + ems = FactoryBot.create(:ems_vmware) + storage = FactoryBot.create(:storage) storage.scan_queue_item(1) storage.scan_queue_item(2) MiqQueue.update_all(:target_id => ems.id, :state => "dequeue") @@ -495,10 +495,10 @@ context '#storage_clusters' do it 'returns only parents' do # A storage mounted on different VCs will have multiple parents - storage = FactoryGirl.create(:storage) - storage_cluster1 = FactoryGirl.create(:storage_cluster, :name => 'test_storage_cluster1') - storage_cluster2 = FactoryGirl.create(:storage_cluster, :name => 'test_storage_cluster2') - _storage_cluster = FactoryGirl.create(:storage_cluster, :name => 'test_storage_cluster3') + storage = FactoryBot.create(:storage) + storage_cluster1 = FactoryBot.create(:storage_cluster, :name => 'test_storage_cluster1') + storage_cluster2 = FactoryBot.create(:storage_cluster, :name => 'test_storage_cluster2') + _storage_cluster = FactoryBot.create(:storage_cluster, :name => 'test_storage_cluster3') storage_cluster1.add_child(storage) storage_cluster2.add_child(storage) expect(storage.storage_clusters).to match_array([storage_cluster1, storage_cluster2]) @@ -506,10 +506,10 @@ it 'returns parents of type storage_cluster only' do # A storage mounted on different VCs will have multiple parents - storage = FactoryGirl.create(:storage) - ems_folder = FactoryGirl.create(:ems_folder, :name => 'test_folder') - storage_cluster1 = FactoryGirl.create(:storage_cluster, :name => 'test_storage_cluster1') - storage_cluster2 = FactoryGirl.create(:storage_cluster, :name => 'test_storage_cluster2') + storage = FactoryBot.create(:storage) + ems_folder = FactoryBot.create(:ems_folder, :name => 'test_folder') + storage_cluster1 = FactoryBot.create(:storage_cluster, :name => 'test_storage_cluster1') + storage_cluster2 = FactoryBot.create(:storage_cluster, :name => 'test_storage_cluster2') ems_folder.add_child(storage) storage_cluster1.add_child(storage) storage_cluster2.add_child(storage) @@ -518,20 +518,20 @@ end it 'return [] if not in any storage cluster' do - storage = FactoryGirl.create(:storage) + storage = FactoryBot.create(:storage) expect(storage.storage_clusters).to match_array([]) end end context "#tenant_identity" do - let(:admin) { FactoryGirl.create(:user_with_group, :userid => "admin") } - let(:tenant) { FactoryGirl.create(:tenant) } - let(:ems) { FactoryGirl.create(:ext_management_system, :tenant => tenant) } - let(:host) { FactoryGirl.create(:host, :ext_management_system => ems) } + let(:admin) { FactoryBot.create(:user_with_group, :userid => "admin") } + let(:tenant) { FactoryBot.create(:tenant) } + let(:ems) { FactoryBot.create(:ext_management_system, :tenant => tenant) } + let(:host) { FactoryBot.create(:host, :ext_management_system => ems) } before { admin } it "has tenant from provider" do - storage = FactoryGirl.create(:storage, :hosts => [host]) + storage = FactoryBot.create(:storage, :hosts => [host]) expect(storage.tenant_identity).to eq(admin) expect(storage.tenant_identity.current_group).to eq(ems.tenant.default_miq_group) @@ -539,7 +539,7 @@ end it "without a provider, has tenant from root tenant" do - storage = FactoryGirl.create(:storage) + storage = FactoryBot.create(:storage) expect(storage.tenant_identity).to eq(admin) expect(storage.tenant_identity.current_group).to eq(Tenant.root_tenant.default_miq_group) diff --git a/spec/models/system_service_spec.rb b/spec/models/system_service_spec.rb index d3673c4476d..b98e1f4f1cb 100644 --- a/spec/models/system_service_spec.rb +++ b/spec/models/system_service_spec.rb @@ -1,33 +1,33 @@ describe SystemService do describe ".svc_type" do it "has nice names" do - ss = FactoryGirl.build(:system_service, :svc_type => "4") + ss = FactoryBot.build(:system_service, :svc_type => "4") expect(ss.svc_type).to eq("Service Adapter") end it "has falls back to numeric name" do - ss = FactoryGirl.build(:system_service, :svc_type => "5") + ss = FactoryBot.build(:system_service, :svc_type => "5") expect(ss.svc_type).to eq("5") end it "works with find" do - ss = FactoryGirl.create(:system_service, :svc_type => "4") + ss = FactoryBot.create(:system_service, :svc_type => "4") expect(SystemService.find(ss.id).svc_type).to eq("Service Adapter") end end describe ".start" do it "has nice names" do - ss = FactoryGirl.build(:system_service, :start => "4") + ss = FactoryBot.build(:system_service, :start => "4") expect(ss.start).to eq("Disabled") end it "has falls back to numeric name" do - ss = FactoryGirl.build(:system_service, :start => "9") + ss = FactoryBot.build(:system_service, :start => "9") expect(ss.start).to eq("9") end it "works with find" do - ss = FactoryGirl.create(:system_service, :start => "4") + ss = FactoryBot.create(:system_service, :start => "4") expect(SystemService.find(ss.id).start).to eq("Disabled") end end diff --git a/spec/models/tag_spec.rb b/spec/models/tag_spec.rb index edd5a4f08da..31fc6d30962 100644 --- a/spec/models/tag_spec.rb +++ b/spec/models/tag_spec.rb @@ -1,15 +1,15 @@ describe Tag do describe ".list" do it "returns an empty string for something that is untaggable" do - account = FactoryGirl.create(:account) + account = FactoryBot.create(:account) actual = described_class.list(account) expect(actual).to eq("") end end describe ".tags" do - let!(:account) { FactoryGirl.create(:account) } - let!(:tag) { FactoryGirl.create(:tag) } + let!(:account) { FactoryBot.create(:account) } + let!(:tag) { FactoryBot.create(:tag) } it "returns tags with tagged items" do Tagging.create(:taggable => account, :tag => tag) @@ -78,7 +78,7 @@ context "categorization" do before do - FactoryGirl.create(:classification_department_with_tags) + FactoryBot.create(:classification_department_with_tags) @tag = Tag.find_by(:name => "/managed/department/finance") @category = Classification.find_by_name("department") @@ -120,11 +120,11 @@ let(:parent_ns) { "/managed/test_category" } let(:entry_ns) { "/managed/test_category/test_entry" } let(:my_region_number) { Tag.my_region_number } - let(:parent) { FactoryGirl.create(:classification, :name => "test_category") } + let(:parent) { FactoryBot.create(:classification, :name => "test_category") } before do - FactoryGirl.create(:classification_tag, :name => "test_entry", :parent => parent) - FactoryGirl.create(:classification_tag, :name => "another_test_entry", :parent => parent) + FactoryBot.create(:classification_tag, :name => "test_entry", :parent => parent) + FactoryBot.create(:classification_tag, :name => "another_test_entry", :parent => parent) end it "finds tag by name" do @@ -166,23 +166,23 @@ describe "#==" do it "equals only itself" do - tag1 = FactoryGirl.build(:tag) - tag2 = FactoryGirl.build(:tag) + tag1 = FactoryBot.build(:tag) + tag2 = FactoryBot.build(:tag) expect(tag1).to eq tag1 expect(tag1).not_to eq tag2 end it "equals its name" do - tag1 = FactoryGirl.build(:tag, :name => '/a/b/c') + tag1 = FactoryBot.build(:tag, :name => '/a/b/c') expect(tag1).to eq '/a/b/c' end end describe "#destroy" do - let(:miq_group) { FactoryGirl.create(:miq_group, :entitlement => Entitlement.create!) } - let(:other_miq_group) { FactoryGirl.create(:miq_group, :entitlement => Entitlement.create!) } + let(:miq_group) { FactoryBot.create(:miq_group, :entitlement => Entitlement.create!) } + let(:other_miq_group) { FactoryBot.create(:miq_group, :entitlement => Entitlement.create!) } let(:filters) { [["/managed/prov_max_memory/test"], ["/managed/my_name/test"]] } - let(:tag) { FactoryGirl.create(:tag, :name => "/managed/my_name/test") } + let(:tag) { FactoryBot.create(:tag, :name => "/managed/my_name/test") } before do miq_group.entitlement.set_managed_filters(filters) diff --git a/spec/models/tenant_quota_spec.rb b/spec/models/tenant_quota_spec.rb index 5af8e09bb4a..0f8d380ea36 100644 --- a/spec/models/tenant_quota_spec.rb +++ b/spec/models/tenant_quota_spec.rb @@ -1,5 +1,5 @@ describe TenantQuota do - let(:tenant) { FactoryGirl.create(:tenant) } + let(:tenant) { FactoryBot.create(:tenant) } describe "#valid?" do it "rejects invalid name" do @@ -36,10 +36,10 @@ end describe ".check_for_over_allocation" do - let(:child_tenant) { FactoryGirl.create(:tenant) } - let(:grandchild_tenant1) { FactoryGirl.create(:tenant, :parent => child_tenant) } - let(:grandchild_tenant2) { FactoryGirl.create(:tenant, :parent => child_tenant) } - let(:great_grandchild_tenant) { FactoryGirl.create(:tenant, :parent => grandchild_tenant1) } + let(:child_tenant) { FactoryBot.create(:tenant) } + let(:grandchild_tenant1) { FactoryBot.create(:tenant, :parent => child_tenant) } + let(:grandchild_tenant2) { FactoryBot.create(:tenant, :parent => child_tenant) } + let(:great_grandchild_tenant) { FactoryBot.create(:tenant, :parent => grandchild_tenant1) } before do child_tenant @@ -116,36 +116,36 @@ describe "#format" do it "has cpu" do - expect(FactoryGirl.build(:tenant_quota_cpu).format).to eq("general_number_precision_0") + expect(FactoryBot.build(:tenant_quota_cpu).format).to eq("general_number_precision_0") end end describe "#default_unit" do it "has cpu" do - expect(FactoryGirl.build(:tenant_quota_cpu).default_unit).to eq("fixnum") + expect(FactoryBot.build(:tenant_quota_cpu).default_unit).to eq("fixnum") end end context "formatted tenant quota values" do include Spec::Support::QuotaHelper - let(:child_tenant) { FactoryGirl.create(:tenant, :parent => @tenant) } + let(:child_tenant) { FactoryBot.create(:tenant, :parent => @tenant) } - let(:child_tenant_quota_cpu) { FactoryGirl.create(:tenant_quota_cpu, :tenant => child_tenant) } - let(:child_tenant_quota_mem) { FactoryGirl.create(:tenant_quota_mem, :tenant => child_tenant) } - let(:child_tenant_quota_storage) { FactoryGirl.create(:tenant_quota_storage, :tenant => child_tenant) } - let(:child_tenant_quota_vms) { FactoryGirl.create(:tenant_quota_vms, :tenant => child_tenant) } - let(:child_tenant_quota_templates) { FactoryGirl.create(:tenant_quota_templates, :tenant => child_tenant) } + let(:child_tenant_quota_cpu) { FactoryBot.create(:tenant_quota_cpu, :tenant => child_tenant) } + let(:child_tenant_quota_mem) { FactoryBot.create(:tenant_quota_mem, :tenant => child_tenant) } + let(:child_tenant_quota_storage) { FactoryBot.create(:tenant_quota_storage, :tenant => child_tenant) } + let(:child_tenant_quota_vms) { FactoryBot.create(:tenant_quota_vms, :tenant => child_tenant) } + let(:child_tenant_quota_templates) { FactoryBot.create(:tenant_quota_templates, :tenant => child_tenant) } - let(:tenant_quota_cpu) { FactoryGirl.create(:tenant_quota_cpu, :tenant => child_tenant, :value => 2) } - let(:tenant_quota_mem) { FactoryGirl.create(:tenant_quota_mem, :tenant => child_tenant, :value => 4_294_967_296) } + let(:tenant_quota_cpu) { FactoryBot.create(:tenant_quota_cpu, :tenant => child_tenant, :value => 2) } + let(:tenant_quota_mem) { FactoryBot.create(:tenant_quota_mem, :tenant => child_tenant, :value => 4_294_967_296) } let(:tenant_quota_storage) do - FactoryGirl.create(:tenant_quota_storage, :tenant => child_tenant, :value => 4_294_967_296) + FactoryBot.create(:tenant_quota_storage, :tenant => child_tenant, :value => 4_294_967_296) end - let(:tenant_quota_vms) { FactoryGirl.create(:tenant_quota_vms, :tenant => child_tenant, :value => 4) } - let(:tenant_quota_templates) { FactoryGirl.create(:tenant_quota_templates, :tenant => child_tenant, :value => 4) } + let(:tenant_quota_vms) { FactoryBot.create(:tenant_quota_vms, :tenant => child_tenant, :value => 4) } + let(:tenant_quota_templates) { FactoryBot.create(:tenant_quota_templates, :tenant => child_tenant, :value => 4) } before do setup_model @@ -291,7 +291,7 @@ end describe ".destroy_missing" do - let(:tenant2) { FactoryGirl.create(:tenant) } + let(:tenant2) { FactoryBot.create(:tenant) } it "removes extra quotas only from object in question" do tenant.tenant_quotas.create(:name => :vms_allocated, :value => 20) diff --git a/spec/models/tenant_spec.rb b/spec/models/tenant_spec.rb index 37d2ed601f5..38340b3a7c3 100644 --- a/spec/models/tenant_spec.rb +++ b/spec/models/tenant_spec.rb @@ -3,7 +3,7 @@ let(:tenant) { described_class.new(:domain => 'x.com', :parent => default_tenant) } let(:user_admin) { - user = FactoryGirl.create(:user_admin) + user = FactoryBot.create(:user_admin) allow(user).to receive(:get_timezone).and_return("UTC") user } @@ -81,8 +81,8 @@ end describe "#display_type" do - let(:tenant) { FactoryGirl.build(:tenant) } - let(:project) { FactoryGirl.build(:tenant, :divisible => false) } + let(:tenant) { FactoryBot.build(:tenant) } + let(:project) { FactoryBot.build(:tenant, :divisible => false) } it "detects Tenant" do expect(tenant.display_type).to eql 'Tenant' @@ -97,8 +97,8 @@ describe ".all_tenants" do it "returns divisible projects (root and created is divisible)" do - FactoryGirl.create(:tenant, :parent => root_tenant) - FactoryGirl.create(:tenant, :parent => root_tenant, :divisible => false) + FactoryBot.create(:tenant, :parent => root_tenant) + FactoryBot.create(:tenant, :parent => root_tenant, :divisible => false) expect(Tenant.all_tenants.count).to eql(2) end @@ -106,8 +106,8 @@ describe ".app_projects" do it "returns non-divisible projects (root is divisible))" do - FactoryGirl.create(:tenant, :parent => root_tenant, :divisible => false) - FactoryGirl.create(:tenant, :parent => root_tenant, :divisible => false) + FactoryBot.create(:tenant, :parent => root_tenant, :divisible => false) + FactoryBot.create(:tenant, :parent => root_tenant, :divisible => false) expect(Tenant.all_projects.count).to eql 2 end @@ -115,12 +115,12 @@ context "subtenants and subprojects" do before do - @t1 = FactoryGirl.create(:tenant, :parent => root_tenant, :name => "T1") - @t2 = FactoryGirl.create(:tenant, :parent => @t1, :name => "T2") - @t2p = FactoryGirl.create(:tenant, :parent => @t1, :name => "T2 Project", :divisible => false) - @t3 = FactoryGirl.create(:tenant, :parent => @t2, :name => "T3") - @t3a = FactoryGirl.create(:tenant, :parent => @t2, :name => "T3a") - @t4p = FactoryGirl.create(:tenant, :parent => @t3, :name => "T4 Project", :divisible => false) + @t1 = FactoryBot.create(:tenant, :parent => root_tenant, :name => "T1") + @t2 = FactoryBot.create(:tenant, :parent => @t1, :name => "T2") + @t2p = FactoryBot.create(:tenant, :parent => @t1, :name => "T2 Project", :divisible => false) + @t3 = FactoryBot.create(:tenant, :parent => @t2, :name => "T3") + @t3a = FactoryBot.create(:tenant, :parent => @t2, :name => "T3a") + @t4p = FactoryBot.create(:tenant, :parent => @t3, :name => "T4 Project", :divisible => false) end it "#all_subtenants" do @@ -150,18 +150,18 @@ end it "is unique per parent tenant" do - FactoryGirl.create(:tenant, :name => "common", :parent => root_tenant) - expect { FactoryGirl.create(:tenant, :name => "common", :parent => root_tenant) } + FactoryBot.create(:tenant, :name => "common", :parent => root_tenant) + expect { FactoryBot.create(:tenant, :name => "common", :parent => root_tenant) } .to raise_error(ActiveRecord::RecordInvalid, /Name should be unique per parent/) end it "can be the same for different parents" do - parent1 = FactoryGirl.create(:tenant, :name => "parent1", :parent => root_tenant) - parent2 = FactoryGirl.create(:tenant, :name => "parent2", :parent => root_tenant) + parent1 = FactoryBot.create(:tenant, :name => "parent1", :parent => root_tenant) + parent2 = FactoryBot.create(:tenant, :name => "parent2", :parent => root_tenant) - FactoryGirl.create(:tenant, :name => "common", :parent => parent1) + FactoryBot.create(:tenant, :name => "common", :parent => parent1) expect do - FactoryGirl.create(:tenant, :name => "common", :parent => parent2) + FactoryBot.create(:tenant, :name => "common", :parent => parent2) end.not_to raise_error end @@ -179,8 +179,8 @@ end it "#parent_name" do - t1 = FactoryGirl.create(:tenant, :name => "T1", :parent => root_tenant) - t2 = FactoryGirl.create(:tenant, :name => "T2", :parent => t1, :divisible => false) + t1 = FactoryBot.create(:tenant, :name => "T1", :parent => root_tenant) + t2 = FactoryBot.create(:tenant, :name => "T2", :parent => t1, :divisible => false) expect(t2.parent_name).to eql "T1" expect(default_tenant.parent_name).to eql nil @@ -212,16 +212,16 @@ context "#validate_default_tenant" do it "fails assigning a group with the wrong tenant" do - tenant1 = FactoryGirl.create(:tenant) - tenant2 = FactoryGirl.create(:tenant) - g = FactoryGirl.create(:miq_group, :tenant => tenant1) + tenant1 = FactoryBot.create(:tenant) + tenant2 = FactoryBot.create(:tenant) + g = FactoryBot.create(:miq_group, :tenant => tenant1) expect { tenant2.update_attributes!(:default_miq_group => g) } .to raise_error(ActiveRecord::RecordInvalid, /default group must be a default group for this tenant/) end # we may want to change this in the future it "prevents changing default_miq_group" do - g = FactoryGirl.create(:miq_group, :tenant => tenant) + g = FactoryBot.create(:miq_group, :tenant => tenant) expect { tenant.update_attributes!(:default_miq_group => g) } .to raise_error(ActiveRecord::RecordInvalid, /default group must be a default group for this tenant/) end @@ -237,11 +237,11 @@ end context "#ensure_can_be_destroyed" do - let(:tenant) { FactoryGirl.create(:tenant) } - let(:cloud_tenant) { FactoryGirl.create(:cloud_tenant) } + let(:tenant) { FactoryBot.create(:tenant) } + let(:cloud_tenant) { FactoryBot.create(:cloud_tenant) } it "wouldn't delete tenant with groups associated" do - FactoryGirl.create(:miq_group, :tenant => tenant) + FactoryBot.create(:miq_group, :tenant => tenant) expect { tenant.destroy! }.to raise_error(RuntimeError, /A tenant with groups.*cannot be deleted/) end @@ -269,24 +269,24 @@ end context "#admins" do - let(:self_service_role) { FactoryGirl.create(:miq_user_role, :settings => {:restrictions => {:vms => :user}}) } - let(:admin_with_brand) { FactoryGirl.create(:miq_user_role, :name => "tenant_admin-brand-master") } + let(:self_service_role) { FactoryBot.create(:miq_user_role, :settings => {:restrictions => {:vms => :user}}) } + let(:admin_with_brand) { FactoryBot.create(:miq_user_role, :name => "tenant_admin-brand-master") } - let(:tenant1) { FactoryGirl.create(:tenant) } + let(:tenant1) { FactoryBot.create(:tenant) } let(:tenant1_admins) do - FactoryGirl.create(:miq_group, + FactoryBot.create(:miq_group, :miq_user_role => admin_with_brand, :tenant => tenant1 ) end let(:tenant1_users) do - FactoryGirl.create(:miq_group, + FactoryBot.create(:miq_group, :tenant => tenant1, :miq_user_role => self_service_role) end - let(:admin) { FactoryGirl.create(:user, :miq_groups => [tenant1_users, tenant1_admins]) } - let(:user1) { FactoryGirl.create(:user, :miq_groups => [tenant1_users]) } - let(:user2) { FactoryGirl.create(:user) } + let(:admin) { FactoryBot.create(:user, :miq_groups => [tenant1_users, tenant1_admins]) } + let(:user1) { FactoryBot.create(:user, :miq_groups => [tenant1_users]) } + let(:user2) { FactoryBot.create(:user) } it "has users" do admin @@ -299,21 +299,21 @@ end context "#miq_ae_domains" do - let(:t1) { FactoryGirl.create(:tenant, :name => "T1", :parent => root_tenant) } - let(:t2) { FactoryGirl.create(:tenant, :name => "T2", :parent => root_tenant) } - let(:dom1) { FactoryGirl.create(:miq_ae_domain, :tenant => t1, :name => 'DOM1', :priority => 20) } - let(:dom2) { FactoryGirl.create(:miq_ae_domain, :tenant => t2, :name => 'DOM2', :priority => 40) } - let(:t1_1) { FactoryGirl.create(:tenant, :name => 'T1_1', :domain => 'a.a.com', :parent => t1) } - let(:t2_2) { FactoryGirl.create(:tenant, :name => 'T2_1', :domain => 'b.b.com', :parent => t2) } + let(:t1) { FactoryBot.create(:tenant, :name => "T1", :parent => root_tenant) } + let(:t2) { FactoryBot.create(:tenant, :name => "T2", :parent => root_tenant) } + let(:dom1) { FactoryBot.create(:miq_ae_domain, :tenant => t1, :name => 'DOM1', :priority => 20) } + let(:dom2) { FactoryBot.create(:miq_ae_domain, :tenant => t2, :name => 'DOM2', :priority => 40) } + let(:t1_1) { FactoryBot.create(:tenant, :name => 'T1_1', :domain => 'a.a.com', :parent => t1) } + let(:t2_2) { FactoryBot.create(:tenant, :name => 'T2_1', :domain => 'b.b.com', :parent => t2) } context "reset priority" do it "#reset_domain_priority_by_ordered_ids" do - FactoryGirl.create(:miq_ae_system_domain, :name => 'ManageIQ', :priority => 0, + FactoryBot.create(:miq_ae_system_domain, :name => 'ManageIQ', :priority => 0, :tenant_id => root_tenant.id) - FactoryGirl.create(:miq_ae_system_domain, :name => 'Redhat', :priority => 1, + FactoryBot.create(:miq_ae_system_domain, :name => 'Redhat', :priority => 1, :tenant_id => root_tenant.id) - dom3 = FactoryGirl.create(:miq_ae_domain, :name => 'A', :tenant_id => root_tenant.id) - dom4 = FactoryGirl.create(:miq_ae_domain, :name => 'B', :tenant_id => root_tenant.id) + dom3 = FactoryBot.create(:miq_ae_domain, :name => 'A', :tenant_id => root_tenant.id) + dom4 = FactoryBot.create(:miq_ae_domain, :name => 'B', :tenant_id => root_tenant.id) expect(root_tenant.visible_domains.collect(&:name)).to eq(%w(B A Redhat ManageIQ)) ids = [dom4.id, dom3.id] @@ -324,14 +324,14 @@ end it "#reset_domain_priority_by_ordered_ids by subtenant" do - FactoryGirl.create(:miq_ae_system_domain, :name => 'ManageIQ', :priority => 0, + FactoryBot.create(:miq_ae_system_domain, :name => 'ManageIQ', :priority => 0, :tenant_id => root_tenant.id) - FactoryGirl.create(:miq_ae_system_domain, :name => 'Redhat', :priority => 1, + FactoryBot.create(:miq_ae_system_domain, :name => 'Redhat', :priority => 1, :tenant_id => root_tenant.id) - FactoryGirl.create(:miq_ae_domain, :name => 'T1_A', :tenant_id => t1.id) - FactoryGirl.create(:miq_ae_domain, :name => 'T1_B', :tenant_id => t1.id) - dom5 = FactoryGirl.create(:miq_ae_domain, :name => 'T1_1_A', :tenant_id => t1_1.id) - dom6 = FactoryGirl.create(:miq_ae_domain, :name => 'T1_1_B', :tenant_id => t1_1.id) + FactoryBot.create(:miq_ae_domain, :name => 'T1_A', :tenant_id => t1.id) + FactoryBot.create(:miq_ae_domain, :name => 'T1_B', :tenant_id => t1.id) + dom5 = FactoryBot.create(:miq_ae_domain, :name => 'T1_1_A', :tenant_id => t1_1.id) + dom6 = FactoryBot.create(:miq_ae_domain, :name => 'T1_1_B', :tenant_id => t1_1.id) expect(t1_1.visible_domains.collect(&:name)).to eq(%w(T1_1_B T1_1_A T1_B T1_A Redhat ManageIQ)) ids = [dom6.id, dom5.id] t1_1.reset_domain_priority_by_ordered_ids(ids) @@ -341,9 +341,9 @@ it '#sequenceable_domains' do t1_1 - FactoryGirl.create(:miq_ae_domain, :name => 'DOM15', :priority => 15, + FactoryBot.create(:miq_ae_domain, :name => 'DOM15', :priority => 15, :tenant_id => t1_1.id) - FactoryGirl.create(:miq_ae_system_domain, :name => 'DOM10', :priority => 10, + FactoryBot.create(:miq_ae_system_domain, :name => 'DOM10', :priority => 10, :tenant_id => root_tenant.id, :enabled => false) expect(t1_1.sequenceable_domains.collect(&:name)).to eq(%w(DOM15)) @@ -353,15 +353,15 @@ before do dom1 dom2 - FactoryGirl.create(:miq_ae_domain, :name => 'DOM15', :priority => 15, + FactoryBot.create(:miq_ae_domain, :name => 'DOM15', :priority => 15, :tenant_id => root_tenant.id) - FactoryGirl.create(:miq_ae_domain, :name => 'DOM10', :priority => 10, + FactoryBot.create(:miq_ae_domain, :name => 'DOM10', :priority => 10, :tenant_id => root_tenant.id, :enabled => false) - FactoryGirl.create(:miq_ae_domain, :name => 'DOM3', :priority => 3, + FactoryBot.create(:miq_ae_domain, :name => 'DOM3', :priority => 3, :tenant_id => t1_1.id) - FactoryGirl.create(:miq_ae_domain, :name => 'DOM5', :priority => 7, + FactoryBot.create(:miq_ae_domain, :name => 'DOM5', :priority => 7, :tenant_id => t1_1.id) - FactoryGirl.create(:miq_ae_domain, :name => 'DOM4', :priority => 5, + FactoryBot.create(:miq_ae_domain, :name => 'DOM4', :priority => 5, :tenant_id => t2_2.id) end @@ -414,7 +414,7 @@ it "no editable domains available for current tenant" do t1_1 - FactoryGirl.create(:miq_ae_system_domain, + FactoryBot.create(:miq_ae_system_domain, :name => 'non_editable', :priority => 3, :tenant_id => t1_1.id) @@ -423,7 +423,7 @@ it "editable domains available for current_tenant" do t1_1 - FactoryGirl.create(:miq_ae_domain, + FactoryBot.create(:miq_ae_domain, :name => 'editable', :priority => 3, :tenant_id => t1_1.id) @@ -432,7 +432,7 @@ end describe ".set_quotas" do - let(:tenant) { FactoryGirl.build(:tenant, :parent => default_tenant) } + let(:tenant) { FactoryBot.build(:tenant, :parent => default_tenant) } it "can set quotas" do tenant.set_quotas(:vms_allocated => {:value => 20}) @@ -504,7 +504,7 @@ end describe ".get_quotas" do - let(:tenant) { FactoryGirl.build(:tenant, :parent => default_tenant) } + let(:tenant) { FactoryBot.build(:tenant, :parent => default_tenant) } it "can get quotas" do expect(tenant.get_quotas).not_to be_empty @@ -547,41 +547,41 @@ end describe ".used_quotas" do - let(:tenant) { FactoryGirl.create(:tenant, :parent => default_tenant) } - let(:ems) { FactoryGirl.create(:ems_vmware, :name => 'ems', :tenant => tenant) } + let(:tenant) { FactoryBot.create(:tenant, :parent => default_tenant) } + let(:ems) { FactoryBot.create(:ems_vmware, :name => 'ems', :tenant => tenant) } let(:vm1) do - FactoryGirl.create( + FactoryBot.create( :vm_vmware, :tenant_id => tenant.id, :host_id => 1, :ext_management_system => ems, - :hardware => FactoryGirl.create( + :hardware => FactoryBot.create( :hardware, :memory_mb => 1024, :cpu_total_cores => 1, - :disks => [FactoryGirl.create(:disk, :size => 12_345_678, :size_on_disk => 12_345)] + :disks => [FactoryBot.create(:disk, :size => 12_345_678, :size_on_disk => 12_345)] ) ) end let(:vm2) do - FactoryGirl.create( + FactoryBot.create( :vm_vmware, :tenant_id => tenant.id, :host_id => 1, :ext_management_system => ems, - :hardware => FactoryGirl.create( + :hardware => FactoryBot.create( :hardware, :memory_mb => 1024, :cpu_total_cores => 1, - :disks => [FactoryGirl.create(:disk, :size => 12_345_678, :size_on_disk => 12_345)] + :disks => [FactoryBot.create(:disk, :size => 12_345_678, :size_on_disk => 12_345)] ) ) end let(:template) do - FactoryGirl.create( + FactoryBot.create( :miq_template, :name => "test", :location => "test.vmx", @@ -589,11 +589,11 @@ :tenant_id => tenant.id, :host_id => 1, :ext_management_system => ems, - :hardware => FactoryGirl.create( + :hardware => FactoryBot.create( :hardware, :memory_mb => 1024, :cpu_total_cores => 1, - :disks => [FactoryGirl.create(:disk, :size => 12_345_678, :size_on_disk => 12_345)] + :disks => [FactoryBot.create(:disk, :size => 12_345_678, :size_on_disk => 12_345)] ) ) end @@ -634,10 +634,10 @@ end context "quota allocation" do - let(:parent_tenant) { FactoryGirl.create(:tenant, :parent => default_tenant) } - let(:child_tenant1) { FactoryGirl.create(:tenant, :parent => parent_tenant) } - let(:child_tenant2) { FactoryGirl.create(:tenant, :parent => parent_tenant) } - let(:child_tenant3) { FactoryGirl.create(:tenant, :parent => parent_tenant) } + let(:parent_tenant) { FactoryBot.create(:tenant, :parent => default_tenant) } + let(:child_tenant1) { FactoryBot.create(:tenant, :parent => parent_tenant) } + let(:child_tenant2) { FactoryBot.create(:tenant, :parent => parent_tenant) } + let(:child_tenant3) { FactoryBot.create(:tenant, :parent => parent_tenant) } before do parent_tenant.set_quotas( @@ -750,8 +750,8 @@ # ten1 # ten2 it "builds names with dots" do - ten1 = FactoryGirl.create(:tenant, :name => "ten1", :parent => root_tenant) - ten2 = FactoryGirl.create(:tenant, :name => "ten2", :parent => ten1) + ten1 = FactoryBot.create(:tenant, :name => "ten1", :parent => root_tenant) + ten2 = FactoryBot.create(:tenant, :name => "ten2", :parent => ten1) User.with_user(user_admin) do tenants, projects = Tenant.tenant_and_project_names @@ -764,8 +764,8 @@ # proj1 # proj2 it "separates projects" do - proj2 = FactoryGirl.create(:tenant, :name => "proj2", :divisible => false, :parent => root_tenant) - proj1 = FactoryGirl.create(:tenant, :name => "proj1", :divisible => false, :parent => root_tenant) + proj2 = FactoryBot.create(:tenant, :name => "proj2", :divisible => false, :parent => root_tenant) + proj1 = FactoryBot.create(:tenant, :name => "proj1", :divisible => false, :parent => root_tenant) User.with_user(user_admin) do tenants, projects = Tenant.tenant_and_project_names @@ -782,12 +782,12 @@ # proj2 # ten3 it "separates tenants from projects" do - FactoryGirl.create(:tenant, :name => "ten3", :parent => root_tenant) - ten1 = FactoryGirl.create(:tenant, :name => "ten1", :parent => root_tenant) - ten2 = FactoryGirl.create(:tenant, :name => "ten2", :parent => root_tenant) - FactoryGirl.create(:tenant, :name => "proj2", :divisible => false, :parent => ten2) - FactoryGirl.create(:tenant, :name => "proj1", :divisible => false, :parent => ten1) - FactoryGirl.create(:tenant, :name => "proj3", :divisible => false, :parent => root_tenant) + FactoryBot.create(:tenant, :name => "ten3", :parent => root_tenant) + ten1 = FactoryBot.create(:tenant, :name => "ten1", :parent => root_tenant) + ten2 = FactoryBot.create(:tenant, :name => "ten2", :parent => root_tenant) + FactoryBot.create(:tenant, :name => "proj2", :divisible => false, :parent => ten2) + FactoryBot.create(:tenant, :name => "proj1", :divisible => false, :parent => ten1) + FactoryBot.create(:tenant, :name => "proj3", :divisible => false, :parent => root_tenant) User.with_user(user_admin) do tenants, projects = Tenant.tenant_and_project_names @@ -800,9 +800,9 @@ end describe ".build_tenant_tree" do - let!(:tenant) { FactoryGirl.create(:tenant) } - let!(:tenantA) { FactoryGirl.create(:tenant, :parent => tenant) } - let!(:tenantA1) { FactoryGirl.create(:tenant, :parent => tenantA) } + let!(:tenant) { FactoryBot.create(:tenant) } + let!(:tenantA) { FactoryBot.create(:tenant, :parent => tenant) } + let!(:tenantA1) { FactoryBot.create(:tenant, :parent => tenantA) } it "returns subtenants of a tenant" do expected_array = [{:name => tenantA.name, :id => tenantA.id, :parent => tenant.id}, @@ -818,14 +818,14 @@ describe "setting a parent for a new record" do it "passes back the parent assigned" do tenant.save! - sub_tenant = FactoryGirl.build(:tenant, :parent => Tenant.root_tenant) + sub_tenant = FactoryBot.build(:tenant, :parent => Tenant.root_tenant) expect(sub_tenant.parent = tenant).to eq(tenant) end it "passes back the parent_id assigned" do tenant.save! - sub_tenant = FactoryGirl.build(:tenant, :parent => Tenant.root_tenant) + sub_tenant = FactoryBot.build(:tenant, :parent => Tenant.root_tenant) expect(sub_tenant.parent_id = tenant.id).to eq(tenant.id) end @@ -842,7 +842,7 @@ tenant.update_attribute(:default_miq_group_id, nil) # rubocop:enable Rails/SkipsModelValidations # lets make sure the tenant doesn't get assigned this user created group (the bug) - false_group = FactoryGirl.create(:miq_group, :tenant_id => tenant.id) + false_group = FactoryBot.create(:miq_group, :tenant_id => tenant.id) # 20151021174140_assign_tenant_default_group.rb tenant.send(:create_tenant_group) @@ -852,10 +852,10 @@ end context 'dynamic product features' do - let!(:miq_product_feature_1) { FactoryGirl.create(:miq_product_feature, :name => "Edit1", :description => "XXX1", :identifier => 'dialog_edit_editor') } - let!(:miq_product_feature_2) { FactoryGirl.create(:miq_product_feature, :name => "Edit2", :description => "XXX2", :identifier => 'dialog_new_editor') } + let!(:miq_product_feature_1) { FactoryBot.create(:miq_product_feature, :name => "Edit1", :description => "XXX1", :identifier => 'dialog_edit_editor') } + let!(:miq_product_feature_2) { FactoryBot.create(:miq_product_feature, :name => "Edit2", :description => "XXX2", :identifier => 'dialog_new_editor') } - let(:tenant_product_feature) { FactoryGirl.create(:tenant) } + let(:tenant_product_feature) { FactoryBot.create(:tenant) } it "properly creates a related product feature" do features = tenant_product_feature.miq_product_features.map { |x| x.slice(:name, :description, :identifier, :feature_type) } @@ -867,7 +867,7 @@ end describe "#create_miq_product_features_for_tenant_nodes" do - let(:tenant_product_feature) { FactoryGirl.create(:tenant) } + let(:tenant_product_feature) { FactoryBot.create(:tenant) } it "creates product features for tenant nodes" do expect(tenant_product_feature.create_miq_product_features_for_tenant_nodes).to match_array(["dialog_edit_editor_tenant_#{tenant_product_feature.id}", "dialog_new_editor_tenant_#{tenant_product_feature.id}"]) diff --git a/spec/models/time_profile_spec.rb b/spec/models/time_profile_spec.rb index 88a249a8fd4..168333b13a2 100644 --- a/spec/models/time_profile_spec.rb +++ b/spec/models/time_profile_spec.rb @@ -1,7 +1,7 @@ describe TimeProfile do before do @server = EvmSpecHelper.local_miq_server - @ems = FactoryGirl.create(:ems_vmware, :zone => @server.zone) + @ems = FactoryBot.create(:ems_vmware, :zone => @server.zone) end it "will default to the correct profile values" do @@ -18,7 +18,7 @@ end it "with a non-default profile" do - tp = FactoryGirl.create(:time_profile, :tz => "Hawaii") + tp = FactoryBot.create(:time_profile, :tz => "Hawaii") expect(tp).to_not be_default end end @@ -59,13 +59,13 @@ end it "will not rollup daily performances on create if rollups are disabled" do - FactoryGirl.create(:time_profile) + FactoryBot.create(:time_profile) assert_nothing_queued end context "with an existing time profile with rollups disabled" do before do - @tp = FactoryGirl.create(:time_profile) + @tp = FactoryBot.create(:time_profile) MiqQueue.delete_all end @@ -84,13 +84,13 @@ end it "will rollup daily performances on create if rollups are enabled" do - @tp = FactoryGirl.create(:time_profile_with_rollup) + @tp = FactoryBot.create(:time_profile_with_rollup) assert_rebuild_daily_queued end context "with an existing time profile with rollups enabled" do before do - @tp = FactoryGirl.create(:time_profile_with_rollup) + @tp = FactoryBot.create(:time_profile_with_rollup) MiqQueue.delete_all end @@ -119,13 +119,13 @@ tp = TimeProfile.find_by(:description => TimeProfile::DEFAULT_TZ) tp.profile_type = "global" tp.save - FactoryGirl.create(:time_profile, + FactoryBot.create(:time_profile, :description => "test1", :profile_type => "user", :profile_key => "some_user", :rollup_daily_metrics => true) - FactoryGirl.create(:time_profile, + FactoryBot.create(:time_profile, :description => "test2", :profile_type => "user", :profile_key => "foo", @@ -141,14 +141,14 @@ end it "gets time profiles that matches user's tz and marked for daily Rollup" do - FactoryGirl.create(:time_profile, + FactoryBot.create(:time_profile, :description => "test1", :profile_type => "user", :profile_key => "some_user", :tz => "other_tz", :rollup_daily_metrics => true) - FactoryGirl.create(:time_profile, + FactoryBot.create(:time_profile, :description => "test2", :profile_type => "user", :profile_key => "foo", @@ -161,19 +161,19 @@ describe "#profile_for_each_region" do it "returns none for a non rollup metric" do - tp = FactoryGirl.create(:time_profile, :rollup_daily_metrics => false) + tp = FactoryBot.create(:time_profile, :rollup_daily_metrics => false) expect(tp.profile_for_each_region).to eq([]) end it "returns unique entries" do - tp1a = FactoryGirl.create(:time_profile_with_rollup, :id => id_in_region(5, 1)) - tp1b = FactoryGirl.create(:time_profile_with_rollup, :id => id_in_region(5, 2)) - FactoryGirl.create(:time_profile_with_rollup, :days => [1, 2], :id => id_in_region(5, 3)) - FactoryGirl.create(:time_profile, :rollup_daily_metrics => false, :id => id_in_region(5, 4)) - tp2 = FactoryGirl.create(:time_profile_with_rollup, :id => id_in_region(6, 1)) - FactoryGirl.create(:time_profile_with_rollup, :days => [1, 2], :id => id_in_region(6, 2)) - FactoryGirl.create(:time_profile, :rollup_daily_metrics => false, :id => id_in_region(6, 3)) + tp1a = FactoryBot.create(:time_profile_with_rollup, :id => id_in_region(5, 1)) + tp1b = FactoryBot.create(:time_profile_with_rollup, :id => id_in_region(5, 2)) + FactoryBot.create(:time_profile_with_rollup, :days => [1, 2], :id => id_in_region(5, 3)) + FactoryBot.create(:time_profile, :rollup_daily_metrics => false, :id => id_in_region(5, 4)) + tp2 = FactoryBot.create(:time_profile_with_rollup, :id => id_in_region(6, 1)) + FactoryBot.create(:time_profile_with_rollup, :days => [1, 2], :id => id_in_region(6, 2)) + FactoryBot.create(:time_profile, :rollup_daily_metrics => false, :id => id_in_region(6, 3)) results = tp1a.profile_for_each_region expect(results.size).to eq(2) @@ -185,9 +185,9 @@ describe ".all_timezones" do it "works with seeds" do - FactoryGirl.create(:time_profile, :tz => "tz") - FactoryGirl.create(:time_profile, :tz => "tz") - FactoryGirl.create(:time_profile, :tz => "other_tz") + FactoryBot.create(:time_profile, :tz => "tz") + FactoryBot.create(:time_profile, :tz => "tz") + FactoryBot.create(:time_profile, :tz => "other_tz") expect(TimeProfile.all_timezones).to match_array(%w(tz other_tz)) end @@ -195,8 +195,8 @@ describe ".find_all_with_entire_tz" do it "only returns profiles with all days" do - FactoryGirl.create(:time_profile, :days => [1, 2]) - tp = FactoryGirl.create(:time_profile) + FactoryBot.create(:time_profile, :days => [1, 2]) + tp = FactoryBot.create(:time_profile) expect(TimeProfile.find_all_with_entire_tz).to eq([tp]) end @@ -204,19 +204,19 @@ describe ".profile_for_user_tz" do it "finds global profiles" do - FactoryGirl.create(:time_profile_with_rollup, :tz => "good", :profile_type => "global") + FactoryBot.create(:time_profile_with_rollup, :tz => "good", :profile_type => "global") expect(TimeProfile.profile_for_user_tz(1, "good")).to be_truthy end it "finds user profiles" do - FactoryGirl.create(:time_profile_with_rollup, :tz => "good", :profile_type => "user", :profile_key => 1) + FactoryBot.create(:time_profile_with_rollup, :tz => "good", :profile_type => "user", :profile_key => 1) expect(TimeProfile.profile_for_user_tz(1, "good")).to be_truthy end it "skips invalid records" do - FactoryGirl.create(:time_profile_with_rollup, :tz => "bad", :profile_type => "global") - FactoryGirl.create(:time_profile, :tz => "good", :profile_type => "global", :rollup_daily_metrics => false) - FactoryGirl.create(:time_profile_with_rollup, :tz => "good", :profile_type => "user", :profile_key => "2") + FactoryBot.create(:time_profile_with_rollup, :tz => "bad", :profile_type => "global") + FactoryBot.create(:time_profile, :tz => "good", :profile_type => "global", :rollup_daily_metrics => false) + FactoryBot.create(:time_profile_with_rollup, :tz => "good", :profile_type => "user", :profile_key => "2") expect(TimeProfile.profile_for_user_tz(1, "good")).not_to be end diff --git a/spec/models/transformation_mapping/cloud_best_fit_spec.rb b/spec/models/transformation_mapping/cloud_best_fit_spec.rb index 6948916b53e..85244311b64 100644 --- a/spec/models/transformation_mapping/cloud_best_fit_spec.rb +++ b/spec/models/transformation_mapping/cloud_best_fit_spec.rb @@ -1,7 +1,7 @@ describe TransformationMapping::CloudBestFit do - let(:ems) { FactoryGirl.create(:ems_openstack) } - let(:vm) { FactoryGirl.create(:vm_vmware, :hardware => vm_hardware) } - let(:vm_hardware) { FactoryGirl.create(:hardware, :cpu1x2, :ram1GB) } + let(:ems) { FactoryBot.create(:ems_openstack) } + let(:vm) { FactoryBot.create(:vm_vmware, :hardware => vm_hardware) } + let(:vm_hardware) { FactoryBot.create(:hardware, :cpu1x2, :ram1GB) } subject { described_class.new(vm, ems) } diff --git a/spec/models/transformation_mapping_spec.rb b/spec/models/transformation_mapping_spec.rb index a62a78017fb..fc12686e106 100644 --- a/spec/models/transformation_mapping_spec.rb +++ b/spec/models/transformation_mapping_spec.rb @@ -1,10 +1,10 @@ describe TransformationMapping do - let(:src) { FactoryGirl.create(:ems_cluster) } - let(:dst) { FactoryGirl.create(:ems_cluster) } - let(:vm) { FactoryGirl.create(:vm_vmware, :ems_cluster => src) } + let(:src) { FactoryBot.create(:ems_cluster) } + let(:dst) { FactoryBot.create(:ems_cluster) } + let(:vm) { FactoryBot.create(:vm_vmware, :ems_cluster => src) } let(:mapping) do - FactoryGirl.create( + FactoryBot.create( :transformation_mapping, :transformation_mapping_items => [TransformationMappingItem.new(:source => src, :destination => dst)] ) @@ -16,13 +16,13 @@ end it "returns nil for unmapped source" do - expect(mapping.destination(FactoryGirl.create(:ems_cluster))).to be_nil + expect(mapping.destination(FactoryBot.create(:ems_cluster))).to be_nil end end describe '#service_templates' do - let(:plan) { FactoryGirl.create(:service_template_transformation_plan) } - before { FactoryGirl.create(:service_resource, :resource => mapping, :service_template => plan) } + let(:plan) { FactoryBot.create(:service_template_transformation_plan) } + before { FactoryBot.create(:service_resource, :resource => mapping, :service_template => plan) } it 'finds the transformation plans' do expect(mapping.service_templates).to match([plan]) @@ -30,18 +30,18 @@ end describe '#search_vms_and_validate' do - let(:vm) { FactoryGirl.create(:vm_vmware, :name => 'test_vm', :ems_cluster => src, :ext_management_system => FactoryGirl.create(:ext_management_system)) } - let(:vm2) { FactoryGirl.create(:vm_vmware, :ems_cluster => src, :ext_management_system => FactoryGirl.create(:ext_management_system)) } - let(:inactive_vm) { FactoryGirl.create(:vm_vmware, :name => 'test_vm_inactive', :ems_cluster => src, :ext_management_system => nil) } - let(:storage) { FactoryGirl.create(:storage) } - let(:lan) { FactoryGirl.create(:lan) } - let(:nic) { FactoryGirl.create(:guest_device_nic, :lan => lan) } + let(:vm) { FactoryBot.create(:vm_vmware, :name => 'test_vm', :ems_cluster => src, :ext_management_system => FactoryBot.create(:ext_management_system)) } + let(:vm2) { FactoryBot.create(:vm_vmware, :ems_cluster => src, :ext_management_system => FactoryBot.create(:ext_management_system)) } + let(:inactive_vm) { FactoryBot.create(:vm_vmware, :name => 'test_vm_inactive', :ems_cluster => src, :ext_management_system => nil) } + let(:storage) { FactoryBot.create(:storage) } + let(:lan) { FactoryBot.create(:lan) } + let(:nic) { FactoryBot.create(:guest_device_nic, :lan => lan) } before do mapping.transformation_mapping_items << TransformationMappingItem.new(:source => storage, :destination => storage) mapping.transformation_mapping_items << TransformationMappingItem.new(:source => lan, :destination => lan) vm.storages << storage - vm.hardware = FactoryGirl.create(:hardware, :guest_devices => [nic]) + vm.hardware = FactoryBot.create(:hardware, :guest_devices => [nic]) end context 'with VM list' do @@ -52,47 +52,47 @@ end it 'if VM is inactive' do - inactive_vm.storages << FactoryGirl.create(:storage, :name => 'storage_for_inactive_vm') + inactive_vm.storages << FactoryBot.create(:storage, :name => 'storage_for_inactive_vm') result = mapping.search_vms_and_validate(['name' => 'test_vm_inactive']) expect(result['invalid'].first.reason).to eq(TransformationMapping::VmMigrationValidator::VM_INACTIVE) end it "if VM's cluster is not in the mapping" do - FactoryGirl.create( + FactoryBot.create( :vm_vmware, :name => 'vm2', - :ems_cluster => FactoryGirl.create(:ems_cluster, :name => 'cluster1'), - :ext_management_system => FactoryGirl.create(:ext_management_system) + :ems_cluster => FactoryBot.create(:ems_cluster, :name => 'cluster1'), + :ext_management_system => FactoryBot.create(:ext_management_system) ) result = mapping.search_vms_and_validate(['name' => 'vm2']) expect(result['invalid'].first.reason).to match(/not_exist/) end it "if VM's storages are not all in the mapping" do - vm.storages << FactoryGirl.create(:storage, :name => 'storage2') + vm.storages << FactoryBot.create(:storage, :name => 'storage2') result = mapping.search_vms_and_validate(['name' => vm.name]) expect(result['invalid'].first.reason).to match(/Mapping source not found - storages: storage2/) end it "if VM's lans are not all in the mapping" do - vm.hardware.guest_devices << FactoryGirl.create(:guest_device_nic, :lan =>FactoryGirl.create(:lan, :name => 'lan2')) + vm.hardware.guest_devices << FactoryBot.create(:guest_device_nic, :lan =>FactoryBot.create(:lan, :name => 'lan2')) result = mapping.search_vms_and_validate(['name' => vm.name]) expect(result['invalid'].first.reason).to match(/Mapping source not found - lans: lan2/) end it "if any source is invalid" do - vm.storages << FactoryGirl.create(:storage, :name => 'storage2') - vm.hardware.guest_devices << FactoryGirl.create(:guest_device_nic, :lan =>FactoryGirl.create(:lan, :name => 'lan2')) + vm.storages << FactoryBot.create(:storage, :name => 'storage2') + vm.hardware.guest_devices << FactoryBot.create(:guest_device_nic, :lan =>FactoryBot.create(:lan, :name => 'lan2')) result = mapping.search_vms_and_validate(['name' => vm.name]) expect(result['invalid'].first.reason).to match(/Mapping source not found - storages: storage2. lans: lan2/) end it 'if VM is in another migration plan' do %w(Queued Approved Active).each do |status| - FactoryGirl.create( + FactoryBot.create( :service_resource, :resource => vm, - :service_template => FactoryGirl.create(:service_template_transformation_plan), + :service_template => FactoryBot.create(:service_template_transformation_plan), :status => status ) @@ -102,10 +102,10 @@ end it 'if VM has been migrated' do - FactoryGirl.create( + FactoryBot.create( :service_resource, :resource => vm, - :service_template => FactoryGirl.create(:service_template_transformation_plan), + :service_template => FactoryBot.create(:service_template_transformation_plan), :status => 'Completed' ) @@ -121,7 +121,7 @@ end it 'returns conflict vms' do - FactoryGirl.create(:vm_vmware, :name => 'test_vm', :ems_cluster => src, :ext_management_system => FactoryGirl.create(:ext_management_system)) + FactoryBot.create(:vm_vmware, :name => 'test_vm', :ems_cluster => src, :ext_management_system => FactoryBot.create(:ext_management_system)) result = mapping.search_vms_and_validate(['name' => vm.name]) expect(result['conflicted'].first.reason).to eq(TransformationMapping::VmMigrationValidator::VM_CONFLICT) end @@ -129,9 +129,9 @@ context 'with VM list and service_template_id' do it 'returns valid vms when a ServiceTemplate record is edited with CSV containing the same VM already included in the ServiceTemplate record' do - service_template = FactoryGirl.create(:service_template_transformation_plan) + service_template = FactoryBot.create(:service_template_transformation_plan) - FactoryGirl.create( + FactoryBot.create( :service_resource, :resource => vm2, :service_template => service_template, @@ -142,10 +142,10 @@ end it 'returns invalid vms when the Service Template record is edited with CSV containing a different VM that belongs to a different ServiceTemplate record' do - service_template = FactoryGirl.create(:service_template_transformation_plan) - service_template2 = FactoryGirl.create(:service_template_transformation_plan) + service_template = FactoryBot.create(:service_template_transformation_plan) + service_template2 = FactoryBot.create(:service_template_transformation_plan) - FactoryGirl.create( + FactoryBot.create( :service_resource, :resource => vm2, :service_template => service_template, @@ -163,11 +163,11 @@ end it 'skips invalid vms' do - FactoryGirl.create( + FactoryBot.create( :vm_vmware, :name => 'vm2', - :ems_cluster => FactoryGirl.create(:ems_cluster, :name => 'cluster1'), - :ext_management_system => FactoryGirl.create(:ext_management_system) + :ems_cluster => FactoryBot.create(:ems_cluster, :name => 'cluster1'), + :ext_management_system => FactoryBot.create(:ext_management_system) ) result = mapping.search_vms_and_validate expect(result['valid'].count).to eq(1) diff --git a/spec/models/user/user_ldap_methods_spec.rb b/spec/models/user/user_ldap_methods_spec.rb index 2a34bd08b33..6318fa4d9bd 100644 --- a/spec/models/user/user_ldap_methods_spec.rb +++ b/spec/models/user/user_ldap_methods_spec.rb @@ -30,7 +30,7 @@ end it "user exists" do - user = FactoryGirl.create(:user_admin, :userid => @fqusername) + user = FactoryBot.create(:user_admin, :userid => @fqusername) allow(@auth).to receive(:lookup_by_identity).and_return(user) expect(current_user).to eq(user) end @@ -102,10 +102,10 @@ end def create_super_admin_group - FactoryGirl.create( + FactoryBot.create( :miq_group, :description => "EvmGroup-super_administrator", - :miq_user_role => FactoryGirl.create(:miq_user_role, :role => "super_administrator") + :miq_user_role => FactoryBot.create(:miq_user_role, :role => "super_administrator") ) end diff --git a/spec/models/user_password_spec.rb b/spec/models/user_password_spec.rb index 1055e43594e..489c0b58010 100644 --- a/spec/models/user_password_spec.rb +++ b/spec/models/user_password_spec.rb @@ -6,7 +6,7 @@ EvmSpecHelper.create_guid_miq_server_zone @old = 'smartvm' - @admin = FactoryGirl.create(:user, :userid => 'admin', + @admin = FactoryBot.create(:user, :userid => 'admin', :password_digest => BCrypt::Password.create(@old)) end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 37442bbd6c8..24eb6c6fc02 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,28 +1,28 @@ describe User do context "validations" do it "should ensure presence of name" do - expect(FactoryGirl.build(:user, :name => nil)).not_to be_valid + expect(FactoryBot.build(:user, :name => nil)).not_to be_valid end it "should ensure presence of user id" do - expect(FactoryGirl.build(:user, :userid => nil)).not_to be_valid + expect(FactoryBot.build(:user, :userid => nil)).not_to be_valid end it "should invalidate incorrect email address" do - expect(FactoryGirl.build(:user, :email => "thisguy@@manageiq.com")).not_to be_valid + expect(FactoryBot.build(:user, :email => "thisguy@@manageiq.com")).not_to be_valid end it "should validate email address with a value of nil" do - expect(FactoryGirl.build(:user, :email => nil)).to be_valid + expect(FactoryBot.build(:user, :email => nil)).to be_valid end it "should save proper email address" do - expect(FactoryGirl.build(:user, :email => "that.guy@manageiq.com")).to be_valid + expect(FactoryBot.build(:user, :email => "that.guy@manageiq.com")).to be_valid end end describe "#change_password" do - let(:user) { FactoryGirl.create(:user, :password => "smartvm") } + let(:user) { FactoryBot.create(:user, :password => "smartvm") } it "should change user password" do password = user.password @@ -41,12 +41,12 @@ end context "filter methods" do - let(:user) { FactoryGirl.create(:user, :miq_groups => [miq_group]) } + let(:user) { FactoryBot.create(:user, :miq_groups => [miq_group]) } let(:mfilters) { {"managed" => "m"} } let(:bfilters) { {"belongsto" => "b"} } - let(:miq_group) { FactoryGirl.create(:miq_group, :entitlement => entitlement) } + let(:miq_group) { FactoryBot.create(:miq_group, :entitlement => entitlement) } let(:entitlement) do - entitlement = FactoryGirl.create(:entitlement) + entitlement = FactoryBot.create(:entitlement) entitlement.set_managed_filters(mfilters) entitlement.set_belongsto_filters(bfilters) entitlement.save! @@ -62,7 +62,7 @@ context "timezone methods" do let!(:miq_server) { EvmSpecHelper.local_miq_server } - let(:user) { FactoryGirl.create(:user) } + let(:user) { FactoryBot.create(:user) } describe "#get_timezone" do it "gets Server time zone setting" do @@ -83,7 +83,7 @@ describe ".missing_user_features" do it "user with group and role returns nil" do - user = FactoryGirl.create(:user_admin) + user = FactoryBot.create(:user_admin) expect(User.missing_user_features(user)).to be_nil end @@ -92,19 +92,19 @@ end it "missing group returns 'Group'" do - user = FactoryGirl.create(:user) + user = FactoryBot.create(:user) expect(User.missing_user_features(user)).to eq "Group" end it "missing role returns 'Role'" do - user = FactoryGirl.create(:user_with_group) + user = FactoryBot.create(:user_with_group) expect(User.missing_user_features(user)).to eq "Role" end end describe "role methods" do let(:user) do - FactoryGirl.create(:user, + FactoryBot.create(:user, :settings => {"Setting1" => 1, "Setting2" => 2, "Setting3" => 3}, :role => role_name) end @@ -206,14 +206,14 @@ context "group assignment" do before do - @group1 = FactoryGirl.create(:miq_group, :description => "EvmGroup 1") - @group2 = FactoryGirl.create(:miq_group, :description => "EvmGroup 2") - @group3 = FactoryGirl.create(:miq_group, :description => "EvmGroup 3") + @group1 = FactoryBot.create(:miq_group, :description => "EvmGroup 1") + @group2 = FactoryBot.create(:miq_group, :description => "EvmGroup 2") + @group3 = FactoryBot.create(:miq_group, :description => "EvmGroup 3") end describe "#miq_groups=" do before do - @user = FactoryGirl.create(:user, :miq_groups => [@group3]) + @user = FactoryBot.create(:user, :miq_groups => [@group3]) end it "sets miq_groups" do @@ -243,7 +243,7 @@ describe "#current_group=" do before do - @user = FactoryGirl.create(:user, :miq_groups => [@group1, @group2]) + @user = FactoryBot.create(:user, :miq_groups => [@group1, @group2]) end it "sets current_group" do @@ -272,36 +272,36 @@ @disk_size = 1_000_000 @num_cpu = 2 - group = FactoryGirl.create(:miq_group) - @user = FactoryGirl.create(:user, :miq_groups => [group]) - @ems = FactoryGirl.create(:ems_vmware, :name => "test_vcenter") - @storage = FactoryGirl.create(:storage, :name => "test_storage_nfs", :store_type => "NFS") - - @hw1 = FactoryGirl.create(:hardware, :cpu_total_cores => @num_cpu, :memory_mb => @ram_size) - @hw2 = FactoryGirl.create(:hardware, :cpu_total_cores => @num_cpu, :memory_mb => @ram_size) - @hw3 = FactoryGirl.create(:hardware, :cpu_total_cores => @num_cpu, :memory_mb => @ram_size) - @hw4 = FactoryGirl.create(:hardware, :cpu_total_cores => @num_cpu, :memory_mb => @ram_size) - @disk1 = FactoryGirl.create(:disk, :device_type => "disk", :size => @disk_size, :hardware_id => @hw1.id) - @disk2 = FactoryGirl.create(:disk, :device_type => "disk", :size => @disk_size, :hardware_id => @hw2.id) - @disk3 = FactoryGirl.create(:disk, :device_type => "disk", :size => @disk_size, :hardware_id => @hw3.id) - @disk4 = FactoryGirl.create(:disk, :device_type => "disk", :size => @disk_size, :hardware_id => @hw4.id) - - @active_vm = FactoryGirl.create(:vm_vmware, + group = FactoryBot.create(:miq_group) + @user = FactoryBot.create(:user, :miq_groups => [group]) + @ems = FactoryBot.create(:ems_vmware, :name => "test_vcenter") + @storage = FactoryBot.create(:storage, :name => "test_storage_nfs", :store_type => "NFS") + + @hw1 = FactoryBot.create(:hardware, :cpu_total_cores => @num_cpu, :memory_mb => @ram_size) + @hw2 = FactoryBot.create(:hardware, :cpu_total_cores => @num_cpu, :memory_mb => @ram_size) + @hw3 = FactoryBot.create(:hardware, :cpu_total_cores => @num_cpu, :memory_mb => @ram_size) + @hw4 = FactoryBot.create(:hardware, :cpu_total_cores => @num_cpu, :memory_mb => @ram_size) + @disk1 = FactoryBot.create(:disk, :device_type => "disk", :size => @disk_size, :hardware_id => @hw1.id) + @disk2 = FactoryBot.create(:disk, :device_type => "disk", :size => @disk_size, :hardware_id => @hw2.id) + @disk3 = FactoryBot.create(:disk, :device_type => "disk", :size => @disk_size, :hardware_id => @hw3.id) + @disk4 = FactoryBot.create(:disk, :device_type => "disk", :size => @disk_size, :hardware_id => @hw4.id) + + @active_vm = FactoryBot.create(:vm_vmware, :name => "Active VM", :evm_owner_id => @user.id, :ems_id => @ems.id, :storage_id => @storage.id, :hardware => @hw1) - @archived_vm = FactoryGirl.create(:vm_vmware, + @archived_vm = FactoryBot.create(:vm_vmware, :name => "Archived VM", :evm_owner_id => @user.id, :hardware => @hw2) - @orphaned_vm = FactoryGirl.create(:vm_vmware, + @orphaned_vm = FactoryBot.create(:vm_vmware, :name => "Orphaned VM", :evm_owner_id => @user.id, :storage_id => @storage.id, :hardware => @hw3) - @retired_vm = FactoryGirl.create(:vm_vmware, + @retired_vm = FactoryBot.create(:vm_vmware, :name => "Retired VM", :evm_owner_id => @user.id, :retired => true, @@ -336,7 +336,7 @@ end context ".authenticate_with_http_basic" do - let(:user) { FactoryGirl.create(:user, :password => "dummy") } + let(:user) { FactoryBot.create(:user, :password => "dummy") } before do EvmSpecHelper.create_guid_miq_server_zone @@ -366,24 +366,24 @@ context "#accessible_vms" do before do - @user = FactoryGirl.create(:user_admin) + @user = FactoryBot.create(:user_admin) - @self_service_role = FactoryGirl.create( + @self_service_role = FactoryBot.create( :miq_user_role, :name => "ss_role", :settings => {:restrictions => {:vms => :user_or_group}} ) - @self_service_group = FactoryGirl.create(:miq_group, :miq_user_role => @self_service_role) + @self_service_group = FactoryBot.create(:miq_group, :miq_user_role => @self_service_role) - @limited_self_service_role = FactoryGirl.create( + @limited_self_service_role = FactoryBot.create( :miq_user_role, :name => "lss_role", :settings => {:restrictions => {:vms => :user}} ) - @limited_self_service_group = FactoryGirl.create(:miq_group, :miq_user_role => @limited_self_service_role) + @limited_self_service_group = FactoryBot.create(:miq_group, :miq_user_role => @limited_self_service_role) @vm = [] - (1..5).each { |i| @vm[i] = FactoryGirl.create(:vm_redhat, :name => "vm_#{i}") } + (1..5).each { |i| @vm[i] = FactoryBot.create(:vm_redhat, :name => "vm_#{i}") } end subject(:accessible_vms) { @user.accessible_vms } @@ -410,9 +410,9 @@ end describe "#current_group_by_description=" do - subject { FactoryGirl.create(:user, :miq_groups => [g1, g2], :current_group => g1) } - let(:g1) { FactoryGirl.create(:miq_group) } - let(:g2) { FactoryGirl.create(:miq_group) } + subject { FactoryBot.create(:user, :miq_groups => [g1, g2], :current_group => g1) } + let(:g1) { FactoryBot.create(:miq_group) } + let(:g2) { FactoryBot.create(:miq_group) } it "ignores blank" do subject.current_group_by_description = "" @@ -427,7 +427,7 @@ end it "ignores a group that you do not belong" do - subject.current_group_by_description = FactoryGirl.create(:miq_group).description + subject.current_group_by_description = FactoryBot.create(:miq_group).description expect(subject.current_group).to eq(g1) expect(subject.miq_group_description).to eq(g1.description) end @@ -439,7 +439,7 @@ end context "as a super admin" do - subject { FactoryGirl.create(:user, :role => "super_administrator") } + subject { FactoryBot.create(:user, :role => "super_administrator") } it "sets any group, regardless of group membership" do expect(subject).to be_super_admin_user @@ -451,7 +451,7 @@ it "ignores groups from other regions" do expect(subject).to be_super_admin_user - group = FactoryGirl.create(:miq_group, :id => ApplicationRecord.id_in_region(1, ApplicationRecord.my_region_number + 1)) + group = FactoryBot.create(:miq_group, :id => ApplicationRecord.id_in_region(1, ApplicationRecord.my_region_number + 1)) subject.current_group_by_description = group.description expect(subject.current_group.description).not_to eq(group.description) @@ -461,18 +461,18 @@ describe ".find_by_lower_email" do it "uses cache" do - u = FactoryGirl.build(:user_with_email) + u = FactoryBot.build(:user_with_email) expect(User.find_by_lower_email(u.email.upcase, u)).to eq(u) end it "finds in the table" do - u = FactoryGirl.create(:user_with_email) + u = FactoryBot.create(:user_with_email) expect(User.find_by_lower_email(u.email.upcase)).to eq(u) end end describe "#current_tenant" do - let(:user1) { FactoryGirl.create(:user_with_group) } + let(:user1) { FactoryBot.create(:user_with_group) } it "sets the tenant" do User.with_user(user1) do @@ -483,7 +483,7 @@ end describe "#current_user=" do - let(:user1) { FactoryGirl.create(:user) } + let(:user1) { FactoryBot.create(:user) } it "sets the user" do User.current_user = user1 @@ -493,8 +493,8 @@ end describe "#with_user" do - let(:user1) { FactoryGirl.create(:user) } - let(:user2) { FactoryGirl.create(:user) } + let(:user1) { FactoryBot.create(:user) } + let(:user2) { FactoryBot.create(:user) } it "sets the user" do User.with_user(user1) do @@ -523,8 +523,8 @@ end describe "#with_user_group" do - let(:user1) { FactoryGirl.create(:user_with_group) } - let(:user2) { FactoryGirl.create(:user_with_group) } + let(:user1) { FactoryBot.create(:user_with_group) } + let(:user2) { FactoryBot.create(:user_with_group) } it "sets the user and group" do User.with_user_group(user1, user2.current_group_id) do @@ -542,17 +542,17 @@ end describe "#change_current_group" do - let(:group1) { FactoryGirl.create(:miq_group) } - let(:group2) { FactoryGirl.create(:miq_group) } + let(:group1) { FactoryBot.create(:miq_group) } + let(:group2) { FactoryBot.create(:miq_group) } it "changes the user to a group other than the current one" do - user = FactoryGirl.create(:user, :miq_groups => [group1, group2], :current_group => group1) + user = FactoryBot.create(:user, :miq_groups => [group1, group2], :current_group => group1) user.change_current_group expect(user.current_group).to eq(group2) end it "raises an error if there is no group other than the current one to switch to" do - user = FactoryGirl.create(:user, :miq_groups => [group1], :current_group => group1) + user = FactoryBot.create(:user, :miq_groups => [group1], :current_group => group1) expect { user.change_current_group } .to raise_error(RuntimeError, /The user's current group cannot be changed because the user does not belong to any other group/) end @@ -560,7 +560,7 @@ context ".super_admin" do it "has super_admin" do - FactoryGirl.create(:miq_group, :role => "super_administrator") + FactoryBot.create(:miq_group, :role => "super_administrator") User.seed expect(User.super_admin).to be_super_admin_user end @@ -589,22 +589,22 @@ describe ".with_same_userid" do # this is testing the select does not break and in general, the scope works it "properly handles select clause" do - u = FactoryGirl.create(:user) + u = FactoryBot.create(:user) expect(User.select(:id, :email).with_same_userid(u.id)).to eq([u]) end end describe ".with_roles_excluding" do it "handles multiple columns" do - a1 = FactoryGirl.create(:miq_group, :features => "good") - a2 = FactoryGirl.create(:miq_group, :features => "something") - b = FactoryGirl.create(:miq_group, :features => %w(good everything)) - c = FactoryGirl.create(:miq_group, :features => "everything") + a1 = FactoryBot.create(:miq_group, :features => "good") + a2 = FactoryBot.create(:miq_group, :features => "something") + b = FactoryBot.create(:miq_group, :features => %w(good everything)) + c = FactoryBot.create(:miq_group, :features => "everything") - u1 = FactoryGirl.create(:user, :miq_groups => [a1]) - u2 = FactoryGirl.create(:user, :miq_groups => [a1, a2]) - FactoryGirl.create(:user, :miq_groups => [a1, b]) - FactoryGirl.create(:user, :miq_groups => [c]) + u1 = FactoryBot.create(:user, :miq_groups => [a1]) + u2 = FactoryBot.create(:user, :miq_groups => [a1, a2]) + FactoryBot.create(:user, :miq_groups => [a1, b]) + FactoryBot.create(:user, :miq_groups => [c]) expect(User.with_roles_excluding("everything").select(:id, :name)).to match_array([u1, u2]) end @@ -612,12 +612,12 @@ describe "#regional_users" do let(:other_id) { ApplicationRecord.id_in_region(1, ApplicationRecord.my_region_number + 1) } - let(:user) { FactoryGirl.create(:user) } - let!(:regional_user) { FactoryGirl.create(:user, :userid => user.userid.upcase, :id => other_id) } + let(:user) { FactoryBot.create(:user) } + let!(:regional_user) { FactoryBot.create(:user, :userid => user.userid.upcase, :id => other_id) } it "finds regional users" do - FactoryGirl.create(:user) # ensure these doen't come back - FactoryGirl.create(:user, :id => other_id + 1) + FactoryBot.create(:user) # ensure these doen't come back + FactoryBot.create(:user, :id => other_id + 1) expect(user.regional_users).to match_array([user, regional_user]) end diff --git a/spec/models/vim_performance_analysis_spec.rb b/spec/models/vim_performance_analysis_spec.rb index af02666375b..2944febd610 100644 --- a/spec/models/vim_performance_analysis_spec.rb +++ b/spec/models/vim_performance_analysis_spec.rb @@ -1,14 +1,14 @@ RSpec.describe VimPerformanceAnalysis do let(:tag_text) { "operations/good" } - let(:tag_good) { FactoryGirl.create(:tag, :name => "/managed/#{tag_text}") } - let(:tag_bad) { FactoryGirl.create(:tag, :name => "/managed/operations/bad") } - let(:time_profile) { FactoryGirl.create(:time_profile_with_rollup, :profile => {:tz => "UTC"}) } - let(:ems) { FactoryGirl.create(:ems_vmware) } + let(:tag_good) { FactoryBot.create(:tag, :name => "/managed/#{tag_text}") } + let(:tag_bad) { FactoryBot.create(:tag, :name => "/managed/operations/bad") } + let(:time_profile) { FactoryBot.create(:time_profile_with_rollup, :profile => {:tz => "UTC"}) } + let(:ems) { FactoryBot.create(:ems_vmware) } let(:good_day) { DateTime.current - 2.day } let(:bad_day) { DateTime.current - 4.months } let(:vm1) do - FactoryGirl.create(:vm_vmware, :name => "test_vm", :tags => [tag_good], :ext_management_system => ems).tap do |vm| + FactoryBot.create(:vm_vmware, :name => "test_vm", :tags => [tag_good], :ext_management_system => ems).tap do |vm| [7, 8, 9, 10].each do |hour| add_rollup(vm, (good_day + hour.hours).to_s, tag_text) add_rollup(vm, (bad_day + hour.hours).to_s, tag_text) @@ -17,10 +17,10 @@ end end - let(:storage) { FactoryGirl.create(:storage_target_vmware) } + let(:storage) { FactoryBot.create(:storage_target_vmware) } let(:host1) do - FactoryGirl.create(:host, - :hardware => FactoryGirl.create(:hardware, + FactoryBot.create(:host, + :hardware => FactoryBot.create(:hardware, :memory_mb => 8124, :cpu_total_cores => 1, :cpu_speed => 9576), @@ -29,7 +29,7 @@ end let(:ems_cluster) do - FactoryGirl.create(:ems_cluster, :ext_management_system => ems, :hosts => [host1]) + FactoryBot.create(:ems_cluster, :ext_management_system => ems, :hosts => [host1]) end before do @@ -56,7 +56,7 @@ describe '.group_perf_by_timestamp' do let(:storage_metric) do - FactoryGirl.create(:metric_rollup, + FactoryBot.create(:metric_rollup, :derived_storage_total => '42', :derived_storage_free => '13') end @@ -85,7 +85,7 @@ private def add_rollup(vm, timestamp, tag = tag_text) - vm.metric_rollups << FactoryGirl.create(:metric_rollup_vm_daily, :with_data, + vm.metric_rollups << FactoryBot.create(:metric_rollup_vm_daily, :with_data, :timestamp => timestamp, :tag_names => tag, :parent_host => vm.host, diff --git a/spec/models/vim_performance_planning_spec.rb b/spec/models/vim_performance_planning_spec.rb index c6e8f248388..c098e39ac1c 100644 --- a/spec/models/vim_performance_planning_spec.rb +++ b/spec/models/vim_performance_planning_spec.rb @@ -1,11 +1,11 @@ describe VimPerformancePlanning do context '.vm_how_many_more_can_fit' do let!(:local) { EvmSpecHelper.local_miq_server } - let(:cluster) { FactoryGirl.create(:ems_cluster) } - let(:compute_host) { FactoryGirl.create(:host, :ems_cluster => cluster) } + let(:cluster) { FactoryBot.create(:ems_cluster) } + let(:compute_host) { FactoryBot.create(:host, :ems_cluster => cluster) } let(:time_profile) { TimeProfile.seed } let!(:metrics) do - FactoryGirl.create(:metric_rollup, :with_data, + FactoryBot.create(:metric_rollup, :with_data, :resource => compute_host, :capture_interval_name => 'daily', :time_profile => time_profile) end let(:options) do diff --git a/spec/models/vim_performance_state/purging_spec.rb b/spec/models/vim_performance_state/purging_spec.rb index 1a0e8d88860..8ec8eeb4f79 100644 --- a/spec/models/vim_performance_state/purging_spec.rb +++ b/spec/models/vim_performance_state/purging_spec.rb @@ -3,20 +3,20 @@ describe ".purge_by_orphaned" do it "purges all the orphaned rows for all referenced classes" do # Create an orphaned row referencing VmOrTemplate - vm1 = FactoryGirl.create(:vm_or_template) - vm_perf1 = FactoryGirl.create(:vim_performance_state, :resource => vm1) + vm1 = FactoryBot.create(:vm_or_template) + vm_perf1 = FactoryBot.create(:vim_performance_state, :resource => vm1) vm1.delete # Create a non-orphaned row referencing VmOrTemplate - vm_perf2 = FactoryGirl.create(:vim_performance_state, :resource => FactoryGirl.create(:vm_or_template)) + vm_perf2 = FactoryBot.create(:vim_performance_state, :resource => FactoryBot.create(:vm_or_template)) # Create an orphaned row referencing ExtManagementSystem - ems1 = FactoryGirl.create(:ext_management_system) - ems_perf1 = FactoryGirl.create(:vim_performance_state, :resource => ems1) + ems1 = FactoryBot.create(:ext_management_system) + ems_perf1 = FactoryBot.create(:vim_performance_state, :resource => ems1) ems1.delete # Create a non-orphaned row referencing ExtManagementSystem - ems_perf2 = FactoryGirl.create(:vim_performance_state, :resource => FactoryGirl.create(:ext_management_system)) + ems_perf2 = FactoryBot.create(:vim_performance_state, :resource => FactoryBot.create(:ext_management_system)) expect(described_class.all).to match_array([vm_perf1, vm_perf2, ems_perf1, ems_perf2]) count = described_class.purge_by_orphaned("resource") diff --git a/spec/models/vim_performance_state_spec.rb b/spec/models/vim_performance_state_spec.rb index 5d104dc9fa1..5a4f1106f29 100644 --- a/spec/models/vim_performance_state_spec.rb +++ b/spec/models/vim_performance_state_spec.rb @@ -1,19 +1,19 @@ RSpec.describe VimPerformanceState do describe ".capture_host_sockets" do it "returns the host sockets when given a host" do - hardware = FactoryGirl.build(:hardware, :cpu_sockets => 2) - host = FactoryGirl.create(:host, :hardware => hardware) + hardware = FactoryBot.build(:hardware, :cpu_sockets => 2) + host = FactoryBot.create(:host, :hardware => hardware) state = VimPerformanceState.capture(host) expect(state.host_sockets).to eq(2) end it "rolls up the total sockets when given something that has hosts" do - hardware_1 = FactoryGirl.build(:hardware, :cpu_sockets => 2) - hardware_2 = FactoryGirl.build(:hardware, :cpu_sockets => 4) - host_1 = FactoryGirl.build(:host, :hardware => hardware_1) - host_2 = FactoryGirl.build(:host, :hardware => hardware_2) - cluster = FactoryGirl.create(:ems_cluster, :hosts => [host_1, host_2]) + hardware_1 = FactoryBot.build(:hardware, :cpu_sockets => 2) + hardware_2 = FactoryBot.build(:hardware, :cpu_sockets => 4) + host_1 = FactoryBot.build(:host, :hardware => hardware_1) + host_2 = FactoryBot.build(:host, :hardware => hardware_2) + cluster = FactoryBot.create(:ems_cluster, :hosts => [host_1, host_2]) state = VimPerformanceState.capture(cluster) expect(state.host_sockets).to eq(6) @@ -48,26 +48,26 @@ let(:ssd_size) { 1_234 } let(:hdd1_size) { 5_678 } let(:hdd2_size) { 9_101 } - let(:ssd_volume) { FactoryGirl.create(:cloud_volume_openstack, :volume_type => 'ssd') } - let(:ssd_disk) { FactoryGirl.create(:disk, :size => ssd_size, :backing => ssd_volume) } - let(:hdd_volume) { FactoryGirl.create(:cloud_volume_openstack, :volume_type => nil) } - let(:hdd1_disk) { FactoryGirl.create(:disk, :size => hdd1_size, :backing => hdd_volume) } - let(:hdd2_disk) { FactoryGirl.create(:disk, :size => hdd2_size) } - let(:hardware) { FactoryGirl.create(:hardware, :disks => [ssd_disk, hdd1_disk, hdd2_disk]) } - let(:vm) { FactoryGirl.create(:vm_openstack, :hardware => hardware) } + let(:ssd_volume) { FactoryBot.create(:cloud_volume_openstack, :volume_type => 'ssd') } + let(:ssd_disk) { FactoryBot.create(:disk, :size => ssd_size, :backing => ssd_volume) } + let(:hdd_volume) { FactoryBot.create(:cloud_volume_openstack, :volume_type => nil) } + let(:hdd1_disk) { FactoryBot.create(:disk, :size => hdd1_size, :backing => hdd_volume) } + let(:hdd2_disk) { FactoryBot.create(:disk, :size => hdd2_size) } + let(:hardware) { FactoryBot.create(:hardware, :disks => [ssd_disk, hdd1_disk, hdd2_disk]) } + let(:vm) { FactoryBot.create(:vm_openstack, :hardware => hardware) } subject { vm.perf_capture_state.allocated_disk_types } it { is_expected.to match('ssd' => ssd_size, 'unclassified' => hdd1_size + hdd2_size) } context 'when disk size is nil' do - let!(:hdd1_disk) { FactoryGirl.create(:disk, :size => nil, :backing => hdd_volume) } + let!(:hdd1_disk) { FactoryBot.create(:disk, :size => nil, :backing => hdd_volume) } it { is_expected.to match('ssd' => ssd_size, 'unclassified' => hdd2_size) } context "when all disk's sizes are nil" do - let!(:hdd2_disk) { FactoryGirl.create(:disk, :size => nil, :backing => hdd_volume) } - let!(:ssd_disk) { FactoryGirl.create(:disk, :size => nil, :backing => ssd_volume) } + let!(:hdd2_disk) { FactoryBot.create(:disk, :size => nil, :backing => hdd_volume) } + let!(:ssd_disk) { FactoryBot.create(:disk, :size => nil, :backing => ssd_volume) } it { is_expected.to be_empty } end diff --git a/spec/models/vim_performance_tag_spec.rb b/spec/models/vim_performance_tag_spec.rb index e80ac46d04f..7b62175b4d4 100644 --- a/spec/models/vim_performance_tag_spec.rb +++ b/spec/models/vim_performance_tag_spec.rb @@ -1,7 +1,7 @@ describe VimPerformanceTag do before do @server = EvmSpecHelper.local_miq_server - @ems = FactoryGirl.create(:ems_vmware, :zone => @server.zone) + @ems = FactoryBot.create(:ems_vmware, :zone => @server.zone) allow(Classification).to receive(:category_names_for_perf_by_tag).and_return(["environment"]) @classification_entries = ["prod", "dev", "test"] @@ -14,12 +14,12 @@ @test = "environment/test" @vms = [] - @vms << FactoryGirl.create(:vm_vmware, :name => "prod") - @vms << FactoryGirl.create(:vm_vmware, :name => "dev") - @vms << FactoryGirl.create(:vm_vmware, :name => "test") - @vms << FactoryGirl.create(:vm_vmware, :name => "none") + @vms << FactoryBot.create(:vm_vmware, :name => "prod") + @vms << FactoryBot.create(:vm_vmware, :name => "dev") + @vms << FactoryBot.create(:vm_vmware, :name => "test") + @vms << FactoryBot.create(:vm_vmware, :name => "none") - @host = FactoryGirl.create(:host, :vms => @vms, :vmm_vendor => 'vmware', :vmm_product => "ESX", :type => "ManageIQ::Providers::Vmware::InfraManager::HostEsx") + @host = FactoryBot.create(:host, :vms => @vms, :vmm_vendor => 'vmware', :vmm_product => "ESX", :type => "ManageIQ::Providers::Vmware::InfraManager::HostEsx") @host = Host.find_by(:id => @host.id) end @@ -92,13 +92,13 @@ @vms.each do |vm| case_sets[vm.name.to_sym].each do |timestamp, value| if vm.name == "none" - perf = FactoryGirl.create(:metric_rollup_vm_hr, + perf = FactoryBot.create(:metric_rollup_vm_hr, :timestamp => timestamp, :cpu_usagemhz_rate_average => value ) else tag = "environment/#{vm.name}" - perf = FactoryGirl.create(:metric_rollup_vm_hr, + perf = FactoryBot.create(:metric_rollup_vm_hr, :timestamp => timestamp, :cpu_usagemhz_rate_average => value, :tag_names => tag @@ -110,7 +110,7 @@ end case_sets[:host].each do |timestamp, value| - perf = FactoryGirl.create(:metric_rollup_host_hr, + perf = FactoryBot.create(:metric_rollup_host_hr, :timestamp => timestamp, :cpu_usagemhz_rate_average => value ) diff --git a/spec/models/vm/operations_spec.rb b/spec/models/vm/operations_spec.rb index 6b5e7e2f4d4..e21fca1b872 100644 --- a/spec/models/vm/operations_spec.rb +++ b/spec/models/vm/operations_spec.rb @@ -1,12 +1,12 @@ describe 'VM::Operations' do before do @miq_server = EvmSpecHelper.local_miq_server - @ems = FactoryGirl.create(:ems_vmware, :zone => @miq_server.zone) - @vm = FactoryGirl.create(:vm_vmware, :ems_id => @ems.id) + @ems = FactoryBot.create(:ems_vmware, :zone => @miq_server.zone) + @vm = FactoryBot.create(:vm_vmware, :ems_id => @ems.id) ipaddresses = %w(fe80::21a:4aff:fe22:dde5 127.0.0.1) allow(@vm).to receive(:ipaddresses).and_return(ipaddresses) - @hardware = FactoryGirl.create(:hardware) + @hardware = FactoryBot.create(:hardware) @hardware.ipaddresses << '10.142.0.2' @hardware.ipaddresses << '35.190.140.48' end @@ -27,9 +27,9 @@ context 'cloud providers' do before { @ipaddresses = %w(10.10.1.121 35.190.140.48) } it 'returns the public ipv4 address for AWS' do - ems = FactoryGirl.create(:ems_google, :project => 'manageiq-dev') - az = FactoryGirl.create(:availability_zone_google) - vm = FactoryGirl.create(:vm_google, + ems = FactoryBot.create(:ems_google, :project => 'manageiq-dev') + az = FactoryBot.create(:availability_zone_google) + vm = FactoryBot.create(:vm_google, :ext_management_system => ems, :ems_ref => 123, :availability_zone => az, @@ -40,8 +40,8 @@ end it 'returns the public ipv4 address for GCE' do - ems = FactoryGirl.create(:ems_amazon) - vm = FactoryGirl.create(:vm_amazon, :ext_management_system => ems, :hardware => @hardware) + ems = FactoryBot.create(:ems_amazon) + vm = FactoryBot.create(:vm_amazon, :ext_management_system => ems, :hardware => @hardware) allow(vm).to receive(:ipaddresses).and_return(@ipaddresses) url = vm.send(:ipv4_address) expect(url).to eq('35.190.140.48') @@ -52,8 +52,8 @@ context '#public_address' do it 'returns a public ipv4 address' do ipaddresses = %w(10.10.1.121 35.190.140.48) - ems = FactoryGirl.create(:ems_amazon) - vm = FactoryGirl.create(:vm_amazon, :ext_management_system => ems, :hardware => @hardware) + ems = FactoryBot.create(:ems_amazon) + vm = FactoryBot.create(:vm_amazon, :ext_management_system => ems, :hardware => @hardware) allow(vm).to receive(:ipaddresses).and_return(ipaddresses) url = vm.send(:public_address) expect(url).to eq('35.190.140.48') diff --git a/spec/models/vm/retirement_management_spec.rb b/spec/models/vm/retirement_management_spec.rb index e771dacc1fa..1c8fbbe0d34 100644 --- a/spec/models/vm/retirement_management_spec.rb +++ b/spec/models/vm/retirement_management_spec.rb @@ -1,12 +1,12 @@ describe "VM Retirement Management" do - let!(:user) { FactoryGirl.create(:user_miq_request_approver) } - let(:region) { FactoryGirl.create(:miq_region, :region => ApplicationRecord.my_region_number) } - let(:vm2) { FactoryGirl.create(:vm) } + let!(:user) { FactoryBot.create(:user_miq_request_approver) } + let(:region) { FactoryBot.create(:miq_region, :region => ApplicationRecord.my_region_number) } + let(:vm2) { FactoryBot.create(:vm) } before do @zone = EvmSpecHelper.local_miq_server.zone - @ems = FactoryGirl.create(:ems_vmware, :zone => @zone) - @vm = FactoryGirl.create(:vm_vmware, :ems_id => @ems.id, :evm_owner => user) + @ems = FactoryBot.create(:ems_vmware, :zone => @zone) + @vm = FactoryBot.create(:vm_vmware, :ems_id => @ems.id, :evm_owner => user) end it "#retirement_check" do @@ -148,7 +148,7 @@ end it "#retirement_due?" do - vm = FactoryGirl.create(:vm_vmware, :ems_id => @ems.id) + vm = FactoryBot.create(:vm_vmware, :ems_id => @ems.id) expect(vm.retirement_due?).to be_falsey vm.update_attributes(:retires_on => Time.zone.today + 1.day) expect(vm.retirement_due?).to be_falsey @@ -183,7 +183,7 @@ it "#raise_audit_event" do event_name = 'foo' message = 'bar' - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) event_hash = {:target_class => "Vm", :target_id => vm.id.to_s, :event => event_name, :message => message} expect(AuditEvent).to receive(:success).with(event_hash) diff --git a/spec/models/vm/snapshotting_spec.rb b/spec/models/vm/snapshotting_spec.rb index 663f507e89d..eb076808910 100644 --- a/spec/models/vm/snapshotting_spec.rb +++ b/spec/models/vm/snapshotting_spec.rb @@ -1,10 +1,10 @@ describe "VM Snapshotting" do before { EvmSpecHelper.local_miq_server } - let(:vm) { FactoryGirl.create(:vm) } + let(:vm) { FactoryBot.create(:vm) } describe ".v_total_snapshots" do it "counts many" do - FactoryGirl.create_list(:snapshot, 2, :create_time => 1.minute.ago, :vm_or_template => vm) + FactoryBot.create_list(:snapshot, 2, :create_time => 1.minute.ago, :vm_or_template => vm) expect(vm.v_total_snapshots).to eq(2) end @@ -15,7 +15,7 @@ describe ".v_snapshot_oldest_name" do it "returns value" do - FactoryGirl.create(:snapshot, :create_time => 1.minute.ago, :vm_or_template => vm, :name => "the name") + FactoryBot.create(:snapshot, :create_time => 1.minute.ago, :vm_or_template => vm, :name => "the name") expect(vm.v_snapshot_oldest_name).to eq("the name") end @@ -26,7 +26,7 @@ describe ".v_snapshot_oldest_description" do it "returns value" do - FactoryGirl.create(:snapshot, :create_time => 1.minute.ago, :vm_or_template => vm, :description => "the description") + FactoryBot.create(:snapshot, :create_time => 1.minute.ago, :vm_or_template => vm, :description => "the description") expect(vm.v_snapshot_oldest_description).to eq("the description") end @@ -37,7 +37,7 @@ describe ".v_snapshot_oldest_total_size" do it "returns value" do - FactoryGirl.create(:snapshot, :create_time => 1.minute.ago, :vm_or_template => vm, :total_size => 500) + FactoryBot.create(:snapshot, :create_time => 1.minute.ago, :vm_or_template => vm, :total_size => 500) expect(vm.v_snapshot_oldest_total_size).to eq(500) end @@ -49,7 +49,7 @@ describe ".v_snapshot_newest_name" do it "returns value" do - FactoryGirl.create(:snapshot, :create_time => 1.minute.ago, :vm_or_template => vm, :name => "the name") + FactoryBot.create(:snapshot, :create_time => 1.minute.ago, :vm_or_template => vm, :name => "the name") expect(vm.v_snapshot_newest_name).to eq("the name") end @@ -60,7 +60,7 @@ describe ".v_snapshot_newest_description" do it "returns value" do - FactoryGirl.create(:snapshot, :create_time => 1.minute.ago, :vm_or_template => vm, :description => "the description") + FactoryBot.create(:snapshot, :create_time => 1.minute.ago, :vm_or_template => vm, :description => "the description") expect(vm.v_snapshot_newest_description).to eq("the description") end @@ -71,7 +71,7 @@ describe ".v_snapshot_newest_total_size" do it "returns value" do - FactoryGirl.create(:snapshot, :create_time => 1.minute.ago, :vm_or_template => vm, :total_size => 500) + FactoryBot.create(:snapshot, :create_time => 1.minute.ago, :vm_or_template => vm, :total_size => 500) expect(vm.v_snapshot_newest_total_size).to eq(500) end diff --git a/spec/models/vm_migrate_task_spec.rb b/spec/models/vm_migrate_task_spec.rb index 1a947d4544d..c86e4e139a8 100644 --- a/spec/models/vm_migrate_task_spec.rb +++ b/spec/models/vm_migrate_task_spec.rb @@ -3,7 +3,7 @@ let(:vm) { Vm.new } before do subject.vm = vm - host = FactoryGirl.create(:host, :name => "test") + host = FactoryBot.create(:host, :name => "test") subject.update_attributes(:options => {:placement_host_name => [host.id, host.name]}) end diff --git a/spec/models/vm_migrate_workflow_spec.rb b/spec/models/vm_migrate_workflow_spec.rb index 07dc636858b..ca639678b8d 100644 --- a/spec/models/vm_migrate_workflow_spec.rb +++ b/spec/models/vm_migrate_workflow_spec.rb @@ -1,11 +1,11 @@ describe VmMigrateWorkflow do include Spec::Support::WorkflowHelper - let(:admin) { FactoryGirl.create(:user_with_group) } - let(:ems) { FactoryGirl.create(:ems_vmware) } - let(:vm) { FactoryGirl.create(:vm_vmware, :name => 'My VM', :ext_management_system => ems) } + let(:admin) { FactoryBot.create(:user_with_group) } + let(:ems) { FactoryBot.create(:ems_vmware) } + let(:vm) { FactoryBot.create(:vm_vmware, :name => 'My VM', :ext_management_system => ems) } - let(:redhat_ems) { FactoryGirl.create(:ems_redhat) } - let(:redhat_vm) { FactoryGirl.create(:vm_redhat, :name => 'My RHV VM', :ext_management_system => redhat_ems) } + let(:redhat_ems) { FactoryBot.create(:ems_redhat) } + let(:redhat_vm) { FactoryBot.create(:vm_redhat, :name => 'My RHV VM', :ext_management_system => redhat_ems) } context "With a Valid Template," do context "#allowed_hosts" do @@ -19,7 +19,7 @@ it "with a host" do stub_dialog - host = FactoryGirl.create(:host_vmware, :ext_management_system => ems) + host = FactoryBot.create(:host_vmware, :ext_management_system => ems) host.set_parent(ems) allow(workflow).to receive(:process_filter).and_return([host]) @@ -57,7 +57,7 @@ end describe "#make_request" do - let(:alt_user) { FactoryGirl.create(:user_with_group) } + let(:alt_user) { FactoryBot.create(:user_with_group) } it "creates and update a request" do EvmSpecHelper.local_miq_server diff --git a/spec/models/vm_or_template/operations/configuration_spec.rb b/spec/models/vm_or_template/operations/configuration_spec.rb index ea30ebc4069..eebd7f41965 100644 --- a/spec/models/vm_or_template/operations/configuration_spec.rb +++ b/spec/models/vm_or_template/operations/configuration_spec.rb @@ -4,7 +4,7 @@ let(:disk_size) { "123" } context "when ext_management_system does not exist" do - let(:vm) { FactoryGirl.create(:vm_or_template) } + let(:vm) { FactoryBot.create(:vm_or_template) } it "raises an exception when does not find ext_management_system" do message = "VM has no EMS, unable to add disk" @@ -13,10 +13,10 @@ end context "when ext_management_system exists" do - let(:vm) { FactoryGirl.create(:vm_or_template, :ext_management_system => ems) } - let(:ems) { FactoryGirl.create(:ext_management_system) } + let(:vm) { FactoryBot.create(:vm_or_template, :ext_management_system => ems) } + let(:ems) { FactoryBot.create(:ext_management_system) } let(:storage_name) { "test_storage" } - let(:storage) { FactoryGirl.create(:storage, :name => storage_name) } + let(:storage) { FactoryBot.create(:storage, :name => storage_name) } let(:storages) { double("storages") } let(:host) { double("host", :writable_storages => storages) } let(:hosts) { [host] } @@ -61,7 +61,7 @@ let(:disk_name) { "[datastore1] vm1/vm1.vmdk" } context "from an archived vm" do - let(:vm) { FactoryGirl.create(:vm_or_template) } + let(:vm) { FactoryBot.create(:vm_or_template) } it "raises an exception" do expect { vm.raw_remove_disk(disk_name) }.to raise_error("VM has no EMS, unable to remove disk") @@ -69,8 +69,8 @@ end context "from an active vm" do - let(:ems) { FactoryGirl.create(:ext_management_system) } - let(:vm) { FactoryGirl.create(:vm_or_template, :ext_management_system => ems) } + let(:ems) { FactoryBot.create(:ext_management_system) } + let(:vm) { FactoryBot.create(:vm_or_template, :ext_management_system => ems) } it "defaults to delete the backing file" do expected_options = { diff --git a/spec/models/vm_or_template_spec.rb b/spec/models/vm_or_template_spec.rb index 976ae9eba45..87aa3a7102c 100644 --- a/spec/models/vm_or_template_spec.rb +++ b/spec/models/vm_or_template_spec.rb @@ -1,15 +1,15 @@ describe VmOrTemplate do include Spec::Support::ArelHelper - let(:vm) { FactoryGirl.create(:vm_or_template) } - let(:ems) { FactoryGirl.create(:ext_management_system) } - let(:storage) { FactoryGirl.create(:storage) } + let(:vm) { FactoryBot.create(:vm_or_template) } + let(:ems) { FactoryBot.create(:ext_management_system) } + let(:storage) { FactoryBot.create(:storage) } # Basically these specs are a truth table for the #registered? method, but # need it to verify functionality when converting these to scopes describe "being registered" do - subject { FactoryGirl.create(:vm_or_template, attrs) } - let(:host) { FactoryGirl.create(:host) } + subject { FactoryBot.create(:vm_or_template, attrs) } + let(:host) { FactoryBot.create(:host) } let(:registered_vms) { described_class.registered.to_a } let(:unregistered_vms) { described_class.unregistered.to_a } @@ -83,18 +83,18 @@ end describe ".miq_expression_includes_any_ipaddresses_arel" do - subject { FactoryGirl.create(:vm) } - let(:no_hardware_vm) { FactoryGirl.create(:vm) } - let(:wrong_ip_vm) { FactoryGirl.create(:vm) } + subject { FactoryBot.create(:vm) } + let(:no_hardware_vm) { FactoryBot.create(:vm) } + let(:wrong_ip_vm) { FactoryBot.create(:vm) } before do - hw1 = FactoryGirl.create(:hardware, :vm => subject) - FactoryGirl.create(:network, :hardware => hw1, :ipaddress => "10.11.11.11") - FactoryGirl.create(:network, :hardware => hw1, :ipaddress => "10.10.10.10") - FactoryGirl.create(:network, :hardware => hw1, :ipaddress => "10.10.10.11") + hw1 = FactoryBot.create(:hardware, :vm => subject) + FactoryBot.create(:network, :hardware => hw1, :ipaddress => "10.11.11.11") + FactoryBot.create(:network, :hardware => hw1, :ipaddress => "10.10.10.10") + FactoryBot.create(:network, :hardware => hw1, :ipaddress => "10.10.10.11") - hw2 = FactoryGirl.create(:hardware, :vm => wrong_ip_vm) - FactoryGirl.create(:network, :hardware => hw2, :ipaddress => "11.11.11.11") + hw2 = FactoryBot.create(:hardware, :vm => wrong_ip_vm) + FactoryBot.create(:network, :hardware => hw2, :ipaddress => "11.11.11.11") end it "runs a single query, returning only the valid vm" do @@ -111,8 +111,8 @@ before do Timecop.freeze(Time.now) - @host = FactoryGirl.create(:host, :name => "host") - @vm = FactoryGirl.create(:vm_vmware, :host => @host, :name => "vm", :uid_ems => "1", :ems_id => 101) + @host = FactoryBot.create(:host, :name => "host") + @vm = FactoryBot.create(:vm_vmware, :host => @host, :name => "vm", :uid_ems => "1", :ems_id => 101) @event_type = "foo" @event_timestamp = Time.now.utc @@ -124,8 +124,8 @@ it "by IP Address" do ipaddress = "192.268.20.1" - hardware = FactoryGirl.create(:hardware, :vm_or_template_id => @vm.id, :host => @host) - FactoryGirl.create(:network, :hardware_id => hardware.id, :ipaddress => ipaddress) + hardware = FactoryBot.create(:hardware, :vm_or_template_id => @vm.id, :host => @host) + FactoryBot.create(:network, :hardware_id => hardware.id, :ipaddress => ipaddress) event_msg = "Add EMS Event by IP address" expect_any_instance_of(VmOrTemplate).to receive(:add_ems_event).with(@event_type, event_msg, @event_timestamp) @@ -148,8 +148,8 @@ context "#add_ems_event" do before do - @host = FactoryGirl.create(:host, :name => "host 1") - @vm = FactoryGirl.create(:vm_vmware, :name => "vm 1", :location => "/local/path", :host => @host, :uid_ems => "1", :ems_id => 101) + @host = FactoryBot.create(:host, :name => "host 1") + @vm = FactoryBot.create(:vm_vmware, :name => "vm 1", :location => "/local/path", :host => @host, :uid_ems => "1", :ems_id => 101) @event_type = "foo" @source = "EVM" @event_timestamp = Time.now.utc.iso8601 @@ -164,8 +164,8 @@ context "should add an EMS Event" do before do @ipaddress = "192.268.20.1" - @hardware = FactoryGirl.create(:hardware, :vm_or_template_id => @vm.id) - @network = FactoryGirl.create(:network, :hardware_id => @hardware.id, :ipaddress => @ipaddress) + @hardware = FactoryBot.create(:hardware, :vm_or_template_id => @vm.id) + @network = FactoryBot.create(:network, :hardware_id => @hardware.id, :ipaddress => @ipaddress) end it "with host and ems id" do @@ -183,10 +183,10 @@ end it "with no host" do - vm_no_host = FactoryGirl.create(:vm_vmware, :name => "vm 2", :location => "/local/path", :uid_ems => "2", :ems_id => 102) + vm_no_host = FactoryBot.create(:vm_vmware, :name => "vm 2", :location => "/local/path", :uid_ems => "2", :ems_id => 102) ipaddress = "192.268.20.2" - hardware_no_host = FactoryGirl.create(:hardware, :vm_or_template_id => vm_no_host.id) - FactoryGirl.create(:network, :hardware_id => hardware_no_host.id, :ipaddress => ipaddress) + hardware_no_host = FactoryBot.create(:hardware, :vm_or_template_id => vm_no_host.id) + FactoryBot.create(:network, :hardware_id => hardware_no_host.id, :ipaddress => ipaddress) event_msg = "Add EMS Event by IP address with no host" @event_hash[:message] = event_msg @@ -200,10 +200,10 @@ end it "with no ems id" do - vm_no_ems = FactoryGirl.create(:vm_vmware, :name => "vm 3", :location => "/local/path", :host => @host) + vm_no_ems = FactoryBot.create(:vm_vmware, :name => "vm 3", :location => "/local/path", :host => @host) ipaddress = "192.268.20.3" - hardware_no_ems = FactoryGirl.create(:hardware, :vm_or_template_id => vm_no_ems.id) - FactoryGirl.create(:network, :hardware_id => hardware_no_ems.id, :ipaddress => ipaddress) + hardware_no_ems = FactoryBot.create(:hardware, :vm_or_template_id => vm_no_ems.id) + FactoryBot.create(:network, :hardware_id => hardware_no_ems.id, :ipaddress => ipaddress) event_msg = "Add EMS Event by IP address with no ems id" @event_hash[:message] = event_msg @@ -218,10 +218,10 @@ end it "with no host and no ems id" do - vm_no_host_no_ems = FactoryGirl.create(:vm_vmware, :name => "vm 4", :location => "/local/path") + vm_no_host_no_ems = FactoryBot.create(:vm_vmware, :name => "vm 4", :location => "/local/path") ipaddress = "192.268.20.4" - hardware_no_host_no_ems = FactoryGirl.create(:hardware, :vm_or_template_id => vm_no_host_no_ems.id) - FactoryGirl.create(:network, :hardware_id => hardware_no_host_no_ems.id, :ipaddress => ipaddress) + hardware_no_host_no_ems = FactoryBot.create(:hardware, :vm_or_template_id => vm_no_host_no_ems.id) + FactoryBot.create(:network, :hardware_id => hardware_no_host_no_ems.id, :ipaddress => ipaddress) event_msg = "Add EMS Event by IP address with no host and no ems id" @event_hash[:message] = event_msg @@ -237,8 +237,8 @@ context "#reconfigured_hardware_value?" do before do - @vm = FactoryGirl.create(:vm_vmware) - FactoryGirl.create(:hardware, :vm_or_template_id => @vm.id, :memory_mb => 1024) + @vm = FactoryBot.create(:vm_vmware) + FactoryBot.create(:hardware, :vm_or_template_id => @vm.id, :memory_mb => 1024) @options = {:hdw_attr => :memory_mb} end @@ -302,29 +302,29 @@ context "#miq_server_proxies" do context "SmartProxy Affinity" do before do - @storage1 = FactoryGirl.create(:storage) - @storage2 = FactoryGirl.create(:storage) - @storage3 = FactoryGirl.create(:storage) - - @host1 = FactoryGirl.create(:host, :name => 'host1', :storages => [@storage1]) - @host2 = FactoryGirl.create(:host, :name => 'host2', :storages => [@storage2]) - @host3 = FactoryGirl.create(:host, :name => 'host3', :storages => [@storage1, @storage2]) - @vm = FactoryGirl.create(:vm_vmware, + @storage1 = FactoryBot.create(:storage) + @storage2 = FactoryBot.create(:storage) + @storage3 = FactoryBot.create(:storage) + + @host1 = FactoryBot.create(:host, :name => 'host1', :storages => [@storage1]) + @host2 = FactoryBot.create(:host, :name => 'host2', :storages => [@storage2]) + @host3 = FactoryBot.create(:host, :name => 'host3', :storages => [@storage1, @storage2]) + @vm = FactoryBot.create(:vm_vmware, :host => @host1, :name => 'vm', :vendor => 'vmware', :storage => @storage1, :storages => [@storage1, @storage2]) - @zone = FactoryGirl.create(:zone, :name => 'zone') + @zone = FactoryBot.create(:zone, :name => 'zone') allow_any_instance_of(MiqServer).to receive_messages(:is_vix_disk? => true) @svr1 = EvmSpecHelper.local_miq_server(:name => 'svr1') - @svr2 = FactoryGirl.create(:miq_server, :name => 'svr2', :zone => @svr1.zone) - @svr3 = FactoryGirl.create(:miq_server, :name => 'svr3', :zone => @svr1.zone) + @svr2 = FactoryBot.create(:miq_server, :name => 'svr2', :zone => @svr1.zone) + @svr3 = FactoryBot.create(:miq_server, :name => 'svr3', :zone => @svr1.zone) - @svr1_vm = FactoryGirl.create(:vm_vmware, :host => @host1, :name => 'svr1_vm', :miq_server => @svr1) - @svr2_vm = FactoryGirl.create(:vm_vmware, :host => @host2, :name => 'svr2_vm', :miq_server => @svr2) - @svr3_vm = FactoryGirl.create(:vm_vmware, :host => @host3, :name => 'svr3_vm', :miq_server => @svr3) + @svr1_vm = FactoryBot.create(:vm_vmware, :host => @host1, :name => 'svr1_vm', :miq_server => @svr1) + @svr2_vm = FactoryBot.create(:vm_vmware, :host => @host2, :name => 'svr2_vm', :miq_server => @svr2) + @svr3_vm = FactoryBot.create(:vm_vmware, :host => @host3, :name => 'svr3_vm', :miq_server => @svr3) end it "should select SmartProxies with matching VM host affinity" do @@ -367,13 +367,13 @@ context "RHEV" do before do - @storage1 = FactoryGirl.create(:storage) - @storage2 = FactoryGirl.create(:storage) + @storage1 = FactoryBot.create(:storage) + @storage2 = FactoryBot.create(:storage) - @host1 = FactoryGirl.create(:host, :name => 'host1', :storages => [@storage1]) - @host2 = FactoryGirl.create(:host, :name => 'host2', :storages => [@storage2]) + @host1 = FactoryBot.create(:host, :name => 'host1', :storages => [@storage1]) + @host2 = FactoryBot.create(:host, :name => 'host2', :storages => [@storage2]) - @vm = FactoryGirl.create(:vm_redhat, + @vm = FactoryBot.create(:vm_redhat, :host => @host1, :name => 'vm', :vendor => 'redhat', @@ -381,10 +381,10 @@ :storages => [@storage1]) @svr1 = EvmSpecHelper.local_miq_server(:name => 'svr1') - @svr2 = FactoryGirl.create(:miq_server, :name => 'svr2', :zone => @svr1.zone) + @svr2 = FactoryBot.create(:miq_server, :name => 'svr2', :zone => @svr1.zone) - @svr1_vm = FactoryGirl.create(:vm_redhat, :host => @host1, :name => 'svr1_vm', :miq_server => @svr1) - @svr1_vm = FactoryGirl.create(:vm_redhat, :host => @host2, :name => 'svr2_vm', :miq_server => @svr2) + @svr1_vm = FactoryBot.create(:vm_redhat, :host => @host1, :name => 'svr1_vm', :miq_server => @svr1) + @svr1_vm = FactoryBot.create(:vm_redhat, :host => @host2, :name => 'svr2_vm', :miq_server => @svr2) end it "should select SmartProxies with access to the same NFS storage" do @@ -404,9 +404,9 @@ context "#users" do before do - @vm = FactoryGirl.create(:vm_vmware) - @user = FactoryGirl.create(:account_user, :vm_or_template => @vm, :name => "test") - @group = FactoryGirl.create(:account_group, :vm_or_template => @vm, :name => "dev") + @vm = FactoryBot.create(:vm_vmware) + @user = FactoryBot.create(:account_user, :vm_or_template => @vm, :name => "test") + @group = FactoryBot.create(:account_group, :vm_or_template => @vm, :name => "dev") end it "association" do @@ -421,9 +421,9 @@ context "#groups" do before do - @vm = FactoryGirl.create(:vm_vmware) - @user = FactoryGirl.create(:account_user, :vm_or_template => @vm, :name => "test") - @group = FactoryGirl.create(:account_group, :vm_or_template => @vm, :name => "dev") + @vm = FactoryBot.create(:vm_vmware) + @user = FactoryBot.create(:account_user, :vm_or_template => @vm, :name => "test") + @group = FactoryBot.create(:account_group, :vm_or_template => @vm, :name => "dev") end it "association" do @@ -438,9 +438,9 @@ context "#resource_group" do before do - @resource_group = FactoryGirl.create(:resource_group) - @vm_with_rg = FactoryGirl.create(:vm_amazon, :resource_group => @resource_group) - @vm_without_rg = FactoryGirl.create(:vm_amazon) + @resource_group = FactoryBot.create(:resource_group) + @vm_with_rg = FactoryBot.create(:vm_amazon, :resource_group => @resource_group) + @vm_without_rg = FactoryBot.create(:vm_amazon) end it "has a has_one association with resource groups" do @@ -451,7 +451,7 @@ context "#scan_profile_categories" do before do - @vm = FactoryGirl.create(:vm_vmware) + @vm = FactoryBot.create(:vm_vmware) end it "should produce profile categories without a default or customer profile" do @@ -461,7 +461,7 @@ it "should produce profile categories from the default profile" do item_set = ScanItemSet.new - allow(item_set).to receive(:members) { [FactoryGirl.build(:scan_item_category_default), FactoryGirl.build(:scan_item_file)] } + allow(item_set).to receive(:members) { [FactoryBot.build(:scan_item_category_default), FactoryBot.build(:scan_item_file)] } allow(ScanItemSet).to receive(:find_by).with(:name => "default") { item_set } categories = @vm.scan_profile_categories(@vm.scan_profile_list) @@ -470,7 +470,7 @@ it "should produce profile categories from the customer profile" do item_set = ScanItemSet.new - allow(item_set).to receive(:members) { [FactoryGirl.build(:scan_item_category_test), FactoryGirl.build(:scan_item_file)] } + allow(item_set).to receive(:members) { [FactoryBot.build(:scan_item_category_test), FactoryBot.build(:scan_item_file)] } allow(ScanItemSet).to receive(:find_by).with(:name => "test") { item_set } categories = @vm.scan_profile_categories(ScanItem.get_profile("test")) @@ -480,7 +480,7 @@ context ".refresh_ems queues refresh for proper class" do [:template_vmware, :vm_vmware].each do |vm_or_template| - let(:instance) { FactoryGirl.create(vm_or_template) } + let(:instance) { FactoryBot.create(vm_or_template) } it vm_or_template.to_s.classify do expect(EmsRefresh).to receive(:queue_refresh).with([[VmOrTemplate, instance.id]]) @@ -491,9 +491,9 @@ end context "#tenant" do - let(:tenant) { FactoryGirl.create(:tenant) } + let(:tenant) { FactoryBot.create(:tenant) } it "has a tenant" do - vm = FactoryGirl.create(:vm_vmware, :tenant => tenant, :miq_group => nil) + vm = FactoryBot.create(:vm_vmware, :tenant => tenant, :miq_group => nil) expect(vm.reload.tenant).to eq(tenant) expect(tenant.vm_or_templates).to include(vm) end @@ -501,88 +501,88 @@ context "#supports_migrate?" do it "returns true for vmware VM neither orphaned nor archived when queried if it supports migrate operation" do - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) allow(vm).to receive_messages(:archived? => false) allow(vm).to receive_messages(:orphaned? => false) expect(vm.supports_migrate?).to eq(true) end it "returns false for SCVMM VM when queried if it supports migrate operation" do - vm = FactoryGirl.create(:vm_microsoft) + vm = FactoryBot.create(:vm_microsoft) expect(vm.supports_migrate?).to eq(false) end it "returns false for openstack VM when queried if it supports migrate operation" do - vm = FactoryGirl.create(:vm_openstack) + vm = FactoryBot.create(:vm_openstack) expect(vm.supports_migrate?).to eq(false) end end context "#supports_live_migrate?" do it "returns false for vmware VM" do - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) expect(vm.supports_live_migrate?).to eq(false) end it "returns false for SCVMM VM" do - vm = FactoryGirl.create(:vm_microsoft) + vm = FactoryBot.create(:vm_microsoft) expect(vm.supports_live_migrate?).to eq(false) end end context "#supports_evacuate?" do it "returns false for querying vmware VM if it supports evacuate operation" do - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) expect(vm.supports_evacuate?).to eq(false) end it "returns false for querying SCVMM VM if it supports evacuate operation" do - vm = FactoryGirl.create(:vm_microsoft) + vm = FactoryBot.create(:vm_microsoft) expect(vm.supports_evacuate?).to eq(false) end end context "#supports_smartstate_analysis?" do it "returns true for VMware VM" do - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) allow(vm).to receive_messages(:archived? => false) allow(vm).to receive_messages(:orphaned? => false) expect(vm.supports_smartstate_analysis?).to eq(true) end it "returns false for Amazon VM" do - vm = FactoryGirl.create(:vm_amazon) + vm = FactoryBot.create(:vm_amazon) expect(vm.supports_smartstate_analysis?).to_not eq(true) end end context "#supports_terminate?" do - let(:ems_does_vm_destroy) { FactoryGirl.create(:ems_vmware) } - let(:ems_doesnot_vm_destroy) { FactoryGirl.create(:ems_cloud) } - let(:host) { FactoryGirl.create(:host) } + let(:ems_does_vm_destroy) { FactoryBot.create(:ems_vmware) } + let(:ems_doesnot_vm_destroy) { FactoryBot.create(:ems_cloud) } + let(:host) { FactoryBot.create(:host) } it "returns true for a VM not terminated" do - vm = FactoryGirl.create(:vm, :host => host, :ext_management_system => ems_does_vm_destroy) + vm = FactoryBot.create(:vm, :host => host, :ext_management_system => ems_does_vm_destroy) allow(vm).to receive_messages(:terminated? => false) expect(vm.supports_terminate?).to eq(true) end it "returns false for a terminated VM" do - vm = FactoryGirl.create(:vm, :host => host, :ext_management_system => ems_does_vm_destroy) + vm = FactoryBot.create(:vm, :host => host, :ext_management_system => ems_does_vm_destroy) allow(vm).to receive_messages(:terminated? => true) expect(vm.supports_terminate?).to eq(false) expect(vm.unsupported_reason(:terminate)).to eq("The VM is terminated") end it "returns false for a provider doesn't support vm_destroy" do - vm = FactoryGirl.create(:vm, :host => host, :ext_management_system => ems_doesnot_vm_destroy) + vm = FactoryBot.create(:vm, :host => host, :ext_management_system => ems_doesnot_vm_destroy) allow(vm).to receive_messages(:terminated? => false) expect(vm.supports_terminate?).to eq(false) expect(vm.unsupported_reason(:terminate)).to eq("Provider doesn't support vm_destroy") end it "returns false for a WMware VM" do - vm = FactoryGirl.create(:vm, :host => host, :ext_management_system => ems_does_vm_destroy) + vm = FactoryBot.create(:vm, :host => host, :ext_management_system => ems_does_vm_destroy) allow(vm).to receive_messages(:terminated? => false) expect(vm.supports_terminate?).to eq(true) end @@ -590,47 +590,47 @@ context ".set_tenant_from_group" do before { Tenant.seed } - let(:tenant1) { FactoryGirl.create(:tenant) } - let(:tenant2) { FactoryGirl.create(:tenant) } - let(:group1) { FactoryGirl.create(:miq_group, :tenant => tenant1) } - let(:group2) { FactoryGirl.create(:miq_group, :tenant => tenant2) } + let(:tenant1) { FactoryBot.create(:tenant) } + let(:tenant2) { FactoryBot.create(:tenant) } + let(:group1) { FactoryBot.create(:miq_group, :tenant => tenant1) } + let(:group2) { FactoryBot.create(:miq_group, :tenant => tenant2) } it "assigns the tenant from the group" do - expect(FactoryGirl.create(:vm_vmware, :miq_group => group1).tenant).to eq(tenant1) + expect(FactoryBot.create(:vm_vmware, :miq_group => group1).tenant).to eq(tenant1) end it "assigns the tenant from the group_id" do - expect(FactoryGirl.create(:vm_vmware, :miq_group_id => group1.id).tenant).to eq(tenant1) + expect(FactoryBot.create(:vm_vmware, :miq_group_id => group1.id).tenant).to eq(tenant1) end it "assigns the tenant from the group over the tenant" do - expect(FactoryGirl.create(:vm_vmware, :miq_group => group1, :tenant => tenant2).tenant).to eq(tenant1) + expect(FactoryBot.create(:vm_vmware, :miq_group => group1, :tenant => tenant2).tenant).to eq(tenant1) end it "uses default tenant via tenancy_mixin" do - expect(FactoryGirl.create(:vm_vmware).tenant).to eq(Tenant.root_tenant) + expect(FactoryBot.create(:vm_vmware).tenant).to eq(Tenant.root_tenant) end it "changes the tenant after changing the group" do - vm = FactoryGirl.create(:vm_vmware, :miq_group => group1) + vm = FactoryBot.create(:vm_vmware, :miq_group => group1) vm.update_attributes(:miq_group_id => group2.id) expect(vm.tenant).to eq(tenant2) end end it "with ems_events" do - ems = FactoryGirl.create(:ems_vmware_with_authentication) - vm = FactoryGirl.create(:vm_vmware, :ext_management_system => ems) - ems_event = FactoryGirl.create(:ems_event) + ems = FactoryBot.create(:ems_vmware_with_authentication) + vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems) + ems_event = FactoryBot.create(:ems_event) vm.ems_events << ems_event expect(vm.ems_events.first).to be_kind_of(EmsEvent) expect(vm.ems_events.first.id).to eq(ems_event.id) end it "#miq_provision_vms" do - ems = FactoryGirl.create(:ems_vmware_with_authentication) - template = FactoryGirl.create(:template_vmware, :ext_management_system => ems) - vm = FactoryGirl.create(:vm_vmware, :ext_management_system => ems) + ems = FactoryBot.create(:ems_vmware_with_authentication) + template = FactoryBot.create(:template_vmware, :ext_management_system => ems) + vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems) options = { :vm_name => vm.name, @@ -638,7 +638,7 @@ :src_vm_id => [template.id, template.name] } - provision = FactoryGirl.create( + provision = FactoryBot.create( :miq_provision_vmware, :destination => vm, :source => template, @@ -655,9 +655,9 @@ describe "#miq_provision_template" do it "links vm to template" do - ems = FactoryGirl.create(:ems_vmware_with_authentication) - template = FactoryGirl.create(:template_vmware, :ext_management_system => ems) - vm = FactoryGirl.create(:vm_vmware, :ext_management_system => ems) + ems = FactoryBot.create(:ems_vmware_with_authentication) + template = FactoryBot.create(:template_vmware, :ext_management_system => ems) + vm = FactoryBot.create(:vm_vmware, :ext_management_system => ems) options = { :vm_name => vm.name, @@ -665,7 +665,7 @@ :src_vm_id => [template.id, template.name] } - FactoryGirl.create( + FactoryBot.create( :miq_provision_vmware, :destination => vm, :source => template, @@ -680,8 +680,8 @@ end describe ".v_pct_free_disk_space (delegated to hardware)" do - let(:vm) { FactoryGirl.create(:vm_vmware, :hardware => hardware) } - let(:hardware) { FactoryGirl.create(:hardware, :disk_free_space => 20, :disk_capacity => 100) } + let(:vm) { FactoryBot.create(:vm_vmware, :hardware => hardware) } + let(:hardware) { FactoryBot.create(:hardware, :disk_free_space => 20, :disk_capacity => 100) } it "calculates in ruby" do expect(vm.v_pct_free_disk_space).to eq(20.0) @@ -695,7 +695,7 @@ end context "with null disk capacity" do - let(:hardware) { FactoryGirl.build(:hardware, :disk_free_space => 20, :disk_capacity => nil) } + let(:hardware) { FactoryBot.build(:hardware, :disk_free_space => 20, :disk_capacity => nil) } it "calculates in ruby" do expect(vm.v_pct_free_disk_space).to be_nil @@ -712,31 +712,31 @@ describe "#used_storage" do it "calculates in ruby with null hardware" do - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) expect(vm.used_storage).to eq(0.0) end it "calculates in ruby" do - hardware = FactoryGirl.create(:hardware, :memory_mb => 10) - vm = FactoryGirl.create(:vm_vmware, :hardware => hardware) - disk = FactoryGirl.create(:disk, :size_on_disk => 1024, :size => 10_240, :hardware => hardware) + hardware = FactoryBot.create(:hardware, :memory_mb => 10) + vm = FactoryBot.create(:vm_vmware, :hardware => hardware) + disk = FactoryBot.create(:disk, :size_on_disk => 1024, :size => 10_240, :hardware => hardware) expect(vm.used_storage).to eq(10 * 1024 * 1024 + 1024) # memory_mb + size on disk end end # allocated_disk_storage.to_i + ram_size_in_bytes describe "#provisioned_storage" do - let(:vm) { FactoryGirl.create(:vm_vmware, :hardware => hardware) } - let(:hardware) { FactoryGirl.create(:hardware, :memory_mb => 10) } - let(:disk) { FactoryGirl.create(:disk, :size_on_disk => 1024, :size => 10_240, :hardware => hardware) } + let(:vm) { FactoryBot.create(:vm_vmware, :hardware => hardware) } + let(:hardware) { FactoryBot.create(:hardware, :memory_mb => 10) } + let(:disk) { FactoryBot.create(:disk, :size_on_disk => 1024, :size => 10_240, :hardware => hardware) } it "calculates in ruby with null hardware" do - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) expect(vm.provisioned_storage).to eq(0.0) end it "uses calculated (inline) attribute with null hardware" do - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) vm2 = VmOrTemplate.select(:id, :provisioned_storage).first expect { expect(vm2.provisioned_storage).to eq(0) }.to match_query_limit_of(0) end @@ -755,11 +755,11 @@ end describe ".ram_size", ".mem_cpu" do - let(:vm) { FactoryGirl.create(:vm_vmware, :hardware => hardware) } - let(:hardware) { FactoryGirl.create(:hardware, :memory_mb => 10) } + let(:vm) { FactoryBot.create(:vm_vmware, :hardware => hardware) } + let(:hardware) { FactoryBot.create(:hardware, :memory_mb => 10) } it "supports null hardware" do - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) expect(vm.ram_size).to eq(0) expect(vm.mem_cpu).to eq(0) end @@ -777,11 +777,11 @@ end describe ".ram_size_in_bytes" do - let(:vm) { FactoryGirl.create(:vm_vmware, :hardware => hardware) } - let(:hardware) { FactoryGirl.create(:hardware, :memory_mb => 10) } + let(:vm) { FactoryBot.create(:vm_vmware, :hardware => hardware) } + let(:hardware) { FactoryBot.create(:hardware, :memory_mb => 10) } it "supports null hardware" do - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) expect(vm.ram_size_in_bytes).to eq(0) end @@ -796,12 +796,12 @@ end describe ".cpu_usagemhz_rate_average_max_over_time_period (virtual_attribute)" do - let(:vm) { FactoryGirl.create :vm_vmware } + let(:vm) { FactoryBot.create :vm_vmware } before do EvmSpecHelper.local_miq_server tp_id = TimeProfile.seed.id - FactoryGirl.create :metric_rollup_vm_daily, + FactoryBot.create :metric_rollup_vm_daily, :with_data, :timestamp => 1.day.ago, :time_profile_id => tp_id, @@ -810,7 +810,7 @@ :abs_max_cpu_usagemhz_rate_average_value => 100.00 } - FactoryGirl.create :metric_rollup_vm_daily, + FactoryBot.create :metric_rollup_vm_daily, :with_data, :cpu_usagemhz_rate_average => 10.0, :timestamp => 1.day.ago, @@ -819,7 +819,7 @@ :min_max => { :abs_max_cpu_usagemhz_rate_average_value => 900.00 } - FactoryGirl.create :metric_rollup_vm_daily, + FactoryBot.create :metric_rollup_vm_daily, :with_data, :cpu_usagemhz_rate_average => 100.0, :timestamp => 1.day.ago, @@ -845,12 +845,12 @@ end describe ".derived_memory_used_max_over_time_period (virtual_attribute)" do - let(:vm) { FactoryGirl.create :vm_vmware } + let(:vm) { FactoryBot.create :vm_vmware } before do EvmSpecHelper.local_miq_server tp_id = TimeProfile.seed.id - FactoryGirl.create :metric_rollup_vm_daily, + FactoryBot.create :metric_rollup_vm_daily, :with_data, :time_profile_id => tp_id, :timestamp => 1.day.ago, @@ -858,7 +858,7 @@ :min_max => { :abs_max_derived_memory_used_value => 100.00 } - FactoryGirl.create :metric_rollup_vm_daily, + FactoryBot.create :metric_rollup_vm_daily, :with_data, :derived_memory_used => 10.0, :timestamp => 1.day.ago, @@ -867,7 +867,7 @@ :min_max => { :abs_max_derived_memory_used_value => 500.00 } - FactoryGirl.create :metric_rollup_vm_daily, + FactoryBot.create :metric_rollup_vm_daily, :with_data, :derived_memory_used => 1000.0, :timestamp => 1.day.ago, @@ -893,8 +893,8 @@ end describe ".host_name" do - let(:vm) { FactoryGirl.create(:vm_vmware, :host => host) } - let(:host) { FactoryGirl.create(:host_vmware, :name => "our host") } + let(:vm) { FactoryBot.create(:vm_vmware, :host => host) } + let(:host) { FactoryBot.create(:host_vmware, :name => "our host") } it "calculates in ruby" do expect(vm.host_name).to eq("our host") @@ -908,8 +908,8 @@ describe ".v_host_vmm_product" do it "delegates to host" do - host = FactoryGirl.build(:host, :vmm_product => "Hyper-V") - vm = FactoryGirl.build(:vm_vmware, :host => host) + host = FactoryBot.build(:host, :vmm_product => "Hyper-V") + vm = FactoryBot.build(:vm_vmware, :host => host) expect(vm.v_host_vmm_product).to eq("Hyper-V") end @@ -983,9 +983,9 @@ end describe "connected_to_ems?" do - let(:vm) { FactoryGirl.create(:vm_vmware, :connection_state => "connected") } - let(:vm2) { FactoryGirl.create(:vm_vmware, :connection_state => "disconnected") } - let(:vm3) { FactoryGirl.create(:vm_vmware, :connection_state => nil) } + let(:vm) { FactoryBot.create(:vm_vmware, :connection_state => "connected") } + let(:vm2) { FactoryBot.create(:vm_vmware, :connection_state => "disconnected") } + let(:vm3) { FactoryBot.create(:vm_vmware, :connection_state => nil) } it "detects nil" do expect(vm3).to be_connected_to_ems @@ -1001,9 +1001,9 @@ end describe ".disconnected?" do - let(:vm) { FactoryGirl.create(:vm_vmware, :connection_state => "connected") } - let(:vm2) { FactoryGirl.create(:vm_vmware, :connection_state => "disconnected") } - let(:vm3) { FactoryGirl.create(:vm_vmware, :connection_state => nil) } + let(:vm) { FactoryBot.create(:vm_vmware, :connection_state => "connected") } + let(:vm2) { FactoryBot.create(:vm_vmware, :connection_state => "disconnected") } + let(:vm3) { FactoryBot.create(:vm_vmware, :connection_state => nil) } it "detects nil" do expect(vm3).not_to be_disconnected @@ -1042,57 +1042,57 @@ end describe ".v_annotation" do - let(:vm) { FactoryGirl.create(:vm) } + let(:vm) { FactoryBot.create(:vm) } it "handles no hardware" do expect(vm.v_annotation).to be_nil end it "handles hardware" do - FactoryGirl.create(:hardware, :vm => vm, :annotation => "the annotation") + FactoryBot.create(:hardware, :vm => vm, :annotation => "the annotation") expect(vm.v_annotation).to eq("the annotation") end end describe ".cpu_total_cores" do - let(:vm) { FactoryGirl.create(:vm) } + let(:vm) { FactoryBot.create(:vm) } it "handles no hardware" do expect(vm.cpu_total_cores).to eq(0) end it "handles hardware" do - FactoryGirl.create(:hardware, :vm => vm, :cpu_total_cores => 8) + FactoryBot.create(:hardware, :vm => vm, :cpu_total_cores => 8) expect(vm.cpu_total_cores).to eq(8) end it "calculates in the database" do - FactoryGirl.create(:hardware, :vm => vm, :cpu_total_cores => 8) + FactoryBot.create(:hardware, :vm => vm, :cpu_total_cores => 8) expect(virtual_column_sql_value(VmOrTemplate, "cpu_total_cores")).to eq(8) end end describe ".cpu_cores_per_socket" do - let(:vm) { FactoryGirl.create(:vm) } + let(:vm) { FactoryBot.create(:vm) } it "handles no hardware" do expect(vm.cpu_cores_per_socket).to eq(0) end it "handles hardware" do - FactoryGirl.create(:hardware, :vm => vm, :cpu_cores_per_socket => 4) + FactoryBot.create(:hardware, :vm => vm, :cpu_cores_per_socket => 4) expect(vm.cpu_cores_per_socket).to eq(4) end it "calculates in the database" do - FactoryGirl.create(:hardware, :vm => vm, :cpu_cores_per_socket => 4) + FactoryBot.create(:hardware, :vm => vm, :cpu_cores_per_socket => 4) expect(virtual_column_sql_value(VmOrTemplate, "cpu_cores_per_socket")).to eq(4) end end describe "#disconnect_ems" do - let(:ems) { FactoryGirl.build(:ext_management_system) } + let(:ems) { FactoryBot.build(:ext_management_system) } let(:vm) do - FactoryGirl.build(:vm_or_template, + FactoryBot.build(:vm_or_template, :ext_management_system => ems, - :ems_cluster => FactoryGirl.build(:ems_cluster)) + :ems_cluster => FactoryBot.build(:ems_cluster)) end it "clears ems and cluster" do @@ -1102,18 +1102,18 @@ end it "doesnt clear the wrong ems" do - vm.disconnect_ems(FactoryGirl.build(:ext_management_system)) + vm.disconnect_ems(FactoryBot.build(:ext_management_system)) expect(vm.ext_management_system).not_to be_nil expect(vm.ems_cluster).not_to be_nil end end describe "#all_archived" do - let(:ems) { FactoryGirl.build(:ext_management_system) } + let(:ems) { FactoryBot.build(:ext_management_system) } it "works" do - FactoryGirl.create(:vm_or_template, :ext_management_system => ems) - arch = FactoryGirl.create(:vm_or_template) - FactoryGirl.create(:vm_or_template, :storage => FactoryGirl.create(:storage)) + FactoryBot.create(:vm_or_template, :ext_management_system => ems) + arch = FactoryBot.create(:vm_or_template) + FactoryBot.create(:vm_or_template, :storage => FactoryBot.create(:storage)) expect(VmOrTemplate.archived).to eq([arch]) end @@ -1121,9 +1121,9 @@ describe "#all_orphaned" do it "works" do - FactoryGirl.create(:vm_or_template, :ext_management_system => ems) - FactoryGirl.create(:vm_or_template) - orph = FactoryGirl.create(:vm_or_template, :storage => FactoryGirl.create(:storage)) + FactoryBot.create(:vm_or_template, :ext_management_system => ems) + FactoryBot.create(:vm_or_template) + orph = FactoryBot.create(:vm_or_template, :storage => FactoryBot.create(:storage)) expect(VmOrTemplate.orphaned).to eq([orph]) end @@ -1131,9 +1131,9 @@ describe "#all_archived_or_orphaned" do it "works" do - vm = FactoryGirl.create(:vm_or_template, :ext_management_system => ems) - FactoryGirl.create(:vm_or_template) - FactoryGirl.create(:vm_or_template, :storage => FactoryGirl.create(:storage)) + vm = FactoryBot.create(:vm_or_template, :ext_management_system => ems) + FactoryBot.create(:vm_or_template) + FactoryBot.create(:vm_or_template, :storage => FactoryBot.create(:storage)) expect(VmOrTemplate.with_ems).to eq([vm]) end @@ -1148,17 +1148,17 @@ let!(:ems) do _, _, zone = EvmSpecHelper.local_guid_miq_server_zone - FactoryGirl.create(:ems_vmware, :zone => zone).tap do |ems| + FactoryBot.create(:ems_vmware, :zone => zone).tap do |ems| build_vmware_folder_structure!(ems) - folder_blue1.add_child(FactoryGirl.create(:vm_vmware, :name => "vm_blue1", :ems_id => ems.id)) - folder_blue2.add_child(FactoryGirl.create(:vm_vmware, :name => "vm_blue2", :ems_id => ems.id)) + folder_blue1.add_child(FactoryBot.create(:vm_vmware, :name => "vm_blue1", :ems_id => ems.id)) + folder_blue2.add_child(FactoryBot.create(:vm_vmware, :name => "vm_blue2", :ems_id => ems.id)) end end let!(:start_time) { Time.now.utc } it "when a folder is created under a folder" do - new_folder = FactoryGirl.create(:vmware_folder_vm, :ems_id => ems.id) + new_folder = FactoryBot.create(:vmware_folder_vm, :ems_id => ems.id) new_folder.parent = folder_blue1 described_class.post_refresh_ems(ems.id, start_time) @@ -1193,7 +1193,7 @@ end it "when a VM is created under a folder" do - new_vm = FactoryGirl.create(:vm_vmware, :ems_id => ems.id) + new_vm = FactoryBot.create(:vm_vmware, :ems_id => ems.id) new_vm.with_relationship_type("ems_metadata") { |v| v.parent = folder_blue1 } described_class.post_refresh_ems(ems.id, start_time) @@ -1220,7 +1220,7 @@ end it "when a folder is created and a folder is moved under it simultaneously" do - new_folder = FactoryGirl.create(:vmware_folder_vm, :ems_id => ems.id) + new_folder = FactoryBot.create(:vmware_folder_vm, :ems_id => ems.id) new_folder.parent = folder_vm_root folder_blue1.parent = new_folder @@ -1255,7 +1255,7 @@ end it "when a folder is created and a VM is moved under it simultaneously" do - new_folder = FactoryGirl.create(:vmware_folder_vm, :ems_id => ems.id) + new_folder = FactoryBot.create(:vmware_folder_vm, :ems_id => ems.id) new_folder.parent = folder_vm_root vm_blue1.with_relationship_type("ems_metadata") { |v| v.parent = new_folder } @@ -1307,7 +1307,7 @@ context "#policy_events" do it "returns the policy events with target class of VmOrTemplate and target_id of the vm" do - policy_event = FactoryGirl.create(:policy_event, :target_class => "VmOrTemplate", :target_id => vm.id) + policy_event = FactoryBot.create(:policy_event, :target_class => "VmOrTemplate", :target_id => vm.id) expect(vm.policy_events).to eq([policy_event]) end @@ -1315,13 +1315,13 @@ describe '#normalized_state' do let(:klass) { :vm_vmware } - let(:storage) { FactoryGirl.create(:storage_vmware) } - let(:ems) { FactoryGirl.create(:ems_vmware) } + let(:storage) { FactoryBot.create(:storage_vmware) } + let(:ems) { FactoryBot.create(:ems_vmware) } let(:connection_state) { 'disconnected' } let(:retired) { false } let!(:vm) do - FactoryGirl.create(klass, :storage => storage, + FactoryBot.create(klass, :storage => storage, :ems_id => ems.try(:id), :connection_state => connection_state, :retired => retired) diff --git a/spec/models/vm_reconfigure_request_spec.rb b/spec/models/vm_reconfigure_request_spec.rb index 733aea5377a..ce8e7059783 100644 --- a/spec/models/vm_reconfigure_request_spec.rb +++ b/spec/models/vm_reconfigure_request_spec.rb @@ -1,13 +1,13 @@ describe VmReconfigureRequest do - let(:admin) { FactoryGirl.create(:user, :userid => "tester") } - let(:ems_vmware) { FactoryGirl.create(:ems_vmware, :zone => zone2) } - let(:host_hardware) { FactoryGirl.build(:hardware, :cpu_total_cores => 40, :cpu_sockets => 10, :cpu_cores_per_socket => 4) } - let(:host) { FactoryGirl.build(:host, :hardware => host_hardware) } - let(:request) { FactoryGirl.create(:vm_reconfigure_request, :requester => admin) } - let(:vm_hardware) { FactoryGirl.build(:hardware, :virtual_hw_version => "07") } - let(:vm_redhat) { FactoryGirl.create(:vm_redhat) } - let(:vm_vmware) { FactoryGirl.create(:vm_vmware, :hardware => vm_hardware, :host => host) } - let(:zone2) { FactoryGirl.create(:zone, :name => "zone_2") } + let(:admin) { FactoryBot.create(:user, :userid => "tester") } + let(:ems_vmware) { FactoryBot.create(:ems_vmware, :zone => zone2) } + let(:host_hardware) { FactoryBot.build(:hardware, :cpu_total_cores => 40, :cpu_sockets => 10, :cpu_cores_per_socket => 4) } + let(:host) { FactoryBot.build(:host, :hardware => host_hardware) } + let(:request) { FactoryBot.create(:vm_reconfigure_request, :requester => admin) } + let(:vm_hardware) { FactoryBot.build(:hardware, :virtual_hw_version => "07") } + let(:vm_redhat) { FactoryBot.create(:vm_redhat) } + let(:vm_vmware) { FactoryBot.create(:vm_vmware, :hardware => vm_hardware, :host => host) } + let(:zone2) { FactoryBot.create(:zone, :name => "zone_2") } before { _guid, _server, @zone1 = EvmSpecHelper.create_guid_miq_server_zone } @@ -28,7 +28,7 @@ end describe "#make_request" do - let(:alt_user) { FactoryGirl.create(:user_with_group) } + let(:alt_user) { FactoryBot.create(:user_with_group) } it "creates and update a request" do EvmSpecHelper.local_miq_server @@ -95,7 +95,7 @@ end it "multiple vms" do - @options = {:src_ids => [vm_redhat.id, FactoryGirl.create(:vm_redhat).id]} + @options = {:src_ids => [vm_redhat.id, FactoryBot.create(:vm_redhat).id]} assert_rhev_cpu_and_memory_min_max end @@ -109,8 +109,8 @@ end it "multiple vms" do - hardware = FactoryGirl.build(:hardware, :virtual_hw_version => "07") - @options = {:src_ids => [vm_vmware.id, FactoryGirl.create(:vm_vmware, :host => host, :hardware => hardware).id]} + hardware = FactoryBot.build(:hardware, :virtual_hw_version => "07") + @options = {:src_ids => [vm_vmware.id, FactoryBot.create(:vm_vmware, :host => host, :hardware => hardware).id]} assert_vmware_cpu_and_memory_min_max end diff --git a/spec/models/vm_retire_task_spec.rb b/spec/models/vm_retire_task_spec.rb index a31bcef99fd..a60e3c95c28 100644 --- a/spec/models/vm_retire_task_spec.rb +++ b/spec/models/vm_retire_task_spec.rb @@ -1,9 +1,9 @@ describe VmRetireTask do - let(:user) { FactoryGirl.create(:user_with_group) } - let(:vm) { FactoryGirl.create(:vm) } - let(:miq_request) { FactoryGirl.create(:vm_retire_request, :requester => user) } - let(:vm_retire_task) { FactoryGirl.create(:vm_retire_task, :source => vm, :miq_request => miq_request, :options => {:src_ids => [vm.id] }) } - let(:approver) { FactoryGirl.create(:user_miq_request_approver) } + let(:user) { FactoryBot.create(:user_with_group) } + let(:vm) { FactoryBot.create(:vm) } + let(:miq_request) { FactoryBot.create(:vm_retire_request, :requester => user) } + let(:vm_retire_task) { FactoryBot.create(:vm_retire_task, :source => vm, :miq_request => miq_request, :options => {:src_ids => [vm.id] }) } + let(:approver) { FactoryBot.create(:user_miq_request_approver) } it "should initialize properly" do expect(vm_retire_task).to have_attributes(:state => 'pending', :status => 'Ok') diff --git a/spec/models/vm_scan_spec.rb b/spec/models/vm_scan_spec.rb index 597ec41dfb5..bac3bbc2d36 100644 --- a/spec/models/vm_scan_spec.rb +++ b/spec/models/vm_scan_spec.rb @@ -7,13 +7,13 @@ # TODO: stub only settings needed for test instead of all from settings.yml stub_settings(::Settings.to_hash.merge(:coresident_miqproxy => {:scan_via_host => false})) - @user = FactoryGirl.create(:user_with_group, :userid => "tester") - @ems = FactoryGirl.create(:ems_vmware_with_authentication, :name => "Test EMS", :zone => @server.zone, - :tenant => FactoryGirl.create(:tenant)) - @storage = FactoryGirl.create(:storage, :name => "test_storage", :store_type => "VMFS") - @host = FactoryGirl.create(:host, :name => "test_host", :hostname => "test_host", + @user = FactoryBot.create(:user_with_group, :userid => "tester") + @ems = FactoryBot.create(:ems_vmware_with_authentication, :name => "Test EMS", :zone => @server.zone, + :tenant => FactoryBot.create(:tenant)) + @storage = FactoryBot.create(:storage, :name => "test_storage", :store_type => "VMFS") + @host = FactoryBot.create(:host, :name => "test_host", :hostname => "test_host", :state => 'on', :ext_management_system => @ems) - @vm = FactoryGirl.create(:vm_vmware, :name => "test_vm", :location => "abc/abc.vmx", + @vm = FactoryBot.create(:vm_vmware, :name => "test_vm", :location => "abc/abc.vmx", :raw_power_state => 'poweredOn', :host => @host, :ext_management_system => @ems, @@ -58,7 +58,7 @@ context "without Broker Running and with valid MiqVimBrokerWorker record," do before do - @vim_broker_worker = FactoryGirl.create(:miq_vim_broker_worker, :miq_server_id => @server.id) + @vim_broker_worker = FactoryBot.create(:miq_vim_broker_worker, :miq_server_id => @server.id) end context "in status of 'starting'," do @@ -202,7 +202,7 @@ end it "should raise vm_scan_start for template" do - template = FactoryGirl.create( + template = FactoryBot.create( :template_vmware, :name => "test_vm", :location => "abc/abc.vmx", @@ -414,13 +414,13 @@ before do # local zone @server1 = EvmSpecHelper.local_miq_server(:capabilities => {:vixDisk => true}) - @user = FactoryGirl.create(:user_with_group, :userid => "tester") - @ems = FactoryGirl.create(:ems_vmware_with_authentication, :name => "Test EMS", :zone => @server1.zone, - :tenant => FactoryGirl.create(:tenant)) - @storage = FactoryGirl.create(:storage, :name => "test_storage", :store_type => "VMFS") - @host = FactoryGirl.create(:host, :name => "test_host", :hostname => "test_host", + @user = FactoryBot.create(:user_with_group, :userid => "tester") + @ems = FactoryBot.create(:ems_vmware_with_authentication, :name => "Test EMS", :zone => @server1.zone, + :tenant => FactoryBot.create(:tenant)) + @storage = FactoryBot.create(:storage, :name => "test_storage", :store_type => "VMFS") + @host = FactoryBot.create(:host, :name => "test_host", :hostname => "test_host", :state => 'on', :ext_management_system => @ems) - @vm = FactoryGirl.create(:vm_vmware, :name => "test_vm", :location => "abc/abc.vmx", + @vm = FactoryBot.create(:vm_vmware, :name => "test_vm", :location => "abc/abc.vmx", :raw_power_state => 'poweredOn', :host => @host, :ext_management_system => @ems, @@ -430,11 +430,11 @@ # remote zone @server2 = EvmSpecHelper.remote_miq_server(:capabilities => {:vixDisk => true}) - @user2 = FactoryGirl.create(:user_with_group, :userid => "tester2") - @storage2 = FactoryGirl.create(:storage, :name => "test_storage2", :store_type => "VMFS") - @host2 = FactoryGirl.create(:host, :name => "test_host2", :hostname => "test_host2", + @user2 = FactoryBot.create(:user_with_group, :userid => "tester2") + @storage2 = FactoryBot.create(:storage, :name => "test_storage2", :store_type => "VMFS") + @host2 = FactoryBot.create(:host, :name => "test_host2", :hostname => "test_host2", :state => 'on', :ext_management_system => @ems) - @vm2 = FactoryGirl.create(:vm_vmware, :name => "test_vm2", :location => "abc2/abc2.vmx", + @vm2 = FactoryBot.create(:vm_vmware, :name => "test_vm2", :location => "abc2/abc2.vmx", :raw_power_state => 'poweredOn', :host => @host2, :ext_management_system => @ems, @@ -517,7 +517,7 @@ private def assign_smartproxy_role_to_server(server) - server_role = FactoryGirl.create( + server_role = FactoryBot.create( :server_role, :name => "smartproxy", :description => "SmartProxy", @@ -525,7 +525,7 @@ def assign_smartproxy_role_to_server(server) :external_failover => false, :role_scope => "zone" ) - FactoryGirl.create( + FactoryBot.create( :assigned_server_role, :miq_server_id => server.id, :server_role_id => server_role.id, diff --git a/spec/models/vm_spec.rb b/spec/models/vm_spec.rb index 2c26f1dc93e..9d7d1b1bbd6 100644 --- a/spec/models/vm_spec.rb +++ b/spec/models/vm_spec.rb @@ -14,7 +14,7 @@ end context "#template=" do - before { @vm = FactoryGirl.create(:vm_vmware) } + before { @vm = FactoryBot.create(:vm_vmware) } it "false" do @vm.update_attribute(:template, false) @@ -36,22 +36,22 @@ end it "#validate_remote_console_vmrc_support only suppored on vmware" do - vm = FactoryGirl.create(:vm_redhat, :vendor => "redhat") + vm = FactoryBot.create(:vm_redhat, :vendor => "redhat") expect { vm.validate_remote_console_vmrc_support }.to raise_error MiqException::RemoteConsoleNotSupportedError end context ".find_all_by_mac_address_and_hostname_and_ipaddress" do before do - @hardware1 = FactoryGirl.create(:hardware) - @vm1 = FactoryGirl.create(:vm_vmware, :hardware => @hardware1) + @hardware1 = FactoryBot.create(:hardware) + @vm1 = FactoryBot.create(:vm_vmware, :hardware => @hardware1) - @hardware2 = FactoryGirl.create(:hardware) - @vm2 = FactoryGirl.create(:vm_vmware, :hardware => @hardware2) + @hardware2 = FactoryBot.create(:hardware) + @vm2 = FactoryBot.create(:vm_vmware, :hardware => @hardware2) end it "mac_address" do address = "ABCDEFG" - guest_device = FactoryGirl.create(:guest_device, :address => address, :device_type => "ethernet") + guest_device = FactoryBot.create(:guest_device, :address => address, :device_type => "ethernet") @hardware1.guest_devices << guest_device expect(described_class.find_all_by_mac_address_and_hostname_and_ipaddress(address, nil, nil)) @@ -60,7 +60,7 @@ it "hostname" do hostname = "ABCDEFG" - network = FactoryGirl.create(:network, :hostname => hostname) + network = FactoryBot.create(:network, :hostname => hostname) @hardware1.networks << network expect(described_class.find_all_by_mac_address_and_hostname_and_ipaddress(nil, hostname, nil)) @@ -69,7 +69,7 @@ it "ipaddress" do ipaddress = "127.0.0.1" - network = FactoryGirl.create(:network, :ipaddress => ipaddress) + network = FactoryBot.create(:network, :ipaddress => ipaddress) @hardware1.networks << network expect(described_class.find_all_by_mac_address_and_hostname_and_ipaddress(nil, nil, ipaddress)) @@ -84,10 +84,10 @@ context "with relationships of multiple types" do before do - @rp = FactoryGirl.create(:resource_pool, :name => "RP") - @parent_vm = FactoryGirl.create(:vm_vmware, :name => "Parent VM") - @vm = FactoryGirl.create(:vm_vmware, :name => "VM") - @child_vm = FactoryGirl.create(:vm_vmware, :name => "Child VM") + @rp = FactoryBot.create(:resource_pool, :name => "RP") + @parent_vm = FactoryBot.create(:vm_vmware, :name => "Parent VM") + @vm = FactoryBot.create(:vm_vmware, :name => "VM") + @child_vm = FactoryBot.create(:vm_vmware, :name => "Child VM") @rp.with_relationship_type("ems_metadata") { @rp.add_child(@vm) } @parent_vm.with_relationship_type("genealogy") { @parent_vm.add_child(@vm) } @@ -115,8 +115,8 @@ context "#invoke_tasks_local" do before do EvmSpecHelper.create_guid_miq_server_zone - @host = FactoryGirl.create(:host) - @vm = FactoryGirl.create(:vm_vmware, :host => @host) + @host = FactoryBot.create(:host) + @vm = FactoryBot.create(:vm_vmware, :host => @host) end it "sets up standard callback for non Power Operations" do @@ -159,14 +159,14 @@ context "#start" do before do EvmSpecHelper.create_guid_miq_server_zone - @host = FactoryGirl.create(:host_vmware) - @vm = FactoryGirl.create(:vm_vmware, + @host = FactoryBot.create(:host_vmware) + @vm = FactoryBot.create(:vm_vmware, :host => @host, - :miq_group => FactoryGirl.create(:miq_group) + :miq_group => FactoryBot.create(:miq_group) ) - FactoryGirl.create(:miq_event_definition, :name => :request_vm_start) + FactoryBot.create(:miq_event_definition, :name => :request_vm_start) # admin user is needed to process Events - User.super_admin || FactoryGirl.create(:user_with_group, :userid => "admin") + User.super_admin || FactoryBot.create(:user_with_group, :userid => "admin") end it "policy passes" do @@ -193,15 +193,15 @@ context "#scan" do before do EvmSpecHelper.create_guid_miq_server_zone - @host = FactoryGirl.create(:host_vmware) - @vm = FactoryGirl.create( + @host = FactoryBot.create(:host_vmware) + @vm = FactoryBot.create( :vm_vmware, :host => @host, - :miq_group => FactoryGirl.create(:miq_group) + :miq_group => FactoryBot.create(:miq_group) ) - FactoryGirl.create(:miq_event_definition, :name => :request_vm_scan) + FactoryBot.create(:miq_event_definition, :name => :request_vm_scan) # admin user is needed to process Events - User.super_admin || FactoryGirl.create(:user_with_group, :userid => "admin") + User.super_admin || FactoryBot.create(:user_with_group, :userid => "admin") end it "policy passes" do @@ -227,7 +227,7 @@ it "#save_drift_state" do # TODO: Beef up with more data - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) vm.save_drift_state expect(vm.drift_states.size).to eq(1) @@ -255,7 +255,7 @@ end it '#set_remote_console_url' do - vm = FactoryGirl.create(:vm_vmware) + vm = FactoryBot.create(:vm_vmware) vm.send(:remote_console_url=, url = 'http://www.redhat.com', 1) console = SystemConsole.find_by(:vm_id => vm.id) @@ -264,8 +264,8 @@ end describe '#add_to_service' do - let(:vm) { FactoryGirl.create(:vm_vmware) } - let(:service) { FactoryGirl.create(:service) } + let(:vm) { FactoryBot.create(:vm_vmware) } + let(:service) { FactoryBot.create(:service) } it 'associates the vm to the service' do vm.add_to_service(service) @@ -289,19 +289,19 @@ allow(ServerRole).to receive(:seed_data).and_return(@csv) ServerRole.seed _, _, @zone = EvmSpecHelper.create_guid_miq_server_zone - @ems = FactoryGirl.create(:ext_management_system, :zone => @zone) + @ems = FactoryBot.create(:ext_management_system, :zone => @zone) end it "is direct when no role" do - vm = FactoryGirl.create(:vm_openstack) + vm = FactoryBot.create(:vm_openstack) allow(vm).to receive_messages(:ipaddresses => ["10.0.0.1"]) expect(vm.cockpit_url).to eq(URI::HTTP.build(:host => "10.0.0.1", :port => 9090)) end it "uses dashboard redirect when cockpit role is active" do - vm = FactoryGirl.create(:vm_openstack, :ext_management_system => @ems) + vm = FactoryBot.create(:vm_openstack, :ext_management_system => @ems) allow(vm).to receive_messages(:ipaddresses => ["10.0.0.1"]) - server = FactoryGirl.create(:miq_server, :ipaddress => "10.0.0.2", :has_active_cockpit_ws => true, :zone => @zone) + server = FactoryBot.create(:miq_server, :ipaddress => "10.0.0.2", :has_active_cockpit_ws => true, :zone => @zone) server.assign_role('cockpit_ws', 1) server.activate_roles('cockpit_ws') expect(vm.cockpit_url).to eq(URI.parse("https://10.0.0.2/cws/=10.0.0.1")) @@ -310,7 +310,7 @@ context "#supported_consoles" do it 'returns all of the console types' do - vm = FactoryGirl.create(:vm) + vm = FactoryBot.create(:vm) expect(vm.supported_consoles.keys).to match_array([:spice, :vnc, :vmrc, :webmks, :cockpit]) end end diff --git a/spec/models/vmdb_database/seeding_spec.rb b/spec/models/vmdb_database/seeding_spec.rb index 3f7b823d7f2..259fae85474 100644 --- a/spec/models/vmdb_database/seeding_spec.rb +++ b/spec/models/vmdb_database/seeding_spec.rb @@ -14,7 +14,7 @@ context "#seed" do before do MiqDatabase.seed - @db = FactoryGirl.create(:vmdb_database) + @db = FactoryBot.create(:vmdb_database) end it "adds new tables" do @@ -26,7 +26,7 @@ it "removes deleted tables" do table = 'flintstones' - FactoryGirl.create(:vmdb_table_evm, :vmdb_database => @db, :name => table) + FactoryBot.create(:vmdb_table_evm, :vmdb_database => @db, :name => table) @db.reload expect(@db.evm_tables.collect(&:name)).to include(table) @@ -38,7 +38,7 @@ it "finds existing tables" do table = 'flintstones' connection.select_value("CREATE TABLE #{table} (id BIGINT PRIMARY KEY)") - FactoryGirl.create(:vmdb_table_evm, :vmdb_database => @db, :name => table) + FactoryBot.create(:vmdb_table_evm, :vmdb_database => @db, :name => table) expect(VmdbTableEvm).to receive(:create).never @db.seed @@ -74,7 +74,7 @@ it "should not update table values" do factory_ip_address = "127.0.0.1" - FactoryGirl.create(:vmdb_database, :ipaddress => factory_ip_address) + FactoryBot.create(:vmdb_database, :ipaddress => factory_ip_address) stubbed_ip_address = "127.0.0.1" allow(described_class).to receive(:db_server_ipaddress).and_return(stubbed_ip_address) @@ -86,7 +86,7 @@ it "should update table values" do factory_ip_address = "127.0.0.1" - FactoryGirl.create(:vmdb_database, :ipaddress => factory_ip_address) + FactoryBot.create(:vmdb_database, :ipaddress => factory_ip_address) stubbed_ip_address = "192.255.255.1" allow(described_class).to receive(:db_server_ipaddress).and_return(stubbed_ip_address) diff --git a/spec/models/vmdb_database_setting_spec.rb b/spec/models/vmdb_database_setting_spec.rb index cb2b6a83dd9..6cace19ec81 100644 --- a/spec/models/vmdb_database_setting_spec.rb +++ b/spec/models/vmdb_database_setting_spec.rb @@ -1,6 +1,6 @@ describe VmdbDatabaseSetting do before do - @db = FactoryGirl.create(:vmdb_database) + @db = FactoryBot.create(:vmdb_database) end it 'has database settings' do diff --git a/spec/models/vmdb_database_spec.rb b/spec/models/vmdb_database_spec.rb index c5a9bb1c158..66737fed6ee 100644 --- a/spec/models/vmdb_database_spec.rb +++ b/spec/models/vmdb_database_spec.rb @@ -1,8 +1,8 @@ describe VmdbDatabase do before do - @db = FactoryGirl.create(:vmdb_database) - @table = FactoryGirl.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'accounts') - @text = FactoryGirl.create(:vmdb_table_text, :vmdb_database => @db, :name => 'accounts', :parent_id => @table.id) + @db = FactoryBot.create(:vmdb_database) + @table = FactoryBot.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'accounts') + @text = FactoryBot.create(:vmdb_table_text, :vmdb_database => @db, :name => 'accounts', :parent_id => @table.id) end it "#size" do @@ -85,22 +85,22 @@ context "#top_tables_by" do before do - @table_1 = FactoryGirl.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'accounts1') - @table_2 = FactoryGirl.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'accounts2') - @table_3 = FactoryGirl.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'accounts3') - @table_4 = FactoryGirl.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'accounts4') - @table_5 = FactoryGirl.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'accounts5') - @table_6 = FactoryGirl.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'accounts6') - @table_7 = FactoryGirl.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'accounts7') - - @metric_1 = FactoryGirl.create(:vmdb_metric, :resource => @table_1, :capture_interval_name => 'hourly', :rows => 125, :size => 15000, :wasted_bytes => 4) - @metric_2 = FactoryGirl.create(:vmdb_metric, :resource => @table_2, :capture_interval_name => 'hourly', :rows => 255, :size => 10000, :wasted_bytes => 8) - @metric_3 = FactoryGirl.create(:vmdb_metric, :resource => @table_3, :capture_interval_name => 'hourly', :rows => 505, :size => 5000, :wasted_bytes => 16) - @metric_4 = FactoryGirl.create(:vmdb_metric, :resource => @table_4, :capture_interval_name => 'hourly', :rows => 1005, :size => 2000, :wasted_bytes => 32) - @metric_5 = FactoryGirl.create(:vmdb_metric, :resource => @table_5, :capture_interval_name => 'hourly', :rows => 2005, :size => 1000, :wasted_bytes => 64) - @metric_6 = FactoryGirl.create(:vmdb_metric, :resource => @table_6, :capture_interval_name => 'hourly', :rows => 4005, :size => 500, :wasted_bytes => 128) - @metric_7a = FactoryGirl.create(:vmdb_metric, :resource => @table_7, :capture_interval_name => 'hourly', :rows => 10005, :size => 150, :wasted_bytes => 256, :timestamp => 1.hour.ago) - @metric_7b = FactoryGirl.create(:vmdb_metric, :resource => @table_7, :capture_interval_name => 'hourly', :rows => 1, :size => 150, :wasted_bytes => 256, :timestamp => 1.minute.ago) + @table_1 = FactoryBot.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'accounts1') + @table_2 = FactoryBot.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'accounts2') + @table_3 = FactoryBot.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'accounts3') + @table_4 = FactoryBot.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'accounts4') + @table_5 = FactoryBot.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'accounts5') + @table_6 = FactoryBot.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'accounts6') + @table_7 = FactoryBot.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'accounts7') + + @metric_1 = FactoryBot.create(:vmdb_metric, :resource => @table_1, :capture_interval_name => 'hourly', :rows => 125, :size => 15000, :wasted_bytes => 4) + @metric_2 = FactoryBot.create(:vmdb_metric, :resource => @table_2, :capture_interval_name => 'hourly', :rows => 255, :size => 10000, :wasted_bytes => 8) + @metric_3 = FactoryBot.create(:vmdb_metric, :resource => @table_3, :capture_interval_name => 'hourly', :rows => 505, :size => 5000, :wasted_bytes => 16) + @metric_4 = FactoryBot.create(:vmdb_metric, :resource => @table_4, :capture_interval_name => 'hourly', :rows => 1005, :size => 2000, :wasted_bytes => 32) + @metric_5 = FactoryBot.create(:vmdb_metric, :resource => @table_5, :capture_interval_name => 'hourly', :rows => 2005, :size => 1000, :wasted_bytes => 64) + @metric_6 = FactoryBot.create(:vmdb_metric, :resource => @table_6, :capture_interval_name => 'hourly', :rows => 4005, :size => 500, :wasted_bytes => 128) + @metric_7a = FactoryBot.create(:vmdb_metric, :resource => @table_7, :capture_interval_name => 'hourly', :rows => 10005, :size => 150, :wasted_bytes => 256, :timestamp => 1.hour.ago) + @metric_7b = FactoryBot.create(:vmdb_metric, :resource => @table_7, :capture_interval_name => 'hourly', :rows => 1, :size => 150, :wasted_bytes => 256, :timestamp => 1.minute.ago) end it "will return a list of ALL tables sorted by number of rows" do @@ -133,7 +133,7 @@ context 'with metrics' do before do - @db.vmdb_database_metrics = [FactoryGirl.create(:vmdb_database_metric, :capture_interval_name => 'hourly')] + @db.vmdb_database_metrics = [FactoryBot.create(:vmdb_database_metric, :capture_interval_name => 'hourly')] end it { is_expected.to be_truthy } diff --git a/spec/models/vmdb_index_spec.rb b/spec/models/vmdb_index_spec.rb index 1586f454339..75f0a78fcb3 100644 --- a/spec/models/vmdb_index_spec.rb +++ b/spec/models/vmdb_index_spec.rb @@ -1,6 +1,6 @@ describe VmdbIndex do context "#capture_metrics" do - let(:index) { FactoryGirl.create(:vmdb_index, :name => "accounts_pkey") } + let(:index) { FactoryBot.create(:vmdb_index, :name => "accounts_pkey") } it "creates a vmdb_metrics record" do # The first capture just gets the raw data @@ -34,64 +34,64 @@ context "#rollup_metrics" do before do db = VmdbDatabase.seed_self - @evm_table = FactoryGirl.create(:vmdb_table_evm, :vmdb_database => db, :name => 'accounts') - @evm_index = FactoryGirl.create(:vmdb_index, :vmdb_table => @evm_table, :name => "accounts_pkey") + @evm_table = FactoryBot.create(:vmdb_table_evm, :vmdb_database => db, :name => 'accounts') + @evm_index = FactoryBot.create(:vmdb_index, :vmdb_table => @evm_table, :name => "accounts_pkey") ts = Time.gm(2012, 8, 15, 10, 00, 01) # Need specific date in order to keep track of rollup data... - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 50.hours, :rows => 0, :size => 0, :wasted_bytes => 0, :percent_bloat => 0.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 49.hours, :rows => 10, :size => 100, :wasted_bytes => 2, :percent_bloat => 0.2) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 48.hours, :rows => 10, :size => 100, :wasted_bytes => 2, :percent_bloat => 0.2) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 47.hours, :rows => 20, :size => 200, :wasted_bytes => 4, :percent_bloat => 0.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 46.hours, :rows => 20, :size => 200, :wasted_bytes => 4, :percent_bloat => 0.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 45.hours, :rows => 20, :size => 200, :wasted_bytes => 4, :percent_bloat => 0.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 44.hours, :rows => 30, :size => 300, :wasted_bytes => 6, :percent_bloat => 0.5) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 43.hours, :rows => 40, :size => 400, :wasted_bytes => 8, :percent_bloat => 0.6) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 42.hours, :rows => 50, :size => 500, :wasted_bytes => 10, :percent_bloat => 0.7) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 41.hours, :rows => 60, :size => 600, :wasted_bytes => 12, :percent_bloat => 0.8) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 40.hours, :rows => 60, :size => 600, :wasted_bytes => 12, :percent_bloat => 0.8) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 39.hours, :rows => 70, :size => 700, :wasted_bytes => 14, :percent_bloat => 1.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 38.hours, :rows => 80, :size => 800, :wasted_bytes => 16, :percent_bloat => 1.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 37.hours, :rows => 90, :size => 900, :wasted_bytes => 18, :percent_bloat => 4.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 36.hours, :rows => 100, :size => 1000, :wasted_bytes => 20, :percent_bloat => 5.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 35.hours, :rows => 110, :size => 1100, :wasted_bytes => 22, :percent_bloat => 6.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 50.hours, :rows => 0, :size => 0, :wasted_bytes => 0, :percent_bloat => 0.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 49.hours, :rows => 10, :size => 100, :wasted_bytes => 2, :percent_bloat => 0.2) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 48.hours, :rows => 10, :size => 100, :wasted_bytes => 2, :percent_bloat => 0.2) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 47.hours, :rows => 20, :size => 200, :wasted_bytes => 4, :percent_bloat => 0.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 46.hours, :rows => 20, :size => 200, :wasted_bytes => 4, :percent_bloat => 0.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 45.hours, :rows => 20, :size => 200, :wasted_bytes => 4, :percent_bloat => 0.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 44.hours, :rows => 30, :size => 300, :wasted_bytes => 6, :percent_bloat => 0.5) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 43.hours, :rows => 40, :size => 400, :wasted_bytes => 8, :percent_bloat => 0.6) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 42.hours, :rows => 50, :size => 500, :wasted_bytes => 10, :percent_bloat => 0.7) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 41.hours, :rows => 60, :size => 600, :wasted_bytes => 12, :percent_bloat => 0.8) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 40.hours, :rows => 60, :size => 600, :wasted_bytes => 12, :percent_bloat => 0.8) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 39.hours, :rows => 70, :size => 700, :wasted_bytes => 14, :percent_bloat => 1.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 38.hours, :rows => 80, :size => 800, :wasted_bytes => 16, :percent_bloat => 1.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 37.hours, :rows => 90, :size => 900, :wasted_bytes => 18, :percent_bloat => 4.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 36.hours, :rows => 100, :size => 1000, :wasted_bytes => 20, :percent_bloat => 5.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 35.hours, :rows => 110, :size => 1100, :wasted_bytes => 22, :percent_bloat => 6.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 34.hours, :rows => 120, :size => 1200, :wasted_bytes => 24, :percent_bloat => 9.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 33.hours, :rows => 130, :size => 1300, :wasted_bytes => 26, :percent_bloat => 11.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 32.hours, :rows => 130, :size => 1300, :wasted_bytes => 26, :percent_bloat => 11.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 31.hours, :rows => 130, :size => 1300, :wasted_bytes => 26, :percent_bloat => 11.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 30.hours, :rows => 140, :size => 1400, :wasted_bytes => 28, :percent_bloat => 14.5) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 29.hours, :rows => 150, :size => 1500, :wasted_bytes => 30, :percent_bloat => 15.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 28.hours, :rows => 160, :size => 1600, :wasted_bytes => 32, :percent_bloat => 16.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 27.hours, :rows => 170, :size => 1700, :wasted_bytes => 34, :percent_bloat => 17.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 26.hours, :rows => 180, :size => 1800, :wasted_bytes => 36, :percent_bloat => 18.3) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 25.hours, :rows => 190, :size => 1900, :wasted_bytes => 38, :percent_bloat => 19.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 24.hours, :rows => 200, :size => 2000, :wasted_bytes => 40, :percent_bloat => 20.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 23.hours, :rows => 200, :size => 2000, :wasted_bytes => 40, :percent_bloat => 20.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 22.hours, :rows => 210, :size => 2100, :wasted_bytes => 42, :percent_bloat => 21.6) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 21.hours, :rows => 220, :size => 2200, :wasted_bytes => 44, :percent_bloat => 22.1) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 20.hours, :rows => 240, :size => 2400, :wasted_bytes => 26, :percent_bloat => 24.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 19.hours, :rows => 250, :size => 2500, :wasted_bytes => 28, :percent_bloat => 25.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 18.hours, :rows => 260, :size => 2600, :wasted_bytes => 30, :percent_bloat => 26.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 17.hours, :rows => 290, :size => 2900, :wasted_bytes => 32, :percent_bloat => 29.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 16.hours, :rows => 300, :size => 3000, :wasted_bytes => 34, :percent_bloat => 30.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 15.hours, :rows => 340, :size => 3400, :wasted_bytes => 36, :percent_bloat => 34.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 14.hours, :rows => 350, :size => 3500, :wasted_bytes => 38, :percent_bloat => 35.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 13.hours, :rows => 350, :size => 3500, :wasted_bytes => 40, :percent_bloat => 35.3) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 12.hours, :rows => 360, :size => 3600, :wasted_bytes => 40, :percent_bloat => 36.5) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 11.hours, :rows => 380, :size => 3800, :wasted_bytes => 42, :percent_bloat => 38.8) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 34.hours, :rows => 120, :size => 1200, :wasted_bytes => 24, :percent_bloat => 9.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 33.hours, :rows => 130, :size => 1300, :wasted_bytes => 26, :percent_bloat => 11.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 32.hours, :rows => 130, :size => 1300, :wasted_bytes => 26, :percent_bloat => 11.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 31.hours, :rows => 130, :size => 1300, :wasted_bytes => 26, :percent_bloat => 11.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 30.hours, :rows => 140, :size => 1400, :wasted_bytes => 28, :percent_bloat => 14.5) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 29.hours, :rows => 150, :size => 1500, :wasted_bytes => 30, :percent_bloat => 15.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 28.hours, :rows => 160, :size => 1600, :wasted_bytes => 32, :percent_bloat => 16.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 27.hours, :rows => 170, :size => 1700, :wasted_bytes => 34, :percent_bloat => 17.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 26.hours, :rows => 180, :size => 1800, :wasted_bytes => 36, :percent_bloat => 18.3) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 25.hours, :rows => 190, :size => 1900, :wasted_bytes => 38, :percent_bloat => 19.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 24.hours, :rows => 200, :size => 2000, :wasted_bytes => 40, :percent_bloat => 20.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 23.hours, :rows => 200, :size => 2000, :wasted_bytes => 40, :percent_bloat => 20.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 22.hours, :rows => 210, :size => 2100, :wasted_bytes => 42, :percent_bloat => 21.6) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 21.hours, :rows => 220, :size => 2200, :wasted_bytes => 44, :percent_bloat => 22.1) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 20.hours, :rows => 240, :size => 2400, :wasted_bytes => 26, :percent_bloat => 24.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 19.hours, :rows => 250, :size => 2500, :wasted_bytes => 28, :percent_bloat => 25.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 18.hours, :rows => 260, :size => 2600, :wasted_bytes => 30, :percent_bloat => 26.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 17.hours, :rows => 290, :size => 2900, :wasted_bytes => 32, :percent_bloat => 29.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 16.hours, :rows => 300, :size => 3000, :wasted_bytes => 34, :percent_bloat => 30.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 15.hours, :rows => 340, :size => 3400, :wasted_bytes => 36, :percent_bloat => 34.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 14.hours, :rows => 350, :size => 3500, :wasted_bytes => 38, :percent_bloat => 35.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 13.hours, :rows => 350, :size => 3500, :wasted_bytes => 40, :percent_bloat => 35.3) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 12.hours, :rows => 360, :size => 3600, :wasted_bytes => 40, :percent_bloat => 36.5) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 11.hours, :rows => 380, :size => 3800, :wasted_bytes => 42, :percent_bloat => 38.8) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 10.hours, :rows => 400, :size => 4000, :wasted_bytes => 44, :percent_bloat => 40.9) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 9.hours, :rows => 410, :size => 4100, :wasted_bytes => 60, :percent_bloat => 41.1) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 8.hours, :rows => 420, :size => 4200, :wasted_bytes => 62, :percent_bloat => 42.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 7.hours, :rows => 420, :size => 4200, :wasted_bytes => 64, :percent_bloat => 42.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 6.hours, :rows => 430, :size => 4300, :wasted_bytes => 70, :percent_bloat => 43.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 5.hours, :rows => 440, :size => 4400, :wasted_bytes => 72, :percent_bloat => 44.7) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 4.hours, :rows => 460, :size => 4600, :wasted_bytes => 74, :percent_bloat => 46.3) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 3.hours, :rows => 470, :size => 4700, :wasted_bytes => 76, :percent_bloat => 47.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 2.hours, :rows => 480, :size => 4800, :wasted_bytes => 80, :percent_bloat => 48.5) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 1.hour, :rows => 490, :size => 4900, :wasted_bytes => 84, :percent_bloat => 49.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts, :rows => 500, :size => 5000, :wasted_bytes => 90, :percent_bloat => 50.7) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 10.hours, :rows => 400, :size => 4000, :wasted_bytes => 44, :percent_bloat => 40.9) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 9.hours, :rows => 410, :size => 4100, :wasted_bytes => 60, :percent_bloat => 41.1) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 8.hours, :rows => 420, :size => 4200, :wasted_bytes => 62, :percent_bloat => 42.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 7.hours, :rows => 420, :size => 4200, :wasted_bytes => 64, :percent_bloat => 42.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 6.hours, :rows => 430, :size => 4300, :wasted_bytes => 70, :percent_bloat => 43.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 5.hours, :rows => 440, :size => 4400, :wasted_bytes => 72, :percent_bloat => 44.7) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 4.hours, :rows => 460, :size => 4600, :wasted_bytes => 74, :percent_bloat => 46.3) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 3.hours, :rows => 470, :size => 4700, :wasted_bytes => 76, :percent_bloat => 47.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 2.hours, :rows => 480, :size => 4800, :wasted_bytes => 80, :percent_bloat => 48.5) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts - 1.hour, :rows => 490, :size => 4900, :wasted_bytes => 84, :percent_bloat => 49.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_index, :timestamp => ts, :rows => 500, :size => 5000, :wasted_bytes => 90, :percent_bloat => 50.7) end it "will return 1 row with average daily rollups for metrics" do diff --git a/spec/models/vmdb_table_evm_spec.rb b/spec/models/vmdb_table_evm_spec.rb index 3e7d9e5eedf..0b2660eff5c 100644 --- a/spec/models/vmdb_table_evm_spec.rb +++ b/spec/models/vmdb_table_evm_spec.rb @@ -1,7 +1,7 @@ describe VmdbTableEvm do it "#seed" do VmdbDatabase.seed_self - evm_table = FactoryGirl.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'foo') + evm_table = FactoryBot.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'foo') expect(evm_table).to receive(:seed_texts).once expect(evm_table).to receive(:seed_indexes).once evm_table.seed @@ -12,7 +12,7 @@ let(:table_name) { "vmdb_table_evm_test_table" } let(:unique_name) { "vmdb_table_evm_test_unique" } let(:index_name) { "vmdb_table_evm_test_index" } - let(:evm_table) { FactoryGirl.create(:vmdb_table_evm, :name => table_name) } + let(:evm_table) { FactoryBot.create(:vmdb_table_evm, :name => table_name) } let(:expected_values) do [ @@ -59,7 +59,7 @@ context "#seed_texts" do before do @db = VmdbDatabase.seed_self - @evm_table = FactoryGirl.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'foo') + @evm_table = FactoryBot.create(:vmdb_table_evm, :vmdb_database => @db, :name => 'foo') end it "adds new tables" do @@ -72,7 +72,7 @@ it "removes deleted tables" do table_names = ['flintstones'] - table_names.each { |t| FactoryGirl.create(:vmdb_table_text, :vmdb_database => @db, :evm_table => @evm_table, :name => t) } + table_names.each { |t| FactoryBot.create(:vmdb_table_text, :vmdb_database => @db, :evm_table => @evm_table, :name => t) } @evm_table.reload expect(@evm_table.text_tables.collect(&:name)).to eq(table_names) @@ -84,7 +84,7 @@ it "finds existing tables" do table_names = ['flintstones'] - table_names.each { |t| FactoryGirl.create(:vmdb_table_text, :vmdb_database => @db, :evm_table => @evm_table, :name => t) } + table_names.each { |t| FactoryBot.create(:vmdb_table_text, :vmdb_database => @db, :evm_table => @evm_table, :name => t) } allow(described_class.connection).to receive(:text_tables).and_return(table_names) @evm_table.seed_texts @evm_table.reload @@ -93,7 +93,7 @@ end context "#capture_metrics" do - let(:table) { FactoryGirl.create(:vmdb_table_evm, :name => "accounts") } + let(:table) { FactoryBot.create(:vmdb_table_evm, :name => "accounts") } it "creates a vmdb_metrics record" do # The first capture just gets the raw data @@ -119,7 +119,7 @@ end it "captures index metrics" do - index = FactoryGirl.create(:vmdb_index, :name => "accounts_pkey") + index = FactoryBot.create(:vmdb_index, :name => "accounts_pkey") table.vmdb_database = VmdbDatabase.seed_self table.vmdb_indexes << index @@ -131,63 +131,63 @@ context "#rollup_metrics" do before do db = VmdbDatabase.seed_self - @evm_table = FactoryGirl.create(:vmdb_table_evm, :vmdb_database => db, :name => 'accounts') + @evm_table = FactoryBot.create(:vmdb_table_evm, :vmdb_database => db, :name => 'accounts') ts = Time.gm(2012, 8, 15, 10, 00, 01) # Need specific date in order to keep track of rollup data... - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 50.hours, :rows => 0, :size => 0, :wasted_bytes => 0, :percent_bloat => 0.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 49.hours, :rows => 10, :size => 100, :wasted_bytes => 2, :percent_bloat => 0.2) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 48.hours, :rows => 10, :size => 100, :wasted_bytes => 2, :percent_bloat => 0.2) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 47.hours, :rows => 20, :size => 200, :wasted_bytes => 4, :percent_bloat => 0.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 46.hours, :rows => 20, :size => 200, :wasted_bytes => 4, :percent_bloat => 0.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 45.hours, :rows => 20, :size => 200, :wasted_bytes => 4, :percent_bloat => 0.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 44.hours, :rows => 30, :size => 300, :wasted_bytes => 6, :percent_bloat => 0.5) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 43.hours, :rows => 40, :size => 400, :wasted_bytes => 8, :percent_bloat => 0.6) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 42.hours, :rows => 50, :size => 500, :wasted_bytes => 10, :percent_bloat => 0.7) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 41.hours, :rows => 60, :size => 600, :wasted_bytes => 12, :percent_bloat => 0.8) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 40.hours, :rows => 60, :size => 600, :wasted_bytes => 12, :percent_bloat => 0.8) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 39.hours, :rows => 70, :size => 700, :wasted_bytes => 14, :percent_bloat => 1.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 38.hours, :rows => 80, :size => 800, :wasted_bytes => 16, :percent_bloat => 1.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 37.hours, :rows => 90, :size => 900, :wasted_bytes => 18, :percent_bloat => 4.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 36.hours, :rows => 100, :size => 1000, :wasted_bytes => 20, :percent_bloat => 5.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 35.hours, :rows => 110, :size => 1100, :wasted_bytes => 22, :percent_bloat => 6.0) - - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 34.hours, :rows => 120, :size => 1200, :wasted_bytes => 24, :percent_bloat => 9.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 33.hours, :rows => 130, :size => 1300, :wasted_bytes => 26, :percent_bloat => 11.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 32.hours, :rows => 130, :size => 1300, :wasted_bytes => 26, :percent_bloat => 11.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 31.hours, :rows => 130, :size => 1300, :wasted_bytes => 26, :percent_bloat => 11.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 30.hours, :rows => 140, :size => 1400, :wasted_bytes => 28, :percent_bloat => 14.5) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 29.hours, :rows => 150, :size => 1500, :wasted_bytes => 30, :percent_bloat => 15.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 28.hours, :rows => 160, :size => 1600, :wasted_bytes => 32, :percent_bloat => 16.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 27.hours, :rows => 170, :size => 1700, :wasted_bytes => 34, :percent_bloat => 17.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 26.hours, :rows => 180, :size => 1800, :wasted_bytes => 36, :percent_bloat => 18.3) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 25.hours, :rows => 190, :size => 1900, :wasted_bytes => 38, :percent_bloat => 19.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 24.hours, :rows => 200, :size => 2000, :wasted_bytes => 40, :percent_bloat => 20.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 23.hours, :rows => 200, :size => 2000, :wasted_bytes => 40, :percent_bloat => 20.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 22.hours, :rows => 210, :size => 2100, :wasted_bytes => 42, :percent_bloat => 21.6) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 21.hours, :rows => 220, :size => 2200, :wasted_bytes => 44, :percent_bloat => 22.1) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 20.hours, :rows => 240, :size => 2400, :wasted_bytes => 26, :percent_bloat => 24.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 19.hours, :rows => 250, :size => 2500, :wasted_bytes => 28, :percent_bloat => 25.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 18.hours, :rows => 260, :size => 2600, :wasted_bytes => 30, :percent_bloat => 26.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 17.hours, :rows => 290, :size => 2900, :wasted_bytes => 32, :percent_bloat => 29.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 16.hours, :rows => 300, :size => 3000, :wasted_bytes => 34, :percent_bloat => 30.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 15.hours, :rows => 340, :size => 3400, :wasted_bytes => 36, :percent_bloat => 34.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 14.hours, :rows => 350, :size => 3500, :wasted_bytes => 38, :percent_bloat => 35.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 13.hours, :rows => 350, :size => 3500, :wasted_bytes => 40, :percent_bloat => 35.3) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 12.hours, :rows => 360, :size => 3600, :wasted_bytes => 40, :percent_bloat => 36.5) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 11.hours, :rows => 380, :size => 3800, :wasted_bytes => 42, :percent_bloat => 38.8) - - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 10.hours, :rows => 400, :size => 4000, :wasted_bytes => 44, :percent_bloat => 40.9) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 9.hours, :rows => 410, :size => 4100, :wasted_bytes => 60, :percent_bloat => 41.1) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 8.hours, :rows => 420, :size => 4200, :wasted_bytes => 62, :percent_bloat => 42.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 7.hours, :rows => 420, :size => 4200, :wasted_bytes => 64, :percent_bloat => 42.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 6.hours, :rows => 430, :size => 4300, :wasted_bytes => 70, :percent_bloat => 43.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 5.hours, :rows => 440, :size => 4400, :wasted_bytes => 72, :percent_bloat => 44.7) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 4.hours, :rows => 460, :size => 4600, :wasted_bytes => 74, :percent_bloat => 46.3) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 3.hours, :rows => 470, :size => 4700, :wasted_bytes => 76, :percent_bloat => 47.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 2.hours, :rows => 480, :size => 4800, :wasted_bytes => 80, :percent_bloat => 48.5) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 1.hour, :rows => 490, :size => 4900, :wasted_bytes => 84, :percent_bloat => 49.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts, :rows => 500, :size => 5000, :wasted_bytes => 90, :percent_bloat => 50.7) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 50.hours, :rows => 0, :size => 0, :wasted_bytes => 0, :percent_bloat => 0.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 49.hours, :rows => 10, :size => 100, :wasted_bytes => 2, :percent_bloat => 0.2) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 48.hours, :rows => 10, :size => 100, :wasted_bytes => 2, :percent_bloat => 0.2) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 47.hours, :rows => 20, :size => 200, :wasted_bytes => 4, :percent_bloat => 0.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 46.hours, :rows => 20, :size => 200, :wasted_bytes => 4, :percent_bloat => 0.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 45.hours, :rows => 20, :size => 200, :wasted_bytes => 4, :percent_bloat => 0.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 44.hours, :rows => 30, :size => 300, :wasted_bytes => 6, :percent_bloat => 0.5) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 43.hours, :rows => 40, :size => 400, :wasted_bytes => 8, :percent_bloat => 0.6) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 42.hours, :rows => 50, :size => 500, :wasted_bytes => 10, :percent_bloat => 0.7) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 41.hours, :rows => 60, :size => 600, :wasted_bytes => 12, :percent_bloat => 0.8) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 40.hours, :rows => 60, :size => 600, :wasted_bytes => 12, :percent_bloat => 0.8) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 39.hours, :rows => 70, :size => 700, :wasted_bytes => 14, :percent_bloat => 1.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 38.hours, :rows => 80, :size => 800, :wasted_bytes => 16, :percent_bloat => 1.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 37.hours, :rows => 90, :size => 900, :wasted_bytes => 18, :percent_bloat => 4.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 36.hours, :rows => 100, :size => 1000, :wasted_bytes => 20, :percent_bloat => 5.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 35.hours, :rows => 110, :size => 1100, :wasted_bytes => 22, :percent_bloat => 6.0) + + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 34.hours, :rows => 120, :size => 1200, :wasted_bytes => 24, :percent_bloat => 9.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 33.hours, :rows => 130, :size => 1300, :wasted_bytes => 26, :percent_bloat => 11.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 32.hours, :rows => 130, :size => 1300, :wasted_bytes => 26, :percent_bloat => 11.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 31.hours, :rows => 130, :size => 1300, :wasted_bytes => 26, :percent_bloat => 11.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 30.hours, :rows => 140, :size => 1400, :wasted_bytes => 28, :percent_bloat => 14.5) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 29.hours, :rows => 150, :size => 1500, :wasted_bytes => 30, :percent_bloat => 15.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 28.hours, :rows => 160, :size => 1600, :wasted_bytes => 32, :percent_bloat => 16.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 27.hours, :rows => 170, :size => 1700, :wasted_bytes => 34, :percent_bloat => 17.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 26.hours, :rows => 180, :size => 1800, :wasted_bytes => 36, :percent_bloat => 18.3) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 25.hours, :rows => 190, :size => 1900, :wasted_bytes => 38, :percent_bloat => 19.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 24.hours, :rows => 200, :size => 2000, :wasted_bytes => 40, :percent_bloat => 20.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 23.hours, :rows => 200, :size => 2000, :wasted_bytes => 40, :percent_bloat => 20.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 22.hours, :rows => 210, :size => 2100, :wasted_bytes => 42, :percent_bloat => 21.6) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 21.hours, :rows => 220, :size => 2200, :wasted_bytes => 44, :percent_bloat => 22.1) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 20.hours, :rows => 240, :size => 2400, :wasted_bytes => 26, :percent_bloat => 24.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 19.hours, :rows => 250, :size => 2500, :wasted_bytes => 28, :percent_bloat => 25.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 18.hours, :rows => 260, :size => 2600, :wasted_bytes => 30, :percent_bloat => 26.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 17.hours, :rows => 290, :size => 2900, :wasted_bytes => 32, :percent_bloat => 29.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 16.hours, :rows => 300, :size => 3000, :wasted_bytes => 34, :percent_bloat => 30.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 15.hours, :rows => 340, :size => 3400, :wasted_bytes => 36, :percent_bloat => 34.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 14.hours, :rows => 350, :size => 3500, :wasted_bytes => 38, :percent_bloat => 35.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 13.hours, :rows => 350, :size => 3500, :wasted_bytes => 40, :percent_bloat => 35.3) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 12.hours, :rows => 360, :size => 3600, :wasted_bytes => 40, :percent_bloat => 36.5) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 11.hours, :rows => 380, :size => 3800, :wasted_bytes => 42, :percent_bloat => 38.8) + + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 10.hours, :rows => 400, :size => 4000, :wasted_bytes => 44, :percent_bloat => 40.9) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 9.hours, :rows => 410, :size => 4100, :wasted_bytes => 60, :percent_bloat => 41.1) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 8.hours, :rows => 420, :size => 4200, :wasted_bytes => 62, :percent_bloat => 42.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 7.hours, :rows => 420, :size => 4200, :wasted_bytes => 64, :percent_bloat => 42.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 6.hours, :rows => 430, :size => 4300, :wasted_bytes => 70, :percent_bloat => 43.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 5.hours, :rows => 440, :size => 4400, :wasted_bytes => 72, :percent_bloat => 44.7) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 4.hours, :rows => 460, :size => 4600, :wasted_bytes => 74, :percent_bloat => 46.3) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 3.hours, :rows => 470, :size => 4700, :wasted_bytes => 76, :percent_bloat => 47.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 2.hours, :rows => 480, :size => 4800, :wasted_bytes => 80, :percent_bloat => 48.5) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts - 1.hour, :rows => 490, :size => 4900, :wasted_bytes => 84, :percent_bloat => 49.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @evm_table, :timestamp => ts, :rows => 500, :size => 5000, :wasted_bytes => 90, :percent_bloat => 50.7) end it "returns 1 row with average daily rollups for metrics" do diff --git a/spec/models/vmdb_table_spec.rb b/spec/models/vmdb_table_spec.rb index 7874966cdf9..1c410d2a6de 100644 --- a/spec/models/vmdb_table_spec.rb +++ b/spec/models/vmdb_table_spec.rb @@ -2,7 +2,7 @@ context "#seed_indexes" do before do @db = VmdbDatabase.seed_self - @vmdb_table = FactoryGirl.create(:vmdb_table, :vmdb_database => @db, :name => 'foo') + @vmdb_table = FactoryBot.create(:vmdb_table, :vmdb_database => @db, :name => 'foo') end it "adds new indexes" do @@ -19,7 +19,7 @@ it "removes deleted indexes" do index_names = ['flintstones'] - index_names.each { |i| FactoryGirl.create(:vmdb_index, :vmdb_table => @vmdb_table, :name => i) } + index_names.each { |i| FactoryBot.create(:vmdb_index, :vmdb_table => @vmdb_table, :name => i) } @vmdb_table.reload expect(@vmdb_table.vmdb_indexes.collect(&:name)).to eq(index_names) @@ -36,7 +36,7 @@ allow(index).to receive(:name).and_return(i) index end - index_names.each { |i| FactoryGirl.create(:vmdb_index, :vmdb_table => @vmdb_table, :name => i) } + index_names.each { |i| FactoryBot.create(:vmdb_index, :vmdb_table => @vmdb_table, :name => i) } allow(@vmdb_table).to receive(:sql_indexes).and_return(index_results) @vmdb_table.seed_indexes @vmdb_table.reload @@ -46,17 +46,17 @@ it "fetches latest metric record" do ts = Time.gm(2012, 8, 15, 10, 00, 01) # Need specific date in order to keep track of rollup data... - FactoryGirl.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 10.hours, :rows => 400, :size => 4000, :wasted_bytes => 44, :percent_bloat => 40.9) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 9.hours, :rows => 410, :size => 4100, :wasted_bytes => 60, :percent_bloat => 41.1) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 8.hours, :rows => 420, :size => 4200, :wasted_bytes => 62, :percent_bloat => 42.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 7.hours, :rows => 420, :size => 4200, :wasted_bytes => 64, :percent_bloat => 42.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 6.hours, :rows => 430, :size => 4300, :wasted_bytes => 70, :percent_bloat => 43.4) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 5.hours, :rows => 440, :size => 4400, :wasted_bytes => 72, :percent_bloat => 44.7) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 4.hours, :rows => 460, :size => 4600, :wasted_bytes => 74, :percent_bloat => 46.3) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 3.hours, :rows => 470, :size => 4700, :wasted_bytes => 76, :percent_bloat => 47.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 2.hours, :rows => 480, :size => 4800, :wasted_bytes => 80, :percent_bloat => 48.5) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 1.hour, :rows => 490, :size => 4900, :wasted_bytes => 84, :percent_bloat => 49.0) - FactoryGirl.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts, :rows => 500, :size => 5000, :wasted_bytes => 90, :percent_bloat => 50.7) + FactoryBot.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 10.hours, :rows => 400, :size => 4000, :wasted_bytes => 44, :percent_bloat => 40.9) + FactoryBot.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 9.hours, :rows => 410, :size => 4100, :wasted_bytes => 60, :percent_bloat => 41.1) + FactoryBot.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 8.hours, :rows => 420, :size => 4200, :wasted_bytes => 62, :percent_bloat => 42.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 7.hours, :rows => 420, :size => 4200, :wasted_bytes => 64, :percent_bloat => 42.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 6.hours, :rows => 430, :size => 4300, :wasted_bytes => 70, :percent_bloat => 43.4) + FactoryBot.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 5.hours, :rows => 440, :size => 4400, :wasted_bytes => 72, :percent_bloat => 44.7) + FactoryBot.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 4.hours, :rows => 460, :size => 4600, :wasted_bytes => 74, :percent_bloat => 46.3) + FactoryBot.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 3.hours, :rows => 470, :size => 4700, :wasted_bytes => 76, :percent_bloat => 47.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 2.hours, :rows => 480, :size => 4800, :wasted_bytes => 80, :percent_bloat => 48.5) + FactoryBot.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts - 1.hour, :rows => 490, :size => 4900, :wasted_bytes => 84, :percent_bloat => 49.0) + FactoryBot.create(:vmdb_metric_hourly, :resource => @vmdb_table, :timestamp => ts, :rows => 500, :size => 5000, :wasted_bytes => 90, :percent_bloat => 50.7) expect(@vmdb_table.latest_hourly_metric.rows).to eq(500) expect(@vmdb_table.latest_hourly_metric.size).to eq(5000) diff --git a/spec/models/zone_spec.rb b/spec/models/zone_spec.rb index c74fac3a64b..586ebada25e 100644 --- a/spec/models/zone_spec.rb +++ b/spec/models/zone_spec.rb @@ -3,10 +3,10 @@ context "with two small envs" do before do - @zone1 = FactoryGirl.create(:small_environment) + @zone1 = FactoryBot.create(:small_environment) @host1 = @zone1.ext_management_systems.first.hosts.first @zone1.reload - @zone2 = FactoryGirl.create(:small_environment) + @zone2 = FactoryBot.create(:small_environment) @host2 = @zone2.ext_management_systems.first.hosts.first @zone2.reload end @@ -43,9 +43,9 @@ it "returns the set of ems_clouds" do ems_clouds = [] - 2.times { ems_clouds << FactoryGirl.create(:ems_openstack, :zone => @zone) } - 2.times { ems_clouds << FactoryGirl.create(:ems_amazon, :zone => @zone) } - ems_infra = FactoryGirl.create(:ems_vmware, :zone => @zone) + 2.times { ems_clouds << FactoryBot.create(:ems_openstack, :zone => @zone) } + 2.times { ems_clouds << FactoryBot.create(:ems_amazon, :zone => @zone) } + ems_infra = FactoryBot.create(:ems_vmware, :zone => @zone) zone_clouds = @zone.ems_clouds expect(zone_clouds).to match_array(ems_clouds) @@ -54,20 +54,20 @@ end it "returns the set of availability_zones" do - openstack = FactoryGirl.create(:ems_openstack, :zone => @zone) + openstack = FactoryBot.create(:ems_openstack, :zone => @zone) azs = [] - 3.times { azs << FactoryGirl.create(:availability_zone, :ems_id => openstack.id) } + 3.times { azs << FactoryBot.create(:availability_zone, :ems_id => openstack.id) } expect(@zone.availability_zones).to match_array(azs) end end describe "#clustered_hosts" do - let(:zone) { FactoryGirl.create(:zone) } - let(:ems) { FactoryGirl.create(:ems_vmware, :zone => zone) } - let(:cluster) { FactoryGirl.create(:ems_cluster, :ext_management_system => ems)} - let(:host_with_cluster) { FactoryGirl.create(:host, :ext_management_system => ems, :ems_cluster => cluster) } - let(:host) { FactoryGirl.create(:host, :ext_management_system => ems) } + let(:zone) { FactoryBot.create(:zone) } + let(:ems) { FactoryBot.create(:ems_vmware, :zone => zone) } + let(:cluster) { FactoryBot.create(:ems_cluster, :ext_management_system => ems)} + let(:host_with_cluster) { FactoryBot.create(:host, :ext_management_system => ems, :ems_cluster => cluster) } + let(:host) { FactoryBot.create(:host, :ext_management_system => ems) } it "returns clustered hosts" do host @@ -78,11 +78,11 @@ end describe "#non_clustered_hosts" do - let(:zone) { FactoryGirl.create(:zone) } - let(:ems) { FactoryGirl.create(:ems_vmware, :zone => zone) } - let(:cluster) { FactoryGirl.create(:ems_cluster, :ext_management_system => ems)} - let(:host_with_cluster) { FactoryGirl.create(:host, :ext_management_system => ems, :ems_cluster => cluster) } - let(:host) { FactoryGirl.create(:host, :ext_management_system => ems) } + let(:zone) { FactoryBot.create(:zone) } + let(:ems) { FactoryBot.create(:ems_vmware, :zone => zone) } + let(:cluster) { FactoryBot.create(:ems_cluster, :ext_management_system => ems)} + let(:host_with_cluster) { FactoryBot.create(:host, :ext_management_system => ems, :ems_cluster => cluster) } + let(:host) { FactoryBot.create(:host, :ext_management_system => ems) } it "returns clustered hosts" do host @@ -162,7 +162,7 @@ end it "server when enabled" do - server = FactoryGirl.create(:miq_server, :has_active_cockpit_ws => true, :zone => @zone) + server = FactoryBot.create(:miq_server, :has_active_cockpit_ws => true, :zone => @zone) server.assign_role('cockpit_ws', 1) server.activate_roles('cockpit_ws') expect(@zone.remote_cockpit_ws_miq_server).to eq(server) @@ -174,9 +174,9 @@ it "queues a ntp reload for all active servers in the zone" do expect(MiqEnvironment::Command).to receive(:is_appliance?).and_return(true) expect(MiqEnvironment::Command).to receive(:is_container?).and_return(false) - zone = FactoryGirl.create(:zone) - server_1 = FactoryGirl.create(:miq_server, :zone => zone) - FactoryGirl.create(:miq_server, :zone => zone, :status => "stopped") + zone = FactoryBot.create(:zone) + server_1 = FactoryBot.create(:miq_server, :zone => zone) + FactoryBot.create(:miq_server, :zone => zone, :status => "stopped") zone.ntp_reload_queue @@ -203,8 +203,8 @@ end it "removes queued items on destroy" do - zone = FactoryGirl.create(:zone) - FactoryGirl.create(:miq_queue, :zone => zone.name) + zone = FactoryBot.create(:zone) + FactoryBot.create(:miq_queue, :zone => zone.name) expect(MiqQueue.where(:zone => zone.name).count).to eq(1) zone.destroy! expect(MiqQueue.where(:zone => zone.name).count).to eq(0) diff --git a/spec/shared/models/floating_ip.rb b/spec/shared/models/floating_ip.rb index c5c2d68712c..0e93ef2932b 100644 --- a/spec/shared/models/floating_ip.rb +++ b/spec/shared/models/floating_ip.rb @@ -1,8 +1,8 @@ shared_examples :floating_ip do |provider_name| it ".available" do - vm = FactoryGirl.create("vm_#{provider_name}") - _ip1 = FactoryGirl.create("floating_ip_#{provider_name}", :vm => vm) - ip2 = FactoryGirl.create("floating_ip_#{provider_name}") + vm = FactoryBot.create("vm_#{provider_name}") + _ip1 = FactoryBot.create("floating_ip_#{provider_name}", :vm => vm) + ip2 = FactoryBot.create("floating_ip_#{provider_name}") expect(described_class.available).to eq([ip2]) end diff --git a/spec/support/auth_helper.rb b/spec/support/auth_helper.rb index f954c89ce50..fb1206622f5 100644 --- a/spec/support/auth_helper.rb +++ b/spec/support/auth_helper.rb @@ -23,7 +23,7 @@ def stub_user(features:) allow_any_instance_of(described_class).to receive(:set_user_time_zone) features = "everything" if features == :all - login_as FactoryGirl.create(:user, :features => Array.wrap(features).map(&:to_s)), :stub_controller => true + login_as FactoryBot.create(:user, :features => Array.wrap(features).map(&:to_s)), :stub_controller => true end def stub_admin diff --git a/spec/support/automation_helper.rb b/spec/support/automation_helper.rb index ae9b8f6e8c4..cf2082ad553 100644 --- a/spec/support/automation_helper.rb +++ b/spec/support/automation_helper.rb @@ -17,7 +17,7 @@ def create_ae_model(attrs = {}) ae_fields ||= {'field1' => {:aetype => 'relationship', :datatype => 'string'}} ae_instances ||= {instance_name => {'field1' => {:value => 'hello world'}}} - FactoryGirl.create(:miq_ae_domain, :with_small_model, :with_instances, + FactoryBot.create(:miq_ae_domain, :with_small_model, :with_instances, attrs.merge('ae_fields' => ae_fields, 'ae_instances' => ae_instances)) end @@ -27,7 +27,7 @@ def create_state_ae_model(attrs = {}) ae_fields = {'field1' => {:aetype => 'state', :datatype => 'string'}} ae_instances = {instance_name => {'field1' => {:value => 'phases of matter'}}} - FactoryGirl.create(:miq_ae_domain, :with_small_model, :with_instances, + FactoryBot.create(:miq_ae_domain, :with_small_model, :with_instances, attrs.merge('ae_fields' => ae_fields, 'ae_instances' => ae_instances)) end @@ -44,7 +44,7 @@ def create_ae_model_with_method(attrs = {}) :data => method_script, :language => 'ruby', 'params' => method_params}} - FactoryGirl.create(:miq_ae_domain, :with_small_model, :with_instances, :with_methods, + FactoryBot.create(:miq_ae_domain, :with_small_model, :with_instances, :with_methods, attrs.merge('ae_fields' => ae_fields, 'ae_instances' => ae_instances, 'ae_methods' => ae_methods)) diff --git a/spec/support/chargeback_helper.rb b/spec/support/chargeback_helper.rb index e2d879998a4..a50d9714958 100644 --- a/spec/support/chargeback_helper.rb +++ b/spec/support/chargeback_helper.rb @@ -20,7 +20,7 @@ def add_metric_rollups_for(resources, range, step, metric_rollup_params, trait = metric_rollup_params[:resource_id] = resource.id metric_rollup_params[:resource_name] = resource.name params = [:metric_rollup_vm_hr, trait, metric_rollup_params].compact - resource.metric_rollups << FactoryGirl.create(*params) + resource.metric_rollups << FactoryBot.create(*params) end end end @@ -28,7 +28,7 @@ def add_metric_rollups_for(resources, range, step, metric_rollup_params, trait = def add_vim_performance_state_for(resources, range, step, state_data) range.step_value(step).each do |time| Array(resources).each do |resource| - FactoryGirl.create(:vim_performance_state, + FactoryBot.create(:vim_performance_state, :timestamp => time, :resource => resource, :state_data => state_data, diff --git a/spec/support/evm_spec_helper.rb b/spec/support/evm_spec_helper.rb index 9839b3f30c8..b71abfcadec 100644 --- a/spec/support/evm_spec_helper.rb +++ b/spec/support/evm_spec_helper.rb @@ -14,17 +14,17 @@ module EvmSpecHelper module EmsMetadataHelper def self.vmware_nested_folders(ems) - datacenters = FactoryGirl.create(:ems_folder, :name => 'Datacenters').tap { |x| x.parent = ems } - nested = FactoryGirl.create(:ems_folder, :name => 'nested').tap { |x| x.parent = datacenters } - testing = FactoryGirl.create(:ems_folder, :name => 'testing').tap { |x| x.parent = nested } - FactoryGirl.create(:datacenter).tap { |x| x.parent = testing } + datacenters = FactoryBot.create(:ems_folder, :name => 'Datacenters').tap { |x| x.parent = ems } + nested = FactoryBot.create(:ems_folder, :name => 'nested').tap { |x| x.parent = datacenters } + testing = FactoryBot.create(:ems_folder, :name => 'testing').tap { |x| x.parent = nested } + FactoryBot.create(:datacenter).tap { |x| x.parent = testing } end end def self.assign_embedded_ansible_role(miq_server = nil) MiqRegion.seed miq_server ||= local_miq_server - ServerRole.find_by(:name => "embedded_ansible") || FactoryGirl.create(:server_role, :name => 'embedded_ansible', :max_concurrent => 0) + ServerRole.find_by(:name => "embedded_ansible") || FactoryBot.create(:server_role, :name => 'embedded_ansible', :max_concurrent => 0) miq_server.assign_role('embedded_ansible').update_attributes(:active => true) end @@ -80,7 +80,7 @@ class << self def self.remote_miq_server(attrs = {}) Tenant.root_tenant || Tenant.create!(:use_config_for_attributes => false) - FactoryGirl.create(:miq_server, attrs) + FactoryBot.create(:miq_server, attrs) end def self.remote_guid_miq_server_zone diff --git a/spec/support/examples_group/shared_examples_for_ownership_mixin.rb b/spec/support/examples_group/shared_examples_for_ownership_mixin.rb index e5be43ef019..2119a2d0d3c 100644 --- a/spec/support/examples_group/shared_examples_for_ownership_mixin.rb +++ b/spec/support/examples_group/shared_examples_for_ownership_mixin.rb @@ -3,34 +3,34 @@ include Spec::Support::ArelHelper let(:user) do - FactoryGirl.create(:user, + FactoryBot.create(:user, :userid => "ownership_user", - :miq_groups => FactoryGirl.create_list(:miq_group, 1)) + :miq_groups => FactoryBot.create_list(:miq_group, 1)) end - let(:user2) { FactoryGirl.create(:user) } + let(:user2) { FactoryBot.create(:user) } let(:group) { user.current_group } - let(:group2) { FactoryGirl.create(:miq_group) } + let(:group2) { FactoryBot.create(:miq_group) } let(:factory) { described_class.to_s.underscore.to_sym } - let!(:in_ldap) { FactoryGirl.create(factory, :name => "in_ldap", :miq_group => group) } - let!(:not_in_ldap) { FactoryGirl.create(factory, :name => "not_in_ldap", :miq_group => group2) } - let!(:no_group) { FactoryGirl.create(factory, :name => "no_group") } - let!(:user_owned) { FactoryGirl.create(factory, :name => "user_owned", :evm_owner => user) } - let!(:user_owned2) { FactoryGirl.create(factory, :name => "user_owned2", :evm_owner => user2) } + let!(:in_ldap) { FactoryBot.create(factory, :name => "in_ldap", :miq_group => group) } + let!(:not_in_ldap) { FactoryBot.create(factory, :name => "not_in_ldap", :miq_group => group2) } + let!(:no_group) { FactoryBot.create(factory, :name => "no_group") } + let!(:user_owned) { FactoryBot.create(factory, :name => "user_owned", :evm_owner => user) } + let!(:user_owned2) { FactoryBot.create(factory, :name => "user_owned2", :evm_owner => user2) } describe ".user_or_group_owned" do let(:user_other_region) do other_region_id = ApplicationRecord.id_in_region(1, MiqRegion.my_region_number + 1) - FactoryGirl.create(:user, :id => other_region_id).tap do |u| + FactoryBot.create(:user, :id => other_region_id).tap do |u| u.update_column(:userid, user.userid) # Bypass validation for test purposes end end let(:group_other_region) do other_region_id = ApplicationRecord.id_in_region(1, MiqRegion.my_region_number + 1) - FactoryGirl.create(:miq_group, :id => other_region_id).tap do |g| + FactoryBot.create(:miq_group, :id => other_region_id).tap do |g| g.update_column(:description, group.description) # Bypass validation for test purposes end end diff --git a/spec/support/factory_girl_helper.rb b/spec/support/factory_bot_helper.rb similarity index 53% rename from spec/support/factory_girl_helper.rb rename to spec/support/factory_bot_helper.rb index f83678226c9..e3c38df6bab 100644 --- a/spec/support/factory_girl_helper.rb +++ b/spec/support/factory_bot_helper.rb @@ -17,11 +17,15 @@ def seq_padded_for_sorting(n) n.to_s.rjust(13, '0') # pad to 13 for max region size end -require 'factory_girl' -# in case we are running as an engine, the factories are located in the dummy app -FactoryGirl.definition_file_paths << 'spec/manageiq/spec/factories' -# also add factories from provider gems until miq codebase does not use any provider specific factories anymore +require 'factory_bot' +FactoryGirl = FactoryBot # Alias until all associated repositories are updated + +# In case we are running as an engine, the factories are located in the dummy app +FactoryBot.definition_file_paths << 'spec/manageiq/spec/factories' + +# Also, add factories from provider gems until miq codebase does not use any provider specific factories anymore Rails::Engine.subclasses.select { |e| e.name.starts_with?("ManageIQ::Providers") }.each do |engine| - FactoryGirl.definition_file_paths << File.join(engine.root, 'spec', 'factories') + FactoryBot.definition_file_paths << File.join(engine.root, 'spec', 'factories') end -FactoryGirl.find_definitions + +FactoryBot.find_definitions diff --git a/spec/support/job_proxy_dispatcher_helper.rb b/spec/support/job_proxy_dispatcher_helper.rb index a70a9fa8374..17dcade0bd5 100644 --- a/spec/support/job_proxy_dispatcher_helper.rb +++ b/spec/support/job_proxy_dispatcher_helper.rb @@ -2,19 +2,19 @@ module Spec module Support module JobProxyDispatcherHelper def build_entities(options = {}) - options = {:hosts => 2, :storages => 2, :vms => 3, :repo_vms => 3, :container_providers => [1, 2], :zone => FactoryGirl.create(:zone)}.merge(options) + options = {:hosts => 2, :storages => 2, :vms => 3, :repo_vms => 3, :container_providers => [1, 2], :zone => FactoryBot.create(:zone)}.merge(options) proxies = [] storages = [] options[:storages].times do |i| - storage = FactoryGirl.create(:storage, :name => "test_storage_#{i}", :store_type => "VMFS") + storage = FactoryBot.create(:storage, :name => "test_storage_#{i}", :store_type => "VMFS") storages << storage end - ems = FactoryGirl.create(:ems_vmware, :name => "ems1", :zone => options[:zone]) + ems = FactoryBot.create(:ems_vmware, :name => "ems1", :zone => options[:zone]) hosts = [] options[:hosts].times do |i| - host = FactoryGirl.create(:host, :name => "test_host_#{i}", :hostname => "test_host_#{i}") + host = FactoryBot.create(:host, :name => "test_host_#{i}", :hostname => "test_host_#{i}") max = i > storages.length ? storages.length : i host.storages = storages[0..max] host.ext_management_system = ems @@ -24,7 +24,7 @@ def build_entities(options = {}) vms = [] options[:vms].times do |i| - vm = FactoryGirl.create(:vm_vmware, :name => "test_vm_#{i}", :location => "abc/abc.vmx") + vm = FactoryBot.create(:vm_vmware, :name => "test_vm_#{i}", :location => "abc/abc.vmx") vm.storage = storages[(i % options[:storages])] vm.host = hosts[(i % options[:hosts])] vm.ext_management_system = ems @@ -34,12 +34,12 @@ def build_entities(options = {}) repo_vms = [] - repo_storage = FactoryGirl.create(:storage, :name => "test_repo_storage", :store_type => "VMFS") + repo_storage = FactoryBot.create(:storage, :name => "test_repo_storage", :store_type => "VMFS") repo_storage.hosts = [] repo_storage.save options[:repo_vms].times do |i| - vm = FactoryGirl.create(:vm_vmware, :name => "test_repo_vm_#{i}", :location => "abc/abc.vmx") + vm = FactoryBot.create(:vm_vmware, :name => "test_repo_vm_#{i}", :location => "abc/abc.vmx") vm.storage = repo_storage vm.host = nil vm.save @@ -48,12 +48,12 @@ def build_entities(options = {}) container_providers = [] options[:container_providers].each_with_index do |images_count, i| - ems_openshift = FactoryGirl.create(:ems_openshift, :name => "test_container_provider_#{i}", :zone => options[:zone]) + ems_openshift = FactoryBot.create(:ems_openshift, :name => "test_container_provider_#{i}", :zone => options[:zone]) container_providers << ems_openshift container_image_classes = ContainerImage.descendants.append(ContainerImage) images_count.times do |idx| container_image_classes.each do |cic| - FactoryGirl.create(:container_image, + FactoryBot.create(:container_image, :name => "test_container_images_#{idx}", :ems_id => ems_openshift.id, :type => cic.name) diff --git a/spec/support/missing_factory_helper.rb b/spec/support/missing_factory_helper.rb index 5c6385d03d3..2aa5b5ea094 100644 --- a/spec/support/missing_factory_helper.rb +++ b/spec/support/missing_factory_helper.rb @@ -1,4 +1,4 @@ -# HACK: Allow calling FactoryGirl.create or FactoryGirl.build on anything. +# HACK: Allow calling FactoryBot.create or FactoryBot.build on anything. module Spec module Support module MissingFactoryHelper @@ -23,11 +23,11 @@ def factory_exists?(factory) def registered_factory_symbols @registered_factory_symbols ||= begin require 'set' - FactoryGirl.factories.collect { |i| i.name.to_sym }.to_set + FactoryBot.factories.collect { |i| i.name.to_sym }.to_set end end end end end -FactoryGirl.singleton_class.prepend(Spec::Support::MissingFactoryHelper) +FactoryBot.singleton_class.prepend(Spec::Support::MissingFactoryHelper) diff --git a/spec/support/quota_helper.rb b/spec/support/quota_helper.rb index 911ae2dd2f5..86fdac10523 100644 --- a/spec/support/quota_helper.rb +++ b/spec/support/quota_helper.rb @@ -33,18 +33,18 @@ def create_hardware @disk_size = 1_000_000 @num_cpu = 0 - @hw1 = FactoryGirl.create(:hardware, :cpu_sockets => @num_cpu, :memory_mb => @ram_size) - @hw2 = FactoryGirl.create(:hardware, :cpu_sockets => @num_cpu, :memory_mb => @ram_size) - @hw3 = FactoryGirl.create(:hardware, :cpu_sockets => @num_cpu, :memory_mb => @ram_size) - @hw4 = FactoryGirl.create(:hardware, :cpu_sockets => @num_cpu, :memory_mb => @ram_size) + @hw1 = FactoryBot.create(:hardware, :cpu_sockets => @num_cpu, :memory_mb => @ram_size) + @hw2 = FactoryBot.create(:hardware, :cpu_sockets => @num_cpu, :memory_mb => @ram_size) + @hw3 = FactoryBot.create(:hardware, :cpu_sockets => @num_cpu, :memory_mb => @ram_size) + @hw4 = FactoryBot.create(:hardware, :cpu_sockets => @num_cpu, :memory_mb => @ram_size) create_disks end def create_disks - @disk1 = FactoryGirl.create(:disk, :device_type => "disk", :size => @disk_size, :hardware_id => @hw1.id) - @disk2 = FactoryGirl.create(:disk, :device_type => "disk", :size => @disk_size, :hardware_id => @hw2.id) - @disk3 = FactoryGirl.create(:disk, :device_type => "disk", :size => @disk_size, :hardware_id => @hw3.id) - @disk3 = FactoryGirl.create(:disk, :device_type => "disk", :size => @disk_size, :hardware_id => @hw4.id) + @disk1 = FactoryBot.create(:disk, :device_type => "disk", :size => @disk_size, :hardware_id => @hw1.id) + @disk2 = FactoryBot.create(:disk, :device_type => "disk", :size => @disk_size, :hardware_id => @hw2.id) + @disk3 = FactoryBot.create(:disk, :device_type => "disk", :size => @disk_size, :hardware_id => @hw3.id) + @disk3 = FactoryBot.create(:disk, :device_type => "disk", :size => @disk_size, :hardware_id => @hw4.id) end def create_tenant_quota @@ -56,23 +56,23 @@ def create_tenant_quota end def create_vmware_vms - @active_vm = FactoryGirl.create(:vm_vmware, + @active_vm = FactoryBot.create(:vm_vmware, :miq_group_id => @miq_group.id, :evm_owner_id => @user.id, :ems_id => @ems.id, :storage_id => @storage.id, :hardware => @hw1, :tenant => @tenant) - @archived_vm = FactoryGirl.create(:vm_vmware, + @archived_vm = FactoryBot.create(:vm_vmware, :miq_group_id => @miq_group.id, :evm_owner_id => @user.id, :hardware => @hw2) - @orphaned_vm = FactoryGirl.create(:vm_vmware, + @orphaned_vm = FactoryBot.create(:vm_vmware, :miq_group_id => @miq_group.id, :evm_owner_id => @user.id, :storage_id => @storage.id, :hardware => @hw3) - @retired_vm = FactoryGirl.create(:vm_vmware, + @retired_vm = FactoryBot.create(:vm_vmware, :miq_group_id => @miq_group.id, :evm_owner_id => @user.id, :retired => true, @@ -80,20 +80,20 @@ def create_vmware_vms end def create_google_vms - @active_vm = FactoryGirl.create(:vm_google, + @active_vm = FactoryBot.create(:vm_google, :miq_group_id => @miq_group.id, :evm_owner_id => @user.id, :ext_management_system => @ems, :tenant => @tenant) - @archived_vm = FactoryGirl.create(:vm_google, + @archived_vm = FactoryBot.create(:vm_google, :miq_group_id => @miq_group.id, :evm_owner_id => @user.id, :tenant => @tenant) - @orphaned_vm = FactoryGirl.create(:vm_google, + @orphaned_vm = FactoryBot.create(:vm_google, :miq_group_id => @miq_group.id, :evm_owner_id => @user.id, :tenant => @tenant) - @retired_vm = FactoryGirl.create(:vm_google, + @retired_vm = FactoryBot.create(:vm_google, :miq_group_id => @miq_group.id, :evm_owner_id => @user.id, :retired => true, @@ -101,7 +101,7 @@ def create_google_vms end def create_request(prov_options) - @miq_provision_request = FactoryGirl.create(:miq_provision_request, + @miq_provision_request = FactoryBot.create(:miq_provision_request, :requester => @user, :source => @vm_template, :options => prov_options) @@ -117,28 +117,28 @@ def vmware_requested_quota_values end def vmware_template - @ems = FactoryGirl.create(:ems_vmware) - FactoryGirl.create(:template_vmware, - :hardware => FactoryGirl.create(:hardware, :cpu1x2, :memory_mb => 512)) + @ems = FactoryBot.create(:ems_vmware) + FactoryBot.create(:template_vmware, + :hardware => FactoryBot.create(:hardware, :cpu1x2, :memory_mb => 512)) end def vmware_model @vm_template = vmware_template - @storage = FactoryGirl.create(:storage_nfs) + @storage = FactoryBot.create(:storage_nfs) create_request(vmware_requested_quota_values) create_hardware create_vmware_vms end def vmware_reconfigure_model - @ems = FactoryGirl.create(:ems_vmware) - @storage = FactoryGirl.create(:storage_nfs) + @ems = FactoryBot.create(:ems_vmware) + @storage = FactoryBot.create(:storage_nfs) create_hardware create_vmware_vms - @reconfigure_request = FactoryGirl.create(:vm_reconfigure_request, :requester => @user) - @vm_hardware = FactoryGirl.build(:hardware, :virtual_hw_version => "07", :cpu_total_cores => 2,\ + @reconfigure_request = FactoryBot.create(:vm_reconfigure_request, :requester => @user) + @vm_hardware = FactoryBot.build(:hardware, :virtual_hw_version => "07", :cpu_total_cores => 2,\ :memory_mb => 4096, :cpu_sockets => 2, :cpu_cores_per_socket => 1) - @vm_vmware = FactoryGirl.create(:vm_vmware, :hardware => @vm_hardware) + @vm_vmware = FactoryBot.create(:vm_vmware, :hardware => @vm_hardware) @vm_vmware.update_attributes(:ems_id => @ems.id) end @@ -155,14 +155,14 @@ def google_requested_quota_values end def google_template - @ems = FactoryGirl.create(:ems_google_with_authentication, - :availability_zones => [FactoryGirl.create(:availability_zone_google)]) - FactoryGirl.create(:template_google, :ext_management_system => @ems) + @ems = FactoryBot.create(:ems_google_with_authentication, + :availability_zones => [FactoryBot.create(:availability_zone_google)]) + FactoryBot.create(:template_google, :ext_management_system => @ems) end def google_model @vm_template = google_template - m2_small_flavor = FactoryGirl.create(:flavor_google, :ems_id => @ems.id, :cloud_subnet_required => false, + m2_small_flavor = FactoryBot.create(:flavor_google, :ems_id => @ems.id, :cloud_subnet_required => false, :cpus => 4, :cpu_cores => 1, :memory => 1024) create_request(:number_of_vms => 1, :owner_email => 'user@example.com', :src_vm_id => @vm_template.id, @@ -173,7 +173,7 @@ def google_model end def generic_template - FactoryGirl.create(:service_template, + FactoryBot.create(:service_template, :name => 'generic', :service_type => 'atomic', :prov_type => 'generic') @@ -185,7 +185,7 @@ def build_generic_service_item end def build_generic_ansible_tower_service_item - @service_template = FactoryGirl.create(:service_template, + @service_template = FactoryBot.create(:service_template, :name => 'generic_ansible_tower', :service_type => 'atomic', :prov_type => 'generic_ansible_tower') @@ -203,7 +203,7 @@ def build_vmware_service_item end def build_google_service_item - @small_flavor = FactoryGirl.create(:flavor_google, :ems_id => @ems.id, :cloud_subnet_required => false, + @small_flavor = FactoryBot.create(:flavor_google, :ems_id => @ems.id, :cloud_subnet_required => false, :cpus => 1, :cpu_cores => 1, :memory => 1024) options = {:src_vm_id => @vm_template.id, :requester_id => @user.id}.merge(google_requested_quota_values) @@ -222,7 +222,7 @@ def create_service_bundle(items) end def user_setup - @user = FactoryGirl.create(:user_with_group) + @user = FactoryBot.create(:user_with_group) @miq_group = @user.current_group @tenant = @miq_group.tenant end diff --git a/spec/support/service_template_helper.rb b/spec/support/service_template_helper.rb index 2906604cdd7..3521788455b 100644 --- a/spec/support/service_template_helper.rb +++ b/spec/support/service_template_helper.rb @@ -14,7 +14,7 @@ def build_all_atomics(hash) hash.each do |name, value| next unless value[:type] == "atomic" - item = FactoryGirl.create(:service_template, :name => name, + item = FactoryBot.create(:service_template, :name => name, :options => {:dialog => {}}, :service_type => 'atomic') item.update_attributes(:prov_type => value[:prov_type]) if value[:prov_type].present? @@ -22,7 +22,7 @@ def build_all_atomics(hash) options = value[:request] options ||= {} options[:dialog] = {} - mprt = FactoryGirl.create(:miq_provision_request_template, + mprt = FactoryBot.create(:miq_provision_request_template, :requester => get_user(options), :src_vm_id => options[:src_vm_id], :options => options) @@ -68,7 +68,7 @@ def add_item(item) end def build_a_composite(name, hash) - item = FactoryGirl.create(:service_template, :name => name, + item = FactoryBot.create(:service_template, :name => name, :options => {:dialog => {}}, :service_type => 'composite') properties = hash[name] @@ -94,7 +94,7 @@ def build_service_template_request(root_st_name, user, dialog_options = {}) root = ServiceTemplate.find_by(:name => root_st_name) return nil unless root options = {:src_id => root.id, :target_name => "barney"}.merge(dialog_options) - FactoryGirl.create(:service_template_provision_request, + FactoryBot.create(:service_template_provision_request, :description => 'Service Request', :source_type => 'ServiceTemplate', :type => 'ServiceTemplateProvisionRequest', @@ -117,9 +117,9 @@ def request_stubs def build_small_environment @miq_server = EvmSpecHelper.local_miq_server - @ems = FactoryGirl.create(:ems_vmware_with_authentication) - @host1 = FactoryGirl.create(:host_vmware, :ems_id => @ems.id) - @src_vm = FactoryGirl.create(:vm_vmware, :host => @host1, + @ems = FactoryBot.create(:ems_vmware_with_authentication) + @host1 = FactoryBot.create(:host_vmware, :ems_id => @ems.id) + @src_vm = FactoryBot.create(:vm_vmware, :host => @host1, :ems_id => @ems.id, :name => "barney") end @@ -132,7 +132,7 @@ def service_template_stubs def user_helper allow_any_instance_of(User).to receive(:role).and_return("admin") - @user = FactoryGirl.create(:user_with_group, :name => 'Wilma', :userid => 'wilma') + @user = FactoryBot.create(:user_with_group, :name => 'Wilma', :userid => 'wilma') end end end diff --git a/spec/tools/copy_reports_structure_spec.rb b/spec/tools/copy_reports_structure_spec.rb index 9a38c993ce9..273bdb341a9 100644 --- a/spec/tools/copy_reports_structure_spec.rb +++ b/spec/tools/copy_reports_structure_spec.rb @@ -5,9 +5,9 @@ describe ReportStructure do let(:group_name) { "SourceGroup" } let(:settings) { {"reports_menus" => [["Configuration Management", ["Virtual Machines", ["Vendor and Type"]]]]} } - let(:role) { FactoryGirl.create(:miq_user_role) } - let(:source_group) { FactoryGirl.create(:miq_group, :settings => settings) } - let(:destination_group) { FactoryGirl.create(:miq_group, :miq_user_role => role) } + let(:role) { FactoryBot.create(:miq_user_role) } + let(:source_group) { FactoryBot.create(:miq_group, :settings => settings) } + let(:destination_group) { FactoryBot.create(:miq_group, :miq_user_role => role) } context "copy reports structure" do describe ".duplicate_for_group" do @@ -33,7 +33,7 @@ describe ".duplicate_for_role" do before do - @destination_group2 = FactoryGirl.create(:miq_group, :miq_user_role => destination_group.miq_user_role) + @destination_group2 = FactoryBot.create(:miq_group, :miq_user_role => destination_group.miq_user_role) end it "copies reports structure from one group to role (to all groups having that role)" do @@ -94,4 +94,4 @@ end end end -end \ No newline at end of file +end diff --git a/spec/tools/environment_builders/openstack/tests/interaction_methods_spec.rb b/spec/tools/environment_builders/openstack/tests/interaction_methods_spec.rb index a0c487eb1c5..9ac75c632e2 100644 --- a/spec/tools/environment_builders/openstack/tests/interaction_methods_spec.rb +++ b/spec/tools/environment_builders/openstack/tests/interaction_methods_spec.rb @@ -39,13 +39,13 @@ } end - let(:host1) { FactoryGirl.create(:host, host1_data) } - let(:host2) { FactoryGirl.create(:host, host2_data) } - let(:host3) { FactoryGirl.create(:host, host3_data) } - let(:host4) { FactoryGirl.create(:host, host4_data) } - let(:host5) { FactoryGirl.create(:host, host5_data) } - let(:host6) { FactoryGirl.create(:host, host6_data) } - let(:host7) { FactoryGirl.create(:host, host7_data) } + let(:host1) { FactoryBot.create(:host, host1_data) } + let(:host2) { FactoryBot.create(:host, host2_data) } + let(:host3) { FactoryBot.create(:host, host3_data) } + let(:host4) { FactoryBot.create(:host, host4_data) } + let(:host5) { FactoryBot.create(:host, host5_data) } + let(:host6) { FactoryBot.create(:host, host6_data) } + let(:host7) { FactoryBot.create(:host, host7_data) } let(:data) do [ diff --git a/tools/copy_reports_structure.rb b/tools/copy_reports_structure.rb index c139c78faf5..1c548a7cdac 100644 --- a/tools/copy_reports_structure.rb +++ b/tools/copy_reports_structure.rb @@ -40,4 +40,4 @@ ReportStructure.reset_for_role(opts[:reset_role], opts[:dry_run]) if opts[:reset_role_given] end -puts "**** Dry run, no updates have been made" if opts[:dry_run] \ No newline at end of file +puts "**** Dry run, no updates have been made" if opts[:dry_run] diff --git a/tools/radar/rollup_radar_mixin_spec.rb b/tools/radar/rollup_radar_mixin_spec.rb index 0c59e865312..a73576e37de 100644 --- a/tools/radar/rollup_radar_mixin_spec.rb +++ b/tools/radar/rollup_radar_mixin_spec.rb @@ -3,25 +3,25 @@ describe RollupRadarMixin do include RollupRadarMixin - let(:ems) { FactoryGirl.create(:ems_openshift, :name => 'OpenShiftProvider') } + let(:ems) { FactoryBot.create(:ems_openshift, :name => 'OpenShiftProvider') } let(:container_project) do - FactoryGirl.create(:container_project, :ext_management_system => ems) + FactoryBot.create(:container_project, :ext_management_system => ems) end let(:container_group) do - FactoryGirl.create(:container_group, :container_project => container_project, + FactoryBot.create(:container_group, :container_project => container_project, :ext_management_system => ems) end let(:container_image_a) do - FactoryGirl.create(:container_image, + FactoryBot.create(:container_image, :ext_management_system => ems, :custom_attributes => [custom_attribute_a]) end let(:container_a) do - FactoryGirl.create(:container, + FactoryBot.create(:container, :name => "A", :container_group => container_group, :container_image => container_image_a, @@ -29,14 +29,14 @@ end let(:custom_attribute_a) do - FactoryGirl.create(:custom_attribute, + FactoryBot.create(:custom_attribute, :name => 'com.redhat.component', :value => 'EAP7', :section => 'docker_labels') end let(:container_b) do - FactoryGirl.create(:container, + FactoryBot.create(:container, :name => "B", :container_group => container_group, :container_image => container_image_b, @@ -44,13 +44,13 @@ end let(:container_image_b) do - FactoryGirl.create(:container_image, + FactoryBot.create(:container_image, :ext_management_system => ems, :custom_attributes => [custom_attribute_b]) end let(:custom_attribute_b) do - FactoryGirl.create(:custom_attribute, + FactoryBot.create(:custom_attribute, :name => 'com.redhat.component', :value => 'EAP7', :section => 'docker_labels') @@ -68,7 +68,7 @@ def add_metric_for(resources, timestamp) metric_rollup_params[:resource_id] = resource.id metric_rollup_params[:resource_name] = resource.name params = [:metric, metric_rollup_params].compact - resource.metrics << FactoryGirl.create(*params) + resource.metrics << FactoryBot.create(*params) end end @@ -270,7 +270,7 @@ def check_results(results, expected) end let(:custom_attribute_a) do - FactoryGirl.create(:custom_attribute, + FactoryBot.create(:custom_attribute, :name => 'com.redhat.component_different', :value => 'EAP7', :section => 'docker_labels')