All checks were successful
parsley/pipeline/head This commit looks good
- Remove duplicate Save buttons in log creator/editor (fired with null data before recipe loaded) - Redirect to new resource after creating recipe/log instead of dropping back to list - Fix TheFoodCreator Cancel linking to dead route /food → /foods - Refactor AppSearchText to use defineModel; fix search box not initializing from URL - Fix TheCalculator variable shadowing bug (ingredient ref never updated on food select) - Refactor UsdaImporter to use insert_all! instead of per-record save! (~240k branded foods) - Fix string-based ndbn min comparison in build_enumerator (fragile on non-padded IDs) - Add CLAUDE.md with project overview and architecture notes Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
48 lines
1.2 KiB
Ruby
48 lines
1.2 KiB
Ruby
require 'rails_helper'
|
|
require 'usda_importer'
|
|
|
|
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
|
|
|
|
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
|
|
|
|
clif_bar = UsdaFood.find_by(ndbn: '45042066')
|
|
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')
|
|
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
|
|
|
|
end
|