Added more jobs in the past to seeds
This commit is contained in:
29
db/seeds.rb
29
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!
|
user=User.new(email: email, firstname: firstname, lastname: lastname, password_digest: BCrypt::Password.create("password"), verified: false, created_at: created_at).save!
|
||||||
end
|
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
|
# Jobs paid (and some canceled) in the past
|
||||||
2.times do
|
2.times do
|
||||||
[ 'GanzWichtig.pdf', 'IchBinIn5MinDran.pdf', 'DerPlanDerImmerProblemeMacht.pdf',
|
[ 'GanzWichtig.pdf', 'IchBinIn5MinDran.pdf', 'DerPlanDerImmerProblemeMacht.pdf',
|
||||||
|
|||||||
Reference in New Issue
Block a user