From 9dd1e79791542555a4f06ab48c8ab5caf3349092 Mon Sep 17 00:00:00 2001 From: Jack S Date: Mon, 17 Oct 2022 17:26:32 +0100 Subject: [PATCH] [CLDC-1679] Add relationshop type to org relationship --- app/models/organisation_relationship.rb | 7 +++++++ ..._relationship_type_to_org_relationships.rb | 10 ++++++++++ db/schema.rb | 8 ++++---- spec/models/organisation_spec.rb | 20 +++++++++++++++++-- 4 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20221017095918_add_relationship_type_to_org_relationships.rb diff --git a/app/models/organisation_relationship.rb b/app/models/organisation_relationship.rb index 034fc5d0e..5c50c3e0f 100644 --- a/app/models/organisation_relationship.rb +++ b/app/models/organisation_relationship.rb @@ -1,4 +1,11 @@ class OrganisationRelationship < ApplicationRecord belongs_to :child_organisation, class_name: "Organisation" belongs_to :parent_organisation, class_name: "Organisation" + + RELATIONSHIP_TYPE = { + "owning": 0, + "managing": 1, + }.freeze + + enum relationship_type: RELATIONSHIP_TYPE end diff --git a/db/migrate/20221017095918_add_relationship_type_to_org_relationships.rb b/db/migrate/20221017095918_add_relationship_type_to_org_relationships.rb new file mode 100644 index 000000000..a45cff1d9 --- /dev/null +++ b/db/migrate/20221017095918_add_relationship_type_to_org_relationships.rb @@ -0,0 +1,10 @@ +class AddRelationshipTypeToOrgRelationships < ActiveRecord::Migration[7.0] + def change + add_column( + :organisation_relationships, + :relationship_type, + :integer, + null: false, # rubocop:disable Rails/NotNullColumn + ) + end +end diff --git a/db/schema.rb b/db/schema.rb index 2af1b4f54..59a0dbd24 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2022_10_11_094347) do +ActiveRecord::Schema[7.0].define(version: 2022_10_17_095918) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -277,6 +277,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_11_094347) do t.integer "parent_organisation_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.integer "relationship_type", null: false end create_table "organisation_rent_periods", force: :cascade do |t| @@ -358,15 +359,14 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_11_094347) do t.integer "hholdcount" t.integer "age3" t.integer "age3_known" + t.integer "income1" + t.integer "income1nk" t.integer "age4" t.integer "age4_known" t.integer "age5" t.integer "age5_known" t.integer "age6" t.integer "age6_known" - t.integer "proplen" - t.integer "income1" - t.integer "income1nk" t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id" t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id" diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 7bc1d7cc1..b6011cf20 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -27,11 +27,27 @@ RSpec.describe Organisation, type: :model do .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Provider type #{I18n.t('validations.organisation.provider_type_missing')}") end - context "with parent/child association" do + context "with managing association" do let(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") } before do - FactoryBot.create(:organisation_relationship, child_organisation:, parent_organisation: organisation) + FactoryBot.create(:organisation_relationship, child_organisation:, parent_organisation: organisation, relationship_type: 0) + end + + it "has correct child" do + expect(organisation.child_organisations.first).to eq(child_organisation) + end + + it "has correct parent" do + expect(child_organisation.parent_organisations.first).to eq(organisation) + end + end + + context "with owning association" do + let(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") } + + before do + FactoryBot.create(:organisation_relationship, child_organisation:, parent_organisation: organisation, relationship_type: 1) end it "has correct child" do