Refactor Poll Question & Answer creation section

This commit is contained in:
Bertocq
2017-11-09 13:04:12 +01:00
parent a4a4f3beb2
commit cf76898308

View File

@@ -566,17 +566,17 @@ section "Creating polls" do
stats_enabled: true)
end
section "Creating Poll Questions" do
25.times do
poll = Poll.reorder("RANDOM()").first
author = User.reorder("RANDOM()").first
description = "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>"
open_at = rand(2.months.ago..2.months.from_now)
question = Poll::Question.create!(author: author,
title: Faker::Lorem.sentence(3).truncate(60),
poll: poll)
Faker::Lorem.words((2..4).to_a.sample).each do |answer|
Poll::Question::Answer.create!(question: question, title: answer.capitalize, description: Faker::ChuckNorris.fact)
section "Creating Poll Questions & Answers" do
Poll.all.each do |poll|
(1..4).to_a.sample.times do
question = Poll::Question.create!(author: User.all.sample,
title: Faker::Lorem.sentence(3).truncate(60) + '?',
poll: poll)
Faker::Lorem.words((2..4).to_a.sample).each do |answer|
Poll::Question::Answer.create!(question: question,
title: answer.capitalize,
description: "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>")
end
end
end
end