Browse Source

bulk upload setup error for location

pull/1399/head
Phil Lee 3 years ago
parent
commit
97b0d841d9
  1. 9
      app/services/bulk_upload/lettings/row_parser.rb
  2. 11
      spec/services/bulk_upload/lettings/row_parser_spec.rb

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

@ -186,6 +186,7 @@ class BulkUpload::Lettings::RowParser
validate :validate_location_related
validate :validate_location_exists
validate :validate_location_data_given
def valid?
errors.clear
@ -244,7 +245,13 @@ private
def validate_location_exists
if scheme && field_5.present? && location.nil?
errors.add(:field_5, "Location could be found with provided scheme code", category: :setup)
errors.add(:field_5, "Location could be found with provided scheme code")
end
end
def validate_location_data_given
if bulk_upload.supported_housing? && field_5.blank?
errors.add(:field_5, "The scheme code must be present", category: "setup")
end
end

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

@ -353,6 +353,17 @@ RSpec.describe BulkUpload::Lettings::RowParser do
end
describe "#field_5" do
context "when not nullable" do
let(:bulk_upload) { create(:bulk_upload, :lettings, user:, needstype: 2) }
let(:attributes) { { bulk_upload:, field_1: "2", field_5: nil } }
it "cannot be nulled" do
setup_errors = parser.errors.select { |e| e.options[:category] == "setup" }
expect(setup_errors.find { |e| e.attribute == :field_5 }).to be_present
end
end
context "when location does not exist" do
let(:scheme) { create(:scheme, :with_old_visible_id, owning_organisation: owning_org) }
let(:attributes) do

Loading…
Cancel
Save