Rake Task for Faker

49 views
Skip to first unread message

Chris Moore

unread,
Feb 21, 2008, 9:19:33 AM2/21/08
to Ruby Faker
I have no idea if I went about it the right way, but I wrote a Rake
task for faker. It works great for me! Just thought I'd share.

namespace :db do
namespace :development do
desc "Create records in the development database."
task :fake_data => :environment do
require 'faker'

100.times do
c = Client.new(
:first_name => Faker::Name.first_name,
:middle_initial => ("A".."Z").to_a.rand,
:last_name => Faker::Name.last_name,
:ss_number => 99999999 + rand(999999999 - 99999999),
:date_of_birth => Time.now - (rand(12000)).days)
end
end
end
end


Chris
http://26Webs.com/

Benjamin Curtis

unread,
Feb 25, 2008, 1:45:27 PM2/25/08
to ruby-...@googlegroups.com
Thanks for sharing, Chris! You probably want Client.create rather
than Client.new, though. :)

----
Benjamin Curtis
http://catchthebest.com/ - Track, share, and rate incoming resumes
http://www.bencurtis.com/ - Personal blog

Chris Moore

unread,
Feb 25, 2008, 5:22:51 PM2/25/08
to Ruby Faker
D'oh! You're right. I copied it from the task, which had some extra
associations.

Faker is super handy, though. Thanks!

On Feb 25, 1:45 pm, Benjamin Curtis <benjamin.cur...@gmail.com> wrote:
> Thanks for sharing, Chris!  You probably want Client.create rather  
> than Client.new, though. :)
>
> ----
> Benjamin Curtishttp://catchthebest.com/- Track, share, and rate incoming resumeshttp://www.bencurtis.com/- Personal blog
Reply all
Reply to author
Forward
Message has been deleted
0 new messages