Ryan, I just wanna thank your for this awesome Screencast! Keep up the great work! It helps me a lot focussing on what really matters.
off topic, but one of your ads says "Powered by Railsmachine". Isn't railscasts being run on slicehost?
Good work, Ryan. I've done something similar to the "populator" gem on the last on the last few projects I've done, but your interface is much more pleasent, and I'll be using it in the future. Thanks.
This is great. For the longest time I relied on my spreadsheet data based approach to generating random names as test data.
http://www.markrichman.com/2007/09/26/generating-random-names-as-test-data/
Cool!
I wrote an article about this a while back (http://railspikes.com/2008/1/25/fuzzing-your-database) but it was a more random approach. I like the approach of using Faker to generate more realistic data.
Wow, I was just thinking about creating some loops to do this very thing to do some sort of stress testing on my slice to see how long different approaches would take. Perfect timing, thanks!
Very cool & useful gem!
Almost sent you a comment on the future dates ;-)
T.
I'm getting this error:
rake aborted!
Could not find RubyGem echoe (>= 0)
I'm pretty sure I installed the gem properly.
Ren, I have the same problem, and I also believe I installed the gem correctly. Have you updated your rubygems system too?
Having the same problem here...
Try putting this in your environment.rb file:
Rails::Initializer.run do |config|
config.gem 'populator'
end
@Ren & @Neil, do a gem install echoe...should install and you'll be good to go. I had the same issue, maybe he doesn't have it requiring it as a dependency upon installation.
Looks nice. I usually do this with a fixture http://pastie.org/268729 , but you'd still need something for really random data... this works well. :)
@James
Thanks! Didn't even consider "echoe" to be a gem. It works. Thanks Ryan for an awesome tutorial/gem. Mucho helpful.
Echoe isn't supposed to be a gem dependency, but looks like something is hosed in my gem config. I think I fixed it, so the latest populator version (0.2.4) should work without echoe installed.
Thanks for the great screencast, Ryan. I have a question, however, concerning how you would populate a habtm (has_many :through is possible though) association? In your example, Category-to-Products is a one-to-many, but what if you modeled products to be part of many categories? Nesting the two like you have in your example wouldn't work in that case. Maybe you already came across this problem and have a nice solution? :)
@Greg, currently HABTM associations aren't supported by Populator, I'll work on adding that though. Thanks. :)
Great technique, just a question. Is there any support for counter caches?
sthapit: ping it:
PING railscasts.com (75.127.77.214) 56(84) bytes of data.
64 bytes from rm-75-127-77-214.railsmachina.com (75.127.77.214): icmp_seq=1 ttl=47 time=36.2 ms
Hi
If I add to many records at the same time, MySQL give me this error through the task:
Mysql::Error: Got a packet bigger than 'max_allowed_packet' bytes
I know that max_allowed_packet is a parameter into MySQL, but do you know if there is a way to tell Populator to insert the records by steps instead of waiting at the end to do a big insert ?
Thanks !
@Pascal: Just had the same problem. There is an option to #populate called :per_query that limits how many records are inserted per query.
@sthapit I used to use slicehost and had no problems, but Rails Machine was kind enough to host it for free. :)
@Fredd, you'll need to set the counter caches directly. Usually this is possible with a query at the end to count the associated models. I'll look into providing a more convenient way to do this.
@Pascal, the :per_query option will do this, it defaults to 1000 so I may need to lower this. It will vary depending on the size of each record.
@Ryan,
I'm at slicehost now and I'm happy with what I get for my $$, but I'm also curious about other providers. Ignoring the price difference (or what it would be if you had to pay for it) how would you compare the two for a production rails app? What kind of slice (size and OS) were you running railscasts on before?
@Carl, I'm just running on a 256 MB slice, both here and at slicehost. Both hosts fit my needs equally well since this is such a simple site. Rails Machine offers quite a bit more with their plan so you should look into it and see if it fits your needs.
Ryan, this is really a great screencast! Thanx for it and keep up the good work!
How can I use this to load up a bunch of dummy users using restful_authentication?
I can't seem to set user.password = 'foo' here:
Account.populate 200 do |account|
account.name = Faker::Company.name
account.email = Faker::Internet.email
account.created_at = 2.years.ago..Time.now
User.populate 10 do |user|
user.login = Faker::Internet.user_name
user.password = 'foo'
user.first_name = Faker::Name.name
user.last_name = Faker::Name.name
user.email = Faker::Internet.email
user.account_id = account.id
end
end
@Mark,
I wonder if that's because populator is working directly with the database for speed and bypassing the virtual attribute? Does it give you an error or just not set anything for the password, or just not create any users?
@Mark, Carl is correct, the "account" passed to the block is not a true instance of account. You can only set columns direction, not through virtual attributes.
I'm thinking of changing how this is done so it allows you to use virtual attributes as well. But it doesn't work yet.
This was great. Thank you! I have almost everything in your railscasts in my apps!
Hey, this is a good idea. I just cloned Faker and spent a little time in the wee hours of the morning adding a couple features. I'll likely be adding a bit more too. I haven't created a patch yet for the SVN version, but I'll get around to it quickly.
Also I need to set up a gemspec so that it can be used with GitHub's gem thingy, but until then:
http://github.com/darrylring/faker/tree/master
It would be nice to have the ability to supply a max length to Populator.words, Populator.sentences etc. as otherwise I think you'd hit the limits on some columns.
I thought I was hitting that problem but it appears that I'm hitting a problem with duplicate keys although it doesn't make any sense as the queries that it's complaining about aren't duplicating keys from what I can see.
I figured out the duplicate key issue, it would be nice to be able to tell populator about what should be unique within a database.
Hi, and thanks for the great screencast! I am having the following error when I run the rake:
rake aborted!
no such file to load -- spec/rake/spectask
So I read all the comments and tried:
sudo gem install echoe
and got:
ERROR: Error installing echoe:
echoe requires RubyGems version = 1.2
I am running this on a fresh Rails 2.1 app and have not had any proplems with RubyGems before... Any suggestions?
Here's how I'm trying to populate now... http://pastie.org/276597
I know the last couple of lines won't work, and I know why. I'm just demonstrating how slick it would be if I could. Do you have a github project for the gem, or anything? I'd be happy to help accomplish that if you'd like.
Also, it would be slick if there was something available along the lines of "Populator.bool" that would return an array of true and false, so I don't have to set that up manually in my task.
Thanks a ton for this plugin, it's way slick. Hit me on twitter or GT if there's any way I can contribute. :)
And of course, as soon as I submit it, I find the github link. :)
Is there any support for min/max or high/low fields? I have a model that has a price range that is stored as 2 separate fields. I can set pkg.min_price = 1..100 and pkg.max_price = 101..200, but that's not ideal.
restful_authentication X 2 I would like to know the best approach for this as well
Here's a quick example of how you can use Populator and Faker to create valid records for use in demos, acceptance testing, etc:
http://almosteffortless.com/2008/09/27/creating-valid-records-with-populator-and-faker/
hello, great as usual!
i have a small issue though with the following code
deal.name = Populator.words(4..9).titleize
deal.permalink = PermalinkFu.escape(deal.name)
this code dose correctly set the permalink but it also sets deal.name to be a permalink, any thoughts why??
Echoe isn't supposed to be a gem dependency, but looks like something is hosed in my gem config. I think I fixed it, so the latest populator version (0.2.4) should work without echoe installed.
This is awesome - can't wait to try it!
I do have one issue. This is more of a general question, but...
In one of my applications, a number of my models have one uploaded file (ex. User has one uploaded_image). I'm using attachment_fu, which provides an "uploaded_data=" setter that works perfectly via the web interface. However, I can't seem to get this working in the rake task. I'm pretty sure that uploaded_data= expects a binary file, but none of my attempts with File, Tempfile, StringIO, or ActionController::UploadedTempfile have worked.
Is there a way to create a model with attachments via a rake task?
Hey! don't you know Wrath of the Lich King release in about 20 days later? All of us is wating for Lich King release, you still worry about WOTLK cdkey? Surely no! we start preorder wrath of the lich king cd key, wrath cd key is not hart to get, we don't think it's happy that waiting for the wow wrath of the lich king cdkey, if you still don't have WOW WOTLK cd key,wlk cd key,wrath key, put an order for preorder WOTLK cd key , wlk cdkey on WOW cd key page, then see you in game when the Wrath of the Lich King release!
Preorder Wrath of the Lich King cd key on Gamevive
Hey! don't you know Wrath of the Lich King release in about 20 days later? All of us is wating for Lich King release, you still worry about WOTLK cdkey? Surely no! we start preorder wrath of the lich king cd key, wrath cd key is not hart to get, we don't think it's happy that waiting for the wow wrath of the lich king cdkey, if you still don't have WOW WOTLK cd key,wlk cd key,wrath key, put an order for preorder WOTLK cd key , wlk cdkey on WOW cd key page, then see you in game when the Wrath of the Lich King release!
Preorder Wrath of the Lich King cd key on Gamevive
Hey! don't you know Wrath of the Lich King release in about 20 days later? All of us is wating for Lich King release, you still worry about WOTLK cdkey? Surely no! we start preorder wrath of the lich king cd key, wrath cd key is not hart to get, we don't think it's happy that waiting for the wow wrath of the lich king cdkey, if you still don't have WOW WOTLK cd key,wlk cd key,wrath key, put an order for preorder WOTLK cd key , wlk cdkey on WOW cd key page, then see you in game when the Wrath of the Lich King release!
Hey! don't you know Wrath of the Lich King release in about 20 days later? All of us is wating for Lich King release, you still worry about WOTLK cdkey? Surely no! we start preorder wrath of the lich king cd key, wrath cd key is not hart to get, we don't think it's happy that waiting for the wow wrath of the lich king cdkey, if you still don't have WOW WOTLK cd key,wlk cd key,wrath key, put an order for preorder WOTLK cd key , wlk cdkey on WOW cd key page, then see you in game when the Wrath of the Lich King release!
Preorder Wrath of the Lich King cd key on Gamevive
Hey! don't you know Wrath of the Lich King release in about 20 days later? All of us is wating for Lich King release, you still worry about WOTLK cdkey? Surely no! we start preorder wrath of the lich king cd key, wrath cd key is not hart to get, we don't think it's happy that waiting for the wow wrath of the lich king cdkey, if you still don't have WOW WOTLK cd key,wlk cd key,wrath key, put an order for preorder WOTLK cd key , wlk cdkey on WOW cd key page, then see you in game when the Wrath of the Lich King release!
Is there a way to get populator to add records to a HABTM relationship?
Two questions:
1) How do I enforce that this db:populate only gets ran on 'test' environment? Don't want to accidently do it on prod :)
2) What about test scripts that rely on data to be the same, is there a better way of writing tests that don't rely on the data itself in the db? (ie: selenium tests for UI)
For whatever reason, I get a TON of failures during testing phase:
$ rake db:populate
Ftest
F
Finished in 0.872049 seconds.
1) Failure:
test_should_create_directory(ThingControllerTest)
[/usr/lib/ruby/gems/1.8/gems/activesupport-
... about 100 failures form this pint.
<p><a href="http://www.gamevive.com/Warhammer/cheap-Warhammer-gold/Warhammer-Anlec(Oceanic)-24-2093-Order.html"> Buy WAR gold </a></p>
<p><a href="http://www.gamevive.com/Warhammer/cheap-Warhammer-gold/Warhammer-Anlec(Oceanic)-24-2093-Order.html"> Cheap Warhammer Gold </a></p>
<p><a href="http://www.gamevive.com/Warhammer/cheap-Warhammer-gold/Warhammer-Anlec(Oceanic)-24-2093-Order.html"> Buy warhammer online gold </a></p>
<p><a href="http://www.gamevive.com/Warhammer/cheap-Warhammer-gold/Warhammer-Anlec(Oceanic)-24-2093-Order.html"> cheap warhammer online gold </a></p>
<p><a href="http://www.gamevive.com/Warhammer/cheap-Warhammer-gold/Warhammer-Anlec(Oceanic)-24-2093-Order.html"> Buy warhammer gold </a></p>
<p><a href="http://www.gamevive.com/Warhammer/cheap-Warhammer-gold/Warhammer-Anlec(Oceanic)-24-2093-Order.html"> buy warhammer online gold </a></p>
<p><a href="http://www.gamevive.com/Warhammer/cheap-Warhammer-gold/Warhammer-Anlec(Oceanic)-24-2093-Order.html"> buy cheap warhammer gold </a></p>
<p><a href="http://www.gamevive.com/Warhammer/Warhammer-Gold/Cheap-Warhammer-Gold.html
"> War Gold </a></p>
<p><a href="http://www.gamevive.com/Warhammer/Warhammer-Gold/Cheap-Warhammer-Gold.html
"> Buy Warhammer Gold </a></p>
<p><a href="http://www.gamevive.com/Warhammer/Warhammer-Gold/Cheap-Warhammer-Gold.html
"> Warhammer Online Gold </a></p>
<p><a href="http://www.gamevive.com/Warhammer/Warhammer-Gold/Cheap-Warhammer-Gold.html
"> Warhammer Gold for sale </a></p>
<p><a href="http://www.gamevive.com/Warhammer/Warhammer-Gold/Cheap-Warhammer-Gold.html
"> Cheap Warhammer Gold </a></p>
<p><a href="http://www.gamevive.com/Warhammer/Warhammer-Account/Cheap-Warhammer-Account.html
"> Warhammer Accounts </a></p>
<p><a


