Allow assigning both targets and local targets

Particularly useful in tests, because writing `targets` is shorter than
writing `global_targets` and `local_targets`.
This commit is contained in:
Javi Martín
2021-01-21 18:05:07 +01:00
parent 39d68a1779
commit b5ccae2f40
2 changed files with 21 additions and 1 deletions

View File

@@ -69,6 +69,18 @@ describe SDG::Relatable do
end
end
describe "#sdg_targets=" do
it "assigns both targets and local targets" do
global_targets = [SDG::Target[2.2], SDG::Target[1.2]]
local_targets = %w[2.2.1 3.1.1].map { |code| create(:sdg_local_target, code: code) }
relatable.sdg_targets = global_targets + local_targets
expect(relatable.sdg_global_targets).to match_array global_targets
expect(relatable.sdg_local_targets).to match_array local_targets
end
end
describe "#sdg_local_targets" do
it "can assign local targets to a model" do
relatable.sdg_local_targets = [local_target, another_local_target]