From ab0d899a17c2198ee4d6de9e886816f3e75abd0e Mon Sep 17 00:00:00 2001 From: Cillian O'Ruanaidh Date: Fri, 4 Aug 2023 10:04:14 +0100 Subject: [PATCH] Revert "Validate voucher code doesn't contain new line characters" This reverts commit 0c0b85f4c41c8e5a3136fd155be2062961fcfb9e. --- app/models/voucher.rb | 5 +---- spec/models/voucher_spec.rb | 10 ---------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/app/models/voucher.rb b/app/models/voucher.rb index 6d24830534..e963c2ab92 100644 --- a/app/models/voucher.rb +++ b/app/models/voucher.rb @@ -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 } diff --git a/spec/models/voucher_spec.rb b/spec/models/voucher_spec.rb index 7ccd223acd..f965904ab1 100644 --- a/spec/models/voucher_spec.rb +++ b/spec/models/voucher_spec.rb @@ -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