Skip to content
Browse files

Merge git://github.com/Croaker/searchgasm_example

  • Loading branch information...
2 parents 7c381bd + 1fb141a commit bf266c59343fc3d8415f88f0e3f71de37c287c0c Ben Johnson committed Sep 13, 2008
Showing with 73 additions and 0 deletions.
  1. +17 −0 README.rdoc
  2. +24 −0 config/database.example.yml
  3. +2 −0 config/environment.rb
  4. +30 −0 lib/tasks/populate.rake
View
17 README.rdoc
@@ -12,6 +12,23 @@ Here are the files you want to glance at:
1. All of the controllers and their respective views
2. config/initializers/searchgasm.rb
+=== Generate Test Data
+
+First you need to install the Populator and Faker gems. You can do this by either using rails' gems task
+
+<tt>rake gems:install</tt>
+
+or by installing the gems manually
+
+<tt>sudo gem install populator</tt>
+
+<tt>sudo gem install faker</tt>
+
+After you have set up the gems and migrated your database you can generate the data:
+
+<tt>rake db:populate</tt>
+
+The populate task will create 8 user groups with 0 to 150 users each. Each user can have upto 7 orders. (see lib/tasks/populate.rb)
Copyright (c) 2008 [Ben Johnson](http://github.com/binarylogic) of [Binary Logic](http://www.binarylogic.com), released under the MIT license
View
24 config/database.example.yml
@@ -0,0 +1,24 @@
+login: &login
+ username: root
+ password:
+
+development:
+ adapter: mysql
+ database: searchgasm_development
+ encoding: utf8
+ socket: /tmp/mysql.sock
+ <<: *login
+
+test:
+ adapter: mysql
+ database: searchgasm_test
+ encoding: utf8
+ socket: /tmp/mysql.sock
+ <<: *login
+
+production:
+ adapter: mysql
+ database: searchgasm_production
+ encoding: utf8
+ socket: /tmp/mysql.sock
+ <<: *login
View
2 config/environment.rb
@@ -26,6 +26,8 @@
# config.gem "hpricot", :version => '0.6', :source => "http://code.whytheluckystiff.net"
# config.gem "aws-s3", :lib => "aws/s3"
#config.gem :searchgasm
+ config.gem "populator", :version => ">=0.2.4"
+ config.gem "faker", :version => ">=0.3.1"
# Only load the plugins named here, in the order given. By default, all plugins
# in vendor/plugins are loaded in alphabetical order.
View
30 lib/tasks/populate.rake
@@ -0,0 +1,30 @@
+namespace :db do
+ desc "Erase and fill the database with test data"
+ task :populate => :environment do
+ require 'populator'
+ require 'faker'
+
+ [UserGroup, User, Order].each(&:delete_all)
+
+ # Generates 8 user groups with 0 to 150 users.
+ # Each user has 0 to 7 orders..
+ UserGroup.populate 8 do |user_group|
+ user_group.name = Populator.words(1..2).titleize
+ user_group.active = [true, false]
+ User.populate 0..150 do |user|
+ user.user_group_id = user_group.id
+ user.first_name = Faker::Name.first_name
+ user.last_name = Faker::Name.last_name
+ user.email = "#{user.first_name.downcase}.#{user.last_name.downcase}@#{Faker::Internet.domain_name}"
+ user.born_on = 42.years.ago..18.years.ago
+ user.created_at = 2.years.ago..Time.now
+ Order.populate 0..7 do |order|
+ order.user_id = user.id
+ order.total = [ 29.95, 4.99, 795.00, 31.70, 1.99 ]
+ order.description = Populator.sentences(2..6)
+ order.created_at = user.created_at..Time.now
+ end
+ end
+ end
+ end
+end

0 comments on commit bf266c5

Please sign in to comment.
Something went wrong with that request. Please try again.