List local targets alongside targets

This commit is contained in:
Javi Martín
2021-01-20 19:56:17 +01:00
parent 176839c905
commit 39d68a1779
2 changed files with 12 additions and 2 deletions

View File

@@ -14,7 +14,6 @@ module SDG::Relatable
through: :sdg_relations,
source: :related_sdg,
source_type: "SDG::Target"
alias_method :sdg_targets, :sdg_global_targets
alias_method :sdg_targets=, :sdg_global_targets=
has_one :sdg_review, as: :relatable, dependent: :destroy, class_name: "SDG::Review"
@@ -54,12 +53,16 @@ module SDG::Relatable
sdg_relations.map(&:related_sdg)
end
def sdg_targets
sdg_global_targets + sdg_local_targets
end
def sdg_goal_list
sdg_goals.order(:code).map(&:code).join(", ")
end
def sdg_target_list
sdg_global_targets.sort.map(&:code).join(", ")
sdg_targets.sort.map(&:code).join(", ")
end
def sdg_related_list

View File

@@ -60,6 +60,13 @@ describe SDG::Relatable do
expect(relatable.sdg_target_list).to eq "1.2, 2.1, 2.2"
end
it "includes both targets and local targets in order" do
relatable.sdg_global_targets = [SDG::Target[2.2], SDG::Target[1.2], SDG::Target[2.1]]
relatable.sdg_local_targets = %w[1.1.1 2.1.3].map { |code| create(:sdg_local_target, code: code) }
expect(relatable.sdg_target_list).to eq "1.1.1, 1.2, 2.1, 2.1.3, 2.2"
end
end
describe "#sdg_local_targets" do