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
c3f43e45
Commit
c3f43e45
authored
Jul 04, 2017
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate feature availability in the Boards::CreateService
parent
ef3eb79a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
34 deletions
+111
-34
app/controllers/ee/projects/boards_controller.rb
app/controllers/ee/projects/boards_controller.rb
+1
-1
app/services/boards/create_service.rb
app/services/boards/create_service.rb
+12
-5
app/services/ee/boards/create_service.rb
app/services/ee/boards/create_service.rb
+22
-0
spec/services/boards/create_service_spec.rb
spec/services/boards/create_service_spec.rb
+9
-28
spec/services/ee/boards/create_service_spec.rb
spec/services/ee/boards/create_service_spec.rb
+67
-0
No files found.
app/controllers/ee/projects/boards_controller.rb
View file @
c3f43e45
...
...
@@ -9,7 +9,7 @@ module EE
end
def
create
board
=
::
Boards
::
CreateService
.
new
(
project
,
current_user
,
board_params
).
execute
board
=
EE
::
Boards
::
CreateService
.
new
(
project
,
current_user
,
board_params
).
execute
respond_to
do
|
format
|
format
.
json
do
...
...
app/services/boards/create_service.rb
View file @
c3f43e45
module
Boards
class
CreateService
<
BaseService
def
execute
board
=
project
.
boards
.
create
(
params
)
if
board
.
persisted?
board
.
lists
.
create
(
list_type: :backlog
)
board
.
lists
.
create
(
list_type: :closed
)
if
project
.
boards
.
empty?
create_board!
else
project
.
boards
.
first
end
end
private
def
create_board!
board
=
project
.
boards
.
create
board
.
lists
.
create
(
list_type: :backlog
)
board
.
lists
.
create
(
list_type: :closed
)
board
end
...
...
app/services/ee/boards/create_service.rb
0 → 100644
View file @
c3f43e45
module
EE
module
Boards
class
CreateService
<
BaseService
def
execute
return
nil
unless
can_create_board?
board
=
project
.
boards
.
create
(
params
)
if
board
.
persisted?
board
.
lists
.
create
(
list_type: :backlog
)
board
.
lists
.
create
(
list_type: :closed
)
end
board
end
def
can_create_board?
project
.
feature_available?
(
:multiple_issue_boards
)
||
project
.
boards
.
size
<
1
end
end
end
end
spec/services/boards/create_service_spec.rb
View file @
c3f43e45
...
...
@@ -4,11 +4,11 @@ describe Boards::CreateService, services: true do
describe
'#execute'
do
let
(
:project
)
{
create
(
:empty_project
)
}
context
'with valid params'
do
subject
(
:service
)
{
described_class
.
new
(
project
,
double
,
name:
'Backend'
)
}
subject
(
:service
)
{
described_class
.
new
(
project
,
double
)
}
it
'creates a new project board'
do
expect
{
service
.
execute
}.
to
change
(
project
.
boards
,
:count
).
by
(
1
)
context
'when project does not have a board'
do
it
'creates a new board'
do
expect
{
service
.
execute
}.
to
change
(
Board
,
:count
).
by
(
1
)
end
it
'creates the default lists'
do
...
...
@@ -20,32 +20,13 @@ describe Boards::CreateService, services: true do
end
end
context
'with invalid params'
do
subject
(
:service
)
{
described_class
.
new
(
project
,
double
,
name:
nil
)
}
it
'does not create a new project board'
do
expect
{
service
.
execute
}.
not_to
change
(
project
.
boards
,
:count
)
end
it
"does not create board's default lists"
do
board
=
service
.
execute
expect
(
board
.
lists
.
size
).
to
eq
0
context
'when project has a board'
do
before
do
create
(
:board
,
project:
project
)
end
end
context
'without params'
do
subject
(
:service
)
{
described_class
.
new
(
project
,
double
)
}
it
'creates a new project board'
do
expect
{
service
.
execute
}.
to
change
(
project
.
boards
,
:count
).
by
(
1
)
end
it
"creates board's default lists"
do
board
=
service
.
execute
expect
(
board
.
lists
.
size
).
to
eq
2
expect
(
board
.
lists
.
last
).
to
be_closed
it
'does not create a new board'
do
expect
{
service
.
execute
}.
not_to
change
(
project
.
boards
,
:count
)
end
end
end
...
...
spec/services/ee/boards/create_service_spec.rb
0 → 100644
View file @
c3f43e45
require
'spec_helper'
describe
EE
::
Boards
::
CreateService
,
services:
true
do
describe
'#execute'
do
let
(
:project
)
{
create
(
:empty_project
)
}
context
'With the feature available'
do
before
do
stub_licensed_features
(
multiple_issue_boards:
true
)
end
context
'with valid params'
do
subject
(
:service
)
{
described_class
.
new
(
project
,
double
,
name:
'Backend'
)
}
it
'creates a new project board'
do
expect
{
service
.
execute
}.
to
change
(
project
.
boards
,
:count
).
by
(
1
)
end
it
'creates the default lists'
do
board
=
service
.
execute
expect
(
board
.
lists
.
size
).
to
eq
2
expect
(
board
.
lists
.
first
).
to
be_backlog
expect
(
board
.
lists
.
last
).
to
be_closed
end
end
context
'with invalid params'
do
subject
(
:service
)
{
described_class
.
new
(
project
,
double
,
name:
nil
)
}
it
'does not create a new project board'
do
expect
{
service
.
execute
}.
not_to
change
(
project
.
boards
,
:count
)
end
it
"does not create board's default lists"
do
board
=
service
.
execute
expect
(
board
.
lists
.
size
).
to
eq
0
end
end
context
'without params'
do
subject
(
:service
)
{
described_class
.
new
(
project
,
double
)
}
it
'creates a new project board'
do
expect
{
service
.
execute
}.
to
change
(
project
.
boards
,
:count
).
by
(
1
)
end
it
"creates board's default lists"
do
board
=
service
.
execute
expect
(
board
.
lists
.
size
).
to
eq
2
expect
(
board
.
lists
.
last
).
to
be_closed
end
end
end
it
'skips creating a second board when the feature is not available'
do
stub_licensed_features
(
multiple_issue_boards:
false
)
service
=
described_class
.
new
(
project
,
double
)
expect
(
service
.
execute
).
not_to
be_nil
expect
{
service
.
execute
}.
not_to
change
(
project
.
boards
,
:count
)
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