Skip to content

Commit

Permalink
Correct #visible? method so the button gets hidden when the record is…
Browse files Browse the repository at this point in the history
… miq_server or miq_region only if layout != ops and tailors the spec file accordingly
  • Loading branch information
Attila Vecerek committed Oct 27, 2016
1 parent a194d8e commit 0f79a50
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
8 changes: 6 additions & 2 deletions app/helpers/application_helper/button/refresh_workers.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class ApplicationHelper::Button::RefreshWorkers < ApplicationHelper::Button::Basic
needs :@record, :@lastaction, @sb
needs :@record, :@lastaction, :@sb, :@layout

def visible?
return true if diagnostics_worker_tab? && !miq?
return false if miq? && !(ops? && diagnostics_worker_tab?)
return !%w(download_logs evm_logs audit_logs).include?(@lastaction) if @record.class == NilClass
true
end
Expand All @@ -16,4 +16,8 @@ def diagnostics_worker_tab?
def miq?
@record.class == MiqServer || @record.class == MiqRegion
end

def ops?
@layout == 'ops'
end
end
35 changes: 25 additions & 10 deletions spec/helpers/application_helper/buttons/refresh_workers_spec.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
describe ApplicationHelper::Button::RefreshWorkers do
before :all do
@record = FactoryGirl.create(
:assigned_server_role,
:miq_server => FactoryGirl.create(:miq_server))
@records = [FactoryGirl.create(:miq_server), FactoryGirl.create(:miq_region)]
end

describe '#visible?' do
it 'should be visible when active_tab == diagnostics_workers in :diagnostics_tree' do
view_context = setup_view_context_with_sandbox({})
button = described_class.new(view_context, {}, {'record' => @record}, {})
button.instance_variable_set(:@sb, :active_tab => 'diagnostics_workers')
expect(button.visible?).to be_truthy
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')
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
end
end

%w(download_logs evm_logs audit_logs).each do |lastaction|
context "action #{lastaction} being taken as last" do
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}, {})
Expand All @@ -23,7 +38,7 @@
end
end

context 'other action being taken as last' do
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'}, {})
Expand Down

0 comments on commit 0f79a50

Please sign in to comment.