Skip to content

Commit

Permalink
Changed if condition to rely on back-end method.
Browse files Browse the repository at this point in the history
Changed check to call back-end method "MiqRegion#role_active?" to decide whether button should be enabled/disabled

https://bugzilla.redhat.com/show_bug.cgi?id=1450290
  • Loading branch information
h-kataria committed May 15, 2017
1 parent d315a66 commit c4bd99d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/helpers/application_helper/button/embedded_ansible.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ApplicationHelper::Button::EmbeddedAnsible < ApplicationHelper::Button::Basic
def disabled?
if ManageIQ::Providers::EmbeddedAnsible::Provider.count != 1 ||
ManageIQ::Providers::EmbeddedAnsible::AutomationManager.first.try(:last_refresh_status) != "success"
if !MiqRegion.my_region.role_active?('embedded_ansible') ||
ManageIQ::Providers::EmbeddedAnsible::Provider.count <= 0
@error_message = _("Embedded Ansible Role is not enabled.")
end
@error_message.present?
Expand Down
30 changes: 23 additions & 7 deletions spec/helpers/application_helper/buttons/embedded_ansible_spec.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
describe ApplicationHelper::Button::EmbeddedAnsible do
before(:each) do
MiqRegion.seed
EvmSpecHelper.create_guid_miq_server_zone
end

let(:view_context) { setup_view_context_with_sandbox({}) }
subject { described_class.new(view_context, {}, {}, {}) }

context 'Embedded Ansible provider is present' do
context 'Embedded Ansible role is turned on and provider is present' do
before do
server_role = FactoryGirl.create(
:server_role,
:name => "embedded_ansible",
:description => "Embedded Ansible",
:max_concurrent => 1,
:external_failover => false,
:role_scope => "zone"
)
FactoryGirl.create(
:assigned_server_role,
:miq_server_id => MiqServer.first.id,
:server_role_id => server_role.id,
:active => true,
:priority => 1
)
# Add embedded Ansible provider if there is none
FactoryGirl.create(:provider_embedded_ansible) if ManageIQ::Providers::EmbeddedAnsible::Provider.count == 0
allow_any_instance_of(ManageIQ::Providers::EmbeddedAnsible::AutomationManager).to receive(:last_refresh_status).and_return("success")
end
it '#disabled? returns false' do
expect(subject.disabled?).to be false
end
end
context 'Embedded Ansible provider is missing' do
before do
# no embedded provider
allow(ManageIQ::Providers::EmbeddedAnsible::Provider).to receive(:count).and_return(0)
end

context 'Embedded Ansible provider is missing & Role is not enabled' do
it '#disabled? returns true' do
expect(subject.disabled?).to be true
end
Expand Down

0 comments on commit c4bd99d

Please sign in to comment.