Skip to content

Commit

Permalink
working thru punch list
Browse files Browse the repository at this point in the history
  • Loading branch information
armandofox committed Oct 18, 2023
1 parent 819b289 commit c24573e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
8 changes: 5 additions & 3 deletions app/models/valid_voucher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class InvalidProcessedByError < RuntimeError ; end
validates_associated :showdate, :if => lambda { |v| !(v.vouchertype.bundle?) }
validates_associated :vouchertype
validates_numericality_of :max_sales_for_type, :allow_nil => true, :greater_than_or_equal_to => 0
validates_numericality_of :min_sales_per_txn, :greater_than_or_equal_to => 1, :less_than_or_equal_to => INFINITE
validates_numericality_of :max_sales_per_txn, :greater_than_or_equal_to => 1, :less_than_or_equal_to => INFINITE
validates_numericality_of :min_sales_per_txn, :greater_than_or_equal_to => 1, :less_than_or_equal_to => INFINITE, :message => "must be blank, or greater than or equal to 1"
validates_numericality_of :max_sales_per_txn, :greater_than_or_equal_to => 1, :less_than_or_equal_to => INFINITE, :message => "must be blank, or greater than or equal to 1"
validate :min_max_sales_do_not_conflict
validates_presence_of :start_sales
validates_presence_of :end_sales
Expand Down Expand Up @@ -89,7 +89,7 @@ def min_and_max_sales_for_this_txn

def display_min_and_max_sales_per_txn
if min_sales_per_txn == 1
max_sales_per_txn == INFINITE ? '' : "(max #{max_sales_per_txn}/order)"
max_sales_per_txn == INFINITE ? '' : "(max #{max_sales_per_txn} per order)"
else # minimum order
case max_sales_per_txn
when min_sales_per_txn then "(#{min_sales_per_txn} per order)"
Expand All @@ -114,6 +114,8 @@ def self_service_comps_must_have_promo_code
def min_max_sales_do_not_conflict
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
errors.add :min_sales_per_txn, "cannot be greater than minimum purchase per transaction" if
min_sales_per_txn > max_sales_per_txn
errors.empty?
end

Expand Down
4 changes: 2 additions & 2 deletions config/locales/en.popup_help.yml
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,13 @@ en:
valid_voucher_min_sales_per_txn:

Minimum number of tickets of this type that can be purchased in one transaction.
For example, set it to 2 to offer a 2-ticket pack. Default is 1.
For example, set it to 2 to offer a 2-ticket pack. Leave blank for 1.

valid_voucher_max_sales_per_txn:

Maximum number of tickets of this type that can be purchased in one transaction.
For example, you can limit sales of a promo or discount ticket to a maximum
per transaction. Default is no limit.
per transaction. Leave blank for unlimited.

valid_voucher_promo_code: >
Expand Down
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
en:
activerecord:
attributes:
valid_voucher:
min_sales_per_txn: "Minimum purchase per transaction"

reports:
revenue_details:
csv_error: >
Expand Down
10 changes: 10 additions & 0 deletions spec/models/valid_voucher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
end
end

describe "has a friendly error message for min_sales_per_txn" do
specify "for min_sales_per_txn" do
@v = build(:valid_voucher)
@v.min_sales_per_txn = -1
expect(@v).not_to be_valid
expect(@v.errors.full_messages).to include_match_for /^Minimum purchase per transaction must be blank, or greater than or equal to 1$/
end
end


describe "seats remaining" do
subject do
ValidVoucher.new(
Expand Down

0 comments on commit c24573e

Please sign in to comment.