sample-products
1.27 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
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment'
# tourn on autoflush
STDOUT.sync = true
enterprises = Enterprise.all
categories = ProductCategory.all
print "Creating products: "
THINGS = %w[ Car House Bicycle Book Pen Computer Webcam ]
COLORS = %w[ Black Red White Blue Green Purple ]
for thing in THINGS
for color in COLORS
name = [color, thing].join(' ')
rand(10).times do |i|
Product.create(
:name => name,
:enterprise_id => enterprises.rand.id, :price => (i * 13.7),
:product_category_id => categories.rand.id
)
print '.'
end
end
end
puts ' done!'
environment = Environment.default
print "Creating qualifiers and certifier: "
QUALIFIERS = ['Organic', 'Free as in Freedom', 'Regional']
CERTIFIERS = ['FBES', 'Colivre', 'Institute Paulo Freire', 'Fora do Eixo']
for qualifier in QUALIFIERS
environment.qualifiers << Qualifier.new(:name => qualifier)
print '.'
end
for certifier in CERTIFIERS
environment.certifiers << Certifier.new(:name => certifier)
print '.'
end
puts ' done!'
print "Creating units: "
[['Litre', 'Litres'], ['Kilo', 'Kilos'], ['Meter', 'Meters']].each do |unit|
Unit.create!(:singular => unit[0], :plural => unit[1], :environment => environment)
print '.'
end
puts ' done!'