diff options
author | GitLab Release Tools Bot <delivery-team+release-tools@gitlab.com> | 2022-08-30 15:09:23 +0000 |
---|---|---|
committer | GitLab Release Tools Bot <delivery-team+release-tools@gitlab.com> | 2022-08-30 15:09:23 +0000 |
commit | 33d3043f0f3b825f98c7ff2c794208a79bcafdb3 (patch) | |
tree | 2fc8f97f12f9e3049ed3daad5700ae438b7eac9b /spec/models/snippet_spec.rb | |
parent | 99e4792893862d913d0bc9168da7d85775445590 (diff) | |
parent | f1452cd5cf4c3e2dd6697bc25636b49c1aadecd1 (diff) | |
download | gitlab-ce-15-1-stable.tar.gz |
Merge remote-tracking branch 'dev/15-1-stable' into 15-1-stable15-1-stable
Diffstat (limited to 'spec/models/snippet_spec.rb')
-rw-r--r-- | spec/models/snippet_spec.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb index a54edc8510e..da94441d621 100644 --- a/spec/models/snippet_spec.rb +++ b/spec/models/snippet_spec.rb @@ -91,6 +91,45 @@ RSpec.describe Snippet do end end end + + context 'description validations' do + let_it_be(:invalid_description) { 'a' * (described_class::DESCRIPTION_LENGTH_MAX * 2) } + + context 'with existing snippets' do + let(:snippet) { create(:personal_snippet, description: 'This is a valid content at the time of creation') } + + it 'does not raise a validation error if the description is not changed' do + snippet.title = 'new title' + + expect(snippet).to be_valid + end + + it 'raises and error if the description is changed and the size is bigger than limit' do + expect(snippet).to be_valid + + snippet.description = invalid_description + + expect(snippet).not_to be_valid + end + end + + context 'with new snippets' do + it 'is valid when description is smaller than the limit' do + snippet = build(:personal_snippet, description: 'Valid Desc') + + expect(snippet).to be_valid + end + + it 'raises error when description is bigger than setting limit' do + snippet = build(:personal_snippet, description: invalid_description) + + aggregate_failures do + expect(snippet).not_to be_valid + expect(snippet.errors.messages_for(:description)).to include("is too long (2 MB). The maximum size is 1 MB.") + end + end + end + end end describe 'callbacks' do |