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:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-26 17:36:54 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-26 17:36:54 +0300
commitdaf5ae5bd439f1f32363d410129d5b9e73fbb539 (patch)
tree6d670487dc3dccf1a0c3e6b8337e5b4ab9da4ee9 /spec/models/snippet_spec.rb
parent6e8c2290dab8ae1612dff80e312911bc1147edaa (diff)
Add latest changes from gitlab-org/security/gitlab@15-3-stable-ee
Diffstat (limited to 'spec/models/snippet_spec.rb')
-rw-r--r--spec/models/snippet_spec.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb
index 38bd189f6f4..da1f2653676 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