Files
nairobi/db/dev_seeds/debates.rb
Javi Martín 102cf74b3d Bump faker from 1.8.7 to 2.0
Since version 2.0 introduced many breaking changes, we're upgrading to
it first.

The changes have been done by installing the rubocop-faker gem and
running:

```
rubocop \
  --require rubocop-faker \
  --only Faker/DeprecatedArguments \
  --auto-correct
```
2021-08-13 04:39:44 +02:00

43 lines
1.7 KiB
Ruby

section "Creating Debates" do
tags = Faker::Lorem.words(number: 25)
30.times do
author = User.all.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((Time.current - 1.week)..Time.current),
description: description,
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
terms_of_service: "1")
random_locales.map do |locale|
Globalize.with_locale(locale) do
debate.title = "Title for locale #{locale}"
debate.description = "<p>Description for locale #{locale}</p>"
debate.save!
end
end
end
tags = Tag.where(kind: "category")
30.times do
author = User.all.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((Time.current - 1.week)..Time.current),
description: description,
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
terms_of_service: "1")
random_locales.map do |locale|
Globalize.with_locale(locale) do
debate.title = "Title for locale #{locale}"
debate.description = "<p>Description for locale #{locale}</p>"
debate.save!
end
end
end
end