File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed
Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ class Distribution < ApplicationRecord
4848 enum delivery_method : { pick_up : 0 , delivery : 1 , shipped : 2 }
4949 scope :active , -> { joins ( :line_items ) . joins ( :items ) . where ( items : { active : true } ) }
5050 scope :with_diapers , -> { joins ( line_items : :item ) . merge ( Item . disposable . or ( Item . cloth_diapers ) ) }
51+ scope :with_period_supplies , -> { joins ( line_items : :item ) . merge ( Item . period_supplies ) }
5152 # add item_id scope to allow filtering distributions by item
5253 scope :by_item_id , -> ( item_id ) { includes ( :items ) . where ( items : { id : item_id } ) }
5354 # partner scope to allow filtering by partner
Original file line number Diff line number Diff line change @@ -186,7 +186,8 @@ def self.csv_export_headers
186186 "Contact Phone" ,
187187 "Contact Email" ,
188188 "Notes" ,
189- "Providing Diapers"
189+ "Providing Diapers" ,
190+ "Providing Period Supplies"
190191 ]
191192 end
192193
@@ -204,14 +205,19 @@ def csv_export_attributes
204205 contact_person [ :phone ] ,
205206 contact_person [ :email ] ,
206207 notes ,
207- providing_diapers
208+ providing_diapers ,
209+ providing_period_supplies
208210 ]
209211 end
210212
211213 def providing_diapers
212214 distributions . with_diapers . any? ? "Y" : "N"
213215 end
214216
217+ def providing_period_supplies
218+ distributions . with_period_supplies . any? ? "Y" : "N"
219+ end
220+
215221 def contact_person
216222 return @contact_person if @contact_person
217223
Original file line number Diff line number Diff line change 300300 let ( :other_agency_type ) { "Another Agency Name" }
301301 let ( :notes ) { "Some notes" }
302302 let ( :providing_diapers ) { "N" }
303+ let ( :providing_period_supplies ) { "N" }
303304
304305 before do
305306 partner . profile . update ( {
332333 contact_phone ,
333334 contact_email ,
334335 notes ,
335- providing_diapers
336+ providing_diapers ,
337+ providing_period_supplies
336338 ] )
337339 end
338340
339341 context "when partner has a distribution" do
340342 let ( :providing_diapers ) { "Y" }
343+ let ( :providing_period_supplies ) { "Y" }
341344 let ( :distribution ) { create ( :distribution , partner : partner ) }
342345 let ( :item ) { create ( :item ) }
343346
365368 context "with a cloth diaper item" do
366369 include_examples "providing_diapers check" , :cloth_diapers
367370 end
371+
372+ context "with a period supplies item" do
373+ before do
374+ create ( :line_item , item : item , itemizable : distribution )
375+ # Mock the given scope to at least satisfy one item
376+ allow ( Item ) . to receive ( :period_supplies ) { Item . where ( id : item . id ) }
377+ end
378+
379+ it "should have Y as providing_period_supplies" do
380+ expect ( partner . csv_export_attributes [ 13 ] ) . to eq ( providing_period_supplies )
381+ end
382+ end
368383 end
369384 end
370385
You can’t perform that action at this time.
0 commit comments