From dbb25155ca95502bf36eadb52a4104da59135f62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Sun, 19 Jan 2025 20:37:42 +0100 Subject: [PATCH] Don't allow spaces in external billing id --- app/models/enterprise.rb | 3 +++ spec/models/enterprise_spec.rb | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 15d7fb33f21..89cbf1f646a 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -127,6 +127,9 @@ class Enterprise < ApplicationRecord message: Spree.t('errors.messages.invalid_instagram_url') }, allow_blank: true validate :validate_white_label_logo_link + validates :external_billing_id, + format: { with:/\A\S+\Z/ }, + allow_blank: true before_validation :initialize_permalink, if: lambda { permalink.nil? } before_validation :set_unused_address_fields diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index de519e52e84..b34121d65fc 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -415,6 +415,13 @@ expect(e).not_to be_valid end end + + describe "external_billing_id" do + it "does not validate the external_billing_id attribute with a space" do + e = build(:enterprise, external_billing_id: 'with spaces') + expect(e).not_to be_valid + end + end end describe "serialisation" do