Created
September 14, 2009 03:42
-
-
Save saberma/186485 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
# lib/tasks/populate.rake | |
namespace :db do | |
desc "Erase and fill database" | |
task :populate => :environment do | |
require 'populator' | |
require 'faker' | |
[Conversation, Event, History, Dispatch, Record, Workitem, Duty, Person].each(&:delete_all) | |
#区划代码 | |
districtcodes = District.communitee.under(District.top.first).map(&:code) | |
#用户 | |
cogentsoft_id = User.find_by_login('admin').id | |
Conversation.populate 800 do |conversation| | |
conversation.title = Faker::Name.name | |
conversation.content = Faker::Lorem.paragraph | |
conversation.state = [-1, 0, 10, 20, 30, 40, 60, 70, 90] | |
conversation.aim = 1..9 | |
conversation.emergency = 1..3 | |
conversation.security = 1..5 | |
conversation.kind_id = 1..2 | |
conversation.sub_kind_id = (1..10).to_a + (51..60).to_a | |
conversation.place = Faker::Address.street_address | |
conversation.district = districtcodes | |
conversation.grid = District.find_by_code(conversation.district).grids.map(&:code) | |
conversation.source = 1..9 | |
conversation.reportor_id = cogentsoft_id | |
conversation.ownerdistrict = districtcodes | |
conversation.creator_id = cogentsoft_id | |
conversation.modifier_id = cogentsoft_id | |
conversation.created_at = 3.months.ago..Time.now | |
conversation.updated_at = 1.years.ago..Time.now | |
conversation.reported_at = 1.months.ago..Time.now | |
Person.populate 1..2 do |person| | |
person.name = Faker::Name.name | |
person.cardno = '441521198384784534' | |
person.sex = 1..2 | |
person.phone = Faker::PhoneNumber.phone_number | |
person.mobile = Faker::PhoneNumber.phone_number | |
person.email = Faker::Internet.email | |
person.address = Faker::Address.street_address | |
person.jobunit = Faker::Company.name | |
person.created_at = 1.years.ago..Time.now | |
person.updated_at = 1.years.ago..Time.now | |
Event.populate 1 do |event| | |
event.person_id = person | |
event.conversation_id = conversation.id | |
event.category = (1..7).to_a + (21..26).to_a | |
event.timing = 1.years.ago..Time.now | |
event.content = Faker::Lorem.paragraph | |
event.creator_id = cogentsoft_id | |
event.modifier_id = cogentsoft_id | |
event.created_at = 1.years.ago..Time.now | |
event.updated_at = 1.years.ago..Time.now | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment