Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix highlighting the condition in accordion after creating it #5302

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/miq_policy_controller/conditions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def condition_edit
condition_get_info(condition)
case x_active_tree
when :condition_tree
@new_condition_node = "xx-#{condition.towhat.downcase}_co-#{condition.id}"
@new_condition_node = "xx-#{condition.towhat.camelize(:lower)}_co-#{condition.id}"
replace_right_cell(:nodetype => "co", :replace_trees => %i(condition), :remove_form_buttons => true)
when :policy_tree
node_ids = @sb[:node_ids][x_active_tree] # Get the selected node ids
Expand Down
46 changes: 31 additions & 15 deletions spec/controllers/miq_policy_controller/conditions_spec.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
describe MiqPolicyController do
context "::Conditions" do
context '#condition_remove' do
it 'removes condition successfully' do
login_as FactoryBot.create(:user, :features => "condition_remove")
condition = FactoryBot.create(:condition)
policy = FactoryBot.create(:miq_policy, :name => "test_policy", :conditions => [condition])
controller.instance_variable_set(:@_params, :policy_id => policy.id, :id => condition.id)
controller.instance_variable_set(:@sb, {})
controller.x_node = "pp_pp-1r36_p-#{policy.id}_co-#{condition.id}"
expect(controller).to receive(:replace_right_cell)
controller.send(:condition_remove)
policy.reload
expect(assigns(:flash_array).first[:message]).to include("has been removed from Policy")
expect(policy.conditions).to eq([])
describe MiqPolicyController::Conditions do
let(:test_class) { Struct.new(:params) { include MiqPolicyController::Conditions } }
subject { test_class.new(params) }

describe '#condition_edit' do
context 'adding new condition' do
let(:params) { {:button => 'add'} }

before do
allow(subject).to receive(:add_flash)
allow(subject).to receive(:assert_privileges)
allow(subject).to receive(:build_saved_audit).and_return(:event => 'condition_record_add',
:target_id => 1,
:target_class => 'Condition',
:userid => 'admin',
:message => '')
allow(subject).to receive(:exp_build_table)
allow(subject).to receive(:exp_remove_tokens)
allow(subject).to receive(:load_edit).and_return(true)
allow(subject).to receive(:replace_right_cell)
allow(subject).to receive(:x_active_tree).and_return(:condition_tree)
subject.instance_variable_set(:@edit, :new => {:towhat => 'ContainerReplicator',
:description => 'New_condition',
:notes => nil,
:expression => {},
:applies_to_exp => {"???"=>"???"}})
end

it 'sets new node correctly' do
subject.send(:condition_edit)
expect(subject.instance_variable_get(:@new_condition_node)).to include('xx-containerReplicator_co-')
end
end
end
Expand Down
20 changes: 20 additions & 0 deletions spec/controllers/miq_policy_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,24 @@
end
end
end

context 'removing conditions' do
let(:condition) { FactoryBot.create(:condition) }
let(:policy) { FactoryBot.create(:miq_policy, :name => "test_policy", :conditions => [condition]) }

before do
login_as FactoryBot.create(:user, :features => 'condition_remove')
controller.instance_variable_set(:@_params, :policy_id => policy.id, :id => condition.id)
controller.instance_variable_set(:@sb, {})
allow(controller).to receive(:x_node).and_return("pp_pp-1r36_p-#{policy.id}_co-#{condition.id}")
end

it 'removes condition successfully' do
expect(controller).to receive(:replace_right_cell)
controller.send(:condition_remove)
policy.reload
expect(assigns(:flash_array).first[:message]).to include("has been removed from Policy")
expect(policy.conditions).to eq([])
end
end
end