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/ci/secure_file_spec.rb')
-rw-r--r--spec/models/ci/secure_file_spec.rb32
1 files changed, 24 insertions, 8 deletions
diff --git a/spec/models/ci/secure_file_spec.rb b/spec/models/ci/secure_file_spec.rb
index 4382385aaf5..f92db3fe8db 100644
--- a/spec/models/ci/secure_file_spec.rb
+++ b/spec/models/ci/secure_file_spec.rb
@@ -3,14 +3,14 @@
require 'spec_helper'
RSpec.describe Ci::SecureFile do
- let(:sample_file) { fixture_file('ci_secure_files/upload-keystore.jks') }
-
- subject { create(:ci_secure_file) }
-
before do
stub_ci_secure_file_object_storage
end
+ let(:sample_file) { fixture_file('ci_secure_files/upload-keystore.jks') }
+
+ subject { create(:ci_secure_file, file: CarrierWaveStringFile.new(sample_file)) }
+
it { is_expected.to be_a FileStoreMounter }
it { is_expected.to belong_to(:project).required }
@@ -27,6 +27,26 @@ RSpec.describe Ci::SecureFile do
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_presence_of(:permissions) }
it { is_expected.to validate_presence_of(:project_id) }
+ context 'unique filename' do
+ let_it_be(:project1) { create(:project) }
+
+ it 'ensures the file name is unique within a given project' do
+ file1 = create(:ci_secure_file, project: project1, name: 'file1')
+ expect do
+ create(:ci_secure_file, project: project1, name: 'file1')
+ end.to raise_error(ActiveRecord::RecordInvalid, 'Validation failed: Name has already been taken')
+
+ expect(project1.secure_files.where(name: 'file1').count).to be 1
+ expect(project1.secure_files.find_by(name: 'file1').id).to eq(file1.id)
+ end
+
+ it 'allows duplicate file names in different projects' do
+ create(:ci_secure_file, project: project1)
+ expect do
+ create(:ci_secure_file, project: create(:project))
+ end.not_to raise_error
+ end
+ end
end
describe '#permissions' do
@@ -37,8 +57,6 @@ RSpec.describe Ci::SecureFile do
describe '#checksum' do
it 'computes SHA256 checksum on the file before encrypted' do
- subject.file = CarrierWaveStringFile.new(sample_file)
- subject.save!
expect(subject.checksum).to eq(Digest::SHA256.hexdigest(sample_file))
end
end
@@ -51,8 +69,6 @@ RSpec.describe Ci::SecureFile do
describe '#file' do
it 'returns the saved file' do
- subject.file = CarrierWaveStringFile.new(sample_file)
- subject.save!
expect(Base64.encode64(subject.file.read)).to eq(Base64.encode64(sample_file))
end
end