summaryrefslogtreecommitdiff
path: root/spec/initializers
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2018-12-27 15:46:57 +0100
committerDouwe Maan <douwe@selenight.nl>2018-12-27 15:59:19 +0100
commit82370345302426c9d854e78c2a32a56ab4eb6c47 (patch)
tree38447a22b8aeafab9e69ac70e6d6d1712e0a38c9 /spec/initializers
parentfd27be93489d7485754895ffef161431bf268b3d (diff)
downloadgitlab-ce-82370345302426c9d854e78c2a32a56ab4eb6c47.tar.gz
Support both 0 and NULL lock_versions
Diffstat (limited to 'spec/initializers')
-rw-r--r--spec/initializers/active_record_locking_spec.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/spec/initializers/active_record_locking_spec.rb b/spec/initializers/active_record_locking_spec.rb
new file mode 100644
index 00000000000..5a16aef78e6
--- /dev/null
+++ b/spec/initializers/active_record_locking_spec.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'ActiveRecord locking' do
+ let(:issue) { create(:issue) }
+
+ shared_examples 'locked model' do
+ before do
+ issue.update_column(:lock_version, start_lock_version)
+ end
+
+ it 'can be updated' do
+ issue.update(title: "New title")
+
+ expect(issue.reload.lock_version).to eq(new_lock_version)
+ end
+
+ it 'can be deleted' do
+ expect { issue.destroy }.to change { Issue.count }.by(-1)
+ end
+ end
+
+ context 'when lock_version is NULL' do
+ let(:start_lock_version) { nil }
+ let(:new_lock_version) { 1 }
+
+ it_behaves_like 'locked model'
+ end
+
+ context 'when lock_version is 0' do
+ let(:start_lock_version) { 0 }
+ let(:new_lock_version) { 1 }
+
+ it_behaves_like 'locked model'
+ end
+
+ context 'when lock_version is 1' do
+ let(:start_lock_version) { 1 }
+ let(:new_lock_version) { 2 }
+
+ it_behaves_like 'locked model'
+ end
+end