Strip surrounding whitespace from HTMLVariant name (#15776)
This commit is contained in:
parent
9970a57841
commit
9e0570968e
2 changed files with 11 additions and 0 deletions
|
|
@ -8,6 +8,8 @@ class HtmlVariant < ApplicationRecord
|
|||
has_many :html_variant_successes, dependent: :destroy
|
||||
has_many :html_variant_trials, dependent: :destroy
|
||||
|
||||
before_validation :strip_whitespace
|
||||
|
||||
validates :group, inclusion: { in: GROUP_NAMES }
|
||||
validates :html, presence: true
|
||||
validates :name, uniqueness: true
|
||||
|
|
@ -77,4 +79,8 @@ class HtmlVariant < ApplicationRecord
|
|||
def allowed_image_host?(src)
|
||||
src.start_with?("https://res.cloudinary.com/") || src.start_with?(Images::Optimizer.get_imgproxy_endpoint)
|
||||
end
|
||||
|
||||
def strip_whitespace
|
||||
name.strip!
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -70,4 +70,9 @@ RSpec.describe HtmlVariant, type: :model do
|
|||
html_variant.save
|
||||
expect(Images::Optimizer).not_to have_received(:call)
|
||||
end
|
||||
|
||||
it "strips whitespace from the name" do
|
||||
variant = create(:html_variant, name: " hello world ")
|
||||
variant.reload.name.should eq "hello world"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue