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

Show flash message when "Submit" button is pressed. #3198

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 2 additions & 12 deletions app/controllers/planning_controller.rb
Expand Up @@ -106,16 +106,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 +200,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 +215,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