summaryrefslogtreecommitdiff
path: root/spec/models/alerting/project_alerting_setting_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-23 00:09:51 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-23 00:09:51 +0000
commit71da67f3262eeffe59cc228986e0a2bb97b6dba5 (patch)
tree426845fe569787b0ab1b2bae573fb1ae8ccb6fe1 /spec/models/alerting/project_alerting_setting_spec.rb
parentf2dfd9ee819afb07bf11bd36a5f9d23009be0d39 (diff)
downloadgitlab-ce-71da67f3262eeffe59cc228986e0a2bb97b6dba5.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/alerting/project_alerting_setting_spec.rb')
-rw-r--r--spec/models/alerting/project_alerting_setting_spec.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/spec/models/alerting/project_alerting_setting_spec.rb b/spec/models/alerting/project_alerting_setting_spec.rb
new file mode 100644
index 00000000000..40fbe3a6e78
--- /dev/null
+++ b/spec/models/alerting/project_alerting_setting_spec.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Alerting::ProjectAlertingSetting do
+ let_it_be(:project) { create(:project) }
+
+ subject { create(:project_alerting_setting, project: project) }
+
+ describe 'Associations' do
+ it { is_expected.to belong_to(:project) }
+ end
+
+ describe '#token' do
+ context 'when set' do
+ let(:token) { SecureRandom.hex }
+
+ subject do
+ create(:project_alerting_setting, project: project, token: token)
+ end
+
+ it 'reads the token' do
+ expect(subject.token).to eq(token)
+ expect(subject.encrypted_token).not_to be_nil
+ expect(subject.encrypted_token_iv).not_to be_nil
+ end
+ end
+
+ context 'when not set' do
+ before do
+ subject.token = nil
+ end
+
+ it 'generates a token before validation' do
+ expect(subject).to be_valid
+ expect(subject.token).to match(/\A\h{32}\z/)
+ end
+ end
+ end
+end