Skip to content

Commit

Permalink
Working on populate task
Browse files Browse the repository at this point in the history
  • Loading branch information
Roendal committed Aug 22, 2011
1 parent be2dd25 commit 7ad1107
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 17 deletions.
3 changes: 3 additions & 0 deletions db/migrate/20110821125347_create_fuzion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ def up
end

create_table :weapons do |t|
t.string :type
t.string :name
t.integer :price

t.timestamps
end

create_table :armors do |t|
t.string :type
t.string :name
t.integer :price

t.timestamps
end

create_table :consumables do |t|
t.string :type
t.string :name
t.integer :price

Expand Down
58 changes: 58 additions & 0 deletions lib/tasks/db/populate.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
namespace :db do
desc 'Populate database with fake data for development'
task :populate => [ 'db:seed', 'db:populate:create' ]

namespace :populate do

desc "Reload populate data"
task :reload => [ 'db:reset', :create ]

desc "Create populate data"
task :create => :environment do

require 'forgery'

puts 'User population'
time_start = Time.now
time_end = Time.now
puts ' -> ' + (time_end - time_start).round(4).to_s + 's'


puts 'Character population'
time_start = Time.now
time_end = Time.now
puts ' -> ' + (time_end - time_start).round(4).to_s + 's'


puts 'Armor population'
time_start = Time.now
10.times do
Armor.create :name => Forgery::Name.company_name,
:price => Forgery::Monetary.money(:min => 100, :max => 1000)
end
time_end = Time.now
puts ' -> ' + (time_end - time_start).round(4).to_s + 's'


puts 'Weapon population'
time_start = Time.now
10.times do
Weapon.create :name => Forgery::Name.company_name,
:price => Forgery::Monetary.money(:min => 100, :max => 1000)
end
time_end = Time.now
puts ' -> ' + (time_end - time_start).round(4).to_s + 's'


puts 'Consumable population'
time_start = Time.now
10.times do
Consumable.create :name => Forgery::Name.company_name,
:price => Forgery::Monetary.money(:min => 100, :max => 1000)
end
time_end = Time.now
puts ' -> ' + (time_end - time_start).round(4).to_s + 's'

end
end
end
8 changes: 8 additions & 0 deletions spec/dummy/db/seeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Mayor.create(:name => 'Daley', :city => cities.first)

17 changes: 0 additions & 17 deletions tasks/db/populate.rake

This file was deleted.

0 comments on commit 7ad1107

Please sign in to comment.