diff --git a/README.md b/README.md index 462a3d3fcf..f916e540b3 100644 --- a/README.md +++ b/README.md @@ -123,8 +123,6 @@ The project is a fairly standard Rails web app. However, there are a few aspects The framework-specific routes and code are all isolated from each other using namespaces with some code shared across frameworks. In some ways the code for each framework could be considered as a mini web app in its own right and the intention is that it should be relatively easy to extract the code for one framework into a separate Rails app if that was deemed appropriate down the line. -A bunch of other less-variable data is stored in CSV files in the code repository and made available to the application via classes including the `StaticRecord` concern, e.g. `Nuts3Region` which loads its data from `data/nuts3_regions.csv`. - The user journey for each framework is made up of a series of questions which lead the user to an appropriate outcome. This workflow is modelled by a journey class which inherits from `GenericJourney`, a series of step classes which include the `Steppable` concern, and view templates corresponding to each step. diff --git a/app/models/nuts1_region.rb b/app/models/nuts1_region.rb deleted file mode 100644 index 851b4dfffd..0000000000 --- a/app/models/nuts1_region.rb +++ /dev/null @@ -1,15 +0,0 @@ -class Nuts1Region - include StaticRecord - - attr_accessor :code, :name - - def nuts2_regions - Nuts2Region.where(nuts1_code: code) - end - - def self.all_codes - all.map(&:code) - end -end - -StaticDataLoader.load_static_data(Nuts1Region) diff --git a/app/models/nuts2_region.rb b/app/models/nuts2_region.rb deleted file mode 100644 index ec9bda0baf..0000000000 --- a/app/models/nuts2_region.rb +++ /dev/null @@ -1,23 +0,0 @@ -class Nuts2Region - include StaticRecord - - attr_accessor :code, :nuts1_code, :name - - def nuts1_region - Nuts1Region.find_by(code: nuts1_code) - end - - def nuts3_regions - Nuts3Region.where(nuts2_code: code) - end - - def self.all_codes - all.map(&:code) - end - - def self.to_h - Nuts2Region.all.map(&:code).zip(Nuts2Region.all.map(&:name)).to_h - end -end - -StaticDataLoader.load_static_data(Nuts2Region) diff --git a/app/models/nuts3_region.rb b/app/models/nuts3_region.rb deleted file mode 100644 index c3b2d7f079..0000000000 --- a/app/models/nuts3_region.rb +++ /dev/null @@ -1,13 +0,0 @@ -class Nuts3Region - include StaticRecord - - attr_accessor :code, :nuts2_code, :name - - def nuts2_region - Nuts2Region.find_by(code: nuts2_code) - end - - delegate :nuts1_code, :nuts1_region, to: :nuts2_region -end - -StaticDataLoader.load_static_data(Nuts3Region) diff --git a/app/services/static_data_loader.rb b/app/services/static_data_loader.rb deleted file mode 100644 index 2299381411..0000000000 --- a/app/services/static_data_loader.rb +++ /dev/null @@ -1,40 +0,0 @@ -class StaticDataLoader - @queries = { - Nuts1Region: 'SELECT code, name FROM nuts_regions where nuts1_code is null and nuts2_code is null', - Nuts2Region: 'SELECT code, nuts1_code, name FROM nuts_regions where not nuts1_code is null', - Nuts3Region: 'SELECT code, name, nuts2_code FROM nuts_regions where not nuts2_code is null', - } - - def self.load_static_data(static_data_class) - class_name = static_data_class.name.demodulize - begin - # typical SQL select query - # query = <<~SQL - # SELECT code, name FROM fm_regions - # SQL - query = @queries[class_name.to_sym] - static_data_class.load_db(query) - rescue StandardError - call_rake static_data_class, class_name, query if static_data_class.count.zero? - end - end - - def self.call_rake(static_data_class, class_name, query) - if File.split($PROGRAM_NAME).last == 'rake' - Rails.logger.info('') - else - begin - Rails.logger.info('No, this is not a Rake task') - Rails.application.load_tasks - Rake::Task['db:static'].execute - # reload the data a second time - static_data_class.load_db(query) - rescue StandardError => e - message = "#{class_name} data is missing! Please run 'rake db:static' to load static data." - Rails.logger.info("\e[5;37;41m\n#{message}\e[0m\n") - Rails.logger.info("\e[5;37;41m\n#{e}\e[0m\n") - raise e - end - end - end -end diff --git a/data/nuts1_regions.csv b/data/nuts1_regions.csv deleted file mode 100644 index 3a9b2c24c9..0000000000 --- a/data/nuts1_regions.csv +++ /dev/null @@ -1,13 +0,0 @@ -code,name -UKC,North East (England) -UKD,North West (England) -UKE,Yorkshire and The Humber -UKF,East Midlands (England) -UKG,West Midlands (England) -UKH,East of England -UKI,London -UKJ,South East (England) -UKK,South West (England) -UKL,Wales -UKM,Scotland -UKN,Northern Ireland diff --git a/data/nuts2_regions.csv b/data/nuts2_regions.csv deleted file mode 100644 index bf393e1359..0000000000 --- a/data/nuts2_regions.csv +++ /dev/null @@ -1,41 +0,0 @@ -code,nuts1_code,name -UKC1,UKC,Tees Valley and Durham -UKC2,UKC,Northumberland and Tyne and Wear -UKD1,UKD,Cumbria -UKD3,UKD,Greater Manchester -UKD4,UKD,Lancashire -UKD6,UKD,Cheshire -UKD7,UKD,Merseyside -UKE1,UKE,East Yorkshire and Northern Lincolnshire -UKE2,UKE,North Yorkshire -UKE3,UKE,South Yorkshire -UKE4,UKE,West Yorkshire -UKF1,UKF,Derbyshire and Nottinghamshire -UKF2,UKF,"Leicestershire, Rutland and Northamptonshire" -UKF3,UKF,Lincolnshire -UKG1,UKG,"Herefordshire, Worcestershire and Warwickshire" -UKG2,UKG,Shropshire and Staffordshire -UKG3,UKG,West Midlands -UKH1,UKH,East Anglia -UKH2,UKH,Bedfordshire and Hertfordshire -UKH3,UKH,Essex -UKI3,UKI,Inner London - West -UKI4,UKI,Inner London - East -UKI5,UKI,Outer London - East and North East -UKI6,UKI,Outer London - South -UKI7,UKI,Outer London - West and North West -UKJ1,UKJ,"Berkshire, Buckinghamshire and Oxfordshire" -UKJ2,UKJ,"Surrey, East and West Sussex" -UKJ3,UKJ,Hampshire and Isle of Wight -UKJ4,UKJ,Kent -UKK1,UKK,"Gloucestershire, Wiltshire and Bristol/Bath area" -UKK2,UKK,Dorset and Somerset -UKK3,UKK,Cornwall and Isles of Scilly -UKK4,UKK,Devon -UKL1,UKL,West Wales and The Valleys -UKL2,UKL,East Wales -UKM2,UKM,Eastern Scotland -UKM3,UKM,South Western Scotland -UKM5,UKM,North Eastern Scotland -UKM6,UKM,Highlands and Islands -UKN0,UKN,Northern Ireland diff --git a/data/nuts3_regions.csv b/data/nuts3_regions.csv deleted file mode 100644 index 53a81f1520..0000000000 --- a/data/nuts3_regions.csv +++ /dev/null @@ -1,174 +0,0 @@ -code,nuts2_code,name -UKC11,UKC1,Hartlepool and Stockton-on-Tees -UKC12,UKC1,South Teesside -UKC13,UKC1,Darlington -UKC14,UKC1,Durham CC -UKC21,UKC2,Northumberland -UKC22,UKC2,Tyneside -UKC23,UKC2,Sunderland -UKD11,UKD1,West Cumbria -UKD12,UKD1,East Cumbria -UKD33,UKD3,Manchester -UKD34,UKD3,Greater Manchester South West -UKD35,UKD3,Greater Manchester South East -UKD36,UKD3,Greater Manchester North West -UKD37,UKD3,Greater Manchester North East -UKD41,UKD4,Blackburn with Darwen -UKD42,UKD4,Blackpool -UKD44,UKD4,Lancaster and Wyre -UKD45,UKD4,Mid Lancashire -UKD46,UKD4,East Lancashire -UKD47,UKD4,Chorley and West Lancashire -UKD61,UKD6,Warrington -UKD62,UKD6,Cheshire East -UKD63,UKD6,Cheshire West and Chester -UKD71,UKD7,East Merseyside -UKD72,UKD7,Liverpool -UKD73,UKD7,Sefton -UKD74,UKD7,Wirral -UKE11,UKE1,"Kingston upon Hull, City of" -UKE12,UKE1,East Riding of Yorkshire -UKE13,UKE1,North and North East Lincolnshire -UKE21,UKE2,York -UKE22,UKE2,North Yorkshire CC -UKE31,UKE3,"Barnsley, Doncaster and Rotherham" -UKE32,UKE3,Sheffield -UKE41,UKE4,Bradford -UKE42,UKE4,Leeds -UKE44,UKE4,Calderdale and Kirklees -UKE45,UKE4,Wakefield -UKF11,UKF1,Derby -UKF12,UKF1,East Derbyshire -UKF13,UKF1,South and West Derbyshire -UKF14,UKF1,Nottingham -UKF15,UKF1,North Nottinghamshire -UKF16,UKF1,South Nottinghamshire -UKF21,UKF2,Leicester -UKF22,UKF2,Leicestershire CC and Rutland -UKF24,UKF2,West Northamptonshire -UKF25,UKF2,North Northamptonshire -UKF30,UKF3,Lincolnshire -UKG11,UKG1,"Herefordshire, County of" -UKG12,UKG1,Worcestershire -UKG13,UKG1,Warwickshire -UKG21,UKG2,Telford and Wrekin -UKG22,UKG2,Shropshire CC -UKG23,UKG2,Stoke-on-Trent -UKG24,UKG2,Staffordshire CC -UKG31,UKG3,Birmingham -UKG32,UKG3,Solihull -UKG33,UKG3,Coventry -UKG36,UKG3,Dudley -UKG37,UKG3,Sandwell -UKG38,UKG3,Walsall -UKG39,UKG3,Wolverhampton -UKH11,UKH1,Peterborough -UKH12,UKH1,Cambridgeshire CC -UKH14,UKH1,Suffolk -UKH15,UKH1,Norwich and East Norfolk -UKH16,UKH1,North and West Norfolk -UKH17,UKH1,Breckland and South Norfolk -UKH21,UKH2,Luton -UKH23,UKH2,Hertfordshire -UKH24,UKH2,Bedford -UKH25,UKH2,Central Bedfordshire -UKH31,UKH3,Southend-on-Sea -UKH32,UKH3,Thurrock -UKH34,UKH3,Essex Haven Gateway -UKH35,UKH3,West Essex -UKH36,UKH3,Heart of Essex -UKH37,UKH3,Essex Thames Gateway -UKI31,UKI3,Camden and City of London -UKI32,UKI3,Westminster -UKI33,UKI3,Kensington & Chelsea and Hammersmith & Fulham -UKI34,UKI3,Wandsworth -UKI41,UKI4,Hackney and Newham -UKI42,UKI4,Tower Hamlets -UKI43,UKI4,Haringey and Islington -UKI44,UKI4,Lewisham and Southwark -UKI45,UKI4,Lambeth -UKI51,UKI5,Bexley and Greenwich -UKI52,UKI5,Barking & Dagenham and Havering -UKI53,UKI5,Redbridge and Waltham Forest -UKI54,UKI5,Enfield -UKI61,UKI6,Bromley -UKI62,UKI6,Croydon -UKI63,UKI6,"Merton, Kingston upon Thames and Sutton" -UKI71,UKI7,Barnet -UKI72,UKI7,Brent -UKI73,UKI7,Ealing -UKI74,UKI7,Harrow and Hillingdon -UKI75,UKI7,Hounslow and Richmond upon Thames -UKJ11,UKJ1,Berkshire -UKJ12,UKJ1,Milton Keynes -UKJ13,UKJ1,Buckinghamshire CC -UKJ14,UKJ1,Oxfordshire -UKJ21,UKJ2,Brighton and Hove -UKJ22,UKJ2,East Sussex CC -UKJ25,UKJ2,West Surrey -UKJ26,UKJ2,East Surrey -UKJ27,UKJ2,West Sussex (South West) -UKJ28,UKJ2,West Sussex (North East) -UKJ31,UKJ3,Portsmouth -UKJ32,UKJ3,Southampton -UKJ34,UKJ3,Isle of Wight -UKJ35,UKJ3,South Hampshire -UKJ36,UKJ3,Central Hampshire -UKJ37,UKJ3,North Hampshire -UKJ41,UKJ4,Medway -UKJ43,UKJ4,Kent Thames Gateway -UKJ44,UKJ4,East Kent -UKJ45,UKJ4,Mid Kent -UKJ46,UKJ4,West Kent -UKK11,UKK1,"Bristol, City of" -UKK12,UKK1,"Bath and North East Somerset, North Somerset and South Gloucestershire" -UKK13,UKK1,Gloucestershire -UKK14,UKK1,Swindon -UKK15,UKK1,Wiltshire -UKK21,UKK2,Bournemouth and Poole -UKK22,UKK2,Dorset CC -UKK23,UKK2,Somerset -UKK30,UKK3,Cornwall and Isles of Scilly -UKK41,UKK4,Plymouth -UKK42,UKK4,Torbay -UKK43,UKK4,Devon CC -UKL11,UKL1,Isle of Anglesey -UKL12,UKL1,Gwynedd -UKL13,UKL1,Conwy and Denbighshire -UKL14,UKL1,South West Wales -UKL15,UKL1,Central Valleys -UKL16,UKL1,Gwent Valleys -UKL17,UKL1,Bridgend and Neath Port Talbot -UKL18,UKL1,Swansea -UKL21,UKL2,Monmouthshire and Newport -UKL22,UKL2,Cardiff and Vale of Glamorgan -UKL23,UKL2,Flintshire and Wrexham -UKL24,UKL2,Powys -UKM21,UKM2,Angus and Dundee City -UKM22,UKM2,Clackmannanshire and Fife -UKM23,UKM2,East Lothian and Midlothian -UKM24,UKM2,Scottish Borders -UKM25,UKM2,Edinburgh -UKM26,UKM2,Falkirk -UKM27,UKM2,Perth & Kinross and Stirling -UKM28,UKM2,West Lothian -UKM31,UKM3,"East Dunbartonshire, West Dunbartonshire and Helensburgh & Lomond" -UKM32,UKM3,Dumfries & Galloway -UKM33,UKM3,East Ayrshire and North Ayrshire mainland -UKM34,UKM3,Glasgow -UKM35,UKM3,"Inverclyde, East Renfrewshire and Renfrewshire" -UKM36,UKM3,North Lanarkshire -UKM37,UKM3,South Ayrshire -UKM38,UKM3,South Lanarkshire -UKM50,UKM5,Aberdeen and Aberdeenshire -UKM61,UKM6,Caithness & Sutherland and Ross & Cromarty -UKM62,UKM6,"Inverness & Nairn and Moray, Badenoch & Strathspey" -UKM63,UKM6,"Lochaber, Skye & Lochalsh, Arran & Cumbrae and Argyll & Bute" -UKM64,UKM6,Eilean Siar (Western Isles) -UKM65,UKM6,Orkney Islands -UKM66,UKM6,Shetland Islands -UKN01,UKN0,Belfast -UKN02,UKN0,Outer Belfast -UKN03,UKN0,East of Northern Ireland -UKN04,UKN0,North of Northern Ireland -UKN05,UKN0,West and South of Northern Ireland diff --git a/data/regions.csv b/data/regions.csv deleted file mode 100644 index ca46beb7e1..0000000000 --- a/data/regions.csv +++ /dev/null @@ -1,75 +0,0 @@ -code,name -UKC1,Tees Valley and Durham -UKC2,Northumberland and Tyne and Wear -UKD1,Cumbria -UKD3,Greater Manchester -UKD4,Lancashire -UKD6,Cheshire -UKD7,Merseyside -UKE1,East Yorkshire and Northern Lincolnshire -UKE2,North Yorkshire -UKE3,South Yorkshire -UKE4,West Yorkshire -UKF1,Derbyshire and Nottinghamshire -UKF2,"Leicestershire, Rutland and Northamptonshire" -UKF3,Lincolnshire -UKG1,"Herefordshire, Worcestershire and Warwickshire" -UKG2,Shropshire and Staffordshire -UKG3,West Midlands (county) -UKH1,East Anglia -UKH2,Bedfordshire and Hertfordshire -UKH3,Essex -UKI3,Inner London - West -UKI4,Inner London - East -UKI5,Outer London - East and North East -UKI6,Outer London - South -UKI7,Outer London - West and North West -UKJ1,"Berkshire, Buckinghamshire and Oxfordshire" -UKJ2,"Surrey, East and West Sussex" -UKJ3,Hampshire and Isle of Wight -UKJ4,Kent -UKK1,"Gloucestershire, Wiltshire and Bristol/Bath area" -UKK2,Dorset and Somerset -UKK3,Cornwall and Isles of Scilly -UKK4,Devon -UKL11,Isle of Anglesey -UKL12,Gwynedd -UKL13,Conwy and Denbighshire -UKL14,"South West Wales (Ceredigion, Carmarthenshire, Pembrokeshire)" -UKL15,"Central Valleys (Merthyr Tydfil, Rhondda Cynon Taff)" -UKL16,"Gwent Valleys (Blaenau Gwent, Caerphilly, Torfaen)" -UKL17,Bridgend and Neath Port Talbot -UKL18,Swansea -UKL21,Monmouthshire and Newport -UKL22,Cardiff and Vale of Glamorgan -UKL23,Flintshire and Wrexham -UKL24,Powys -UKM21,Angus and Dundee -UKM22,Clackmannanshire and Fife -UKM23,East Lothian and Midlothian -UKM24,Scottish Borders -UKM25,Edinburgh -UKM26,Falkirk -UKM27,"Perth and Kinross, and Stirling" -UKM28,West Lothian -UKM31,"East Dunbartonshire, West Dunbartonshire, and Helensburgh and Lomond" -UKM32,Dumfries and Galloway -UKM33,East and North Ayrshire mainland -UKM34,Glasgow -UKM35,"Inverclyde, East Renfrewshire, and Renfrewshire" -UKM36,North Lanarkshire -UKM37,South Ayrshire -UKM38,South Lanarkshire -UKM50,Aberdeen and Aberdeenshire -UKM61,"Caithness and Sutherland, and Ross and Cromarty" -UKM62,"Inverness, Nairn, Moray, and Badenoch and Strathspey" -UKM63,"Lochaber, Skye and Lochalsh, Arran and Cumbrae, and Argyll and Bute (except Helensburgh and Lomond)" -UKM64,Eilean Siar (Western Isles) -UKM65,Orkney Islands -UKM66,Shetland Islands -UKN01,Belfast -UKN02,"Outer Belfast (Carrickfergus, Castlereagh, Lisburn, Newtownabbey, North Down)" -UKN03,"East of Northern Ireland (Antrim, Ards, Ballymena, Banbridge, Craigavon, Down, Larne)" -UKN04,"North of Northern Ireland (Ballymoney, Coleraine, Derry, Limavady, Moyle, Strabane)" -UKN05,"West and South of Northern Ireland (Armagh, Cookstown, Dungannon, Fermanagh, Magherafelt, Newry and Mourne, Omagh)" -OS01,International coverage diff --git a/db/migrate/20240906101133_remove_nuts_tables.rb b/db/migrate/20240906101133_remove_nuts_tables.rb new file mode 100644 index 0000000000..9e24561beb --- /dev/null +++ b/db/migrate/20240906101133_remove_nuts_tables.rb @@ -0,0 +1,11 @@ +class RemoveNutsTables < ActiveRecord::Migration[7.1] + def change + drop_table 'nuts_regions', id: false, force: :cascade do |t| + t.string 'code', limit: 255 + t.string 'name', limit: 255 + t.string 'nuts1_code', limit: 255 + t.string 'nuts2_code', limit: 255 + t.index ['code'], name: 'nuts_regions_code_key', unique: true + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 773845ede2..2e8e1280f1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_07_04_110527) do +ActiveRecord::Schema[7.1].define(version: 2024_09_06_101133) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -152,14 +152,6 @@ t.datetime "updated_at", precision: nil, null: false end - create_table "nuts_regions", id: false, force: :cascade do |t| - t.string "code", limit: 255 - t.string "name", limit: 255 - t.string "nuts1_code", limit: 255 - t.string "nuts2_code", limit: 255 - t.index ["code"], name: "nuts_regions_code_key", unique: true - end - create_table "supply_teachers_rm6238_admin_current_data", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.text "error" t.datetime "created_at", null: false diff --git a/lib/tasks/command.rake b/lib/tasks/command.rake index eddf089c68..f07ce4dbad 100644 --- a/lib/tasks/command.rake +++ b/lib/tasks/command.rake @@ -1,3 +1,5 @@ +require_relative 'distributed_locks' + module Command def self.run_rake_tasks # ENV['RAKE_TASK_LIST'] is a comma seperated lists of the rake tasks that need to be run e.g. db:static,further_competition:update_fc_data diff --git a/lib/tasks/frameworks.rake b/lib/tasks/frameworks.rake index 0e8aafb2f7..d7b61712f0 100644 --- a/lib/tasks/frameworks.rake +++ b/lib/tasks/frameworks.rake @@ -1,3 +1,5 @@ +require_relative 'distributed_locks' + module Frameworks def self.add_frameworks ActiveRecord::Base.connection.truncate_tables(:frameworks) diff --git a/lib/tasks/static.rake b/lib/tasks/static.rake deleted file mode 100644 index 21e84d6478..0000000000 --- a/lib/tasks/static.rake +++ /dev/null @@ -1,46 +0,0 @@ -module CCS - require 'pg' - require 'csv' - require 'json' - require Rails.root.join('lib', 'tasks', 'distributed_locks') - - def self.csv_to_nuts_regions(file_name) - ActiveRecord::Base.connection_pool.with_connection do |db| - db.exec_query('create table IF NOT EXISTS nuts_regions (code varchar(255) UNIQUE, name varchar(255), - nuts1_code varchar(255), nuts2_code varchar(255) );') - CSV.read(file_name, headers: true).each do |row| - column_names = row.headers.map { |i| "\"#{i}\"" }.join(',') - values = row.fields.map { |i| "'#{i}'" }.join(',') - db.exec_query("DELETE FROM nuts_regions where code = '#{row['code']}' ; ") - db.exec_query("insert into nuts_regions ( #{column_names}) values (#{values})") - end - end - rescue PG::Error => e - puts e.message - end - - def self.load_nuts_data(directory) - DistributedLocks.distributed_lock(150) do - puts "Loading NUTS static data, Environment: #{Rails.env}" - CCS.csv_to_nuts_regions "#{directory}nuts1_regions.csv" - CCS.csv_to_nuts_regions "#{directory}nuts2_regions.csv" - CCS.csv_to_nuts_regions "#{directory}nuts3_regions.csv" - puts "Finished loading NUTS codes into db #{Rails.application.config.database_configuration[Rails.env]['database']}" - end - end - - def self.load_static(directory = 'data/') - CCS.load_nuts_data directory - end -end - -namespace :db do - desc 'add NUTS static data to the database' - task static: :environment do - puts 'Loading NUTS static' - CCS.load_static - end - - desc 'add static data to the database' - task setup: :static -end diff --git a/spec/models/nuts1_region_spec.rb b/spec/models/nuts1_region_spec.rb deleted file mode 100644 index c5bc6ea4e4..0000000000 --- a/spec/models/nuts1_region_spec.rb +++ /dev/null @@ -1,21 +0,0 @@ -require 'rails_helper' - -RSpec.describe Nuts1Region do - subject(:region) { described_class.find_by(code: 'UKM') } - - let(:all_codes) { described_class.all.map(&:code) } - - it 'has a code and a name' do - expect(region) - .to have_attributes(code: 'UKM', name: 'Scotland') - end - - it 'only has unique codes' do - expect(all_codes.uniq).to match_array(all_codes) - end - - it 'has many NUTS 2 regions' do - expect(region.nuts2_regions) - .to have_attributes(length: 4) - end -end diff --git a/spec/models/nuts2_region_spec.rb b/spec/models/nuts2_region_spec.rb deleted file mode 100644 index 0a6ee9bd2b..0000000000 --- a/spec/models/nuts2_region_spec.rb +++ /dev/null @@ -1,36 +0,0 @@ -require 'rails_helper' - -RSpec.describe Nuts2Region do - subject(:region) { described_class.find_by(code: 'UKM6') } - - let(:all_codes) { described_class.all_codes } - - it 'has a code and a name' do - expect(region) - .to have_attributes(code: 'UKM6', name: 'Highlands and Islands') - end - - it 'only has unique codes' do - expect(all_codes.uniq).to match_array(all_codes) - end - - it 'belongs to a NUTS 1 region' do - expect(region.nuts1_region) - .to have_attributes(code: 'UKM', name: 'Scotland') - end - - it 'has many NUTS 3 regions' do - expect(region.nuts3_regions) - .to have_attributes(length: 6) - end - - describe '.all_codes' do - let(:regions) { described_class.all } - let(:first_region) { regions.first } - - it 'returns codes for all regions' do - expect(all_codes.count).to eq(regions.count) - expect(all_codes.first).to eq(first_region.code) - end - end -end diff --git a/spec/models/nuts3_region_spec.rb b/spec/models/nuts3_region_spec.rb deleted file mode 100644 index 4c80e7a29a..0000000000 --- a/spec/models/nuts3_region_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'rails_helper' - -RSpec.describe Nuts3Region do - subject(:region) { described_class.find_by(code: 'UKL12') } - - let(:all_codes) { described_class.all.map(&:code) } - - it 'has a code and a name' do - expect(region) - .to have_attributes(code: 'UKL12', name: 'Gwynedd') - end - - it 'only has unique codes' do - expect(all_codes.uniq).to match_array(all_codes) - end - - it 'belongs to a NUTS 2 region' do - expect(region.nuts2_region) - .to have_attributes(code: 'UKL1', name: 'West Wales and The Valleys') - end - - it 'belongs to a NUTS 1 region' do - expect(region.nuts1_region) - .to have_attributes(code: 'UKL', name: 'Wales') - end -end diff --git a/spec/services/static_data_loader_spec.rb b/spec/services/static_data_loader_spec.rb deleted file mode 100644 index 393f4783a8..0000000000 --- a/spec/services/static_data_loader_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -require 'rails_helper' - -RSpec.describe StaticDataLoader do - describe '.nuts1_codes_not_empty' do - it 'there is at least one Nuts1 Region' do - described_class.load_static_data(Nuts1Region) - expect(Nuts1Region.count.zero?).to be(false) - end - end - - describe '.nuts2_codes_not_empty' do - it 'there is at least 1 Nuts2 Regions' do - described_class.load_static_data(Nuts2Region) - expect(Nuts2Region.count.zero?).to be(false) - end - end - - describe '.nuts3_codes_not_empty' do - it 'there is at least 1 Nuts3 Region' do - described_class.load_static_data(Nuts3Region) - expect(Nuts3Region.count.zero?).to be(false) - end - end -end