FIX: Validate email_accent_bg_color color (#13778)

Using an invalid value was allowed. This commit tries to automatically
fix the color by adding missing # symbol or will show an error to the
user if it is not possible and it is not a CSS color either.
This commit is contained in:
Bianca Nenciu
2021-07-22 17:42:47 +03:00
committed by GitHub
parent 3667cc6447
commit 18c32a809b
5 changed files with 88 additions and 4 deletions

View File

@ -0,0 +1,23 @@
# frozen_string_literal: true
require 'rails_helper'
describe CssColorValidator do
subject { described_class.new }
it "validates hex colors" do
expect(subject.valid_value?('#0')).to eq(false)
expect(subject.valid_value?('#00')).to eq(false)
expect(subject.valid_value?('#000')).to eq(true)
expect(subject.valid_value?('#0000')).to eq(false)
expect(subject.valid_value?('#00000')).to eq(false)
expect(subject.valid_value?('#000000')).to eq(true)
end
it "validates css colors" do
expect(subject.valid_value?('red')).to eq(true)
expect(subject.valid_value?('green')).to eq(true)
expect(subject.valid_value?('blue')).to eq(true)
expect(subject.valid_value?('hello')).to eq(false)
end
end