From 127cbcc5c7623cc3f23bf8afe94815b335e08e2c Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 16 Nov 2016 19:38:41 +0100 Subject: [PATCH] adds dev seeds for polls and poll questions --- db/dev_seeds.rb | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 51f46b3c6..2c2f106ee 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -362,7 +362,32 @@ end puts "Creating polls" 3.times.each_with_index do |i| - Poll.create(name: "Poll #{i}") + starts_at = rand(2.months.ago .. 2.months.from_now) + ends_at = starts_at + 1.month + + poll = Poll.create(name: "Poll #{i}", + starts_at: starts_at, + ends_at: ends_at) + puts " #{poll.name}" +end + +puts "Creating Poll Questions" + +(1..10).each do |i| + poll = Poll.reorder("RANDOM()").first + author = User.reorder("RANDOM()").first + description = "

#{Faker::Lorem.paragraphs.join('

')}

" + open_at = rand(2.months.ago .. 2.months.from_now) + question = Poll::Question.create!(author: author, + title: Faker::Lorem.sentence(3).truncate(60), + question: Faker::Lorem.sentence(3) + "?", + summary: Faker::Lorem.sentence(3), + description: description, + valid_answers: Faker::Lorem.words(3).join(', '), + poll: poll, + geozones: Geozone.reorder("RANDOM()").limit(3), + all_geozones: [true, false].sample) + puts " #{question.title}" end 10.times.each_with_index do |i|