From de043b3d6dd1f129d9636e1ae29c5f9a15bafd37 Mon Sep 17 00:00:00 2001 From: Michael Kohl Date: Thu, 22 Jul 2021 15:35:20 +0700 Subject: [PATCH] Fix brand color validation (#14303) --- app/models/users/setting.rb | 3 ++- spec/models/users/setting_spec.rb | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/models/users/setting.rb b/app/models/users/setting.rb index a998f66d3..3b45cb5c1 100644 --- a/app/models/users/setting.rb +++ b/app/models/users/setting.rb @@ -17,7 +17,8 @@ module Users validates :brand_color1, :brand_color2, - format: { with: HEX_COLOR_REGEXP, message: "is not a valid hex color" } + format: { with: HEX_COLOR_REGEXP, message: "is not a valid hex color" }, + allow_nil: true validates :user_id, presence: true validates :experience_level, numericality: { less_than_or_equal_to: 10 }, allow_blank: true validates :feed_referential_link, inclusion: { in: [true, false] } diff --git a/spec/models/users/setting_spec.rb b/spec/models/users/setting_spec.rb index d57caf47e..25d951a60 100644 --- a/spec/models/users/setting_spec.rb +++ b/spec/models/users/setting_spec.rb @@ -29,6 +29,11 @@ RSpec.describe Users::Setting, type: :model do expect(setting).to be_valid end + it "is valid if the brand color is nil" do + setting.brand_color1 = nil + expect(setting).to be_valid + end + it "is invalid if the field is too long" do setting.brand_color1 = "#deadbeef" expect(setting).not_to be_valid