-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #710 from DEFRA/feature/RUBY-2729-pafs-pso-rfcc-re…
…factoring Feature/ruby 2729 pafs pso rfcc refactoring
- Loading branch information
Showing
16 changed files
with
164 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module PafsCore | ||
class PsoRfccService | ||
class << self | ||
def map | ||
PafsCore::Area.pso_areas.select(:name, :sub_type).to_h { |a| [a.name, a.sub_type] } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddRfccCodes < ActiveRecord::Migration[7.0] | ||
def up | ||
PafsCore::DataMigration::AddRfccCodes.up | ||
end | ||
|
||
def down | ||
PafsCore::DataMigration::AddRfccCodes.down | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# frozen_string_literal: true | ||
|
||
module PafsCore | ||
module DataMigration | ||
class AddRfccCodes | ||
class << self | ||
def up | ||
# map PSO areas to RFCC codes | ||
pso_rfcc_map = { | ||
"PSO Berkshire and Buckinghamshire" => "TH", | ||
"PSO Cambridge and Bedfordshire" => "AC", | ||
"PSO Cheshire and Merseyside" => "NW", | ||
"PSO Coastal Essex Suffolk and Norfolk" => "AE", | ||
"PSO Coastal Lincolnshire and Northamptonshire" => "AN", | ||
"PSO Cumbria" => "NW", | ||
"PSO Derbyshire and Leicestershire" => "TR", | ||
"PSO Dorset and Wiltshire" => "WX", | ||
"PSO Durham and Tees Valley" => "NO", | ||
"PSO East Devon and Cornwall" => "SW", | ||
"PSO East Kent" => "SO", | ||
"PSO East Sussex" => "SO", | ||
"PSO East Yorkshire" => "YO", | ||
"PSO Essex" => "AE", | ||
"PSO Greater Manchester" => "NW", | ||
"PSO Hampshire and Isle of Wight" => "SO", | ||
"PSO Herefordshire and Gloucestershire" => "SN", | ||
"PSO Lancashire" => "NW", | ||
"PSO Lincolnshire" => "AN", | ||
"PSO London East" => "TH", | ||
"PSO London West" => "TH", | ||
"PSO Luton Hertfordshire and Essex" => "TH", | ||
"PSO Norfolk and Suffolk" => "AE", | ||
"PSO North Yorkshire" => "YO", | ||
"PSO Nottinghamshire and Tidal Trent" => "TR", | ||
"PSO Oxfordshire" => "TH", | ||
"PSO Shropshire Worcestershire Telford and Wrekin" => "SN", | ||
"PSO Somerset" => "WX", | ||
"PSO South East London and North Kent" => "TH", | ||
"PSO South West London and Mole" => "TH", | ||
"PSO South Yorkshire" => "YO", | ||
"PSO Staffordshire and the Black Country" => "TR", | ||
"PSO Surrey" => "TH", | ||
"PSO Test Area" => "TS", | ||
"PSO Tyne and Wear and Northumberland" => "NO", | ||
"PSO Warwickshire Birmingham Solihull and Coventry" => "SN", | ||
"PSO Welland and Nene" => "AN", | ||
"PSO West Devon and Cornwall" => "SW", | ||
"PSO West Kent" => "SO", | ||
"PSO West of England" => "WX", | ||
"PSO West Sussex" => "SO", | ||
"PSO West Yorkshire" => "YO" | ||
} | ||
|
||
pso_rfcc_map.each do |pso_name, code| | ||
pso = PafsCore::Area.find_by(area_type: PafsCore::Area::PSO_AREA, name: pso_name) | ||
next if pso.nil? | ||
|
||
pso.update(sub_type: code) | ||
end | ||
end | ||
|
||
def down | ||
PafsCore::Area.where(area_type: PafsCore::Area::PSO_AREA).update(sub_type: nil) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name,"parent area","type","sub type" | ||
England,,Country, | ||
Wessex,England,EA Area, | ||
Bristol & Bath,Wessex,PSO Area, | ||
Bristol & Bath,Wessex,PSO Area,WX | ||
Bristol City Council,Bristol & Bath,RMA,Local Authority |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name,"parent area","type","sub type" | ||
England,,Country, | ||
Wessex,England,EA Area, | ||
Bristol & Bath,Wessex,PSO Area, | ||
Bristol & Bath,Wessex,PSO Area,WX | ||
Bristol City Council,Bristil & Bath,RMA,Local Authority | ||
Bath & NES council,Bristol & Bath,RMA,, | ||
,,Country, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name,"parent area","type","sub type" | ||
England,,Country, | ||
EA Test Area,England,EA Area, | ||
PSO Test Area,EA Test Area,PSO Area, | ||
PSO Test Area,EA Test Area,PSO Area,TR | ||
RMA Test Area,PSO Test Area,RMA,Local Authority |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe PafsCore::DataMigration::AddRfccCodes do | ||
|
||
describe "#up" do | ||
it "updates RFCC codes for PSO records" do | ||
pso = build(:pso_area, name: "PSO Berkshire and Buckinghamshire", sub_type: nil) | ||
pso.save!(validate: false) | ||
|
||
described_class.up | ||
expect(pso.reload.sub_type).to eq("TH") | ||
end | ||
end | ||
|
||
describe "#down" do | ||
it "removes RFCC codes from PSOuthorities records" do | ||
pso = create(:pso_area, name: "PSO Berkshire and Buckinghamshire", sub_type: "TH") | ||
described_class.down | ||
expect(pso.reload.sub_type).to eq("TH") | ||
end | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
spec/lib/pafs_core/data_migration/update_authorities_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe PafsCore::DataMigration::UpdateAuthorities do | ||
|
||
describe "#up" do | ||
it "adds authorities records if not present" do | ||
expect(PafsCore::Area.authorities.count).to eq(0) | ||
described_class.up | ||
expect(PafsCore::Area.authorities.count).to eq(7) | ||
end | ||
|
||
it "adds missing authorities records" do | ||
create(:authority, name: "Environment Agency", identifier: "EA") | ||
expect(PafsCore::Area.authorities.count).to eq(1) | ||
described_class.up | ||
expect(PafsCore::Area.authorities.count).to eq(7) | ||
end | ||
end | ||
|
||
describe "#down" do | ||
it "removes authorities records" do | ||
create(:authority, name: "Environment Agency", identifier: "EA") | ||
described_class.down | ||
expect(PafsCore::Area.authorities.count).to eq(0) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters