2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Git::PreReceiveError do
|
2019-07-07 11:18:12 +05:30
|
|
|
Gitlab::Git::PreReceiveError::SAFE_MESSAGE_PREFIXES.each do |prefix|
|
|
|
|
context "error messages prefixed with #{prefix}" do
|
|
|
|
it 'accepts only errors lines with the prefix' do
|
2020-10-24 23:57:45 +05:30
|
|
|
raw_message = "#{prefix} Hello,\nworld!"
|
|
|
|
ex = described_class.new(raw_message)
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
expect(ex.message).to eq('Hello,')
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(ex.raw_message).to eq(raw_message)
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'makes its message HTML-friendly' do
|
2020-10-24 23:57:45 +05:30
|
|
|
raw_message = "#{prefix} Hello,\n#{prefix} world!\n"
|
|
|
|
ex = described_class.new(raw_message)
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
expect(ex.message).to eq('Hello,<br>world!')
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(ex.raw_message).to eq(raw_message)
|
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
it 'prefers the original message over the fallback' do
|
|
|
|
raw_message = "#{prefix} Hello,\nworld!"
|
|
|
|
ex = described_class.new(raw_message, fallback_message: "User message")
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
expect(ex.message).to eq('Hello,')
|
2020-10-24 23:57:45 +05:30
|
|
|
expect(ex.raw_message).to eq(raw_message)
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
it 'uses the fallback message' do
|
|
|
|
raw_message = 'Hello\n'
|
|
|
|
ex = described_class.new(raw_message, fallback_message: "User message")
|
|
|
|
|
|
|
|
expect(ex.raw_message).to eq(raw_message)
|
|
|
|
expect(ex.message).to eq('User message')
|
|
|
|
end
|
2018-11-08 19:23:39 +05:30
|
|
|
end
|
|
|
|
end
|