2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'matches_cross_reference_regex? fails fast' do
|
2019-09-04 21:01:54 +05:30
|
|
|
it 'fails fast for long strings' do
|
|
|
|
# took well under 1 second in CI https://dev.gitlab.org/gitlab/gitlabhq/merge_requests/3267#note_172823
|
|
|
|
expect do
|
2019-12-20 00:11:08 +05:30
|
|
|
Timeout.timeout(6.seconds) { mentionable.matches_cross_reference_regex? }
|
2019-09-04 21:01:54 +05:30
|
|
|
end.not_to raise_error
|
|
|
|
end
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'validates description length with custom validation' do
|
2019-12-21 20:55:43 +05:30
|
|
|
let(:issuable) { build(:issue, description: 'x' * (::Issuable::DESCRIPTION_LENGTH_MAX + 1)) }
|
|
|
|
let(:context) { :update }
|
|
|
|
|
|
|
|
subject { issuable.validate(context) }
|
|
|
|
|
|
|
|
context 'when Issuable is a new record' do
|
|
|
|
it 'validates the maximum description length' do
|
|
|
|
subject
|
|
|
|
expect(issuable.errors[:description]).to eq(["is too long (maximum is #{::Issuable::DESCRIPTION_LENGTH_MAX} characters)"])
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'on create' do
|
|
|
|
let(:context) { :create }
|
|
|
|
|
|
|
|
it 'does not validate the maximum description length' do
|
|
|
|
allow(issuable).to receive(:description_max_length_for_new_records_is_valid).and_call_original
|
|
|
|
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(issuable).not_to have_received(:description_max_length_for_new_records_is_valid)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when Issuable is an existing record' do
|
|
|
|
before do
|
|
|
|
allow(issuable).to receive(:expire_etag_cache) # to skip the expire_etag_cache callback
|
|
|
|
|
|
|
|
issuable.save!(validate: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not validate the maximum description length' do
|
|
|
|
subject
|
|
|
|
expect(issuable.errors).not_to have_key(:description)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
RSpec.shared_examples 'truncates the description to its allowed maximum length on import' do
|
2019-12-21 20:55:43 +05:30
|
|
|
before do
|
|
|
|
allow(issuable).to receive(:importing?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:issuable) { build(:issue, description: 'x' * (::Issuable::DESCRIPTION_LENGTH_MAX + 1)) }
|
|
|
|
|
|
|
|
subject { issuable.validate(:create) }
|
|
|
|
|
|
|
|
it 'truncates the description to its allowed maximum length' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(issuable.description).to eq('x' * ::Issuable::DESCRIPTION_LENGTH_MAX)
|
|
|
|
expect(issuable.errors[:description]).to be_empty
|
|
|
|
end
|
|
|
|
end
|