Remove redundant .all in .all.sample calls

Rubocop doesn't detect this method because we've added it in the
ApplicationRecord class, but we're removing the `.all` calls for
consistency.
This commit is contained in:
taitus
2023-11-08 14:07:17 +01:00
committed by Javi Martín
parent 0aee568977
commit 76837919b8
11 changed files with 49 additions and 49 deletions

View File

@@ -94,7 +94,7 @@ end
section "Creating Investments" do
tags = Faker::Lorem.words(number: 10)
100.times do
heading = Budget::Heading.all.sample
heading = Budget::Heading.sample
translation_attributes = random_locales.each_with_object({}) do |locale, attributes|
attributes["title_#{locale.to_s.underscore}"] = "Title for locale #{locale}"
@@ -102,7 +102,7 @@ section "Creating Investments" do
end
investment = Budget::Investment.create!({
author: User.all.sample,
author: User.sample,
heading: heading,
group: heading.group,
budget: heading.group.budget,
@@ -145,9 +145,9 @@ end
section "Winner Investments" do
budget = Budget.finished.first
50.times do
heading = budget.headings.all.sample
heading = budget.headings.sample
investment = Budget::Investment.create!(
author: User.all.sample,
author: User.sample,
heading: heading,
group: heading.group,
budget: heading.group.budget,
@@ -169,6 +169,6 @@ end
section "Creating Valuation Assignments" do
(1..50).to_a.sample.times do
Budget::Investment.all.sample.valuators << Valuator.first
Budget::Investment.sample.valuators << Valuator.first
end
end

View File

@@ -1,8 +1,8 @@
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,
commentable = commentable_class.constantize.sample
Comment.create!(user: User.sample,
created_at: rand(commentable.created_at..Time.current),
commentable: commentable,
body: Faker::Lorem.sentence)
@@ -12,8 +12,8 @@ end
section "Commenting Comments" do
200.times do
parent = Comment.all.sample
Comment.create!(user: User.all.sample,
parent = Comment.sample
Comment.create!(user: User.sample,
created_at: rand(parent.created_at..Time.current),
commentable_id: parent.commentable_id,
commentable_type: parent.commentable_type,

View File

@@ -5,15 +5,15 @@ end
section "Creating Communities Topics" do
Community.find_each do |community|
Topic.create(community: community, author: User.all.sample,
Topic.create(community: community, author: User.sample,
title: Faker::Lorem.sentence(word_count: 3).truncate(60), description: Faker::Lorem.sentence)
end
end
section "Commenting Community Topics" do
30.times do
author = User.all.sample
topic = Topic.all.sample
author = User.sample
topic = Topic.sample
Comment.create!(user: author,
created_at: rand(topic.created_at..Time.current),
commentable: topic,

View File

@@ -1,14 +1,14 @@
section "Creating Debates" do
tags = Faker::Lorem.words(number: 25)
30.times do
author = User.all.sample
author = User.sample
description = "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>"
debate = Debate.create!(author: author,
title: Faker::Lorem.sentence(word_count: 3).truncate(60),
created_at: rand((1.week.ago)..Time.current),
description: description,
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
geozone: Geozone.sample,
terms_of_service: "1")
random_locales.map do |locale|
Globalize.with_locale(locale) do
@@ -21,7 +21,7 @@ section "Creating Debates" do
tags = Tag.where(kind: "category")
30.times do
author = User.all.sample
author = User.sample
description = "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>"
debate = Debate.create!(author: author,
@@ -29,7 +29,7 @@ section "Creating Debates" do
created_at: rand((1.week.ago)..Time.current),
description: description,
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
geozone: Geozone.sample,
terms_of_service: "1")
random_locales.map do |locale|
Globalize.with_locale(locale) do

View File

@@ -1,19 +1,19 @@
section "Flagging Debates & Comments" do
40.times do
debate = Debate.all.sample
flagger = User.where.not(id: debate.author_id).all.sample
debate = Debate.sample
flagger = User.where.not(id: debate.author_id).sample
Flag.flag(flagger, debate)
end
40.times do
comment = Comment.all.sample
flagger = User.where.not(id: comment.user_id).all.sample
comment = Comment.sample
flagger = User.where.not(id: comment.user_id).sample
Flag.flag(flagger, comment)
end
40.times do
proposal = Proposal.all.sample
flagger = User.where.not(id: proposal.author_id).all.sample
proposal = Proposal.sample
flagger = User.where.not(id: proposal.author_id).sample
Flag.flag(flagger, proposal)
end
end

View File

@@ -3,8 +3,8 @@ section "Creating legislation proposals" do
Legislation::Proposal.create!(title: Faker::Lorem.sentence(word_count: 3).truncate(60),
description: Faker::Lorem.paragraphs.join("\n\n"),
summary: Faker::Lorem.paragraph,
author: User.all.sample,
process: Legislation::Process.all.sample,
author: User.sample,
process: Legislation::Process.sample,
terms_of_service: "1",
selected: rand <= 1.0 / 3)
end

View File

@@ -11,7 +11,7 @@ section "Creating investment milestones" do
rand(1..5).times do
milestone = record.milestones.build(
publication_date: Date.tomorrow,
status_id: Milestone::Status.all.sample
status_id: Milestone::Status.sample
)
random_locales.map do |locale|

View File

@@ -56,7 +56,7 @@ section "Creating Poll Questions & Answers" do
Poll.find_each do |poll|
(3..5).to_a.sample.times do
question_title = Faker::Lorem.sentence(word_count: 3).truncate(60) + "?"
question = Poll::Question.new(author: User.all.sample,
question = Poll::Question.new(author: User.sample,
title: question_title,
poll: poll)
I18n.available_locales.map do |locale|
@@ -96,7 +96,7 @@ section "Creating Poll Booths & BoothAssignments" do
20.times do |i|
Poll::Booth.create(name: "Booth #{i}",
location: Faker::Address.street_address,
polls: [Poll.all.sample])
polls: [Poll.sample])
end
end
@@ -125,8 +125,8 @@ end
section "Commenting Polls" do
30.times do
author = User.all.sample
poll = Poll.all.sample
author = User.sample
poll = Poll.sample
Comment.create!(user: author,
created_at: rand(poll.created_at..Time.current),
commentable: poll,
@@ -136,7 +136,7 @@ end
section "Creating Poll Voters" do
def vote_poll_on_booth(user, poll)
officer = Poll::Officer.all.sample
officer = Poll::Officer.sample
Poll::Voter.create!(document_type: user.document_type,
document_number: user.document_number,
@@ -230,7 +230,7 @@ end
section "Creating Poll Questions from Proposals" do
3.times do
proposal = Proposal.all.sample
proposal = Proposal.sample
poll = Poll.current.first
question = Poll::Question.new(poll: poll)
question.copy_attributes_from_proposal(proposal)
@@ -260,7 +260,7 @@ end
section "Creating Successful Proposals" do
10.times do
proposal = Proposal.all.sample
proposal = Proposal.sample
poll = Poll.current.first
question = Poll::Question.new(poll: poll)
question.copy_attributes_from_proposal(proposal)

View File

@@ -19,7 +19,7 @@ section "Creating Proposals" do
30.times do
title = Faker::Lorem.sentence(word_count: 3).truncate(60)
summary = Faker::Lorem.sentence(word_count: 3)
author = User.all.sample
author = User.sample
description = "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>"
proposal = Proposal.create!(author: author,
@@ -29,7 +29,7 @@ section "Creating Proposals" do
description: description,
created_at: rand((1.week.ago)..Time.current),
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
geozone: Geozone.sample,
terms_of_service: "1",
published_at: Time.current)
random_locales.map do |locale|
@@ -47,7 +47,7 @@ end
section "Creating Archived Proposals" do
tags = Faker::Lorem.words(number: 25)
5.times do
author = User.all.sample
author = User.sample
description = "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>"
proposal = Proposal.create!(author: author,
title: Faker::Lorem.sentence(word_count: 3).truncate(60),
@@ -55,7 +55,7 @@ section "Creating Archived Proposals" do
responsible_name: Faker::Name.name,
description: description,
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
geozone: Geozone.sample,
terms_of_service: "1",
created_at: Setting.archived_proposals_date_limit,
published_at: Setting.archived_proposals_date_limit)
@@ -74,7 +74,7 @@ end
section "Creating Successful Proposals" do
tags = Faker::Lorem.words(number: 25)
10.times do
author = User.all.sample
author = User.sample
description = "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>"
proposal = Proposal.create!(author: author,
title: Faker::Lorem.sentence(word_count: 3).truncate(60),
@@ -83,7 +83,7 @@ section "Creating Successful Proposals" do
description: description,
created_at: rand((1.week.ago)..Time.current),
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
geozone: Geozone.sample,
terms_of_service: "1",
cached_votes_up: Setting["votes_for_proposal_success"],
published_at: Time.current)
@@ -100,7 +100,7 @@ section "Creating Successful Proposals" do
tags = Tag.where(kind: "category")
30.times do
author = User.all.sample
author = User.sample
description = "<p>#{Faker::Lorem.paragraphs.join("</p><p>")}</p>"
proposal = Proposal.create!(author: author,
title: Faker::Lorem.sentence(word_count: 4).truncate(60),
@@ -109,7 +109,7 @@ section "Creating Successful Proposals" do
description: description,
created_at: rand((1.week.ago)..Time.current),
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
geozone: Geozone.sample,
terms_of_service: "1",
published_at: Time.current)
random_locales.map do |locale|
@@ -128,7 +128,7 @@ section "Creating proposal notifications" do
100.times do |i|
ProposalNotification.create!(title: "Proposal notification title #{i}",
body: "Proposal notification body #{i}",
author: User.all.sample,
proposal: Proposal.all.sample)
author: User.sample,
proposal: Proposal.sample)
end
end

View File

@@ -110,7 +110,7 @@ section "Creating Users" do
confirmed_phone: Faker::PhoneNumber.phone_number,
document_number: unique_document_number,
document_type: "1",
geozone: Geozone.all.sample)
geozone: Geozone.sample)
end
if level == 3
user.update(verified_at: Time.current, document_number: unique_document_number)

View File

@@ -1,22 +1,22 @@
section "Voting Debates, Proposals & Comments" do
not_org_users = User.where.not(id: User.organizations)
100.times do
voter = not_org_users.level_two_or_three_verified.all.sample
voter = not_org_users.level_two_or_three_verified.sample
vote = [true, false].sample
debate = Debate.all.sample
debate = Debate.sample
debate.vote_by(voter: voter, vote: vote)
end
100.times do
voter = not_org_users.all.sample
voter = not_org_users.sample
vote = [true, false].sample
comment = Comment.all.sample
comment = Comment.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
voter = not_org_users.level_two_or_three_verified.sample
proposal = Proposal.sample
proposal.vote_by(voter: voter, vote: true)
end
end