wedding-planner/db/seeds.rb

77 lines
2.7 KiB
Ruby

# This file should ensure the existence of records required to run the application in every environment (production,
# development, test). The code here should be idempotent so that it can be executed at any point in every environment.
# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
#
# Example:
#
# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name|
# MovieGenre.find_or_create_by!(name: genre_name)
# end
Expense.delete_all
Guest.delete_all
ActsAsTaggableOn::Tagging.delete_all
ActsAsTaggableOn::Tag.delete_all
Expense.create!(name: 'Photographer', amount: 3000, pricing_type: 'fixed')
Expense.create!(name: 'Country house', amount: 6000, pricing_type: 'fixed')
Expense.create!(name: 'Catering', amount: 200, pricing_type: 'per_person')
Expense.create!(name: 'Flowers', amount: 500, pricing_type: 'fixed')
Expense.create!(name: 'Band', amount: 1000, pricing_type: 'fixed')
Expense.create!(name: 'Wedding planner', amount: 2000, pricing_type: 'fixed')
Expense.create!(name: 'Dress', amount: 1000, pricing_type: 'fixed')
Expense.create!(name: 'Suit', amount: 500, pricing_type: 'fixed')
Expense.create!(name: 'Rings', amount: 1000, pricing_type: 'fixed')
Expense.create!(name: 'Makeup', amount: 200, pricing_type: 'fixed')
Expense.create!(name: 'Hair', amount: 200, pricing_type: 'fixed')
Expense.create!(name: 'Transportation', amount: 3000, pricing_type: 'fixed')
Expense.create!(name: 'Invitations', amount: 200, pricing_type: 'fixed')
Expense.create!(name: 'Cake', amount: 500, pricing_type: 'fixed')
<<<<<<< HEAD
=======
>>>>>>> 8fd0b7c (Modify seeds file to make sure every guest is part of a group)
samples = {
close_family: 10,
family_1_group_a: 5,
family_1_group_b: 5,
family_2_group_a: 7,
family_2_group_b: 15,
previous_company: 5,
new_company: 20,
college: 10,
high_school: 5,
childhood: 5,
basket_team: 20,
soccer_team: 15,
dance_club: 10
}.each_with_object([]) do |(affinity_group, count), acc|
count.times { acc << affinity_group }
end
300.times do
guest = Guest.create!(first_name: Faker::Name.first_name,
last_name: Faker::Name.last_name,
email: Faker::Internet.email,
phone: Faker::PhoneNumber.cell_phone)
guest.affinity_group_list.add(samples.sample)
guest.save!
end
Guest.affinity_group_counts.each do |group|
couples = (group.taggings_count / 4).floor
guests_involved = Guest.tagged_with(group.name).limit(couples * 2)
guests_involved.each_slice(2) do |a, b|
bond_name = "#{a.full_name} & #{b.full_name}"
a.unbreakable_bond_list.add(bond_name)
b.unbreakable_bond_list.add(bond_name)
a.save!
b.save!
end
end