Improve dev seeds comments adding them to investments

This commit is contained in:
Bertocq
2018-01-30 03:29:20 +01:00
parent 093b191f16
commit a4fb568654

View File

@@ -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 = "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>"
feasible_explanation = "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>"
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 = "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>"
feasible_explanation = "<p>#{Faker::Lorem.paragraphs.join('</p><p>')}</p>"
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)