Skip to content
This repository has been archived by the owner on Jul 24, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1567 from YaleSTC/1229_fix_seed_res_dates
Browse files Browse the repository at this point in the history
[1229] Seed script generates reservations with start date after due date
  • Loading branch information
orenyk committed May 22, 2016
2 parents 5e73c7d + 6d30de1 commit 1736e62
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

require 'ffaker'
require 'ruby-progressbar'
include ActiveSupport::Testing::TimeHelpers

# rubocop:disable Rails/Output

Expand Down Expand Up @@ -62,6 +63,9 @@
# odds a scheduled reservation has not been picked up
MISSED_CHANCE = 0.2

# odds that a checked out reservation has been returned
RETURNED_CHANCE = 0.5

# time in the future reservations could be scheduled
FUTURE_RANGE = 3.months

Expand Down Expand Up @@ -277,9 +281,12 @@ def throw_into_past(res)
factor = rand(1.day..PAST_RANGE)
res.start_date = res.start_date - factor
res.due_date = res.due_date - factor
travel_to(res.start_date) { res.save }
mark_checked_out res
return if res.status == 'missed' || rand < RETURNED_CHANCE

mark_checked_in(res, res.equipment_model.category.max_checkout_length)
res.save(validate: false)
travel_to(res.due_date) { res.save } unless res.overdue
end

# rubocop:disable AbcSize, MethodLength
Expand All @@ -299,10 +306,9 @@ def generate_reservation
checkout_length.days).to_date
res.notes = FFaker::HipsterIpsum.paragraph(8)
res.notes_unsent = [true, false].sample
if rand < PAST_CHANCE
throw_into_past res
return
end

throw_into_past res if rand < PAST_CHANCE

try_again = false
begin
res.save!
Expand Down

0 comments on commit 1736e62

Please sign in to comment.