Skip to content

Commit

Permalink
Silent bug: validation for min_purchase_per_txn <= max_sales_for_type…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
armandofox committed Dec 7, 2023
1 parent 38b2e5d commit 416c136
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/models/valid_voucher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
11 changes: 4 additions & 7 deletions features/step_definitions/show_and_showdate_setup_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 416c136

Please sign in to comment.