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:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 18:09:30 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-07 18:09:30 +0300
commitc6b3ec3f56fa32a0e0ed3de0d0878d25f1adaddf (patch)
tree967afee9a510ff9dd503ebd83706dc760ec2e3ed /spec/support
parent903ccf7c93eb9490c76857bffe744249cc07de09 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/shared_examples/models/update_highest_role_shared_examples.rb52
-rw-r--r--spec/support/shared_examples/models/versioned_description_shared_examples.rb52
2 files changed, 69 insertions, 35 deletions
diff --git a/spec/support/shared_examples/models/update_highest_role_shared_examples.rb b/spec/support/shared_examples/models/update_highest_role_shared_examples.rb
new file mode 100644
index 00000000000..34c4ada1718
--- /dev/null
+++ b/spec/support/shared_examples/models/update_highest_role_shared_examples.rb
@@ -0,0 +1,52 @@
+# frozen_string_literal: true
+
+# requires a subject and a user_id
+RSpec.shared_examples 'update highest role with exclusive lease' do
+ include ExclusiveLeaseHelpers
+
+ let(:lease_key) { "update_highest_role:#{user_id}" }
+
+ before do
+ allow(Gitlab::ExclusiveLease).to receive(:new).and_call_original
+ end
+
+ context 'when lease is obtained', :clean_gitlab_redis_shared_state do
+ it 'takes the lease but does not release it', :aggregate_failures do
+ expect_to_obtain_exclusive_lease(lease_key, 'uuid', timeout: described_class::HIGHEST_ROLE_LEASE_TIMEOUT)
+ expect(Gitlab::ExclusiveLease).not_to receive(:cancel).with(lease_key, 'uuid')
+
+ subject
+ end
+
+ it 'schedules a job in the future', :aggregate_failures do
+ allow_next_instance_of(Gitlab::ExclusiveLease) do |instance|
+ allow(instance).to receive(:try_obtain).and_return('uuid')
+ end
+
+ expect(UpdateHighestRoleWorker).to receive(:perform_in).with(described_class::HIGHEST_ROLE_JOB_DELAY, user_id).and_call_original
+
+ expect { subject }.to change(UpdateHighestRoleWorker.jobs, :size).by(1)
+ end
+ end
+
+ context 'when lease cannot be obtained', :clean_gitlab_redis_shared_state do
+ it 'only schedules one job' do
+ stub_exclusive_lease_taken(lease_key, timeout: described_class::HIGHEST_ROLE_LEASE_TIMEOUT)
+
+ expect { subject }.not_to change(UpdateHighestRoleWorker.jobs, :size)
+ end
+ end
+end
+
+# requires a subject and a user_id
+RSpec.shared_examples 'does not update the highest role' do
+ it 'does not obtain an exclusive lease' do
+ allow(Gitlab::ExclusiveLease).to receive(:new).and_call_original
+
+ lease = stub_exclusive_lease("update_highest_role:#{user_id}", 'uuid', timeout: described_class::HIGHEST_ROLE_LEASE_TIMEOUT)
+
+ expect(lease).not_to receive(:try_obtain)
+
+ subject
+ end
+end
diff --git a/spec/support/shared_examples/models/versioned_description_shared_examples.rb b/spec/support/shared_examples/models/versioned_description_shared_examples.rb
index 59124af19ec..8fee2494af7 100644
--- a/spec/support/shared_examples/models/versioned_description_shared_examples.rb
+++ b/spec/support/shared_examples/models/versioned_description_shared_examples.rb
@@ -9,54 +9,36 @@ RSpec.shared_examples 'versioned description' do
let(:factory_name) { described_class.name.underscore.to_sym }
let!(:model) { create(factory_name, description: 'Original description') }
- context 'when feature is enabled' do
+ context 'when description was changed' do
before do
- stub_feature_flags(save_description_versions: true)
+ model.update!(description: 'New description')
end
- context 'when description was changed' do
- before do
- model.update!(description: 'New description')
- end
-
- it 'saves the old and new description for the first update' do
- expect(model.description_versions.first.description).to eq('Original description')
- expect(model.description_versions.last.description).to eq('New description')
- end
-
- it 'only saves the new description for subsequent updates' do
- expect { model.update!(description: 'Another description') }.to change { model.description_versions.count }.by(1)
-
- expect(model.description_versions.last.description).to eq('Another description')
- end
+ it 'saves the old and new description for the first update' do
+ expect(model.description_versions.first.description).to eq('Original description')
+ expect(model.description_versions.last.description).to eq('New description')
+ end
- it 'sets the new description version to `saved_description_version`' do
- expect(model.saved_description_version).to eq(model.description_versions.last)
- end
+ it 'only saves the new description for subsequent updates' do
+ expect { model.update!(description: 'Another description') }.to change { model.description_versions.count }.by(1)
- it 'clears `saved_description_version` after another save that does not change description' do
- model.save!
+ expect(model.description_versions.last.description).to eq('Another description')
+ end
- expect(model.saved_description_version).to be_nil
- end
+ it 'sets the new description version to `saved_description_version`' do
+ expect(model.saved_description_version).to eq(model.description_versions.last)
end
- context 'when description was not changed' do
- it 'does not save any description version' do
- expect { model.save! }.not_to change { model.description_versions.count }
+ it 'clears `saved_description_version` after another save that does not change description' do
+ model.save!
- expect(model.saved_description_version).to be_nil
- end
+ expect(model.saved_description_version).to be_nil
end
end
- context 'when feature is disabled' do
- before do
- stub_feature_flags(save_description_versions: false)
- end
-
+ context 'when description was not changed' do
it 'does not save any description version' do
- expect { model.update!(description: 'New description') }.not_to change { model.description_versions.count }
+ expect { model.save! }.not_to change { model.description_versions.count }
expect(model.saved_description_version).to be_nil
end