add serving logic
This commit is contained in:
parent
c4ef70d0e8
commit
521c62d09b
@ -90,8 +90,12 @@ class Recipe < Ingredient
|
||||
def yields_list
|
||||
@yields_list ||= self.yields.to_s.split(',').concat(['1 each']).map { |y| y.strip }.select { |y| y.present? }.map do |y|
|
||||
begin
|
||||
UnitConversion::parse(y)
|
||||
rescue UntConversion::UnparseableUnitError
|
||||
vu = UnitConversion::parse(y)
|
||||
if vu.unit.nil?
|
||||
vu = UnitConversion::ValueUnit.for(vu.value, 'servings')
|
||||
end
|
||||
vu
|
||||
rescue UnitConversion::UnparseableUnitError
|
||||
nil
|
||||
end
|
||||
end.compact
|
||||
|
@ -14,6 +14,7 @@ services:
|
||||
environment:
|
||||
- RAILS_USE_MEMCACHE=true
|
||||
- PASSENGER_APP_ENV=production
|
||||
- RAILS_ENV=production
|
||||
env_file: /etc/default/parsley
|
||||
volumes:
|
||||
- /var/log/parsley/:/home/app/parsley/log
|
||||
|
@ -46,6 +46,16 @@ RSpec.describe Recipe, type: :model do
|
||||
|
||||
expect(l1.first).not_to equal(l2.first)
|
||||
end
|
||||
|
||||
it 'converts a bare value into a servings unit' do
|
||||
r = create(:recipe, yields: '3')
|
||||
l = r.yields_list
|
||||
expect(l.length).to eq 2
|
||||
s = l.detect { |y| y.unit.unit == 'servings' }
|
||||
expect(s).to be_a UnitConversion::ValueUnit
|
||||
expect(s.raw_value).to eq 3
|
||||
expect(s.unit.unit).to eq 'servings'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#custom_units' do
|
||||
|
Loading…
Reference in New Issue
Block a user