Browse Source

aded has many to org for schemes

pull/648/head
JG 3 years ago
parent
commit
d232db9bb7
  1. 1
      app/models/organisation.rb
  2. 5
      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 :managed_case_logs, class_name: "CaseLog", foreign_key: "managing_organisation_id"
has_many :data_protection_confirmations has_many :data_protection_confirmations
has_many :organisation_rent_periods has_many :organisation_rent_periods
has_many :schemes
scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") } scope :search_by_name, ->(name) { where("name ILIKE ?", "%#{name}%") }
scope :search_by, ->(param) { search_by_name(param) } scope :search_by, ->(param) { search_by_name(param) }

5
spec/models/organisation_spec.rb

@ -4,6 +4,7 @@ RSpec.describe Organisation, type: :model do
describe "#new" do describe "#new" do
let(:user) { FactoryBot.create(:user) } let(:user) { FactoryBot.create(:user) }
let!(:organisation) { user.organisation } let!(:organisation) { user.organisation }
let!(:scheme) { FactoryBot.create(:scheme, organisation: organisation) }
it "has expected fields" do it "has expected fields" do
expect(organisation.attribute_names).to include("name", "phone", "provider_type") expect(organisation.attribute_names).to include("name", "phone", "provider_type")
@ -13,6 +14,10 @@ RSpec.describe Organisation, type: :model do
expect(organisation.users.first).to eq(user) expect(organisation.users.first).to eq(user)
end end
it "has schemes" do
expect(organisation.schemes.first).to eq(scheme)
end
it "validates provider_type presence" do it "validates provider_type presence" do
expect { FactoryBot.create(:organisation, provider_type: nil) } expect { FactoryBot.create(:organisation, provider_type: nil) }
.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Provider type can’t be blank") .to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Provider type can’t be blank")

Loading…
Cancel
Save