Permalink
Browse files

Seed data

  • Loading branch information...
1 parent 184f552 commit 24cdfdf25eac2f43ca3187e6d7c584b9aa52326a @ignar committed Oct 25, 2012
Showing with 44 additions and 3 deletions.
  1. +6 −2 ctracker.org
  2. +33 −1 db/seeds.rb
  3. +5 −0 lib/tasks/load.rake
View
8 ctracker.org
@@ -1,10 +1,10 @@
#+STARTUP: showall
#+BEGIN: clocktable :maxlevel 2 :scope file
-Clock summary at [2012-10-25 Thu 11:17]
+Clock summary at [2012-10-25 Thu 12:08]
| Headline | Time |
|----------------------------------------------------------------------------------+---------|
-| *Total time* | *18:22* |
+| *Total time* | *19:06* |
|----------------------------------------------------------------------------------+---------|
| DONE Setup. Understand the task. Read existed code. | 0:37 |
| DONE Rake task | 0:07 |
@@ -31,6 +31,7 @@ Clock summary at [2012-10-25 Thu 11:17]
| DONE Add apply controll | 0:14 |
| DONE Progress chart | 2:15 |
| DONE Rewrite from hbtm to has_many | 1:52 |
+| DONE Create seed data | 0:44 |
#+END:
#+STARTUP: hidestars
#+STARTUP: logdone
@@ -123,3 +124,6 @@ Clock summary at [2012-10-25 Thu 11:17]
* DONE Rewrite from hbtm to has_many
CLOSED: [2012-10-25 Thu 02:21]
CLOCK: [2012-10-25 Thu 00:29]--[2012-10-25 Thu 02:21] => 1:52
+* DONE Create seed data
+ CLOSED: [2012-10-25 Thu 12:08]
+ CLOCK: [2012-10-25 Thu 11:24]--[2012-10-25 Thu 12:08] => 0:44
View
34 db/seeds.rb
@@ -6,9 +6,41 @@
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Mayor.create(:name => 'Daley', :city => cities.first)
-User.find_or_create_by_email("user1@example.com", :password => "Password123!")
+user1 = User.find_or_create_by_email("user1@example.com", :password => "Password123!")
puts """
You could login as user1
email: user1@example.com
password: Password123!
+---------------------------
"""
+
+user2 = User.find_or_create_by_email("user2@example.com", :password => "Password123!")
+puts """
+You could login as user2
+email: user2@example.com
+password: Password123!
+---------------------------
+"""
+
+countries = Country.where("code in (?)", ["af", "ar", "gb", "an", "ht", "mt", "vu"])
+
+countries.each do |country|
+ user1.toggle_visiting(country)
+end
+
+puts "-- Faking data"
+start_time = Date.today - 8.days
+ucs = UserCountry.where(:user_id => user1.id).all
+1.upto(7) do |t|
+ date = start_time + t.days
+ uc = ucs.shift()
+ uc.update_attributes({:created_at, date, :updated_at, date})
+
+
+ uc.country.currencies.map do |c|
+ UserCurrency.where(:user_id => user1.id, :currency_code => c.code).map do |c|
+ c.update_attributes({:created_at, date, :updated_at, date})
+ end
+ end
+end
+puts "-- Done"
View
5 lib/tasks/load.rake
@@ -1,6 +1,11 @@
namespace :ctracker do
desc "Load countries and currencies"
task :load => :environment do
+ puts "-- Loading Currencies and Countries"
DataUpdater.instance.update
end
end
+
+namespace :db do
+ task :seed => ["ctracker:load"]
+end

0 comments on commit 24cdfdf

Please sign in to comment.