From 6d78ee8be4c5fc1d5073073be60bf696d66ccfc8 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Mon, 27 Jan 2025 12:47:09 +1100 Subject: [PATCH 1/5] Fix rubocop warning --- app/models/enterprise.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index b369712fb1..823c161e3d 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -133,6 +133,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 From 98251b306e01e4f9ef882af0e2395ecbb62b4d27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Tue, 4 Feb 2025 23:10:15 +0100 Subject: [PATCH 2/5] Improve the no-white-spaces regexp for enterprises --- app/models/enterprise.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 823c161e3d..9a1da2e551 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -134,7 +134,7 @@ class Enterprise < ApplicationRecord }, allow_blank: true validate :validate_white_label_logo_link validates :external_billing_id, - format: { with: /\A\S+\Z/ }, + format: { with: /^\S+$/ }, allow_blank: true before_validation :initialize_permalink, if: lambda { permalink.nil? } From 243d81c78696187d0d1818c05c00115b9a47c90f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Wed, 9 Apr 2025 23:20:51 +0200 Subject: [PATCH 3/5] Revert "Improve the no-white-spaces regexp for enterprises" This reverts commit baf89053638628052752f345b357d630d7484046. --- app/models/enterprise.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 9a1da2e551..823c161e3d 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -134,7 +134,7 @@ class Enterprise < ApplicationRecord }, allow_blank: true validate :validate_white_label_logo_link validates :external_billing_id, - format: { with: /^\S+$/ }, + format: { with: /\A\S+\Z/ }, allow_blank: true before_validation :initialize_permalink, if: lambda { permalink.nil? } From 9529acd4771d34124929740e8df159010ba36634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Wed, 9 Apr 2025 23:23:37 +0200 Subject: [PATCH 4/5] Adjust the regexp --- app/models/enterprise.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 823c161e3d..5bd406ece8 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -134,7 +134,7 @@ class Enterprise < ApplicationRecord }, allow_blank: true validate :validate_white_label_logo_link validates :external_billing_id, - format: { with: /\A\S+\Z/ }, + format: { with: /\A\S+\z/ }, allow_blank: true before_validation :initialize_permalink, if: lambda { permalink.nil? } From 318bc1dae02dc2b68388953ed2a7254c9d3614e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Turbelin?= Date: Thu, 17 Apr 2025 21:29:23 +0200 Subject: [PATCH 5/5] Add tests --- spec/models/enterprise_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 1d05f99bd6..f553c518d0 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -415,6 +415,18 @@ RSpec.describe Enterprise do expect(e).not_to be_valid end end + + describe "external_billing_id" do + it "validates the external_billing_id attribute" do + e = build(:enterprise, external_billing_id: '123456') + expect(e).to be_valid + end + + it "does not validate the external_billing_id attribute with spaces" do + e = build(:enterprise, external_billing_id: '123 456') + expect(e).not_to be_valid + end + end end describe "serialisation" do