diff options
Diffstat (limited to 'spec/support/shared_examples/models/concerns')
3 files changed, 5 insertions, 122 deletions
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 deleted file mode 100644 index 76339837351..00000000000 --- a/spec/support/shared_examples/models/concerns/blob_replicator_strategy_shared_examples.rb +++ /dev/null @@ -1,117 +0,0 @@ -# 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 - - it 'schedules the checksum calculation if needed' do - expect(Geo::BlobVerificationPrimaryWorker).to receive(:perform_async) - expect(replicator).to receive(:needs_checksum?).and_return(true) - - replicator.handle_after_create_commit - end - - it 'does not schedule the checksum calculation if feature flag is disabled' do - stub_feature_flags(geo_self_service_framework: false) - - expect(Geo::BlobVerificationPrimaryWorker).not_to receive(:perform_async) - allow(replicator).to receive(:needs_checksum?).and_return(true) - - replicator.handle_after_create_commit - end - end - - describe '#calculate_checksum!' do - it 'calculates the checksum' do - model_record.save! - - replicator.calculate_checksum! - - expect(model_record.reload.verification_checksum).not_to be_nil - expect(model_record.reload.verified_at).not_to be_nil - end - - it 'saves the error message and increments retry counter' do - model_record.save! - - allow(model_record).to receive(:calculate_checksum!) do - raise StandardError.new('Failure to calculate checksum') - end - - replicator.calculate_checksum! - - expect(model_record.reload.verification_failure).to eq 'Failure to calculate checksum' - expect(model_record.verification_retry_count).to be 1 - 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_event_created - 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.class.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/support/shared_examples/models/concerns/has_repository_shared_examples.rb b/spec/support/shared_examples/models/concerns/has_repository_shared_examples.rb index 30c8c7d0fe5..f37ef3533c3 100644 --- a/spec/support/shared_examples/models/concerns/has_repository_shared_examples.rb +++ b/spec/support/shared_examples/models/concerns/has_repository_shared_examples.rb @@ -148,18 +148,18 @@ RSpec.shared_examples 'model with repository' do expect(subject).to eq('picked') end - it 'picks from the latest available storage', :request_store do + it 'picks from the available storages based on weight', :request_store do stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') Gitlab::CurrentSettings.expire_current_application_settings Gitlab::CurrentSettings.current_application_settings settings = ApplicationSetting.last - settings.repository_storages = %w(picked) + settings.repository_storages_weighted = { 'picked' => 100, 'default' => 0 } settings.save! - expect(Gitlab::CurrentSettings.repository_storages).to eq(%w(default)) + expect(Gitlab::CurrentSettings.repository_storages_weighted).to eq({ 'default' => 100 }) expect(subject).to eq('picked') - expect(Gitlab::CurrentSettings.repository_storages).to eq(%w(picked)) + expect(Gitlab::CurrentSettings.repository_storages_weighted).to eq({ 'default' => 0, 'picked' => 100 }) end end end diff --git a/spec/support/shared_examples/models/concerns/limitable_shared_examples.rb b/spec/support/shared_examples/models/concerns/limitable_shared_examples.rb index 4bcea36fd42..d21823661f8 100644 --- a/spec/support/shared_examples/models/concerns/limitable_shared_examples.rb +++ b/spec/support/shared_examples/models/concerns/limitable_shared_examples.rb @@ -26,7 +26,7 @@ RSpec.shared_examples 'includes Limitable concern' do subject.dup.save end - it 'cannot create new models exceding the plan limits' do + it 'cannot create new models exceeding the plan limits' do expect { subject.save }.not_to change { described_class.count } expect(subject.errors[:base]).to contain_exactly("Maximum number of #{subject.class.limit_name.humanize(capitalize: false)} (1) exceeded") end |