@@ -15,6 +15,38 @@ def seed_additional_expense(case_contact: nil, case_contact_id: nil)
1515 end
1616end
1717
18+ def seed_additional_expenses ( case_contacts : nil , case_contact_ids : nil , count : 0 )
19+ if case_contacts . nil? && case_contact_ids . nil?
20+ raise ArgumentError . new ( "case_contacts: or case_contact_ids: is required" )
21+ elsif !case_contacts . nil? && !case_contact_ids . nil?
22+ raise ArgumentError . new ( "cannot use case_contacts: and case_contact_ids:" )
23+ end
24+
25+ created_additional_expense_ids = [ ]
26+
27+ if !case_contacts . nil?
28+ unless case_contacts . is_a? ( ActiveRecord ::Relation )
29+ raise TypeError . new ( "param case_contacts must be an ActiveRecord::Relation" )
30+ end
31+
32+ count . times {
33+ created_additional_expense_ids . push ( seed_additional_expense ( case_contact : case_contacts . sample ) . id )
34+ }
35+ else
36+ if !case_contact_ids . is_a? ( Array )
37+ raise TypeError . new ( "param case_contact_ids: must be an array" )
38+ elsif case_contact_ids . length === 0
39+ raise RangeError . new ( "param case_contact_ids: must contain at least one element" )
40+ end
41+
42+ count . times {
43+ created_additional_expense_ids . push ( seed_additional_expense ( case_contact_id : case_contact_ids . sample ) . id )
44+ }
45+ end
46+
47+ created_additional_expense_ids
48+ end
49+
1850# # Seeder API
1951#
2052# A File containing functions that satisfy:
@@ -24,10 +56,11 @@ def seed_additional_expense(case_contact: nil, case_contact_id: nil)
2456# - if a record requires other records to exist they are passed in as an argument to the function
2557# - accepts an active record object or a database id for each required object
2658# - error checking to make sure each of the required objects is present
59+ # - returns the new activerecord object created
2760# - one to create n records of the model
2861# - if a record requires other records to exist they are passed in as an argument to the function
2962# - the collection(s) are completely error checked so no partial record creation is possible
30- # - each function returns the activerecord collection of the created record(s)
63+ # - returns an array of the ids of the records created
3164
3265#
3366# addresses
0 commit comments