From 01626ae43cc95b8200b3f1c1369ad6c2eed1142c Mon Sep 17 00:00:00 2001 From: Mooli Tayer Date: Thu, 29 Jun 2017 11:22:53 +0300 Subject: [PATCH] Fail explicitly when MAS creation fails. --- app/models/miq_alert.rb | 2 +- spec/models/miq_alert_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/miq_alert.rb b/app/models/miq_alert.rb index 2097fdc48a6..8a3e731f966 100644 --- a/app/models/miq_alert.rb +++ b/app/models/miq_alert.rb @@ -225,7 +225,7 @@ def add_status_post_evaluate(target, result, event) status.event_ems_ref = ems_ref unless ems_ref.blank? status.resolved = resolved status.evaluated_on = Time.now.utc - status.save + status.save! miq_alert_statuses << status end diff --git a/spec/models/miq_alert_spec.rb b/spec/models/miq_alert_spec.rb index f4f6685268a..3f17b7e7396 100644 --- a/spec/models/miq_alert_spec.rb +++ b/spec/models/miq_alert_spec.rb @@ -190,6 +190,15 @@ expect(mas.severity).to eq(nil) end + it "raises an exception when miq_alert_status creation fails" do + expect do + @alert.evaluate( + [@vm.class.base_class.name, @vm.id], + :ems_event => FactoryGirl.create(:ems_event, :full_data => {:severity => 'undefined'}) + ) + end.to raise_error(ActiveRecord::RecordInvalid) + end + it "miq_alert_status.url = ems_event.full_data.url if present" do @alert.evaluate( [@vm.class.base_class.name, @vm.id],