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
d1b7e0f6
Commit
d1b7e0f6
authored
Jul 22, 2021
by
Tiger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use nullify_if_blank for Environment#external_url
parent
a35e8a20
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
3 additions
and
14 deletions
+3
-14
app/models/environment.rb
app/models/environment.rb
+2
-5
spec/models/environment_spec.rb
spec/models/environment_spec.rb
+1
-9
No files found.
app/models/environment.rb
View file @
d1b7e0f6
...
...
@@ -5,6 +5,7 @@ class Environment < ApplicationRecord
include
ReactiveCaching
include
FastDestroyAll
::
Helpers
include
Presentable
include
NullifyIfBlank
self
.
reactive_cache_refresh_interval
=
1
.
minute
self
.
reactive_cache_lifetime
=
55
.
seconds
...
...
@@ -14,6 +15,7 @@ class Environment < ApplicationRecord
belongs_to
:project
,
required:
true
use_fast_destroy
:all_deployments
nullify_if_blank
:external_url
has_many
:all_deployments
,
class_name:
'Deployment'
has_many
:deployments
,
->
{
visible
}
...
...
@@ -33,7 +35,6 @@ class Environment < ApplicationRecord
has_one
:upcoming_deployment
,
->
{
running
.
distinct_on_environment
},
class_name:
'Deployment'
,
inverse_of: :environment
has_one
:latest_opened_most_severe_alert
,
->
{
order_severity_with_open_prometheus_alert
},
class_name:
'AlertManagement::Alert'
,
inverse_of: :environment
before_validation
:nullify_external_url
before_validation
:generate_slug
,
if:
->
(
env
)
{
env
.
slug
.
blank?
}
before_save
:set_environment_type
...
...
@@ -230,10 +231,6 @@ class Environment < ApplicationRecord
ref
.
to_s
==
last_deployment
.
try
(
:ref
)
end
def
nullify_external_url
self
.
external_url
=
nil
if
self
.
external_url
.
blank?
end
def
set_environment_type
names
=
name
.
split
(
'/'
)
...
...
spec/models/environment_spec.rb
View file @
d1b7e0f6
...
...
@@ -14,6 +14,7 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
subject
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
it
{
is_expected
.
to
be_kind_of
(
ReactiveCaching
)
}
it
{
is_expected
.
to
nullify_if_blank
(
:external_url
)
}
it
{
is_expected
.
to
belong_to
(
:project
).
required
}
it
{
is_expected
.
to
have_many
(
:deployments
)
}
...
...
@@ -412,15 +413,6 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
end
end
describe
'#nullify_external_url'
do
it
'replaces a blank url with nil'
do
env
=
build
(
:environment
,
external_url:
""
)
expect
(
env
.
save
).
to
be
true
expect
(
env
.
external_url
).
to
be_nil
end
end
describe
'#includes_commit?'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
...
...
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