11Rails . logger . debug "Creating units..."
22
3- def create_unit ( name :, serial_prefix :, manufacturer :, operator :, description :)
3+ # Create badge batch and badges for all units
4+ badge_batch = BadgeBatch . create! ( note : "Seed data badges" , count : 8 )
5+ badges = 8 . times . map { Badge . create! ( badge_batch : badge_batch ) }
6+ badge_ids = badges . map ( &:id )
7+
8+ def create_unit ( name :, serial_prefix :, manufacturer :, operator :, description :, badge_id :)
49 Unit . create! (
510 SeedData . unit_fields . merge (
11+ id : badge_id ,
612 user : $test_user,
713 name : name ,
814 serial : "#{ serial_prefix } -#{ SecureRandom . hex ( 4 ) . upcase } " ,
@@ -19,63 +25,71 @@ def create_unit(name:, serial_prefix:, manufacturer:, operator:, description:)
1925 serial_prefix : "ACQ-2021" ,
2026 manufacturer : "Airquee Manufacturing Ltd" ,
2127 operator : "Stef's Castles" ,
22- description : "15ft x 15ft medieval themed bouncy castle with turrets"
28+ description : "15ft x 15ft medieval themed bouncy castle with turrets" ,
29+ badge_id : badge_ids [ 0 ]
2330)
2431
2532$castle_large = create_unit (
2633 name : "Giant Party Castle" ,
2734 serial_prefix : "BCN-2020" ,
2835 manufacturer : "Bouncy Castle Boys" ,
2936 operator : "Estephan Events" ,
30- description : "30ft x 30ft large bouncy castle suitable for 20+ children"
37+ description : "30ft x 30ft large bouncy castle suitable for 20+ children" ,
38+ badge_id : badge_ids [ 1 ]
3139)
3240
3341$castle_slide_combo = create_unit (
3442 name : "Princess Castle with Slide" ,
3543 serial_prefix : "J4J-2022" ,
3644 manufacturer : "Jump4Joy Inflatables" ,
3745 operator : "Stefan's Fun Factory" ,
38- description : "Pink princess themed castle with integrated 8ft slide"
46+ description : "Pink princess themed castle with integrated 8ft slide" ,
47+ badge_id : badge_ids [ 2 ]
3948)
4049
4150$soft_play_unit = create_unit (
4251 name : "Toddler Soft Play Centre" ,
4352 serial_prefix : "CIU-2023" ,
4453 manufacturer : "Custom Inflatables UK" ,
4554 operator : "Steff's Soft Play" ,
46- description : "Fully enclosed soft play area for under 5s"
55+ description : "Fully enclosed soft play area for under 5s" ,
56+ badge_id : badge_ids [ 3 ]
4757)
4858
4959$obstacle_course = create_unit (
5060 name : "Assault Course Challenge" ,
5161 serial_prefix : "IWL-2021" ,
5262 manufacturer : "Inflatable World Ltd" ,
5363 operator : "Stephan's Adventure Co" ,
54- description : "40ft assault course with obstacles, tunnels and slide finish"
64+ description : "40ft assault course with obstacles, tunnels and slide finish" ,
65+ badge_id : badge_ids [ 4 ]
5566)
5667
5768$giant_slide = create_unit (
5869 name : "Mega Slide Experience" ,
5970 serial_prefix : "ACQ-2019" ,
6071 manufacturer : "Airquee Manufacturing Ltd" ,
6172 operator : "Stefan Family Inflatables" ,
62- description : "25ft platform height giant inflatable slide"
73+ description : "25ft platform height giant inflatable slide" ,
74+ badge_id : badge_ids [ 5 ]
6375)
6476
6577$gladiator_duel = create_unit (
6678 name : "Gladiator Duel Platform" ,
6779 serial_prefix : "HHE-2022" ,
6880 manufacturer : "Happy Hop Europe" ,
6981 operator : "Stefano's Party Hire" ,
70- description : "Inflatable gladiator duel platform with pedestals"
82+ description : "Inflatable gladiator duel platform with pedestals" ,
83+ badge_id : badge_ids [ 6 ]
7184)
7285
7386$bungee_run = create_unit (
7487 name : "Double Bungee Run" ,
7588 serial_prefix : "PCM-2023" ,
7689 manufacturer : "Party Castle Manufacturers" ,
7790 operator : "Stef's Fun Factory" ,
78- description : "Two lane inflatable bungee run competition game"
91+ description : "Two lane inflatable bungee run competition game" ,
92+ badge_id : badge_ids [ 7 ]
7993)
8094
8195Rails . logger . debug { "Created #{ Unit . count } units." }
0 commit comments