File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,11 @@ class Purchase < ApplicationRecord
6060 validates :amount_spent_in_cents , numericality : { greater_than : 0 }
6161 validate :total_equal_to_all_categories
6262
63+ validates :amount_spent_on_diapers_cents , numericality : { greater_than_or_equal_to : 0 }
64+ validates :amount_spent_on_adult_incontinence_cents , numericality : { greater_than_or_equal_to : 0 }
65+ validates :amount_spent_on_period_supplies_cents , numericality : { greater_than_or_equal_to : 0 }
66+ validates :amount_spent_on_other_cents , numericality : { greater_than_or_equal_to : 0 }
67+
6368 SummaryByDates = Data . define (
6469 :amount_spent ,
6570 :recent_purchases ,
Original file line number Diff line number Diff line change 5454 expect ( d ) . to be_valid
5555 end
5656
57+ it "is not valid if any category negative" do
58+ d = build ( :purchase , amount_spent_on_diapers_cents : -1 )
59+ expect ( d ) . not_to be_valid
60+ d = build ( :purchase , amount_spent_on_adult_incontinence_cents : -2 )
61+ expect ( d ) . not_to be_valid
62+ d = build ( :purchase , amount_spent_on_period_supplies_cents : -3 )
63+ expect ( d ) . not_to be_valid
64+ d = build ( :purchase , amount_spent_on_other_cents : -4 )
65+ expect ( d ) . not_to be_valid
66+ end
67+
68+ it "is valid if all categories are positive and add up to the total" do
69+ d = build ( :purchase , amount_spent_in_cents : 1150 ,
70+ amount_spent_on_diapers_cents : 200 ,
71+ amount_spent_on_adult_incontinence_cents : 300 ,
72+ amount_spent_on_period_supplies_cents : 400 ,
73+ amount_spent_on_other_cents : 250 )
74+ expect ( d ) . to be_valid
75+ end
76+
5777 # 2813 update annual reports -- this covers off making sure it's checking the case of period supplies only (which it won't be before we make it so)
5878
5979 it "is not valid if period supplies is non-zero but no other category is " do
You can’t perform that action at this time.
0 commit comments