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
35420cec
Commit
35420cec
authored
Jul 28, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Respect Backlog/Done positions when creating a new list
parent
260f1593
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
11 deletions
+57
-11
app/services/boards/lists/create_service.rb
app/services/boards/lists/create_service.rb
+19
-3
spec/services/boards/lists/create_service_spec.rb
spec/services/boards/lists/create_service_spec.rb
+38
-8
No files found.
app/services/boards/lists/create_service.rb
View file @
35420cec
...
...
@@ -7,15 +7,31 @@ module Boards
end
def
execute
board
.
lists
.
create
(
params
.
merge
(
position:
position
))
List
.
transaction
do
position
=
find_next_position
increment_higher_lists
(
position
)
create_list_at
(
position
)
end
end
private
attr_reader
:board
,
:params
def
position
board
.
lists
.
size
def
find_next_position
return
0
unless
board
.
lists
.
any?
records
=
board
.
lists
.
where
.
not
(
list_type:
List
.
list_types
[
:done
])
records
.
maximum
(
:position
).
to_i
+
1
end
def
create_list_at
(
position
)
board
.
lists
.
create
(
params
.
merge
(
list_type: :label
,
position:
position
))
end
def
increment_higher_lists
(
position
)
board
.
lists
.
where
(
'position >= ?'
,
position
)
.
update_all
(
'position = position + 1'
)
end
end
end
...
...
spec/services/boards/lists/create_service_spec.rb
View file @
35420cec
...
...
@@ -6,19 +6,49 @@ describe Boards::Lists::CreateService, services: true do
let
(
:board
)
{
project
.
board
}
let
(
:label
)
{
create
(
:label
,
name:
'in-progress'
)
}
it
'creates a new list for board'
do
service
=
described_class
.
new
(
project
,
label_id:
label
.
id
)
subject
(
:service
)
{
described_class
.
new
(
project
,
label_id:
label
.
id
)
}
expect
{
service
.
execute
}.
to
change
(
board
.
lists
,
:count
).
by
(
1
)
context
'when board lists is empty'
do
it
'creates a new list at begginning of the list'
do
list
=
service
.
execute
expect
(
list
.
position
).
to
eq
0
end
end
context
'when board lists has a backlog list'
do
it
'creates a new list at end of the list'
do
create
(
:backlog_list
,
board:
board
,
position:
0
)
list
=
service
.
execute
expect
(
list
.
position
).
to
eq
1
end
end
context
'when board lists are only labels lists'
do
it
'creates a new list at end of the list'
do
create_list
(
:label_list
,
2
,
board:
board
)
list
=
described_class
.
new
(
project
,
label_id:
label
.
id
).
execute
expect
(
list
.
position
).
to
eq
3
end
end
it
'inserts the list to the end of lists'
do
create_list
(
:list
,
2
,
board:
board
)
service
=
described_class
.
new
(
project
,
label_id:
label
.
id
)
context
'when board lists has a done list'
do
it
'creates a new list before'
do
list1
=
create
(
:backlog_list
,
board:
board
,
position:
1
)
list2
=
create
(
:label_list
,
board:
board
,
position:
2
)
list3
=
create
(
:done_list
,
board:
board
,
position:
3
)
list
=
service
.
execute
list
=
described_class
.
new
(
project
,
label_id:
label
.
id
)
.
execute
expect
(
list
.
position
).
to
eq
2
expect
(
list
.
position
).
to
eq
3
expect
(
list1
.
reload
.
position
).
to
eq
1
expect
(
list2
.
reload
.
position
).
to
eq
2
expect
(
list3
.
reload
.
position
).
to
eq
4
end
end
end
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