Fix brand color validation (#14303)

This commit is contained in:
Michael Kohl 2021-07-22 15:35:20 +07:00 committed by GitHub
parent dc27f597fb
commit de043b3d6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

@ -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] }

View file

@ -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