Browse Source

[CLDC-1679] Add relationshop type to org relationship (#947)

pull/951/head
Jack S 2 years ago committed by GitHub
parent
commit
75206fdde9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      app/models/organisation_relationship.rb
  2. 10
      db/migrate/20221017095918_add_relationship_type_to_org_relationships.rb
  3. 8
      db/schema.rb
  4. 20
      spec/models/organisation_spec.rb

7
app/models/organisation_relationship.rb

@ -1,4 +1,11 @@
class OrganisationRelationship < ApplicationRecord class OrganisationRelationship < ApplicationRecord
belongs_to :child_organisation, class_name: "Organisation" belongs_to :child_organisation, class_name: "Organisation"
belongs_to :parent_organisation, class_name: "Organisation" belongs_to :parent_organisation, class_name: "Organisation"
RELATIONSHIP_TYPE = {
"owning": 0,
"managing": 1,
}.freeze
enum relationship_type: RELATIONSHIP_TYPE
end end

10
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

8
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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 # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -277,6 +277,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_11_094347) do
t.integer "parent_organisation_id" t.integer "parent_organisation_id"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.integer "relationship_type", null: false
end end
create_table "organisation_rent_periods", force: :cascade do |t| 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 "hholdcount"
t.integer "age3" t.integer "age3"
t.integer "age3_known" t.integer "age3_known"
t.integer "income1"
t.integer "income1nk"
t.integer "age4" t.integer "age4"
t.integer "age4_known" t.integer "age4_known"
t.integer "age5" t.integer "age5"
t.integer "age5_known" t.integer "age5_known"
t.integer "age6" t.integer "age6"
t.integer "age6_known" 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 ["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 ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

20
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')}") .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Provider type #{I18n.t('validations.organisation.provider_type_missing')}")
end end
context "with parent/child association" do context "with managing association" do
let(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") } let(:child_organisation) { FactoryBot.create(:organisation, name: "DLUHC Child") }
before do 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 end
it "has correct child" do it "has correct child" do

Loading…
Cancel
Save