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:
Diffstat (limited to 'spec/models/shard_spec.rb')
-rw-r--r--spec/models/shard_spec.rb20
1 files changed, 11 insertions, 9 deletions
diff --git a/spec/models/shard_spec.rb b/spec/models/shard_spec.rb
index a9d11f4290c..38729fa1758 100644
--- a/spec/models/shard_spec.rb
+++ b/spec/models/shard_spec.rb
@@ -33,19 +33,21 @@ RSpec.describe Shard do
expect(result.name).to eq('foo')
end
- it 'retries if creation races' do
+ it 'returns existing record if creation races' do
+ shard_created_by_others = double(described_class)
+
expect(described_class)
- .to receive(:find_or_create_by)
- .with(name: 'default')
- .and_raise(ActiveRecord::RecordNotUnique, 'fail')
- .once
+ .to receive(:find_by)
+ .with(name: 'new_shard')
+ .and_return(nil, shard_created_by_others)
expect(described_class)
- .to receive(:find_or_create_by)
- .with(name: 'default')
- .and_call_original
+ .to receive(:create)
+ .with(name: 'new_shard')
+ .and_raise(ActiveRecord::RecordNotUnique, 'fail')
+ .once
- expect(described_class.by_name('default')).to eq(default_shard)
+ expect(described_class.by_name('new_shard')).to eq(shard_created_by_others)
end
end
end