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
d9d69d7b
Commit
d9d69d7b
authored
Nov 16, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for environments recently updated on branch
parent
e49229aa
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
1 deletion
+64
-1
app/models/environment.rb
app/models/environment.rb
+1
-1
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+21
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+42
-0
No files found.
app/models/environment.rb
View file @
d9d69d7b
...
@@ -38,7 +38,7 @@ class Environment < ActiveRecord::Base
...
@@ -38,7 +38,7 @@ class Environment < ActiveRecord::Base
end
end
def
recently_updated_on_branch?
(
ref
)
def
recently_updated_on_branch?
(
ref
)
ref
.
to_s
==
last_deployment
.
ref
ref
.
to_s
==
last_deployment
.
try
(
:ref
)
end
end
def
last_deployment
def
last_deployment
...
...
spec/models/environment_spec.rb
View file @
d9d69d7b
...
@@ -166,4 +166,25 @@ describe Environment, models: true do
...
@@ -166,4 +166,25 @@ describe Environment, models: true do
end
end
end
end
end
end
describe
'recently_updated_on_branch?'
do
subject
{
environment
.
recently_updated_on_branch?
(
'feature'
)
}
context
'when last deployment to environment is the most recent one'
do
before
do
create
(
:deployment
,
environment:
environment
,
ref:
'feature'
)
end
it
{
is_expected
.
to
be
true
}
end
context
'when last deployment to environment is not the most recent'
do
before
do
create
(
:deployment
,
environment:
environment
,
ref:
'feature'
)
create
(
:deployment
,
environment:
environment
,
ref:
'master'
)
end
it
{
is_expected
.
to
be
false
}
end
end
end
end
spec/models/project_spec.rb
View file @
d9d69d7b
...
@@ -1688,6 +1688,48 @@ describe Project, models: true do
...
@@ -1688,6 +1688,48 @@ describe Project, models: true do
end
end
end
end
describe
'#environments_recently_updated_on_branch'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
context
'when last deployment to environment is the most recent one'
do
before
do
create
(
:deployment
,
environment:
environment
,
ref:
'feature'
)
end
it
'finds recently updated environment'
do
expect
(
project
.
environments_recently_updated_on_branch
(
'feature'
))
.
to
contain_exactly
(
environment
)
end
end
context
'when last deployment to environment is not the most recent'
do
before
do
create
(
:deployment
,
environment:
environment
,
ref:
'feature'
)
create
(
:deployment
,
environment:
environment
,
ref:
'master'
)
end
it
'does not find environment'
do
expect
(
project
.
environments_recently_updated_on_branch
(
'feature'
))
.
to
be_empty
end
end
context
'when there are two environments that deploy to the same branch'
do
let
(
:second_environment
)
{
create
(
:environment
,
project:
project
)
}
before
do
create
(
:deployment
,
environment:
environment
,
ref:
'feature'
)
create
(
:deployment
,
environment:
second_environment
,
ref:
'feature'
)
end
it
'finds both environments'
do
expect
(
project
.
environments_recently_updated_on_branch
(
'feature'
))
.
to
contain_exactly
(
environment
,
second_environment
)
end
end
end
def
enable_lfs
def
enable_lfs
allow
(
Gitlab
.
config
.
lfs
).
to
receive
(
:enabled
).
and_return
(
true
)
allow
(
Gitlab
.
config
.
lfs
).
to
receive
(
:enabled
).
and_return
(
true
)
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