Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not allow spaces in external billing #13081

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/models/enterprise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/ },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't familiar with the \A or \Z, so I tested this out. A website like regexr.com is really handy for testing and perfecting regular expressions.

I don't think this is what was intended, and it would always be considered invalid. Can you please add at least one other test to ensure that a valid Billing ID is validated correctly.

Screenshot 2025-01-28 at 12 47 40 pm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it seems I messed up with the regex, not sure how the tests is passing... I will update with a standard one : /^\S+$/.
image

allow_blank: true

before_validation :initialize_permalink, if: lambda { permalink.nil? }
before_validation :set_unused_address_fields
Expand Down
7 changes: 7 additions & 0 deletions spec/models/enterprise_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading