sample-enterprises
1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment'
# turn on autoflush
STDOUT.sync = true
def rand_position(type)
range = {
:lat => [-33.52, 4.6],
:lng => [-72.9, -32.41],
}[type]
amplitude = (range.last - range.first)
range.first + rand() * amplitude
end
groups = ['Associação', 'Empresa Solidária', 'Cooperativa']
what = ['de Produção de Alimentos', 'de Serviços', 'de Artesanato', 'de Comercialização']
places = ['de Caximbinha do Sul', 'de Bonito', 'de Reviravolta do Serrado']
start_time = Time.now
print "Creating enterprises: "
groups.each do |group|
what.each do |production|
places.each do |place|
name = [group, production, place].join(' ')
Enterprise.create!(
:name => name,
:identifier => name.to_slug,
:enabled => false,
:foundation_year => (1990..2008).to_a[rand(18)],
:lat => rand_position(:lat),
:lng => rand_position(:lng)
)
print "."
end
end
end
puts " done!"
EnterpriseActivation.find(:all, :conditions => ['created_at > ?', start_time]).each do |activation|
enterprise = activation.enterprise
puts [activation.code, enterprise.name, enterprise.foundation_year].join(';')
end
ze = Person['ze']
# give admin rights for 'ze' in some enterprises
Enterprise.all.rand.add_admin(ze)
Enterprise.all.rand.add_admin(ze)
Enterprise.all.rand.add_admin(ze)