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
Boxiang Sun
gitlab-ce
Commits
44ae9939
Commit
44ae9939
authored
Mar 08, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use ActiveRecord for comparison
parent
658f2cb1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
50 deletions
+36
-50
spec/finders/pipelines_finder_spec.rb
spec/finders/pipelines_finder_spec.rb
+36
-50
No files found.
spec/finders/pipelines_finder_spec.rb
View file @
44ae9939
require
'spec_helper'
require
'spec_helper'
describe
PipelinesFinder
do
describe
PipelinesFinder
do
let!
(
:user1
)
{
create
(
:user
)
}
let
(
:user1
)
{
create
(
:user
)
}
let!
(
:user2
)
{
create
(
:user
)
}
let
(
:user2
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let!
(
:dummy_pipelines
)
do
before
do
{
create
(
:ci_pipeline
,
project:
project
,
user:
user1
,
ref:
'v1.0.0'
,
tag:
true
)
tag:
create
(
:ci_pipeline
,
project:
project
,
user:
user1
,
created_at:
9
.
minutes
.
ago
,
ref:
'v1.0.0'
,
tag:
true
),
create
(
:ci_pipeline
,
project:
project
,
user:
user1
,
status:
'created'
)
created:
create
(
:ci_pipeline
,
project:
project
,
user:
user1
,
created_at:
8
.
minutes
.
ago
,
status:
'created'
),
create
(
:ci_pipeline
,
project:
project
,
user:
user1
,
status:
'pending'
)
pending:
create
(
:ci_pipeline
,
project:
project
,
user:
user1
,
created_at:
7
.
minutes
.
ago
,
status:
'pending'
),
create
(
:ci_pipeline
,
project:
project
,
user:
user1
,
status:
'running'
)
running:
create
(
:ci_pipeline
,
project:
project
,
user:
user1
,
created_at:
6
.
minutes
.
ago
,
status:
'running'
),
create
(
:ci_pipeline
,
project:
project
,
user:
user1
,
status:
'success'
)
success:
create
(
:ci_pipeline
,
project:
project
,
user:
user1
,
created_at:
5
.
minutes
.
ago
,
status:
'success'
),
create
(
:ci_pipeline
,
project:
project
,
user:
user2
,
status:
'failed'
)
failed:
create
(
:ci_pipeline
,
project:
project
,
user:
user2
,
created_at:
4
.
minutes
.
ago
,
status:
'failed'
),
create
(
:ci_pipeline
,
project:
project
,
user:
user2
,
status:
'canceled'
)
canceled:
create
(
:ci_pipeline
,
project:
project
,
user:
user2
,
created_at:
3
.
minutes
.
ago
,
status:
'canceled'
),
create
(
:ci_pipeline
,
project:
project
,
user:
user2
,
status:
'skipped'
)
skipped:
create
(
:ci_pipeline
,
project:
project
,
user:
user2
,
created_at:
2
.
minutes
.
ago
,
status:
'skipped'
),
create
(
:ci_pipeline
,
project:
project
,
user:
user2
,
yaml_errors:
'Syntax error'
)
yaml_errors:
create
(
:ci_pipeline
,
project:
project
,
user:
user2
,
created_at:
1
.
minute
.
ago
,
yaml_errors:
'Syntax error'
),
}
end
end
subject
{
described_class
.
new
(
project
,
params
).
execute
}
subject
{
described_class
.
new
(
project
,
params
).
execute
}
...
@@ -26,12 +24,11 @@ describe PipelinesFinder do
...
@@ -26,12 +24,11 @@ describe PipelinesFinder do
let
(
:params
)
{
{}
}
let
(
:params
)
{
{}
}
it
'selects all pipelines'
do
it
'selects all pipelines'
do
expect
(
subject
.
count
).
to
be
dummy_pipelines
.
count
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
all
)
expect
(
subject
).
to
match_array
dummy_pipelines
.
values
end
end
it
'orders in descending order on ID'
do
it
'orders in descending order on ID'
do
expect
(
subject
.
map
(
&
:id
)).
to
eq
dummy_pipelines
.
values
.
map
(
&
:id
).
sort
.
reverse
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
order
(
id: :desc
))
end
end
end
end
...
@@ -40,7 +37,7 @@ describe PipelinesFinder do
...
@@ -40,7 +37,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
scope:
'running'
}
}
let
(
:params
)
{
{
scope:
'running'
}
}
it
'has only running status'
do
it
'has only running status'
do
expect
(
subject
.
map
(
&
:status
)).
to
all
(
eq
(
'running'
)
)
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
running
)
end
end
end
end
...
@@ -48,7 +45,7 @@ describe PipelinesFinder do
...
@@ -48,7 +45,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
scope:
'pending'
}
}
let
(
:params
)
{
{
scope:
'pending'
}
}
it
'has only pending status'
do
it
'has only pending status'
do
expect
(
subject
.
map
(
&
:status
)).
to
all
(
eq
(
'pending'
)
)
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
pending
)
end
end
end
end
...
@@ -56,7 +53,7 @@ describe PipelinesFinder do
...
@@ -56,7 +53,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
scope:
'finished'
}
}
let
(
:params
)
{
{
scope:
'finished'
}
}
it
'has only finished status'
do
it
'has only finished status'
do
expect
(
subject
.
map
(
&
:status
)).
to
match_array
%w[success canceled failed]
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
finished
)
end
end
end
end
...
@@ -64,9 +61,7 @@ describe PipelinesFinder do
...
@@ -64,9 +61,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
scope:
'branches'
}
}
let
(
:params
)
{
{
scope:
'branches'
}
}
it
'excludes tags'
do
it
'excludes tags'
do
expect
(
subject
.
count
).
to
be
1
expect
(
subject
).
to
eq
([
Ci
::
Pipeline
.
where
(
tag:
false
).
last
])
expect
(
subject
).
not_to
include
dummy_pipelines
[
:tag
]
expect
(
subject
.
map
(
&
:ref
)).
to
all
(
eq
(
'master'
))
end
end
end
end
...
@@ -74,9 +69,7 @@ describe PipelinesFinder do
...
@@ -74,9 +69,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
scope:
'tags'
}
}
let
(
:params
)
{
{
scope:
'tags'
}
}
it
'excludes branches'
do
it
'excludes branches'
do
expect
(
subject
.
count
).
to
be
1
expect
(
subject
).
to
eq
([
Ci
::
Pipeline
.
where
(
tag:
true
).
last
])
expect
(
subject
).
to
include
dummy_pipelines
[
:tag
]
expect
(
subject
.
map
(
&
:ref
)).
not_to
include
(
'master'
)
end
end
end
end
end
end
...
@@ -86,7 +79,7 @@ describe PipelinesFinder do
...
@@ -86,7 +79,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
status:
'running'
}
}
let
(
:params
)
{
{
status:
'running'
}
}
it
'has only running status'
do
it
'has only running status'
do
expect
(
subject
.
map
(
&
:status
)).
to
all
(
eq
(
'running'
)
)
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
running
)
end
end
end
end
...
@@ -94,7 +87,7 @@ describe PipelinesFinder do
...
@@ -94,7 +87,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
status:
'pending'
}
}
let
(
:params
)
{
{
status:
'pending'
}
}
it
'has only pending status'
do
it
'has only pending status'
do
expect
(
subject
.
map
(
&
:status
)).
to
all
(
eq
(
'pending'
)
)
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
pending
)
end
end
end
end
...
@@ -102,7 +95,7 @@ describe PipelinesFinder do
...
@@ -102,7 +95,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
status:
'success'
}
}
let
(
:params
)
{
{
status:
'success'
}
}
it
'has only success status'
do
it
'has only success status'
do
expect
(
subject
.
map
(
&
:status
)).
to
all
(
eq
(
'success'
)
)
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
success
)
end
end
end
end
...
@@ -110,7 +103,7 @@ describe PipelinesFinder do
...
@@ -110,7 +103,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
status:
'failed'
}
}
let
(
:params
)
{
{
status:
'failed'
}
}
it
'has only failed status'
do
it
'has only failed status'
do
expect
(
subject
.
map
(
&
:status
)).
to
all
(
eq
(
'failed'
)
)
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
failed
)
end
end
end
end
...
@@ -118,7 +111,7 @@ describe PipelinesFinder do
...
@@ -118,7 +111,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
status:
'canceled'
}
}
let
(
:params
)
{
{
status:
'canceled'
}
}
it
'has only canceled status'
do
it
'has only canceled status'
do
expect
(
subject
.
map
(
&
:status
)).
to
all
(
eq
(
'canceled'
)
)
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
canceled
)
end
end
end
end
...
@@ -126,7 +119,7 @@ describe PipelinesFinder do
...
@@ -126,7 +119,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
status:
'skipped'
}
}
let
(
:params
)
{
{
status:
'skipped'
}
}
it
'has only skipped status'
do
it
'has only skipped status'
do
expect
(
subject
.
map
(
&
:status
)).
to
all
(
eq
(
'skipped'
)
)
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
skipped
)
end
end
end
end
end
end
...
@@ -136,8 +129,7 @@ describe PipelinesFinder do
...
@@ -136,8 +129,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
ref:
'master'
}
}
let
(
:params
)
{
{
ref:
'master'
}
}
it
'selects all pipelines which belong to the ref'
do
it
'selects all pipelines which belong to the ref'
do
expected
=
dummy_pipelines
.
except
(
:tag
)
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
where
(
ref:
'master'
))
expect
(
subject
).
to
match_array
expected
.
values
end
end
end
end
...
@@ -155,8 +147,7 @@ describe PipelinesFinder do
...
@@ -155,8 +147,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
username:
user1
.
name
}
}
let
(
:params
)
{
{
username:
user1
.
name
}
}
it
'selects all pipelines which belong to the username'
do
it
'selects all pipelines which belong to the username'
do
expected
=
dummy_pipelines
.
except
(
:failed
).
except
(
:canceled
).
except
(
:skipped
).
except
(
:yaml_errors
)
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
where
(
user:
user1
))
expect
(
subject
).
to
match_array
expected
.
values
end
end
end
end
...
@@ -174,8 +165,7 @@ describe PipelinesFinder do
...
@@ -174,8 +165,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
yaml_errors:
true
}
}
let
(
:params
)
{
{
yaml_errors:
true
}
}
it
'selects only pipelines have yaml_errors'
do
it
'selects only pipelines have yaml_errors'
do
expect
(
subject
.
count
).
to
be
1
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
where
(
"yaml_errors IS NOT NULL"
))
expect
(
subject
.
first
).
to
eq
dummy_pipelines
[
:yaml_errors
]
end
end
end
end
...
@@ -183,9 +173,7 @@ describe PipelinesFinder do
...
@@ -183,9 +173,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
yaml_errors:
false
}
}
let
(
:params
)
{
{
yaml_errors:
false
}
}
it
'selects only pipelines do not have yaml_errors'
do
it
'selects only pipelines do not have yaml_errors'
do
expected
=
dummy_pipelines
.
except
(
:yaml_errors
)
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
where
(
"yaml_errors IS NULL"
))
expect
(
subject
.
count
).
to
be
expected
.
count
expect
(
subject
).
to
match_array
expected
.
values
end
end
end
end
...
@@ -193,7 +181,7 @@ describe PipelinesFinder do
...
@@ -193,7 +181,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
yaml_errors:
"UnexpectedValue"
}
}
let
(
:params
)
{
{
yaml_errors:
"UnexpectedValue"
}
}
it
'selects all pipelines'
do
it
'selects all pipelines'
do
expect
(
subject
).
to
match_array
dummy_pipelines
.
values
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
all
)
end
end
end
end
end
end
...
@@ -203,8 +191,7 @@ describe PipelinesFinder do
...
@@ -203,8 +191,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
order_by:
'created_at'
,
sort:
'asc'
}
}
let
(
:params
)
{
{
order_by:
'created_at'
,
sort:
'asc'
}
}
it
'sorts by created_at asc'
do
it
'sorts by created_at asc'
do
expect
(
subject
.
first
).
to
eq
dummy_pipelines
[
:tag
]
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
order
(
created_at: :asc
))
expect
(
subject
.
last
).
to
eq
dummy_pipelines
[
:yaml_errors
]
end
end
end
end
...
@@ -212,8 +199,7 @@ describe PipelinesFinder do
...
@@ -212,8 +199,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
order_by:
'created_at'
,
sort:
'desc'
}
}
let
(
:params
)
{
{
order_by:
'created_at'
,
sort:
'desc'
}
}
it
'sorts by created_at desc'
do
it
'sorts by created_at desc'
do
expect
(
subject
.
first
).
to
eq
dummy_pipelines
[
:yaml_errors
]
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
order
(
created_at: :desc
))
expect
(
subject
.
last
).
to
eq
dummy_pipelines
[
:tag
]
end
end
end
end
...
@@ -221,7 +207,7 @@ describe PipelinesFinder do
...
@@ -221,7 +207,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
order_by:
'abnormal_column'
,
sort:
'desc'
}
}
let
(
:params
)
{
{
order_by:
'abnormal_column'
,
sort:
'desc'
}
}
it
'sorts by default'
do
it
'sorts by default'
do
expect
(
subject
.
map
(
&
:id
)).
to
eq
dummy_pipelines
.
values
.
map
(
&
:id
).
sort
.
reverse
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
order
(
id: :desc
))
end
end
end
end
...
@@ -229,7 +215,7 @@ describe PipelinesFinder do
...
@@ -229,7 +215,7 @@ describe PipelinesFinder do
let
(
:params
)
{
{
order_by:
'created_at'
,
sort:
'abnormal_sort'
}
}
let
(
:params
)
{
{
order_by:
'created_at'
,
sort:
'abnormal_sort'
}
}
it
'sorts by default'
do
it
'sorts by default'
do
expect
(
subject
.
map
(
&
:id
)).
to
eq
dummy_pipelines
.
values
.
map
(
&
:id
).
sort
.
reverse
expect
(
subject
).
to
match_array
(
Ci
::
Pipeline
.
order
(
id: :desc
))
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