summaryrefslogtreecommitdiff
path: root/spec/models/alerting/project_alerting_setting_spec.rb
blob: 90c5f8313b07bc2dbb1a3863892951357a49f00c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

require 'spec_helper'

RSpec.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