Browse Source

Only display errors on selected housing needs

pull/1501/head
Kat 3 years ago
parent
commit
cfe52d9523
  1. 6
      app/services/bulk_upload/lettings/year2022/row_parser.rb
  2. 34
      spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb

6
app/services/bulk_upload/lettings/year2022/row_parser.rb

@ -545,9 +545,9 @@ private
def validate_only_one_housing_needs_type def validate_only_one_housing_needs_type
if [field_55, field_56, field_57].count(1) > 1 if [field_55, field_56, field_57].count(1) > 1
errors.add(:field_55, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) errors.add(:field_55, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) if field_55 == 1
errors.add(:field_56, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) errors.add(:field_56, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) if field_56 == 1
errors.add(:field_57, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) errors.add(:field_57, I18n.t("validations.household.housingneeds_type.only_one_option_permitted")) if field_57 == 1
end end
end end

34
spec/services/bulk_upload/lettings/year2022/row_parser_spec.rb

@ -507,7 +507,6 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
it "is not permitted" do it "is not permitted" do
expect(parser.errors[:field_55]).to be_present expect(parser.errors[:field_55]).to be_present
expect(parser.errors[:field_56]).to be_present expect(parser.errors[:field_56]).to be_present
expect(parser.errors[:field_57]).to be_present
end end
end end
end end
@ -1430,6 +1429,39 @@ RSpec.describe BulkUpload::Lettings::Year2022::RowParser do
expect(parser.log.housingneeds_other).to eq(1) expect(parser.log.housingneeds_other).to eq(1)
end end
end end
context "when housingneeds a and b are selected" do
let(:attributes) { { bulk_upload:, field_55: "1", field_56: "1" } }
it "sets error on housingneeds a and b" do
parser.valid?
expect(parser.errors[:field_55]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_56]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_57]).to be_blank
end
end
context "when housingneeds a and c are selected" do
let(:attributes) { { bulk_upload:, field_55: "1", field_57: "1" } }
it "sets error on housingneeds a and c" do
parser.valid?
expect(parser.errors[:field_55]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_57]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_56]).to be_blank
end
end
context "when housingneeds b and c are selected" do
let(:attributes) { { bulk_upload:, field_56: "1", field_57: "1" } }
it "sets error on housingneeds b and c" do
parser.valid?
expect(parser.errors[:field_56]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_57]).to include("Only one disabled access need: fully wheelchair-accessible housing, wheelchair access to essential rooms or level access housing, can be selected")
expect(parser.errors[:field_55]).to be_blank
end
end
end end
describe "#housingneeds_type" do describe "#housingneeds_type" do

Loading…
Cancel
Save