Browse Source

Louis | Improve dummy data

master
Loos 10 years ago
parent
commit
884d95bb5c
  1. 46
      lib/tasks/dummydata.rake

46
lib/tasks/dummydata.rake

@ -8,7 +8,23 @@ namespace :db do
Bike.destroy_all Bike.destroy_all
puts "clearing clients" puts "clearing clients"
Client.destroy_all Client.destroy_all
puts "clearing agencies"
Agency.destroy_all
def random_agency
return {
agency_name: Faker::Company.name,
contact_name: Faker::Name.name,
street_address: Faker::Address.street_address,
city: Faker::Address.city,
state: "IL",
postal_code: Faker::Number.number(5),
phone_number: Faker::Number.number(7),
email: Faker::Internet.email
}
end
def random_client def random_client
return { return {
first_name: Faker::Name.first_name, first_name: Faker::Name.first_name,
@ -19,8 +35,15 @@ namespace :db do
weight: rand(100) + 100, weight: rand(100) + 100,
helmet: [true, false].sample, helmet: [true, false].sample,
lock: [true, false].sample, lock: [true, false].sample,
agency: Faker::Company.name, completion_date: rand(30.days).ago,
completion_date: rand(30.days).ago bike_type_requested: ["Cruiser", "Road", "Mountain"].sample,
will_pay: [true, false].sample,
notes: "A great client!",
bike_fixed: [true, false].sample,
number_of_calls: [0, 1, 2].sample,
application_voided: [false, false, false, false, true].sample,
pickup_date: rand(10.days).ago,
volunteer_at_pickup: Faker::Name.first_name
} }
end end
@ -40,7 +63,10 @@ namespace :db do
top_tube_size: rand(45), top_tube_size: rand(45),
log_number: Faker::Number.number(8), log_number: Faker::Number.number(8),
purpose: ["Sale", "Freecyclery"].sample, purpose: ["Sale", "Freecyclery"].sample,
mechanic: Faker::Name.first_name mechanic: Faker::Name.first_name,
new_parts: Array.new(4) {Faker::Commerce.product_name}.join("\n"),
work_done: Faker::Hacker.say_something_smart
## , date_sold: rand(2.months).ago,
} }
end end
@ -51,19 +77,29 @@ namespace :db do
10.times do 10.times do
Client.new(random_client).save Client.new(random_client).save
end end
clients = Client.all clients = Client.all
puts "creating some bikes" puts "creating some bikes"
30.times do 30.times do
Bike.new(random_bike).save Bike.new(random_bike).save
end end
bikes = Bike.all bikes = Bike.all
puts "creating some agencies"
5.times do
Agency.new(random_agency).save
end
agencies = Agency.all
puts "assigning agencies to clients"
Client.all.each do |client|
client.update_attribute("agency_id", agencies.sample.id)
end
puts "assigning bikes to clients" puts "assigning bikes to clients"
Client.all.each_with_index do |client, index| Client.all.each_with_index do |client, index|
client.update_attribute("bike_id", Bike.all[index].id) client.update_attribute("bike_id", Bike.all[index].id)
end end
end end
end end

Loading…
Cancel
Save