Commit ac0a419c3abc2b007340506ab5a84d67783ae866
1 parent
44487be7
Exists in
staging
and in
42 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 | 1 | #!/usr/bin/env ruby |
| 2 | 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 | 14 | people = [] |
| 7 | 15 | |
| ... | ... | @@ -12,12 +20,13 @@ print "Creating users: "; $stdout.flush |
| 12 | 20 | for name in NAMES |
| 13 | 21 | for surname in SURNAMES |
| 14 | 22 | full_name = [name, surname].join(' ') |
| 15 | - user = User.create!( | |
| 23 | + user = User.create!({ | |
| 16 | 24 | :login => full_name.to_slug, |
| 17 | 25 | :email => full_name.to_slug + '@localhost.localdomain', |
| 18 | 26 | :password => 'test', |
| 19 | - :password_confirmation => 'test' | |
| 20 | - ) | |
| 27 | + :password_confirmation => 'test', | |
| 28 | + :environment => environment, | |
| 29 | + }) | |
| 21 | 30 | user.person.name = full_name |
| 22 | 31 | user.person.save! |
| 23 | 32 | people << user.person |
| ... | ... | @@ -46,7 +55,7 @@ print "Creating communities: "; $stdout.flush |
| 46 | 55 | for verb in VERBS |
| 47 | 56 | for stuff in STUFF |
| 48 | 57 | name = [verb, stuff].join(' ') |
| 49 | - community = Community.create!(:name => name) | |
| 58 | + community = Community.create!(:name => name, :environment => environment) | |
| 50 | 59 | rand(10).times do |
| 51 | 60 | community.add_member(people.rand) |
| 52 | 61 | end |
| ... | ... | @@ -55,5 +64,11 @@ for verb in VERBS |
| 55 | 64 | end |
| 56 | 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) | ... | ... |