Skip to content
Snippets Groups Projects
Commit d1b7e0f6 authored by Tiger Watson's avatar Tiger Watson
Browse files

Use nullify_if_blank for Environment#external_url

parent a35e8a20
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
Loading
Loading
@@ -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 }
Loading
Loading
@@ -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
Loading
Loading
@@ -230,10 +231,6 @@ def recently_updated_on_branch?(ref)
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('/')
 
Loading
Loading
Loading
Loading
@@ -14,6 +14,7 @@
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) }
Loading
Loading
@@ -412,15 +413,6 @@
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) }
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment