baarkerlounger
3 years ago
committed by
GitHub
28 changed files with 398 additions and 99 deletions
@ -0,0 +1,10 @@
|
||||
module DetailsTableHelper |
||||
def details_html(attribute) |
||||
if attribute[:format] == :bullet |
||||
list = attribute[:value].map { |la| "<li>#{la}</li>" }.join |
||||
simple_format(list, { class: "govuk-list govuk-list--bullet" }, wrapper_tag: "ul") |
||||
else |
||||
simple_format(attribute[:value].to_s, {}, wrapper_tag: "div") |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,5 @@
|
||||
class LocalAuthority |
||||
def self.ons_code_mappings |
||||
FormHandler.instance.current_form.get_question("la", nil).answer_options |
||||
end |
||||
end |
@ -0,0 +1,3 @@
|
||||
class OrganisationLa < ApplicationRecord |
||||
belongs_to :organisation |
||||
end |
@ -0,0 +1,23 @@
|
||||
module Imports |
||||
class OrganisationLaImportService < ImportService |
||||
def create_organisation_las(folder) |
||||
import_from(folder, :create_organisation_la) |
||||
end |
||||
|
||||
private |
||||
|
||||
def create_organisation_la(xml_document) |
||||
xml_document.remove_namespaces! |
||||
organisation = Organisation.find_by(old_org_id: record_field_value(xml_document, "InstitutionId")) |
||||
|
||||
OrganisationLa.create!( |
||||
organisation:, |
||||
ons_code: record_field_value(xml_document, "ONSCode"), |
||||
) |
||||
end |
||||
|
||||
def record_field_value(xml_document, field) |
||||
xml_document.at_xpath("//#{field}")&.text |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,11 @@
|
||||
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 |
||||
remove_column :organisations, :local_authorities, :string |
||||
end |
||||
end |
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?> |
||||
<institution xmlns="http://www.ons.gov.uk/institutions-and-ons-la"> |
||||
<InstitutionId>44026acc7ed5c29516b26f2a5deb639e5e37966d</InstitutionId> |
||||
<AssociationId>7076</AssociationId> |
||||
<ONSCode>E07000041</ONSCode> |
||||
</institution> |
@ -0,0 +1,31 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe DetailsTableHelper do |
||||
describe "details html" do |
||||
let(:details) { details_html(attribute) } |
||||
|
||||
context "when given a simple attribute" do |
||||
let(:attribute) { { name: "name", value: "Dummy org", editable: true } } |
||||
|
||||
it "displays the string wrapped in a div" do |
||||
expect(details).to eq("<div>Dummy org</div>") |
||||
end |
||||
end |
||||
|
||||
context "when given a bullet point list of attibutes" do |
||||
let(:list) { %w[Camden Westminster Bristol] } |
||||
let(:attribute) do |
||||
{ |
||||
name: "local_authorities_operated_in", |
||||
value: list, |
||||
editable: false, |
||||
format: :bullet, |
||||
} |
||||
end |
||||
|
||||
it "displays the string wrapped in an unordered list with the correct classes" do |
||||
expect(details).to eq("<ul class=\"govuk-list govuk-list--bullet\"><li>Camden</li><li>Westminster</li><li>Bristol</li></ul>") |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,16 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe LocalAuthority, type: :model do |
||||
describe "ons code mapping" do |
||||
let(:form) { Form.new("spec/fixtures/forms/2021_2022.json", "2021_2022") } |
||||
|
||||
before do |
||||
allow(FormHandler.instance).to receive(:current_form).and_return(form) |
||||
end |
||||
|
||||
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 |
@ -0,0 +1,41 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe Imports::OrganisationLaImportService do |
||||
let(:fixture_directory) { "spec/fixtures/softwire_imports/organisation_las" } |
||||
let(:old_org_id) { "44026acc7ed5c29516b26f2a5deb639e5e37966d" } |
||||
let(:old_id) { "00013f30e159d7f72a3abe9ea93fb5b685d311e4" } |
||||
let(:import_file) { File.open("#{fixture_directory}/#{old_id}.xml") } |
||||
let(:storage_service) { instance_double(StorageService) } |
||||
|
||||
context "when importing data protection confirmations" do |
||||
subject(:import_service) { described_class.new(storage_service) } |
||||
|
||||
before do |
||||
allow(storage_service) |
||||
.to receive(:list_files) |
||||
.and_return(["organisation_la_directory/#{old_id}.xml"]) |
||||
allow(storage_service) |
||||
.to receive(:get_file_io) |
||||
.with("organisation_la_directory/#{old_id}.xml") |
||||
.and_return(import_file) |
||||
end |
||||
|
||||
context "when the organisation in the import file doesn't exist in the system" do |
||||
it "does not create an organisation la record" do |
||||
expect { import_service.create_organisation_las("organisation_la_directory") } |
||||
.to raise_error(ActiveRecord::RecordInvalid, /Organisation must exist/) |
||||
end |
||||
end |
||||
|
||||
context "when the organisation does exist" do |
||||
before do |
||||
FactoryBot.create(:organisation, old_org_id:) |
||||
end |
||||
|
||||
it "successfully create an organisation la record with the expected data" do |
||||
import_service.create_organisation_las("organisation_la_directory") |
||||
expect(Organisation.find_by(old_org_id:).organisation_las.pluck("ons_code")).to eq(%w[E07000041]) |
||||
end |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue