Skip to content

Commit

Permalink
Merge pull request #3198 from h-kataria/planning_options_flash_messag…
Browse files Browse the repository at this point in the history
…e_fix

Show flash message when "Submit" button is pressed.
(cherry picked from commit 86854e0)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1533514
  • Loading branch information
Dan Clarizio authored and simaishi committed Jan 11, 2018
1 parent e651e1c commit 6ad0477
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 30 deletions.
17 changes: 4 additions & 13 deletions app/controllers/planning_controller.rb
Expand Up @@ -58,7 +58,8 @@ def option_changed
filter_typ = params[:filter_typ] == "<Choose>" ? nil : params[:filter_typ]

@sb[:options][:filter_typ] = filter_typ
@sb[:vms] = wizard_get_vms('all', nil) if filter_typ == 'all'
@sb[:vms] = filter_typ == 'all' ? wizard_get_vms('all', nil) : nil
@sb[:options][:filter_value] = @sb[:options][:chosen_vm] = nil
end

if params[:filter_value].present?
Expand Down Expand Up @@ -106,16 +107,6 @@ def option_changed
params[:time_profile]

@sb[:vm_opts] = VimPerformancePlanning.vm_default_options(@sb[:options][:vm_mode])
unless (@sb[:vm_opts][:cpu] && @sb[:options][:trend_cpu]) || # Check that at least one required metric is checked
(@sb[:vm_opts][:vcpus] && @sb[:options][:trend_vcpus]) ||
(@sb[:vm_opts][:memory] && @sb[:options][:trend_memory]) ||
(@sb[:vm_opts][:storage] && @sb[:options][:trend_storage])
add_flash(_("At least one VM Option must be selected"), :error)
@sb[:options][:trend_cpu] = true if params[:trend_cpu]
@sb[:options][:trend_vcpus] = true if params[:trend_vcpus]
@sb[:options][:trend_memory] = true if params[:trend_memory]
@sb[:options][:trend_storage] = true if params[:trend_storage]
end
if params.key?(:display_vms)
perf_planning_gen_data
replace_right_cell
Expand Down Expand Up @@ -210,7 +201,7 @@ def wizard_get_vms(filter_type, filter_value)

def build_options
@sb[:options] ||= {}
@sb[:options].reverse_merge(
@sb[:options].reverse_merge!(
:days => 7, :vm_mode => :allocated, :trend_cpu => true, :trend_vcpus => true,
:trend_memory => true, :trend_storage => true, :tz => session[:user_tz], :values => {}
)
Expand All @@ -225,7 +216,7 @@ def build_options
set_time_profile_vars(selected_time_profile_for_pull_down, @sb[:options])
end

@sb[:options].reverse_merge(
@sb[:options].reverse_merge!(
:target_typ => 'EmsCluster',
:target_filters => MiqSearch.where(:db => @sb[:options][:target_typ]).descriptions,
:limit_cpu => 90, :limit_vcpus => 10, :limit_memory => 90, :limit_storage => 90,
Expand Down
68 changes: 51 additions & 17 deletions spec/controllers/planning_controller_spec.rb
@@ -1,9 +1,11 @@
describe PlanningController do
before do
EvmSpecHelper.create_guid_miq_server_zone
stub_user(:features => :all)
end

describe "#option_changed" do
before do
EvmSpecHelper.create_guid_miq_server_zone
stub_user(:features => :all)

@host1 = FactoryGirl.create(:host, :name => 'Host1')
@host2 = FactoryGirl.create(:host, :name => 'Host2')

Expand All @@ -13,7 +15,7 @@
@vm4 = FactoryGirl.create(:vm_vmware, :name => 'Name4', :host => @host1)
end

it 'displays all Vms' do
it 'displays all Vms and no flash message is set' do
allow(controller).to receive(:render)
controller.instance_variable_set(:@sb, :vms => {}, :options => {})
controller.instance_variable_set(:@_params, :filter_typ => "all")
Expand All @@ -23,6 +25,7 @@
@vm2.id.to_s => @vm2.name,
@vm3.id.to_s => @vm3.name,
@vm4.id.to_s => @vm4.name)
expect(assigns(:flash_array)).to be_nil
end

it 'displays Vms with the same name' do
Expand All @@ -49,28 +52,59 @@
expect(sb[:vms]).to eq(@vm1.id.to_s => @vm1.name, @vm3.id.to_s => @vm3.name, @vm4.id.to_s => @vm4.name)
end

it 'successfully resets data' do
it 'successfully resets data and sets all default options' do
allow(controller).to receive(:render)
controller.instance_variable_set(:@sb, :vms => {}, :options => {})
controller.send(:reset)
sb = controller.instance_variable_get(:@sb)
sb_result = {
:options => {
:time_profile => nil,
:time_profile_tz => nil,
:time_profile_days => nil,
:tz => nil
},
:emss => {},
:clusters => {},
:datastores => {},
:emss => {},
:hosts => {
@host1.id.to_s => "Host1",
@host2.id.to_s => "Host2"
},
:datastores => {},
:vm_filters => {}
:vm_filters => {},
:options => {
:days => 7,
:vm_mode => :allocated,
:trend_cpu => true,
:trend_vcpus => true,
:trend_memory => true,
:trend_storage => true,
:tz => nil,
:values => {},
:time_profile => nil,
:time_profile_tz => nil,
:time_profile_days => nil,
:target_typ => "EmsCluster",
:target_filters => {},
:limit_cpu => 90,
:limit_vcpus => 10,
:limit_memory => 90,
:limit_storage => 90,
:display_vms => 100
}
}
expect(sb).to eq(sb_result)
expect(assigns(:sb)).to include(sb_result)
end
end

describe "#plan" do
it 'displays flash message when submit button is pressed with selecting vm options' do
allow(controller).to receive(:render)
controller.instance_variable_set(:@sb, :vms => {}, :options => {:vm_mode => :allocated})
controller.instance_variable_set(:@_params, :button => "submit")
controller.send(:plan)
expect(assigns(:flash_array).first[:message]).to include("At least one VM Option must be selected")
end

it 'no flash message is set when atleast one vm options is set' do
allow(controller).to receive(:render)
controller.instance_variable_set(:@sb, :vms => {}, :options => {:vm_mode => :allocated, :trend_vcpus => "1"})
controller.instance_variable_set(:@_params, :button => "submit")
allow(controller).to receive(:perf_planning_gen_data)
controller.send(:plan)
expect(assigns(:flash_array)).to be_nil
end
end
end

0 comments on commit 6ad0477

Please sign in to comment.