Add method to easily access a local target by code

Similar to what we do in goals and targets.
This commit is contained in:
Javi Martín
2021-01-20 19:41:50 +01:00
committed by taitus
parent 8542e3e3cf
commit cb57a4696d
3 changed files with 20 additions and 5 deletions

View File

@@ -82,4 +82,16 @@ describe SDG::LocalTarget do
expect(local_target).to be < greater_target
end
end
describe ".[]" do
it "finds existing local targets by code" do
create(:sdg_local_target, code: "1.1.1")
expect(SDG::LocalTarget["1.1.1"].code).to eq "1.1.1"
end
it "raises an exception for non-existing codes" do
expect { SDG::LocalTarget["1.1.99"] }.to raise_exception ActiveRecord::RecordNotFound
end
end
end