From f35693e295c407f74af481d071420faffae269bd Mon Sep 17 00:00:00 2001 From: Arafat Mohamed Date: Tue, 11 Nov 2008 20:15:49 -0600 Subject: [PATCH] Added rake task - bootstrap - to populate database --- lib/tasks/bootstrap.rake | 45 +++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/lib/tasks/bootstrap.rake b/lib/tasks/bootstrap.rake index db8f7d4..5ab1959 100644 --- a/lib/tasks/bootstrap.rake +++ b/lib/tasks/bootstrap.rake @@ -1,11 +1,36 @@ -namespace :bootstrap do - desc "Add the default user" - task :user => :environment do - User.create(:name => 'user', - :login => 'user', - :password => 'user99', - :password_confirmation => 'user99', - :email => 'user@capwn.com', - :admin => true) - end +task :bootstrap => :environment do + + # Create User + u = User.generate(:name => 'user', + :login => 'user', + :password => 'user99', + :password_confirmation => 'user99', + :email => 'user@capwn.com', + :admin => true) + + # Create Accounts + income = Account.generate(:name => 'Income') + checking = Account.generate(:name => 'Checking') + taxes = Account.generate(:name => 'Taxes') + groceries = Account.generate(:name => 'Groceries') + + # Create Transactions/Entries + t1 = Transaction.generate(:memo => 'Paycheck', + :user => u) + + t1e1 = Entry.generate(:amount => 80, + :debit_account => income, + :credit_account => checking, + :transaction => t1) + t1e2 = Entry.generate(:amount => 20, + :debit_account => income, + :credit_account => taxes, + :transaction => t1) + + t2 = Transaction.generate(:memo => 'Buy Groceries', + :user => u) + + t2e1 = Entry.generate(:debit_account => checking, + :credit_account => groceries, + :transaction => t2) end