Files
nairobi/spec/factories/sdg.rb
taitus 0a3de68206 Add relation between Goal and LocalTarget
This is similar to what we do with investments, which belong to a heading
but also belong to a budget. In our case, the reason is we've been asked
to add local targets which belong to a goal but are not related to any
existing target.
Even though we're not implementing that case right now, we're adding the
relation so we don't have to add data migrations in the future.
2021-01-26 19:10:12 +01:00

32 lines
894 B
Ruby

FactoryBot.define do
factory :sdg_goal, class: "SDG::Goal" do
sequence(:code) { |n| n }
end
factory :sdg_target, class: "SDG::Target" do
sequence(:code, 1) { |n| "#{n}.#{n}" }
end
factory :sdg_local_target, class: "SDG::LocalTarget" do
code { "1.1.1" }
sequence(:title) { |n| "Local Target #{n} title" }
sequence(:description) { |n| "Help for Local Target #{n}" }
target { SDG::Target[code.rpartition(".").first] }
goal { SDG::Goal[code.split(".")[0]] }
end
factory :sdg_phase, class: "SDG::Phase" do
kind { :sensitization }
end
factory :sdg_review, class: "SDG::Review" do
SDG::Related::RELATABLE_TYPES.map { |relatable_type| relatable_type.downcase.gsub("::", "_") }
.each do |relatable|
trait :"#{relatable}_review" do
association :relatable, factory: relatable
end
end
end
end