Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/ci/pipeline_message_spec.rb')
-rw-r--r--spec/models/ci/pipeline_message_spec.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/models/ci/pipeline_message_spec.rb b/spec/models/ci/pipeline_message_spec.rb
new file mode 100644
index 00000000000..6c97a025625
--- /dev/null
+++ b/spec/models/ci/pipeline_message_spec.rb
@@ -0,0 +1,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