Commit 3b051f52 authored by Ryan Cobb's avatar Ryan Cobb

Allow blank external_dashboard_url

Allow blank external_dashboard_url on project_metrics_setting. This is
needed so we can change other fields while keeping
external_dashboard_url blank.
parent cdec1cad
...@@ -4,6 +4,7 @@ class ProjectMetricsSetting < ApplicationRecord ...@@ -4,6 +4,7 @@ class ProjectMetricsSetting < ApplicationRecord
belongs_to :project belongs_to :project
validates :external_dashboard_url, validates :external_dashboard_url,
allow_nil: true,
length: { maximum: 255 }, length: { maximum: 255 },
addressable_url: { enforce_sanitization: true, ascii_only: true } addressable_url: { enforce_sanitization: true, ascii_only: true }
......
...@@ -41,9 +41,9 @@ module Projects ...@@ -41,9 +41,9 @@ module Projects
attribs = params[:metrics_setting_attributes] attribs = params[:metrics_setting_attributes]
return {} unless attribs 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 end
def error_tracking_params def error_tracking_params
......
...@@ -44,12 +44,12 @@ describe ProjectMetricsSetting do ...@@ -44,12 +44,12 @@ describe ProjectMetricsSetting do
it { is_expected.to be_valid } it { is_expected.to be_valid }
end end
context 'external_dashboard_url is blank' do context 'dashboard_timezone' do
before do it { is_expected.to define_enum_for(:dashboard_timezone).with_values({ local: 0, utc: 1 }) }
subject.external_dashboard_url = ''
end
it { is_expected.to be_invalid } it 'defaults to local' do
expect(subject.dashboard_timezone).to eq('local')
end
end end
end end
end end
...@@ -126,21 +126,23 @@ describe Projects::Operations::UpdateService do ...@@ -126,21 +126,23 @@ describe Projects::Operations::UpdateService do
) )
expect(project.metrics_setting.dashboard_timezone).to eq('utc') expect(project.metrics_setting.dashboard_timezone).to eq('utc')
end end
end
context 'with blank external_dashboard_url in params' do context 'with blank external_dashboard_url' do
let(:params) do let(:params) do
{ {
metrics_setting_attributes: { metrics_setting_attributes: {
external_dashboard_url: '' external_dashboard_url: '',
dashboard_timezone: 'utc'
} }
} }
end end
it 'destroys the metrics_setting entry in DB' do it 'updates dashboard_timezone' do
expect(result[:status]).to eq(:success) expect(result[:status]).to eq(:success)
expect(project.reload.metrics_setting).to be_nil expect(project.reload.metrics_setting.external_dashboard_url).to be(nil)
end expect(project.metrics_setting.dashboard_timezone).to eq('utc')
end end
end 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