Skip to content

Commit d468ce6

Browse files
committed
Fixes issue while adding alert with event threshold
1 parent 1a9995f commit d468ce6

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

app/views/miq_alert/_alert_builtin_exp.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
edit[:new][:expression][:options][:event_types]),
1313
:class => "selectpicker")
1414
:javascript
15-
miqInitSelectPicker f();
15+
miqInitSelectPicker();
1616
miqSelectPickerEvent('event_types', '#{url}', {beforeSend: true, complete: true})
1717
- when :time_threshold
1818
%label.control-label.col-md-2

spec/controllers/miq_alert_controller_spec.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,44 @@
154154
expect(assigns(:flash_array)).to be_nil
155155
end
156156

157+
it "forces Event to check to be present for eval_method - Event threshold" do
158+
@miq_alert = FactoryBot.create(
159+
:miq_alert,
160+
:db => "Host",
161+
:options => {:notifications => {:email => {:to => ["[email protected]"]}}},
162+
:expression => {:eval_method => 'event_threshold', :mode => "internal", :options => {:event_types => []}},
163+
:severity => 'info'
164+
)
165+
166+
edit = {
167+
:new => {
168+
:expression => {:eval_method => 'event_threshold', :mode => "internal", :options => {:event_types => []}},
169+
}
170+
}
171+
controller.instance_variable_set(:@edit, edit)
172+
controller.send(:alert_valid_record?, @miq_alert)
173+
expect(assigns(:flash_array).first[:message]).to(match("Event to Check is required"))
174+
end
175+
176+
it "does not force Event to check to be present for eval_method - Event threshold" do
177+
@miq_alert = FactoryBot.create(
178+
:miq_alert,
179+
:db => "Host",
180+
:options => {:notifications => {:email => {:to => ["[email protected]"]}}},
181+
:expression => {:eval_method => 'event_threshold', :mode => "internal", :options => {:event_types => ["PowerOnVM_Task_Complete"]}},
182+
:severity => 'info'
183+
)
184+
185+
edit = {
186+
:new => {
187+
:expression => {:eval_method => 'event_threshold', :mode => "internal", :options => {:event_types => ["PowerOnVM_Task_Complete"]}},
188+
}
189+
}
190+
controller.instance_variable_set(:@edit, edit)
191+
controller.send(:alert_valid_record?, @miq_alert)
192+
expect(assigns(:flash_array)).to(be_nil)
193+
end
194+
157195
context 'not choosing Send an E-mail option while adding new Alert' do
158196
let(:alert) do
159197
FactoryBot.create(:miq_alert,

0 commit comments

Comments
 (0)