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-03-17 09:09:21 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-17 09:09:21 +0300
commitc8df22c555ab707a705e57c4257fd3ed1ce7c3b0 (patch)
tree009fb7c1ff12a6192921212cae404b790fd7d66b /spec/lib/gitlab/checks
parent9345f69894862e02f3491ea3136c3ed2b23fd5b8 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/checks')
-rw-r--r--spec/lib/gitlab/checks/push_file_count_check_spec.rb53
-rw-r--r--spec/lib/gitlab/checks/snippet_check_spec.rb10
2 files changed, 58 insertions, 5 deletions
diff --git a/spec/lib/gitlab/checks/push_file_count_check_spec.rb b/spec/lib/gitlab/checks/push_file_count_check_spec.rb
new file mode 100644
index 00000000000..58ba7d579a3
--- /dev/null
+++ b/spec/lib/gitlab/checks/push_file_count_check_spec.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Gitlab::Checks::PushFileCountCheck do
+ let(:snippet) { create(:personal_snippet, :repository) }
+ let(:changes) { { oldrev: oldrev, newrev: newrev, ref: ref } }
+ let(:timeout) { Gitlab::GitAccess::INTERNAL_TIMEOUT }
+ let(:logger) { Gitlab::Checks::TimedLogger.new(timeout: timeout) }
+
+ subject { described_class.new(changes, repository: snippet.repository, limit: 1, logger: logger) }
+
+ describe '#validate!' do
+ using RSpec::Parameterized::TableSyntax
+
+ before do
+ allow(snippet.repository).to receive(:new_commits).and_return(
+ snippet.repository.commits_between(oldrev, newrev)
+ )
+ end
+
+ context 'initial creation' do
+ let(:oldrev) { Gitlab::Git::EMPTY_TREE_ID }
+ let(:newrev) { TestEnv::BRANCH_SHA["snippet/single-file"] }
+ let(:ref) { "refs/heads/snippet/single-file" }
+
+ it 'allows creation' do
+ expect { subject.validate! }.not_to raise_error
+ end
+ end
+
+ where(:old, :new, :valid, :message) do
+ 'single-file' | 'edit-file' | true | nil
+ 'single-file' | 'multiple-files' | false | 'The repository can contain at most 1 file(s).'
+ 'single-file' | 'no-files' | false | 'The repository must contain at least 1 file.'
+ 'edit-file' | 'rename-and-edit-file' | true | nil
+ end
+
+ with_them do
+ let(:oldrev) { TestEnv::BRANCH_SHA["snippet/#{old}"] }
+ let(:newrev) { TestEnv::BRANCH_SHA["snippet/#{new}"] }
+ let(:ref) { "refs/heads/snippet/#{new}" }
+
+ it "verifies" do
+ if valid
+ expect { subject.validate! }.not_to raise_error
+ else
+ expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, message)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/checks/snippet_check_spec.rb b/spec/lib/gitlab/checks/snippet_check_spec.rb
index 43c69ab7042..3eee5ccfc0a 100644
--- a/spec/lib/gitlab/checks/snippet_check_spec.rb
+++ b/spec/lib/gitlab/checks/snippet_check_spec.rb
@@ -10,16 +10,16 @@ describe Gitlab::Checks::SnippetCheck do
subject { Gitlab::Checks::SnippetCheck.new(changes, logger: logger) }
- describe '#exec' do
+ describe '#validate!' do
it 'does not raise any error' do
- expect { subject.exec }.not_to raise_error
+ expect { subject.validate! }.not_to raise_error
end
context 'trying to delete the branch' do
let(:newrev) { '0000000000000000000000000000000000000000' }
it 'raises an error' do
- expect { subject.exec }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You can not create or delete branches.')
+ expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You can not create or delete branches.')
end
end
@@ -28,14 +28,14 @@ describe Gitlab::Checks::SnippetCheck do
let(:ref) { 'refs/heads/feature' }
it 'raises an error' do
- expect { subject.exec }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You can not create or delete branches.')
+ expect { subject.validate! }.to raise_error(Gitlab::GitAccess::ForbiddenError, 'You can not create or delete branches.')
end
context "when branch is 'master'" do
let(:ref) { 'refs/heads/master' }
it "allows the operation" do
- expect { subject.exec }.not_to raise_error
+ expect { subject.validate! }.not_to raise_error
end
end
end