Skip to content

Commit

Permalink
Add Activity#roda_identifier
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
James Coglan committed Sep 22, 2020
1 parent 404b2d9 commit 651f754
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/models/activity.rb
Expand Up @@ -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?
Expand Down
7 changes: 6 additions & 1 deletion db/seeds/activity.rb
Expand Up @@ -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",
Expand All @@ -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
10 changes: 10 additions & 0 deletions spec/models/activity_spec.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 651f754

Please sign in to comment.