Commit 6e700f55 authored by David Kim's avatar David Kim

Merge branch 'nullify-if-blank-environment-external-url' into 'master'

Use nullify_if_blank for Environment#external_url

See merge request gitlab-org/gitlab!66589
parents cb233f0e d1b7e0f6
...@@ -5,6 +5,7 @@ class Environment < ApplicationRecord ...@@ -5,6 +5,7 @@ class Environment < ApplicationRecord
include ReactiveCaching include ReactiveCaching
include FastDestroyAll::Helpers include FastDestroyAll::Helpers
include Presentable include Presentable
include NullifyIfBlank
self.reactive_cache_refresh_interval = 1.minute self.reactive_cache_refresh_interval = 1.minute
self.reactive_cache_lifetime = 55.seconds self.reactive_cache_lifetime = 55.seconds
...@@ -14,6 +15,7 @@ class Environment < ApplicationRecord ...@@ -14,6 +15,7 @@ class Environment < ApplicationRecord
belongs_to :project, required: true belongs_to :project, required: true
use_fast_destroy :all_deployments use_fast_destroy :all_deployments
nullify_if_blank :external_url
has_many :all_deployments, class_name: 'Deployment' has_many :all_deployments, class_name: 'Deployment'
has_many :deployments, -> { visible } has_many :deployments, -> { visible }
...@@ -33,7 +35,6 @@ class Environment < ApplicationRecord ...@@ -33,7 +35,6 @@ class Environment < ApplicationRecord
has_one :upcoming_deployment, -> { running.distinct_on_environment }, class_name: 'Deployment', inverse_of: :environment 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 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_validation :generate_slug, if: ->(env) { env.slug.blank? }
before_save :set_environment_type before_save :set_environment_type
...@@ -230,10 +231,6 @@ class Environment < ApplicationRecord ...@@ -230,10 +231,6 @@ class Environment < ApplicationRecord
ref.to_s == last_deployment.try(:ref) ref.to_s == last_deployment.try(:ref)
end end
def nullify_external_url
self.external_url = nil if self.external_url.blank?
end
def set_environment_type def set_environment_type
names = name.split('/') names = name.split('/')
......
...@@ -14,6 +14,7 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do ...@@ -14,6 +14,7 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
subject(:environment) { create(:environment, project: project) } subject(:environment) { create(:environment, project: project) }
it { is_expected.to be_kind_of(ReactiveCaching) } 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 belong_to(:project).required }
it { is_expected.to have_many(:deployments) } it { is_expected.to have_many(:deployments) }
...@@ -412,15 +413,6 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do ...@@ -412,15 +413,6 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
end end
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 describe '#includes_commit?' do
let(:project) { create(:project, :repository) } 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