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
c2d8cb73
Commit
c2d8cb73
authored
Dec 03, 2019
by
Pavel Shutsin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve pipelines finder ordering spec
parent
5a41e479
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
39 deletions
+32
-39
app/finders/pipelines_finder.rb
app/finders/pipelines_finder.rb
+1
-1
spec/finders/pipelines_finder_spec.rb
spec/finders/pipelines_finder_spec.rb
+31
-38
No files found.
app/finders/pipelines_finder.rb
View file @
c2d8cb73
...
@@ -129,7 +129,7 @@ class PipelinesFinder
...
@@ -129,7 +129,7 @@ class PipelinesFinder
end
end
# rubocop: enable CodeReuse/ActiveRecord
# rubocop: enable CodeReuse/ActiveRecord
def
by_updated_at
(
items
)
def
by_updated_at
(
items
)
items
=
items
.
updated_before
(
params
[
:updated_before
])
if
params
[
:updated_before
].
present?
items
=
items
.
updated_before
(
params
[
:updated_before
])
if
params
[
:updated_before
].
present?
items
=
items
.
updated_after
(
params
[
:updated_after
])
if
params
[
:updated_after
].
present?
items
=
items
.
updated_after
(
params
[
:updated_after
])
if
params
[
:updated_after
].
present?
...
...
spec/finders/pipelines_finder_spec.rb
View file @
c2d8cb73
...
@@ -181,44 +181,6 @@ describe PipelinesFinder do
...
@@ -181,44 +181,6 @@ describe PipelinesFinder do
end
end
end
end
context
'when order_by and sort are specified'
do
context
'when order_by user_id'
do
let
(
:params
)
{
{
order_by:
'user_id'
,
sort:
'asc'
}
}
let
(
:users
)
{
Array
.
new
(
2
)
{
create
(
:user
,
developer_projects:
[
project
])
}
}
let!
(
:pipelines
)
{
users
.
map
{
|
user
|
create
(
:ci_pipeline
,
project:
project
,
user:
user
)
}
}
it
'sorts as user_id: :asc'
do
is_expected
.
to
match_array
(
pipelines
)
end
context
'when sort is invalid'
do
let
(
:params
)
{
{
order_by:
'user_id'
,
sort:
'invalid_sort'
}
}
it
'sorts as user_id: :desc'
do
is_expected
.
to
eq
(
pipelines
.
sort_by
{
|
p
|
-
p
.
user
.
id
})
end
end
end
context
'when order_by is invalid'
do
let
(
:params
)
{
{
order_by:
'invalid_column'
,
sort:
'asc'
}
}
let!
(
:pipelines
)
{
create_list
(
:ci_pipeline
,
2
,
project:
project
)
}
it
'sorts as id: :asc'
do
is_expected
.
to
eq
(
pipelines
.
sort_by
{
|
p
|
p
.
id
})
end
end
context
'when both are nil'
do
let
(
:params
)
{
{
order_by:
nil
,
sort:
nil
}
}
let!
(
:pipelines
)
{
create_list
(
:ci_pipeline
,
2
,
project:
project
)
}
it
'sorts as id: :desc'
do
is_expected
.
to
eq
(
pipelines
.
sort_by
{
|
p
|
-
p
.
id
})
end
end
end
context
'when sha is specified'
do
context
'when sha is specified'
do
let!
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
sha:
'97de212e80737a608d939f648d959671fb0a0142'
)
}
let!
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
sha:
'97de212e80737a608d939f648d959671fb0a0142'
)
}
...
@@ -260,5 +222,36 @@ describe PipelinesFinder do
...
@@ -260,5 +222,36 @@ describe PipelinesFinder do
end
end
end
end
end
end
describe
'ordering'
do
using
RSpec
::
Parameterized
::
TableSyntax
let
(
:params
)
{
{
order_by:
order_by
,
sort:
sort
}
}
let!
(
:pipeline_1
)
{
create
(
:ci_pipeline
,
:scheduled
,
project:
project
,
iid:
11
,
ref:
'master'
,
created_at:
Time
.
now
,
updated_at:
Time
.
now
,
user:
create
(
:user
))
}
let!
(
:pipeline_2
)
{
create
(
:ci_pipeline
,
:created
,
project:
project
,
iid:
12
,
ref:
'feature'
,
created_at:
1
.
day
.
ago
,
updated_at:
2
.
hours
.
ago
,
user:
create
(
:user
))
}
let!
(
:pipeline_3
)
{
create
(
:ci_pipeline
,
:success
,
project:
project
,
iid:
8
,
ref:
'patch'
,
created_at:
2
.
days
.
ago
,
updated_at:
1
.
hour
.
ago
,
user:
create
(
:user
))
}
where
(
:order_by
,
:sort
,
:ordered_pipelines
)
do
'id'
|
'asc'
|
[
:pipeline_1
,
:pipeline_2
,
:pipeline_3
]
'id'
|
'desc'
|
[
:pipeline_3
,
:pipeline_2
,
:pipeline_1
]
'ref'
|
'asc'
|
[
:pipeline_2
,
:pipeline_1
,
:pipeline_3
]
'ref'
|
'desc'
|
[
:pipeline_3
,
:pipeline_1
,
:pipeline_2
]
'status'
|
'asc'
|
[
:pipeline_2
,
:pipeline_1
,
:pipeline_3
]
'status'
|
'desc'
|
[
:pipeline_3
,
:pipeline_1
,
:pipeline_2
]
'updated_at'
|
'asc'
|
[
:pipeline_2
,
:pipeline_3
,
:pipeline_1
]
'updated_at'
|
'desc'
|
[
:pipeline_1
,
:pipeline_3
,
:pipeline_2
]
'user_id'
|
'asc'
|
[
:pipeline_1
,
:pipeline_2
,
:pipeline_3
]
'user_id'
|
'desc'
|
[
:pipeline_3
,
:pipeline_2
,
:pipeline_1
]
'invalid'
|
'asc'
|
[
:pipeline_1
,
:pipeline_2
,
:pipeline_3
]
'id'
|
'err'
|
[
:pipeline_3
,
:pipeline_2
,
:pipeline_1
]
end
with_them
do
it
'returns the pipelines ordered'
do
expect
(
subject
).
to
eq
(
ordered_pipelines
.
map
{
|
name
|
public_send
(
name
)
})
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