diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /spec/models/lfs_object_spec.rb | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'spec/models/lfs_object_spec.rb')
-rw-r--r-- | spec/models/lfs_object_spec.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/models/lfs_object_spec.rb b/spec/models/lfs_object_spec.rb index a0f633218b0..5210709a468 100644 --- a/spec/models/lfs_object_spec.rb +++ b/spec/models/lfs_object_spec.rb @@ -178,4 +178,34 @@ RSpec.describe LfsObject do expect(described_class.calculate_oid(path)).to eq expected end end + + context 'when an lfs object is associated with a project' do + let!(:lfs_object) { create(:lfs_object) } + let!(:lfs_object_project) { create(:lfs_objects_project, lfs_object: lfs_object) } + + it 'cannot be deleted' do + expect { lfs_object.destroy! }.to raise_error(ActiveRecord::InvalidForeignKey) + + lfs_object_project.destroy! + + expect { lfs_object.destroy! }.not_to raise_error + end + end + + describe '.unreferenced_in_batches' do + let!(:unreferenced_lfs_object1) { create(:lfs_object, oid: '1') } + let!(:referenced_lfs_object) { create(:lfs_objects_project).lfs_object } + let!(:unreferenced_lfs_object2) { create(:lfs_object, oid: '2') } + + it 'returns lfs objects in batches' do + stub_const('LfsObject::BATCH_SIZE', 1) + + batches = [] + described_class.unreferenced_in_batches { |batch| batches << batch } + + expect(batches.size).to eq(2) + expect(batches.first).to eq([unreferenced_lfs_object2]) + expect(batches.last).to eq([unreferenced_lfs_object1]) + end + end end |