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>2020-07-20 15:26:25 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-07-20 15:26:25 +0300
commita09983ae35713f5a2bbb100981116d31ce99826e (patch)
tree2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/models/snippet_spec.rb
parent18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff)
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/models/snippet_spec.rb')
-rw-r--r--spec/models/snippet_spec.rb39
1 files changed, 38 insertions, 1 deletions
diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb
index 4d6586c1df4..3f9c6981de1 100644
--- a/spec/models/snippet_spec.rb
+++ b/spec/models/snippet_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-describe Snippet do
+RSpec.describe Snippet do
describe 'modules' do
subject { described_class }
@@ -20,6 +20,7 @@ describe Snippet do
it { is_expected.to have_many(:award_emoji).dependent(:destroy) }
it { is_expected.to have_many(:user_mentions).class_name("SnippetUserMention") }
it { is_expected.to have_one(:snippet_repository) }
+ it { is_expected.to have_one(:statistics).class_name('SnippetStatistics').dependent(:destroy) }
end
describe 'validation' do
@@ -91,6 +92,17 @@ describe Snippet do
end
end
+ describe 'callbacks' do
+ it 'creates snippet statistics when the snippet is created' do
+ snippet = build(:snippet)
+ expect(snippet.statistics).to be_nil
+
+ snippet.save
+
+ expect(snippet.statistics).to be_persisted
+ end
+ end
+
describe '#to_reference' do
context 'when snippet belongs to a project' do
let(:project) { build(:project, name: 'sample-project') }
@@ -750,4 +762,29 @@ describe Snippet do
end
end
end
+
+ describe '#list_files' do
+ let_it_be(:snippet) { create(:snippet, :repository) }
+ let(:ref) { 'test-ref' }
+
+ subject { snippet.list_files(ref) }
+
+ context 'when snippet has a repository' do
+ it 'lists files from the repository with the ref' do
+ expect(snippet.repository).to receive(:ls_files).with(ref)
+
+ subject
+ end
+ end
+
+ context 'when snippet does not have a repository' do
+ before do
+ allow(snippet.repository).to receive(:empty?).and_return(true)
+ end
+
+ it 'returns an empty array' do
+ expect(subject).to eq []
+ end
+ end
+ end
end