From ea03d76dced9036267e3d95583aafe9011d48bdc Mon Sep 17 00:00:00 2001 From: meyric Date: Wed, 4 Dec 2024 14:49:33 +0000 Subject: [PATCH] Fix org_participation role This enum stores the values as integers and maps them to symbols for ease. We have also declared is as a string, which is both incorrect and broken in Rails 7. In Rails 7 we can declare a default inside the enum definition, so we do that. We think this is working now because all records are 'implementing/3' so any loaded model returns the string `implementing` by default. We've check the production database and all values are correctly set to the integer '3'. --- app/models/org_participation.rb | 6 ++---- spec/models/org_participation_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/models/org_participation.rb b/app/models/org_participation.rb index 5869bdcdb..df3eb5e40 100644 --- a/app/models/org_participation.rb +++ b/app/models/org_participation.rb @@ -2,15 +2,13 @@ class OrgParticipation < ApplicationRecord belongs_to :activity belongs_to :organisation - attribute :role, :string, default: "implementing" - - enum role: { + enum :role, { partner_organisation: 0, matched_effort_provider: 1, external_income_provider: 2, implementing: 3, service_owner: 99 - } + }, default: :implementing scope :implementing, -> { where(role: :implementing) } diff --git a/spec/models/org_participation_spec.rb b/spec/models/org_participation_spec.rb index d7c523136..892e92722 100644 --- a/spec/models/org_participation_spec.rb +++ b/spec/models/org_participation_spec.rb @@ -45,4 +45,12 @@ end end end + + describe "the default role" do + it "is implementing" do + subject = OrgParticipation.new + + expect(subject.implementing?).to be true + end + end end