Browse Source

fix field_4 validation for bulk upload

- the null check was inverted by mistake
pull/1148/head
Phil Lee 3 years ago
parent
commit
e06cee3fd7
  1. 3
      app/services/bulk_upload/lettings/row_parser.rb
  2. 14
      spec/services/bulk_upload/lettings/row_parser_spec.rb

3
app/services/bulk_upload/lettings/row_parser.rb

@ -140,7 +140,8 @@ class BulkUpload::Lettings::RowParser
attribute :field_134, :integer
validates :field_1, presence: true, inclusion: { in: (1..12).to_a }
validates :field_4, presence: { if: proc { [1, 3, 5, 7, 9, 11].include?(field_1) } }
validates :field_4, presence: { if: proc { [2, 4, 6, 8, 10, 12].include?(field_1) } }
validates :field_96, presence: true
validates :field_97, presence: true
validates :field_98, presence: true

14
spec/services/bulk_upload/lettings/row_parser_spec.rb

@ -13,7 +13,7 @@ RSpec.describe BulkUpload::Lettings::RowParser do
let(:setup_section_params) do
{
bulk_upload:,
field_1: "1",
field_1: "2",
field_111: owning_org.old_visible_id,
field_113: managing_org.old_visible_id,
field_96: now.day.to_s,
@ -205,19 +205,19 @@ RSpec.describe BulkUpload::Lettings::RowParser do
end
describe "#field_4" do
context "when nullable permitted" do
context "when nullable not permitted" do
let(:attributes) { { bulk_upload:, field_1: "2", field_4: nil } }
it "can be nulled" do
expect(parser.errors[:field_4]).to be_blank
it "cannot be nulled" do
expect(parser.errors[:field_4]).to be_present
end
end
context "when nullable not permitted" do
context "when nullable permitted" do
let(:attributes) { { bulk_upload:, field_1: "1", field_4: nil } }
it "cannot be nulled" do
expect(parser.errors[:field_4]).to be_present
it "can be nulled" do
expect(parser.errors[:field_4]).to be_blank
end
end

Loading…
Cancel
Save