Skip to content

Commit

Permalink
Fix org_participation role
Browse files Browse the repository at this point in the history
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'.
  • Loading branch information
mec committed Dec 18, 2024
1 parent bb439a9 commit ea03d76
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 2 additions & 4 deletions app/models/org_participation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
8 changes: 8 additions & 0 deletions spec/models/org_participation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ea03d76

Please sign in to comment.