parsley/db/seeds.rb

95 lines
4.4 KiB
Ruby
Raw Normal View History

2016-01-12 18:43:00 -06:00
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
2016-01-14 15:22:15 -06:00
2016-01-24 17:10:43 -06:00
require 'usda_importer'
2016-01-14 15:22:15 -06:00
puts "Seeding..."
2016-04-03 18:03:51 -05:00
dan = User.create!({username: 'dan', full_name: 'Dan', email: 'dan.elbert@gmail.com', password: 'qwerty', password_confirmation: 'qwerty'})
2018-09-12 17:17:15 -05:00
foods = {
2016-04-03 18:03:51 -05:00
water: {name: 'Water', density: '1 g/ml'},
butter: {name: 'Butter, Salted', ndbn: '01001'},
butter_sal: {name: 'Butter, Unsalted', density: '226 gram/cup'},
flour: {name: 'Flour, Bleached All Purpose', density: '130 gram/cup'},
flour_cake: {name: 'Flour, Cake', density: '120 gram/cup'},
flour_wheat: {name: 'Flour, Whole Wheat', density: '130 gram/cup'},
cornstarch: {name: 'Cornstarch', ndbn: '20027'},
cornmeal: {name: 'Cornmeal', density: '120 gram/cup'},
sugar: {name: 'Sugar, Granulated', ndbn: '19335'},
sugar_brown: {name: 'Sugar, Brown, Lightly Packed', density: '210 gram/cup'},
sugar_powder: {name: 'Sugar, Powdered', density: '120 gram/cup'},
chips: {name: 'Chocolate Chips', density: '170 gram/cup'},
cocoa: {name: 'Cocoa Powder', density: '100 gram/cup'},
salt: {name: 'Salt, Kosher', density: '248 gram/cup'},
table_salt: {name: 'Salt, Table', density: '304 gram/cup'},
whole_milk: {name: 'Milk, Whole', density: '1.028 gram/ml'},
skim_milk: {name: 'Milk, Skim', density: '1.032 gram/ml'},
two_per_milk: {name: 'Milk, 2%', density: '1.03 gram/ml'} ,
flank: {name: 'Flank Steak', ndbn: '13970'},
soy_sauce: {name: 'Soy Sauce', ndbn: '16123'},
shaoxing: {name: 'Shaoxing Wine', ndbn: '14084'},
stock: {name: 'Chicken Stock, Low Sodium', ndbn: '06970'} ,
oyster_sauce: {name: 'Oyster Sauce', ndbn: '06176'},
seasame_oil: {name: 'Sesame Seed Oil', ndbn: '04058'} ,
garlic: {name: 'Garlic', ndbn: '11215'},
peanut_oil: {name: 'Peanut Oil', ndbn: '04042'},
broccoli: {name: 'Broccoli Florets', ndbn: '11740'}
}
2018-09-12 17:17:15 -05:00
foods.each do |k, v|
foods[k] = Food.create!({user_id: dan.id}.merge(v))
2016-04-03 18:03:51 -05:00
end
2016-10-21 09:41:59 -05:00
g = Recipe.create!({
name: 'Guacamole',
yields: '1 cup',
total_time: 15,
active_time: 15,
user_id: dan.id
})
g.tag_names = ['vegan', 'vegetarian', 'appetizer']
2016-04-03 18:03:51 -05:00
bb = Recipe.create!({
name: 'Beef and Broccoli With Oyster Sauce',
source: 'http://www.seriouseats.com/recipes/2012/06/chinese-american-beef-and-broccoli-with-oyster-sauce-recipe.html',
yields: 4,
total_time: 30,
active_time: 10,
user_id: dan.id
})
2016-10-21 09:41:59 -05:00
bb.tag_names = ['beef', 'dinner', 'stirfry']
2016-04-03 18:03:51 -05:00
[
2018-09-12 17:17:15 -05:00
{quantity: '1', units: 'pound', preparation: 'flank steak, skirt steak, hanger steak, or flap meat, cut into 1/4-inch thick strips', food: foods[:flank]},
{quantity: '1/4', units: 'cup', preparation: 'divided', food: foods[:soy_sauce]},
{quantity: '1/4', units: 'cup', preparation: 'divided', food: foods[:shaoxing]},
{quantity: '2', units: 'teaspoons', preparation: '', food: foods[:cornstarch]},
{quantity: '1/3', units: 'cup', preparation: '', food: foods[:stock]},
{quantity: '1/4', units: 'cup', preparation: '', food: foods[:oyster_sauce]},
{quantity: '1', units: 'tablespoon', preparation: '', food: foods[:sugar]},
{quantity: '1', units: 'teaspoon', preparation: '', food: foods[:seasame_oil]},
{quantity: '2', units: 'medium cloves', preparation: 'finely minced', food: foods[:garlic]},
2016-04-03 18:03:51 -05:00
{quantity: '2', units: 'teaspoons', preparation: 'finely minced', name: 'ginger root'},
{quantity: '3', units: '', preparation: 'whites finely sliced, greens cut into 1/2-inch segments, reserved separately', name: 'Scallions'},
2018-09-12 17:17:15 -05:00
{quantity: '4', units: 'tablespoons', preparation: '', food: foods[:peanut_oil]},
{quantity: '1', units: 'pound', preparation: '', food: foods[:broccoli]},
2016-04-03 18:03:51 -05:00
].each_with_index do |ri, i|
RecipeIngredient.create!({recipe: bb, sort_order: i}.merge(ri))
end
2016-01-28 14:19:51 -06:00
2016-01-28 18:18:45 -06:00
importer = UsdaImporter.new(Rails.root.join('vendor', 'data', 'usda'))
2016-01-24 17:10:43 -06:00
importer.import
2016-01-14 15:22:15 -06:00
2016-01-28 14:19:51 -06:00
puts "Seeds planted."