Commit b2e86043 authored by allison.browne's avatar allison.browne

Add enabled check within client method

parent 7cb54ab3
......@@ -17,6 +17,8 @@ class GrafanaIntegration < ApplicationRecord
validates :enabled, inclusion: { in: [true, false] }
def client
@client ||= ::Grafana::Client.new(api_url: grafana_url.chomp('/'), token: token)
if enabled?
@client ||= ::Grafana::Client.new(api_url: grafana_url.chomp('/'), token: token)
end
end
end
......@@ -48,4 +48,22 @@ describe GrafanaIntegration do
).for(:enabled)
end
end
describe '.client' do
subject(:grafana_integration) { create(:grafana_integration) }
context 'with grafana integration disabled' do
it 'returns a grafana client' do
expect(grafana_integration.client).to be_an_instance_of(::Grafana::Client)
end
end
context 'with grafana integration enabled' do
it 'returns nil' do
grafana_integration.update(enabled: false)
expect(grafana_integration.client).to be(nil)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment