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
ae58f82e
Commit
ae58f82e
authored
Jul 23, 2019
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract common spec elements to shared_examples
parent
38ab1ae2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
92 deletions
+71
-92
spec/models/project_spec.rb
spec/models/project_spec.rb
+8
-92
spec/support/shared_examples/project_latest_successful_build_for_examples.rb
..._examples/project_latest_successful_build_for_examples.rb
+63
-0
No files found.
spec/models/project_spec.rb
View file @
ae58f82e
...
...
@@ -2023,54 +2023,16 @@ describe Project do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:pipeline
)
{
create_pipeline
(
project
)
}
context
'with many builds'
do
it
'gives the latest builds from latest pipeline'
do
pipeline1
=
create_pipeline
(
project
)
pipeline2
=
create_pipeline
(
project
)
create_build
(
pipeline1
,
'test'
)
create_build
(
pipeline1
,
'test2'
)
build1_p2
=
create_build
(
pipeline2
,
'test'
)
create_build
(
pipeline2
,
'test2'
)
expect
(
project
.
latest_successful_build_for_ref
(
build1_p2
.
name
))
.
to
eq
(
build1_p2
)
end
end
it_behaves_like
'latest successful build for sha or ref'
context
'with succeeded pipeline'
do
let!
(
:build
)
{
create_build
}
subject
{
project
.
latest_successful_build_for_ref
(
build_name
)
}
context
'standalone pipeline'
do
it
'returns builds for ref for default_branch'
do
expect
(
project
.
latest_successful_build_for_ref
(
build
.
name
))
.
to
eq
(
build
)
end
context
'with a specified ref'
do
let
(
:build
)
{
create_build
}
it
'returns empty relation if the build cannot be found'
do
expect
(
project
.
latest_successful_build_for_ref
(
'TAIL'
))
.
to
be_nil
end
end
subject
{
project
.
latest_successful_build_for_ref
(
build
.
name
,
project
.
default_branch
)
}
context
'with some pending pipeline'
do
before
do
create_build
(
create_pipeline
(
project
,
'pending'
))
end
it
'gives the latest build from latest pipeline'
do
expect
(
project
.
latest_successful_build_for_ref
(
build
.
name
))
.
to
eq
(
build
)
end
end
end
context
'with pending pipeline'
do
it
'returns empty relation'
do
pipeline
.
update
(
status:
'pending'
)
pending_build
=
create_build
(
pipeline
)
expect
(
project
.
latest_successful_build_for_ref
(
pending_build
.
name
)).
to
be_nil
end
it
{
is_expected
.
to
eq
(
build
)
}
end
end
...
...
@@ -2078,55 +2040,9 @@ describe Project do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:pipeline
)
{
create_pipeline
(
project
)
}
context
'with many builds'
do
it
'gives the latest builds from latest pipeline'
do
pipeline1
=
create_pipeline
(
project
)
pipeline2
=
create_pipeline
(
project
)
create_build
(
pipeline1
,
'test'
)
create_build
(
pipeline1
,
'test2'
)
build1_p2
=
create_build
(
pipeline2
,
'test'
)
create_build
(
pipeline2
,
'test2'
)
expect
(
project
.
latest_successful_build_for_sha
(
build1_p2
.
name
))
.
to
eq
(
build1_p2
)
end
end
context
'with succeeded pipeline'
do
let!
(
:build
)
{
create_build
}
context
'standalone pipeline'
do
it
'returns builds for ref for default_branch'
do
expect
(
project
.
latest_successful_build_for_sha
(
build
.
name
))
.
to
eq
(
build
)
end
it_behaves_like
'latest successful build for sha or ref'
it
'returns empty relation if the build cannot be found'
do
expect
(
project
.
latest_successful_build_for_sha
(
'TAIL'
))
.
to
be_nil
end
end
context
'with some pending pipeline'
do
before
do
create_build
(
create_pipeline
(
project
,
'pending'
))
end
it
'gives the latest build from latest pipeline'
do
expect
(
project
.
latest_successful_build_for_sha
(
build
.
name
))
.
to
eq
(
build
)
end
end
end
context
'with pending pipeline'
do
it
'returns empty relation'
do
pipeline
.
update
(
status:
'pending'
)
pending_build
=
create_build
(
pipeline
)
expect
(
project
.
latest_successful_build_for_sha
(
pending_build
.
name
)).
to
be_nil
end
end
subject
{
project
.
latest_successful_build_for_sha
(
build_name
,
project
.
commit
.
sha
)
}
end
describe
'#latest_successful_build_for_ref!'
do
...
...
spec/support/shared_examples/project_latest_successful_build_for_examples.rb
0 → 100644
View file @
ae58f82e
# frozen_string_literal: true
shared_examples
'latest successful build for sha or ref'
do
context
'with many builds'
do
let
(
:other_pipeline
)
{
create_pipeline
(
project
)
}
let
(
:other_build
)
{
create_build
(
other_pipeline
,
'test'
)
}
let
(
:build_name
)
{
other_build
.
name
}
before
do
pipeline1
=
create_pipeline
(
project
)
pipeline2
=
create_pipeline
(
project
)
create_build
(
pipeline1
,
'test'
)
create_build
(
pipeline1
,
'test2'
)
create_build
(
pipeline2
,
'test2'
)
end
it
'gives the latest builds from latest pipeline'
do
expect
(
subject
).
to
eq
(
other_build
)
end
end
context
'with succeeded pipeline'
do
let!
(
:build
)
{
create_build
}
let
(
:build_name
)
{
build
.
name
}
context
'standalone pipeline'
do
it
'returns builds for ref for default_branch'
do
expect
(
subject
).
to
eq
(
build
)
end
context
'with nonexistent build'
do
let
(
:build_name
)
{
'TAIL'
}
it
'returns empty relation if the build cannot be found'
do
expect
(
subject
).
to
be_nil
end
end
end
context
'with some pending pipeline'
do
before
do
create_build
(
create_pipeline
(
project
,
'pending'
))
end
it
'gives the latest build from latest pipeline'
do
expect
(
subject
).
to
eq
(
build
)
end
end
end
context
'with pending pipeline'
do
let!
(
:pending_build
)
{
create_build
(
pipeline
)
}
let
(
:build_name
)
{
pending_build
.
name
}
before
do
pipeline
.
update
(
status:
'pending'
)
end
it
'returns empty relation'
do
expect
(
subject
).
to
be_nil
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