Skip to content
This repository has been archived by the owner on Mar 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #679 from AndyGauge/rescue-date
Browse files Browse the repository at this point in the history
Invalid birthdates should be set to nil rather than raise exceptions
  • Loading branch information
seven1m committed Jul 9, 2017
2 parents 1b73d1b + b4045e2 commit 1fe2d9c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 7 additions & 0 deletions app/models/concerns/import/attributes.rb
Expand Up @@ -9,6 +9,9 @@ def attributes_for_person(row)
attrs = attributes(row).reject { |a| a =~ /^family_|^id$|^field\d+/ }
attrs.reverse_merge!('status' => 'active') if @import.create_as_active # TODO: allow creating as pending
attrs['fields'] = custom_field_values_for_person(row)
%w{birthday anniversary}.each do |key|
attrs[key] = filter_date_formatting_errors(attrs[key]) if attrs.key? key
end
attrs
end

Expand Down Expand Up @@ -43,6 +46,10 @@ def legacy_id_for_family(row)
def attributes(row)
row.import_attributes_as_hash(real_attributes: true)
end

def filter_date_formatting_errors(date)
date.digits_only && date
end
end
end
end
25 changes: 24 additions & 1 deletion spec/models/import_execution_spec.rb
Expand Up @@ -21,7 +21,8 @@
'state' => 'family_state',
'zip' => 'family_zip',
'email' => 'email',
'rel' => 'relationships'
'rel' => 'relationships',
'birthday' => 'birthday'
}
)
end
Expand Down Expand Up @@ -811,6 +812,28 @@ def create_row(attrs, status: :previewed)
expect(row.family).to eq(family)
end
end

context 'given a row with a birthday that cannot be parsed' do
let(:family) { FactoryGirl.create(:family, name: "John Jones") }
let!(:row) { create_row(first: 'Jimmy', last: 'Jones', fam_name: family.name, birthday: '/ /') }

before { subject.execute }

it 'creates the person' do
expect(row.reload.attributes).to include(
'created_person' => true,
'created_family' => false,
'updated_person' => false,
'errored' => false
)
end

it 'sets the birthday to blank' do
expect(subject.attributes_for_person(row)).to include(
'birthday' => nil
)
end
end
end
end
end

0 comments on commit 1fe2d9c

Please sign in to comment.