parsley/spec/lib/usda_importer_spec.rb

48 lines
1.2 KiB
Ruby
Raw Normal View History

require 'rails_helper'
require 'usda_importer'
2024-09-28 11:50:07 -05:00
RSpec.describe UsdaImporter do
subject(:import) { UsdaImporter.new(Rails.root.join('spec', 'test_data')).import }
it 'imports the correct number of foods with weights' do
import
2018-09-14 19:32:49 -05:00
expect(UsdaFood.count).to eq 5
butter = UsdaFood.find_by(ndbn: '01001')
expect(butter).not_to be_nil
expect(butter.usda_food_weights.count).to eq 4
2018-09-14 19:32:49 -05:00
clif_bar = UsdaFood.find_by(ndbn: '45042066')
2018-09-14 19:32:49 -05:00
expect(clif_bar).not_to be_nil
expect(clif_bar.usda_food_weights.count).to eq 1
end
it 'imports SR28 nutrition fields correctly' do
import
butter = UsdaFood.find_by(ndbn: '01001')
expect(butter.kcal).to eq 717
expect(butter.protein).to eq 0.85
expect(butter.source).to eq 'sr'
end
it 'imports branded nutrition fields via map_function' do
import
clif_bar = UsdaFood.find_by(ndbn: '45042066')
2018-09-14 19:32:49 -05:00
expect(clif_bar.kcal).to eq 368
expect(clif_bar.protein).to eq 13.24
expect(clif_bar.source).to eq 'bf'
end
it 'updates linked Food records with usda nutrition data' do
food = create(:food, ndbn: '01001')
import
food.reload
expect(food.kcal).to eq 717
end
2022-12-01 18:02:26 -06:00
end