diff --git a/spec/lib/pafs_core/data_migration/add_rfcc_codes_spec.rb b/spec/lib/pafs_core/data_migration/add_rfcc_codes_spec.rb new file mode 100644 index 00000000..20d18f24 --- /dev/null +++ b/spec/lib/pafs_core/data_migration/add_rfcc_codes_spec.rb @@ -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 diff --git a/spec/lib/pafs_core/data_migration/update_authorities_spec.rb b/spec/lib/pafs_core/data_migration/update_authorities_spec.rb new file mode 100644 index 00000000..d03420de --- /dev/null +++ b/spec/lib/pafs_core/data_migration/update_authorities_spec.rb @@ -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