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
path: root/spec
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2019-02-05 17:41:00 +0300
committerSean McGivern <sean@gitlab.com>2019-02-05 17:41:00 +0300
commitd6be539bf1be90d81ac4ad7aac94aedebac10c43 (patch)
tree96993829bc0d4437ddf6363afa3aed710a824ea5 /spec
parent5dc15b2a3b5fee22bb905c1e178e3ea6300d02c3 (diff)
parentccd8a9b2821c964b85533c253430041712ef195e (diff)
Merge branch 'bvl-codeowner-rules-model-ce' into 'master'
Adds helper for `find_or_create_by` in transaction See merge request gitlab-org/gitlab-ce!24913
Diffstat (limited to 'spec')
-rw-r--r--spec/models/application_record_spec.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/spec/models/application_record_spec.rb b/spec/models/application_record_spec.rb
index 68aed387bfc..ca23f581fdc 100644
--- a/spec/models/application_record_spec.rb
+++ b/spec/models/application_record_spec.rb
@@ -10,4 +10,14 @@ describe ApplicationRecord do
expect(User.id_in(records.last(2).map(&:id))).to eq(records.last(2))
end
end
+
+ describe '#safe_find_or_create_by' do
+ it 'creates the user avoiding race conditions' do
+ expect(Suggestion).to receive(:find_or_create_by).and_raise(ActiveRecord::RecordNotUnique)
+ allow(Suggestion).to receive(:find_or_create_by).and_call_original
+
+ expect { Suggestion.safe_find_or_create_by(build(:suggestion).attributes) }
+ .to change { Suggestion.count }.by(1)
+ end
+ end
end