Skip to content

Commit

Permalink
Add spec to check successful adding a new Alert
Browse files Browse the repository at this point in the history
Check successful adding Alert while no Send an E-mail option was chosen.
  • Loading branch information
hstastna committed Dec 7, 2018
1 parent d9906ea commit 37f4cf7
Showing 1 changed file with 24 additions and 17 deletions.
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 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 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 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 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 37f4cf7

Please sign in to comment.