add serving logic
This commit is contained in:
parent
c4ef70d0e8
commit
521c62d09b
@ -90,8 +90,12 @@ class Recipe < Ingredient
|
|||||||
def yields_list
|
def yields_list
|
||||||
@yields_list ||= self.yields.to_s.split(',').concat(['1 each']).map { |y| y.strip }.select { |y| y.present? }.map do |y|
|
@yields_list ||= self.yields.to_s.split(',').concat(['1 each']).map { |y| y.strip }.select { |y| y.present? }.map do |y|
|
||||||
begin
|
begin
|
||||||
UnitConversion::parse(y)
|
vu = UnitConversion::parse(y)
|
||||||
rescue UntConversion::UnparseableUnitError
|
if vu.unit.nil?
|
||||||
|
vu = UnitConversion::ValueUnit.for(vu.value, 'servings')
|
||||||
|
end
|
||||||
|
vu
|
||||||
|
rescue UnitConversion::UnparseableUnitError
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
end.compact
|
end.compact
|
||||||
|
@ -14,6 +14,7 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- RAILS_USE_MEMCACHE=true
|
- RAILS_USE_MEMCACHE=true
|
||||||
- PASSENGER_APP_ENV=production
|
- PASSENGER_APP_ENV=production
|
||||||
|
- RAILS_ENV=production
|
||||||
env_file: /etc/default/parsley
|
env_file: /etc/default/parsley
|
||||||
volumes:
|
volumes:
|
||||||
- /var/log/parsley/:/home/app/parsley/log
|
- /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)
|
expect(l1.first).not_to equal(l2.first)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe '#custom_units' do
|
describe '#custom_units' do
|
||||||
|
Loading…
Reference in New Issue
Block a user