Commit d1b7e0f6 authored by Tiger's avatar Tiger

Use nullify_if_blank for Environment#external_url

parent a35e8a20
......@@ -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('/')
......
......@@ -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) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment