summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-03-05 03:07:52 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-03-05 03:07:52 +0000
commita0c1ba61c8e8c9195e3ad4deefc5c4cb5c6a1501 (patch)
tree0731210fac047fdfb04a8e907701e0efab8c897e /spec
parent77237c5a6b9044f58beabc54d3589e5fa09cbfba (diff)
downloadgitlab-ce-a0c1ba61c8e8c9195e3ad4deefc5c4cb5c6a1501.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/models/project_spec.rb55
-rw-r--r--spec/requests/lfs_http_spec.rb32
-rw-r--r--spec/support/shared_examples/models/concerns/blob_replicator_strategy_shared_examples.rb77
-rw-r--r--spec/workers/repository_fork_worker_spec.rb2
4 files changed, 155 insertions, 11 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 56f4c68a913..ca6ff8606f5 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -5692,6 +5692,53 @@ describe Project do
end
end
+ describe '#all_lfs_objects_oids' do
+ let(:project) { create(:project) }
+ let(:lfs_object) { create(:lfs_object) }
+ let(:another_lfs_object) { create(:lfs_object) }
+
+ subject { project.all_lfs_objects_oids }
+
+ context 'when project has associated LFS objects' do
+ before do
+ create(:lfs_objects_project, lfs_object: lfs_object, project: project)
+ create(:lfs_objects_project, lfs_object: another_lfs_object, project: project)
+ end
+
+ it 'returns OIDs of LFS objects' do
+ expect(subject).to match_array([lfs_object.oid, another_lfs_object.oid])
+ end
+
+ context 'and there are specified oids' do
+ subject { project.all_lfs_objects_oids(oids: [lfs_object.oid]) }
+
+ it 'returns OIDs of LFS objects that match specified oids' do
+ expect(subject).to eq([lfs_object.oid])
+ end
+ end
+ end
+
+ context 'when fork has associated LFS objects to itself and source' do
+ let(:source) { create(:project) }
+ let(:project) { fork_project(source) }
+
+ before do
+ create(:lfs_objects_project, lfs_object: lfs_object, project: source)
+ create(:lfs_objects_project, lfs_object: another_lfs_object, project: project)
+ end
+
+ it 'returns OIDs of LFS objects' do
+ expect(subject).to match_array([lfs_object.oid, another_lfs_object.oid])
+ end
+ end
+
+ context 'when project has no associated LFS objects' do
+ it 'returns empty array' do
+ expect(subject).to be_empty
+ end
+ end
+ end
+
describe '#lfs_objects_oids' do
let(:project) { create(:project) }
let(:lfs_object) { create(:lfs_object) }
@@ -5708,6 +5755,14 @@ describe Project do
it 'returns OIDs of LFS objects' do
expect(subject).to match_array([lfs_object.oid, another_lfs_object.oid])
end
+
+ context 'and there are specified oids' do
+ subject { project.lfs_objects_oids(oids: [lfs_object.oid]) }
+
+ it 'returns OIDs of LFS objects that match specified oids' do
+ expect(subject).to eq([lfs_object.oid])
+ end
+ end
end
context 'when project has no associated LFS objects' do
diff --git a/spec/requests/lfs_http_spec.rb b/spec/requests/lfs_http_spec.rb
index c6403a6ab75..c71b803a7ab 100644
--- a/spec/requests/lfs_http_spec.rb
+++ b/spec/requests/lfs_http_spec.rb
@@ -690,22 +690,34 @@ describe 'Git LFS API and storage' do
end
context 'when pushing an LFS object that already exists' do
+ shared_examples_for 'batch upload with existing LFS object' do
+ it_behaves_like 'LFS http 200 response'
+
+ it 'responds with links the object to the project' do
+ expect(json_response['objects']).to be_kind_of(Array)
+ expect(json_response['objects'].first).to include(sample_object)
+ expect(lfs_object.projects.pluck(:id)).not_to include(project.id)
+ expect(lfs_object.projects.pluck(:id)).to include(other_project.id)
+ expect(json_response['objects'].first['actions']['upload']['href']).to eq(objects_url(project, sample_oid, sample_size))
+ expect(json_response['objects'].first['actions']['upload']['header']).to include('Content-Type' => 'application/octet-stream')
+ end
+
+ it_behaves_like 'process authorization header', renew_authorization: true
+ end
+
let(:update_lfs_permissions) do
other_project.lfs_objects << lfs_object
end
- it_behaves_like 'LFS http 200 response'
-
- it 'responds with links the object to the project' do
- expect(json_response['objects']).to be_kind_of(Array)
- expect(json_response['objects'].first).to include(sample_object)
- expect(lfs_object.projects.pluck(:id)).not_to include(project.id)
- expect(lfs_object.projects.pluck(:id)).to include(other_project.id)
- expect(json_response['objects'].first['actions']['upload']['href']).to eq(objects_url(project, sample_oid, sample_size))
- expect(json_response['objects'].first['actions']['upload']['header']).to include('Content-Type' => 'application/octet-stream')
+ context 'in another project' do
+ it_behaves_like 'batch upload with existing LFS object'
end
- it_behaves_like 'process authorization header', renew_authorization: true
+ context 'in source of fork project' do
+ let(:project) { fork_project(other_project) }
+
+ it_behaves_like 'batch upload with existing LFS object'
+ end
end
context 'when pushing a LFS object that does not exist' do
diff --git a/spec/support/shared_examples/models/concerns/blob_replicator_strategy_shared_examples.rb b/spec/support/shared_examples/models/concerns/blob_replicator_strategy_shared_examples.rb
new file mode 100644
index 00000000000..ebe464735c5
--- /dev/null
+++ b/spec/support/shared_examples/models/concerns/blob_replicator_strategy_shared_examples.rb
@@ -0,0 +1,77 @@
+# frozen_string_literal: true
+
+# Include these shared examples in specs of Replicators that include
+# BlobReplicatorStrategy.
+#
+# A let variable called model_record should be defined in the spec. It should be
+# a valid, unpersisted instance of the model class.
+#
+RSpec.shared_examples 'a blob replicator' do
+ include EE::GeoHelpers
+
+ let_it_be(:primary) { create(:geo_node, :primary) }
+ let_it_be(:secondary) { create(:geo_node) }
+
+ subject(:replicator) { model_record.replicator }
+
+ before do
+ stub_current_geo_node(primary)
+ end
+
+ describe '#handle_after_create_commit' do
+ it 'creates a Geo::Event' do
+ expect do
+ replicator.handle_after_create_commit
+ end.to change { ::Geo::Event.count }.by(1)
+
+ expect(::Geo::Event.last.attributes).to include(
+ "replicable_name" => replicator.replicable_name, "event_name" => "created", "payload" => { "model_record_id" => replicator.model_record.id })
+ end
+ end
+
+ describe '#consume_created_event' do
+ it 'invokes Geo::BlobDownloadService' do
+ service = double(:service)
+
+ expect(service).to receive(:execute)
+ expect(::Geo::BlobDownloadService).to receive(:new).with(replicator: replicator).and_return(service)
+
+ replicator.consume_created_event
+ end
+ end
+
+ describe '#carrierwave_uploader' do
+ it 'is implemented' do
+ expect do
+ replicator.carrierwave_uploader
+ end.not_to raise_error
+ end
+ end
+
+ describe '#model' do
+ let(:invoke_model) { replicator.send(:model) }
+
+ it 'is implemented' do
+ expect do
+ invoke_model
+ end.not_to raise_error
+ end
+
+ it 'is a Class' do
+ expect(invoke_model).to be_a(Class)
+ end
+
+ # For convenience (and reliability), instead of asking developers to include shared examples on each model spec as well
+ context 'replicable model' do
+ it 'defines #replicator' do
+ expect(model_record).to respond_to(:replicator)
+ end
+
+ it 'invokes replicator.handle_after_create_commit on create' do
+ expect(replicator).to receive(:handle_after_create_commit)
+
+ model_record.save!
+ end
+ end
+ end
+end
diff --git a/spec/workers/repository_fork_worker_spec.rb b/spec/workers/repository_fork_worker_spec.rb
index 01104049404..c0fb0a40025 100644
--- a/spec/workers/repository_fork_worker_spec.rb
+++ b/spec/workers/repository_fork_worker_spec.rb
@@ -83,7 +83,7 @@ describe RepositoryForkWorker do
it 'calls Projects::LfsPointers::LfsLinkService#execute with OIDs of source project LFS objects' do
expect_fork_repository.and_return(true)
expect_next_instance_of(Projects::LfsPointers::LfsLinkService) do |service|
- expect(service).to receive(:execute).with(project.lfs_objects_oids)
+ expect(service).to receive(:execute).with(project.all_lfs_objects_oids)
end
perform!