Created
July 29, 2010 15:20
-
-
Save mallain/498391 to your computer and use it in GitHub Desktop.
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
# Import Fake data on the entire project | |
namespace :fake_data do | |
######### | |
# Tasks # | |
######### | |
desc "Import fake date on each part (HR, Production, Commerce, Finance)" | |
task :create => :environment do | |
# Require librairies | |
require 'faker' | |
require 'factory_girl' | |
# Init locale | |
I18n.default_locale = :en | |
# Listing referencial models which not need Factory generation | |
referencial = %w(feedback departure_type country division agency account assignment account_type skill function stage service delivery subcontract_type collaborator) | |
models_to_exclude = %w(project feeling user feedback user_session) | |
models_one_per_feedback = %w(book feeling_agency claim_collection cost_number day_rate interco_collaborator production_day distribution_day pipe interview production_number collaborator_number knowledge_management ) | |
# Instanciate array | |
models_excluded = referencial + models_to_exclude | |
factory_models = %w() | |
# Retrieves Factories template from test directory | |
factories = Dir["#{RAILS_ROOT}/test/factories/*.rb"] | |
# Require Factories | |
factories.each do |file| | |
# Require the factory template | |
require file | |
# Exclude referencial model from the list of files | |
factory_name = File.basename(file, "_factory.rb") | |
unless models_excluded.include?(factory_name) | |
factory_models << factory_name | |
end | |
end | |
# For each agency | |
Agency.agencies.each do |agency| | |
# 5 Feedbacks | |
Feedback.find(:all, :limit => 5).each do |feedback| | |
puts "##### Faking data for \"#{agency.name}\" and \"#{I18n.t('date.month_names')[feedback.feedback_time.month].titleize} #{feedback.feedback_time.year}\"" | |
# Each model | |
factory_models.each do |model| | |
models_one_per_feedback.include?(model) ? loop = (1..1) : loop = (1..5) | |
puts "### Processing #{model}" | |
loop.each do |i| | |
begin | |
Factory(model.to_sym, :agency => agency, :feedback => feedback) | |
rescue Exception => e | |
puts "# Errors Factory(#{model.to_sym}) with :agency_id => #{agency.id} and feedback_id => #{feedback.id}" | |
puts "#{e.message}" | |
end | |
end | |
end | |
end | |
end | |
end | |
end |
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
##### Faking data for "Sud" and "April 2000" | |
### Processing trouble_project | |
### Processing book | |
### Processing alert_collaborator | |
### Processing delivery_distribution | |
### Processing feeling_agency | |
# Errors Factory(feeling_agency) with :agency_id => 10 and feedback_id => 4 | |
Validation failed: Level has already been taken | |
### Processing cost_number | |
### Processing prospect | |
### Processing claim_collection | |
### Processing small_company | |
### Processing major_company | |
### Processing collaborator_function | |
### Processing arrival_collaborator | |
### Processing knowledge_management | |
### Processing collaborator_number | |
### Processing departure_collaborator | |
### Processing production_number | |
### Processing interview | |
### Processing pipe | |
### Processing distribution_day | |
### Processing training | |
### Processing offer | |
### Processing big_deal | |
### Processing subcontract_number | |
### Processing production_day | |
### Processing interco_collaborator | |
### Processing ask_help | |
### Processing day_rate | |
##### Faking data for "Sud" and "May 2000" | |
### Processing trouble_project | |
### Processing book | |
### Processing alert_collaborator | |
### Processing delivery_distribution | |
### Processing feeling_agency | |
# Errors Factory(feeling_agency) with :agency_id => 10 and feedback_id => 5 | |
Validation failed: Level has already been taken | |
### Processing cost_number | |
### Processing prospect | |
### Processing claim_collection | |
### Processing small_company | |
### Processing major_company | |
### Processing collaborator_function | |
### Processing arrival_collaborator | |
### Processing knowledge_management | |
### Processing collaborator_number | |
### Processing departure_collaborator | |
### Processing production_number | |
### Processing interview | |
### Processing pipe | |
### Processing distribution_day | |
### Processing training | |
### Processing offer | |
### Processing big_deal | |
### Processing subcontract_number | |
### Processing production_day | |
### Processing interco_collaborator | |
### Processing ask_help | |
### Processing day_rate | |
##### Faking data for "Sud-Ouest" and "January 2000" | |
### Processing trouble_project | |
### Processing book | |
### Processing alert_collaborator | |
### Processing delivery_distribution | |
### Processing feeling_agency | |
# Errors Factory(feeling_agency) with :agency_id => 8 and feedback_id => 1 | |
Validation failed: Level has already been taken | |
### Processing cost_number | |
### Processing prospect | |
### Processing claim_collection | |
### Processing small_company | |
### Processing major_company | |
### Processing collaborator_function | |
### Processing arrival_collaborator | |
### Processing knowledge_management | |
### Processing collaborator_number | |
### Processing departure_collaborator | |
### Processing production_number | |
### Processing interview | |
### Processing pipe | |
### Processing distribution_day | |
### Processing training | |
### Processing offer | |
### Processing big_deal | |
### Processing subcontract_number | |
### Processing production_day | |
### Processing interco_collaborator | |
### Processing ask_help | |
### Processing day_rate | |
##### Faking data for "Sud-Ouest" and "February 2000" | |
### Processing trouble_project | |
### Processing book | |
### Processing alert_collaborator | |
### Processing delivery_distribution | |
### Processing feeling_agency | |
# Errors Factory(feeling_agency) with :agency_id => 8 and feedback_id => 2 | |
Validation failed: Level has already been taken | |
### Processing cost_number | |
### Processing prospect | |
### Processing claim_collection | |
### Processing small_company | |
### Processing major_company | |
### Processing collaborator_function | |
### Processing arrival_collaborator | |
### Processing knowledge_management | |
### Processing collaborator_number | |
### Processing departure_collaborator | |
### Processing production_number | |
### Processing interview | |
### Processing pipe | |
### Processing distribution_day | |
### Processing training | |
### Processing offer | |
### Processing big_deal | |
### Processing subcontract_number | |
### Processing production_day | |
### Processing interco_collaborator | |
### Processing ask_help | |
### Processing day_rate | |
##### Faking data for "Sud-Ouest" and "March 2000" | |
### Processing trouble_project | |
### Processing book | |
### Processing alert_collaborator | |
### Processing delivery_distribution | |
### Processing feeling_agency | |
# Errors Factory(feeling_agency) with :agency_id => 8 and feedback_id => 3 | |
Validation failed: Level has already been taken | |
### Processing cost_number | |
### Processing prospect | |
### Processing claim_collection | |
### Processing small_company | |
### Processing major_company | |
### Processing collaborator_function | |
### Processing arrival_collaborator | |
### Processing knowledge_management | |
### Processing collaborator_number | |
### Processing departure_collaborator | |
### Processing production_number | |
### Processing interview | |
### Processing pipe | |
### Processing distribution_day | |
### Processing training | |
### Processing offer | |
### Processing big_deal | |
### Processing subcontract_number | |
### Processing production_day | |
### Processing interco_collaborator | |
### Processing ask_help | |
### Processing day_rate | |
##### Faking data for "Sud-Ouest" and "April 2000" | |
### Processing trouble_project | |
### Processing book | |
### Processing alert_collaborator | |
### Processing delivery_distribution | |
### Processing feeling_agency | |
# Errors Factory(feeling_agency) with :agency_id => 8 and feedback_id => 4 | |
Validation failed: Level has already been taken | |
### Processing cost_number | |
### Processing prospect | |
### Processing claim_collection | |
### Processing small_company | |
### Processing major_company | |
### Processing collaborator_function | |
### Processing arrival_collaborator | |
### Processing knowledge_management | |
### Processing collaborator_number | |
### Processing departure_collaborator | |
### Processing production_number | |
### Processing interview | |
### Processing pipe | |
### Processing distribution_day | |
### Processing training | |
### Processing offer | |
### Processing big_deal | |
### Processing subcontract_number | |
### Processing production_day | |
### Processing interco_collaborator | |
### Processing ask_help | |
### Processing day_rate | |
##### Faking data for "Sud-Ouest" and "May 2000" | |
### Processing trouble_project | |
### Processing book | |
### Processing alert_collaborator | |
### Processing delivery_distribution | |
### Processing feeling_agency | |
# Errors Factory(feeling_agency) with :agency_id => 8 and feedback_id => 5 | |
Validation failed: Level has already been taken | |
### Processing cost_number | |
### Processing prospect | |
### Processing claim_collection | |
### Processing small_company | |
### Processing major_company | |
### Processing collaborator_function | |
### Processing arrival_collaborator | |
### Processing knowledge_management | |
### Processing collaborator_number | |
### Processing departure_collaborator | |
### Processing production_number | |
### Processing interview | |
### Processing pipe | |
### Processing distribution_day | |
### Processing training | |
### Processing offer | |
### Processing big_deal | |
### Processing subcontract_number | |
### Processing production_day | |
### Processing interco_collaborator | |
### Processing ask_help | |
### Processing day_rate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment