From a152163b04422aaa226370f7de65f56b6803e4a3 Mon Sep 17 00:00:00 2001 From: Gauri Joshi Date: Thu, 27 Jun 2024 20:37:47 -0700 Subject: [PATCH 1/7] Add create_other_duties for volunteers only --- db/seeds/db_populator.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/db/seeds/db_populator.rb b/db/seeds/db_populator.rb index ca57427fcd..f6cf04bb16 100644 --- a/db/seeds/db_populator.rb +++ b/db/seeds/db_populator.rb @@ -58,6 +58,21 @@ def create_org(options_hash) private # ------------------------------------------------------------------------------------------------------- + # Create other duties (only if Volunteer) + def create_other_duties(casa_org) + Volunteer.where(casa_org: casa_org).find_each do |v| + rand(1..5).times do + OtherDuty.create!( + creator_id: v.id, + creator_type: "Volunteer", + occurred_at: Faker::Date.between(2.days.ago, Date.today), + duration_minutes: rand(5..180), + notes: Faker::Lorem.words(3..7) + ) + end + end + end + # Create 2 judges for each casa_org. def create_judges(casa_org) 2.times { Judge.create(name: Faker::Name.name, casa_org: casa_org) } From b84d55e5884e33f9321e1ebb311603e779ec3ba5 Mon Sep 17 00:00:00 2001 From: Gauri Joshi Date: Thu, 27 Jun 2024 20:39:49 -0700 Subject: [PATCH 2/7] Remove casa_org param to apply other duties to all volunteers regardless of casa org --- db/seeds/db_populator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/seeds/db_populator.rb b/db/seeds/db_populator.rb index f6cf04bb16..5eb273361e 100644 --- a/db/seeds/db_populator.rb +++ b/db/seeds/db_populator.rb @@ -59,8 +59,8 @@ def create_org(options_hash) private # ------------------------------------------------------------------------------------------------------- # Create other duties (only if Volunteer) - def create_other_duties(casa_org) - Volunteer.where(casa_org: casa_org).find_each do |v| + def create_other_duties + Volunteer.where.find_each do |v| rand(1..5).times do OtherDuty.create!( creator_id: v.id, From 9cedaaff5f783dedcbce11fe40b7954fec056445 Mon Sep 17 00:00:00 2001 From: Gauri Joshi Date: Sun, 7 Jul 2024 14:39:46 -0700 Subject: [PATCH 3/7] other_duties_counter initialized to 0 --- db/seeds/db_populator.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/db/seeds/db_populator.rb b/db/seeds/db_populator.rb index 5eb273361e..850a8b0f36 100644 --- a/db/seeds/db_populator.rb +++ b/db/seeds/db_populator.rb @@ -19,6 +19,7 @@ def initialize(random_instance, case_fourteen_years_old: false) @casa_org_counter = 0 @case_number_sequence = 1000 @case_fourteen_years_old = case_fourteen_years_old + @other_duties_counter = 0 ## adds other duties counter end def create_all_casa_admin(email) From acae87f8b638967e21835b67dcb5c9e1dd4f8c56 Mon Sep 17 00:00:00 2001 From: Gauri Joshi Date: Sun, 7 Jul 2024 14:40:45 -0700 Subject: [PATCH 4/7] Call on new private method create_other_duties --- db/seeds/db_populator.rb | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/db/seeds/db_populator.rb b/db/seeds/db_populator.rb index 850a8b0f36..ff87e18b39 100644 --- a/db/seeds/db_populator.rb +++ b/db/seeds/db_populator.rb @@ -54,26 +54,12 @@ def create_org(options_hash) create_learning_hour_types(casa_org) create_learning_hour_topics(casa_org) create_learning_hours(casa_org) + create_other_duties casa_org end private # ------------------------------------------------------------------------------------------------------- - # Create other duties (only if Volunteer) - def create_other_duties - Volunteer.where.find_each do |v| - rand(1..5).times do - OtherDuty.create!( - creator_id: v.id, - creator_type: "Volunteer", - occurred_at: Faker::Date.between(2.days.ago, Date.today), - duration_minutes: rand(5..180), - notes: Faker::Lorem.words(3..7) - ) - end - end - end - # Create 2 judges for each casa_org. def create_judges(casa_org) 2.times { Judge.create(name: Faker::Name.name, casa_org: casa_org) } From 9d54e36af88707bcff55fd2da8e6ad0ba4dd5162 Mon Sep 17 00:00:00 2001 From: Gauri Joshi Date: Sun, 7 Jul 2024 14:41:57 -0700 Subject: [PATCH 5/7] create_other_duties maps through Volunteer to create OtherDuty 2x. Increments to the other_duties_counter each time and prints statement of how many other duties were created --- db/seeds/db_populator.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/db/seeds/db_populator.rb b/db/seeds/db_populator.rb index ff87e18b39..e1aaa8d8f1 100644 --- a/db/seeds/db_populator.rb +++ b/db/seeds/db_populator.rb @@ -106,6 +106,25 @@ def create_users(casa_org, options) Volunteer.all.each { |v| v.supervisor = supervisors.sample(random: rng) } end + # Create other duties (Volunteer only) + # Increment other_duties_counter by 1 each time other duty is created + # Print out statement that indicates number of other duties created + + def create_other_duties + Volunteer.map do |v| + 2.times { + OtherDuty.create!( + creator_id: v.id, + creator_type: "Volunteer", + occurred_at: Faker::Date.between(from: 2.days.ago, to: Date.today), + duration_minutes: rand(5..180), + notes: Faker::Lorem.sentence + )} + @other_duties_counter =+ 1 + end + puts "Created #{@other_duties_counter} Other Duties." + end + def generate_case_number # CINA-YY-XXXX years = ((DateTime.now.year - 20)..DateTime.now.year).to_a From 350963b514cb6395eaa79ba2742743b5fd27f860 Mon Sep 17 00:00:00 2001 From: Gauri Joshi Date: Mon, 8 Jul 2024 20:50:43 -0700 Subject: [PATCH 6/7] Modifies enumerable to find_each + returns other_duties_counter after OtherDuty.create --- db/seeds/db_populator.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/db/seeds/db_populator.rb b/db/seeds/db_populator.rb index e1aaa8d8f1..0d52e54e84 100644 --- a/db/seeds/db_populator.rb +++ b/db/seeds/db_populator.rb @@ -54,7 +54,7 @@ def create_org(options_hash) create_learning_hour_types(casa_org) create_learning_hour_topics(casa_org) create_learning_hours(casa_org) - create_other_duties + create_other_duties casa_org end @@ -111,17 +111,18 @@ def create_users(casa_org, options) # Print out statement that indicates number of other duties created def create_other_duties - Volunteer.map do |v| + Volunteer.find_each do |v| 2.times { OtherDuty.create!( - creator_id: v.id, - creator_type: "Volunteer", - occurred_at: Faker::Date.between(from: 2.days.ago, to: Date.today), - duration_minutes: rand(5..180), - notes: Faker::Lorem.sentence - )} - @other_duties_counter =+ 1 - end + creator_id: v.id, + creator_type: "Volunteer", + occurred_at: Faker::Date.between(from: 2.days.ago, to: Date.today), + duration_minutes: rand(5..180), + notes: Faker::Lorem.sentence + ) + @other_duties_counter = + 1 + } + end puts "Created #{@other_duties_counter} Other Duties." end From 23a021098e67f3ff1c4a19aeac2605e1d2db2398 Mon Sep 17 00:00:00 2001 From: Gauri Joshi Date: Sat, 13 Jul 2024 14:38:53 -0700 Subject: [PATCH 7/7] Add OtherDuty to main seeds file and remove counter and puts statement from seeder --- db/seeds.rb | 1 + db/seeds/db_populator.rb | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index 02e87c3099..1219fa7d6a 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -68,6 +68,7 @@ def active_record_classes LearningHourType, LearningHourTopic, MileageRate, + OtherDuty, Supervisor, SupervisorVolunteer, User, diff --git a/db/seeds/db_populator.rb b/db/seeds/db_populator.rb index 0d52e54e84..d6717e44c0 100644 --- a/db/seeds/db_populator.rb +++ b/db/seeds/db_populator.rb @@ -19,7 +19,6 @@ def initialize(random_instance, case_fourteen_years_old: false) @casa_org_counter = 0 @case_number_sequence = 1000 @case_fourteen_years_old = case_fourteen_years_old - @other_duties_counter = 0 ## adds other duties counter end def create_all_casa_admin(email) @@ -120,10 +119,8 @@ def create_other_duties duration_minutes: rand(5..180), notes: Faker::Lorem.sentence ) - @other_duties_counter = + 1 } end - puts "Created #{@other_duties_counter} Other Duties." end def generate_case_number