diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-18 09:08:14 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-18 09:08:14 +0300 |
commit | 7e5f8d08817c5672a0fe2f36609897f20d7e120e (patch) | |
tree | c09839c3ea64f6ec1035fdc4942c9022ca5a101a /spec/services | |
parent | 25861ffdce4061974732c8403992a0532433e012 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
-rw-r--r-- | spec/services/snippets/create_service_spec.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/spec/services/snippets/create_service_spec.rb b/spec/services/snippets/create_service_spec.rb index b545d7a8aa8..c0a0a2f6ac2 100644 --- a/spec/services/snippets/create_service_spec.rb +++ b/spec/services/snippets/create_service_spec.rb @@ -285,6 +285,20 @@ describe Snippets::CreateService do it_behaves_like 'an error service response when save fails' it_behaves_like 'creates repository and files' it_behaves_like 'after_save callback to store_mentions', ProjectSnippet + + context 'when uploaded files are passed to the service' do + let(:extra_opts) { { files: ['foo'] } } + + it 'does not move uploaded files to the snippet' do + expect_next_instance_of(described_class) do |instance| + expect(instance).to receive(:move_temporary_files).and_call_original + end + + expect_any_instance_of(FileMover).not_to receive(:execute) + + subject + end + end end context 'when PersonalSnippet' do @@ -297,6 +311,51 @@ describe Snippets::CreateService do it_behaves_like 'an error service response when save fails' it_behaves_like 'creates repository and files' it_behaves_like 'after_save callback to store_mentions', PersonalSnippet + + context 'when the snippet description contains files' do + include FileMoverHelpers + + let(:title) { 'Title' } + let(:picture_secret) { SecureRandom.hex } + let(:text_secret) { SecureRandom.hex } + let(:picture_file) { "/-/system/user/#{creator.id}/#{picture_secret}/picture.jpg" } + let(:text_file) { "/-/system/user/#{creator.id}/#{text_secret}/text.txt" } + let(:files) { [picture_file, text_file] } + let(:description) do + "Description with picture: ![picture](/uploads#{picture_file}) and "\ + "text: [text.txt](/uploads#{text_file})" + end + + before do + allow(FileUtils).to receive(:mkdir_p) + allow(FileUtils).to receive(:move) + end + + let(:extra_opts) { { description: description, title: title, files: files } } + + it 'stores the snippet description correctly' do + stub_file_mover(text_file) + stub_file_mover(picture_file) + + snippet = subject.payload[:snippet] + + expected_description = "Description with picture: "\ + "![picture](/uploads/-/system/personal_snippet/#{snippet.id}/#{picture_secret}/picture.jpg) and "\ + "text: [text.txt](/uploads/-/system/personal_snippet/#{snippet.id}/#{text_secret}/text.txt)" + + expect(snippet.description).to eq(expected_description) + end + + context 'when there is a validation error' do + let(:title) { nil } + + it 'does not move uploaded files to the snippet' do + expect_any_instance_of(described_class).not_to receive(:move_temporary_files) + + subject + end + end + end end end end |