Skip to content

Commit

Permalink
modify sidekiq job and tests for string zip codes (#12979)
Browse files Browse the repository at this point in the history
* modify sidekiq job and tests for string zip codes

* lint

* remove test skips

* test update

* update zip job
  • Loading branch information
jtmst authored Jun 15, 2023
1 parent 1deb266 commit 5cb9a05
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
36 changes: 19 additions & 17 deletions app/workers/income_limits/std_zipcode_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,25 @@ def perform
CSV.parse(data, headers: true) do |row|
created = DateTime.strptime(row['CREATED'], '%m/%d/%Y %l:%M:%S.%N %p').to_s
updated = DateTime.strptime(row['UPDATED'], '%m/%d/%Y %l:%M:%S.%N %p').to_s if row['UPDATED']
std_zipcode = StdZipcode.find_or_initialize_by(id: row['ID'].to_i)
next unless std_zipcode.new_record?

std_zipcode.assign_attributes(
id: row['ID'].to_i,
zip_code: row['ZIPCODE'].to_i,
zip_classification_id: row['ZIPCLASSIFICATION_ID']&.to_i,
preferred_zip_place_id: row['PREFERREDZIPPLACE_ID']&.to_i,
state_id: row['STATE_ID'].to_i,
county_number: row['COUNTYNUMBER'].to_i,
version: row['VERSION'].to_i,
created:,
updated:,
created_by: row['CREATEDBY'],
updated_by: row['UPDATEDBY']
)
std_zipcode.save!
std_zipcode = StdZipcode.find_by(id: row['ID'].to_i)
if std_zipcode
std_zipcode.update(zip_code: row['ZIPCODE'].to_s) if std_zipcode.zip_code != row['ZIPCODE'].to_s
else
std_zipcode = StdZipcode.find_or_initialize_by(zip_code: row['ZIPCODE'].to_s)
std_zipcode.assign_attributes(
id: row['ID'].to_i,
zip_classification_id: row['ZIPCLASSIFICATION_ID']&.to_i,
preferred_zip_place_id: row['PREFERREDZIPPLACE_ID']&.to_i,
state_id: row['STATE_ID'].to_i,
county_number: row['COUNTYNUMBER'].to_i,
version: row['VERSION'].to_i,
created:,
updated:,
created_by: row['CREATEDBY'],
updated_by: row['UPDATEDBY']
)
std_zipcode.save!
end
end
else
raise 'Failed to fetch CSV data'
Expand Down
6 changes: 2 additions & 4 deletions spec/jobs/income_limits/std_zipcode_import_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
end

it 'populates zipcodes' do
skip 'For migration'
IncomeLimits::StdZipcodeImport.new.perform
expect(StdZipcode.find_by(zip_code: 12_345)).not_to be_nil
expect(StdZipcode.find_by(zip_code: '12345')).not_to be_nil
expect(StdZipcode.find_by(county_number: 123)).not_to be_nil
end

Expand All @@ -30,10 +29,9 @@
end

it 'sets the attributes correctly' do
skip 'For migration'
described_class.new.perform
zipcode = StdZipcode.last
expect(zipcode.zip_code).to eq(12_345)
expect(zipcode.zip_code).to eq('12345')
expect(zipcode.zip_classification_id).to eq(1)
expect(zipcode.preferred_zip_place_id).to eq(2)
expect(zipcode.state_id).to eq(3)
Expand Down

0 comments on commit 5cb9a05

Please sign in to comment.