diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-23 12:09:47 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-23 12:09:47 +0000 |
commit | 8f9beefac3774b30e911fb00a68f4c7a5244cf27 (patch) | |
tree | 919c3a043f8c10bc3f78f3f6e029acfb6b972556 /spec/models/snippet_repository_spec.rb | |
parent | e4bf776a8829e5186a0f63603c0be627b891d80e (diff) | |
download | gitlab-ce-8f9beefac3774b30e911fb00a68f4c7a5244cf27.tar.gz |
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 | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/models/snippet_repository_spec.rb b/spec/models/snippet_repository_spec.rb index 6861e03282a..c31fe192367 100644 --- a/spec/models/snippet_repository_spec.rb +++ b/spec/models/snippet_repository_spec.rb @@ -140,6 +140,41 @@ describe SnippetRepository do let_it_be(:named_snippet) { { file_path: 'fee.txt', content: 'bar', action: :create } } let_it_be(:unnamed_snippet) { { file_path: '', content: 'dummy', action: :create } } + context 'when existing file has a default name' do + let(:default_name) { 'snippetfile1.txt' } + let(:new_file) { { file_path: '', content: 'bar' } } + let(:existing_file) { { previous_path: default_name, file_path: '', content: 'new_content' } } + + before do + expect(blob_at(snippet, default_name)).to be_nil + + snippet_repository.multi_files_action(user, [new_file], commit_opts) + + expect(blob_at(snippet, default_name)).to be + end + + it 'reuses the existing file name' do + snippet_repository.multi_files_action(user, [existing_file], commit_opts) + + blob = blob_at(snippet, default_name) + expect(blob.data).to eq existing_file[:content] + end + end + + context 'when file name consists of one or several whitespaces' do + let(:default_name) { 'snippetfile1.txt' } + let(:new_file) { { file_path: ' ', content: 'bar' } } + + it 'assigns a new name to the file' do + expect(blob_at(snippet, default_name)).to be_nil + + snippet_repository.multi_files_action(user, [new_file], commit_opts) + + blob = blob_at(snippet, default_name) + expect(blob.data).to eq new_file[:content] + end + end + context 'when some files are not named' do let(:data) { [named_snippet] + Array.new(2) { unnamed_snippet.clone } } |