Browse Source

Validate provider type presence

pull/373/head
baarkerlounger 3 years ago
parent
commit
22f705528c
  1. 6
      app/admin/organisations.rb
  2. 2
      app/models/form/question.rb
  3. 2
      app/models/organisation.rb
  4. 1
      db/seeds.rb
  5. 2
      spec/controllers/admin/organisations_controller_spec.rb
  6. 2
      spec/factories/organisation.rb
  7. 2
      spec/fixtures/exports/case_logs.xml
  8. 4
      spec/models/form/question_spec.rb
  9. 5
      spec/models/organisation_spec.rb

6
app/admin/organisations.rb

@ -2,7 +2,7 @@ ActiveAdmin.register Organisation do
permit_params do permit_params do
permitted = %i[name permitted = %i[name
phone phone
providertype provider_type
address_line1 address_line1
address_line2 address_line2
postcode postcode
@ -28,8 +28,4 @@ ActiveAdmin.register Organisation do
column :managing_agents column :managing_agents
actions actions
end end
before_save do |org|
org.provider_type = params[:organisation][:provider_type]
end
end end

2
app/models/form/question.rb

@ -113,7 +113,7 @@ class Form::Question
else else
value.to_s value.to_s
end end
label || value label || value.to_s
end end
def value_is_yes?(value) def value_is_yes?(value)

2
app/models/organisation.rb

@ -12,6 +12,8 @@ class Organisation < ApplicationRecord
enum provider_type: PROVIDER_TYPE enum provider_type: PROVIDER_TYPE
validates :provider_type, presence: true
def case_logs def case_logs
CaseLog.for_organisation(self) CaseLog.for_organisation(self)
end end

1
db/seeds.rb

@ -15,6 +15,7 @@ org = Organisation.create!(
holds_own_stock: false, holds_own_stock: false,
other_stock_owners: "None", other_stock_owners: "None",
managing_agents: "None", managing_agents: "None",
provider_type: "LA",
) )
User.create!( User.create!(
email: "test@example.com", email: "test@example.com",

2
spec/controllers/admin/organisations_controller_spec.rb

@ -26,7 +26,7 @@ describe Admin::OrganisationsController, type: :controller do
end end
describe "Create organisation" do describe "Create organisation" do
let(:params) { { organisation: { name: "DLUHC" } } } let(:params) { { organisation: { name: "DLUHC", provider_type: "LA" } } }
it "creates a organisation" do it "creates a organisation" do
expect { post :create, session: valid_session, params: params }.to change(Organisation, :count).by(1) expect { post :create, session: valid_session, params: params }.to change(Organisation, :count).by(1)

2
spec/factories/organisation.rb

@ -3,7 +3,7 @@ FactoryBot.define do
name { "DLUHC" } name { "DLUHC" }
address_line1 { "2 Marsham Street" } address_line1 { "2 Marsham Street" }
address_line2 { "London" } address_line2 { "London" }
provider_type { 2 } provider_type { "LA" }
postcode { "SW1P 4DF" } postcode { "SW1P 4DF" }
created_at { Time.zone.now } created_at { Time.zone.now }
updated_at { Time.zone.now } updated_at { Time.zone.now }

2
spec/fixtures/exports/case_logs.xml vendored

@ -121,7 +121,7 @@
<managing_organisation_id>{managing_org_id}</managing_organisation_id> <managing_organisation_id>{managing_org_id}</managing_organisation_id>
<renttype>2</renttype> <renttype>2</renttype>
<needstype>1</needstype> <needstype>1</needstype>
<lettype>5</lettype> <lettype>7</lettype>
<postcode_known>1</postcode_known> <postcode_known>1</postcode_known>
<la_known>1</la_known> <la_known>1</la_known>
<is_la_inferred>false</is_la_inferred> <is_la_inferred>false</is_la_inferred>

4
spec/models/form/question_spec.rb

@ -118,7 +118,7 @@ RSpec.describe Form::Question, type: :model do
context "when the saved answer is not in the value map" do context "when the saved answer is not in the value map" do
it "displays the saved answer umapped" do it "displays the saved answer umapped" do
expect(question.label_from_value(9999)).to eq(9999) expect(question.label_from_value(9999)).to eq("9999")
end end
end end
end end
@ -139,7 +139,7 @@ RSpec.describe Form::Question, type: :model do
context "when the saved answer is not in the value map" do context "when the saved answer is not in the value map" do
it "displays the saved answer umapped" do it "displays the saved answer umapped" do
expect(question.label_from_value(9999)).to eq(9999) expect(question.label_from_value(9999)).to eq("9999")
end end
end end
end end

5
spec/models/organisation_spec.rb

@ -13,6 +13,11 @@ RSpec.describe Organisation, type: :model do
expect(organisation.users.first).to eq(user) expect(organisation.users.first).to eq(user)
end end
it "validates provider_type presence" do
expect { FactoryBot.create(:organisation, provider_type: nil) }
.to raise_error(ActiveRecord::RecordInvalid, "Validation failed: Provider type can't be blank")
end
context "with case logs" do context "with case logs" do
let(:other_organisation) { FactoryBot.create(:organisation) } let(:other_organisation) { FactoryBot.create(:organisation) }
let!(:owned_case_log) do let!(:owned_case_log) do

Loading…
Cancel
Save