From 651f7542ad763f7d442a4caead023260ced6285e Mon Sep 17 00:00:00 2001 From: James Coglan Date: Tue, 22 Sep 2020 11:49:48 +0100 Subject: [PATCH] Add Activity#roda_identifier This method lets you get the RODA identifier for an activity while hiding the implementation details of the `roda_identifier_fragment` and `roda_identifier_compound` fields. It returns the "compound" identifier, i.e. the cached ID formed by concatenating the fragments of all the ancestor activities. --- app/models/activity.rb | 4 ++++ db/seeds/activity.rb | 7 ++++++- spec/models/activity_spec.rb | 10 ++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/models/activity.rb b/app/models/activity.rb index d86329905..bf488d55c 100644 --- a/app/models/activity.rb +++ b/app/models/activity.rb @@ -179,6 +179,10 @@ def child_level end end + def roda_identifier + roda_identifier_compound + end + def can_set_roda_identifier? identifier_fragments = roda_identifier_fragment_chain identifier_fragments[0..-2].all?(&:present?) && identifier_fragments.last.blank? diff --git a/db/seeds/activity.rb b/db/seeds/activity.rb index a8f36a1f5..e9f976f52 100644 --- a/db/seeds/activity.rb +++ b/db/seeds/activity.rb @@ -12,7 +12,7 @@ _newton_fund = Activity.find_or_create_by(newton_fund_params) -delivery_partner = Organisation.find_by!(service_owner: false) +delivery_partner = User.all.find(&:delivery_partner?).organisation first_programme_params = FactoryBot.build(:programme_activity, title: "International Partnerships", @@ -37,3 +37,8 @@ extending_organisation: delivery_partner).attributes Activity.find_or_create_by(project_params) + +Activity.all.each do |activity| + activity.cache_roda_identifier! + activity.save! +end diff --git a/spec/models/activity_spec.rb b/spec/models/activity_spec.rb index 0b4316610..7d668bb06 100644 --- a/spec/models/activity_spec.rb +++ b/spec/models/activity_spec.rb @@ -1012,6 +1012,16 @@ end end + describe "#roda_identifier" do + let(:fund) { create(:fund_activity, roda_identifier_fragment: "GCRF") } + let(:programme) { create(:programme_activity, parent: fund, roda_identifier_fragment: "RSDel") } + let(:project) { create(:project_activity, parent: programme, roda_identifier_fragment: "DEL_Misc") } + + it "returns the compound RODA identifier" do + expect(project.roda_identifier).to eq("GCRF-RSDel-DEL_Misc") + end + end + describe "#actual_total_for_report_financial_quarter" do it "returns the total of all the activity's transactions scoped to a report" do project = create(:project_activity, :with_report)