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
dcc30fec
Commit
dcc30fec
authored
Jan 14, 2020
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor first_board method into the Board model
and add proper specs
parent
c8812965
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
10 deletions
+34
-10
app/models/board.rb
app/models/board.rb
+1
-0
app/services/boards/list_service.rb
app/services/boards/list_service.rb
+1
-4
spec/models/board_spec.rb
spec/models/board_spec.rb
+27
-0
spec/support/shared_examples/services/boards/boards_list_service.rb
...rt/shared_examples/services/boards/boards_list_service.rb
+5
-6
No files found.
app/models/board.rb
View file @
dcc30fec
...
...
@@ -12,6 +12,7 @@ class Board < ApplicationRecord
scope
:with_associations
,
->
{
preload
(
:destroyable_lists
)
}
scope
:order_by_name_asc
,
->
{
order
(
arel_table
[
:name
].
lower
.
asc
)
}
scope
:first_board
,
->
{
where
(
id:
self
.
order_by_name_asc
.
limit
(
1
).
select
(
:id
))
}
def
project_needed?
!
group
...
...
app/services/boards/list_service.rb
View file @
dcc30fec
...
...
@@ -20,12 +20,9 @@ module Boards
parent
.
boards
.
order_by_name_asc
end
# rubocop: disable CodeReuse/ActiveRecord
def
first_board
# We could use just one query but MySQL does not support nested queries using LIMIT
boards
.
where
(
id:
boards
.
first
).
reorder
(
nil
)
parent
.
boards
.
first_board
end
# rubocop: enable CodeReuse/ActiveRecord
def
create_board!
Boards
::
CreateService
.
new
(
parent
,
current_user
).
execute
...
...
spec/models/board_spec.rb
View file @
dcc30fec
...
...
@@ -3,6 +3,9 @@
require
'spec_helper'
describe
Board
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:other_project
)
{
create
(
:project
)
}
describe
'relationships'
do
it
{
is_expected
.
to
belong_to
(
:project
)
}
it
{
is_expected
.
to
have_many
(
:lists
).
order
(
list_type: :asc
,
position: :asc
).
dependent
(
:delete_all
)
}
...
...
@@ -11,4 +14,28 @@ describe Board do
describe
'validations'
do
it
{
is_expected
.
to
validate_presence_of
(
:project
)
}
end
describe
'#order_by_name_asc'
do
let!
(
:second_board
)
{
create
(
:board
,
name:
'Secondary board'
,
project:
project
)
}
let!
(
:first_board
)
{
create
(
:board
,
name:
'First board'
,
project:
project
)
}
it
'returns in alphabetical order'
do
expect
(
project
.
boards
.
order_by_name_asc
).
to
eq
[
first_board
,
second_board
]
end
end
describe
'#first_board'
do
let!
(
:other_board
)
{
create
(
:board
,
name:
'Other board'
,
project:
other_project
)
}
let!
(
:second_board
)
{
create
(
:board
,
name:
'Secondary board'
,
project:
project
)
}
let!
(
:first_board
)
{
create
(
:board
,
name:
'First board'
,
project:
project
)
}
it
'return the first alphabetical board as a relation'
do
expect
(
project
.
boards
.
first_board
).
to
eq
[
first_board
]
end
# BoardsActions#board expects this behavior
it
'raises an error when find is done on a non-existent record'
do
expect
{
project
.
boards
.
first_board
.
find
(
second_board
.
id
)
}.
to
raise_error
(
ActiveRecord
::
RecordNotFound
)
end
end
end
spec/support/shared_examples/services/boards/boards_list_service.rb
View file @
dcc30fec
...
...
@@ -32,7 +32,9 @@ end
shared_examples
'multiple boards list service'
do
let
(
:service
)
{
described_class
.
new
(
parent
,
double
)
}
let!
(
:boards
)
{
create_list
(
:board
,
3
,
resource_parent:
parent
)
}
let!
(
:board_B
)
{
create
(
:board
,
resource_parent:
parent
,
name:
'B-board'
)
}
let!
(
:board_c
)
{
create
(
:board
,
resource_parent:
parent
,
name:
'c-board'
)
}
let!
(
:board_a
)
{
create
(
:board
,
resource_parent:
parent
,
name:
'a-board'
)
}
describe
'#execute'
do
it
'returns all issue boards'
do
...
...
@@ -40,10 +42,7 @@ shared_examples 'multiple boards list service' do
end
it
'returns boards ordered by name'
do
board_names
=
%w[B-board c-board a-board]
boards
.
each_with_index
{
|
board
,
i
|
board
.
update_column
(
:name
,
board_names
[
i
])
}
expect
(
service
.
execute
.
pluck
(
:name
)).
to
eq
(
%w[a-board B-board c-board]
)
expect
(
service
.
execute
).
to
eq
[
board_a
,
board_B
,
board_c
]
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