OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
DRY up Color model validations
Alexander Brandon Coles2ec7690a02cb
diff --git a/app/models/color.rb b/app/models/color.rbindex ff4dd8ae343..1fefd536f7b 100644--- a/app/models/color.rb+++ b/app/models/color.rb@@ -38,9 +38,8 @@ class Color < ApplicationRecorddependent: :nullifyvalidates :name, :hexcode, presence: true-- validates :name, length: { maximum: 255, unless: lambda { |e| e.name.blank? } }- validates :hexcode, format: { with: /\A#[0-9A-F]{6}\z/, unless: lambda { |e| e.hexcode.blank? } }+ validates :name, length: { maximum: 255 }+ validates :hexcode, format: { with: RGB_HEX_FORMAT, allow_blank: true }normalizes :hexcode, with: ::Colors::HexColor::Normalizerenddiff --git a/app/models/colors/hex_color.rb b/app/models/colors/hex_color.rbindex f06dd82f179..4a37b639601 100644--- a/app/models/colors/hex_color.rb+++ b/app/models/colors/hex_color.rb@@ -30,6 +30,9 @@module Colorsmodule HexColor+ RGB_HEX_FORMAT = /\A#[0-9A-F]{6}\z/+ private_constant :RGB_HEX_FORMAT+### Get the fill style for this color.# If the color is light, use a dark font.diff --git a/app/models/design_color.rb b/app/models/design_color.rbindex aa1ca32d377..10cff1b7619 100644--- a/app/models/design_color.rb+++ b/app/models/design_color.rb@@ -43,9 +43,9 @@ class DesignColor < ApplicationRecordendend+ validates :variable, :hexcode, presence: truevalidates :variable, uniqueness: true- validates :hexcode, :variable, presence: true- validates :hexcode, format: { with: /\A#[0-9A-F]{6}\z/, unless: lambda { |e| e.hexcode.blank? } }+ validates :hexcode, format: { with: RGB_HEX_FORMAT, allow_blank: true }normalizes :hexcode, with: ::Colors::HexColor::Normalizer