diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-10 15:08:16 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-10 15:08:16 +0300 |
commit | 1fa79760ad2d4bd67f5c5a27f372a7533b9b7c69 (patch) | |
tree | ffdfbd9113743831ff4f1290959a62cf6567fde5 /spec/models/snippet_repository_spec.rb | |
parent | 82fa8a3d1e8466ef36b58604d20fcc145ea12118 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/snippet_repository_spec.rb')
-rw-r--r-- | spec/models/snippet_repository_spec.rb | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/spec/models/snippet_repository_spec.rb b/spec/models/snippet_repository_spec.rb index 120175fdd05..088d37725aa 100644 --- a/spec/models/snippet_repository_spec.rb +++ b/spec/models/snippet_repository_spec.rb @@ -168,34 +168,42 @@ describe SnippetRepository do end end - context 'when files are not named' do - let(:data) do - [ - { - file_path: '', - content: 'foo', - action: :create - }, - { - file_path: '', - content: 'bar', - action: :create - }, - { - file_path: 'foo.txt', - content: 'bar', - action: :create - } - ] + shared_examples 'snippet repository with file names' do |*filenames| + it 'sets a name for unnamed files' do + ls_files = snippet.repository.ls_files(nil) + expect(ls_files).to include(*filenames) end + end + + let_it_be(:named_snippet) { { file_path: 'fee.txt', content: 'bar', action: :create } } + let_it_be(:unnamed_snippet) { { file_path: '', content: 'dummy', action: :create } } - it 'sets a name for non named files' do + context 'when some files are not named' do + let(:data) { [named_snippet] + Array.new(2) { unnamed_snippet.clone } } + + before do expect do snippet_repository.multi_files_action(user, data, commit_opts) end.not_to raise_error + end + + it_behaves_like 'snippet repository with file names', 'snippetfile1.txt', 'snippetfile2.txt' + end - expect(snippet.repository.ls_files(nil)).to include('snippetfile1.txt', 'snippetfile2.txt', 'foo.txt') + context 'repository already has 10 unnamed snippets' do + let(:pre_populate_data) { Array.new(10) { unnamed_snippet.clone } } + let(:data) { [named_snippet] + Array.new(2) { unnamed_snippet.clone } } + + before do + # Pre-populate repository with 9 unnamed snippets. + snippet_repository.multi_files_action(user, pre_populate_data, commit_opts) + + expect do + snippet_repository.multi_files_action(user, data, commit_opts) + end.not_to raise_error end + + it_behaves_like 'snippet repository with file names', 'snippetfile10.txt', 'snippetfile11.txt' end end |