Skip to content

Commit 33d2d9b

Browse files
committed
Move prov_field_changed test into own describe
1 parent fe977de commit 33d2d9b

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

spec/controllers/application_controller/miq_request_methods_spec.rb

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,39 @@
3030
partial = controller.send(:dialog_partial_for_workflow)
3131
expect(partial).to eq('prov_configured_system_foreman_dialog')
3232
end
33+
end
34+
35+
describe '#prov_field_changed' do
36+
before { stub_user(:features => %w[miq_request_edit]) }
37+
38+
context "with an InfraManager provision workflow" do
39+
let(:wf) { FactoryBot.create(:miq_provision_virt_workflow) }
40+
let(:ems) { FactoryBot.create(:ems_infra) }
41+
let(:datacenter) { FactoryBot.create(:datacenter, :ext_management_system => ems, :name => 'dcname') }
42+
let(:ems_folder) { FactoryBot.create(:ems_folder, :ext_management_system => ems) }
43+
let(:vm2) { FactoryBot.create(:vm_infra, :ext_management_system => ems) }
44+
let(:template) { FactoryBot.create(:template_infra, :ext_management_system => ems) }
45+
46+
it "clears the request datacenter name field when the source VM is changed" do
47+
wf.instance_variable_set(:@dialogs, :dialogs => {:environment => {:fields => {:placement_dc_name => {:values => {datacenter.id.to_s => datacenter.name}}}}})
48+
49+
controller.instance_variable_set(:@edit, :wf => wf, :new => {:src_vm_id => template.id.to_s})
50+
controller.instance_variable_set(:@last_vm_id, vm2.id)
51+
controller.params = {'service__src_vm_id' => template.id, :id => "new", :controller => "miq_request"}
52+
wf.instance_variable_set(:@values, :placement_dc_name=>[datacenter.id.to_s, datacenter.name])
3353

34-
it "clears the request datacenter name field when the source VM is changed" do
35-
datacenter = FactoryBot.create(:datacenter, :name => 'dcname')
36-
ems_folder = FactoryBot.create(:ems_folder)
37-
ems = FactoryBot.create(:ems_vmware)
38-
template = FactoryBot.create(:template_vmware)
39-
vm2 = FactoryBot.create(:vm_vmware)
40-
datacenter.ext_management_system = ems
41-
ems_folder.ext_management_system = ems
42-
@wf.instance_variable_set(:@dialogs, :dialogs => {:environment => {:fields => {:placement_dc_name => {:values => {datacenter.id.to_s => datacenter.name}}}}})
43-
controller.instance_variable_set(:@edit, :wf => @wf, :new => {:src_vm_id => template.id.to_s})
44-
controller.instance_variable_set(:@last_vm_id, vm2.id)
45-
controller.params = {'service__src_vm_id' => template.id, :id => "new", :controller => "miq_request"}
46-
@wf.instance_variable_set(:@values, :placement_dc_name=>[datacenter.id.to_s, datacenter.name])
47-
edit = {:wf => @wf, :new => {:placement_dc_name => [datacenter.id, datacenter.name]}}
48-
@wf.instance_variable_set(:@edit, edit)
49-
allow(controller).to receive(:load_edit).and_return(true)
50-
allow(controller).to receive(:render).and_return(true)
51-
allow(@wf).to receive(:get_field).and_return(:values => {:placement_dc_name=>[datacenter.id.to_s, datacenter.name]})
52-
controller.send(:prov_field_changed)
53-
values = @wf.instance_variable_get(:@values)
54-
expect(values.to_s).to_not include('dcname')
54+
edit = {:wf => wf, :new => {:placement_dc_name => [datacenter.id, datacenter.name]}}
55+
wf.instance_variable_set(:@edit, edit)
56+
57+
allow(controller).to receive(:load_edit).and_return(true)
58+
allow(controller).to receive(:render).and_return(true)
59+
allow(wf).to receive(:get_field).and_return(:values => {:placement_dc_name=>[datacenter.id.to_s, datacenter.name]})
60+
61+
controller.send(:prov_field_changed)
62+
63+
values = wf.instance_variable_get(:@values)
64+
expect(values.to_s).to_not include('dcname')
65+
end
5566
end
5667
end
5768

0 commit comments

Comments
 (0)