From c3a331db747cb4de1430a6e6e5a14f59db8274bf Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Fri, 5 Oct 2018 11:33:45 -0700 Subject: [PATCH] spec that tests for VM validity when a plan is being edited --- spec/models/transformation_mapping_spec.rb | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/models/transformation_mapping_spec.rb b/spec/models/transformation_mapping_spec.rb index de7be5c90a6..a62a78017fb 100644 --- a/spec/models/transformation_mapping_spec.rb +++ b/spec/models/transformation_mapping_spec.rb @@ -31,6 +31,7 @@ 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) } @@ -126,6 +127,35 @@ end end + 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) + + FactoryGirl.create( + :service_resource, + :resource => vm2, + :service_template => service_template, + :status => "Active" + ) + result = mapping.search_vms_and_validate(['name' => vm2.name], service_template.id.to_s) + expect(result['valid'].first.reason).to match(/ok/) + 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) + + FactoryGirl.create( + :service_resource, + :resource => vm2, + :service_template => service_template, + :status => "Active" + ) + result = mapping.search_vms_and_validate(['name' => vm2.name], service_template2.id.to_s) + expect(result['invalid'].first.reason).to match(/in_other_plan/) + end + end + context 'without VM list' do it 'returns valid vms' do result = mapping.search_vms_and_validate