Revert "Validate voucher code doesn't contain new line characters"

This reverts commit 0c0b85f4c4.
This commit is contained in:
Cillian O'Ruanaidh
2023-08-04 10:04:14 +01:00
parent 0c0b85f4c4
commit ab0d899a17
2 changed files with 1 additions and 14 deletions

View File

@@ -1,8 +1,6 @@
# frozen_string_literal: false
class Voucher < ApplicationRecord
INVALID_CODE_REGEX = /(\r|\n)/
acts_as_paranoid
belongs_to :enterprise, optional: false
@@ -14,8 +12,7 @@ class Voucher < ApplicationRecord
before_validation :strip_code
validates :code, format: { without: INVALID_CODE_REGEX },
length: { maximum: STRING_COLUMN_LIMIT },
validates :code, length: { maximum: STRING_COLUMN_LIMIT },
presence: true, uniqueness: { scope: :enterprise_id }
validates :amount, presence: true, numericality: { greater_than: 0 }

View File

@@ -27,16 +27,6 @@ describe Voucher do
it { is_expected.to validate_uniqueness_of(:code).scoped_to(:enterprise_id) }
it { is_expected.to validate_presence_of(:amount) }
it { is_expected.to validate_numericality_of(:amount).is_greater_than(0) }
it { is_expected.to allow_value("somethingvalid").for(:code) }
it "is invalid if the code contains certain forbidden characters e.g. new lines" do
voucher = subject
["\n", "\r"].each do |forbidden_code_character|
voucher.code = "somethingvalid#{forbidden_code_character}somethingvalid"
expect(voucher).not_to be_valid
expect(voucher.errors[:code]).to eq(["is invalid"])
end
end
end
describe '#compute_amount' do