From e212612ee6f5e4a70b51cf7791efcaf8d289d6d3 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Thu, 21 Apr 2022 17:02:46 +0100 Subject: [PATCH] Add table --- app/models/organisation.rb | 1 + app/models/organisation_rent_period.rb | 3 +++ .../20220421140410_organisation_rent_period.rb | 10 ++++++++++ db/schema.rb | 10 +++++++++- spec/factories/organisation.rb | 7 +++++++ .../ebd22326d33e389e9f1bfd546979d2c05f9e68d6.xml | 5 +++++ spec/models/organisation_spec.rb | 13 ++++++++++++- 7 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 app/models/organisation_rent_period.rb create mode 100644 db/migrate/20220421140410_organisation_rent_period.rb create mode 100644 spec/fixtures/softwire_imports/organisation_rent_periods/ebd22326d33e389e9f1bfd546979d2c05f9e68d6.xml diff --git a/app/models/organisation.rb b/app/models/organisation.rb index 85cf76028..e5c26eec4 100644 --- a/app/models/organisation.rb +++ b/app/models/organisation.rb @@ -4,6 +4,7 @@ class Organisation < ApplicationRecord has_many :managed_case_logs, class_name: "CaseLog", foreign_key: "managing_organisation_id" has_many :data_protection_confirmations has_many :organisation_las + has_many :organisation_rent_periods has_paper_trail diff --git a/app/models/organisation_rent_period.rb b/app/models/organisation_rent_period.rb new file mode 100644 index 000000000..292ac75b2 --- /dev/null +++ b/app/models/organisation_rent_period.rb @@ -0,0 +1,3 @@ +class OrganisationRentPeriod < ApplicationRecord + belongs_to :organisation +end diff --git a/db/migrate/20220421140410_organisation_rent_period.rb b/db/migrate/20220421140410_organisation_rent_period.rb new file mode 100644 index 000000000..54e090647 --- /dev/null +++ b/db/migrate/20220421140410_organisation_rent_period.rb @@ -0,0 +1,10 @@ +class OrganisationRentPeriod < ActiveRecord::Migration[7.0] + def change + create_table :organisation_rent_periods do |t| + t.belongs_to :organisation + t.column :rent_period, :integer + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index beff46c57..dcd9e007a 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_04_20_165451) do +ActiveRecord::Schema[7.0].define(version: 2022_04_21_140410) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -264,6 +264,14 @@ ActiveRecord::Schema[7.0].define(version: 2022_04_20_165451) do t.index ["organisation_id"], name: "index_organisation_las_on_organisation_id" end + create_table "organisation_rent_periods", force: :cascade do |t| + t.bigint "organisation_id" + t.integer "rent_period" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["organisation_id"], name: "index_organisation_rent_periods_on_organisation_id" + end + create_table "organisations", force: :cascade do |t| t.string "name" t.string "phone" diff --git a/spec/factories/organisation.rb b/spec/factories/organisation.rb index 2bb293968..7da708cae 100644 --- a/spec/factories/organisation.rb +++ b/spec/factories/organisation.rb @@ -15,4 +15,11 @@ FactoryBot.define do created_at { Time.zone.now } updated_at { Time.zone.now } end + + factory :organisation_rent_period do + organisation + rent_period { 1 } + created_at { Time.zone.now } + updated_at { Time.zone.now } + end end diff --git a/spec/fixtures/softwire_imports/organisation_rent_periods/ebd22326d33e389e9f1bfd546979d2c05f9e68d6.xml b/spec/fixtures/softwire_imports/organisation_rent_periods/ebd22326d33e389e9f1bfd546979d2c05f9e68d6.xml new file mode 100644 index 000000000..7f6e4fb99 --- /dev/null +++ b/spec/fixtures/softwire_imports/organisation_rent_periods/ebd22326d33e389e9f1bfd546979d2c05f9e68d6.xml @@ -0,0 +1,5 @@ + + ebd22326d33e389e9f1bfd546979d2c05f9e68d6 + 44026acc7ed5c29516b26f2a5deb639e5e37966d + 1 + diff --git a/spec/models/organisation_spec.rb b/spec/models/organisation_spec.rb index 4766c35fa..a60d5574a 100644 --- a/spec/models/organisation_spec.rb +++ b/spec/models/organisation_spec.rb @@ -44,7 +44,7 @@ RSpec.describe Organisation, type: :model do end before do - FactoryBot.create(:organisation_la, organisation_id: organisation.id, ons_code: "E07000178") + FactoryBot.create(:organisation_la, organisation:, ons_code: "E07000178") allow(LocalAuthority).to receive(:ons_code_mappings).and_return(ons_code_mappings) end @@ -57,6 +57,17 @@ RSpec.describe Organisation, type: :model do end end + context "when the organisation only uses specific rent periods" do + before do + FactoryBot.create(:organisation_rent_period, organisation:, rent_period: 1) + FactoryBot.create(:organisation_rent_period, organisation:, rent_period: 2) + end + + it "has rent periods associated" do + expect(organisation.organisation_rent_periods.pluck("rent_period")).to eq([1, 2]) + end + end + context "with case logs" do let(:other_organisation) { FactoryBot.create(:organisation) } let!(:owned_case_log) do