Skip to content

Commit

Permalink
Add a chair of governors association
Browse files Browse the repository at this point in the history
We want to store one single contact who is considered the chair of
governors at the school.

This is only available on conversions as academies do not have
governors.
  • Loading branch information
mec committed Mar 28, 2024
1 parent bc0e292 commit b2644a4
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/models/contact/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def self.policy_class
has_one :main_contact_for_incoming_trust, class_name: "::Project", inverse_of: :incoming_trust_main_contact
has_one :main_contact_for_outgoing_trust, class_name: "::Project", inverse_of: :outgoing_trust_main_contact
has_one :main_contact_for_funding_agreement, class_name: "::Project", inverse_of: :funding_agreement_contact
has_one :contact_for_chair_of_governors, class_name: "Conversion::Project", inverse_of: :chair_of_governors_contact

def establishment_main_contact
project.establishment_main_contact_id == id
Expand Down
4 changes: 4 additions & 0 deletions app/models/conversion/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ def self.policy_class
ProjectPolicy
end

has_one :chair_of_governors, class_name: "Contact::Project", inverse_of: :project

belongs_to :chair_of_governors_contact, inverse_of: :contact_for_chair_of_governors, dependent: :destroy, class_name: "Contact::Project", optional: true

attr_writer :academy

alias_attribute :conversion_date, :significant_date
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddChairOfGovernorsToProject < ActiveRecord::Migration[7.0]
def change
add_column :projects, :chair_of_governors_contact_id, :uuid
end
end
3 changes: 2 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions spec/models/contact/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
RSpec.describe Contact::Project do
describe "Relationships" do
it { is_expected.to belong_to(:project) }
it { is_expected.to have_one(:contact_for_chair_of_governors) }
end

describe "#establishment_main_contact" do
Expand Down
6 changes: 6 additions & 0 deletions spec/models/conversion/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
RSpec.describe Conversion::Project do
before { mock_successful_api_response_to_create_any_project }

describe "associations" do
describe "chair of governors" do
it { is_expected.to belong_to(:chair_of_governors_contact).optional(true) }
end
end

describe "validations" do
describe "academy urn" do
context "when there is no academy urn" do
Expand Down

0 comments on commit b2644a4

Please sign in to comment.