Commit 4f8ebc34 authored by Dmytro Zaporozhets's avatar Dmytro Zaporozhets

Merge branch 'rc/allow_blank_dashboard_url' into 'master'

Allow blank external_dashboard_url

See merge request gitlab-org/gitlab!33423
parents e4414cca 3b051f52
......@@ -4,6 +4,7 @@ class ProjectMetricsSetting < ApplicationRecord
belongs_to :project
validates :external_dashboard_url,
allow_nil: true,
length: { maximum: 255 },
addressable_url: { enforce_sanitization: true, ascii_only: true }
......
......@@ -41,9 +41,9 @@ module Projects
attribs = params[:metrics_setting_attributes]
return {} unless attribs
destroy = attribs[:external_dashboard_url].blank?
attribs[:external_dashboard_url] = attribs[:external_dashboard_url].presence
{ metrics_setting_attributes: attribs.merge(_destroy: destroy) }
{ metrics_setting_attributes: attribs }
end
def error_tracking_params
......
......@@ -44,12 +44,12 @@ describe ProjectMetricsSetting do
it { is_expected.to be_valid }
end
context 'external_dashboard_url is blank' do
before do
subject.external_dashboard_url = ''
end
context 'dashboard_timezone' do
it { is_expected.to define_enum_for(:dashboard_timezone).with_values({ local: 0, utc: 1 }) }
it { is_expected.to be_invalid }
it 'defaults to local' do
expect(subject.dashboard_timezone).to eq('local')
end
end
end
end
......@@ -126,21 +126,23 @@ describe Projects::Operations::UpdateService do
)
expect(project.metrics_setting.dashboard_timezone).to eq('utc')
end
end
context 'with blank external_dashboard_url in params' do
let(:params) do
{
metrics_setting_attributes: {
external_dashboard_url: ''
}
context 'with blank external_dashboard_url' do
let(:params) do
{
metrics_setting_attributes: {
external_dashboard_url: '',
dashboard_timezone: 'utc'
}
end
}
end
it 'destroys the metrics_setting entry in DB' do
expect(result[:status]).to eq(:success)
it 'updates dashboard_timezone' do
expect(result[:status]).to eq(:success)
expect(project.reload.metrics_setting).to be_nil
end
expect(project.reload.metrics_setting.external_dashboard_url).to be(nil)
expect(project.metrics_setting.dashboard_timezone).to eq('utc')
end
end
end
......
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