Browse Source

Create org la relation

pull/484/head
baarkerlounger 3 years ago
parent
commit
09eb55b0ca
  1. 1
      app/models/organisation.rb
  2. 2
      app/models/organisation_la.rb
  3. 10
      db/migrate/20220420165451_create_organisation_la.rb
  4. 10
      db/schema.rb
  5. 7
      spec/factories/organisation.rb
  6. 10
      spec/models/organisation_spec.rb

1
app/models/organisation.rb

@ -3,6 +3,7 @@ class Organisation < ApplicationRecord
has_many :owned_case_logs, class_name: "CaseLog", foreign_key: "owning_organisation_id"
has_many :managed_case_logs, class_name: "CaseLog", foreign_key: "managing_organisation_id"
has_many :data_protection_confirmations
has_many :organisation_las
has_paper_trail

2
app/models/organisation_la.rb

@ -0,0 +1,2 @@
class OrganisationLa < ApplicationRecord
end

10
db/migrate/20220420165451_create_organisation_la.rb

@ -0,0 +1,10 @@
class CreateOrganisationLa < ActiveRecord::Migration[7.0]
def change
create_table :organisation_las do |t|
t.belongs_to :organisation
t.column :ons_code, :string
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_11_092231) do
ActiveRecord::Schema[7.0].define(version: 202202071123100) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -256,6 +256,14 @@ ActiveRecord::Schema[7.0].define(version: 2022_04_11_092231) do
t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" }
end
create_table "organisation_las", force: :cascade do |t|
t.bigint "organisation_id"
t.string "ons_code"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["organisation_id"], name: "index_organisation_las_on_organisation_id"
end
create_table "organisations", force: :cascade do |t|
t.string "name"
t.string "phone"

7
spec/factories/organisation.rb

@ -8,4 +8,11 @@ FactoryBot.define do
created_at { Time.zone.now }
updated_at { Time.zone.now }
end
factory :organisation_la do
organisation
ons_code { "E07000041" }
created_at { Time.zone.now }
updated_at { Time.zone.now }
end
end

10
spec/models/organisation_spec.rb

@ -29,6 +29,16 @@ RSpec.describe Organisation, type: :model do
end
end
context "when the organisation only operates in specific local authorities" do
before do
FactoryBot.create(:organisation_la, organisation_id: organisation.id)
end
it "has local authorities associated" do
expect(organisation.organisation_las.pluck(:ons_code)).to eq(["E07000041"])
end
end
context "with case logs" do
let(:other_organisation) { FactoryBot.create(:organisation) }
let!(:owned_case_log) do

Loading…
Cancel
Save