Browse Source

Display LA name rather than code

pull/484/head
baarkerlounger 3 years ago
parent
commit
d9883c13a4
  1. 2
      app/models/form.rb
  2. 5
      app/models/local_authority.rb
  3. 8
      app/models/organisation.rb
  4. 10
      spec/models/local_authority_spec.rb
  5. 8
      spec/models/organisation_spec.rb

2
app/models/form.rb

@ -26,7 +26,7 @@ class Form
def get_question(id, case_log)
all_questions = questions.select { |q| q.id == id.to_s.underscore }
routed_question = all_questions.find { |q| q.page.routed_to?(case_log) }
routed_question = all_questions.find { |q| q.page.routed_to?(case_log) } if case_log
routed_question || all_questions[0]
end

5
app/models/local_authority.rb

@ -0,0 +1,5 @@
class LocalAuthority
def self.ons_code_mappings
FormHandler.instance.forms["2021_2022"].get_question("la", nil).answer_options
end
end

8
app/models/organisation.rb

@ -37,7 +37,11 @@ class Organisation < ApplicationRecord
end
def local_authorities
organisation_las.pluck(:ons_code)
organisation_las.pluck(:ons_code).map { |ons_code| ons_code }
end
def local_authority_names
local_authorities.map { |ons_code| LocalAuthority.ons_code_mappings[ons_code] }
end
def display_attributes
@ -46,7 +50,7 @@ class Organisation < ApplicationRecord
{ name: "address", value: address_string, editable: true },
{ name: "telephone_number", value: phone, editable: true },
{ name: "type", value: "Org type", editable: false },
{ name: "local_authorities_operated_in", value: local_authorities, editable: false, format: :bullet },
{ name: "local_authorities_operated_in", value: local_authority_names, editable: false, format: :bullet },
{ name: "holds_own_stock", value: holds_own_stock.to_s.humanize, editable: false },
{ name: "other_stock_owners", value: other_stock_owners, editable: false },
{ name: "managing_agents", value: managing_agents, editable: false },

10
spec/models/local_authority_spec.rb

@ -0,0 +1,10 @@
require "rails_helper"
RSpec.describe LocalAuthority, type: :model do
describe "ons code mapping" do
it "maps ONS code to local authority names" do
expect(described_class.ons_code_mappings).to be_a(Hash)
expect(described_class.ons_code_mappings["E07000178"]).to eq("Oxford")
end
end
end

8
spec/models/organisation_spec.rb

@ -31,11 +31,15 @@ RSpec.describe Organisation, type: :model do
context "when the organisation only operates in specific local authorities" do
before do
FactoryBot.create(:organisation_la, organisation_id: organisation.id)
FactoryBot.create(:organisation_la, organisation_id: organisation.id, ons_code: "E07000178")
end
it "has local authorities associated" do
expect(organisation.organisation_las.pluck(:ons_code)).to eq(%w[E07000041])
expect(organisation.local_authorities).to eq(%w[E07000178])
end
it "maps the ons codes to LA names for display" do
expect(organisation.local_authority_names).to eq(%w[Oxford])
end
end

Loading…
Cancel
Save