Files
nairobi/db/dev_seeds/sdg.rb
Javi Martín 8b13daad95 Add and apply rules for multi-line hashes
For the HashAlignment rule, we're using the default `key` style (keys
are aligned and values aren't) instead of the `table` style (both keys
and values are aligned) because, even if we used both in the
application, we used the `key` style a lot more. Furthermore, the
`table` style looks strange in places where there are both very long and
very short keys and sometimes we weren't even consistent with the
`table` style, aligning some keys without aligning other keys.

Ideally we could align hashes to "either key or table", so developers
can decide whether keeping the symmetry of the code is worth it in a
case-per-case basis, but Rubocop doesn't allow this option.
2023-08-18 14:56:16 +02:00

40 lines
1.5 KiB
Ruby

section "Creating Sustainable Development Goals" do
load Rails.root.join("db", "sdg.rb")
SDG::Target.sample(30).each do |target|
title = "Title for default locale"
description = "Description for default locale"
rand(2..3).times do |n|
local_target = SDG::LocalTarget.create!(code: "#{target.code}.#{n + 1}",
title: title,
description: description,
target: target)
random_locales.map do |locale|
Globalize.with_locale(locale) do
local_target.title = "Title for locale #{locale}"
local_target.description = "Description for locale #{locale}"
local_target.save!
end
end
end
end
relatables = [Debate, Proposal, Poll, Legislation::Process, Budget::Investment]
relatables.map { |relatable| relatable.sample(5) }.flatten.each do |relatable|
Array(SDG::Goal.sample(rand(1..3))).each do |goal|
target = goal.targets.sample
local_target = target.local_targets.sample
relatable.sdg_goals << goal
relatable.sdg_targets << target
relatable.sdg_local_targets << local_target if local_target.present?
end
end
end
section "Creating SDG homepage cards" do
SDG::Phase.all.each do |phase|
Widget::Card.create!(cardable: phase, title: "#{phase.title} card",
link_text: "Link Text", link_url: "/any_path")
end
end