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:
Diffstat (limited to 'spec/lib/api/entities/snippet_spec.rb')
-rw-r--r--spec/lib/api/entities/snippet_spec.rb55
1 files changed, 54 insertions, 1 deletions
diff --git a/spec/lib/api/entities/snippet_spec.rb b/spec/lib/api/entities/snippet_spec.rb
index dada0942e49..bcb8c364392 100644
--- a/spec/lib/api/entities/snippet_spec.rb
+++ b/spec/lib/api/entities/snippet_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe ::API::Entities::Snippet do
+RSpec.describe ::API::Entities::Snippet do
let_it_be(:user) { create(:user) }
let_it_be(:personal_snippet) { create(:personal_snippet, :repository, author: user ) }
let_it_be(:project_snippet) { create(:project_snippet, :repository, author: user) }
@@ -21,6 +21,16 @@ describe ::API::Entities::Snippet do
it { expect(subject[:visibility]).to eq snippet.visibility }
it { expect(subject).to include(:author) }
+ context 'with snippet_multiple_files feature disabled' do
+ before do
+ stub_feature_flags(snippet_multiple_files: false)
+ end
+
+ it 'does not return files' do
+ expect(subject).not_to include(:files)
+ end
+ end
+
describe 'file_name' do
it 'returns attribute from repository' do
expect(subject[:file_name]).to eq snippet.blobs.first.path
@@ -62,6 +72,49 @@ describe ::API::Entities::Snippet do
end
end
end
+
+ describe 'files' do
+ let(:blob) { snippet.blobs.first }
+ let(:ref) { blob.repository.root_ref }
+
+ context 'when repository does not exist' do
+ it 'does not include the files attribute' do
+ allow(snippet).to receive(:repository_exists?).and_return(false)
+
+ expect(subject).not_to include(:files)
+ end
+ end
+
+ shared_examples 'snippet files' do
+ let(:file) { subject[:files].first }
+
+ it 'returns all snippet files' do
+ expect(subject[:files].count).to eq snippet.blobs.count
+ end
+
+ it 'has the file path' do
+ expect(file[:path]).to eq blob.path
+ end
+
+ it 'has the raw url' do
+ expect(file[:raw_url]).to match(raw_url)
+ end
+ end
+
+ context 'with PersonalSnippet' do
+ it_behaves_like 'snippet files' do
+ let(:snippet) { personal_snippet }
+ let(:raw_url) { "/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}" }
+ end
+ end
+
+ context 'with ProjectSnippet' do
+ it_behaves_like 'snippet files' do
+ let(:snippet) { project_snippet }
+ let(:raw_url) { "#{snippet.project.full_path}/-/snippets/#{snippet.id}/raw/#{ref}/#{blob.path}" }
+ end
+ end
+ end
end
context 'with PersonalSnippet' do