diff options
author | GitLab Release Tools Bot <delivery-team+release-tools@gitlab.com> | 2022-07-28 13:33:09 +0000 |
---|---|---|
committer | GitLab Release Tools Bot <delivery-team+release-tools@gitlab.com> | 2022-07-28 13:33:09 +0000 |
commit | 328ff31ff9e6147e4fb883aaee113001da150b9e (patch) | |
tree | e1c4c45aa86e7d3f3da88030b892764fff3bc0ff /spec/models/grafana_integration_spec.rb | |
parent | 4dc46d5b97305108c1b635baa4241a2ce04a7ed0 (diff) | |
parent | f415ebdb978c4eb976d07664219c788918120d59 (diff) | |
download | gitlab-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.rb | 34 |
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 |