Browse Source

convert field_mapping to array of hashes

remotes/origin/bulk-upload-errors-integration
Phil Lee 3 years ago
parent
commit
a62cc6e96e
  1. 18
      app/services/bulk_upload/lettings/row_parser.rb
  2. 10
      spec/services/bulk_upload/lettings/row_parser_spec.rb

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

@ -176,25 +176,25 @@ private
end end
def field_for_attribute(attribute) def field_for_attribute(attribute)
field_mapping.invert[attribute] field_mapping.find { |h| h[:attribute] == attribute }[:name]
end end
def field_mapping def field_mapping
{ [
field_1: :lettype, { name: :field_1, attribute: :lettype },
field_134: :renewal, { name: :field_7, attribute: :tenancycode },
} { name: :field_134, attribute: :renewal },
]
end end
def attributes_for_log def attributes_for_log
hash = field_mapping.invert
attributes = {} attributes = {}
hash.map do |k, v| field_mapping.map do |h|
attributes[k] = public_send(v) attributes[h[:attribute]] = public_send(h[:name])
end end
hash[:scheme] = scheme attributes[:scheme] = scheme
attributes attributes
end end

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

@ -88,6 +88,16 @@ RSpec.describe BulkUpload::Lettings::RowParser do
end end
end end
describe "#field_7" do
context "when null" do
let(:attributes) { { field_7: nil } }
xit "returns an error" do
expect(parser.errors[:field_7]).to be_present
end
end
end
describe "#field_134" do describe "#field_134" do
context "when an unpermitted value" do context "when an unpermitted value" do
let(:attributes) { { field_134: 3 } } let(:attributes) { { field_134: 3 } }

Loading…
Cancel
Save