Browse Source

Add table

pull/487/head
baarkerlounger 3 years ago
parent
commit
e212612ee6
  1. 1
      app/models/organisation.rb
  2. 3
      app/models/organisation_rent_period.rb
  3. 10
      db/migrate/20220421140410_organisation_rent_period.rb
  4. 10
      db/schema.rb
  5. 7
      spec/factories/organisation.rb
  6. 5
      spec/fixtures/softwire_imports/organisation_rent_periods/ebd22326d33e389e9f1bfd546979d2c05f9e68d6.xml
  7. 13
      spec/models/organisation_spec.rb

1
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

3
app/models/organisation_rent_period.rb

@ -0,0 +1,3 @@
class OrganisationRentPeriod < ApplicationRecord
belongs_to :organisation
end

10
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

10
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"

7
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

5
spec/fixtures/softwire_imports/organisation_rent_periods/ebd22326d33e389e9f1bfd546979d2c05f9e68d6.xml vendored

@ -0,0 +1,5 @@
<rent-period:rent-period xmlns:rent-period="dclg:rent-period">
<rent-period:id>ebd22326d33e389e9f1bfd546979d2c05f9e68d6</rent-period:id>
<rent-period:institution>44026acc7ed5c29516b26f2a5deb639e5e37966d</rent-period:institution>
<rent-period:period>1</rent-period:period>
</rent-period:rent-period>

13
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

Loading…
Cancel
Save