Commit c3879358 authored by allison.browne's avatar allison.browne

Extract zoom meeting validators to Validator class

parent af7cd095
......@@ -5,9 +5,7 @@ class ZoomMeeting < ApplicationRecord
belongs_to :issue, optional: false
validates :url, presence: true, length: { maximum: 255 }
validate :check_zoom_url
validate :check_issue_association
validates_with ZoomMeetingValidator
enum issue_status: {
added: 1,
......@@ -17,17 +15,4 @@ class ZoomMeeting < ApplicationRecord
scope :added_to_issue, -> { where(issue_status: :added) }
scope :removed_from_issue, -> { where(issue_status: :removed) }
private
def check_zoom_url
return if Gitlab::ZoomLinkExtractor.new(url).links.size == 1
errors.add(:url, 'must contain one valid Zoom URL')
end
def check_issue_association
return if project == issue&.project
errors.add(:issue, 'must associate the same project')
end
end
# frozen_string_literal: true
# ZoomMeetingValidator
#
# Custom validator to TODO
#
class ZoomMeetingValidator < ActiveModel::Validator
def validate(zoom_meeting)
unless Gitlab::ZoomLinkExtractor.new(zoom_meeting.url).links.size == 1
zoom_meeting.errors.add(:url, 'must contain one valid Zoom URL')
end
unless zoom_meeting.project == zoom_meeting.issue&.project
zoom_meeting.errors.add(:issue, 'must associate the same project')
end
true
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