From 2797d555fe3bf39b4e9d8b26c6e61c7dfb5c250a Mon Sep 17 00:00:00 2001 From: Attila Vecerek Date: Wed, 26 Oct 2016 20:31:11 +0200 Subject: [PATCH] Adopt the changes suggested by @jzigmund --- .../button/refresh_workers.rb | 18 +------ .../buttons/refresh_workers_spec.rb | 54 +++++++------------ 2 files changed, 19 insertions(+), 53 deletions(-) diff --git a/app/helpers/application_helper/button/refresh_workers.rb b/app/helpers/application_helper/button/refresh_workers.rb index 2c268ed3a3b..b2a4006a9ee 100644 --- a/app/helpers/application_helper/button/refresh_workers.rb +++ b/app/helpers/application_helper/button/refresh_workers.rb @@ -1,23 +1,7 @@ class ApplicationHelper::Button::RefreshWorkers < ApplicationHelper::Button::Basic - needs :@record, :@lastaction, :@sb, :@layout + needs :@record, :@sb def visible? - return false if miq? && !(ops? && diagnostics_worker_tab?) - return !%w(download_logs evm_logs audit_logs).include?(@lastaction) if @record.class == NilClass - true - end - - private - - def diagnostics_worker_tab? @view_context.x_active_tree == :diagnostics_tree && @sb[:active_tab] == 'diagnostics_workers' end - - def miq? - @record.class == MiqServer || @record.class == MiqRegion - end - - def ops? - @layout == 'ops' - end end diff --git a/spec/helpers/application_helper/buttons/refresh_workers_spec.rb b/spec/helpers/application_helper/buttons/refresh_workers_spec.rb index 001cbc75a9d..45d1c64affc 100644 --- a/spec/helpers/application_helper/buttons/refresh_workers_spec.rb +++ b/spec/helpers/application_helper/buttons/refresh_workers_spec.rb @@ -1,47 +1,29 @@ describe ApplicationHelper::Button::RefreshWorkers do - before :all do - @records = [FactoryGirl.create(:miq_server), FactoryGirl.create(:miq_region)] - end + let(:view_context) { setup_view_context_with_sandbox({}) } + let(:record) { FactoryGirl.create(:miq_server) } describe '#visible?' do - context 'when layout == ops and active_tab == diagnostics_workers in :diagnostics_tree' do - it 'will not be skipped' do - view_context = setup_view_context_with_sandbox({}) - button = described_class.new(view_context, {}, {'record' => nil, 'layout' => 'ops'}, {}) - button.instance_variable_set(:@sb, :active_tab => 'diagnostics_workers') + context 'when x_active_tree == diagnostics_tree and active_tab != diagnostics_workers' do + it 'will be skipped' do + button = described_class.new(view_context, {}, {'record' => record}, {}) + button.instance_variable_set(:@sb, :active_tab => 'does not matter') allow(view_context).to receive(:x_active_tree).and_return(:diagnostics_tree) - expect(button.visible?).to be_truthy - end - end - - context 'when layout != ops and' do - %w(miq_server miq_region).each_with_index do |record, i| - context "record is #{record}" do - it 'will be skipped' do - view_context = setup_view_context_with_sandbox({}) - button = described_class.new(view_context, {}, {'record' => @records[i], 'layout' => 'not ops'}, {}) - button.instance_variable_set(:@sb, :active_tab => 'does not matter') - allow(view_context).to receive(:x_active_tree).and_return(:diagnostics_tree) - expect(button.visible?).to be_falsey - end - end + expect(button.visible?).to be_falsey end end - - %w(download_logs evm_logs audit_logs).each do |lastaction| - context "when action #{lastaction} being taken as last" do - it 'will be skipped for this record' do - view_context = setup_view_context_with_sandbox({}) - button = described_class.new(view_context, {}, {'record' => nil, 'lastaction' => lastaction}, {}) - expect(button.visible?).to be_falsey - end + context 'when x_active_tree != diagnostics_tree and active_tab == diagnostics_workers' do + it 'will be skipped' do + button = described_class.new(view_context, {}, {'record' => record}, {}) + button.instance_variable_set(:@sb, :active_tab => 'diagnostics_workers') + allow(view_context).to receive(:x_active_tree).and_return(:does_not_matter) + expect(button.visible?).to be_falsey end end - - context 'when other action being taken as last' do - it 'will not be skipped for this record' do - view_context = setup_view_context_with_sandbox({}) - button = described_class.new(view_context, {}, {'record' => nil, 'lastaction' => 'worker_logs'}, {}) + context 'when x_active_tree == diagnostics_tree and active_tab == diagnostics_workers' do + it 'will not be skipped' do + button = described_class.new(view_context, {}, {'record' => record}, {}) + button.instance_variable_set(:@sb, :active_tab => 'diagnostics_workers') + allow(view_context).to receive(:x_active_tree).and_return(:diagnostics_tree) expect(button.visible?).to be_truthy end end