Some style corrections on dev_seeds, along with abreviations and removal of unused blocks

This commit is contained in:
Bertocq
2017-06-13 23:31:09 +02:00
parent ae82a563d6
commit d99a4da246

View File

@@ -79,7 +79,7 @@ poll_officer = create_user('poll_officer@consul.dev', 'Paul O. Fisher')
poll_officer.create_poll_officer
level_2 = create_user('leveltwo@consul.dev', 'level 2')
level_2.update(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_number: "2222222222", document_type: "1" )
level_2.update(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_number: "2222222222", document_type: "1")
verified = create_user('verified@consul.dev', 'verified')
verified.update(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_type: "1", verified_at: Time.current, document_number: "3333333333")
@@ -91,7 +91,7 @@ verified.update(residence_verified_at: Time.current, confirmed_phone: Faker::Pho
org = org_user.create_organization(name: org_name, responsible_name: org_responsible_name)
verified = [true, false].sample
if verified then
if verified
org.verify
else
org.reject
@@ -107,10 +107,10 @@ 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" )
user.update(residence_verified_at: Time.current, confirmed_phone: Faker::PhoneNumber.phone_number, document_number: Faker::Number.number(10), document_type: "1")
end
if level == 3
user.update(verified_at: Time.current, document_number: Faker::Number.number(10) )
user.update(verified_at: Time.current, document_number: Faker::Number.number(10))
end
end
@@ -131,7 +131,7 @@ ActsAsTaggableOn::Tag.create!(name: "Sostenibilidad", featured: true, kind: "ca
ActsAsTaggableOn::Tag.create!(name: "Participación", featured: true, kind: "category")
ActsAsTaggableOn::Tag.create!(name: "Movilidad", featured: true, kind: "category")
ActsAsTaggableOn::Tag.create!(name: "Medios", featured: true, kind: "category")
ActsAsTaggableOn::Tag.create!(name: "Salud", featured: true , kind: "category")
ActsAsTaggableOn::Tag.create!(name: "Salud", featured: true, kind: "category")
ActsAsTaggableOn::Tag.create!(name: "Transparencia", featured: true, kind: "category")
ActsAsTaggableOn::Tag.create!(name: "Seguridad y Emergencias", featured: true, kind: "category")
ActsAsTaggableOn::Tag.create!(name: "Medio Ambiente", featured: true, kind: "category")
@@ -140,38 +140,36 @@ puts " ✅"
print "Creating Debates"
tags = Faker::Lorem.words(25)
(1..30).each do
30.times do
author = User.reorder("RANDOM()").first
description = "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>"
debate = Debate.create!(author: author,
title: Faker::Lorem.sentence(3).truncate(60),
created_at: rand((Time.current - 1.week) .. Time.current),
created_at: rand((Time.current - 1.week)..Time.current),
description: description,
tag_list: tags.sample(3).join(','),
geozone: Geozone.reorder("RANDOM()").first,
terms_of_service: "1")
end
tags = ActsAsTaggableOn::Tag.where(kind: 'category')
(1..30).each do
30.times do
author = User.reorder("RANDOM()").first
description = "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>"
debate = Debate.create!(author: author,
title: Faker::Lorem.sentence(3).truncate(60),
created_at: rand((Time.current - 1.week) .. Time.current),
created_at: rand((Time.current - 1.week)..Time.current),
description: description,
tag_list: tags.sample(3).join(','),
geozone: Geozone.reorder("RANDOM()").first,
terms_of_service: "1")
end
puts ""
print "Creating Proposals"
tags = Faker::Lorem.words(25)
(1..30).each do |i|
30.times do
author = User.reorder("RANDOM()").first
description = "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>"
proposal = Proposal.create!(author: author,
@@ -181,7 +179,7 @@ tags = Faker::Lorem.words(25)
responsible_name: Faker::Name.name,
external_url: Faker::Internet.url,
description: description,
created_at: rand((Time.current - 1.week) .. Time.current),
created_at: rand((Time.current - 1.week)..Time.current),
tag_list: tags.sample(3).join(','),
geozone: Geozone.reorder("RANDOM()").first,
terms_of_service: "1")
@@ -191,7 +189,7 @@ puts " ✅"
print "Creating Archived Proposals"
tags = Faker::Lorem.words(25)
(1..5).each do
5.times do
author = User.reorder("RANDOM()").first
description = "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>"
proposal = Proposal.create!(author: author,
@@ -211,7 +209,7 @@ puts " ✅"
print "Creating Successful Proposals"
tags = Faker::Lorem.words(25)
(1..10).each do |i|
10.times do
author = User.reorder("RANDOM()").first
description = "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>"
proposal = Proposal.create!(author: author,
@@ -221,16 +219,15 @@ tags = Faker::Lorem.words(25)
responsible_name: Faker::Name.name,
external_url: Faker::Internet.url,
description: description,
created_at: rand((Time.current - 1.week) .. Time.current),
created_at: rand((Time.current - 1.week)..Time.current),
tag_list: tags.sample(3).join(','),
geozone: Geozone.reorder("RANDOM()").first,
terms_of_service: "1",
cached_votes_up: Setting["votes_for_proposal_success"])
end
tags = ActsAsTaggableOn::Tag.where(kind: 'category')
(1..30).each do
30.times do
author = User.reorder("RANDOM()").first
description = "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>"
proposal = Proposal.create!(author: author,
@@ -240,94 +237,89 @@ tags = ActsAsTaggableOn::Tag.where(kind: 'category')
responsible_name: Faker::Name.name,
external_url: Faker::Internet.url,
description: description,
created_at: rand((Time.current - 1.week) .. Time.current),
created_at: rand((Time.current - 1.week)..Time.current),
tag_list: tags.sample(3).join(','),
geozone: Geozone.reorder("RANDOM()").first,
terms_of_service: "1")
end
puts ""
print "Commenting Debates"
(1..100).each do
100.times do
author = User.reorder("RANDOM()").first
debate = Debate.reorder("RANDOM()").first
Comment.create!(user: author,
created_at: rand(debate.created_at .. Time.current),
created_at: rand(debate.created_at..Time.current),
commentable: debate,
body: Faker::Lorem.sentence)
end
puts ""
print "Commenting Proposals"
(1..100).each do |i|
100.times do
author = User.reorder("RANDOM()").first
proposal = Proposal.reorder("RANDOM()").first
Comment.create!(user: author,
created_at: rand(proposal.created_at .. Time.current),
created_at: rand(proposal.created_at..Time.current),
commentable: proposal,
body: Faker::Lorem.sentence)
end
puts ""
print "Commenting Comments"
(1..200).each do
200.times do
author = User.reorder("RANDOM()").first
parent = Comment.reorder("RANDOM()").first
Comment.create!(user: author,
created_at: rand(parent.created_at .. Time.current),
created_at: rand(parent.created_at..Time.current),
commentable_id: parent.commentable_id,
commentable_type: parent.commentable_type,
body: Faker::Lorem.sentence,
parent: parent)
end
puts ""
print "Voting Debates, Proposals & Comments"
(1..100).each do
100.times do
voter = not_org_users.reorder("RANDOM()").first
vote = [true, false].sample
debate = Debate.reorder("RANDOM()").first
debate.vote_by(voter: voter, vote: vote)
end
(1..100).each do |i|
100.times do
voter = not_org_users.reorder("RANDOM()").first
vote = [true, false].sample
comment = Comment.reorder("RANDOM()").first
comment.vote_by(voter: voter, vote: vote)
end
(1..100).each do
100.times do
voter = User.level_two_or_three_verified.reorder("RANDOM()").first
proposal = Proposal.reorder("RANDOM()").first
proposal.vote_by(voter: voter, vote: true)
end
puts ""
print "Flagging Debates & Comments"
(1..40).each do
40.times do
debate = Debate.reorder("RANDOM()").first
flagger = User.where(["users.id <> ?", debate.author_id]).reorder("RANDOM()").first
Flag.flag(flagger, debate)
end
(1..40).each do
40.times do
comment = Comment.reorder("RANDOM()").first
flagger = User.where(["users.id <> ?", comment.user_id]).reorder("RANDOM()").first
Flag.flag(flagger, comment)
end
(1..40).each do
40.times do
proposal = Proposal.reorder("RANDOM()").first
flagger = User.where(["users.id <> ?", proposal.author_id]).reorder("RANDOM()").first
Flag.flag(flagger, proposal)
@@ -338,7 +330,7 @@ print "Creating Spending Proposals"
tags = Faker::Lorem.words(10)
(1..60).each do
60.times do
geozone = Geozone.reorder("RANDOM()").first
author = User.reorder("RANDOM()").first
description = "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>"
@@ -346,17 +338,17 @@ tags = Faker::Lorem.words(10)
valuation_finished = [true, false].sample
feasible = [true, false].sample
spending_proposal = SpendingProposal.create!(author: author,
title: Faker::Lorem.sentence(3).truncate(60),
external_url: Faker::Internet.url,
description: description,
created_at: rand((Time.current - 1.week) .. Time.current),
geozone: [geozone, nil].sample,
feasible: feasible,
feasible_explanation: feasible_explanation,
valuation_finished: valuation_finished,
tag_list: tags.sample(3).join(','),
price: rand(1000000),
terms_of_service: "1")
title: Faker::Lorem.sentence(3).truncate(60),
external_url: Faker::Internet.url,
description: description,
created_at: rand((Time.current - 1.week)..Time.current),
geozone: [geozone, nil].sample,
feasible: feasible,
feasible_explanation: feasible_explanation,
valuation_finished: valuation_finished,
tag_list: tags.sample(3).join(','),
price: rand(1000000),
terms_of_service: "1")
end
puts ""
@@ -366,13 +358,14 @@ print "Creating Valuation Assignments"
SpendingProposal.reorder("RANDOM()").first.valuators << valuator.valuator
end
puts ""
print "Creating Budgets"
Budget::PHASES.each_with_index do |phase, i|
descriptions = Hash[Budget::PHASES.map{ |p| ["description_#{p}",
"<p>#{Faker::Lorem.paragraphs(2).join('</p><p>')}</p>"] }]
descriptions = Hash[Budget::PHASES.map do |p|
["description_#{p}",
"<p>#{Faker::Lorem.paragraphs(2).join('</p><p>')}</p>"]
end]
budget = Budget.create!(
descriptions.merge(
name: (Date.current - 10 + i).to_s,
@@ -387,18 +380,15 @@ Budget::PHASES.each_with_index do |phase, i|
geozones = Geozone.reorder("RANDOM()").limit([2, 5, 6, 7].sample)
geozones.each do |geozone|
group.headings << group.headings.create!(name: geozone.name,
#geozone: geozone,
price: rand(1 .. 100) * 100000)
price: rand(1..100) * 100000)
end
end
end
puts ""
print "Creating Investments"
tags = Faker::Lorem.words(10)
(1..100).each do |i|
100.times do
heading = Budget::Heading.reorder("RANDOM()").first
investment = Budget::Investment.create!(
@@ -409,13 +399,14 @@ tags = Faker::Lorem.words(10)
title: Faker::Lorem.sentence(3).truncate(60),
external_url: Faker::Internet.url,
description: "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>",
created_at: rand((Time.current - 1.week) .. Time.current),
created_at: rand((Time.current - 1.week)..Time.current),
feasibility: %w{undecided unfeasible feasible feasible feasible feasible}.sample,
unfeasibility_explanation: Faker::Lorem.paragraph,
valuation_finished: [false, true].sample,
tag_list: tags.sample(3).join(','),
price: rand(1 .. 100) * 100000,
terms_of_service: "1")
price: rand(1..100) * 100000,
terms_of_service: "1"
)
end
puts ""
@@ -428,7 +419,7 @@ puts " ✅"
print "Winner Investments"
budget = Budget.where(phase: "finished").last
(1..100).each do |i|
100.times do
heading = budget.headings.reorder("RANDOM()").first
investment = Budget::Investment.create!(
author: User.reorder("RANDOM()").first,
@@ -438,12 +429,13 @@ budget = Budget.where(phase: "finished").last
title: Faker::Lorem.sentence(3).truncate(60),
external_url: Faker::Internet.url,
description: "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>",
created_at: rand((Time.current - 1.week) .. Time.current),
created_at: rand((Time.current - 1.week)..Time.current),
feasibility: "feasible",
valuation_finished: true,
selected: true,
price: rand(10000 .. heading.price),
terms_of_service: "1")
price: rand(10000..heading.price),
terms_of_service: "1"
)
end
budget.headings.each do |heading|
Budget::Result.new(budget, heading).calculate_winners
@@ -456,16 +448,13 @@ print "Creating Valuation Assignments"
Budget::Investment.reorder("RANDOM()").first.valuators << valuator.valuator
end
puts ""
print "Ignoring flags in Debates, comments & proposals"
Debate.flagged.reorder("RANDOM()").limit(10).each(&:ignore_flag)
Comment.flagged.reorder("RANDOM()").limit(30).each(&:ignore_flag)
Proposal.flagged.reorder("RANDOM()").limit(10).each(&:ignore_flag)
puts ""
print "Hiding debates, comments & proposals"
@@ -473,7 +462,6 @@ Comment.with_hidden.flagged.reorder("RANDOM()").limit(30).each(&:hide)
Debate.with_hidden.flagged.reorder("RANDOM()").limit(5).each(&:hide)
Proposal.with_hidden.flagged.reorder("RANDOM()").limit(10).each(&:hide)
puts ""
print "Confirming hiding in debates, comments & proposals"
@@ -494,9 +482,9 @@ Proposal.last(3).each do |proposal|
image: ["banner-img banner-img-one", "banner-img banner-img-two",
"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)),
created_at: rand((Time.current - 1.week) .. Time.current))
post_started_at: rand((Time.current - 1.week)..(Time.current - 1.day)),
post_ended_at: rand((Time.current - 1.day)..(Time.current + 1.week)),
created_at: rand((Time.current - 1.week)..Time.current))
end
puts ""
@@ -510,19 +498,14 @@ print "Active Polls"
ends_at: 1.month.from_now,
geozone_restricted: false)
end
(4..5).each do |i|
(1..5).each do |i|
poll = Poll.create(name: "Active Poll #{i}",
starts_at: 1.month.ago,
ends_at: 1.month.from_now,
geozone_restricted: true,
geozones: Geozone.reorder("RANDOM()").limit(3)
)
geozones: Geozone.reorder("RANDOM()").limit(3))
end
puts ""
print "Upcoming Poll"
poll = Poll.create(name: "Upcoming Poll",
@@ -532,17 +515,17 @@ poll = Poll.create(name: "Upcoming Poll",
puts ""
print "Expired Poll"
poll = Poll.create(name: "Expired Poll",
starts_at: 2.months.ago,
ends_at: 1.months.ago)
starts_at: 2.months.ago,
ends_at: 1.month.ago)
puts ""
print "Creating Poll Questions"
(1..50).each do |i|
50.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)
open_at = rand(2.months.ago..2.months.from_now)
question = Poll::Question.create!(author: author,
title: Faker::Lorem.sentence(3).truncate(60),
description: description,
@@ -574,21 +557,21 @@ end
puts ""
print "Creating Poll Recounts" do
(1..15).to_a.sample.times do |i|
poll_officer.poll_officer.officer_assignments.all.sample(i).each do |officer_assignment|
Poll::Recount.create(officer_assignment: officer_assignment,
booth_assignment: officer_assignment.booth_assignment,
date: officer_assignment.date,
count: (1..5000).to_a.sample)
(1..15).to_a.sample.times do |i|
poll_officer.poll_officer.officer_assignments.all.sample(i).each do |officer_assignment|
Poll::Recount.create(officer_assignment: officer_assignment,
booth_assignment: officer_assignment.booth_assignment,
date: officer_assignment.date,
count: (1..5000).to_a.sample)
end
end
end
end
puts ""
print "Creating Poll Questions from Proposals"
(1..3).each do
3.times do
proposal = Proposal.reorder("RANDOM()").first
poll = Poll.current.first
question = Poll::Question.create(valid_answers: "Yes, No")
@@ -599,7 +582,7 @@ end
puts ""
print "Creating Successful Proposals"
(1..10).each do
10.times do
proposal = Proposal.reorder("RANDOM()").first
poll = Poll.current.first
question = Poll::Question.create(valid_answers: "Yes, No")
@@ -610,11 +593,11 @@ end
puts ""
print "Commenting Poll Questions"
(1..30).each do
30.times do
author = User.reorder("RANDOM()").first
question = Poll::Question.reorder("RANDOM()").first
Comment.create!(user: author,
created_at: rand(question.created_at .. Time.current),
created_at: rand(question.created_at..Time.current),
commentable: question,
body: Faker::Lorem.sentence)
end
@@ -622,7 +605,7 @@ end
puts ""
print "Creating Poll Voters"
(1..10).each do
10.times do
poll = Poll.all.sample
user = User.level_two_verified.sample
Poll::Voter.create(poll: poll, user: user)
@@ -631,7 +614,7 @@ end
puts ""
print "Creating legislation processes"
(1..5).each do |i|
5.times do
process = ::Legislation::Process.create!(title: Faker::Lorem.sentence(3).truncate(60),
description: Faker::Lorem.paragraphs.join("\n\n"),
summary: Faker::Lorem.paragraph,
@@ -654,8 +637,7 @@ end
::Legislation::Process.all.each do |process|
(1..3).each do |i|
version = process.draft_versions.create!(title: "Version #{i}",
body: Faker::Lorem.paragraphs.join("\n\n")
)
body: Faker::Lorem.paragraphs.join("\n\n"))
end
end