Skip to content

Commit

Permalink
Fixed to set all default options when screen loads or Reset is pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
h-kataria committed Jan 9, 2018
1 parent 2dcc6a7 commit 9e8101d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
13 changes: 2 additions & 11 deletions app/controllers/planning_controller.rb
Expand Up @@ -106,15 +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])
@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 @@ -209,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 @@ -224,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
40 changes: 26 additions & 14 deletions spec/controllers/planning_controller_spec.rb
Expand Up @@ -52,28 +52,40 @@
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 = {
:clusters => {},
:datastores => {},
:emss => {},
:hosts => {
"#{@host1.id}" => "Host1",
"#{@host2.id}" => "Host2"
},
: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,
:tz => nil
},
:emss => {},
:clusters => {},
:hosts => {
@host1.id.to_s => "Host1",
@host2.id.to_s => "Host2"
},
:datastores => {},
:vm_filters => {}
: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

Expand Down

0 comments on commit 9e8101d

Please sign in to comment.