-
Notifications
You must be signed in to change notification settings - Fork 1
/
seeds.rb
51 lines (44 loc) · 1.54 KB
/
seeds.rb
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
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
def generate_passwd(length=8)
if Rails.env == 'development'
'password'
else
chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789!@#$%^&*)(+'
Array.new(length) { chars[rand(chars.length)].chr }.join
end
end
# Seeding methodology:
#
# Seeding provides records that are minimally needed to run the application
#
# Seeding is non-destructive. An applicaiton can be re-seeded without any
# adverse effects. This means that seeding should not override existing
# records.
# Non-destructively seed the bike brand and model data
if BikeBrand.count == 0
Rake::Task['db:bike_mfg:seed'].invoke
end
if User.count == 0
User.create!(:email=>"staff@freeridepgh.org", :password=>generate_passwd(15), :group => 'staff')
end
if User.count == 1
User.create!(:email=>"volunteer@freeridepgh.org", :password=>generate_passwd(15), :group => 'volunteer')
end
# Seed the hooks
(1..50).each do |n|
['H', 'L'].each do |suffix|
hook_num = "%02d#{suffix}" % n
if Hook.where(:number_record => hook_num).to_a.first.nil?
# Hook for the given number does not exist, so create it
h = Hook.new
h.number = hook_num
h.save
end # Hook.where
end # [suffixes].each
end # (1..N).each