Browse Source

convert field_mapping to array of hashes

pull/1148/head
Phil Lee 3 years ago
parent
commit
466e60216c
  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
def field_for_attribute(attribute)
field_mapping.invert[attribute]
field_mapping.find { |h| h[:attribute] == attribute }[:name]
end
def field_mapping
{
field_1: :lettype,
field_134: :renewal,
}
[
{ name: :field_1, attribute: :lettype },
{ name: :field_7, attribute: :tenancycode },
{ name: :field_134, attribute: :renewal },
]
end
def attributes_for_log
hash = field_mapping.invert
attributes = {}
hash.map do |k, v|
attributes[k] = public_send(v)
field_mapping.map do |h|
attributes[h[:attribute]] = public_send(h[:name])
end
hash[:scheme] = scheme
attributes[:scheme] = scheme
attributes
end

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

@ -88,6 +88,16 @@ RSpec.describe BulkUpload::Lettings::RowParser do
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
context "when an unpermitted value" do
let(:attributes) { { field_134: 3 } }

Loading…
Cancel
Save