diff --git a/db/seeds.rb b/db/seeds.rb index 9111554..5d8af9c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -57,6 +57,35 @@ end user=User.new(email: email, firstname: firstname, lastname: lastname, password_digest: BCrypt::Password.create("password"), verified: false, created_at: created_at).save! end +# Jobs paid (and some canceled) in the far past +10.times do + [ 'GanzWichtig.pdf', 'IchBinIn5MinDran.pdf', 'DerPlanDerImmerProblemeMacht.pdf', + 'DieFarbenGefallenMirNicht.pdf', 'MachHinIchHabsEilig.pdf', 'WarumDauertDasSoLange.pdf', + 'DenPlanBezahleIchNicht.pdf', 'IchWarAlsErstesDran.pdf', 'WarumIstDerPlotterDefekt.pdf', + 'DasNächsteMalGeheIchWoAndersHin.pdf' ].shuffle.each do |pdf| + status = %i[paid paid paid paid paid paid paid canceled].sample + created_at = Faker::Time.backward(days: 1.year.in_days, period: :day) + if status == :paid + printed_at = created_at + 30.minutes + paid_at = created_at + 45.minutes + status_changed_at = paid_at + updated_at = status_changed_at + else + updated_at = created_at + rand(4..44).minutes + status_changed_at = updated_at + end + job = Job.new(status:, privacy_policy: true, created_at: created_at) + job.pdf = File.open(Rails.root.join('db/pdfs/', pdf)) + job.costumer = students[rand(0...9)] + job.save! + job.update_column :printed_at, printed_at # write with update_column to avoid before_save action + job.update_column :status_changed_at, status_changed_at # write with update_column to avoid before_save action + job.update_column :paid_at, paid_at if status == :paid # write with update_column to avoid before_save action + job.update_column :updated_at, updated_at # write with update_column to avoid before_save action + end +end + + # Jobs paid (and some canceled) in the past 2.times do [ 'GanzWichtig.pdf', 'IchBinIn5MinDran.pdf', 'DerPlanDerImmerProblemeMacht.pdf',