sample-products 1.27 KB
#!/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!'