Skip to content

Commit

Permalink
Merge pull request ManageIQ#17696 from bdunne/ServiceTemplate_Schedul…
Browse files Browse the repository at this point in the history
…e_name_validation

Ensure MiqSchedule#name is unique for ServiceTemplate orders
  • Loading branch information
kbrock authored Jul 13, 2018
2 parents eb9b52a + 0b358b8 commit d101c79
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/models/service_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ def order(user_or_id, options = nil, request_options = nil, schedule_time = nil)
return {:errors => errors} unless errors.blank?

schedule = MiqSchedule.create!(
:name => "Order #{self.class.name} #{id}",
:description => "Order #{self.class.name} #{id}",
:name => "Order #{self.class.name} #{id} at #{time}",
:description => "Order #{self.class.name} #{id} at #{time}",
:sched_action => {:args => [user.id, options, request_options], :method => "queue_order"},
:resource_id => id,
:towhat => "ServiceTemplate",
Expand Down
15 changes: 13 additions & 2 deletions spec/models/service_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -832,17 +832,28 @@
EvmSpecHelper.local_miq_server
expect(resource_action_workflow).to receive(:validate_dialog).and_return([])

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

expect(result.keys).to eq([:schedule]) # No errors
expect(result[:schedule]).to have_attributes(
:name => "Order ServiceTemplate #{service_template.id}",
:name => "Order ServiceTemplate #{service_template.id} at #{time}",
:sched_action => {:args => [user.id, {}, {}], :method => "queue_order"},
:towhat => "ServiceTemplate",
:resource_id => service_template.id
)
end

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

service_template.order(user, {}, {}, Time.zone.now.utc.to_s)
service_template.order(user, {}, {}, (Time.zone.now + 1.hour).utc.to_s)

expect(service_template.miq_schedules.length).to eq(2)
end

context "#provision_request" do
let(:arg1) { {'ordered_by' => 'fred'} }
context "with submit_workflow" do
Expand Down

0 comments on commit d101c79

Please sign in to comment.