Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
9000626a
Commit
9000626a
authored
Apr 19, 2018
by
Jacopo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moves Uniquify counter in the initializer
parent
6ae3098e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
13 deletions
+20
-13
app/models/concerns/uniquify.rb
app/models/concerns/uniquify.rb
+16
-11
app/models/issue.rb
app/models/issue.rb
+1
-1
spec/models/concerns/uniquify_spec.rb
spec/models/concerns/uniquify_spec.rb
+3
-1
No files found.
app/models/concerns/uniquify.rb
View file @
9000626a
# Uniquify
#
# Return a version of the given 'base' string that is unique
# by appending a counter to it. Uniqueness is determined by
# repeated calls to the passed block.
#
# You can pass an initial value for the counter, if not given
# counting starts from 1.
#
# If `base` is a function/proc, we expect that calling it with a
# candidate counter returns a string to test/return.
class
Uniquify
# Return a version of the given 'base' string that is unique
# by appending a counter to it. Uniqueness is determined by
# repeated calls to the passed block.
#
# You can pass an initial value for the counter, if not given
# counting starts from 1.
#
# If `base` is a function/proc, we expect that calling it with a
# candidate counter returns a string to test/return.
def
string
(
base
,
counter
=
nil
)
@base
=
base
def
initialize
(
counter
=
nil
)
@counter
=
counter
end
def
string
(
base
)
@base
=
base
increment_counter!
while
yield
(
base_string
)
base_string
...
...
app/models/issue.rb
View file @
9000626a
...
...
@@ -198,7 +198,7 @@ class Issue < ActiveRecord::Base
return
to_branch_name
unless
project
.
repository
.
branch_exists?
(
to_branch_name
)
start_counting_from
=
2
Uniquify
.
new
.
string
(
->
(
counter
)
{
"
#{
to_branch_name
}
-
#{
counter
}
"
},
start_counting_from
)
do
|
suggested_branch_name
|
Uniquify
.
new
(
start_counting_from
).
string
(
->
(
counter
)
{
"
#{
to_branch_name
}
-
#{
counter
}
"
}
)
do
|
suggested_branch_name
|
project
.
repository
.
branch_exists?
(
suggested_branch_name
)
end
end
...
...
spec/models/concerns/uniquify_spec.rb
View file @
9000626a
...
...
@@ -24,7 +24,9 @@ describe Uniquify do
it
'allows to pass an initial value for the counter'
do
start_counting_from
=
2
result
=
uniquify
.
string
(
'test_string'
,
start_counting_from
)
{
|
s
|
s
==
'test_string'
}
uniquify
=
described_class
.
new
(
start_counting_from
)
result
=
uniquify
.
string
(
'test_string'
)
{
|
s
|
s
==
'test_string'
}
expect
(
result
).
to
eq
(
'test_string2'
)
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment