mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Revert "Validate voucher code doesn't contain new line characters"
This reverts commit 0c0b85f4c4.
This commit is contained in:
@@ -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 }
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user