From d42a37c08e6d7c09abe852ee4fb45bca23c1eac7 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Fri, 24 Mar 2023 18:25:15 +0000 Subject: [PATCH] permit at least one housing need (#1470) --- .../bulk_upload/lettings/year2022/row_parser.rb | 2 +- .../bulk_upload/lettings/year2023/row_parser.rb | 2 +- .../bulk_upload/lettings/year2022/row_parser_spec.rb | 10 ++++++++++ .../bulk_upload/lettings/year2023/row_parser_spec.rb | 10 ++++++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/services/bulk_upload/lettings/year2022/row_parser.rb b/app/services/bulk_upload/lettings/year2022/row_parser.rb index d9cc99505..34b65700e 100644 --- a/app/services/bulk_upload/lettings/year2022/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2022/row_parser.rb @@ -520,7 +520,7 @@ private end def validate_only_one_housing_needs_type - if [field_55, field_56, field_57].compact.count.positive? + if [field_55, field_56, field_57].compact.count > 1 errors.add(:field_55, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) errors.add(:field_56, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) errors.add(:field_57, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) diff --git a/app/services/bulk_upload/lettings/year2023/row_parser.rb b/app/services/bulk_upload/lettings/year2023/row_parser.rb index dc2a04a66..3c214a204 100644 --- a/app/services/bulk_upload/lettings/year2023/row_parser.rb +++ b/app/services/bulk_upload/lettings/year2023/row_parser.rb @@ -419,7 +419,7 @@ private end def validate_only_one_housing_needs_type - if [field_83, field_84, field_85].compact.count.positive? + if [field_83, field_84, field_85].compact.count > 1 errors.add(:field_83, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) errors.add(:field_84, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) errors.add(:field_85, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) diff --git a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb index 6355bb3bd..29c48006e 100644 --- a/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb @@ -475,6 +475,16 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do end describe "#field_55, #field_56, #field_57" do + context "when one item selected" do + let(:attributes) { { bulk_upload:, field_55: "1" } } + + it "is permitted" do + expect(parser.errors[:field_55]).to be_blank + expect(parser.errors[:field_56]).to be_blank + expect(parser.errors[:field_57]).to be_blank + end + end + context "when more than one item selected" do let(:attributes) { { bulk_upload:, field_55: "1", field_56: "1" } } diff --git a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb index 4d745f21e..1bb4dc99a 100644 --- a/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb +++ b/spec/services/bulk_upload/lettings/year2023/row_parser_spec.rb @@ -438,6 +438,16 @@ RSpec.describe BulkUpload::Lettings::Year2023::RowParser do end describe "#field_83, #field_84, #field_85" do + context "when one item selected" do + let(:attributes) { { bulk_upload:, field_83: "1" } } + + it "is permitted" do + expect(parser.errors[:field_83]).to be_blank + expect(parser.errors[:field_84]).to be_blank + expect(parser.errors[:field_85]).to be_blank + end + end + context "when more than one item selected" do let(:attributes) { { bulk_upload:, field_83: "1", field_84: "1" } }