summaryrefslogtreecommitdiff
path: root/spec/models/concerns
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2017-02-24 16:04:06 +0000
committerDouwe Maan <douwe@gitlab.com>2017-02-24 16:04:06 +0000
commita0da03d95c34d8d5b9c81d29cfabbf806a036e16 (patch)
tree058f4be5e283eecfcfa8030f825ce37d7ac203af /spec/models/concerns
parentfaaca5e191f9fe3894ad7587b42495fcbcab9328 (diff)
parent53aa043724a0395a2f95f41b8f3fb4c308691874 (diff)
downloadgitlab-ce-a0da03d95c34d8d5b9c81d29cfabbf806a036e16.tar.gz
Merge branch '12726-preserve-issues-after-deleting-users' into 'master'
Deleting a user shouldn't delete associated issues. Closes #12726 See merge request !7393
Diffstat (limited to 'spec/models/concerns')
-rw-r--r--spec/models/concerns/uniquify_spec.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/models/concerns/uniquify_spec.rb b/spec/models/concerns/uniquify_spec.rb
new file mode 100644
index 00000000000..83187d732e4
--- /dev/null
+++ b/spec/models/concerns/uniquify_spec.rb
@@ -0,0 +1,33 @@
+require 'spec_helper'
+
+describe Uniquify, models: true do
+ let(:uniquify) { described_class.new }
+
+ describe "#string" do
+ it 'returns the given string if it does not exist' do
+ result = uniquify.string('test_string') { |s| false }
+
+ expect(result).to eq('test_string')
+ end
+
+ it 'returns the given string with a counter attached if the string exists' do
+ result = uniquify.string('test_string') { |s| s == 'test_string' }
+
+ expect(result).to eq('test_string1')
+ end
+
+ it 'increments the counter for each candidate string that also exists' do
+ result = uniquify.string('test_string') { |s| s == 'test_string' || s == 'test_string1' }
+
+ expect(result).to eq('test_string2')
+ end
+
+ it 'allows passing in a base function that defines the location of the counter' do
+ result = uniquify.string(-> (counter) { "test_#{counter}_string" }) do |s|
+ s == 'test__string'
+ end
+
+ expect(result).to eq('test_1_string')
+ end
+ end
+end