diff --git a/app/controllers/miq_policy_controller/alert_profiles.rb b/app/controllers/miq_policy_controller/alert_profiles.rb index 71098691dc2..15df8bb9c59 100644 --- a/app/controllers/miq_policy_controller/alert_profiles.rb +++ b/app/controllers/miq_policy_controller/alert_profiles.rb @@ -6,7 +6,7 @@ def alert_profile_load end def alert_profile_edit_cancel - alert_profile_load + return unless alert_profile_edit_load_edit @edit = nil if @alert_profile && @alert_profile.id.blank? add_flash(_("Add of new Alert Profile was cancelled by the user")) diff --git a/spec/controllers/miq_policy_controller/alert_profiles_spec.rb b/spec/controllers/miq_policy_controller/alert_profiles_spec.rb index 7038a1a64c9..9c42db2ea91 100644 --- a/spec/controllers/miq_policy_controller/alert_profiles_spec.rb +++ b/spec/controllers/miq_policy_controller/alert_profiles_spec.rb @@ -71,5 +71,26 @@ expect(controller.send(:flash_errors?)).not_to be_truthy end end + + context "#alert_profile_edit" do + before :each do + controller.instance_variable_set(:@sb, + :trees => { + :alert_profile_tree => {:active_node => "xx-Vm"}}, + :active_tree => :alert_profile_tree) + allow(controller).to receive(:replace_right_cell) + edit = { + :key => "alert_profile_edit__new" + } + session[:edit] = edit + end + + it "Test cancel button" do + controller.instance_variable_set(:@_params, :id => 'new', :button => "cancel") + controller.alert_profile_edit + expect(assigns(:flash_array).first[:message]).to include("Add of new Alert Profile was cancelled by the user") + expect(controller.send(:flash_errors?)).not_to be_truthy + end + end end end