parsley/spec/models/nutrition_data_spec.rb

60 lines
1.2 KiB
Ruby
Raw Normal View History

2018-09-11 10:38:07 -05:00
require 'rails_helper'
RSpec.describe NutritionData, type: :model do
let(:rec1_ingredients) do
[
RecipeIngredient.new({
quantity: '100',
units: 'g',
sort_order: 1,
food: create(:food, kcal: 10, protein: 2)
}),
RecipeIngredient.new({
quantity: '100',
units: 'g',
sort_order: 2,
food: create(:food, kcal: 10, lipids: 2)
})
]
end
let(:recipe1) do
create(:recipe, yields: '500 g').tap do |r|
r.recipe_ingredients = rec1_ingredients
end
end
let(:rec2_ingredients) do
[
RecipeIngredient.new({
2018-09-11 22:56:26 -05:00
quantity: '250',
2018-09-11 10:38:07 -05:00
units: 'g',
sort_order: 1,
recipe_as_ingredient: recipe1
}),
RecipeIngredient.new({
quantity: '100',
units: 'g',
sort_order: 2,
food: create(:food, kcal: 10, lipids: 2)
})
]
end
let(:recipe2) do
create(:recipe, yields: '500 g').tap do |r|
r.recipe_ingredients = rec2_ingredients
end
end
2018-09-11 22:56:26 -05:00
it 'runs and calculates properly' do
2018-09-11 10:38:07 -05:00
n = recipe2.nutrition_data
2018-09-11 22:56:26 -05:00
expect(n.kcal).to eq 20
expect(n.protein).to eq 1
expect(n.lipids).to eq 3
2018-09-11 10:38:07 -05:00
end
end