Replace .all.each with .find_each when seeding the DB

This commit is contained in:
Angel Perez
2018-07-13 13:23:35 -04:00
parent 303b96553a
commit b6fe7ca9a7
5 changed files with 12 additions and 12 deletions

View File

@@ -91,7 +91,7 @@ section "Marking investments as visible to valuators" do
end
section "Geolocating Investments" do
Budget.all.each do |budget|
Budget.find_each do |budget|
budget.investments.each do |investment|
MapLocation.create(latitude: Setting['map_latitude'].to_f + rand(-10..10)/100.to_f,
longitude: Setting['map_longitude'].to_f + rand(-10..10)/100.to_f,
@@ -140,7 +140,7 @@ section "Creating Valuation Assignments" do
end
section "Creating investment milestones" do
Budget::Investment.all.each do |investment|
Budget::Investment.find_each do |investment|
milestone = Budget::Investment::Milestone.new(investment_id: investment.id, publication_date: Date.tomorrow)
I18n.available_locales.map do |locale|
neutral_locale = locale.to_s.downcase.underscore.to_sym

View File

@@ -1,10 +1,10 @@
section "Creating Communities" do
Proposal.all.each { |proposal| proposal.update(community: Community.create) }
Budget::Investment.all.each { |investment| investment.update(community: Community.create) }
Proposal.find_each { |proposal| proposal.update(community: Community.create) }
Budget::Investment.find_each { |investment| investment.update(community: Community.create) }
end
section "Creating Communities Topics" do
Community.all.each do |community|
Community.find_each do |community|
Topic.create(community: community, author: User.all.sample,
title: Faker::Lorem.sentence(3).truncate(60), description: Faker::Lorem.sentence)
end

View File

@@ -23,7 +23,7 @@ section "Creating legislation processes" do
published: true)
end
Legislation::Process.all.each do |process|
Legislation::Process.find_each do |process|
(1..3).each do |i|
process.draft_versions.create!(title: "Version #{i}",
body: Faker::Lorem.paragraphs.join("\n\n"))

View File

@@ -1,5 +1,5 @@
section "Creating comment notifications" do
User.all.each do |user|
User.find_each do |user|
debate = Debate.create!(author: user,
title: Faker::Lorem.sentence(3).truncate(60),
description: "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>",

View File

@@ -31,7 +31,7 @@ section "Creating polls" do
end
section "Creating Poll Questions & Answers" do
Poll.all.each do |poll|
Poll.find_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) + '?',
@@ -55,10 +55,10 @@ section "Creating Poll Booths & BoothAssignments" do
end
section "Creating Poll Shifts for Poll Officers" do
Poll.all.each do |poll|
Poll.find_each do |poll|
Poll::BoothAssignment.where(poll: poll).each do |booth_assignment|
scrutiny = (poll.ends_at.to_datetime..poll.ends_at.to_datetime + Poll::RECOUNT_DURATION)
Poll::Officer.all.each do |poll_officer|
Poll::Officer.find_each do |poll_officer|
{
vote_collection: (poll.starts_at.to_datetime..poll.ends_at.to_datetime),
recount_scrutiny: scrutiny
@@ -130,7 +130,7 @@ section "Creating Poll Voters" do
end
section "Creating Poll Recounts" do
Poll.all.each do |poll|
Poll.find_each do |poll|
poll.booth_assignments.each do |booth_assignment|
officer_assignment = poll.officer_assignments.first
author = Poll::Officer.first.user
@@ -148,7 +148,7 @@ section "Creating Poll Recounts" do
end
section "Creating Poll Results" do
Poll.all.each do |poll|
Poll.find_each do |poll|
poll.booth_assignments.each do |booth_assignment|
officer_assignment = poll.officer_assignments.first
author = Poll::Officer.first.user