Browse Source

bulk upload setup error for scheme

pull/1399/head
Phil Lee 3 years ago
parent
commit
18c890d8cf
  1. 9
      app/services/bulk_upload/lettings/row_parser.rb
  2. 5
      spec/services/bulk_upload/lettings/row_parser_spec.rb

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

@ -182,6 +182,7 @@ class BulkUpload::Lettings::RowParser
validate :validate_scheme_related validate :validate_scheme_related
validate :validate_scheme_exists validate :validate_scheme_exists
validate :validate_scheme_data_given
validate :validate_location_related validate :validate_location_related
validate :validate_location_exists validate :validate_location_exists
@ -261,7 +262,13 @@ private
def validate_scheme_exists def validate_scheme_exists
if field_4.present? && scheme.nil? if field_4.present? && scheme.nil?
errors.add(:field_4, "The management group code is not correct", category: :setup) errors.add(:field_4, "The management group code is not correct")
end
end
def validate_scheme_data_given
if bulk_upload.supported_housing? && field_4.blank?
errors.add(:field_4, "The management group code is not correct", category: "setup")
end end
end end

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

@ -298,10 +298,13 @@ RSpec.describe BulkUpload::Lettings::RowParser do
describe "#field_4" do describe "#field_4" do
context "when nullable not permitted" do context "when nullable not permitted" do
let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: 2) }
let(:attributes) { { bulk_upload:, field_1: "2", field_4: nil } } let(:attributes) { { bulk_upload:, field_1: "2", field_4: nil } }
it "cannot be nulled" do it "cannot be nulled" do
expect(parser.errors[:field_4]).to be_present setup_errors = parser.errors.select { |e| e.options[:category] == "setup" }
expect(setup_errors.find { |e| e.attribute == :field_4 }).to be_present
end end
end end

Loading…
Cancel
Save