Correct dev_seeds to correctly create Poll::Question::Answers instead of valid_answers, plus style fixes

This commit is contained in:
Bertocq
2017-10-18 01:29:40 +02:00
parent fbcf8678c3
commit c6d1f727af

View File

@@ -73,7 +73,7 @@ def create_user(email, username = Faker::Name.name)
confirmed_at: Time.current,
terms_of_service: "1",
gender: ['Male', 'Female'].sample,
date_of_birth: rand((Time.current - 80.years) .. (Time.current - 16.years)),
date_of_birth: rand((Time.current - 80.years)..(Time.current - 16.years)),
public_activity: (rand(1..100) > 30)
)
end
@@ -127,7 +127,7 @@ end
user = create_user("user#{i}@consul.dev")
level = [1, 2, 3].sample
if level >= 2
user.update(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_number: Faker::Number.number(10), document_type: "1", geozone: Geozone.reorder("RANDOM()").first)
user.update(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_number: Faker::Number.number(10), document_type: "1", geozone: Geozone.reorder("RANDOM()").first)
end
if level == 3
user.update(verified_at: Time.current, document_number: Faker::Number.number(10))
@@ -319,7 +319,7 @@ end
end
100.times do
voter = not_org_users.level_two_or_three_verified.reorder("RANDOM()").first
voter = not_org_users.level_two_or_three_verified.reorder("RANDOM()").first
proposal = Proposal.reorder("RANDOM()").first
proposal.vote_by(voter: voter, vote: true)
end
@@ -504,7 +504,7 @@ Proposal.last(3).each do |proposal|
"banner-img banner-img-three"].sample,
target_url: Rails.application.routes.url_helpers.proposal_path(proposal),
post_started_at: rand((Time.current - 1.week)..(Time.current - 1.day)),
post_ended_at: rand((Time.current - 1.day)..(Time.current + 1.week)),
post_ended_at: rand((Time.current - 1.day)..(Time.current + 1.week)),
created_at: rand((Time.current - 1.week)..Time.current))
end
@@ -561,13 +561,11 @@ print "Creating Poll Questions"
author = User.reorder("RANDOM()").first
description = "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>"
open_at = rand(2.months.ago..2.months.from_now)
answers = Faker::Lorem.words((2..4).to_a.sample).map { |answer| answer.capitalize }
question = Poll::Question.create!(author: author,
title: Faker::Lorem.sentence(3).truncate(60),
valid_answers: answers.join(', '),
poll: poll)
answers.each do |answer|
Poll::Question::Answer.create!(question: question, title: answer, description: Faker::ChuckNorris.fact)
Faker::Lorem.words((2..4).to_a.sample).each do |answer|
Poll::Question::Answer.create!(question: question, title: answer.capitalize, description: Faker::ChuckNorris.fact)
end
end
@@ -599,7 +597,10 @@ print "Creating Poll Questions from Proposals"
3.times do
proposal = Proposal.reorder("RANDOM()").first
poll = Poll.current.first
question = Poll::Question.create(valid_answers: "Yes, No", poll: poll)
question = Poll::Question.create(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)
end
question.copy_attributes_from_proposal(proposal)
question.save!
end
@@ -610,7 +611,10 @@ print "Creating Successful Proposals"
10.times do
proposal = Proposal.reorder("RANDOM()").first
poll = Poll.current.first
question = Poll::Question.create(valid_answers: "Yes, No", poll: poll)
question = Poll::Question.create(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)
end
question.copy_attributes_from_proposal(proposal)
question.save!
end
@@ -656,8 +660,7 @@ print "Creating legislation processes"
allegations_phase_enabled: true,
draft_publication_enabled: true,
result_publication_enabled: true,
published: true
)
published: true)
end
::Legislation::Process.all.each do |process|