summaryrefslogtreecommitdiff
path: root/spec/models/grafana_integration_spec.rb
diff options
context:
space:
mode:
authorGitLab Release Tools Bot <delivery-team+release-tools@gitlab.com>2022-07-28 13:33:09 +0000
committerGitLab Release Tools Bot <delivery-team+release-tools@gitlab.com>2022-07-28 13:33:09 +0000
commit328ff31ff9e6147e4fb883aaee113001da150b9e (patch)
treee1c4c45aa86e7d3f3da88030b892764fff3bc0ff /spec/models/grafana_integration_spec.rb
parent4dc46d5b97305108c1b635baa4241a2ce04a7ed0 (diff)
parentf415ebdb978c4eb976d07664219c788918120d59 (diff)
downloadgitlab-ce-15-0-stable.tar.gz
Merge remote-tracking branch 'dev/15-0-stable' into 15-0-stable15-0-stable
Diffstat (limited to 'spec/models/grafana_integration_spec.rb')
-rw-r--r--spec/models/grafana_integration_spec.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/spec/models/grafana_integration_spec.rb b/spec/models/grafana_integration_spec.rb
index bb822187e0c..73ec2856c05 100644
--- a/spec/models/grafana_integration_spec.rb
+++ b/spec/models/grafana_integration_spec.rb
@@ -86,4 +86,38 @@ RSpec.describe GrafanaIntegration do
end
end
end
+
+ describe 'Callbacks' do
+ describe 'before_validation :reset_token' do
+ context 'when a token was previously set' do
+ subject(:grafana_integration) { create(:grafana_integration) }
+
+ it 'resets token if url changed' do
+ grafana_integration.grafana_url = 'http://gitlab1.com'
+
+ expect(grafana_integration).not_to be_valid
+ expect(grafana_integration.send(:token)).to be_nil
+ end
+
+ it "does not reset token if new url is set together with the same token" do
+ grafana_integration.grafana_url = 'http://gitlab_edited.com'
+ current_token = grafana_integration.send(:token)
+ grafana_integration.token = current_token
+
+ expect(grafana_integration).to be_valid
+ expect(grafana_integration.send(:token)).to eq(current_token)
+ expect(grafana_integration.grafana_url).to eq('http://gitlab_edited.com')
+ end
+
+ it 'does not reset token if new url is set together with a new token' do
+ grafana_integration.grafana_url = 'http://gitlab_edited.com'
+ grafana_integration.token = 'token'
+
+ expect(grafana_integration).to be_valid
+ expect(grafana_integration.send(:token)).to eq('token')
+ expect(grafana_integration.grafana_url).to eq('http://gitlab_edited.com')
+ end
+ end
+ end
+ end
end