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>2019-12-02 15:06:45 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2019-12-02 15:06:45 +0300
commitbffcdf9bca11a4d43cc40e3f382f03088d36f7c6 (patch)
treec773436393b7a59b5f6b14388b9fa6402a9bd198 /spec/models/snippet_spec.rb
parent259c0cc0c4f8a49001b33d1bee577f4422e16d62 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/snippet_spec.rb')
-rw-r--r--spec/models/snippet_spec.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb
index cfc0703af23..82836dac1d7 100644
--- a/spec/models/snippet_spec.rb
+++ b/spec/models/snippet_spec.rb
@@ -31,6 +31,62 @@ describe Snippet do
it { is_expected.to validate_presence_of(:content) }
it { is_expected.to validate_inclusion_of(:visibility_level).in_array(Gitlab::VisibilityLevel.values) }
+
+ it do
+ allow(Gitlab::CurrentSettings).to receive(:snippet_size_limit).and_return(1)
+
+ is_expected
+ .to validate_length_of(:content)
+ .is_at_most(Gitlab::CurrentSettings.snippet_size_limit)
+ .with_message("is too long (2 Bytes). The maximum size is 1 Byte.")
+ end
+
+ context 'content validations' do
+ context 'with existing snippets' do
+ let(:snippet) { create(:personal_snippet, content: 'This is a valid content at the time of creation') }
+
+ before do
+ expect(snippet).to be_valid
+
+ stub_application_setting(snippet_size_limit: 2)
+ end
+
+ it 'does not raise a validation error if the content is not changed' do
+ snippet.title = 'new title'
+
+ expect(snippet).to be_valid
+ end
+
+ it 'raises and error if the content is changed and the size is bigger than limit' do
+ snippet.content = snippet.content + "test"
+
+ expect(snippet).not_to be_valid
+ end
+ end
+
+ context 'with new snippets' do
+ let(:limit) { 15 }
+
+ before do
+ stub_application_setting(snippet_size_limit: limit)
+ end
+
+ it 'is valid when content is smaller than the limit' do
+ snippet = build(:personal_snippet, content: 'Valid Content')
+
+ expect(snippet).to be_valid
+ end
+
+ it 'raises error when content is bigger than setting limit' do
+ snippet = build(:personal_snippet, content: 'This is an invalid content')
+
+ aggregate_failures do
+ expect(snippet).not_to be_valid
+ expect(snippet.errors[:content]).to include("is too long (#{snippet.content.size} Bytes). The maximum size is #{limit} Bytes.")
+ end
+ end
+ end
+ end
end
describe '#to_reference' do