Skip to content

Commit

Permalink
Merge pull request #5056 from hstastna/Alert_creation_fail_nil
Browse files Browse the repository at this point in the history
Fix failing creating new Alert in Control > Explorer

(cherry picked from commit 8615b74)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1654896
  • Loading branch information
mzazrivec authored and simaishi committed Dec 10, 2018
1 parent e563b6d commit 8fb6d10
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
7 changes: 3 additions & 4 deletions app/controllers/miq_policy_controller/alerts.rb
Expand Up @@ -651,12 +651,11 @@ def alert_valid_record?(alert)
add_flash(_("At least one E-mail recipient must be configured"), :error)
elsif alert.options[:notifications][:email][:to].find { |i| !i.to_s.email? }
add_flash(_("One of e-mail addresses 'To' is not valid"), :error)
elsif alert.options[:notifications][:email][:from].present? &&
!alert.options[:notifications][:email][:from].email?
add_flash(_("E-mail address 'From' is not valid"), :error)
end
end
if alert.options[:notifications][:email][:from].present? &&
!alert.options[:notifications][:email][:from].email?
add_flash(_("E-mail address 'From' is not valid"), :error)
end
if alert.options[:notifications][:snmp]
validate_snmp_options(alert.options[:notifications][:snmp])
unless @flash_array
Expand Down
41 changes: 24 additions & 17 deletions spec/controllers/miq_policy_controller/alerts_spec.rb
@@ -1,12 +1,10 @@
describe MiqPolicyController do
context "::Alerts" do
describe '#alert_delete' do
before do
login_as FactoryGirl.create(:user, :features => "alert_delete")
end

let(:alert) { FactoryGirl.create(:miq_alert, :read_only => readonly) }

before { login_as FactoryGirl.create(:user, :features => "alert_delete") }

context 'read only alert' do
let(:readonly) { true }

Expand All @@ -25,16 +23,13 @@
context "alert edit" do
before do
login_as FactoryGirl.create(:user, :features => "alert_admin")
end

before :each do
@miq_alert = FactoryGirl.create(:miq_alert)
controller.instance_variable_set(:@sb,
:trees => {:alert_tree => {:active_node => "al-#{@miq_alert.id}"}},
:active_tree => :alert_tree)
end

context "#alert_build_edit_screen" do
describe "#alert_build_edit_screen" do
it "it should skip id when copying all attributes of an existing alert" do
controller.instance_variable_set(:@_params, :id => @miq_alert.id, :copy => "copy")
controller.send(:alert_build_edit_screen)
Expand All @@ -48,7 +43,7 @@
end
end

context "#alert_field_changed" do
describe "#alert_field_changed" do
before :each do
controller.params = {:id => 0, :exp_name => ""}
session[:edit] = {:key => "alert_edit__0", :new => {}}
Expand Down Expand Up @@ -80,10 +75,8 @@
end
end

context "#alert_edit_cancel" do
before :each do
allow(controller).to receive(:replace_right_cell).and_return(true)
end
describe "#alert_edit_cancel" do
before { allow(controller).to receive(:replace_right_cell).and_return(true) }

it "it should correctly cancel edit screen of existing alert" do
session[:edit] = {:alert_id => @miq_alert.id}
Expand Down Expand Up @@ -135,12 +128,9 @@
end
end

context "alert_valid_record?" do
describe "#alert_valid_record?" do
before do
login_as FactoryGirl.create(:user, :features => "alert_admin")
end

before :each do
expression = MiqExpression.new("=" => {:tag => "name", :value => "Test"}, :token => 1)
@miq_alert = FactoryGirl.create(
:miq_alert,
Expand Down Expand Up @@ -175,6 +165,23 @@
controller.send(:alert_valid_record?, @miq_alert)
expect(assigns(:flash_array)).to be_nil
end

context 'not choosing Send an E-mail option while adding new Alert' do
let(:alert) do
FactoryGirl.create(:miq_alert,
:expression => {:eval_method => 'nothing'},
:options => {:notifications => {:delay_next_evaluation => 3600, :evm_event => {}}},
:responds_to_events => '_hourly_timer_')
end
let(:edit) { {:new => {:db => 'ContainerNode', :expression => {:eval_method => 'nothing'}}} }

before { controller.instance_variable_set(:@edit, edit) }

it 'returns empty flash array' do
controller.send(:alert_valid_record?, alert)
expect(assigns(:flash_array)).to be_nil
end
end
end
end
end

0 comments on commit 8fb6d10

Please sign in to comment.