From 416c1368c34979a4fd17fbaed12a97a59437cb5f Mon Sep 17 00:00:00 2001 From: Armando Fox Date: Wed, 6 Dec 2023 20:11:08 -0800 Subject: [PATCH] Silent bug: validation for min_purchase_per_txn <= max_sales_for_type should not happen if max_sales_for_type was deliberately set to zero. Bug was silent because we were using old ValidVoucher.new() code in step defs, rather than using the factory. --- app/models/valid_voucher.rb | 2 +- .../step_definitions/show_and_showdate_setup_steps.rb | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/models/valid_voucher.rb b/app/models/valid_voucher.rb index cf7e4bc2a..7f50f1aeb 100644 --- a/app/models/valid_voucher.rb +++ b/app/models/valid_voucher.rb @@ -119,7 +119,7 @@ def self_service_comps_must_have_promo_code # This is checked *after* each attribute is individually range-checked def min_max_sales_constraints errors.add :min_sales_per_txn, "cannot be greater than max allowed sales of this type" if - min_sales_per_txn > max_sales_for_type + min_sales_per_txn > max_sales_for_type && max_sales_for_type != 0 errors.add :min_sales_per_txn, "cannot be greater than maximum purchase per transaction" if min_sales_per_txn > max_sales_per_txn errors.empty? diff --git a/features/step_definitions/show_and_showdate_setup_steps.rb b/features/step_definitions/show_and_showdate_setup_steps.rb index ddf2b6204..994a15cee 100644 --- a/features/step_definitions/show_and_showdate_setup_steps.rb +++ b/features/step_definitions/show_and_showdate_setup_steps.rb @@ -149,13 +149,10 @@ Given /^there are (\d+) "(.*)" tickets and (\d+) total seats available$/ do |per_ticket_limit, vouchertype_name, seat_limit| vtype = Vouchertype.find_by_name!(vouchertype_name) vtype.valid_vouchers = [] - vtype.valid_vouchers << - ValidVoucher.new( - :showdate => @showdate, - :start_sales => 1.week.ago, - :end_sales => @showdate.thedate, - :max_sales_for_type => per_ticket_limit - ) + create(:valid_voucher, + :vouchertype => vtype, + :showdate => @showdate, + :max_sales_for_type => per_ticket_limit) @showdate.update_attributes!(:max_advance_sales => seat_limit) end