From 34d26d9d0867c7581881dd20413faa64a93fa497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Hal=C3=A1sz?= Date: Tue, 15 Jan 2019 13:29:07 +0100 Subject: [PATCH] Disable the provider refresh button for suspended providers --- app/helpers/application_helper/button/ems_refresh.rb | 1 + .../application_helper/buttons/ems_refresh_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/app/helpers/application_helper/button/ems_refresh.rb b/app/helpers/application_helper/button/ems_refresh.rb index e45c74b05a5..a7ab862b557 100644 --- a/app/helpers/application_helper/button/ems_refresh.rb +++ b/app/helpers/application_helper/button/ems_refresh.rb @@ -3,6 +3,7 @@ class ApplicationHelper::Button::EmsRefresh < ApplicationHelper::Button::Basic def disabled? super + @error_message ||= _("Unable to refresh the provider while it is suspended") unless @record.enabled? @error_message ||= _("Credentials must be valid to refresh a provider") unless @record.authentication_status.downcase == "valid" @error_message.present? end diff --git a/spec/helpers/application_helper/buttons/ems_refresh_spec.rb b/spec/helpers/application_helper/buttons/ems_refresh_spec.rb index c4491e5f3d5..df31d2639e5 100644 --- a/spec/helpers/application_helper/buttons/ems_refresh_spec.rb +++ b/spec/helpers/application_helper/buttons/ems_refresh_spec.rb @@ -6,13 +6,22 @@ describe '#disabled?' do subject { button[:title] } before { allow(record).to receive(:authentication_status).and_return(auth_status) } + before { allow(record).to receive(:enabled?).and_return(enabled) } + + context 'provider is suspended' do + let(:enabled) { false } + let(:auth_status) { "Valid" } + it { expect(button.disabled?).to be_truthy } + end context 'and record authentication status is valid' do + let(:enabled) { true } let(:auth_status) { "Valid" } it { expect(button.disabled?).to be_falsey } end context 'and record authentication status is not valid' do + let(:enabled) { true } let(:auth_status) { "Invalid" } it { expect(button.disabled?).to be_truthy } end