Created
March 20, 2015 11:14
-
-
Save MarconiVini/c1508943ab745742aaee to your computer and use it in GitHub Desktop.
rake for generate our delivery data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
namespace :hermes do | |
namespace :development do | |
task :create_deliveries_seed, [:rows, :volumes, :occurrences] => :environment do |t, args| | |
rows = args[:rows].nil? ? 200 : args[:rows].to_i | |
volumes_count = args[:volumes].nil? ? 2 : args[:volumes].to_i | |
occurrences_count = args[:occurrences].nil? ? 3 : args[:occurrences].to_i | |
puts "Before => Delivery.count: #{Delivery.count}" | |
Benchmark.bm do |x| | |
x.report do | |
rows.times do | |
delivery=FactoryGirl.create(:delivery) | |
#create volumes for delivery | |
volumes = generate_volumes(delivery, volumes_count) | |
#create occurrences for volumes | |
#generate_occurrences(delivery, volumes, occurrences_count) | |
#binding.pry | |
end | |
end | |
end | |
puts "After => Delivery.count: #{Delivery.count}" | |
end | |
def generate_volumes(delivery, count) | |
volumes ||= [] | |
count.times do | |
volumes<<FactoryGirl.create(:delivery_volume, delivery: delivery) | |
end | |
volumes | |
end | |
def generate_occurrences(delivery, volumes, occurrences_count) | |
volumes.each do |volume| | |
binding.pry | |
occurrences_count.times do |count| | |
if count == occurrences_count | |
finalize = (rand(0..3) == 3) | |
end | |
type = finalize ? :occurrence_final_status : :occurrence | |
u = FactoryGirl.create(type, trackable_code: delivery.delivery_id, ticket: volume.ticket) | |
binding.pry | |
end | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment