summaryrefslogtreecommitdiff
path: root/spec/models/ci/pipeline_message_spec.rb
blob: 6c97a025625cfedea37eb1ff773f5c481b96eac5 (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
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::PipelineMessage do
  describe 'validations' do
    subject { described_class.new(pipeline: pipeline, content: content) }

    let(:pipeline) { create(:ci_pipeline) }

    context 'when message content is longer than the limit' do
      let(:content) { 'x' * (described_class::MAX_CONTENT_LENGTH + 1) }

      it 'is truncated with ellipsis' do
        subject.save!

        expect(subject.content).to end_with('x...')
        expect(subject.content.length).to eq(described_class::MAX_CONTENT_LENGTH)
      end
    end

    context 'when message is not present' do
      let(:content) { '' }

      it 'returns an error' do
        expect(subject.save).to be_falsey
        expect(subject.errors[:content]).to be_present
      end
    end

    context 'when message content is valid' do
      let(:content) { 'valid message content' }

      it 'is saved with default error severity' do
        subject.save!

        expect(subject.content).to eq(content)
        expect(subject.severity).to eq('error')
        expect(subject).to be_error
      end

      it 'is persist the defined severity' do
        subject.severity = :warning

        subject.save!

        expect(subject.content).to eq(content)
        expect(subject.severity).to eq('warning')
        expect(subject).to be_warning
      end
    end
  end
end