mirror of
				https://github.com/fspc/bike-database.git
				synced 2025-10-31 08:45:34 -04:00 
			
		
		
		
	Louis | Improve dummy data
This commit is contained in:
		
							parent
							
								
									f033485c48
								
							
						
					
					
						commit
						884d95bb5c
					
				| @ -8,7 +8,23 @@ namespace :db do | ||||
|     Bike.destroy_all | ||||
|     puts "clearing clients" | ||||
|     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 | ||||
|       return { | ||||
|         first_name: Faker::Name.first_name, | ||||
| @ -19,8 +35,15 @@ namespace :db do | ||||
|         weight: rand(100) + 100, | ||||
|         helmet: [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  | ||||
|    | ||||
| @ -40,7 +63,10 @@ namespace :db do | ||||
|         top_tube_size: rand(45), | ||||
|         log_number: Faker::Number.number(8), | ||||
|         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 | ||||
| 
 | ||||
| @ -51,19 +77,29 @@ namespace :db do | ||||
|     10.times do | ||||
|       Client.new(random_client).save | ||||
|     end | ||||
| 
 | ||||
|     clients = Client.all | ||||
|         | ||||
|     puts "creating some bikes" | ||||
| 
 | ||||
|     30.times do | ||||
|       Bike.new(random_bike).save | ||||
|     end | ||||
|     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"  | ||||
|     Client.all.each_with_index do |client, index| | ||||
|       client.update_attribute("bike_id", Bike.all[index].id) | ||||
|     end | ||||
| 
 | ||||
|   end | ||||
| end | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user