From f8d3e645db6549e5791e0e5abd4863753f9d81d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Sat, 28 Jan 2017 19:55:02 +0100 Subject: [PATCH 1/4] adds poll recounts to dev_seeds --- db/dev_seeds.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 6f10ca891..6541a007b 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -527,7 +527,7 @@ Poll::Booth.all.each do |booth| end puts "Creating Poll Officer Assignments" -(1..10).to_a.sample.times do |i| +(1..15).to_a.sample.times do |i| Poll::BoothAssignment.all.sample(i).each do |booth_assignment| Poll::OfficerAssignment.create(officer: poll_officer.poll_officer, booth_assignment: booth_assignment, @@ -535,6 +535,18 @@ puts "Creating Poll Officer Assignments" end end +puts "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) + end +end + +end + puts "Creating Poll Question from Proposals" (1..3).each do From ee4320f4c1131c609cd59202796d2e9f439bacc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Sat, 28 Jan 2017 20:05:01 +0100 Subject: [PATCH 2/4] removes noise from dev_seeds output --- db/dev_seeds.rb | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 6541a007b..5ad69a07a 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -51,7 +51,6 @@ puts "Creating Users" def create_user(email, username = Faker::Name.name) pwd = '12345678' - puts " #{username}" User.create!(username: username, email: email, password: pwd, password_confirmation: pwd, confirmed_at: Time.current, terms_of_service: "1") end @@ -141,7 +140,6 @@ tags = Faker::Lorem.words(25) tag_list: tags.sample(3).join(','), geozone: Geozone.reorder("RANDOM()").first, terms_of_service: "1") - puts " #{debate.title}" end @@ -156,7 +154,6 @@ tags = ActsAsTaggableOn::Tag.where(kind: 'category') tag_list: tags.sample(3).join(','), geozone: Geozone.reorder("RANDOM()").first, terms_of_service: "1") - puts " #{debate.title}" end @@ -177,7 +174,6 @@ tags = Faker::Lorem.words(25) tag_list: tags.sample(3).join(','), geozone: Geozone.reorder("RANDOM()").first, terms_of_service: "1") - puts " #{proposal.title}" end puts "Creating Archived Proposals" @@ -197,7 +193,6 @@ tags = Faker::Lorem.words(25) geozone: Geozone.reorder("RANDOM()").first, terms_of_service: "1", created_at: Setting["months_to_archive_proposals"].to_i.months.ago) - puts " #{proposal.title}" end puts "Creating Successful Proposals" @@ -218,7 +213,6 @@ tags = Faker::Lorem.words(25) geozone: Geozone.reorder("RANDOM()").first, terms_of_service: "1", cached_votes_up: Setting["votes_for_proposal_success"]) - puts " #{proposal.title}" end @@ -237,7 +231,6 @@ tags = ActsAsTaggableOn::Tag.where(kind: 'category') tag_list: tags.sample(3).join(','), geozone: Geozone.reorder("RANDOM()").first, terms_of_service: "1") - puts " #{proposal.title}" end @@ -345,7 +338,6 @@ tags = Faker::Lorem.words(10) tag_list: tags.sample(3).join(','), price: rand(1000000), terms_of_service: "1") - puts " #{spending_proposal.title}" end puts "Creating Valuation Assignments" @@ -368,8 +360,6 @@ Budget::PHASES.each_with_index do |phase, i| ) ) - puts budget.name - (1..([1, 2, 3].sample)).each do group = budget.groups.create!(name: Faker::StarWars.planet) @@ -380,9 +370,7 @@ Budget::PHASES.each_with_index do |phase, i| price: rand(1 .. 100) * 100000) end - print "#{group.name} " end - puts "" end @@ -406,7 +394,6 @@ tags = Faker::Lorem.words(10) tag_list: tags.sample(3).join(','), price: rand(1 .. 100) * 100000, terms_of_service: "1") - puts " #{investment.title}" end puts "Selecting Investments" @@ -461,7 +448,6 @@ Proposal.last(3).each do |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)) - puts " #{banner.title}" end puts "Creating polls" @@ -472,7 +458,6 @@ puts "Active Polls" starts_at: 1.month.ago, ends_at: 1.month.from_now, geozone_restricted: false) - puts " #{poll.name}" end (4..5).each do |i| poll = Poll.create(name: "Active Poll #{i}", @@ -481,7 +466,6 @@ end geozone_restricted: true, geozones: Geozone.reorder("RANDOM()").limit(3) ) - puts " #{poll.name}" end @@ -492,13 +476,11 @@ puts "Upcoming Poll" poll = Poll.create(name: "Upcoming Poll", starts_at: 1.month.from_now, ends_at: 2.months.from_now) -puts " #{poll.name}" puts "Expired Poll" poll = Poll.create(name: "Expired Poll", starts_at: 2.months.ago, ends_at: 1.months.ago) -puts " #{poll.name}" puts "Creating Poll Questions" @@ -513,7 +495,6 @@ puts "Creating Poll Questions" description: description, valid_answers: Faker::Lorem.words(3).join(', '), poll: poll) - puts " #{question.title}" end puts "Creating Poll Booths" @@ -547,7 +528,7 @@ end end -puts "Creating Poll Question from Proposals" +puts "Creating Poll Questions from Proposals" (1..3).each do proposal = Proposal.reorder("RANDOM()").first @@ -555,8 +536,6 @@ puts "Creating Poll Question from Proposals" question = Poll::Question.create(valid_answers: "Yes, No") question.copy_attributes_from_proposal(proposal) question.save! - - puts " #{question.title} (from proposal)" end puts "Creating Successful Proposals" @@ -567,8 +546,6 @@ puts "Creating Successful Proposals" question = Poll::Question.create(valid_answers: "Yes, No") question.copy_attributes_from_proposal(proposal) question.save! - - puts " #{question.title} (from proposal)" end puts "Commenting Poll Questions" From e07ebc79672d1c9cd805f0df29fd2a2b0af4f8c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Sat, 28 Jan 2017 20:17:20 +0100 Subject: [PATCH 3/4] beautifies dev_seeds output --- db/dev_seeds.rb | 110 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 36 deletions(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index 5ad69a07a..da6304384 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -2,7 +2,7 @@ require 'database_cleaner' DatabaseCleaner.clean_with :truncation -puts "Creating Settings" +print "Creating Settings" Setting.create(key: 'official_level_1_name', value: 'Empleados públicos') Setting.create(key: 'official_level_2_name', value: 'Organización Municipal') Setting.create(key: 'official_level_3_name', value: 'Directores generales') @@ -42,12 +42,14 @@ Setting.create(key: 'meta_keywords', value: 'citizen participation, open governm Setting.create(key: 'verification_offices_url', value: 'http://oficinas-atencion-ciudadano.url/') Setting.create(key: 'min_age_to_participate', value: '16') -puts "Creating Geozones" +puts " ✅" +print "Creating Geozones" Geozone.create(name: "city") ('A'..'Z').each { |i| Geozone.create(name: "District #{i}", external_code: i.ord, census_code: i.ord) } -puts "Creating Users" +puts " ✅" +print "Creating Users" def create_user(email, username = Faker::Name.name) pwd = '12345678' @@ -109,7 +111,8 @@ end org_user_ids = User.organizations.pluck(:id) not_org_users = User.where(['users.id NOT IN(?)', org_user_ids]) -puts "Creating Tags Categories" +puts " ✅" +print "Creating Tags Categories" ActsAsTaggableOn::Tag.create!(name: "Asociaciones", featured: true, kind: "category") ActsAsTaggableOn::Tag.create!(name: "Cultura", featured: true, kind: "category") @@ -127,7 +130,8 @@ ActsAsTaggableOn::Tag.create!(name: "Transparencia", featured: true, kind: "cat ActsAsTaggableOn::Tag.create!(name: "Seguridad y Emergencias", featured: true, kind: "category") ActsAsTaggableOn::Tag.create!(name: "Medio Ambiente", featured: true, kind: "category") -puts "Creating Debates" +puts " ✅" +print "Creating Debates" tags = Faker::Lorem.words(25) (1..30).each do @@ -157,7 +161,8 @@ tags = ActsAsTaggableOn::Tag.where(kind: 'category') end -puts "Creating Proposals" +puts " ✅" +print "Creating Proposals" tags = Faker::Lorem.words(25) (1..30).each do |i| @@ -176,7 +181,8 @@ tags = Faker::Lorem.words(25) terms_of_service: "1") end -puts "Creating Archived Proposals" +puts " ✅" +print "Creating Archived Proposals" tags = Faker::Lorem.words(25) (1..5).each do @@ -195,7 +201,8 @@ tags = Faker::Lorem.words(25) created_at: Setting["months_to_archive_proposals"].to_i.months.ago) end -puts "Creating Successful Proposals" +puts " ✅" +print "Creating Successful Proposals" tags = Faker::Lorem.words(25) (1..10).each do |i| @@ -234,7 +241,8 @@ tags = ActsAsTaggableOn::Tag.where(kind: 'category') end -puts "Commenting Debates" +puts " ✅" +print "Commenting Debates" (1..100).each do author = User.reorder("RANDOM()").first @@ -246,7 +254,8 @@ puts "Commenting Debates" end -puts "Commenting Proposals" +puts " ✅" +print "Commenting Proposals" (1..100).each do |i| author = User.reorder("RANDOM()").first @@ -258,7 +267,8 @@ puts "Commenting Proposals" end -puts "Commenting Comments" +puts " ✅" +print "Commenting Comments" (1..200).each do author = User.reorder("RANDOM()").first @@ -272,7 +282,8 @@ puts "Commenting Comments" end -puts "Voting Debates, Proposals & Comments" +puts " ✅" +print "Voting Debates, Proposals & Comments" (1..100).each do voter = not_org_users.reorder("RANDOM()").first @@ -295,7 +306,8 @@ end end -puts "Flagging Debates & Comments" +puts " ✅" +print "Flagging Debates & Comments" (1..40).each do debate = Debate.reorder("RANDOM()").first @@ -315,7 +327,8 @@ end Flag.flag(flagger, proposal) end -puts "Creating Spending Proposals" +puts " ✅" +print "Creating Spending Proposals" tags = Faker::Lorem.words(10) @@ -340,14 +353,16 @@ tags = Faker::Lorem.words(10) terms_of_service: "1") end -puts "Creating Valuation Assignments" +puts " ✅" +print "Creating Valuation Assignments" (1..17).to_a.sample.times do SpendingProposal.reorder("RANDOM()").first.valuators << valuator.valuator end -puts "Creating Budgets" +puts " ✅" +print "Creating Budgets" Budget::PHASES.each_with_index do |phase, i| descriptions = Hash[Budget::PHASES.map{ |p| ["description_#{p}", @@ -374,7 +389,8 @@ Budget::PHASES.each_with_index do |phase, i| end -puts "Creating Investments" +puts " ✅" +print "Creating Investments" tags = Faker::Lorem.words(10) (1..100).each do |i| heading = Budget::Heading.reorder("RANDOM()").first @@ -396,44 +412,51 @@ tags = Faker::Lorem.words(10) terms_of_service: "1") end -puts "Selecting Investments" +puts " ✅" +print "Selecting Investments" Budget.balloting.reorder("RANDOM()").limit(3).each do |budget| budget.investments.feasible.reorder("RANDOM()").limit(10).update_all(selected: true) end -puts "Creating Valuation Assignments" +puts " ✅" +print "Creating Valuation Assignments" (1..17).to_a.sample.times do Budget::Investment.reorder("RANDOM()").first.valuators << valuator.valuator end -puts "Creating Legislation" +puts " ✅" +print "Creating Legislation" Legislation.create!(title: 'Participatory Democracy', body: 'In order to achieve...') -puts "Ignoring flags in Debates, comments & proposals" +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 "Hiding debates, comments & proposals" +puts " ✅" +print "Hiding debates, comments & proposals" 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 "Confirming hiding in debates, comments & proposals" +puts " ✅" +print "Confirming hiding in debates, comments & proposals" Comment.only_hidden.flagged.reorder("RANDOM()").limit(10).each(&:confirm_hide) Debate.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide) Proposal.only_hidden.flagged.reorder("RANDOM()").limit(5).each(&:confirm_hide) -puts "Creating banners" +puts " ✅" +print "Creating banners" Proposal.last(3).each do |proposal| title = Faker::Lorem.sentence(word_count = 3) @@ -450,9 +473,11 @@ Proposal.last(3).each do |proposal| created_at: rand((Time.current - 1.week) .. Time.current)) end -puts "Creating polls" +puts " ✅" +print "Creating polls" -puts "Active Polls" +puts " ✅" +print "Active Polls" (1..3).each do |i| poll = Poll.create(name: "Active Poll #{i}", starts_at: 1.month.ago, @@ -472,17 +497,20 @@ end -puts "Upcoming Poll" +puts " ✅" +print "Upcoming Poll" poll = Poll.create(name: "Upcoming Poll", starts_at: 1.month.from_now, ends_at: 2.months.from_now) -puts "Expired Poll" +puts " ✅" +print "Expired Poll" poll = Poll.create(name: "Expired Poll", starts_at: 2.months.ago, ends_at: 1.months.ago) -puts "Creating Poll Questions" +puts " ✅" +print "Creating Poll Questions" (1..50).each do |i| poll = Poll.reorder("RANDOM()").first @@ -497,17 +525,20 @@ puts "Creating Poll Questions" poll: poll) end -puts "Creating Poll Booths" +puts " ✅" +print "Creating Poll Booths" 30.times.each_with_index do |i| Poll::Booth.create(name: "Booth #{i}", polls: [Poll.all.sample]) end -puts "Creating Booth Assignments" +puts " ✅" +print "Creating Booth Assignments" Poll::Booth.all.each do |booth| Poll::BoothAssignment.create(booth: booth, poll: Poll.all.sample) end -puts "Creating Poll Officer Assignments" +puts " ✅" +print "Creating Poll Officer Assignments" (1..15).to_a.sample.times do |i| Poll::BoothAssignment.all.sample(i).each do |booth_assignment| Poll::OfficerAssignment.create(officer: poll_officer.poll_officer, @@ -516,7 +547,8 @@ puts "Creating Poll Officer Assignments" end end -puts "Creating Poll Recounts" do +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, @@ -528,7 +560,8 @@ end end -puts "Creating Poll Questions from Proposals" +puts " ✅" +print "Creating Poll Questions from Proposals" (1..3).each do proposal = Proposal.reorder("RANDOM()").first @@ -538,7 +571,8 @@ puts "Creating Poll Questions from Proposals" question.save! end -puts "Creating Successful Proposals" +puts " ✅" +print "Creating Successful Proposals" (1..10).each do proposal = Proposal.reorder("RANDOM()").first @@ -548,7 +582,8 @@ puts "Creating Successful Proposals" question.save! end -puts "Commenting Poll Questions" +puts " ✅" +print "Commenting Poll Questions" (1..30).each do author = User.reorder("RANDOM()").first @@ -558,3 +593,6 @@ puts "Commenting Poll Questions" commentable: question, body: Faker::Lorem.sentence) end + +puts " ✅" +puts "All dev seeds created succesfully 👍" \ No newline at end of file From 8b19dcfbd8d58a65b15b718fc26174d468ee9135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanjo=20Baza=CC=81n?= Date: Sat, 28 Jan 2017 20:29:45 +0100 Subject: [PATCH 4/4] fixes typo --- db/dev_seeds.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index da6304384..c0183d2fc 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -595,4 +595,4 @@ print "Commenting Poll Questions" end puts " ✅" -puts "All dev seeds created succesfully 👍" \ No newline at end of file +puts "All dev seeds created successfuly 👍" \ No newline at end of file