From 7b659031a3133615c57e0378cd55295a6add7b2c Mon Sep 17 00:00:00 2001 From: Arthur Campbell Date: Tue, 16 May 2023 13:56:13 +0100 Subject: [PATCH] replicate the work from the last commit for the 2023 row parser and associated test file --- .../bulk_upload/sales/year2022/row_parser.rb | 2 +- .../bulk_upload/sales/year2023/row_parser.rb | 9 ++++++++- .../sales/year2022/row_parser_spec.rb | 8 -------- .../sales/year2023/row_parser_spec.rb | 19 +++++++++++-------- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/app/services/bulk_upload/sales/year2022/row_parser.rb b/app/services/bulk_upload/sales/year2022/row_parser.rb index e0fcc051c..6dfb6512d 100644 --- a/app/services/bulk_upload/sales/year2022/row_parser.rb +++ b/app/services/bulk_upload/sales/year2022/row_parser.rb @@ -813,7 +813,7 @@ private end def owning_organisation - Organisation.find_by_id_on_multiple_fields(field_92) + @owning_organisation ||= Organisation.find_by_id_on_multiple_fields(field_92) end def created_by diff --git a/app/services/bulk_upload/sales/year2023/row_parser.rb b/app/services/bulk_upload/sales/year2023/row_parser.rb index f9b690bbd..a13996cc7 100644 --- a/app/services/bulk_upload/sales/year2023/row_parser.rb +++ b/app/services/bulk_upload/sales/year2023/row_parser.rb @@ -396,6 +396,7 @@ class BulkUpload::Sales::Year2023::RowParser }, on: :after_log + validate :validate_buyer1_economic_status, on: :before_log validate :validate_nulls, on: :after_log validate :validate_valid_radio_option, on: :before_log @@ -1031,7 +1032,7 @@ private end def owning_organisation - Organisation.find_by_id_on_multiple_fields(field_1) + @owning_organisation ||= Organisation.find_by_id_on_multiple_fields(field_1) end def created_by @@ -1231,4 +1232,10 @@ private end end end + + def validate_buyer1_economic_status + if field_35 == 9 + errors.add(:field_35, "Buyer 1 cannot be a child under 16") + end + end end diff --git a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb index 2d35fca5d..7a42e5ee6 100644 --- a/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2022/row_parser_spec.rb @@ -107,14 +107,6 @@ RSpec.describe BulkUpload::Sales::Year2022::RowParser do } end - # around do |example| - # FormHandler.instance.use_real_forms! - - # example.run - - # FormHandler.instance.use_fake_forms! - # end - describe "#blank_row?" do context "when a new object" do it "returns true" do diff --git a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb index 4cfbf9b83..ba791e3f4 100644 --- a/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/sales/year2023/row_parser_spec.rb @@ -110,14 +110,6 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do } end - around do |example| - FormHandler.instance.use_real_forms! - - example.run - - FormHandler.instance.use_fake_forms! - end - describe "#blank_row?" do context "when a new object" do it "returns true" do @@ -694,6 +686,17 @@ RSpec.describe BulkUpload::Sales::Year2023::RowParser do end end + describe "field_35" do # ecstat1 + context "when buyer 1 is marked as a child" do + let(:attributes) { valid_attributes.merge({ field_35: "9" }) } + + it "a custom validation is applied" do + validation_message = "Buyer 1 cannot be a child under 16" + expect(parser.errors[:field_35]).to include validation_message + end + end + end + describe "#field_36" do # will buyer1 live in property? context "when not a possible value" do let(:attributes) { valid_attributes.merge({ field_36: "3" }) }