forked from binarylogic/searchlogic_example
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a db:populate rake task. Added the gem requirements for the db:…
…populate task to the environment. Added an example database.yml. Updated README with instructions for the db:populate task.
- Loading branch information
Daniel Grünthal
committed
Sep 12, 2008
1 parent
6ddec71
commit e228f4a
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |