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/models/repository_spec.rb')
-rw-r--r--spec/models/repository_spec.rb100
1 files changed, 98 insertions, 2 deletions
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index af7457c78e2..2265d1b39af 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -3845,11 +3845,50 @@ RSpec.describe Repository, feature_category: :source_code_management do
end
context 'when a Gitlab::Git::CommandError is raised' do
- it 'returns nil' do
+ before do
expect(repository.raw_repository)
.to receive(:get_patch_id).and_raise(Gitlab::Git::CommandError)
+ end
- expect(repository.get_patch_id('HEAD', "f" * 40)).to be_nil
+ it 'returns nil' do
+ expect(repository.get_patch_id('HEAD', 'HEAD')).to be_nil
+ end
+
+ it 'reports the exception' do
+ expect(Gitlab::ErrorTracking)
+ .to receive(:track_exception)
+ .with(
+ instance_of(Gitlab::Git::CommandError),
+ project_id: repository.project.id,
+ old_revision: 'HEAD',
+ new_revision: 'HEAD'
+ )
+
+ repository.get_patch_id('HEAD', 'HEAD')
+ end
+ end
+
+ context 'when a Gitlab::Git::Repository::NoRepository is raised' do
+ before do
+ expect(repository.raw_repository)
+ .to receive(:get_patch_id).and_raise(Gitlab::Git::Repository::NoRepository)
+ end
+
+ it 'returns nil' do
+ expect(repository.get_patch_id('HEAD', 'f' * 40)).to be_nil
+ end
+
+ it 'reports the exception' do
+ expect(Gitlab::ErrorTracking)
+ .to receive(:track_exception)
+ .with(
+ instance_of(Gitlab::Git::Repository::NoRepository),
+ project_id: repository.project.id,
+ old_revision: 'HEAD',
+ new_revision: 'HEAD'
+ )
+
+ repository.get_patch_id('HEAD', 'HEAD')
end
end
end
@@ -3942,4 +3981,61 @@ RSpec.describe Repository, feature_category: :source_code_management do
end
end
end
+
+ describe '#get_file_attributes' do
+ let(:project) do
+ create(:project, :custom_repo, files: {
+ '.gitattributes' => gitattr_content,
+ 'file1.txt' => 'test content'
+ })
+ end
+
+ let(:gitattr_content) { '' }
+ let(:rev) { 'master' }
+ let(:paths) { ['file1.txt', 'README'] }
+ let(:attrs) { %w[text diff] }
+
+ subject(:file_attributes) { repository.get_file_attributes(rev, paths, attrs) }
+
+ context 'when the given attributes are defined' do
+ let(:gitattr_content) { "* -text\n*.txt text\n*.txt diff" }
+
+ it 'returns expected attributes' do
+ expect(file_attributes.count).to eq 3
+ expect(file_attributes[0]).to eq({ path: 'file1.txt', attribute: 'text', value: 'set' })
+ expect(file_attributes[1]).to eq({ path: 'file1.txt', attribute: 'diff', value: 'set' })
+ expect(file_attributes[2]).to eq({ path: 'README', attribute: 'text', value: 'unset' })
+ end
+ end
+
+ context 'when the attribute is not defined for a given file' do
+ let(:gitattr_content) { "*.txt text" }
+
+ let(:rev) { 'master' }
+ let(:paths) { ['README'] }
+ let(:attrs) { ['text'] }
+
+ it 'returns an empty array' do
+ expect(file_attributes).to eq []
+ end
+ end
+
+ context 'when revision is an empty string' do
+ let(:rev) { '' }
+
+ it { expect { file_attributes }.to raise_error(ArgumentError) }
+ end
+
+ context 'when paths list is empty' do
+ let(:paths) { [] }
+
+ it { expect { file_attributes }.to raise_error(ArgumentError) }
+ end
+
+ context 'when attributes list is empty' do
+ let(:attrs) { [] }
+
+ it { expect { file_attributes }.to raise_error(ArgumentError) }
+ end
+ end
end