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
0
Merge Requests
0
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
Tatuya Kamada
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
...
@@ -7,15 +7,31 @@ module Boards
end
end
def
execute
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
end
private
private
attr_reader
:board
,
:params
attr_reader
:board
,
:params
def
position
def
find_next_position
board
.
lists
.
size
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
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
...
@@ -6,19 +6,49 @@ describe Boards::Lists::CreateService, services: true do
let
(
:board
)
{
project
.
board
}
let
(
:board
)
{
project
.
board
}
let
(
:label
)
{
create
(
:label
,
name:
'in-progress'
)
}
let
(
:label
)
{
create
(
:label
,
name:
'in-progress'
)
}
it
'creates a new list for board'
do
subject
(
:service
)
{
described_class
.
new
(
project
,
label_id:
label
.
id
)
}
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
end
it
'inserts the list to the end of lists'
do
context
'when board lists has a done list'
do
create_list
(
:list
,
2
,
board:
board
)
it
'creates a new list before'
do
service
=
described_class
.
new
(
project
,
label_id:
label
.
id
)
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
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