Browse Source

add validation for field_4

pull/1148/head
Phil Lee 3 years ago
parent
commit
4cd4fc44f3
  1. 2
      app/services/bulk_upload/lettings/row_parser.rb
  2. 18
      spec/services/bulk_upload/lettings/row_parser_spec.rb

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

@ -138,6 +138,7 @@ 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) } }
def attribute_set
@attribute_set ||= instance_variable_get(:@attributes)
@ -158,7 +159,6 @@ class BulkUpload::Lettings::RowParser
log.valid?
log.errors.each do |error|
field = field_for_attribute(error.attribute)
errors.add(field, error.type)

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

@ -54,6 +54,24 @@ RSpec.describe BulkUpload::Lettings::RowParser do
end
end
describe "#field_4" do
context "when nullable permitted" do
let(:attributes) { { field_1: "2", field_4: nil } }
it "can be nulled" do
expect(parser.errors[:field_4]).to be_blank
end
end
context "when nullable not permitted" do
let(:attributes) { { field_1: "1", field_4: nil } }
it "cannot be nulled" do
expect(parser.errors[:field_4]).to be_present
end
end
end
describe "#field_134" do
context "when an unpermitted value" do
let(:attributes) { { field_134: 3 } }

Loading…
Cancel
Save