Skip to content

Commit

Permalink
Adopt the changes suggested by @jzigmund
Browse files Browse the repository at this point in the history
  • Loading branch information
Attila Vecerek committed Oct 27, 2016
1 parent 0f79a50 commit 2797d55
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 53 deletions.
18 changes: 1 addition & 17 deletions app/helpers/application_helper/button/refresh_workers.rb
Original file line number Diff line number Diff line change
@@ -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
54 changes: 18 additions & 36 deletions spec/helpers/application_helper/buttons/refresh_workers_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 2797d55

Please sign in to comment.