Commit 85f370f9 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Move OncallSchedule model to EE

Move the model to EE. It's only available for Gitlab Premium.
parent 279cb5d7
...@@ -273,7 +273,6 @@ class Project < ApplicationRecord ...@@ -273,7 +273,6 @@ class Project < ApplicationRecord
has_many :alert_management_alerts, class_name: 'AlertManagement::Alert', inverse_of: :project has_many :alert_management_alerts, class_name: 'AlertManagement::Alert', inverse_of: :project
has_many :alert_management_http_integrations, class_name: 'AlertManagement::HttpIntegration', inverse_of: :project has_many :alert_management_http_integrations, class_name: 'AlertManagement::HttpIntegration', inverse_of: :project
has_many :incident_management_oncall_schedules, class_name: 'IncidentManagement::OncallSchedule', inverse_of: :project
# Container repositories need to remove data from the container registry, # Container repositories need to remove data from the container registry,
# which is not managed by the DB. Hence we're still using dependent: :destroy # which is not managed by the DB. Hence we're still using dependent: :destroy
......
...@@ -98,6 +98,8 @@ module EE ...@@ -98,6 +98,8 @@ module EE
has_many :sourced_pipelines, class_name: 'Ci::Sources::Project', foreign_key: :source_project_id has_many :sourced_pipelines, class_name: 'Ci::Sources::Project', foreign_key: :source_project_id
has_many :incident_management_oncall_schedules, class_name: 'IncidentManagement::OncallSchedule', inverse_of: :project
scope :with_shared_runners_limit_enabled, -> do scope :with_shared_runners_limit_enabled, -> do
if ::Ci::Runner.has_shared_runners_with_non_zero_public_cost? if ::Ci::Runner.has_shared_runners_with_non_zero_public_cost?
with_shared_runners with_shared_runners
......
...@@ -9,7 +9,6 @@ module IncidentManagement ...@@ -9,7 +9,6 @@ module IncidentManagement
NAME_LENGTH = 200 NAME_LENGTH = 200
DESCRIPTION_LENGTH = 1000 DESCRIPTION_LENGTH = 1000
TIMEZONE_LENGTH = 100
belongs_to :project, inverse_of: :incident_management_oncall_schedules belongs_to :project, inverse_of: :incident_management_oncall_schedules
...@@ -17,6 +16,12 @@ module IncidentManagement ...@@ -17,6 +16,12 @@ module IncidentManagement
validates :name, presence: true, length: { maximum: NAME_LENGTH } validates :name, presence: true, length: { maximum: NAME_LENGTH }
validates :description, length: { maximum: DESCRIPTION_LENGTH } validates :description, length: { maximum: DESCRIPTION_LENGTH }
validates :timezone, presence: true, length: { maximum: TIMEZONE_LENGTH } validates :timezone, presence: true, inclusion: { in: :timezones }
private
def timezones
@timezones ||= ActiveSupport::TimeZone.all.map { |tz| tz.tzinfo.identifier }
end
end end
end end
...@@ -10,12 +10,33 @@ RSpec.describe IncidentManagement::OncallSchedule do ...@@ -10,12 +10,33 @@ RSpec.describe IncidentManagement::OncallSchedule do
end end
describe '.validations' do describe '.validations' do
let(:timezones) { ActiveSupport::TimeZone.all.map { |tz| tz.tzinfo.identifier } }
subject { build(:incident_management_oncall_schedule, project: project) } subject { build(:incident_management_oncall_schedule, project: project) }
it { is_expected.to validate_presence_of(:name) } it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_length_of(:name).is_at_most(200) } it { is_expected.to validate_length_of(:name).is_at_most(200) }
it { is_expected.to validate_length_of(:description).is_at_most(1000) } it { is_expected.to validate_length_of(:description).is_at_most(1000) }
it { is_expected.to validate_presence_of(:timezone) } it { is_expected.to validate_presence_of(:timezone) }
it { is_expected.to validate_length_of(:timezone).is_at_most(100) } it { is_expected.to validate_inclusion_of(:timezone).in_array(timezones) }
context 'when the oncall schedule with the same name exists' do
before do
create(:incident_management_oncall_schedule, project: project)
end
it 'has validation errors' do
expect(subject).to be_invalid
expect(subject.errors.full_messages.to_sentence).to eq('Name has already been taken')
end
end
end
it_behaves_like 'AtomicInternalId' do
let(:internal_id_attribute) { :iid }
let(:instance) { build(:incident_management_oncall_schedule) }
let(:scope) { :project }
let(:scope_attrs) { { project: instance.project } }
let(:usage) { :incident_management_oncall_schedules }
end end
end end
...@@ -51,6 +51,8 @@ RSpec.describe Project do ...@@ -51,6 +51,8 @@ RSpec.describe Project do
it { is_expected.to have_many(:project_aliases) } it { is_expected.to have_many(:project_aliases) }
it { is_expected.to have_many(:approval_rules) } it { is_expected.to have_many(:approval_rules) }
it { is_expected.to have_many(:incident_management_oncall_schedules).class_name('IncidentManagement::OncallSchedule') }
describe 'approval_rules association' do describe 'approval_rules association' do
let_it_be(:rule, reload: true) { create(:approval_project_rule) } let_it_be(:rule, reload: true) { create(:approval_project_rule) }
let(:project) { rule.project } let(:project) { rule.project }
......
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