Improve spec for Geo::FileDownloadDispatchWorker

parent ab4a98ed
...@@ -76,35 +76,39 @@ describe Geo::FileDownloadDispatchWorker do ...@@ -76,35 +76,39 @@ describe Geo::FileDownloadDispatchWorker do
end end
context 'when node has namespace restrictions' do context 'when node has namespace restrictions' do
let(:group_1) { create(:group) } let(:synced_group) { create(:group) }
let!(:project_1) { create(:project, group: group_1) } let!(:project_in_synced_group) { create(:project, group: synced_group) }
let!(:project_2) { create(:project) } let!(:unsynced_project) { create(:project) }
before do before do
allow(ProjectCacheWorker).to receive(:perform_async).and_return(true) allow(ProjectCacheWorker).to receive(:perform_async).and_return(true)
allow_any_instance_of(described_class).to receive(:over_time?).and_return(false) allow_any_instance_of(described_class).to receive(:over_time?).and_return(false)
secondary.update_attribute(:namespaces, [group_1]) secondary.update_attribute(:namespaces, [synced_group])
end end
it 'does not perform GeoFileDownloadWorker for LFS object that does not belong to selected namespaces to replicate' do it 'does not perform GeoFileDownloadWorker for LFS object that does not belong to selected namespaces to replicate' do
create(:lfs_objects_project, project: project_1) lfs_objec_in_synced_group = create(:lfs_objects_project, project: project_in_synced_group)
create(:lfs_objects_project, project: project_2) create(:lfs_objects_project, project: unsynced_project)
expect(GeoFileDownloadWorker).to receive(:perform_async).once.and_return(spy) expect(GeoFileDownloadWorker).to receive(:perform_async)
.with(:lfs, lfs_objec_in_synced_group.lfs_object_id).once.and_return(spy)
subject.perform subject.perform
end end
it 'does not perform GeoFileDownloadWorker for upload objects that do not belong to selected namespaces to replicate' do it 'does not perform GeoFileDownloadWorker for upload objects that do not belong to selected namespaces to replicate' do
avatar = fixture_file_upload(Rails.root.join('spec/fixtures/dk.png')) avatar = fixture_file_upload(Rails.root.join('spec/fixtures/dk.png'))
create(:upload, model: group_1, path: avatar) avatar_in_synced_group = create(:upload, model: synced_group, path: avatar)
create(:upload, model: create(:group), path: avatar) create(:upload, model: create(:group), path: avatar)
create(:upload, model: project_1, path: avatar) avatar_in_project_in_synced_group = create(:upload, model: project_in_synced_group, path: avatar)
create(:upload, model: project_2, path: avatar) create(:upload, model: unsynced_project, path: avatar)
create(:note, :with_attachment)
expect(GeoFileDownloadWorker).to receive(:perform_async).exactly(3).times.and_return(spy) expect(GeoFileDownloadWorker).to receive(:perform_async)
.with('avatar', avatar_in_project_in_synced_group.id).once.and_return(spy)
expect(GeoFileDownloadWorker).to receive(:perform_async)
.with('avatar', avatar_in_synced_group.id).once.and_return(spy)
subject.perform subject.perform
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment