From a4fb568654ce7b0d7240af80c3e5f92b2d8bba0f Mon Sep 17 00:00:00 2001 From: Bertocq Date: Tue, 30 Jan 2018 03:29:20 +0100 Subject: [PATCH] Improve dev seeds comments adding them to investments --- db/dev_seeds.rb | 205 +++++++++++++++++++++++------------------------- 1 file changed, 97 insertions(+), 108 deletions(-) diff --git a/db/dev_seeds.rb b/db/dev_seeds.rb index d8f170149..eb5a350e5 100644 --- a/db/dev_seeds.rb +++ b/db/dev_seeds.rb @@ -319,114 +319,6 @@ section "Creating Successful Proposals" do end end -section "Commenting Debates" do - 100.times do - author = User.all.sample - debate = Debate.all.sample - Comment.create!(user: author, - created_at: rand(debate.created_at..Time.current), - commentable: debate, - body: Faker::Lorem.sentence) - end -end - -section "Commenting Proposals" do - 100.times do - author = User.all.sample - proposal = Proposal.all.sample - Comment.create!(user: author, - created_at: rand(proposal.created_at..Time.current), - commentable: proposal, - body: Faker::Lorem.sentence) - end -end - -section "Commenting Comments" do - 200.times do - author = User.all.sample - parent = Comment.all.sample - Comment.create!(user: author, - 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 -end - -section "Voting Debates, Proposals & Comments" do - not_org_users = User.where(['users.id NOT IN(?)', User.organizations.pluck(:id)]) - 100.times do - voter = not_org_users.level_two_or_three_verified.all.sample - vote = [true, false].sample - debate = Debate.all.sample - debate.vote_by(voter: voter, vote: vote) - end - - 100.times do - voter = not_org_users.all.sample - vote = [true, false].sample - comment = Comment.all.sample - comment.vote_by(voter: voter, vote: vote) - end - - 100.times do - voter = not_org_users.level_two_or_three_verified.all.sample - proposal = Proposal.all.sample - proposal.vote_by(voter: voter, vote: true) - end -end - -section "Flagging Debates & Comments" do - 40.times do - debate = Debate.all.sample - flagger = User.where(["users.id <> ?", debate.author_id]).all.sample - Flag.flag(flagger, debate) - end - - 40.times do - comment = Comment.all.sample - flagger = User.where(["users.id <> ?", comment.user_id]).all.sample - Flag.flag(flagger, comment) - end - - 40.times do - proposal = Proposal.all.sample - flagger = User.where(["users.id <> ?", proposal.author_id]).all.sample - Flag.flag(flagger, proposal) - end -end - -section "Creating Spending Proposals" do - tags = Faker::Lorem.words(10) - 60.times do - geozone = Geozone.all.sample - author = User.all.sample - description = "

#{Faker::Lorem.paragraphs.join('

')}

" - feasible_explanation = "

#{Faker::Lorem.paragraphs.join('

')}

" - 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") - end -end - -section "Creating Valuation Assignments" do - (1..17).to_a.sample.times do - SpendingProposal.all.sample.valuators << Valuator.first - end -end - section "Creating Budgets" do Budget.create( name: "Budget #{Date.current.year - 1}", @@ -533,6 +425,103 @@ section "Creating Valuation Assignments" do end end +section "Commenting Investments, Debates & Proposals" do + %w(Budget::Investment Debate Proposal).each do |commentable_class| + 100.times do + commentable = commentable_class.constantize.all.sample + Comment.create!(user: User.all.sample, + created_at: rand(commentable.created_at..Time.current), + commentable: commentable, + body: Faker::Lorem.sentence) + end + end +end + +section "Commenting Comments" do + 200.times do + parent = Comment.all.sample + Comment.create!(user: User.all.sample, + 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 +end + +section "Voting Debates, Proposals & Comments" do + not_org_users = User.where(['users.id NOT IN(?)', User.organizations.pluck(:id)]) + 100.times do + voter = not_org_users.level_two_or_three_verified.all.sample + vote = [true, false].sample + debate = Debate.all.sample + debate.vote_by(voter: voter, vote: vote) + end + + 100.times do + voter = not_org_users.all.sample + vote = [true, false].sample + comment = Comment.all.sample + comment.vote_by(voter: voter, vote: vote) + end + + 100.times do + voter = not_org_users.level_two_or_three_verified.all.sample + proposal = Proposal.all.sample + proposal.vote_by(voter: voter, vote: true) + end +end + +section "Flagging Debates & Comments" do + 40.times do + debate = Debate.all.sample + flagger = User.where(["users.id <> ?", debate.author_id]).all.sample + Flag.flag(flagger, debate) + end + + 40.times do + comment = Comment.all.sample + flagger = User.where(["users.id <> ?", comment.user_id]).all.sample + Flag.flag(flagger, comment) + end + + 40.times do + proposal = Proposal.all.sample + flagger = User.where(["users.id <> ?", proposal.author_id]).all.sample + Flag.flag(flagger, proposal) + end +end + +section "Creating Spending Proposals" do + tags = Faker::Lorem.words(10) + 60.times do + geozone = Geozone.all.sample + author = User.all.sample + description = "

#{Faker::Lorem.paragraphs.join('

')}

" + feasible_explanation = "

#{Faker::Lorem.paragraphs.join('

')}

" + 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") + end +end + +section "Creating Valuation Assignments" do + (1..17).to_a.sample.times do + SpendingProposal.all.sample.valuators << Valuator.first + end +end + section "Ignoring flags in Debates, comments & proposals" do Debate.flagged.reorder("RANDOM()").limit(10).each(&:ignore_flag) Comment.flagged.reorder("RANDOM()").limit(30).each(&:ignore_flag)