Commit ac0a419c3abc2b007340506ab5a84d67783ae866
1 parent
44487be7
Exists in
master
and in
29 other branches
Create sample data in a specified environment
Showing
1 changed file
with
22 additions
and
7 deletions
Show diff stats
script/sample-data
1 | #!/usr/bin/env ruby | 1 | #!/usr/bin/env ruby |
2 | require File.dirname(__FILE__) + '/../config/environment' | 2 | require File.dirname(__FILE__) + '/../config/environment' |
3 | 3 | ||
4 | -system('rake db:populate') | 4 | + |
5 | +environment_id = ARGV.first | ||
6 | +environment = nil | ||
7 | +if environment_id | ||
8 | + environment = Environment.find(environment_id) | ||
9 | +else | ||
10 | + system('rake db:populate') | ||
11 | + environment = Environment.default | ||
12 | +end | ||
5 | 13 | ||
6 | people = [] | 14 | people = [] |
7 | 15 | ||
@@ -12,12 +20,13 @@ print "Creating users: "; $stdout.flush | @@ -12,12 +20,13 @@ print "Creating users: "; $stdout.flush | ||
12 | for name in NAMES | 20 | for name in NAMES |
13 | for surname in SURNAMES | 21 | for surname in SURNAMES |
14 | full_name = [name, surname].join(' ') | 22 | full_name = [name, surname].join(' ') |
15 | - user = User.create!( | 23 | + user = User.create!({ |
16 | :login => full_name.to_slug, | 24 | :login => full_name.to_slug, |
17 | :email => full_name.to_slug + '@localhost.localdomain', | 25 | :email => full_name.to_slug + '@localhost.localdomain', |
18 | :password => 'test', | 26 | :password => 'test', |
19 | - :password_confirmation => 'test' | ||
20 | - ) | 27 | + :password_confirmation => 'test', |
28 | + :environment => environment, | ||
29 | + }) | ||
21 | user.person.name = full_name | 30 | user.person.name = full_name |
22 | user.person.save! | 31 | user.person.save! |
23 | people << user.person | 32 | people << user.person |
@@ -46,7 +55,7 @@ print "Creating communities: "; $stdout.flush | @@ -46,7 +55,7 @@ print "Creating communities: "; $stdout.flush | ||
46 | for verb in VERBS | 55 | for verb in VERBS |
47 | for stuff in STUFF | 56 | for stuff in STUFF |
48 | name = [verb, stuff].join(' ') | 57 | name = [verb, stuff].join(' ') |
49 | - community = Community.create!(:name => name) | 58 | + community = Community.create!(:name => name, :environment => environment) |
50 | rand(10).times do | 59 | rand(10).times do |
51 | community.add_member(people.rand) | 60 | community.add_member(people.rand) |
52 | end | 61 | end |
@@ -55,5 +64,11 @@ for verb in VERBS | @@ -55,5 +64,11 @@ for verb in VERBS | ||
55 | end | 64 | end |
56 | puts | 65 | puts |
57 | 66 | ||
58 | -ze = User.create!(:login => "ze", :email => 'root@localhost.localdomain', :password => 'test', :password_confirmation => 'test').person | ||
59 | -Environment.default.add_admin(ze) | 67 | +ze = User.create!({ |
68 | + :login => "ze", | ||
69 | + :email => 'root@localhost.localdomain', | ||
70 | + :password => 'test', | ||
71 | + :password_confirmation => 'test', | ||
72 | + :environment => environment, | ||
73 | +}).person | ||
74 | +environment.add_admin(ze) |