Skip to content

Commit

Permalink
Remove duplicate resource_action_workflow and simplify stubbing
Browse files Browse the repository at this point in the history
The inner variable was shadowing the outer one, `hash` was poorly
named and the setup can be moved into one `before` block.
  • Loading branch information
carbonin committed Jun 20, 2018
1 parent 08bf0f3 commit 7a64f16
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions spec/models/service_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -814,21 +814,23 @@
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(:hash) { {:target => service_template, :initiator => 'control'} }
let(:resource_action_options) { {:target => service_template, :initiator => 'control'} }
let(:miq_request) { FactoryGirl.create(:service_template_provision_request) }
let(:resource_action_workflow) { ResourceActionWorkflow.new({}, user, resource_action) }
let!(:resource_action_workflow) { ResourceActionWorkflow.new({}, user, resource_action, resource_action_options) }

before do
allow(ResourceActionWorkflow).to(receive(:new).and_return(resource_action_workflow))
end

it "success no optional args" do
expect(ResourceActionWorkflow).to(receive(:new).and_return(resource_action_workflow))
expect(resource_action_workflow).to receive(:submit_request).and_return(miq_request)

expect(service_template.order(user)).to eq(miq_request)
end

it "successfully scheduled" do
EvmSpecHelper.local_miq_server
expect(ResourceActionWorkflow).to(receive(:new).and_return(resource_action_workflow))
expect(resource_action_workflow).to receive(:validate_dialog).and_return(nil)
expect(resource_action_workflow).to receive(:validate_dialog).and_return([])

result = service_template.order(user, {}, {}, Time.now.utc.to_s)

Expand All @@ -844,11 +846,9 @@
context "#provision_request" do
let(:arg1) { {'ordered_by' => 'fred'} }
let(:arg2) { {:initiator => 'control'} }
let(:resource_action_workflow) { ResourceActionWorkflow.new({}, user, resource_action, hash) }

it "provision's a service template without errors" do
expect(ResourceActionWorkflow).to(receive(:new).with({}, user, resource_action, hash).and_return(resource_action_workflow))
expect(resource_action_workflow).to receive(:validate_dialog).and_return(nil)
expect(resource_action_workflow).to receive(:validate_dialog).and_return([])
expect(resource_action_workflow).to receive(:make_request).and_return(miq_request)
expect(resource_action_workflow).to receive(:set_value).with('ordered_by', 'fred')
expect(resource_action_workflow).to receive(:request_options=).with(:initiator => 'control')
Expand All @@ -857,7 +857,6 @@
end

it "provision's a service template with errors" do
expect(ResourceActionWorkflow).to(receive(:new).with({}, user, resource_action, hash).and_return(resource_action_workflow))
expect(resource_action_workflow).to receive(:validate_dialog).and_return(%w(Error1 Error2))
expect(resource_action_workflow).to receive(:set_value).with('ordered_by', 'fred')
expect(resource_action_workflow).to receive(:request_options=).with(:initiator => 'control')
Expand Down

0 comments on commit 7a64f16

Please sign in to comment.