From e09f115e009ae0329905d5d9c28fd746867fa386 Mon Sep 17 00:00:00 2001 From: Sydney Young Date: Wed, 18 May 2016 15:02:44 -0400 Subject: [PATCH] Seed script no longer generates reservations with impossible dates Resolves #1229 and #1263 - Seed script uses TimeHelpers to save reservations in the past, allowing validations to be run on them --- db/seeds.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index a7ea63730..a7bd4174c 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -23,6 +23,7 @@ require 'ffaker' require 'ruby-progressbar' +include ActiveSupport::Testing::TimeHelpers # rubocop:disable Rails/Output @@ -279,7 +280,7 @@ def throw_into_past(res) res.due_date = res.due_date - factor mark_checked_out res mark_checked_in(res, res.equipment_model.category.max_checkout_length) - res.save(validate: false) + travel_to(res.start_date) { res.save } end # rubocop:disable AbcSize, MethodLength @@ -299,10 +300,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!